changeset 1198:1169528a9a5f db-changes

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Oct 2014 13:52:01 +0200
parents 61b71ccac362
children a843ee8bb903
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/IServerIndexListener.h OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndexChange.h Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h Plugins/OrthancCPlugin/OrthancCPlugin.h UnitTestsSources/ServerIndexTests.cpp
diffstat 11 files changed, 133 insertions(+), 121 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/DatabaseWrapper.cpp	Thu Oct 23 13:52:01 2014 +0200
@@ -116,7 +116,8 @@
       virtual void Compute(SQLite::FunctionContext& context)
       {
         ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
-        listener_.SignalChange(ChangeType_Deleted, type, context.GetStringValue(0));
+        ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
+        listener_.SignalChange(change);
       }
     };
 
@@ -258,7 +259,7 @@
       throw OrthancException(ErrorCode_InternalError);
     }
 
-    LogChange(changeType, id, type, publicId);
+    LogChange(id, changeType, type, publicId);
     return id;
   }
 
@@ -647,24 +648,22 @@
   }
 
 
-  void DatabaseWrapper::LogChange(ChangeType changeType,
-                                  int64_t internalId,
-                                  ResourceType resourceType,
-                                  const std::string& publicId)
+  void DatabaseWrapper::LogChange(int64_t internalId,
+                                  const ServerIndexChange& change)
   {
-    if (changeType <= ChangeType_INTERNAL_LastLogged)
+    if (change.GetChangeType() <= ChangeType_INTERNAL_LastLogged)
     {
       const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
 
       SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
-      s.BindInt(0, changeType);
+      s.BindInt(0, change.GetChangeType());
       s.BindInt64(1, internalId);
-      s.BindInt(2, resourceType);
+      s.BindInt(2, change.GetResourceType());
       s.BindString(3, boost::posix_time::to_iso_string(now));
       s.Run();
     }
 
-    listener_.SignalChange(changeType, resourceType, publicId);
+    listener_.SignalChange(change);
   }
 
 
--- a/OrthancServer/DatabaseWrapper.h	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/DatabaseWrapper.h	Thu Oct 23 13:52:01 2014 +0200
@@ -154,10 +154,17 @@
     void GetChildrenInternalId(std::list<int64_t>& result,
                                int64_t id);
 
-    void LogChange(ChangeType changeType,
-                   int64_t internalId,
+    void LogChange(int64_t internalId,
+                   ChangeType changeType,
                    ResourceType resourceType,
-                   const std::string& publicId);
+                   const std::string& publicId)
+    {
+      ServerIndexChange change(changeType, resourceType, publicId);
+      LogChange(internalId, change);
+    }
+
+    void LogChange(int64_t internalId,
+                   const ServerIndexChange& change);
 
     void GetChanges(Json::Value& target,
                     int64_t since,
--- a/OrthancServer/IServerIndexListener.h	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/IServerIndexListener.h	Thu Oct 23 13:52:01 2014 +0200
@@ -34,6 +34,7 @@
 
 #include <string>
 #include "ServerEnumerations.h"
+#include "ServerIndexChange.h"
 
 namespace Orthanc
 {
@@ -49,8 +50,6 @@
 
     virtual void SignalFileDeleted(const FileInfo& info) = 0;
 
-    virtual void SignalChange(ChangeType changeType,
-                              ResourceType resourceType,
-                              const std::string& publicId) = 0;
+    virtual void SignalChange(const ServerIndexChange& change) = 0;
   };
 }
--- a/OrthancServer/ServerContext.cpp	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/ServerContext.cpp	Thu Oct 23 13:52:01 2014 +0200
@@ -522,15 +522,13 @@
   }
 
 
-  void ServerContext::SignalChange(ChangeType changeType,
-                                   ResourceType resourceType,
-                                   const std::string&  publicId)
+  void ServerContext::SignalChange(const ServerIndexChange& change)
   {
     if (plugins_ != NULL)
     {
       try
       {
-        plugins_->SignalChange(changeType, resourceType, publicId);
+        plugins_->SignalChange(change);
       }
       catch (OrthancException& e)
       {
@@ -538,5 +536,4 @@
       }
     }
   }
-
 }
