# HG changeset patch # User Sebastien Jodogne # Date 1445611757 -7200 # Node ID 06addfcd1d4cae9a322e5566ac2666cb29fc962d # Parent 5e99a70b06356b7e4c8daf3db63fbafecfd39ba0 OrthancStarted and OrthancStopped events in plugins diff -r 5e99a70b0635 -r 06addfcd1d4c NEWS --- 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 --- diff -r 5e99a70b0635 -r 06addfcd1d4c OrthancServer/ServerContext.cpp --- 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 diff -r 5e99a70b0635 -r 06addfcd1d4c OrthancServer/ServerContext.h --- 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; diff -r 5e99a70b0635 -r 06addfcd1d4c OrthancServer/main.cpp --- 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"; diff -r 5e99a70b0635 -r 06addfcd1d4c Plugins/Engine/OrthancPlugins.cpp --- 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)); diff -r 5e99a70b0635 -r 06addfcd1d4c Plugins/Engine/OrthancPlugins.h --- 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); + } }; } diff -r 5e99a70b0635 -r 06addfcd1d4c Plugins/Include/orthanc/OrthancCPlugin.h --- 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;