Mercurial > hg > orthanc
changeset 1189:6b9b02a16e99 db-changes
NewChildInstance change type
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Sep 2014 17:02:28 +0200 |
parents | 49edef619f1f |
children | d49505e377e3 |
files | OrthancServer/DatabaseWrapper.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h OrthancServer/ServerIndex.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/OrthancCPlugin/OrthancCPlugin.h |
diffstat | 8 files changed, 70 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Thu Sep 25 17:02:28 2014 +0200 @@ -652,19 +652,17 @@ ResourceType resourceType, const std::string& publicId) { - if (changeType == ChangeType_Deleted) + if (changeType <= ChangeType_INTERNAL_LastLogged) { - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - - const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + 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.BindInt64(1, internalId); - s.BindInt(2, resourceType); - s.BindString(3, boost::posix_time::to_iso_string(now)); - s.Run(); + SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); + s.BindInt(0, changeType); + s.BindInt64(1, internalId); + s.BindInt(2, resourceType); + s.BindString(3, boost::posix_time::to_iso_string(now)); + s.Run(); + } listener_.SignalChange(changeType, resourceType, publicId); }
--- a/OrthancServer/ServerContext.cpp Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Thu Sep 25 17:02:28 2014 +0200 @@ -371,7 +371,7 @@ } catch (OrthancException& e) { - LOG(ERROR) << "Error in OnStoredInstance callback (Lua): " << e.What(); + LOG(ERROR) << "Error in OnStoredInstance callback (plugins): " << e.What(); } } } @@ -520,4 +520,23 @@ { return index_.DeleteResource(target, uuid, expectedType); } + + + void ServerContext::SignalChange(ChangeType changeType, + ResourceType resourceType, + const std::string& publicId) + { + if (plugins_ != NULL) + { + try + { + plugins_->SignalChange(changeType, resourceType, publicId); + } + catch (OrthancException& e) + { + LOG(ERROR) << "Error in OnChangeCallback (plugins): " << e.What(); + } + } + } + }
--- a/OrthancServer/ServerContext.h Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/ServerContext.h Thu Sep 25 17:02:28 2014 +0200 @@ -202,5 +202,9 @@ bool DeleteResource(Json::Value& target, const std::string& uuid, ResourceType expectedType); + + void SignalChange(ChangeType changeType, + ResourceType resourceType, + const std::string& publicId); }; }
--- a/OrthancServer/ServerEnumerations.cpp Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/ServerEnumerations.cpp Thu Sep 25 17:02:28 2014 +0200 @@ -234,6 +234,9 @@ case ChangeType_Deleted: return "Deleted"; + case ChangeType_NewChildInstance: + return "NewChildInstance"; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); }
--- a/OrthancServer/ServerEnumerations.h Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/ServerEnumerations.h Thu Sep 25 17:02:28 2014 +0200 @@ -135,7 +135,12 @@ ChangeType_StablePatient = 12, ChangeType_StableStudy = 13, ChangeType_StableSeries = 14, - ChangeType_Deleted = 15 // Not logged in the index + + ChangeType_INTERNAL_LastLogged = 4095, + + // The changes below this point are not logged into the database + ChangeType_Deleted = 4096, + ChangeType_NewChildInstance = 4097 };
--- a/OrthancServer/ServerIndex.cpp Thu Sep 25 16:42:19 2014 +0200 +++ b/OrthancServer/ServerIndex.cpp Thu Sep 25 17:02:28 2014 +0200 @@ -138,6 +138,7 @@ sizeOfFilesToRemove_ = 0; hasRemainingLevel_ = false; pendingFilesToRemove_.clear(); + pendingChanges_.clear(); } uint64_t GetSizeOfFilesToRemove() @@ -147,7 +148,7 @@ void CommitFilesToRemove() { - for (std::list<FileToRemove>::iterator + for (std::list<FileToRemove>::const_iterator it = pendingFilesToRemove_.begin(); it != pendingFilesToRemove_.end(); ++it) { @@ -155,6 +156,16 @@ } } + void CommitChanges() + { + for (std::list<Change>::const_iterator + it = pendingChanges_.begin(); + it != pendingChanges_.end(); it++) + { + context_.SignalChange(it->GetChangeType(), it->GetResourceType(), it->GetPublicId()); + } + } + virtual void SignalRemainingAncestor(ResourceType parentType, const std::string& publicId) { @@ -250,6 +261,9 @@ assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); + // Send all the pending changes to the Orthanc plugins + index_.listener_->CommitChanges(); + isCommitted_ = true; } } @@ -1695,6 +1709,8 @@ UnstableResourcePayload payload(type, publicId); unstableResources_.AddOrMakeMostRecent(id, payload); //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; + + db_->LogChange(ChangeType_NewChildInstance, id, type, publicId); }
--- a/Plugins/Engine/OrthancPlugins.cpp Thu Sep 25 16:42:19 2014 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Sep 25 17:02:28 2014 +0200 @@ -177,6 +177,9 @@ case ChangeType_ModifiedStudy: return OrthancPluginChangeType_ModifiedStudy; + case ChangeType_NewChildInstance: + return OrthancPluginChangeType_NewChildInstance; + case ChangeType_NewInstance: return OrthancPluginChangeType_NewInstance;
--- a/Plugins/OrthancCPlugin/OrthancCPlugin.h Thu Sep 25 16:42:19 2014 +0200 +++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h Thu Sep 25 17:02:28 2014 +0200 @@ -368,13 +368,14 @@ 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_NewInstance = 8, /*!< New instance received */ - OrthancPluginChangeType_NewPatient = 9, /*!< New patient created */ - OrthancPluginChangeType_NewSeries = 10, /*!< New series created */ - OrthancPluginChangeType_NewStudy = 11, /*!< New study created */ - OrthancPluginChangeType_StablePatient = 12, /*!< No new instance received for this patient */ - OrthancPluginChangeType_StableSeries = 13, /*!< No new instance received for this series */ - OrthancPluginChangeType_StableStudy = 14 /*!< No new instance received for this study */ + 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;