annotate OrthancServer/Sources/LuaScripting.h @ 5501:8b96d1d17831

fix version test
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Jan 2024 16:50:21 +0100
parents 48b8dae6dc77
children f7adfb22e20e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5410
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5410
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
25 #include "DicomInstanceToStore.h"
2894
a27b0e9a3fd9 refactoring DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2738
diff changeset
26 #include "ServerIndexChange.h"
5410
16cbfefa15e9 Solved a deadlock related to the Job Engine events and plugins
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
27 #include "JobEvent.h"
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
28 #include "ServerJobs/LuaJobManager.h"
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
29
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
30 #include "../../OrthancFramework/Sources/MultiThreading/SharedMessageQueue.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
31 #include "../../OrthancFramework/Sources/Lua/LuaContext.h"
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 class ServerContext;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
37 class LuaScripting : public boost::noncopyable
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 private:
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
40 enum State
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
41 {
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
42 State_Setup,
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
43 State_Running,
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
44 State_Done
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
45 };
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
46
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
47 class ExecuteEvent;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
48 class IEvent;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
49 class OnStoredInstanceEvent;
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
50 class StableResourceEvent;
5410
16cbfefa15e9 Solved a deadlock related to the Job Engine events and plugins
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
51 class LuaJobEvent;
3676
231b46ce1984 Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
52 class DeleteEvent;
231b46ce1984 Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
53 class UpdateEvent;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
54
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
55 static ServerContext* GetServerContext(lua_State *state);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
56
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
57 static int RestApiPostOrPut(lua_State *state,
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
58 bool isPost);
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
59 static int RestApiGet(lua_State *state);
1447
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
60 static int RestApiPost(lua_State *state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
61 static int RestApiPut(lua_State *state);
5ba7471780ae refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
62 static int RestApiDelete(lua_State *state);
1587
d7e569640d09 New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1574
diff changeset
63 static int GetOrthancConfiguration(lua_State *state);
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
64
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
65 size_t ParseOperation(LuaJobManager::Lock& lock,
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
66 const std::string& operation,
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
67 const Json::Value& parameters);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
69 void InitializeJob();
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
70
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
71 void SubmitJob();
1435
6406f5493d92 refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1433
diff changeset
72
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
73 boost::recursive_mutex mutex_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
74 LuaContext lua_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
75 ServerContext& context_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
76 LuaJobManager jobManager_;
2651
1da5a052c777 testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2618
diff changeset
77 State state_;
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
78 boost::thread eventThread_;
5017
0d61efc6256c Added Lua OnHeartBeat()
Alain Mazy <am@osimis.io>
parents: 4921
diff changeset
79 boost::thread heartBeatThread_;
0d61efc6256c Added Lua OnHeartBeat()
Alain Mazy <am@osimis.io>
parents: 4921
diff changeset
80 unsigned int heartBeatPeriod_;
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
81 SharedMessageQueue pendingEvents_;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
82
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
83 static void EventThread(LuaScripting* that);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5017
0d61efc6256c Added Lua OnHeartBeat()
Alain Mazy <am@osimis.io>
parents: 4921
diff changeset
85 static void HeartBeatThread(LuaScripting* that);
0d61efc6256c Added Lua OnHeartBeat()
Alain Mazy <am@osimis.io>
parents: 4921
diff changeset
86
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
87 void LoadGlobalConfiguration();
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
88
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 public:
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
90 class Lock : public boost::noncopyable
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 private:
2618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
93 LuaScripting& that_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2617
diff changeset
94 boost::recursive_mutex::scoped_lock lock_;
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 public:
2617
912a767911b0 back to a single Lua context
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
97 explicit Lock(LuaScripting& that) :
1456
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
98 that_(that),
68827c07e683 fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
99 lock_(that.mutex_)
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 LuaContext& GetLua()
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 return that_.lua_;
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 };
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
4204
318c16cfccab cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
109 explicit LuaScripting(ServerContext& context);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
110
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
111 ~LuaScripting();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
112
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
113 void Start();
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
114
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
115 void Stop();
1437
02f5a3f5c0a0 access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1435
diff changeset
116
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
117 void SignalStoredInstance(const std::string& publicId,
3916
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
118 const DicomInstanceToStore& instance,
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
119 const Json::Value& simplifiedTags);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
121 void SignalChange(const ServerIndexChange& change);
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
2738
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
123 bool FilterIncomingInstance(const DicomInstanceToStore& instance,
3a55b77339ff fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2675
diff changeset
124 const Json::Value& simplifiedTags);
1455
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
125
4921
309fb4f02704 fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
126 bool FilterIncomingCStoreInstance(uint16_t& dimseStatus,
309fb4f02704 fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
127 const DicomInstanceToStore& instance,
309fb4f02704 fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
128 const Json::Value& simplified);
4796
94616af363ec added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents: 4437
diff changeset
129
1455
a68545767975 Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1447
diff changeset
130 void Execute(const std::string& command);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
131
5410
16cbfefa15e9 Solved a deadlock related to the Job Engine events and plugins
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
132 void SignalJobEvent(const JobEvent& event);
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3676
diff changeset
133
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3676
diff changeset
134 TimeoutDicomConnectionManager& GetDicomConnectionManager()
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3676
diff changeset
135 {
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3676
diff changeset
136 return jobManager_.GetDicomConnectionManager();
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3676
diff changeset
137 }
1433
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 };
461e7554bff7 refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }