comparison OrthancServer/OrthancFindRequestHandler.cpp @ 2616:2f3007bf0708 jobs

event queues in Lua, serialization of sequence of operations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 May 2018 12:25:37 +0200
parents 6f9225dcfc32
children 912a767911b0
comparison
equal deleted inserted replaced
2614:3200223f9ade 2616:2f3007bf0708
45 #include <boost/regex.hpp> 45 #include <boost/regex.hpp>
46 46
47 47
48 namespace Orthanc 48 namespace Orthanc
49 { 49 {
50 static LuaScripting& GetLuaScripting(ServerContext& context)
51 {
52 // Returns a singleton Lua context
53 static boost::mutex mutex_;
54 static std::auto_ptr<LuaScripting> lua_;
55
56 boost::mutex::scoped_lock lock(mutex_);
57
58 if (lua_.get() == NULL)
59 {
60 LOG(INFO) << "Initializing Lua for OrthancFindRequestHandler";
61 lua_.reset(new LuaScripting(context));
62 lua_->LoadGlobalConfiguration();
63 }
64
65 return *lua_;
66 }
67
68
50 static void GetChildren(std::list<std::string>& target, 69 static void GetChildren(std::list<std::string>& target,
51 ServerIndex& index, 70 ServerIndex& index,
52 const std::list<std::string>& source) 71 const std::list<std::string>& source)
53 { 72 {
54 target.clear(); 73 target.clear();
483 const std::string& remoteIp, 502 const std::string& remoteIp,
484 const std::string& remoteAet, 503 const std::string& remoteAet,
485 const std::string& calledAet) 504 const std::string& calledAet)
486 { 505 {
487 static const char* LUA_CALLBACK = "IncomingFindRequestFilter"; 506 static const char* LUA_CALLBACK = "IncomingFindRequestFilter";
488 507
489 LuaScripting::Locker locker(context_.GetLuaScripting()); 508 LuaScripting::Lock lock(GetLuaScripting(context_));
490 if (!locker.GetLua().IsExistingFunction(LUA_CALLBACK)) 509 if (!lock.GetLua().IsExistingFunction(LUA_CALLBACK))
491 { 510 {
492 return false; 511 return false;
493 } 512 }
494 else 513 else
495 { 514 {
496 Json::Value origin = Json::objectValue; 515 Json::Value origin = Json::objectValue;
497 origin["RemoteIp"] = remoteIp; 516 origin["RemoteIp"] = remoteIp;
498 origin["RemoteAet"] = remoteAet; 517 origin["RemoteAet"] = remoteAet;
499 origin["CalledAet"] = calledAet; 518 origin["CalledAet"] = calledAet;
500 519
501 LuaFunctionCall call(locker.GetLua(), LUA_CALLBACK); 520 LuaFunctionCall call(lock.GetLua(), LUA_CALLBACK);
502 call.PushDicom(source); 521 call.PushDicom(source);
503 call.PushJson(origin); 522 call.PushJson(origin);
504 FromDcmtkBridge::ExecuteToDicom(target, call); 523 FromDcmtkBridge::ExecuteToDicom(target, call);
505 524
506 return true; 525 return true;
507 } 526 }
527 }
528
529
530 OrthancFindRequestHandler::OrthancFindRequestHandler(ServerContext& context) :
531 context_(context),
532 maxResults_(0),
533 maxInstances_(0)
534 {
508 } 535 }
509 536
510 537
511 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, 538 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers,
512 const DicomMap& input, 539 const DicomMap& input,