# HG changeset patch # User Sebastien Jodogne # Date 1435843039 -7200 # Node ID a685457679754326e1b9b63f005885861036e5ee # Parent 9de4fa64e29c7140bfd62558c5ccf61e57301d6e Initialize() and Finalize() events in Lua diff -r 9de4fa64e29c -r a68545767975 CMakeLists.txt --- 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 diff -r 9de4fa64e29c -r a68545767975 NEWS --- 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 ------- diff -r 9de4fa64e29c -r a68545767975 OrthancServer/LuaScripting.cpp --- 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(); + } + } } diff -r 9de4fa64e29c -r a68545767975 OrthancServer/LuaScripting.h --- 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); }; } diff -r 9de4fa64e29c -r a68545767975 OrthancServer/main.cpp --- 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 databasePtr; std::auto_ptr 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 }