--- a/OrthancServer/ServerContext.h	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/ServerContext.h	Thu Oct 23 13:52:01 2014 +0200
@@ -42,6 +42,7 @@
 #include "DicomProtocol/ReusableDicomUserConnection.h"
 #include "Scheduler/ServerScheduler.h"
 #include "DicomInstanceToStore.h"
+#include "ServerIndexChange.h"
 
 #include <boost/filesystem.hpp>
 
@@ -203,8 +204,6 @@
                         const std::string& uuid,
                         ResourceType expectedType);
 
-    void SignalChange(ChangeType changeType,
-                      ResourceType resourceType,
-                      const std::string&  publicId);
+    void SignalChange(const ServerIndexChange& change);
   };
 }
--- a/OrthancServer/ServerIndex.cpp	Thu Oct 23 13:19:18 2014 +0200
+++ b/OrthancServer/ServerIndex.cpp	Thu Oct 23 13:52:01 2014 +0200
@@ -37,6 +37,7 @@
 #define NOMINMAX
 #endif
 
+#include "ServerIndexChange.h"
 #include "EmbeddedResources.h"
 #include "OrthancInitialization.h"
 #include "../Core/Toolbox.h"
@@ -82,39 +83,6 @@
         }
       };
 
-      struct ServerIndexChange
-      {
-      private:
-        ChangeType   changeType_;
-        ResourceType resourceType_;
-        std::string  publicId_;
-
-      public:
-        ServerIndexChange(ChangeType changeType,
-               ResourceType resourceType,
-               const std::string&  publicId) :
-          changeType_(changeType),
-          resourceType_(resourceType),
-          publicId_(publicId)
-        {
-        }
-
-        ChangeType  GetChangeType() const
-        {
-          return changeType_;
-        }
-
-        ResourceType  GetResourceType() const
-        {
-          return resourceType_;
-        }
-
-        const std::string&  GetPublicId() const
-        {
-          return publicId_;
-        }
-      };
-
       ServerContext& context_;
       bool hasRemainingLevel_;
       ResourceType remainingType_;
@@ -174,7 +142,7 @@
                it = pendingChanges_.begin(); 
              it != pendingChanges_.end(); it++)
         {
-          context_.SignalChange(it->GetChangeType(), it->GetResourceType(), it->GetPublicId());
+          context_.SignalChange(*it);
         }
       }
 
@@ -206,20 +174,19 @@
         sizeOfFilesToRemove_ += info.GetCompressedSize();
       }
 
-      virtual void SignalChange(ChangeType changeType,
-                                ResourceType resourceType,
-                                const std::string& publicId)
+      virtual void SignalChange(const ServerIndexChange& change)
       {
-        LOG(INFO) << "Change related to resource " << publicId << " of type " 
-                  << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType);
+        LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type " 
+                  << EnumerationToString(change.GetResourceType()) << ": " 
+                  << EnumerationToString(change.GetChangeType());
 
         if (insideTransaction_)
         {
-          pendingChanges_.push_back(ServerIndexChange(changeType, resourceType, publicId));
+          pendingChanges_.push_back(change);
         }
         else
         {
-          context_.SignalChange(changeType, resourceType, publicId);
+          context_.SignalChange(change);
         }
       }
 
@@ -706,7 +673,7 @@
       SeriesStatus seriesStatus = GetSeriesStatus(series);
       if (seriesStatus == SeriesStatus_Complete)
       {
-        db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series, hasher.HashSeries());
+        db_->LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries());
       }
 
       // Mark the parent resources of this instance as unstable
@@ -1495,7 +1462,7 @@
       throw OrthancException(ErrorCode_UnknownResource);
     }
 
-    db_->LogChange(changeType, id, type, publicId);
+    db_->LogChange(id, changeType, type, publicId);
 
     transaction->Commit();
   }
@@ -1695,15 +1662,15 @@
           switch (payload.GetResourceType())
           {
             case ResourceType_Patient:
-              that->db_->LogChange(ChangeType_StablePatient, id, ResourceType_Patient, payload.GetPublicId());
+              that->db_->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId());
               break;
 
             case ResourceType_Study:
