Mercurial > hg > orthanc
changeset 1455:a68545767975
Initialize() and Finalize() events in Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 Jul 2015 15:17:19 +0200 |
parents | 9de4fa64e29c |
children | 68827c07e683 |
files | CMakeLists.txt NEWS OrthancServer/LuaScripting.cpp OrthancServer/LuaScripting.h OrthancServer/main.cpp |
diffstat | 5 files changed, 33 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Thu Jul 02 12:30:55 2015 +0200 +++ b/CMakeLists.txt Thu Jul 02 15:17:19 2015 +0200 @@ -27,6 +27,7 @@ SET(UNIT_TESTS_WITH_HTTP_CONNEXIONS ON CACHE BOOL "Allow unit tests to make HTTP requests") SET(ENABLE_JPEG ON CACHE BOOL "Enable JPEG decompression") SET(ENABLE_JPEG_LOSSLESS ON CACHE BOOL "Enable JPEG-LS (Lossless) decompression") +SET(ENABLE_PLUGINS ON CACHE BOOL "Enable plugins") # Advanced parameters to fine-tune linking against system libraries SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") @@ -54,6 +55,7 @@ mark_as_advanced(USE_GTEST_DEBIAN_SOURCE_PACKAGE) mark_as_advanced(SYSTEM_MONGOOSE_USE_CALLBACKS) mark_as_advanced(USE_BOOST_ICONV) +mark_as_advanced(USE_PUGIXML) # Path to the root folder of the Orthanc distribution set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}) @@ -261,6 +263,13 @@ endif() +if (ENABLE_PLUGINS) + add_definitions(-DORTHANC_PLUGINS_ENABLED=1) +else() + add_definitions(-DORTHANC_PLUGINS_ENABLED=0) +endif() + + ##################################################################### ## Autogeneration of files
--- a/NEWS Thu Jul 02 12:30:55 2015 +0200 +++ b/NEWS Thu Jul 02 15:17:19 2015 +0200 @@ -14,7 +14,7 @@ * Access to the REST API of Orthanc (RestApiGet, RestApiPost, RestApiPut, RestApiDelete) * Functions to convert between Lua values and JSON strings: "ParseJson" and "DumpJson" -* New events: "OnStablePatient", "OnStableStudy", "OnStableSeries" +* New events: "OnStablePatient", "OnStableStudy", "OnStableSeries", "Initialize", "Finalize" Plugins -------
--- a/OrthancServer/LuaScripting.cpp Thu Jul 02 12:30:55 2015 +0200 +++ b/OrthancServer/LuaScripting.cpp Thu Jul 02 15:17:19 2015 +0200 @@ -488,4 +488,16 @@ return true; } + + + void LuaScripting::Execute(const std::string& command) + { + LuaScripting::Locker locker(*this); + + if (locker.GetLua().IsExistingFunction(command.c_str())) + { + LuaFunctionCall call(locker.GetLua(), command.c_str()); + call.Execute(); + } + } }
--- a/OrthancServer/LuaScripting.h Thu Jul 02 12:30:55 2015 +0200 +++ b/OrthancServer/LuaScripting.h Thu Jul 02 15:17:19 2015 +0200 @@ -104,5 +104,7 @@ virtual bool FilterIncomingInstance(const Json::Value& simplified, const std::string& remoteAet); + + void Execute(const std::string& command); }; }
--- a/OrthancServer/main.cpp Thu Jul 02 12:30:55 2015 +0200 +++ b/OrthancServer/main.cpp Thu Jul 02 15:17:19 2015 +0200 @@ -55,9 +55,6 @@ using namespace Orthanc; -#define ENABLE_PLUGINS 1 - - class OrthancStoreRequestHandler : public IStoreRequestHandler { private: @@ -389,9 +386,13 @@ { LOG(WARNING) << "Orthanc has started"; + context.GetLua().Execute("Initialize"); + Toolbox::ServerBarrier(restApi.ResetRequestReceivedFlag()); bool restart = restApi.ResetRequestReceivedFlag(); + context.GetLua().Execute("Finalize"); + if (restart) { LOG(WARNING) << "Reset request received, restarting Orthanc"; @@ -570,7 +571,7 @@ std::auto_ptr<IDatabaseWrapper> databasePtr; std::auto_ptr<IStorageArea> storage; -#if ENABLE_PLUGINS == 1 +#if ORTHANC_PLUGINS_ENABLED == 1 OrthancPlugins plugins; plugins.SetCommandLineArguments(argc, argv); LoadPlugins(plugins); @@ -602,12 +603,15 @@ return ConfigureServerContext(*database, *storage, &plugins); -#else +#elif ORTHANC_PLUGINS_ENABLED == 0 // The plugins are disabled databasePtr.reset(Configuration::CreateDatabaseWrapper()); storage.reset(Configuration::CreateStorageArea()); return ConfigureServerContext(*databasePtr, *storage, NULL); + +#else +# error The macro ORTHANC_PLUGINS_ENABLED must be set to 0 or 1 #endif }