Mercurial > hg > orthanc
comparison OrthancServer/QueryRetrieveHandler.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 |
---|---|
33 | 33 |
34 #include "PrecompiledHeadersServer.h" | 34 #include "PrecompiledHeadersServer.h" |
35 #include "QueryRetrieveHandler.h" | 35 #include "QueryRetrieveHandler.h" |
36 | 36 |
37 #include "OrthancInitialization.h" | 37 #include "OrthancInitialization.h" |
38 | |
38 #include "../Core/DicomParsing/FromDcmtkBridge.h" | 39 #include "../Core/DicomParsing/FromDcmtkBridge.h" |
40 #include "../Core/Logging.h" | |
39 | 41 |
40 | 42 |
41 namespace Orthanc | 43 namespace Orthanc |
42 { | 44 { |
43 static void FixQuery(DicomMap& query, | 45 static LuaScripting& GetLuaScripting(ServerContext& context) |
44 ServerContext& context, | 46 { |
45 const std::string& modality) | 47 // Returns a singleton Lua context |
48 static boost::mutex mutex_; | |
49 static std::auto_ptr<LuaScripting> lua_; | |
50 | |
51 boost::mutex::scoped_lock lock(mutex_); | |
52 | |
53 if (lua_.get() == NULL) | |
54 { | |
55 LOG(INFO) << "Initializing Lua for QueryRetrieveHandler"; | |
56 lua_.reset(new LuaScripting(context)); | |
57 lua_->LoadGlobalConfiguration(); | |
58 } | |
59 | |
60 return *lua_; | |
61 } | |
62 | |
63 | |
64 static void FixQueryLua(DicomMap& query, | |
65 ServerContext& context, | |
66 const std::string& modality) | |
46 { | 67 { |
47 static const char* LUA_CALLBACK = "OutgoingFindRequestFilter"; | 68 static const char* LUA_CALLBACK = "OutgoingFindRequestFilter"; |
48 | 69 |
49 LuaScripting::Locker locker(context.GetLuaScripting()); | 70 LuaScripting::Lock lock(GetLuaScripting(context)); |
50 if (locker.GetLua().IsExistingFunction(LUA_CALLBACK)) | 71 |
51 { | 72 if (lock.GetLua().IsExistingFunction(LUA_CALLBACK)) |
52 LuaFunctionCall call(locker.GetLua(), LUA_CALLBACK); | 73 { |
74 LuaFunctionCall call(lock.GetLua(), LUA_CALLBACK); | |
53 call.PushDicom(query); | 75 call.PushDicom(query); |
54 call.PushJson(modality); | 76 call.PushJson(modality); |
55 FromDcmtkBridge::ExecuteToDicom(query, call); | 77 FromDcmtkBridge::ExecuteToDicom(query, call); |
56 } | 78 } |
57 } | 79 } |
58 | 80 |
59 | 81 |
60 static void FixQuery(DicomMap& query, | 82 static void FixQueryBuiltin(DicomMap& query, |
61 ModalityManufacturer manufacturer) | 83 ModalityManufacturer manufacturer) |
62 { | 84 { |
63 /** | 85 /** |
64 * Introduce patches for specific manufacturers below. | 86 * Introduce patches for specific manufacturers below. |
65 **/ | 87 **/ |
66 | 88 |
97 if (!done_) | 119 if (!done_) |
98 { | 120 { |
99 // Firstly, fix the content of the query for specific manufacturers | 121 // Firstly, fix the content of the query for specific manufacturers |
100 DicomMap fixed; | 122 DicomMap fixed; |
101 fixed.Assign(query_); | 123 fixed.Assign(query_); |
102 FixQuery(fixed, modality_.GetManufacturer()); | 124 FixQueryBuiltin(fixed, modality_.GetManufacturer()); |
103 | 125 |
104 // Secondly, possibly fix the query with the user-provider Lua callback | 126 // Secondly, possibly fix the query with the user-provider Lua callback |
105 FixQuery(fixed, context_, modality_.GetApplicationEntityTitle()); | 127 FixQueryLua(fixed, context_, modality_.GetApplicationEntityTitle()); |
106 | 128 |
107 GetConnection().Find(answers_, level_, fixed); | 129 GetConnection().Find(answers_, level_, fixed); |
108 | 130 |
109 done_ = true; | 131 done_ = true; |
110 } | 132 } |