Mercurial > hg > orthanc
changeset 1741:06addfcd1d4c
OrthancStarted and OrthancStopped events in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 23 Oct 2015 16:49:17 +0200 |
parents | 5e99a70b0635 |
children | 2dd5c6b0380b |
files | NEWS OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/main.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h Plugins/Include/orthanc/OrthancCPlugin.h |
diffstat | 7 files changed, 62 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Thu Oct 22 19:53:51 2015 +0200 +++ b/NEWS Fri Oct 23 16:49:17 2015 +0200 @@ -14,6 +14,7 @@ * New function "OrthancPluginRegisterErrorCode()" to declare custom error codes * New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags +* New "OrthancStarted" and "OrthancStopped" events in change callbacks Lua ---
--- a/OrthancServer/ServerContext.cpp Thu Oct 22 19:53:51 2015 +0200 +++ b/OrthancServer/ServerContext.cpp Fri Oct 23 16:49:17 2015 +0200 @@ -520,6 +520,18 @@ } } + OrthancPlugins& ServerContext::GetPlugins() + { + if (HasPlugins()) + { + return *plugins_; + } + else + { + throw OrthancException(ErrorCode_InternalError); + } + } + #endif
--- a/OrthancServer/ServerContext.h Thu Oct 22 19:53:51 2015 +0200 +++ b/OrthancServer/ServerContext.h Fri Oct 23 16:49:17 2015 +0200 @@ -256,6 +256,8 @@ void ResetPlugins(); const OrthancPlugins& GetPlugins() const; + + OrthancPlugins& GetPlugins(); #endif bool HasPlugins() const;
--- a/OrthancServer/main.cpp Thu Oct 22 19:53:51 2015 +0200 +++ b/OrthancServer/main.cpp Fri Oct 23 16:49:17 2015 +0200 @@ -597,6 +597,13 @@ { LOG(WARNING) << "Orthanc has started"; +#if ORTHANC_PLUGINS_ENABLED == 1 + if (context.HasPlugins()) + { + context.GetPlugins().SignalOrthancStarted(); + } +#endif + context.GetLua().Execute("Initialize"); Toolbox::ServerBarrier(restApi.LeaveBarrierFlag()); @@ -604,6 +611,13 @@ context.GetLua().Execute("Finalize"); +#if ORTHANC_PLUGINS_ENABLED == 1 + if (context.HasPlugins()) + { + context.GetPlugins().SignalOrthancStopped(); + } +#endif + if (restart) { LOG(WARNING) << "Reset request received, restarting Orthanc";
--- a/Plugins/Engine/OrthancPlugins.cpp Thu Oct 22 19:53:51 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Fri Oct 23 16:49:17 2015 +0200 @@ -514,7 +514,9 @@ - void OrthancPlugins::SignalChange(const ServerIndexChange& change) + void OrthancPlugins::SignalChangeInternal(OrthancPluginChangeType changeType, + OrthancPluginResourceType resourceType, + const char* resource) { boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_); @@ -522,10 +524,7 @@ callback = pimpl_->onChangeCallbacks_.begin(); callback != pimpl_->onChangeCallbacks_.end(); ++callback) { - OrthancPluginErrorCode error = (*callback) - (Plugins::Convert(change.GetChangeType()), - Plugins::Convert(change.GetResourceType()), - change.GetPublicId().c_str()); + OrthancPluginErrorCode error = (*callback) (changeType, resourceType, resource); if (error != OrthancPluginErrorCode_Success) { @@ -537,6 +536,15 @@ + void OrthancPlugins::SignalChange(const ServerIndexChange& change) + { + SignalChangeInternal(Plugins::Convert(change.GetChangeType()), + Plugins::Convert(change.GetResourceType()), + change.GetPublicId().c_str()); + } + + + static void CopyToMemoryBuffer(OrthancPluginMemoryBuffer& target, const void* data, size_t size) @@ -1258,6 +1266,8 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } + printf("ICI %s\n", p.instanceId); + std::string content; pimpl_->context_->ReadFile(content, p.instanceId, FileContentType_Dicom); dicom.reset(new ParsedDicomFile(content));
--- a/Plugins/Engine/OrthancPlugins.h Thu Oct 22 19:53:51 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.h Fri Oct 23 16:49:17 2015 +0200 @@ -130,6 +130,10 @@ void ApplyDicomToJson(_OrthancPluginService service, const void* parameters); + void SignalChangeInternal(OrthancPluginChangeType changeType, + OrthancPluginResourceType resourceType, + const char* resource); + public: OrthancPlugins(); @@ -186,6 +190,16 @@ const PluginsManager& GetManager() const; PluginsErrorDictionary& GetErrorDictionary(); + + void SignalOrthancStarted() + { + SignalChangeInternal(OrthancPluginChangeType_OrthancStarted, OrthancPluginResourceType_None, NULL); + } + + void SignalOrthancStopped() + { + SignalChangeInternal(OrthancPluginChangeType_OrthancStopped, OrthancPluginResourceType_None, NULL); + } }; }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Thu Oct 22 19:53:51 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Fri Oct 23 16:49:17 2015 +0200 @@ -550,6 +550,7 @@ OrthancPluginResourceType_Study = 1, /*!< Study */ OrthancPluginResourceType_Series = 2, /*!< Series */ OrthancPluginResourceType_Instance = 3, /*!< Instance */ + OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ _OrthancPluginResourceType_INTERNAL = 0x7fffffff } OrthancPluginResourceType; @@ -572,6 +573,8 @@ OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ + OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ + OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ _OrthancPluginChangeType_INTERNAL = 0x7fffffff } OrthancPluginChangeType; @@ -3892,7 +3895,7 @@ params.flags = flags; params.maxStringLength = maxStringLength; - if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) + if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) { /* Error */ return NULL;