Mercurial > hg > orthanc
comparison OrthancServer/main.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 |
---|---|
165 | 165 |
166 | 166 |
167 class OrthancApplicationEntityFilter : public IApplicationEntityFilter | 167 class OrthancApplicationEntityFilter : public IApplicationEntityFilter |
168 { | 168 { |
169 private: | 169 private: |
170 ServerContext& context_; | 170 LuaScripting lua_; |
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 context_(context) | 176 lua_(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(); | |
180 } | 183 } |
181 | 184 |
182 virtual bool IsAllowedConnection(const std::string& remoteIp, | 185 virtual bool IsAllowedConnection(const std::string& remoteIp, |
183 const std::string& remoteAet, | 186 const std::string& remoteAet, |
184 const std::string& calledAet) | 187 const std::string& calledAet) |
261 default: | 264 default: |
262 throw OrthancException(ErrorCode_ParameterOutOfRange); | 265 throw OrthancException(ErrorCode_ParameterOutOfRange); |
263 } | 266 } |
264 | 267 |
265 { | 268 { |
266 std::string lua = "Is" + configuration; | 269 std::string name = "Is" + configuration; |
267 | 270 |
268 LuaScripting::Locker locker(context_.GetLuaScripting()); | 271 LuaScripting::Lock lock(lua_); |
269 | 272 |
270 if (locker.GetLua().IsExistingFunction(lua.c_str())) | 273 if (lock.GetLua().IsExistingFunction(name.c_str())) |
271 { | 274 { |
272 LuaFunctionCall call(locker.GetLua(), lua.c_str()); | 275 LuaFunctionCall call(lock.GetLua(), name.c_str()); |
273 call.PushString(remoteAet); | 276 call.PushString(remoteAet); |
274 call.PushString(remoteIp); | 277 call.PushString(remoteIp); |
275 call.PushString(calledAet); | 278 call.PushString(calledAet); |
276 return call.ExecutePredicate(); | 279 return call.ExecutePredicate(); |
277 } | 280 } |
288 static const char* configuration = "UnknownSopClassAccepted"; | 291 static const char* configuration = "UnknownSopClassAccepted"; |
289 | 292 |
290 { | 293 { |
291 std::string lua = "Is" + std::string(configuration); | 294 std::string lua = "Is" + std::string(configuration); |
292 | 295 |
293 LuaScripting::Locker locker(context_.GetLuaScripting()); | 296 LuaScripting::Lock lock(lua_); |
294 | 297 |
295 if (locker.GetLua().IsExistingFunction(lua.c_str())) | 298 if (lock.GetLua().IsExistingFunction(lua.c_str())) |
296 { | 299 { |
297 LuaFunctionCall call(locker.GetLua(), lua.c_str()); | 300 LuaFunctionCall call(lock.GetLua(), lua.c_str()); |
298 call.PushString(remoteAet); | 301 call.PushString(remoteAet); |
299 call.PushString(remoteIp); | 302 call.PushString(remoteIp); |
300 call.PushString(calledAet); | 303 call.PushString(calledAet); |
301 return call.ExecutePredicate(); | 304 return call.ExecutePredicate(); |
302 } | 305 } |
308 | 311 |
309 | 312 |
310 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter | 313 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter |
311 { | 314 { |
312 private: | 315 private: |
313 ServerContext& context_; | 316 LuaScripting lua_; |
314 OrthancPlugins* plugins_; | 317 OrthancPlugins* plugins_; |
315 | 318 |
316 public: | 319 public: |
317 MyIncomingHttpRequestFilter(ServerContext& context, | 320 MyIncomingHttpRequestFilter(ServerContext& context, |
318 OrthancPlugins* plugins) : | 321 OrthancPlugins* plugins) : |
319 context_(context), | 322 lua_(context), |
320 plugins_(plugins) | 323 plugins_(plugins) |
321 { | 324 { |
325 LOG(INFO) << "Initializing Lua for MyIncomingHttpRequestFilter"; | |
326 lua_.LoadGlobalConfiguration(); | |
322 } | 327 } |
323 | 328 |
324 virtual bool IsAllowed(HttpMethod method, | 329 virtual bool IsAllowed(HttpMethod method, |
325 const char* uri, | 330 const char* uri, |
326 const char* ip, | 331 const char* ip, |
327 const char* username, | 332 const char* username, |
328 const IHttpHandler::Arguments& httpHeaders, | 333 const IHttpHandler::Arguments& httpHeaders, |
329 const IHttpHandler::GetArguments& getArguments) const | 334 const IHttpHandler::GetArguments& getArguments) |
330 { | 335 { |
331 if (plugins_ != NULL && | 336 if (plugins_ != NULL && |
332 !plugins_->IsAllowed(method, uri, ip, username, httpHeaders, getArguments)) | 337 !plugins_->IsAllowed(method, uri, ip, username, httpHeaders, getArguments)) |
333 { | 338 { |
334 return false; | 339 return false; |
335 } | 340 } |
336 | 341 |
337 static const char* HTTP_FILTER = "IncomingHttpRequestFilter"; | 342 static const char* HTTP_FILTER = "IncomingHttpRequestFilter"; |
338 | 343 |
339 LuaScripting::Locker locker(context_.GetLuaScripting()); | 344 LuaScripting::Lock lock(lua_); |
340 | 345 |
341 // Test if the instance must be filtered out | 346 // Test if the instance must be filtered out |
342 if (locker.GetLua().IsExistingFunction(HTTP_FILTER)) | 347 if (lock.GetLua().IsExistingFunction(HTTP_FILTER)) |
343 { | 348 { |
344 LuaFunctionCall call(locker.GetLua(), HTTP_FILTER); | 349 LuaFunctionCall call(lock.GetLua(), HTTP_FILTER); |
345 | 350 |
346 switch (method) | 351 switch (method) |
347 { | 352 { |
348 case HttpMethod_Get: | 353 case HttpMethod_Get: |
349 call.PushString("GET"); | 354 call.PushString("GET"); |
638 std::cout << std::endl; | 643 std::cout << std::endl; |
639 } | 644 } |
640 | 645 |
641 | 646 |
642 | 647 |
643 static void LoadLuaScripts(ServerContext& context) | |
644 { | |
645 std::list<std::string> luaScripts; | |
646 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); | |
647 for (std::list<std::string>::const_iterator | |
648 it = luaScripts.begin(); it != luaScripts.end(); ++it) | |
649 { | |
650 std::string path = Configuration::InterpretStringParameterAsPath(*it); | |
651 LOG(WARNING) << "Installing the Lua scripts from: " << path; | |
652 std::string script; | |
653 SystemToolbox::ReadFile(script, path); | |
654 | |
655 LuaScripting::Locker locker(context.GetLuaScripting()); | |
656 locker.GetLua().Execute(script); | |
657 } | |
658 } | |
659 | |
660 | |
661 | |
662 #if ORTHANC_ENABLE_PLUGINS == 1 | 648 #if ORTHANC_ENABLE_PLUGINS == 1 |
663 static void LoadPlugins(OrthancPlugins& plugins) | 649 static void LoadPlugins(OrthancPlugins& plugins) |
664 { | 650 { |
665 std::list<std::string> path; | 651 std::list<std::string> path; |
666 Configuration::GetGlobalListOfStringsParameter(path, "Plugins"); | 652 Configuration::GetGlobalListOfStringsParameter(path, "Plugins"); |
687 { | 673 { |
688 context.GetPlugins().SignalOrthancStarted(); | 674 context.GetPlugins().SignalOrthancStarted(); |
689 } | 675 } |
690 #endif | 676 #endif |
691 | 677 |
692 context.GetLuaScripting().Execute("Initialize"); | 678 context.GetLuaEventHandler().Start(); |
679 context.GetLuaEventHandler().Execute("Initialize"); | |
693 | 680 |
694 bool restart; | 681 bool restart; |
695 | 682 |
696 for (;;) | 683 for (;;) |
697 { | 684 { |
721 { | 708 { |
722 break; | 709 break; |
723 } | 710 } |
724 } | 711 } |
725 | 712 |
726 context.GetLuaScripting().Execute("Finalize"); | 713 context.GetLuaEventHandler().Execute("Finalize"); |
714 context.GetLuaEventHandler().Stop(); | |
727 | 715 |
728 #if ORTHANC_ENABLE_PLUGINS == 1 | 716 #if ORTHANC_ENABLE_PLUGINS == 1 |
729 if (context.HasPlugins()) | 717 if (context.HasPlugins()) |
730 { | 718 { |
731 context.GetPlugins().SignalOrthancStopped(); | 719 context.GetPlugins().SignalOrthancStopped(); |
1009 catch (...) | 997 catch (...) |
1010 { | 998 { |
1011 context.GetIndex().SetMaximumStorageSize(0); | 999 context.GetIndex().SetMaximumStorageSize(0); |
1012 } | 1000 } |
1013 | 1001 |
1014 LoadLuaScripts(context); | 1002 LOG(INFO) << "Initializing Lua for the event handler"; |
1003 context.GetLuaEventHandler().LoadGlobalConfiguration(); | |
1015 | 1004 |
1016 #if ORTHANC_ENABLE_PLUGINS == 1 | 1005 #if ORTHANC_ENABLE_PLUGINS == 1 |
1017 if (plugins) | 1006 if (plugins) |
1018 { | 1007 { |
1019 plugins->SetServerContext(context); | 1008 plugins->SetServerContext(context); |