comparison OrthancServer/main.cpp @ 2617:912a767911b0 jobs

back to a single Lua context
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 May 2018 12:45:34 +0200
parents 2f3007bf0708
children 1232922c8793
comparison
equal deleted inserted replaced
2616:2f3007bf0708 2617:912a767911b0
165 165
166 166
167 class OrthancApplicationEntityFilter : public IApplicationEntityFilter 167 class OrthancApplicationEntityFilter : public IApplicationEntityFilter
168 { 168 {
169 private: 169 private:
170 LuaScripting lua_; 170 ServerContext& context_;
171 bool alwaysAllowEcho_; 171 bool alwaysAllowEcho_;
172 bool alwaysAllowStore_; 172 bool alwaysAllowStore_;
173 173
174 public: 174 public:
175 OrthancApplicationEntityFilter(ServerContext& context) : 175 OrthancApplicationEntityFilter(ServerContext& context) :
176 lua_(context) 176 context_(context)
177 { 177 {
178 alwaysAllowEcho_ = Configuration::GetGlobalBoolParameter("DicomAlwaysAllowEcho", true); 178 alwaysAllowEcho_ = Configuration::GetGlobalBoolParameter("DicomAlwaysAllowEcho", true);
179 alwaysAllowStore_ = Configuration::GetGlobalBoolParameter("DicomAlwaysAllowStore", true); 179 alwaysAllowStore_ = Configuration::GetGlobalBoolParameter("DicomAlwaysAllowStore", true);
180
181 LOG(INFO) << "Initializing Lua for OrthancApplicationEntityFilter";
182 lua_.LoadGlobalConfiguration();
183 } 180 }
184 181
185 virtual bool IsAllowedConnection(const std::string& remoteIp, 182 virtual bool IsAllowedConnection(const std::string& remoteIp,
186 const std::string& remoteAet, 183 const std::string& remoteAet,
187 const std::string& calledAet) 184 const std::string& calledAet)
266 } 263 }
267 264
268 { 265 {
269 std::string name = "Is" + configuration; 266 std::string name = "Is" + configuration;
270 267
271 LuaScripting::Lock lock(lua_); 268 LuaScripting::Lock lock(context_.GetLuaScripting());
272 269
273 if (lock.GetLua().IsExistingFunction(name.c_str())) 270 if (lock.GetLua().IsExistingFunction(name.c_str()))
274 { 271 {
275 LuaFunctionCall call(lock.GetLua(), name.c_str()); 272 LuaFunctionCall call(lock.GetLua(), name.c_str());
276 call.PushString(remoteAet); 273 call.PushString(remoteAet);
291 static const char* configuration = "UnknownSopClassAccepted"; 288 static const char* configuration = "UnknownSopClassAccepted";
292 289
293 { 290 {
294 std::string lua = "Is" + std::string(configuration); 291 std::string lua = "Is" + std::string(configuration);
295 292
296 LuaScripting::Lock lock(lua_); 293 LuaScripting::Lock lock(context_.GetLuaScripting());
297 294
298 if (lock.GetLua().IsExistingFunction(lua.c_str())) 295 if (lock.GetLua().IsExistingFunction(lua.c_str()))
299 { 296 {
300 LuaFunctionCall call(lock.GetLua(), lua.c_str()); 297 LuaFunctionCall call(lock.GetLua(), lua.c_str());
301 call.PushString(remoteAet); 298 call.PushString(remoteAet);
311 308
312 309
313 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter 310 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter
314 { 311 {
315 private: 312 private:
316 LuaScripting lua_; 313 ServerContext& context_;
317 OrthancPlugins* plugins_; 314 OrthancPlugins* plugins_;
318 315
319 public: 316 public:
320 MyIncomingHttpRequestFilter(ServerContext& context, 317 MyIncomingHttpRequestFilter(ServerContext& context,
321 OrthancPlugins* plugins) : 318 OrthancPlugins* plugins) :
322 lua_(context), 319 context_(context),
323 plugins_(plugins) 320 plugins_(plugins)
324 { 321 {
325 LOG(INFO) << "Initializing Lua for MyIncomingHttpRequestFilter";
326 lua_.LoadGlobalConfiguration();
327 } 322 }
328 323
329 virtual bool IsAllowed(HttpMethod method, 324 virtual bool IsAllowed(HttpMethod method,
330 const char* uri, 325 const char* uri,
331 const char* ip, 326 const char* ip,
339 return false; 334 return false;
340 } 335 }
341 336
342 static const char* HTTP_FILTER = "IncomingHttpRequestFilter"; 337 static const char* HTTP_FILTER = "IncomingHttpRequestFilter";
343 338
344 LuaScripting::Lock lock(lua_); 339 LuaScripting::Lock lock(context_.GetLuaScripting());
345 340
346 // Test if the instance must be filtered out 341 // Test if the instance must be filtered out
347 if (lock.GetLua().IsExistingFunction(HTTP_FILTER)) 342 if (lock.GetLua().IsExistingFunction(HTTP_FILTER))
348 { 343 {
349 LuaFunctionCall call(lock.GetLua(), HTTP_FILTER); 344 LuaFunctionCall call(lock.GetLua(), HTTP_FILTER);
673 { 668 {
674 context.GetPlugins().SignalOrthancStarted(); 669 context.GetPlugins().SignalOrthancStarted();
675 } 670 }
676 #endif 671 #endif
677 672
678 context.GetLuaEventHandler().Start(); 673 context.GetLuaScripting().Start();
679 context.GetLuaEventHandler().Execute("Initialize"); 674 context.GetLuaScripting().Execute("Initialize");
680 675
681 bool restart; 676 bool restart;
682 677
683 for (;;) 678 for (;;)
684 { 679 {
708 { 703 {
709 break; 704 break;
710 } 705 }
711 } 706 }
712 707
713 context.GetLuaEventHandler().Execute("Finalize"); 708 context.GetLuaScripting().Execute("Finalize");
714 context.GetLuaEventHandler().Stop(); 709 context.GetLuaScripting().Stop();
715 710
716 #if ORTHANC_ENABLE_PLUGINS == 1 711 #if ORTHANC_ENABLE_PLUGINS == 1
717 if (context.HasPlugins()) 712 if (context.HasPlugins())
718 { 713 {
719 context.GetPlugins().SignalOrthancStopped(); 714 context.GetPlugins().SignalOrthancStopped();
998 { 993 {
999 context.GetIndex().SetMaximumStorageSize(0); 994 context.GetIndex().SetMaximumStorageSize(0);
1000 } 995 }
1001 996
1002 LOG(INFO) << "Initializing Lua for the event handler"; 997 LOG(INFO) << "Initializing Lua for the event handler";
1003 context.GetLuaEventHandler().LoadGlobalConfiguration(); 998 context.GetLuaScripting().LoadGlobalConfiguration();
1004 999
1005 #if ORTHANC_ENABLE_PLUGINS == 1 1000 #if ORTHANC_ENABLE_PLUGINS == 1
1006 if (plugins) 1001 if (plugins)
1007 { 1002 {
1008 plugins->SetServerContext(context); 1003 plugins->SetServerContext(context);