comparison OrthancServer/LuaScripting.cpp @ 2943:9f6716008066

merge
author am@osimis.io
date Thu, 29 Nov 2018 15:26:47 +0100
parents 4767d36679ed
children f395460af74d
comparison
equal deleted inserted replaced
2942:e9613a09cf9e 2943:9f6716008066
32 32
33 33
34 #include "PrecompiledHeadersServer.h" 34 #include "PrecompiledHeadersServer.h"
35 #include "LuaScripting.h" 35 #include "LuaScripting.h"
36 36
37 #include "OrthancInitialization.h" 37 #include "OrthancConfiguration.h"
38 #include "OrthancRestApi/OrthancRestApi.h" 38 #include "OrthancRestApi/OrthancRestApi.h"
39 #include "ServerContext.h" 39 #include "ServerContext.h"
40 40
41 #include "../Core/HttpServer/StringHttpOutput.h" 41 #include "../Core/HttpServer/StringHttpOutput.h"
42 #include "../Core/Logging.h" 42 #include "../Core/Logging.h"
412 412
413 // Syntax in Lua: GetOrthancConfiguration() 413 // Syntax in Lua: GetOrthancConfiguration()
414 int LuaScripting::GetOrthancConfiguration(lua_State *state) 414 int LuaScripting::GetOrthancConfiguration(lua_State *state)
415 { 415 {
416 Json::Value configuration; 416 Json::Value configuration;
417 Configuration::GetConfiguration(configuration); 417
418 {
419 OrthancConfiguration::ReaderLock lock;
420 configuration = lock.GetJson();
421 }
418 422
419 LuaContext::GetLuaContext(state).PushJson(configuration); 423 LuaContext::GetLuaContext(state).PushJson(configuration);
420 424
421 return 1; 425 return 1;
422 } 426 }
443 { 447 {
444 localAet = context_.GetDefaultLocalApplicationEntityTitle(); 448 localAet = context_.GetDefaultLocalApplicationEntityTitle();
445 } 449 }
446 450
447 std::string name = parameters["Modality"].asString(); 451 std::string name = parameters["Modality"].asString();
448 RemoteModalityParameters modality = Configuration::GetModalityUsingSymbolicName(name); 452 RemoteModalityParameters modality;
453
454 {
455 OrthancConfiguration::ReaderLock configLock;
456 modality = configLock.GetConfiguration().GetModalityUsingSymbolicName(name);
457 }
449 458
450 // This is not a C-MOVE: No need to call "StoreScuCommand::SetMoveOriginator()" 459 // This is not a C-MOVE: No need to call "StoreScuCommand::SetMoveOriginator()"
451 return lock.AddStoreScuOperation(localAet, modality); 460 return lock.AddStoreScuOperation(localAet, modality);
452 } 461 }
453 462
454 if (operation == "store-peer") 463 if (operation == "store-peer")
455 { 464 {
465 OrthancConfiguration::ReaderLock configLock;
456 std::string name = parameters["Peer"].asString(); 466 std::string name = parameters["Peer"].asString();
457 467
458 WebServiceParameters peer; 468 WebServiceParameters peer;
459 if (Configuration::GetOrthancPeer(peer, name)) 469 if (configLock.GetConfiguration().GetOrthancPeer(peer, name))
460 { 470 {
461 return lock.AddStorePeerOperation(peer); 471 return lock.AddStorePeerOperation(peer);
462 } 472 }
463 else 473 else
464 { 474 {
740 } 750 }
741 751
742 752
743 void LuaScripting::LoadGlobalConfiguration() 753 void LuaScripting::LoadGlobalConfiguration()
744 { 754 {
755 OrthancConfiguration::ReaderLock configLock;
756
745 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); 757 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
746 758
747 std::list<std::string> luaScripts; 759 std::list<std::string> luaScripts;
748 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); 760 configLock.GetConfiguration().GetListOfStringsParameter(luaScripts, "LuaScripts");
749 761
750 LuaScripting::Lock lock(*this); 762 LuaScripting::Lock lock(*this);
751 763
752 for (std::list<std::string>::const_iterator 764 for (std::list<std::string>::const_iterator
753 it = luaScripts.begin(); it != luaScripts.end(); ++it) 765 it = luaScripts.begin(); it != luaScripts.end(); ++it)
754 { 766 {
755 std::string path = Configuration::InterpretStringParameterAsPath(*it); 767 std::string path = configLock.GetConfiguration().InterpretStringParameterAsPath(*it);
756 LOG(INFO) << "Installing the Lua scripts from: " << path; 768 LOG(INFO) << "Installing the Lua scripts from: " << path;
757 std::string script; 769 std::string script;
758 SystemToolbox::ReadFile(script, path); 770 SystemToolbox::ReadFile(script, path);
759 771
760 lock.GetLua().Execute(script); 772 lock.GetLua().Execute(script);