Mercurial > hg > orthanc
annotate OrthancServer/Sources/LuaScripting.cpp @ 4961:1b76853e1797 more-tags
DbOptimizer plugin
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 23 Mar 2022 11:56:28 +0100 |
parents | 309fb4f02704 |
children | 0d61efc6256c |
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 | 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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 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 #include "PrecompiledHeadersServer.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "LuaScripting.h" |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
26 #include "OrthancConfiguration.h" |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
27 #include "OrthancRestApi/OrthancRestApi.h" |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "ServerContext.h" |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
29 |
4554 | 30 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" |
4045 | 31 #include "../../OrthancFramework/Sources/HttpServer/StringHttpOutput.h" |
32 #include "../../OrthancFramework/Sources/Logging.h" | |
33 #include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h" | |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
4032
058b5ade8acd
renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4031
diff
changeset
|
35 #include <OrthancServerResources.h> |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 namespace Orthanc |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
40 class LuaScripting::IEvent : public IDynamicObject |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
41 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
42 public: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
43 virtual void Apply(LuaScripting& lock) = 0; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
44 }; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
45 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
46 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
47 class LuaScripting::OnStoredInstanceEvent : public LuaScripting::IEvent |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
48 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
49 private: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
50 std::string instanceId_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
51 Json::Value simplifiedTags_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
52 Json::Value metadata_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
53 Json::Value origin_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
54 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
55 public: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
56 OnStoredInstanceEvent(const std::string& instanceId, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
57 const Json::Value& simplifiedTags, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
58 const Json::Value& metadata, |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
59 const DicomInstanceToStore& instance) : |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
60 instanceId_(instanceId), |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
61 simplifiedTags_(simplifiedTags), |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
62 metadata_(metadata) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
63 { |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2638
diff
changeset
|
64 instance.GetOrigin().Format(origin_); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
65 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
66 |
4204 | 67 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
68 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
69 static const char* NAME = "OnStoredInstance"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
70 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
71 LuaScripting::Lock lock(that); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
72 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
73 if (lock.GetLua().IsExistingFunction(NAME)) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
74 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
75 that.InitializeJob(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
76 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
77 LuaFunctionCall call(lock.GetLua(), NAME); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
78 call.PushString(instanceId_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
79 call.PushJson(simplifiedTags_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
80 call.PushJson(metadata_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
81 call.PushJson(origin_); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
82 call.Execute(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
83 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
84 that.SubmitJob(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
85 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
86 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
87 }; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
88 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
89 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
90 class LuaScripting::ExecuteEvent : public LuaScripting::IEvent |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
91 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
92 private: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
93 std::string command_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
94 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
95 public: |
4204 | 96 explicit ExecuteEvent(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
|
97 command_(command) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
98 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
99 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
100 |
4204 | 101 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
102 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
103 LuaScripting::Lock lock(that); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
104 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
105 if (lock.GetLua().IsExistingFunction(command_.c_str())) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
106 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
107 LuaFunctionCall call(lock.GetLua(), command_.c_str()); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
108 call.Execute(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
109 } |
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 }; |
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 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
114 class LuaScripting::StableResourceEvent : public LuaScripting::IEvent |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
115 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
116 private: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
117 ServerIndexChange change_; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
118 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
119 class GetInfoOperations : public ServerIndex::IReadOnlyOperations |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
120 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
121 private: |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
122 const ServerIndexChange& change_; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
123 bool ok_; |
4554 | 124 DicomMap tags_; |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
125 std::map<MetadataType, std::string> metadata_; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
126 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
127 public: |
4555 | 128 explicit GetInfoOperations(const ServerIndexChange& change) : |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
129 change_(change), |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
130 ok_(false) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
131 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
132 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
133 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
134 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
135 { |
4554 | 136 int64_t internalId; |
137 ResourceType level; | |
138 if (transaction.LookupResource(internalId, level, change_.GetPublicId()) && | |
139 level == change_.GetResourceType()) | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
140 { |
4554 | 141 transaction.GetMainDicomTags(tags_, internalId); |
142 transaction.GetAllMetadata(metadata_, internalId); | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
143 ok_ = true; |
4554 | 144 } |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
145 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
146 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
147 void CallLua(LuaScripting& that, |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
148 const char* name) const |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
149 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
150 if (ok_) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
151 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
152 Json::Value formattedMetadata = Json::objectValue; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
153 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
154 for (std::map<MetadataType, std::string>::const_iterator |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
155 it = metadata_.begin(); it != metadata_.end(); ++it) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
156 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
157 std::string key = EnumerationToString(it->first); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
158 formattedMetadata[key] = it->second; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
159 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
160 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
161 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
162 LuaScripting::Lock lock(that); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
163 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
164 if (lock.GetLua().IsExistingFunction(name)) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
165 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
166 that.InitializeJob(); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
167 |
4554 | 168 Json::Value json = Json::objectValue; |
169 | |
170 if (change_.GetResourceType() == ResourceType_Study) | |
171 { | |
172 DicomMap t; | |
173 tags_.ExtractStudyInformation(t); // Discard patient-related tags | |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4606
diff
changeset
|
174 FromDcmtkBridge::ToJson(json, t, DicomToJsonFormat_Human); |
4554 | 175 } |
176 else | |
177 { | |
4697
569d9ef165b1
Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4606
diff
changeset
|
178 FromDcmtkBridge::ToJson(json, tags_, DicomToJsonFormat_Human); |
4554 | 179 } |
180 | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
181 LuaFunctionCall call(lock.GetLua(), name); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
182 call.PushString(change_.GetPublicId()); |
4554 | 183 call.PushJson(json); |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
184 call.PushJson(formattedMetadata); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
185 call.Execute(); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
186 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
187 that.SubmitJob(); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
188 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
189 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
190 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
191 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
192 }; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
193 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
194 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
195 public: |
4204 | 196 explicit StableResourceEvent(const ServerIndexChange& change) : |
197 change_(change) | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
198 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
199 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
200 |
4204 | 201 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
202 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
203 const char* name; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
204 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
205 switch (change_.GetChangeType()) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
206 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
207 case ChangeType_StablePatient: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
208 name = "OnStablePatient"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
209 break; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
210 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
211 case ChangeType_StableStudy: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
212 name = "OnStableStudy"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
213 break; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
214 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
215 case ChangeType_StableSeries: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
216 name = "OnStableSeries"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
217 break; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
218 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
219 default: |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
220 throw OrthancException(ErrorCode_InternalError); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
221 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
222 |
2638
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
223 { |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
224 // Avoid unnecessary calls to the database if there's no Lua callback |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
225 LuaScripting::Lock lock(that); |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
226 |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
227 if (!lock.GetLua().IsExistingFunction(name)) |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
228 { |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
229 return; |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
230 } |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
231 } |
25ae209dcea9
Avoid unnecessary calls to the database if there is no Lua callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
232 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
233 GetInfoOperations operations(change_); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
234 that.context_.GetIndex().Apply(operations); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
235 operations.CallLua(that, name); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
236 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
237 }; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
238 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
239 |
2675
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
240 class LuaScripting::JobEvent : public LuaScripting::IEvent |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
241 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
242 public: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
243 enum Type |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
244 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
245 Type_Failure, |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
246 Type_Submitted, |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
247 Type_Success |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
248 }; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
249 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
250 private: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
251 Type type_; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
252 std::string jobId_; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
253 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
254 public: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
255 JobEvent(Type type, |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
256 const std::string& jobId) : |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
257 type_(type), |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
258 jobId_(jobId) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
259 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
260 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
261 |
4204 | 262 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
2675
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
263 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
264 std::string functionName; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
265 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
266 switch (type_) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
267 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
268 case Type_Failure: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
269 functionName = "OnJobFailure"; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
270 break; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
271 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
272 case Type_Submitted: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
273 functionName = "OnJobSubmitted"; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
274 break; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
275 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
276 case Type_Success: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
277 functionName = "OnJobSuccess"; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
278 break; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
279 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
280 default: |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
281 throw OrthancException(ErrorCode_InternalError); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
282 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
283 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
284 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
285 LuaScripting::Lock lock(that); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
286 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
287 if (lock.GetLua().IsExistingFunction(functionName.c_str())) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
288 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
289 LuaFunctionCall call(lock.GetLua(), functionName.c_str()); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
290 call.PushString(jobId_); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
291 call.Execute(); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
292 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
293 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
294 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
295 }; |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
296 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
297 |
3676
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
298 class LuaScripting::DeleteEvent : public LuaScripting::IEvent |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
299 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
300 private: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
301 ResourceType level_; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
302 std::string publicId_; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
303 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
304 public: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
305 DeleteEvent(ResourceType level, |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
306 const std::string& publicId) : |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
307 level_(level), |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
308 publicId_(publicId) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
309 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
310 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
311 |
4204 | 312 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
3676
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
313 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
314 std::string functionName; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
315 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
316 switch (level_) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
317 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
318 case ResourceType_Patient: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
319 functionName = "OnDeletedPatient"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
320 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
321 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
322 case ResourceType_Study: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
323 functionName = "OnDeletedStudy"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
324 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
325 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
326 case ResourceType_Series: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
327 functionName = "OnDeletedSeries"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
328 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
329 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
330 case ResourceType_Instance: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
331 functionName = "OnDeletedInstance"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
332 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
333 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
334 default: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
335 throw OrthancException(ErrorCode_InternalError); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
336 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
337 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
338 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
339 LuaScripting::Lock lock(that); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
340 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
341 if (lock.GetLua().IsExistingFunction(functionName.c_str())) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
342 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
343 LuaFunctionCall call(lock.GetLua(), functionName.c_str()); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
344 call.PushString(publicId_); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
345 call.Execute(); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
346 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
347 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
348 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
349 }; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
350 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
351 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
352 class LuaScripting::UpdateEvent : public LuaScripting::IEvent |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
353 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
354 private: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
355 ResourceType level_; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
356 std::string publicId_; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
357 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
358 public: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
359 UpdateEvent(ResourceType level, |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
360 const std::string& publicId) : |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
361 level_(level), |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
362 publicId_(publicId) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
363 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
364 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
365 |
4204 | 366 virtual void Apply(LuaScripting& that) ORTHANC_OVERRIDE |
3676
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
367 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
368 std::string functionName; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
369 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
370 switch (level_) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
371 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
372 case ResourceType_Patient: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
373 functionName = "OnUpdatedPatient"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
374 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
375 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
376 case ResourceType_Study: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
377 functionName = "OnUpdatedStudy"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
378 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
379 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
380 case ResourceType_Series: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
381 functionName = "OnUpdatedSeries"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
382 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
383 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
384 case ResourceType_Instance: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
385 functionName = "OnUpdatedInstance"; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
386 break; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
387 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
388 default: |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
389 throw OrthancException(ErrorCode_InternalError); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
390 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
391 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
392 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
393 LuaScripting::Lock lock(that); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
394 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
395 if (lock.GetLua().IsExistingFunction(functionName.c_str())) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
396 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
397 LuaFunctionCall call(lock.GetLua(), functionName.c_str()); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
398 call.PushString(publicId_); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
399 call.Execute(); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
400 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
401 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
402 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
403 }; |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
404 |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
405 |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
406 ServerContext* LuaScripting::GetServerContext(lua_State *state) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
407 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
408 const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext"); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
409 return const_cast<ServerContext*>(reinterpret_cast<const ServerContext*>(value)); |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
410 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
411 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
412 |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
413 // Syntax in Lua: RestApiGet(uri, builtin) |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
414 int LuaScripting::RestApiGet(lua_State *state) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
415 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
416 ServerContext* serverContext = GetServerContext(state); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
417 if (serverContext == NULL) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
418 { |
1440 | 419 LOG(ERROR) << "Lua: The Orthanc API is unavailable"; |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
420 lua_pushnil(state); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
421 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
422 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
423 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
424 // Check the types of the arguments |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
425 int nArgs = lua_gettop(state); |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
426 if (nArgs < 1 || nArgs > 3 || |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
427 !lua_isstring(state, 1) || // URI |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
428 (nArgs >= 2 && !lua_isboolean(state, 2))) // Restrict to built-in API? |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
429 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
430 LOG(ERROR) << "Lua: Bad parameters to RestApiGet()"; |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
431 lua_pushnil(state); |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
432 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
433 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
434 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
435 const char* uri = lua_tostring(state, 1); |
1545 | 436 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
437 |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
438 std::map<std::string, std::string> headers; |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
439 LuaContext::GetDictionaryArgument(headers, state, 3, true /* HTTP header key to lower case */); |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
440 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
441 try |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
442 { |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
443 std::string result; |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
444 if (IHttpHandler::SimpleGet(result, NULL, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
445 RequestOrigin_Lua, uri, headers) == HttpStatus_200_Ok) |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
446 { |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
447 lua_pushlstring(state, result.c_str(), result.size()); |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
448 return 1; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
449 } |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
450 } |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
451 catch (OrthancException& e) |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
452 { |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
453 LOG(ERROR) << "Lua: " << e.What(); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
454 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
455 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
456 LOG(ERROR) << "Lua: Error in RestApiGet() for URI: " << uri; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
457 lua_pushnil(state); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
458 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
459 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
460 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
461 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
462 int LuaScripting::RestApiPostOrPut(lua_State *state, |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
463 bool isPost) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
464 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
465 ServerContext* serverContext = GetServerContext(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
466 if (serverContext == NULL) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
467 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
468 LOG(ERROR) << "Lua: The Orthanc API is unavailable"; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
469 lua_pushnil(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
470 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
471 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
472 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
473 // Check the types of the arguments |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
474 int nArgs = lua_gettop(state); |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
475 if (nArgs < 2 || nArgs > 4 || |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
476 !lua_isstring(state, 1) || // URI |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
477 !lua_isstring(state, 2) || // Body |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
478 (nArgs >= 3 && !lua_isboolean(state, 3))) // Restrict to built-in API? |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
479 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
480 LOG(ERROR) << "Lua: Bad parameters to " << (isPost ? "RestApiPost()" : "RestApiPut()"); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
481 lua_pushnil(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
482 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
483 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
484 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
485 const char* uri = lua_tostring(state, 1); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
486 size_t bodySize = 0; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
487 const char* bodyData = lua_tolstring(state, 2, &bodySize); |
1545 | 488 bool builtin = (nArgs == 3 ? lua_toboolean(state, 3) != 0 : false); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
489 |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
490 std::map<std::string, std::string> headers; |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
491 LuaContext::GetDictionaryArgument(headers, state, 4, true /* HTTP header key to lower case */); |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
492 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
493 try |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
494 { |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
495 std::string result; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
496 if (isPost ? |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
497 IHttpHandler::SimplePost(result, NULL, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
498 serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
499 RequestOrigin_Lua, uri, bodyData, bodySize, headers) == HttpStatus_200_Ok : |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
500 IHttpHandler::SimplePut(result, NULL, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
501 serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
502 RequestOrigin_Lua, uri, bodyData, bodySize, headers) == HttpStatus_200_Ok) |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
503 { |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
504 lua_pushlstring(state, result.c_str(), result.size()); |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
505 return 1; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
506 } |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
507 } |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
508 catch (OrthancException& e) |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
509 { |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
510 LOG(ERROR) << "Lua: " << e.What(); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
511 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
512 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
513 LOG(ERROR) << "Lua: Error in " << (isPost ? "RestApiPost()" : "RestApiPut()") << " for URI: " << uri; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
514 lua_pushnil(state); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
515 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
516 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
517 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
518 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
519 // Syntax in Lua: RestApiPost(uri, body, builtin) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
520 int LuaScripting::RestApiPost(lua_State *state) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
521 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
522 return RestApiPostOrPut(state, true); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
523 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
524 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
525 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
526 // Syntax in Lua: RestApiPut(uri, body, builtin) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
527 int LuaScripting::RestApiPut(lua_State *state) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
528 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
529 return RestApiPostOrPut(state, false); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
530 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
531 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
532 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
533 // Syntax in Lua: RestApiDelete(uri, builtin) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
534 int LuaScripting::RestApiDelete(lua_State *state) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
535 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
536 ServerContext* serverContext = GetServerContext(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
537 if (serverContext == NULL) |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
538 { |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
539 LOG(ERROR) << "Lua: The Orthanc API is unavailable"; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
540 lua_pushnil(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
541 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
542 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
543 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
544 // Check the types of the arguments |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
545 int nArgs = lua_gettop(state); |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
546 if (nArgs < 1 || nArgs > 3 || |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
547 !lua_isstring(state, 1) || // URI |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
548 (nArgs >= 2 && !lua_isboolean(state, 2))) // Restrict to built-in API? |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
549 { |
1449 | 550 LOG(ERROR) << "Lua: Bad parameters to RestApiDelete()"; |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
551 lua_pushnil(state); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
552 return 1; |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
553 } |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
554 |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
555 const char* uri = lua_tostring(state, 1); |
1545 | 556 bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) != 0 : false); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
557 |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
558 std::map<std::string, std::string> headers; |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
559 LuaContext::GetDictionaryArgument(headers, state, 3, true /* HTTP header key to lower case */); |
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3187
diff
changeset
|
560 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
561 try |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
562 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
563 if (IHttpHandler::SimpleDelete(NULL, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4507
diff
changeset
|
564 RequestOrigin_Lua, uri, headers) == HttpStatus_200_Ok) |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
565 { |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
566 lua_pushboolean(state, 1); |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
567 return 1; |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
568 } |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
569 } |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
570 catch (OrthancException& e) |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
571 { |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
572 LOG(ERROR) << "Lua: " << e.What(); |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
573 } |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
574 |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
575 LOG(ERROR) << "Lua: Error in RestApiDelete() for URI: " << uri; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
576 lua_pushnil(state); |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
577 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
578 return 1; |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
579 } |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
580 |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
581 |
1587
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
582 // Syntax in Lua: GetOrthancConfiguration() |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
583 int LuaScripting::GetOrthancConfiguration(lua_State *state) |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
584 { |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
585 Json::Value configuration; |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
586 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
587 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
588 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
589 configuration = lock.GetJson(); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
590 } |
1587
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
591 |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
592 LuaContext::GetLuaContext(state).PushJson(configuration); |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
593 |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
594 return 1; |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
595 } |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
596 |
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
597 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
598 size_t LuaScripting::ParseOperation(LuaJobManager::Lock& lock, |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
599 const std::string& operation, |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
600 const Json::Value& parameters) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
601 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
602 if (operation == "delete") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
603 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
604 LOG(INFO) << "Lua script to delete resource " << parameters["Resource"].asString(); |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
605 return lock.AddDeleteResourceOperation(context_); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
606 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
607 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
608 if (operation == "store-scu") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
609 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
610 std::string localAet; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
611 if (parameters.isMember("LocalAet")) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
612 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
613 localAet = parameters["LocalAet"].asString(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
614 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
615 else |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
616 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
617 localAet = context_.GetDefaultLocalApplicationEntityTitle(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
618 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
619 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
620 std::string name = parameters["Modality"].asString(); |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
621 RemoteModalityParameters modality; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
622 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
623 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
624 OrthancConfiguration::ReaderLock configLock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
625 modality = configLock.GetConfiguration().GetModalityUsingSymbolicName(name); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
626 } |
2222
21713ce8717b
Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
627 |
21713ce8717b
Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
628 // This is not a C-MOVE: No need to call "StoreScuCommand::SetMoveOriginator()" |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3851
diff
changeset
|
629 return lock.AddStoreScuOperation(context_, localAet, modality); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
630 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
631 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
632 if (operation == "store-peer") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
633 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
634 OrthancConfiguration::ReaderLock configLock; |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
635 std::string name = parameters["Peer"].asString(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
636 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
637 WebServiceParameters peer; |
2944
f395460af74d
simplifying OrthancConfiguration for modalities/peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2940
diff
changeset
|
638 if (configLock.GetConfiguration().LookupOrthancPeer(peer, name)) |
2799
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
639 { |
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
640 return lock.AddStorePeerOperation(peer); |
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
641 } |
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
642 else |
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
643 { |
2955 | 644 throw OrthancException(ErrorCode_UnknownResource, |
645 "No peer with symbolic name: " + name); | |
2799
6e3a60b85da6
New primitives to access Orthanc peers from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2738
diff
changeset
|
646 } |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
647 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
648 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
649 if (operation == "modify") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
650 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3676
diff
changeset
|
651 std::unique_ptr<DicomModification> modification(new DicomModification); |
2519
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
652 modification->ParseModifyRequest(parameters); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
653 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
654 return lock.AddModifyInstanceOperation(context_, modification.release()); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
655 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
656 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
657 if (operation == "call-system") |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
658 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
659 LOG(INFO) << "Lua script to call system command on " << parameters["Resource"].asString(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
660 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
661 const Json::Value& argsIn = parameters["Arguments"]; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
662 if (argsIn.type() != Json::arrayValue) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
663 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
664 throw OrthancException(ErrorCode_BadParameterType); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
665 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
666 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
667 std::vector<std::string> args; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
668 args.reserve(argsIn.size()); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
669 for (Json::Value::ArrayIndex i = 0; i < argsIn.size(); ++i) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
670 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
671 // http://jsoncpp.sourceforge.net/namespace_json.html#7d654b75c16a57007925868e38212b4e |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
672 switch (argsIn[i].type()) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
673 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
674 case Json::stringValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
675 args.push_back(argsIn[i].asString()); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
676 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
677 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
678 case Json::intValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
679 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asInt())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
680 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
681 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
682 case Json::uintValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
683 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asUInt())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
684 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
685 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
686 case Json::realValue: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
687 args.push_back(boost::lexical_cast<std::string>(argsIn[i].asFloat())); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
688 break; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
689 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
690 default: |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
691 throw OrthancException(ErrorCode_BadParameterType); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
692 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
693 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
694 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
695 std::string command = parameters["Command"].asString(); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
696 std::vector<std::string> postArgs; |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
697 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
698 return lock.AddSystemCallOperation(command, args, postArgs); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
699 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
700 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
701 throw OrthancException(ErrorCode_ParameterOutOfRange); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
702 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
703 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
704 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
705 void LuaScripting::InitializeJob() |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
706 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
707 lua_.Execute("_InitializeJob()"); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
708 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
709 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
710 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
711 void LuaScripting::SubmitJob() |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
712 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
713 Json::Value operations; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
714 LuaFunctionCall call2(lua_, "_AccessJob"); |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1587
diff
changeset
|
715 call2.ExecuteToJson(operations, false); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
716 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
717 if (operations.type() != Json::arrayValue) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
718 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
719 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
720 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
721 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
722 LuaJobManager::Lock lock(jobManager_, context_.GetJobsEngine()); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
723 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
724 bool isFirst = true; |
2727 | 725 size_t previous = 0; // Dummy initialization to avoid warning |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
726 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
727 for (Json::Value::ArrayIndex i = 0; i < operations.size(); ++i) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
728 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
729 if (operations[i].type() != Json::objectValue || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
730 !operations[i].isMember("Operation")) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
731 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
732 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
733 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
734 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
735 const Json::Value& parameters = operations[i]; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
736 if (!parameters.isMember("Resource")) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
737 { |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
738 throw OrthancException(ErrorCode_InternalError); |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
739 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
740 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
741 std::string operation = parameters["Operation"].asString(); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
742 size_t index = ParseOperation(lock, operation, operations[i]); |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
743 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
744 std::string resource = parameters["Resource"].asString(); |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
745 if (!resource.empty()) |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
746 { |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
747 lock.AddDicomInstanceInput(index, context_, resource); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
748 } |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
749 else if (!isFirst) |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
750 { |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
751 lock.Connect(previous, index); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
752 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
753 |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
754 isFirst = false; |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
755 previous = index; |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
756 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
757 } |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
758 |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
759 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
760 LuaScripting::LuaScripting(ServerContext& context) : |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
761 context_(context), |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
762 state_(State_Setup) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
763 { |
1444
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
764 lua_.SetGlobalVariable("_ServerContext", &context); |
b2b09a3dbd8e
refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
765 lua_.RegisterFunction("RestApiGet", RestApiGet); |
1447
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
766 lua_.RegisterFunction("RestApiPost", RestApiPost); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
767 lua_.RegisterFunction("RestApiPut", RestApiPut); |
5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1445
diff
changeset
|
768 lua_.RegisterFunction("RestApiDelete", RestApiDelete); |
1587
d7e569640d09
New function "GetOrthancConfiguration()" to get the Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1574
diff
changeset
|
769 lua_.RegisterFunction("GetOrthancConfiguration", GetOrthancConfiguration); |
2738
3a55b77339ff
fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2727
diff
changeset
|
770 |
3a55b77339ff
fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2727
diff
changeset
|
771 LOG(INFO) << "Initializing Lua for the event handler"; |
3a55b77339ff
fix deadlock in Lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2727
diff
changeset
|
772 LoadGlobalConfiguration(); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
773 } |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1436
diff
changeset
|
774 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
775 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
776 LuaScripting::~LuaScripting() |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
777 { |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
778 if (state_ == State_Running) |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
779 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
780 LOG(ERROR) << "INTERNAL ERROR: LuaScripting::Stop() should be invoked manually to avoid mess in the destruction order!"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
781 Stop(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
782 } |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
783 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
784 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
785 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
786 void LuaScripting::EventThread(LuaScripting* that) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
787 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
788 for (;;) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
789 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3676
diff
changeset
|
790 std::unique_ptr<IDynamicObject> event(that->pendingEvents_.Dequeue(100)); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
791 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
792 if (event.get() == NULL) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
793 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
794 // The event queue is empty, check whether we should stop |
2618 | 795 boost::recursive_mutex::scoped_lock lock(that->mutex_); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
796 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
797 if (that->state_ != State_Running) |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
798 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
799 return; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
800 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
801 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
802 else |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
803 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
804 try |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
805 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
806 dynamic_cast<IEvent&>(*event).Apply(*that); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
807 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
808 catch (OrthancException& e) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
809 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
810 LOG(ERROR) << "Error while processing Lua events: " << e.What(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
811 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
812 } |
3851
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3845
diff
changeset
|
813 |
6498739a3c3c
refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3845
diff
changeset
|
814 that->jobManager_.GetDicomConnectionManager().CloseIfInactive(); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
815 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
816 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
817 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
818 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
819 void LuaScripting::Start() |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
820 { |
2618 | 821 boost::recursive_mutex::scoped_lock lock(mutex_); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
822 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
823 if (state_ != State_Setup || |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
824 eventThread_.joinable() /* already started */) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
825 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
826 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
827 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
828 else |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
829 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
830 LOG(INFO) << "Starting the Lua engine"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
831 eventThread_ = boost::thread(EventThread, this); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2651
diff
changeset
|
832 state_ = State_Running; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
833 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
834 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
835 |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
836 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
837 void LuaScripting::Stop() |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
838 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
839 { |
2618 | 840 boost::recursive_mutex::scoped_lock lock(mutex_); |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
841 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
842 if (state_ != State_Running) |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
843 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
844 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
845 } |
1572
904096e7367e
More information about the origin request in OnStoredInstance() callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
846 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2649
diff
changeset
|
847 state_ = State_Done; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
848 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
849 |
2620
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2618
diff
changeset
|
850 jobManager_.AwakeTrailingSleep(); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
851 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
852 if (eventThread_.joinable()) |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
853 { |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
854 LOG(INFO) << "Stopping the Lua engine"; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
855 eventThread_.join(); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
856 LOG(INFO) << "The Lua engine has stopped"; |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
857 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
858 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
859 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
860 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
861 void LuaScripting::SignalStoredInstance(const std::string& publicId, |
3916
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
862 const DicomInstanceToStore& instance, |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
863 const Json::Value& simplifiedTags) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
864 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
865 Json::Value metadata = Json::objectValue; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
866 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
867 for (ServerIndex::MetadataMap::const_iterator |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
868 it = instance.GetMetadata().begin(); |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
869 it != instance.GetMetadata().end(); ++it) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
870 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
871 if (it->first.first == ResourceType_Instance) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
872 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
873 metadata[EnumerationToString(it->first.second)] = it->second; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
874 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
875 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
876 |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
877 pendingEvents_.Enqueue(new OnStoredInstanceEvent(publicId, simplifiedTags, metadata, instance)); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
878 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
879 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
880 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
881 void LuaScripting::SignalChange(const ServerIndexChange& change) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
882 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
883 if (change.GetChangeType() == ChangeType_StablePatient || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
884 change.GetChangeType() == ChangeType_StableStudy || |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
885 change.GetChangeType() == ChangeType_StableSeries) |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
886 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
887 pendingEvents_.Enqueue(new StableResourceEvent(change)); |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
888 } |
3676
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
889 else if (change.GetChangeType() == ChangeType_Deleted) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
890 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
891 pendingEvents_.Enqueue(new DeleteEvent(change.GetResourceType(), change.GetPublicId())); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
892 } |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
893 else if (change.GetChangeType() == ChangeType_UpdatedAttachment || |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
894 change.GetChangeType() == ChangeType_UpdatedMetadata) |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
895 { |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
896 pendingEvents_.Enqueue(new UpdateEvent(change.GetResourceType(), change.GetPublicId())); |
231b46ce1984
Lua events for deleted/updated resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
897 } |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
898 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
899 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
900 |
1574
0c29ebe80ac9
give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
901 bool LuaScripting::FilterIncomingInstance(const DicomInstanceToStore& instance, |
0c29ebe80ac9
give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
902 const Json::Value& simplified) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
903 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
904 static const char* NAME = "ReceivedInstanceFilter"; |
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
905 |
1456
68827c07e683
fix recursive calls with Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
906 boost::recursive_mutex::scoped_lock lock(mutex_); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
907 |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
908 if (lua_.IsExistingFunction(NAME)) |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
909 { |
1435
6406f5493d92
refactoring: Lua toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1433
diff
changeset
|
910 LuaFunctionCall call(lua_, NAME); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
911 call.PushJson(simplified); |
1574
0c29ebe80ac9
give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
912 |
0c29ebe80ac9
give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
913 Json::Value origin; |
2640
c691fcf66071
ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2638
diff
changeset
|
914 instance.GetOrigin().Format(origin); |
1574
0c29ebe80ac9
give access to full request origin in ReceivedInstanceFilter (Lua)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1572
diff
changeset
|
915 call.PushJson(origin); |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
916 |
3845
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
917 Json::Value info = Json::objectValue; |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
918 info["HasPixelData"] = instance.HasPixelData(); |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
919 |
4507
b4c58795f3a8
widening the use of DicomTransferSyntax enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
920 DicomTransferSyntax s; |
3845
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
921 if (instance.LookupTransferSyntax(s)) |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
922 { |
4507
b4c58795f3a8
widening the use of DicomTransferSyntax enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
923 info["TransferSyntaxUID"] = GetTransferSyntaxUid(s); |
3845
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
924 } |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
925 |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
926 call.PushJson(info); |
281045a1e6db
new "info" field in "ReceivedInstanceFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
927 |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
928 if (!call.ExecutePredicate()) |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
929 { |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
930 return false; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
931 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
932 } |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
933 |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
934 return true; |
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
935 } |
1455
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
936 |
4921
309fb4f02704
fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
937 bool LuaScripting::FilterIncomingCStoreInstance(uint16_t& dimseStatus, |
309fb4f02704
fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
938 const DicomInstanceToStore& instance, |
309fb4f02704
fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
939 const Json::Value& simplified) |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
940 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
941 static const char* NAME = "ReceivedCStoreInstanceFilter"; |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
942 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
943 boost::recursive_mutex::scoped_lock lock(mutex_); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
944 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
945 if (lua_.IsExistingFunction(NAME)) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
946 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
947 LuaFunctionCall call(lua_, NAME); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
948 call.PushJson(simplified); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
949 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
950 Json::Value origin; |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
951 instance.GetOrigin().Format(origin); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
952 call.PushJson(origin); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
953 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
954 Json::Value info = Json::objectValue; |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
955 info["HasPixelData"] = instance.HasPixelData(); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
956 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
957 DicomTransferSyntax s; |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
958 if (instance.LookupTransferSyntax(s)) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
959 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
960 info["TransferSyntaxUID"] = GetTransferSyntaxUid(s); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
961 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
962 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
963 call.PushJson(info); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
964 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
965 int result; |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
966 call.ExecuteToInt(result); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
967 return static_cast<uint16_t>(result); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
968 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
969 |
4921
309fb4f02704
fix signature of OrthancPluginIncomingCStoreInstanceFilter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
970 return true; |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
971 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4697
diff
changeset
|
972 |
1455
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
973 |
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
974 void LuaScripting::Execute(const std::string& command) |
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
975 { |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
976 pendingEvents_.Enqueue(new ExecuteEvent(command)); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
977 } |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
978 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
979 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
980 void LuaScripting::LoadGlobalConfiguration() |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
981 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
982 OrthancConfiguration::ReaderLock configLock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
983 |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
984 { |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
985 std::string command; |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
986 Orthanc::ServerResources::GetFileResource(command, Orthanc::ServerResources::LUA_TOOLBOX); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
987 lua_.Execute(command); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
988 } |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
989 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
990 std::list<std::string> luaScripts; |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
991 configLock.GetConfiguration().GetListOfStringsParameter(luaScripts, "LuaScripts"); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
992 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
993 LuaScripting::Lock lock(*this); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
994 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
995 for (std::list<std::string>::const_iterator |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
996 it = luaScripts.begin(); it != luaScripts.end(); ++it) |
1455
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
997 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2799
diff
changeset
|
998 std::string path = configLock.GetConfiguration().InterpretStringParameterAsPath(*it); |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
999 LOG(INFO) << "Installing the Lua scripts from: " << path; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
1000 std::string script; |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
1001 SystemToolbox::ReadFile(script, path); |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
1002 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
1003 lock.GetLua().Execute(script); |
1455
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
1004 } |
a68545767975
Initialize() and Finalize() events in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1449
diff
changeset
|
1005 } |
2675
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1006 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1007 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1008 void LuaScripting::SignalJobSubmitted(const std::string& jobId) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1009 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1010 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Submitted, jobId)); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1011 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1012 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1013 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1014 void LuaScripting::SignalJobSuccess(const std::string& jobId) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1015 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1016 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Success, jobId)); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1017 } |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1018 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1019 |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1020 void LuaScripting::SignalJobFailure(const std::string& jobId) |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1021 { |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1022 pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Failure, jobId)); |
3fc310ceb6d4
lua callbacks for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1023 } |
1433
461e7554bff7
refactoring: LuaScripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1024 } |