changeset 1432:0ac74fa21db8

rename IServerIndexListener as IDatabaseListener
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2015 12:51:29 +0200
parents 3e53edcd0120
children 461e7554bff7
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/IDatabaseListener.h OrthancServer/IDatabaseWrapper.h OrthancServer/IServerIndexListener.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h UnitTestsSources/ServerIndexTests.cpp
diffstat 10 files changed, 199 insertions(+), 206 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Tue Jun 30 11:54:16 2015 +0200
+++ b/OrthancServer/DatabaseWrapper.cpp	Tue Jun 30 12:51:29 2015 +0200
@@ -49,10 +49,10 @@
     class SignalFileDeleted : public SQLite::IScalarFunction
     {
     private:
-      IServerIndexListener& listener_;
+      IDatabaseListener& listener_;
 
     public:
-      SignalFileDeleted(IServerIndexListener& listener) :
+      SignalFileDeleted(IDatabaseListener& listener) :
         listener_(listener)
       {
       }
@@ -96,10 +96,10 @@
     class SignalResourceDeleted : public SQLite::IScalarFunction
     {
     private:
-      IServerIndexListener& listener_;
+      IDatabaseListener& listener_;
 
     public:
-      SignalResourceDeleted(IServerIndexListener& listener) :
+      SignalResourceDeleted(IDatabaseListener& listener) :
         listener_(listener)
       {
       }
@@ -834,7 +834,7 @@
     db_.Register(signalRemainingAncestor_);
   }
 
-  void DatabaseWrapper::SetListener(IServerIndexListener& listener)
+  void DatabaseWrapper::SetListener(IDatabaseListener& listener)
   {
     listener_ = &listener;
     db_.Register(new Internals::SignalFileDeleted(listener));
--- a/OrthancServer/DatabaseWrapper.h	Tue Jun 30 11:54:16 2015 +0200
+++ b/OrthancServer/DatabaseWrapper.h	Tue Jun 30 12:51:29 2015 +0200
@@ -52,7 +52,7 @@
   class DatabaseWrapper : public IDatabaseWrapper
   {
   private:
-    IServerIndexListener* listener_;
+    IDatabaseListener* listener_;
     SQLite::Connection db_;
     Internals::SignalRemainingAncestor* signalRemainingAncestor_;
 
@@ -75,7 +75,7 @@
 
     DatabaseWrapper();
 
-    virtual void SetListener(IServerIndexListener& listener);
+    virtual void SetListener(IDatabaseListener& listener);
 
     virtual void SetGlobalProperty(GlobalProperty property,
                                    const std::string& value);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/IDatabaseListener.h	Tue Jun 30 12:51:29 2015 +0200
@@ -0,0 +1,55 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital 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 <string>
+#include "ServerEnumerations.h"
+#include "ServerIndexChange.h"
+
+namespace Orthanc
+{
+  class IDatabaseListener
+  {
+  public:
+    virtual ~IDatabaseListener()
+    {
+    }
+
+    virtual void SignalRemainingAncestor(ResourceType parentType,
+                                         const std::string& publicId) = 0;
+
+    virtual void SignalFileDeleted(const FileInfo& info) = 0;
+
+    virtual void SignalChange(const ServerIndexChange& change) = 0;
+  };
+}
--- a/OrthancServer/IDatabaseWrapper.h	Tue Jun 30 11:54:16 2015 +0200
+++ b/OrthancServer/IDatabaseWrapper.h	Tue Jun 30 12:51:29 2015 +0200
@@ -35,7 +35,7 @@
 #include "../Core/DicomFormat/DicomMap.h"
 #include "../Core/SQLite/ITransaction.h"
 #include "../Core/FileStorage/FileInfo.h"
-#include "IServerIndexListener.h"
+#include "IDatabaseListener.h"
 #include "ExportedResource.h"
 
 #include <list>
@@ -176,6 +176,6 @@
 
     virtual SQLite::ITransaction* StartTransaction() = 0;
 
-    virtual void SetListener(IServerIndexListener& listener) = 0;
+    virtual void SetListener(IDatabaseListener& listener) = 0;
   };
 }
--- a/OrthancServer/IServerIndexListener.h	Tue Jun 30 11:54:16 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/**
- * Orthanc - A Lightweight, RESTful DICOM Store
- * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
- * Department, University Hospital 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 <string>
-#include "ServerEnumerations.h"
-#include "ServerIndexChange.h"
-
-namespace Orthanc
-{
-  class IServerIndexListener
-  {
-  public:
-    virtual ~IServerIndexListener()
-    {
-    }
-
-    virtual void SignalRemainingAncestor(ResourceType parentType,
-                                         const std::string& publicId) = 0;
-
-    virtual void SignalFileDeleted(const FileInfo& info) = 0;
-
-    virtual void SignalChange(const ServerIndexChange& change) = 0;
-  };
-}
--- a/OrthancServer/ServerIndex.cpp	Tue Jun 30 11:54:16 2015 +0200
+++ b/OrthancServer/ServerIndex.cpp	Tue Jun 30 12:51:29 2015 +0200
@@ -54,159 +54,156 @@
 
 namespace Orthanc
 {
-  namespace Internals
+  class ServerIndex::Listener : public IDatabaseListener
   {
-    class ServerIndexListener : public IServerIndexListener
+  private:
+    struct FileToRemove
     {
     private:
-      struct FileToRemove
-      {
-      private:
-        std::string  uuid_;
-        FileContentType  type_;
-
-      public:
-        FileToRemove(const FileInfo& info) : uuid_(info.GetUuid()), 
-                                             type_(info.GetContentType())
-        {
-        }
-
-        const std::string& GetUuid() const
-        {
-          return uuid_;
-        }
+      std::string  uuid_;
+      FileContentType  type_;
 
-        FileContentType GetContentType() const 
-        {
-          return type_;
-        }
-      };
-
-      ServerContext& context_;
-      bool hasRemainingLevel_;
-      ResourceType remainingType_;
-      std::string remainingPublicId_;
-      std::list<FileToRemove> pendingFilesToRemove_;
-      std::list<ServerIndexChange> pendingChanges_;
-      uint64_t sizeOfFilesToRemove_;
-      bool insideTransaction_;
-
-      void Reset()
+    public:
+      FileToRemove(const FileInfo& info) : uuid_(info.GetUuid()), 
+                                           type_(info.GetContentType())
       {
-        sizeOfFilesToRemove_ = 0;
-        hasRemainingLevel_ = false;
-        pendingFilesToRemove_.clear();
-        pendingChanges_.clear();
       }
 
-    public:
-      ServerIndexListener(ServerContext& context) : context_(context),
-                                                    insideTransaction_(false)      
-      {
-        Reset();
-        assert(ResourceType_Patient < ResourceType_Study &&
-               ResourceType_Study < ResourceType_Series &&
-               ResourceType_Series < ResourceType_Instance);
-      }
-
-      void StartTransaction()
+      const std::string& GetUuid() const
       {
-        Reset();
-        insideTransaction_ = true;
-      }
-
-      void EndTransaction()
-      {
-        insideTransaction_ = false;
-      }
-
-      uint64_t GetSizeOfFilesToRemove()
-      {
-        return sizeOfFilesToRemove_;
+        return uuid_;
       }
 
-      void CommitFilesToRemove()
+      FileContentType GetContentType() const 
       {
-        for (std::list<FileToRemove>::const_iterator 
-               it = pendingFilesToRemove_.begin();
-             it != pendingFilesToRemove_.end(); ++it)
-        {
-          context_.RemoveFile(it->GetUuid(), it->GetContentType());
-        }
+        return type_;
       }
+    };
 
-      void CommitChanges()
+    ServerContext& context_;
+    bool hasRemainingLevel_;
+    ResourceType remainingType_;
+    std::string remainingPublicId_;
+    std::list<FileToRemove> pendingFilesToRemove_;
+    std::list<ServerIndexChange> pendingChanges_;
+    uint64_t sizeOfFilesToRemove_;
+    bool insideTransaction_;
+
+    void Reset()
+    {
+      sizeOfFilesToRemove_ = 0;
+      hasRemainingLevel_ = false;
+      pendingFilesToRemove_.clear();
+      pendingChanges_.clear();
+    }
+
+  public:
+    Listener(ServerContext& context) : context_(context),
+                                       insideTransaction_(false)      
+    {
+      Reset();
+      assert(ResourceType_Patient < ResourceType_Study &&
+             ResourceType_Study < ResourceType_Series &&
+             ResourceType_Series < ResourceType_Instance);
+    }
+
+    void StartTransaction()
+    {
+      Reset();
+      insideTransaction_ = true;
+    }
+
+    void EndTransaction()
+    {
+      insideTransaction_ = false;
+    }
+
+    uint64_t GetSizeOfFilesToRemove()
+    {
+      return sizeOfFilesToRemove_;
+    }
+
+    void CommitFilesToRemove()
+    {
+      for (std::list<FileToRemove>::const_iterator 
+             it = pendingFilesToRemove_.begin();
+           it != pendingFilesToRemove_.end(); ++it)
       {
-        for (std::list<ServerIndexChange>::const_iterator 
-               it = pendingChanges_.begin(); 
-             it != pendingChanges_.end(); ++it)
+        context_.RemoveFile(it->GetUuid(), it->GetContentType());
+      }
+    }
+
+    void CommitChanges()
+    {
+      for (std::list<ServerIndexChange>::const_iterator 
+             it = pendingChanges_.begin(); 
+           it != pendingChanges_.end(); ++it)
+      {
+        context_.SignalChange(*it);
+      }
+    }
+
+    virtual void SignalRemainingAncestor(ResourceType parentType,
+                                         const std::string& publicId)
+    {
+      VLOG(1) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
+
+      if (hasRemainingLevel_)
+      {
+        if (parentType < remainingType_)
         {
-          context_.SignalChange(*it);
-        }
-      }
-
-      virtual void SignalRemainingAncestor(ResourceType parentType,
-                                           const std::string& publicId)
-      {
-        VLOG(1) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
-
-        if (hasRemainingLevel_)
-        {
-          if (parentType < remainingType_)
-          {
-            remainingType_ = parentType;
-            remainingPublicId_ = publicId;
-          }
-        }
-        else
-        {
-          hasRemainingLevel_ = true;
           remainingType_ = parentType;
           remainingPublicId_ = publicId;
-        }        
-      }
-
-      virtual void SignalFileDeleted(const FileInfo& info)
-      {
-        assert(Toolbox::IsUuid(info.GetUuid()));
-        pendingFilesToRemove_.push_back(FileToRemove(info));
-        sizeOfFilesToRemove_ += info.GetCompressedSize();
-      }
-
-      virtual void SignalChange(const ServerIndexChange& change)
-      {
-        VLOG(1) << "Change related to resource " << change.GetPublicId() << " of type " 
-                << EnumerationToString(change.GetResourceType()) << ": " 
-                << EnumerationToString(change.GetChangeType());
-
-        if (insideTransaction_)
-        {
-          pendingChanges_.push_back(change);
-        }
-        else
-        {
-          context_.SignalChange(change);
         }
       }
-
-      bool HasRemainingLevel() const
+      else
       {
-        return hasRemainingLevel_;
-      }
+        hasRemainingLevel_ = true;
+        remainingType_ = parentType;
+        remainingPublicId_ = publicId;
+      }        
+    }
 
-      ResourceType GetRemainingType() const
+    virtual void SignalFileDeleted(const FileInfo& info)
+    {
+      assert(Toolbox::IsUuid(info.GetUuid()));
+      pendingFilesToRemove_.push_back(FileToRemove(info));
+      sizeOfFilesToRemove_ += info.GetCompressedSize();
+    }
+
+    virtual void SignalChange(const ServerIndexChange& change)
+    {
+      VLOG(1) << "Change related to resource " << change.GetPublicId() << " of type " 
+              << EnumerationToString(change.GetResourceType()) << ": " 
+              << EnumerationToString(change.GetChangeType());
+
+      if (insideTransaction_)
       {
-        assert(HasRemainingLevel());
-        return remainingType_;
+        pendingChanges_.push_back(change);
       }
-
-      const std::string& GetRemainingPublicId() const
+      else
       {
-        assert(HasRemainingLevel());
-        return remainingPublicId_;
-      }                                 
-    };
-  }
+        context_.SignalChange(change);
+      }
+    }
+
+    bool HasRemainingLevel() const
+    {
+      return hasRemainingLevel_;
+    }
+
+    ResourceType GetRemainingType() const
+    {
+      assert(HasRemainingLevel());
+      return remainingType_;
+    }
+
+    const std::string& GetRemainingPublicId() const
+    {
+      assert(HasRemainingLevel());
+      return remainingPublicId_;
+    }                                 
+  };
 
 
   class ServerIndex::Transaction
@@ -549,7 +546,7 @@
     maximumStorageSize_(0),
     maximumPatients_(0)
   {
-    listener_.reset(new Internals::ServerIndexListener(context));
+    listener_.reset(new Listener(context));
     db_.SetListener(*listener_);
 
     currentStorageSize_ = db_.GetTotalCompressedSize();
--- a/OrthancServer/ServerIndex.h	Tue Jun 30 11:54:16 2015 +0200
+++ b/OrthancServer/ServerIndex.h	Tue Jun 30 12:51:29 2015 +0200
@@ -47,11 +47,6 @@
 {
   class ServerContext;
 
-  namespace Internals
-  {
-    class ServerIndexListener;
-  }
-
   class ServerIndex : public boost::noncopyable
   {
   public:
@@ -59,6 +54,7 @@
     typedef std::map< std::pair<ResourceType, MetadataType>, std::string>  MetadataMap;
 
   private:
+    class Listener;
     class Transaction;
     class UnstableResourcePayload;
 
@@ -67,7 +63,7 @@
     boost::thread flushThread_;
     boost::thread unstableResourcesMonitorThread_;
 
-    std::auto_ptr<Internals::ServerIndexListener> listener_;
+    std::auto_ptr<Listener> listener_;
     IDatabaseWrapper& db_;
     LeastRecentlyUsedIndex<int64_t, UnstableResourcePayload>  unstableResources_;
 
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Jun 30 11:54:16 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Tue Jun 30 12:51:29 2015 +0200
@@ -887,7 +887,7 @@
   }
 
 
-  static void ProcessEvent(IServerIndexListener& listener,
+  static void ProcessEvent(IDatabaseListener& listener,
                            const _OrthancPluginDatabaseAnswer& answer)
   {
     switch (answer.type)
--- a/Plugins/Engine/OrthancPluginDatabase.h	Tue Jun 30 11:54:16 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Tue Jun 30 12:51:29 2015 +0200
@@ -47,7 +47,7 @@
     _OrthancPluginDatabaseAnswerType type_;
     OrthancPluginDatabaseBackend backend_;
     void* payload_;
-    IServerIndexListener* listener_;
+    IDatabaseListener* listener_;
 
     std::list<std::string>         answerStrings_;
     std::list<int32_t>             answerInt32_;
@@ -210,7 +210,7 @@
 
     virtual SQLite::ITransaction* StartTransaction();
 
-    virtual void SetListener(IServerIndexListener& listener)
+    virtual void SetListener(IDatabaseListener& listener)
     {
       listener_ = &listener;
     }
--- a/UnitTestsSources/ServerIndexTests.cpp	Tue Jun 30 11:54:16 2015 +0200
+++ b/UnitTestsSources/ServerIndexTests.cpp	Tue Jun 30 12:51:29 2015 +0200
@@ -54,7 +54,7 @@
   };
 
 
-  class ServerIndexListener : public IServerIndexListener
+  class TestDatabaseListener : public IDatabaseListener
   {
   public:
     std::vector<std::string> deletedFiles_;
@@ -100,7 +100,7 @@
   class DatabaseWrapperTest : public ::testing::TestWithParam<DatabaseWrapperClass>
   {
   protected:
-    std::auto_ptr<ServerIndexListener> listener_;
+    std::auto_ptr<TestDatabaseListener> listener_;
     std::auto_ptr<IDatabaseWrapper> index_;
 
     DatabaseWrapperTest()
@@ -109,7 +109,7 @@
 
     virtual void SetUp() 
     {
-      listener_.reset(new ServerIndexListener);
+      listener_.reset(new TestDatabaseListener);
 
       switch (GetParam())
       {