Mercurial > hg > orthanc
diff OrthancServer/ServerIndex.cpp @ 1432:0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2015 12:51:29 +0200 |
parents | b22ba8c5edbe |
children | c0bdc47165ef |
line wrap: on
line diff
--- 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();