comparison OrthancServer/LuaScripting.h @ 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 f7a84b551ee4
children 912a767911b0
comparison
equal deleted inserted replaced
2614:3200223f9ade 2616:2f3007bf0708
35 35
36 #include "IServerListener.h" 36 #include "IServerListener.h"
37 37
38 #include "ServerJobs/LuaJobManager.h" 38 #include "ServerJobs/LuaJobManager.h"
39 39
40 #include "../Core/MultiThreading/SharedMessageQueue.h"
40 #include "../Core/Lua/LuaContext.h" 41 #include "../Core/Lua/LuaContext.h"
41 42
42 namespace Orthanc 43 namespace Orthanc
43 { 44 {
44 class ServerContext; 45 class ServerContext;
45 46
46 class LuaScripting : public IServerListener 47 class LuaScripting : public IServerListener
47 { 48 {
48 private: 49 private:
50 class ExecuteEvent;
51 class IEvent;
52 class OnStoredInstanceEvent;
53 class StableResourceEvent;
54
49 static ServerContext* GetServerContext(lua_State *state); 55 static ServerContext* GetServerContext(lua_State *state);
50 56
51 static int RestApiPostOrPut(lua_State *state, 57 static int RestApiPostOrPut(lua_State *state,
52 bool isPost); 58 bool isPost);
53 static int RestApiGet(lua_State *state); 59 static int RestApiGet(lua_State *state);
54 static int RestApiPost(lua_State *state); 60 static int RestApiPost(lua_State *state);
55 static int RestApiPut(lua_State *state); 61 static int RestApiPut(lua_State *state);
56 static int RestApiDelete(lua_State *state); 62 static int RestApiDelete(lua_State *state);
57 static int GetOrthancConfiguration(lua_State *state); 63 static int GetOrthancConfiguration(lua_State *state);
58 64
59 void ApplyOnStoredInstance(const std::string& instanceId,
60 const Json::Value& simplifiedDicom,
61 const Json::Value& metadata,
62 const DicomInstanceToStore& instance);
63
64 size_t ParseOperation(LuaJobManager::Lock& lock, 65 size_t ParseOperation(LuaJobManager::Lock& lock,
65 const std::string& operation, 66 const std::string& operation,
66 const Json::Value& parameters); 67 const Json::Value& parameters);
67 68
68 void InitializeJob(); 69 void InitializeJob();
69 70
70 void SubmitJob(const std::string& description); 71 void SubmitJob();
71 72
72 void OnStableResource(const ServerIndexChange& change); 73 boost::mutex mutex_;
74 LuaContext lua_;
75 ServerContext& context_;
76 LuaJobManager jobManager_;
77 bool continue_;
78 boost::thread eventThread_;
79 SharedMessageQueue pendingEvents_;
73 80
74 boost::recursive_mutex mutex_; 81 static void EventThread(LuaScripting* that);
75 LuaContext lua_;
76 ServerContext& context_;
77 LuaJobManager jobManager_;
78 82
79 public: 83 public:
80 class Locker : public boost::noncopyable 84 class Lock : public boost::noncopyable
81 { 85 {
82 private: 86 private:
83 LuaScripting& that_; 87 LuaScripting& that_;
84 boost::recursive_mutex::scoped_lock lock_; 88 boost::mutex::scoped_lock lock_;
85 89
86 public: 90 public:
87 Locker(LuaScripting& that) : 91 Lock(LuaScripting& that) :
88 that_(that), 92 that_(that),
89 lock_(that.mutex_) 93 lock_(that.mutex_)
90 { 94 {
91 } 95 }
92 96
95 return that_.lua_; 99 return that_.lua_;
96 } 100 }
97 }; 101 };
98 102
99 LuaScripting(ServerContext& context); 103 LuaScripting(ServerContext& context);
104
105 ~LuaScripting();
106
107 void Start();
108
109 void Stop();
100 110
101 virtual void SignalStoredInstance(const std::string& publicId, 111 virtual void SignalStoredInstance(const std::string& publicId,
102 DicomInstanceToStore& instance, 112 DicomInstanceToStore& instance,
103 const Json::Value& simplifiedTags); 113 const Json::Value& simplifiedTags);
104 114
106 116
107 virtual bool FilterIncomingInstance(const DicomInstanceToStore& instance, 117 virtual bool FilterIncomingInstance(const DicomInstanceToStore& instance,
108 const Json::Value& simplifiedTags); 118 const Json::Value& simplifiedTags);
109 119
110 void Execute(const std::string& command); 120 void Execute(const std::string& command);
121
122 void LoadGlobalConfiguration();
111 }; 123 };
112 } 124 }