-              that->db_->LogChange(ChangeType_StableStudy, id, ResourceType_Study, payload.GetPublicId());
+              that->db_->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId());
               break;
 
             case ResourceType_Series:
-              that->db_->LogChange(ChangeType_StableSeries, id, ResourceType_Series, payload.GetPublicId());
+              that->db_->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId());
               break;
 
             default:
@@ -1733,7 +1700,7 @@
     unstableResources_.AddOrMakeMostRecent(id, payload);
     //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id;
 
-    db_->LogChange(ChangeType_NewChildInstance, id, type, publicId);
+    db_->LogChange(id, ChangeType_NewChildInstance, type, publicId);
   }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/ServerIndexChange.h	Thu Oct 23 13:52:01 2014 +0200
@@ -0,0 +1,73 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
+ * Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "ServerEnumerations.h"
+
+#include <string>
+
+namespace Orthanc
+{
+  struct ServerIndexChange
+  {
+  private:
+    ChangeType   changeType_;
+    ResourceType resourceType_;
+    std::string  publicId_;
+
+  public:
+    ServerIndexChange(ChangeType changeType,
+                      ResourceType resourceType,
+                      const std::string&  publicId) :
+      changeType_(changeType),
+      resourceType_(resourceType),
+      publicId_(publicId)
+    {
+    }
+
+    ChangeType  GetChangeType() const
+    {
+      return changeType_;
+    }
+
+    ResourceType  GetResourceType() const
+    {
+      return resourceType_;
+    }
+
+    const std::string&  GetPublicId() const
+    {
+      return publicId_;
+    }
+  };
+}
--- a/Plugins/Engine/OrthancPlugins.cpp	Thu Oct 23 13:19:18 2014 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Thu Oct 23 13:52:01 2014 +0200
@@ -153,30 +153,12 @@
   {
     switch (type)
     {
-      case ChangeType_AnonymizedPatient:
-        return OrthancPluginChangeType_AnonymizedPatient;
-
-      case ChangeType_AnonymizedSeries:
-        return OrthancPluginChangeType_AnonymizedSeries;
-
-      case ChangeType_AnonymizedStudy:
-        return OrthancPluginChangeType_AnonymizedStudy;
-
       case ChangeType_CompletedSeries:
         return OrthancPluginChangeType_CompletedSeries;
 
       case ChangeType_Deleted:
         return OrthancPluginChangeType_Deleted;
 
-      case ChangeType_ModifiedPatient:
-        return OrthancPluginChangeType_ModifiedPatient;
-
-      case ChangeType_ModifiedSeries:
-        return OrthancPluginChangeType_ModifiedSeries;
-
-      case ChangeType_ModifiedStudy:
-        return OrthancPluginChangeType_ModifiedStudy;
-
       case ChangeType_NewChildInstance:
         return OrthancPluginChangeType_NewChildInstance;
 
@@ -383,17 +365,15 @@
 
 
 
-  void OrthancPlugins::SignalChange(ChangeType changeType,
-                                    ResourceType resourceType,
-                                    const std::string& publicId)
+  void OrthancPlugins::SignalChange(const ServerIndexChange& change)
   {
     OrthancPluginChangeType c;
     OrthancPluginResourceType r;
 
     try
     {
-      c = Convert(changeType);
-      r = Convert(resourceType);
+      c = Convert(change.GetChangeType());
+      r = Convert(change.GetResourceType());
     }
     catch (OrthancException&)
     {
@@ -407,7 +387,7 @@
            callback = pimpl_->onChangeCallbacks_.begin(); 
          callback != pimpl_->onChangeCallbacks_.end(); ++callback)
     {
-      (*callback) (c, r, publicId.c_str());
+      (*callback) (c, r, change.GetPublicId().c_str());
     }
   }
 
--- a/Plugins/Engine/OrthancPlugins.h	Thu Oct 23 13:19:18 2014 +0200
+++ b/Plugins/Engine/OrthancPlugins.h	Thu Oct 23 13:52:01 2014 +0200
@@ -97,9 +97,7 @@
     virtual bool InvokeService(_OrthancPluginService service,
                                const void* parameters);
 
-    void SignalChange(ChangeType changeType,
-                      ResourceType resourceType,
-                      const std::string& publicId);
+    void SignalChange(const ServerIndexChange& change);
 
     void SignalStoredInstance(DicomInstanceToStore& instance,
                               const std::string& instanceId);
--- a/Plugins/OrthancCPlugin/OrthancCPlugin.h	Thu Oct 23 13:19:18 2014 +0200
+++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h	Thu Oct 23 13:52:01 2014 +0200
@@ -360,22 +360,16 @@
    **/
   typedef enum
   {
-    OrthancPluginChangeType_AnonymizedPatient = 0,  /*!< Patient resulting from an anomyization */
-    OrthancPluginChangeType_AnonymizedSeries = 1,   /*!< Series resulting from an anonymization */
-    OrthancPluginChangeType_AnonymizedStudy = 2,    /*!< Study resulting from an anomyization */
-    OrthancPluginChangeType_CompletedSeries = 3,    /*!< Series is now complete */
-    OrthancPluginChangeType_Deleted = 4,            /*!< Deleted resource */
-    OrthancPluginChangeType_ModifiedPatient = 5,    /*!< Patient resulting from a modification */
-    OrthancPluginChangeType_ModifiedSeries = 6,     /*!< Series resulting from a modification */
-    OrthancPluginChangeType_ModifiedStudy = 7,      /*!< Study resulting from a modification */
-    OrthancPluginChangeType_NewChildInstance = 8,   /*!< A new instance was added to this resource */
-    OrthancPluginChangeType_NewInstance = 9,        /*!< New instance received */
-    OrthancPluginChangeType_NewPatient = 10,        /*!< New patient created */
-    OrthancPluginChangeType_NewSeries = 11,         /*!< New series created */
-    OrthancPluginChangeType_NewStudy = 12,          /*!< New study created */
-    OrthancPluginChangeType_StablePatient = 13,     /*!< Timeout: No new instance in this patient */
-    OrthancPluginChangeType_StableSeries = 14,      /*!< Timeout: No new instance in this series */
-    OrthancPluginChangeType_StableStudy = 15        /*!< Timeout: No new instance in this study */
+    OrthancPluginChangeType_CompletedSeries = 0,    /*!< Series is now complete */
+    OrthancPluginChangeType_Deleted = 1,            /*!< Deleted resource */
+    OrthancPluginChangeType_NewChildInstance = 2,   /*!< A new instance was added to this resource */
+    OrthancPluginChangeType_NewInstance = 3,        /*!< New instance received */
+    OrthancPluginChangeType_NewPatient = 4,         /*!< New patient created */
+    OrthancPluginChangeType_NewSeries = 5,          /*!< New series created */
+    OrthancPluginChangeType_NewStudy = 6,           /*!< New study created */
+    OrthancPluginChangeType_StablePatient = 7,      /*!< Timeout: No new instance in this patient */
+    OrthancPluginChangeType_StableSeries = 8,       /*!< Timeout: No new instance in this series */
+    OrthancPluginChangeType_StableStudy = 9         /*!< Timeout: No new instance in this study */
   } OrthancPluginChangeType;
 
 
--- a/UnitTestsSources/ServerIndexTests.cpp	Thu Oct 23 13:19:18 2014 +0200
+++ b/UnitTestsSources/ServerIndexTests.cpp	Thu Oct 23 13:52:01 2014 +0200
@@ -82,17 +82,16 @@
       LOG(INFO) << "A file must be removed: " << fileUuid;
     }       
 
-    virtual void SignalChange(ChangeType changeType,
-                              ResourceType resourceType,
-                              const std::string& publicId)
+    virtual void SignalChange(const ServerIndexChange& change)
     {
-      if (changeType == ChangeType_Deleted)
+      if (change.GetChangeType() == ChangeType_Deleted)
       {
-        deletedResources_.push_back(publicId);        
+        deletedResources_.push_back(change.GetPublicId());        
       }
 
-      LOG(INFO) << "Change related to resource " << publicId << " of type " 
-                << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType);
+      LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type " 
+                << EnumerationToString(change.GetResourceType()) << ": " 
+                << EnumerationToString(change.GetChangeType());
     }
 
   };