Mercurial > hg > orthanc
diff OrthancServer/ServerIndex.cpp @ 1191:d49505e377e3 db-changes
demo of OnChangeCallback in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Sep 2014 17:50:06 +0200 |
parents | 6b9b02a16e99 |
children | 669bb978d52e |
line wrap: on
line diff
--- a/OrthancServer/ServerIndex.cpp Thu Sep 25 17:02:28 2014 +0200 +++ b/OrthancServer/ServerIndex.cpp Thu Sep 25 17:50:06 2014 +0200 @@ -122,10 +122,19 @@ std::list<FileToRemove> pendingFilesToRemove_; std::list<Change> pendingChanges_; uint64_t sizeOfFilesToRemove_; + bool insideTransaction_; + + void Reset() + { + sizeOfFilesToRemove_ = 0; + hasRemainingLevel_ = false; + pendingFilesToRemove_.clear(); + pendingChanges_.clear(); + } public: - ServerIndexListener(ServerContext& context) : - context_(context) + ServerIndexListener(ServerContext& context) : context_(context), + insideTransaction_(false) { Reset(); assert(ResourceType_Patient < ResourceType_Study && @@ -133,12 +142,15 @@ ResourceType_Series < ResourceType_Instance); } - void Reset() + void StartTransaction() { - sizeOfFilesToRemove_ = 0; - hasRemainingLevel_ = false; - pendingFilesToRemove_.clear(); - pendingChanges_.clear(); + Reset(); + insideTransaction_ = true; + } + + void EndTransaction() + { + insideTransaction_ = false; } uint64_t GetSizeOfFilesToRemove() @@ -201,7 +213,14 @@ LOG(INFO) << "Change related to resource " << publicId << " of type " << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType); - pendingChanges_.push_back(Change(changeType, resourceType, publicId)); + if (insideTransaction_) + { + pendingChanges_.push_back(Change(changeType, resourceType, publicId)); + } + else + { + context_.SignalChange(changeType, resourceType, publicId); + } } bool HasRemainingLevel() const @@ -238,9 +257,15 @@ { assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); - index_.listener_->Reset(); transaction_.reset(index_.db_->StartTransaction()); transaction_->Begin(); + + index_.listener_->StartTransaction(); + } + + ~Transaction() + { + index_.listener_->EndTransaction(); } void Commit(uint64_t sizeOfAddedFiles) @@ -312,7 +337,6 @@ ResourceType expectedType) { boost::mutex::scoped_lock lock(mutex_); - listener_->Reset(); Transaction t(*this); @@ -489,7 +513,6 @@ const MetadataMap& metadata) { boost::mutex::scoped_lock lock(mutex_); - listener_->Reset(); instanceMetadata.clear(); @@ -1826,7 +1849,6 @@ FileContentType type) { boost::mutex::scoped_lock lock(mutex_); - listener_->Reset(); Transaction t(*this);