# HG changeset patch # User Sebastien Jodogne # Date 1615561449 -3600 # Node ID 4a0bf1019335cf188795ef7fc9905dc277adf4b8 # Parent bec74e29f86b09c61c0969c9b40ae8f265b3173d simplification of ServerIndex::Listener as ServerIndex::TransactionContext diff -r bec74e29f86b -r 4a0bf1019335 OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Fri Mar 12 15:33:47 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Fri Mar 12 16:04:09 2021 +0100 @@ -51,7 +51,7 @@ namespace Orthanc { - class ServerIndex::Listener : public StatelessDatabaseOperations::ITransactionContext + class ServerIndex::TransactionContext : public StatelessDatabaseOperations::ITransactionContext { private: struct FileToRemove @@ -85,7 +85,6 @@ std::list pendingFilesToRemove_; std::list pendingChanges_; uint64_t sizeOfFilesToRemove_; - bool insideTransaction_; uint64_t sizeOfAddedAttachments_; void Reset() @@ -97,33 +96,6 @@ sizeOfAddedAttachments_ = 0; } - public: - explicit 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::const_iterator @@ -152,6 +124,16 @@ } } + public: + explicit TransactionContext(ServerContext& context) : + context_(context) + { + Reset(); + assert(ResourceType_Patient < ResourceType_Study && + ResourceType_Study < ResourceType_Series && + ResourceType_Series < ResourceType_Instance); + } + virtual void SignalRemainingAncestor(ResourceType parentType, const std::string& publicId) ORTHANC_OVERRIDE { @@ -192,14 +174,7 @@ << EnumerationToString(change.GetResourceType()) << ": " << EnumerationToString(change.GetChangeType()); - if (insideTransaction_) - { - pendingChanges_.push_back(change); - } - else - { - context_.SignalChange(change); - } + pendingChanges_.push_back(change); } virtual void SignalAttachmentsAdded(uint64_t compressedSize) ORTHANC_OVERRIDE @@ -207,35 +182,13 @@ sizeOfAddedAttachments_ += compressedSize; } - bool HasRemainingLevel() const - { - return hasRemainingLevel_; - } - - ResourceType GetRemainingType() const - { - assert(HasRemainingLevel()); - return remainingType_; - } - - const std::string& GetRemainingPublicId() const - { - assert(HasRemainingLevel()); - return remainingPublicId_; - } - - uint64_t GetSizeOfAddedAttachments() const - { - return sizeOfAddedAttachments_; - } - virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */, ResourceType& remainingLevel /* out */) ORTHANC_OVERRIDE { - if (HasRemainingLevel()) + if (hasRemainingLevel_) { - remainingPublicId = GetRemainingPublicId(); - remainingLevel = GetRemainingType(); + remainingPublicId = remainingPublicId_; + remainingLevel = remainingType_; return true; } else @@ -269,8 +222,8 @@ virtual int64_t GetCompressedSizeDelta() ORTHANC_OVERRIDE { - return (static_cast(GetSizeOfAddedAttachments()) - - static_cast(GetSizeOfFilesToRemove())); + return (static_cast(sizeOfAddedAttachments_) - + static_cast(sizeOfFilesToRemove_)); } }; @@ -278,90 +231,17 @@ class ServerIndex::TransactionContextFactory : public ITransactionContextFactory { private: - class Context : public ITransactionContext - { - private: - Listener& listener_; - - public: - Context(ServerIndex& index) : - listener_(*index.listener_) - { - listener_.StartTransaction(); - } - - ~Context() - { - listener_.EndTransaction(); - } - - virtual bool IsUnstableResource(int64_t id) ORTHANC_OVERRIDE - { - return listener_.IsUnstableResource(id); - } - - virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */, - ResourceType& remainingLevel /* out */) ORTHANC_OVERRIDE - { - return listener_.LookupRemainingLevel(remainingPublicId, remainingLevel); - } - - virtual void MarkAsUnstable(int64_t id, - Orthanc::ResourceType type, - const std::string& publicId) ORTHANC_OVERRIDE - { - listener_.MarkAsUnstable(id, type, publicId); - } - - virtual void SignalAttachmentsAdded(uint64_t compressedSize) ORTHANC_OVERRIDE - { - listener_.SignalAttachmentsAdded(compressedSize); - } - - virtual void SignalChange(const ServerIndexChange& change) ORTHANC_OVERRIDE - { - listener_.SignalChange(change); - } - - virtual void Commit() ORTHANC_OVERRIDE - { - listener_.Commit(); - } - - virtual int64_t GetCompressedSizeDelta() ORTHANC_OVERRIDE - { - return listener_.GetCompressedSizeDelta(); - } - - virtual void SignalRemainingAncestor(ResourceType parentType, - const std::string& publicId) ORTHANC_OVERRIDE - { - listener_.SignalRemainingAncestor(parentType, publicId); - } - - virtual void SignalAttachmentDeleted(const FileInfo& info) ORTHANC_OVERRIDE - { - listener_.SignalAttachmentDeleted(info); - } - - virtual void SignalResourceDeleted(ResourceType type, - const std::string& publicId) ORTHANC_OVERRIDE - { - listener_.SignalResourceDeleted(type, publicId); - } - }; - - ServerIndex& index_; + ServerContext& context_; public: - TransactionContextFactory(ServerIndex& index) : - index_(index) + TransactionContextFactory(ServerContext& context) : + context_(context) { } virtual ITransactionContext* Create() { - return new Context(index_); + return new TransactionContext(context_); } }; @@ -452,9 +332,7 @@ maximumStorageSize_(0), maximumPatients_(0) { - listener_.reset(new Listener(context)); - - SetTransactionContextFactory(new TransactionContextFactory(*this)); + SetTransactionContextFactory(new TransactionContextFactory(context)); // Initial recycling if the parameters have changed since the last // execution of Orthanc diff -r bec74e29f86b -r 4a0bf1019335 OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Fri Mar 12 15:33:47 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Fri Mar 12 16:04:09 2021 +0100 @@ -45,8 +45,8 @@ class ServerIndex : public StatelessDatabaseOperations { private: + class TransactionContext; class TransactionContextFactory; - class Listener; class UnstableResourcePayload; bool done_; @@ -54,7 +54,6 @@ boost::thread flushThread_; boost::thread unstableResourcesMonitorThread_; - std::unique_ptr listener_; LeastRecentlyUsedIndex unstableResources_; uint64_t maximumStorageSize_;