Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Lua/LuaFunctionCall.cpp @ 4819:70d2a97ca8cb openssl-3.x
integration mainline->openssl-3.x
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Nov 2021 13:12:32 +0100 |
parents | 94616af363ec |
children | 7053502fbf97 |
rev | line source |
---|---|
386 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1051
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
386 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
10 * the License, or (at your option) any later version. |
386 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
15 * Lesser General Public License for more details. |
386 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4105
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
386 | 20 **/ |
21 | |
22 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
386 | 24 #include "LuaFunctionCall.h" |
25 | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
26 #include "../OrthancException.h" |
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
27 #include "../Logging.h" |
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
28 |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
29 #if ORTHANC_ENABLE_DCMTK == 1 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
30 # include "../DicomParsing/FromDcmtkBridge.h" |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
31 #endif |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
32 |
996
cf52f3bcb2b3
clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include <cassert> |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
34 #include <stdio.h> |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
35 #include <boost/lexical_cast.hpp> |
386 | 36 |
37 namespace Orthanc | |
38 { | |
39 void LuaFunctionCall::CheckAlreadyExecuted() | |
40 { | |
41 if (isExecuted_) | |
42 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
43 throw OrthancException(ErrorCode_LuaAlreadyExecuted); |
386 | 44 } |
45 } | |
46 | |
47 LuaFunctionCall::LuaFunctionCall(LuaContext& context, | |
48 const char* functionName) : | |
49 context_(context), | |
50 isExecuted_(false) | |
51 { | |
52 // Clear the stack to fulfill the invariant | |
53 lua_settop(context_.lua_, 0); | |
54 lua_getglobal(context_.lua_, functionName); | |
55 } | |
56 | |
57 void LuaFunctionCall::PushString(const std::string& value) | |
58 { | |
59 CheckAlreadyExecuted(); | |
1465
905842836ad4
sample Lua script to write DICOM series to disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1448
diff
changeset
|
60 lua_pushlstring(context_.lua_, value.c_str(), value.size()); |
386 | 61 } |
62 | |
63 void LuaFunctionCall::PushBoolean(bool value) | |
64 { | |
65 CheckAlreadyExecuted(); | |
66 lua_pushboolean(context_.lua_, value); | |
67 } | |
68 | |
69 void LuaFunctionCall::PushInteger(int value) | |
70 { | |
71 CheckAlreadyExecuted(); | |
72 lua_pushinteger(context_.lua_, value); | |
73 } | |
74 | |
75 void LuaFunctionCall::PushDouble(double value) | |
76 { | |
77 CheckAlreadyExecuted(); | |
78 lua_pushnumber(context_.lua_, value); | |
79 } | |
80 | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
81 void LuaFunctionCall::PushJson(const Json::Value& value) |
386 | 82 { |
83 CheckAlreadyExecuted(); | |
1051 | 84 context_.PushJson(value); |
386 | 85 } |
86 | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
87 void LuaFunctionCall::ExecuteInternal(int numOutputs) |
386 | 88 { |
89 CheckAlreadyExecuted(); | |
90 | |
91 assert(lua_gettop(context_.lua_) >= 1); | |
92 int nargs = lua_gettop(context_.lua_) - 1; | |
93 int error = lua_pcall(context_.lua_, nargs, numOutputs, 0); | |
94 | |
95 if (error) | |
96 { | |
97 assert(lua_gettop(context_.lua_) >= 1); | |
98 | |
99 std::string description(lua_tostring(context_.lua_, -1)); | |
100 lua_pop(context_.lua_, 1); /* pop error message from the stack */ | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
101 |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
102 throw OrthancException(ErrorCode_CannotExecuteLua, description); |
386 | 103 } |
104 | |
105 if (lua_gettop(context_.lua_) < numOutputs) | |
106 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
107 throw OrthancException(ErrorCode_LuaBadOutput); |
386 | 108 } |
109 | |
110 isExecuted_ = true; | |
111 } | |
112 | |
113 bool LuaFunctionCall::ExecutePredicate() | |
114 { | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
115 ExecuteInternal(1); |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
116 |
386 | 117 if (!lua_isboolean(context_.lua_, 1)) |
118 { | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
119 throw OrthancException(ErrorCode_NotLuaPredicate); |
386 | 120 } |
121 | |
122 return lua_toboolean(context_.lua_, 1) != 0; | |
123 } | |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
124 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
125 |
1658
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1583
diff
changeset
|
126 void LuaFunctionCall::ExecuteToJson(Json::Value& result, |
54bafe0e7e7b
Optional argument "keepStrings" in "DumpJson()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1583
diff
changeset
|
127 bool keepStrings) |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
128 { |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
129 ExecuteInternal(1); |
3442
dd1e68f2d0c0
Fix issue #106 (Unable to export preview as jpeg from Lua script)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
130 context_.GetJson(result, context_.lua_, lua_gettop(context_.lua_), keepStrings); |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
131 } |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
132 |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
133 |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
134 void LuaFunctionCall::ExecuteToString(std::string& result) |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
135 { |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
136 ExecuteInternal(1); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
137 |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
138 int top = lua_gettop(context_.lua_); |
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
139 if (lua_isstring(context_.lua_, top)) |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
140 { |
1448
3f7722179467
refactoring: GetJson in Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
141 result = lua_tostring(context_.lua_, top); |
1010 | 142 } |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
143 else |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
144 { |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
145 throw OrthancException(ErrorCode_LuaReturnsNoString); |
997
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
146 } |
1b1d51e9f1a2
return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
996
diff
changeset
|
147 } |
1959
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
148 |
4796
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
149 void LuaFunctionCall::ExecuteToInt(int& result) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
150 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
151 ExecuteInternal(1); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
152 |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
153 int top = lua_gettop(context_.lua_); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
154 if (lua_isnumber(context_.lua_, top)) |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
155 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
156 result = static_cast<int>(lua_tointeger(context_.lua_, top)); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
157 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
158 else |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
159 { |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
160 throw OrthancException(ErrorCode_LuaReturnsNoString); |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
161 } |
94616af363ec
added ReceivedCStoreInstanceFilter lua callback + OrthancPluginRegisterIncomingCStoreInstanceFilter in sdk
Alain Mazy <am@osimis.io>
parents:
4437
diff
changeset
|
162 } |
1959
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
163 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
164 void LuaFunctionCall::PushStringMap(const std::map<std::string, std::string>& value) |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
165 { |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
166 Json::Value json = Json::objectValue; |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
167 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
168 for (std::map<std::string, std::string>::const_iterator |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
169 it = value.begin(); it != value.end(); ++it) |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
170 { |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
171 json[it->first] = it->second; |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
172 } |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
173 |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
174 PushJson(json); |
45c4387a379c
Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
175 } |
2218
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
176 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
177 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
178 void LuaFunctionCall::PushDicom(const DicomMap& dicom) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
179 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
180 DicomArray a(dicom); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
181 PushDicom(a); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
182 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
183 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
184 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
185 void LuaFunctionCall::PushDicom(const DicomArray& dicom) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
186 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
187 Json::Value value = Json::objectValue; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
188 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
189 for (size_t i = 0; i < dicom.GetSize(); i++) |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
190 { |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
191 const DicomValue& v = dicom.GetElement(i).GetValue(); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
192 std::string s = (v.IsNull() || v.IsBinary()) ? "" : v.GetContent(); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
193 value[dicom.GetElement(i).GetTag().Format()] = s; |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
194 } |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
195 |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
196 PushJson(value); |
3eefb84ac0bd
dynamically fix outgoing C-Find requests using "OutgoingFindRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1959
diff
changeset
|
197 } |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
198 |
4300 | 199 void LuaFunctionCall::Execute() |
200 { | |
201 ExecuteInternal(0); | |
202 } | |
203 | |
4105
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
204 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
205 #if ORTHANC_ENABLE_DCMTK == 1 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
206 void LuaFunctionCall::ExecuteToDicom(DicomMap& target) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
207 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
208 Json::Value output; |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
209 ExecuteToJson(output, true /* keep strings */); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
210 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
211 target.Clear(); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
212 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
213 if (output.type() == Json::arrayValue && |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
214 output.size() == 0) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
215 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
216 // This case happens for empty tables |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
217 return; |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
218 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
219 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
220 if (output.type() != Json::objectValue) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
221 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
222 throw OrthancException(ErrorCode_LuaBadOutput, |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
223 "Lua: The script must return a table"); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
224 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
225 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
226 Json::Value::Members members = output.getMemberNames(); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
227 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
228 for (size_t i = 0; i < members.size(); i++) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
229 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
230 if (output[members[i]].type() != Json::stringValue) |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
231 { |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
232 throw OrthancException(ErrorCode_LuaBadOutput, |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
233 "Lua: The script must return a table " |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
234 "mapping names of DICOM tags to strings"); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
235 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
236 |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
237 DicomTag tag(FromDcmtkBridge::ParseTag(members[i])); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
238 target.SetValue(tag, output[members[i]].asString(), false); |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
239 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
240 } |
c02a2d9efbc2
move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
241 #endif |
386 | 242 } |