changeset 4003:3c19371090c3

removing useless LoggingMemento
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jun 2020 11:08:59 +0200
parents 02e61695cd83
children 9b5ace33a00d
files Core/Logging.cpp Core/Logging.h UnitTestsSources/LoggingTests.cpp
diffstat 3 files changed, 5 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Logging.cpp	Sat Jun 06 10:58:36 2020 +0200
+++ b/Core/Logging.cpp	Sat Jun 06 11:08:59 2020 +0200
@@ -459,19 +459,6 @@
     {
     }
   };
-
-  struct LoggingMementoImpl
-  {
-    bool valid_;
-    bool infoEnabled_;
-    bool traceEnabled_;
-    std::string  targetFile_;
-    std::string  targetFolder_;
-
-    std::ostream* error_;
-    std::ostream* warning_;
-    std::ostream* info_;
-  };
 }
 
 
@@ -594,59 +581,6 @@
     }
 
 
-    LoggingMemento CreateLoggingMemento()
-    {
-      LoggingMementoImpl* memento = new LoggingMementoImpl();
-
-      memento->valid_ = true;
-      {
-        boost::mutex::scoped_lock lock(loggingMutex_);
-        memento->infoEnabled_ = loggingContext_->infoEnabled_;
-        memento->traceEnabled_ = loggingContext_->traceEnabled_;
-        memento->targetFile_ = loggingContext_->targetFile_;
-        memento->targetFolder_ = loggingContext_->targetFolder_;
-
-        memento->error_ = loggingContext_->error_;
-        memento->warning_ = loggingContext_->warning_;
-        memento->info_ = loggingContext_->info_;
-      }
-      return reinterpret_cast<void*>(memento);
-    }
-    
-    void RestoreLoggingMemento(LoggingMemento mementoPtr)
-    {
-      LoggingMementoImpl* memento = 
-        reinterpret_cast<LoggingMementoImpl*>(mementoPtr);
-      if (!memento->valid_)
-        throw std::runtime_error("Memento already used");
-      memento->valid_ = false;
-      std::unique_ptr<LoggingMementoImpl> deleter(memento);
-      {
-        boost::mutex::scoped_lock lock(loggingMutex_);
-        loggingContext_.reset(new LoggingContext);
-        loggingContext_->error_ = memento->error_;
-        loggingContext_->warning_ = memento->warning_;
-        loggingContext_->info_ = memento->info_;
-      }
-      EnableInfoLevel(memento->infoEnabled_);
-      EnableTraceLevel(memento->traceEnabled_);
-      if (!memento->targetFolder_.empty())
-      {
-        SetTargetFolder(memento->targetFolder_);
-      }
-      else if (!memento->targetFile_.empty())
-      {
-        SetTargetFile(memento->targetFile_);
-      }
-    }
-
-    void DiscardLoggingMemento(LoggingMemento mementoPtr)
-    {
-      LoggingMementoImpl* memento =
-        reinterpret_cast<LoggingMementoImpl*>(mementoPtr);
-      delete memento;
-    }
-
     void EnableInfoLevel(bool enabled)
     {
       boost::mutex::scoped_lock lock(loggingMutex_);
--- a/Core/Logging.h	Sat Jun 06 10:58:36 2020 +0200
+++ b/Core/Logging.h	Sat Jun 06 11:08:59 2020 +0200
@@ -207,40 +207,6 @@
       }
     };
 
-    /**
-       opaque pointer that represents the state of the logging configuration
-    */
-    typedef void* LoggingMemento;
-
-    /**
-       Returns an object that contains the logging configuration.
-
-       This function allocates resources that you must dispose of by
-       using either RestoreLoggingMemento or DiscardLoggingMemento.
-
-       This function is only to be used by tests.
-    */
-    ORTHANC_PUBLIC LoggingMemento CreateLoggingMemento();
-
-    /**
-       Restores the logging configuration. The logging system is restored in 
-       the state it was in when the memento object was created through 
-       GetLoggingMemento().
-
-       After calling this function, the memento object may not be used 
-       again
-
-       This function is only to be used by tests.
-    */
-    ORTHANC_PUBLIC void RestoreLoggingMemento(LoggingMemento memento);
-
-    /**
-       Call this function if you do not plan on restoring the logging 
-       configuration state that you captured with CreateLoggingMemento
-
-       This function is only to be used by tests.
-    */
-    ORTHANC_PUBLIC void DiscardLoggingMemento(LoggingMemento memento);
 
     /**
        Set custom logging streams for the error, warning and info logs.
--- a/UnitTestsSources/LoggingTests.cpp	Sat Jun 06 10:58:36 2020 +0200
+++ b/UnitTestsSources/LoggingTests.cpp	Sat Jun 06 11:08:59 2020 +0200
@@ -105,13 +105,14 @@
   class LoggingMementoScope
   {
   public:
-    LoggingMementoScope() : memento_(CreateLoggingMemento()) {}
+    LoggingMementoScope()
+    {
+    }
+    
     ~LoggingMementoScope()
     {
-      RestoreLoggingMemento(memento_);
+      Orthanc::Logging::Reset();
     }
-  private:
-    LoggingMemento memento_;
   };
 }