Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 4392:3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Dec 2020 18:09:47 +0100 |
parents | 4bb7522a63e0 |
children | f7104e9d044c |
rev | line source |
---|---|
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3478
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
4122
4bb7522a63e0
do not enforce openssl exception in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * General Public License for more details. |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "OrthancPluginCppWrapper.h" |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
3749
edabdf07ee83
replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3669
diff
changeset
|
24 #include <boost/algorithm/string/predicate.hpp> |
edabdf07ee83
replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3669
diff
changeset
|
25 #include <boost/move/unique_ptr.hpp> |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
26 #include <boost/thread.hpp> |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include <json/reader.h> |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
28 #include <json/writer.h> |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
3916
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
31 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
32 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
33 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
34 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
35 |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 namespace OrthancPlugins |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
3028 | 38 static OrthancPluginContext* globalContext_ = NULL; |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
39 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
40 |
3028 | 41 void SetGlobalContext(OrthancPluginContext* context) |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
42 { |
3028 | 43 if (context == NULL) |
44 { | |
45 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
46 } | |
47 else if (globalContext_ == NULL) | |
48 { | |
49 globalContext_ = context; | |
50 } | |
51 else | |
52 { | |
53 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
54 } | |
3026 | 55 } |
56 | |
57 | |
3028 | 58 bool HasGlobalContext() |
59 { | |
60 return globalContext_ != NULL; | |
61 } | |
62 | |
63 | |
64 OrthancPluginContext* GetGlobalContext() | |
65 { | |
66 if (globalContext_ == NULL) | |
67 { | |
68 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
69 } | |
70 else | |
71 { | |
72 return globalContext_; | |
73 } | |
74 } | |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
75 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
76 |
3028 | 77 void MemoryBuffer::Check(OrthancPluginErrorCode code) |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
78 { |
3028 | 79 if (code != OrthancPluginErrorCode_Success) |
80 { | |
81 // Prevent using garbage information | |
82 buffer_.data = NULL; | |
83 buffer_.size = 0; | |
84 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
85 } | |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
86 } |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
87 |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
88 |
3028 | 89 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code) |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
90 { |
3028 | 91 if (code != OrthancPluginErrorCode_Success) |
92 { | |
93 // Prevent using garbage information | |
94 buffer_.data = NULL; | |
95 buffer_.size = 0; | |
96 } | |
97 | |
98 if (code == OrthancPluginErrorCode_Success) | |
99 { | |
100 return true; | |
101 } | |
102 else if (code == OrthancPluginErrorCode_UnknownResource || | |
103 code == OrthancPluginErrorCode_InexistentItem) | |
104 { | |
105 return false; | |
106 } | |
107 else | |
108 { | |
109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
110 } | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
111 } |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
112 |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
113 |
3028 | 114 MemoryBuffer::MemoryBuffer() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 buffer_.data = NULL; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 buffer_.size = 0; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
3028 | 120 |
3934
0b59e2706366
guard on SDK version in OrthancPlugins::MemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
121 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
3930
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
122 MemoryBuffer::MemoryBuffer(const void* buffer, |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
123 size_t size) |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
124 { |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
125 uint32_t s = static_cast<uint32_t>(size); |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
126 if (static_cast<size_t>(s) != size) |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
127 { |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
128 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
129 } |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
130 else if (OrthancPluginCreateMemoryBuffer(GetGlobalContext(), &buffer_, s) != |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
131 OrthancPluginErrorCode_Success) |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
132 { |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
133 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
134 } |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
135 else |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
136 { |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
137 memcpy(buffer_.data, buffer, size); |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
138 } |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
139 } |
3934
0b59e2706366
guard on SDK version in OrthancPlugins::MemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
140 #endif |
3930
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
141 |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3923
diff
changeset
|
142 |
3028 | 143 void MemoryBuffer::Clear() |
3026 | 144 { |
3028 | 145 if (buffer_.data != NULL) |
146 { | |
147 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); | |
148 buffer_.data = NULL; | |
149 buffer_.size = 0; | |
150 } | |
3026 | 151 } |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
3026 | 153 |
3028 | 154 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) |
155 { | |
156 Clear(); | |
157 | |
158 buffer_.data = other.data; | |
159 buffer_.size = other.size; | |
160 | |
161 other.data = NULL; | |
162 other.size = 0; | |
163 } | |
3026 | 164 |
165 | |
3320 | 166 void MemoryBuffer::Swap(MemoryBuffer& other) |
167 { | |
168 std::swap(buffer_.data, other.buffer_.data); | |
169 std::swap(buffer_.size, other.buffer_.size); | |
170 } | |
171 | |
172 | |
3028 | 173 OrthancPluginMemoryBuffer MemoryBuffer::Release() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 { |
3028 | 175 OrthancPluginMemoryBuffer result = buffer_; |
176 | |
3026 | 177 buffer_.data = NULL; |
178 buffer_.size = 0; | |
3028 | 179 |
180 return result; | |
3026 | 181 } |
3028 | 182 |
183 | |
184 void MemoryBuffer::ToString(std::string& target) const | |
185 { | |
186 if (buffer_.size == 0) | |
187 { | |
188 target.clear(); | |
189 } | |
190 else | |
191 { | |
192 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size); | |
193 } | |
194 } | |
3026 | 195 |
196 | |
3028 | 197 void MemoryBuffer::ToJson(Json::Value& target) const |
198 { | |
199 if (buffer_.data == NULL || | |
200 buffer_.size == 0) | |
201 { | |
202 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
203 } | |
3026 | 204 |
3028 | 205 const char* tmp = reinterpret_cast<const char*>(buffer_.data); |
3026 | 206 |
3028 | 207 Json::Reader reader; |
208 if (!reader.parse(tmp, tmp + buffer_.size, target)) | |
209 { | |
210 LogError("Cannot convert some memory buffer to JSON"); | |
211 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
212 } | |
213 } | |
3026 | 214 |
215 | |
3028 | 216 bool MemoryBuffer::RestApiGet(const std::string& uri, |
217 bool applyPlugins) | |
3026 | 218 { |
3028 | 219 Clear(); |
3026 | 220 |
3028 | 221 if (applyPlugins) |
222 { | |
223 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); | |
224 } | |
225 else | |
226 { | |
227 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); | |
228 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 |
3028 | 231 bool MemoryBuffer::RestApiGet(const std::string& uri, |
232 const std::map<std::string, std::string>& httpHeaders, | |
233 bool applyPlugins) | |
3026 | 234 { |
3028 | 235 Clear(); |
236 | |
237 std::vector<const char*> headersKeys; | |
238 std::vector<const char*> headersValues; | |
3039 | 239 |
240 for (std::map<std::string, std::string>::const_iterator | |
241 it = httpHeaders.begin(); it != httpHeaders.end(); it++) | |
3028 | 242 { |
243 headersKeys.push_back(it->first.c_str()); | |
244 headersValues.push_back(it->second.c_str()); | |
245 } | |
246 | |
3039 | 247 return CheckHttp(OrthancPluginRestApiGet2( |
248 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(), | |
249 (headersKeys.empty() ? NULL : &headersKeys[0]), | |
250 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins)); | |
3026 | 251 } |
3028 | 252 |
253 bool MemoryBuffer::RestApiPost(const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
254 const void* body, |
3028 | 255 size_t bodySize, |
256 bool applyPlugins) | |
257 { | |
258 Clear(); | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
259 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
260 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
261 const char* b = reinterpret_cast<const char*>(body); |
3028 | 262 |
263 if (applyPlugins) | |
264 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
265 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 266 } |
267 else | |
268 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
269 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 270 } |
271 } | |
3026 | 272 |
273 | |
3028 | 274 bool MemoryBuffer::RestApiPut(const std::string& uri, |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
275 const void* body, |
3028 | 276 size_t bodySize, |
277 bool applyPlugins) | |
278 { | |
279 Clear(); | |
3026 | 280 |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
281 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
282 const char* b = reinterpret_cast<const char*>(body); |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
283 |
3028 | 284 if (applyPlugins) |
285 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
286 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 287 } |
288 else | |
289 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
290 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 291 } |
3026 | 292 } |
3028 | 293 |
3026 | 294 |
3028 | 295 bool MemoryBuffer::RestApiPost(const std::string& uri, |
296 const Json::Value& body, | |
297 bool applyPlugins) | |
3026 | 298 { |
3028 | 299 Json::FastWriter writer; |
300 return RestApiPost(uri, writer.write(body), applyPlugins); | |
3026 | 301 } |
302 | |
3028 | 303 |
304 bool MemoryBuffer::RestApiPut(const std::string& uri, | |
305 const Json::Value& body, | |
306 bool applyPlugins) | |
307 { | |
308 Json::FastWriter writer; | |
309 return RestApiPut(uri, writer.write(body), applyPlugins); | |
310 } | |
3026 | 311 |
3028 | 312 |
313 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
314 OrthancPluginCreateDicomFlags flags) | |
315 { | |
316 Clear(); | |
317 | |
318 Json::FastWriter writer; | |
319 std::string s = writer.write(tags); | |
3026 | 320 |
3028 | 321 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); |
3026 | 322 } |
3028 | 323 |
324 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
325 const OrthancImage& pixelData, | |
326 OrthancPluginCreateDicomFlags flags) | |
3026 | 327 { |
3028 | 328 Clear(); |
329 | |
330 Json::FastWriter writer; | |
331 std::string s = writer.write(tags); | |
332 | |
333 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); | |
3026 | 334 } |
3028 | 335 |
336 | |
337 void MemoryBuffer::ReadFile(const std::string& path) | |
338 { | |
339 Clear(); | |
340 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); | |
341 } | |
3026 | 342 |
343 | |
3028 | 344 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) |
3026 | 345 { |
3028 | 346 Clear(); |
347 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); | |
3026 | 348 } |
349 | |
350 | |
3028 | 351 void OrthancString::Assign(char* str) |
352 { | |
3440 | 353 Clear(); |
354 | |
355 if (str != NULL) | |
3028 | 356 { |
357 str_ = str; | |
358 } | |
359 } | |
3026 | 360 |
361 | |
3028 | 362 void OrthancString::Clear() |
363 { | |
364 if (str_ != NULL) | |
365 { | |
366 OrthancPluginFreeString(GetGlobalContext(), str_); | |
367 str_ = NULL; | |
368 } | |
369 } | |
3026 | 370 |
371 | |
3028 | 372 void OrthancString::ToString(std::string& target) const |
373 { | |
374 if (str_ == NULL) | |
375 { | |
376 target.clear(); | |
377 } | |
378 else | |
379 { | |
380 target.assign(str_); | |
381 } | |
382 } | |
3026 | 383 |
384 | |
3028 | 385 void OrthancString::ToJson(Json::Value& target) const |
386 { | |
387 if (str_ == NULL) | |
388 { | |
389 LogError("Cannot convert an empty memory buffer to JSON"); | |
390 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
391 } | |
392 | |
393 Json::Reader reader; | |
394 if (!reader.parse(str_, target)) | |
395 { | |
396 LogError("Cannot convert some memory buffer to JSON"); | |
397 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
398 } | |
399 } | |
3026 | 400 |
401 | |
3028 | 402 void MemoryBuffer::DicomToJson(Json::Value& target, |
403 OrthancPluginDicomToJsonFormat format, | |
404 OrthancPluginDicomToJsonFlags flags, | |
405 uint32_t maxStringLength) | |
406 { | |
407 OrthancString str; | |
408 str.Assign(OrthancPluginDicomBufferToJson | |
409 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); | |
410 str.ToJson(target); | |
411 } | |
3026 | 412 |
413 | |
3028 | 414 bool MemoryBuffer::HttpGet(const std::string& url, |
415 const std::string& username, | |
416 const std::string& password) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 Clear(); |
3028 | 419 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), |
420 username.empty() ? NULL : username.c_str(), | |
421 password.empty() ? NULL : password.c_str())); | |
3026 | 422 } |
423 | |
424 | |
3028 | 425 bool MemoryBuffer::HttpPost(const std::string& url, |
426 const std::string& body, | |
427 const std::string& username, | |
428 const std::string& password) | |
3026 | 429 { |
3028 | 430 Clear(); |
431 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), | |
432 body.c_str(), body.size(), | |
433 username.empty() ? NULL : username.c_str(), | |
434 password.empty() ? NULL : password.c_str())); | |
3026 | 435 } |
436 | |
437 | |
3028 | 438 bool MemoryBuffer::HttpPut(const std::string& url, |
439 const std::string& body, | |
440 const std::string& username, | |
441 const std::string& password) | |
3026 | 442 { |
3028 | 443 Clear(); |
444 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), | |
445 body.empty() ? NULL : body.c_str(), | |
446 body.size(), | |
447 username.empty() ? NULL : username.c_str(), | |
448 password.empty() ? NULL : password.c_str())); | |
3026 | 449 } |
450 | |
3028 | 451 |
452 void MemoryBuffer::GetDicomInstance(const std::string& instanceId) | |
3026 | 453 { |
3028 | 454 Clear(); |
455 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); | |
3026 | 456 } |
457 | |
458 | |
3028 | 459 bool HttpDelete(const std::string& url, |
460 const std::string& username, | |
461 const std::string& password) | |
462 { | |
463 OrthancPluginErrorCode error = OrthancPluginHttpDelete | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
464 (GetGlobalContext(), url.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
465 username.empty() ? NULL : username.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
466 password.empty() ? NULL : password.c_str()); |
3028 | 467 |
468 if (error == OrthancPluginErrorCode_Success) | |
469 { | |
470 return true; | |
471 } | |
472 else if (error == OrthancPluginErrorCode_UnknownResource || | |
473 error == OrthancPluginErrorCode_InexistentItem) | |
474 { | |
475 return false; | |
476 } | |
477 else | |
478 { | |
479 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
480 } | |
481 } | |
3026 | 482 |
483 | |
3028 | 484 void LogError(const std::string& message) |
485 { | |
486 if (HasGlobalContext()) | |
487 { | |
488 OrthancPluginLogError(GetGlobalContext(), message.c_str()); | |
489 } | |
490 } | |
3026 | 491 |
492 | |
3028 | 493 void LogWarning(const std::string& message) |
494 { | |
495 if (HasGlobalContext()) | |
496 { | |
497 OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); | |
498 } | |
499 } | |
500 | |
501 | |
502 void LogInfo(const std::string& message) | |
503 { | |
504 if (HasGlobalContext()) | |
505 { | |
506 OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); | |
507 } | |
508 } | |
3026 | 509 |
510 | |
3421
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
511 void OrthancConfiguration::LoadConfiguration() |
3028 | 512 { |
513 OrthancString str; | |
514 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); | |
3026 | 515 |
3028 | 516 if (str.GetContent() == NULL) |
517 { | |
518 LogError("Cannot access the Orthanc configuration"); | |
519 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
520 } | |
3026 | 521 |
3028 | 522 str.ToJson(configuration_); |
523 | |
524 if (configuration_.type() != Json::objectValue) | |
525 { | |
526 LogError("Unable to read the Orthanc configuration"); | |
527 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
528 } | |
529 } | |
3421
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
530 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
531 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
532 OrthancConfiguration::OrthancConfiguration() |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
533 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
534 LoadConfiguration(); |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
535 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
536 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
537 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
538 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration) |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
539 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
540 if (loadConfiguration) |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
541 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
542 LoadConfiguration(); |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
543 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
544 else |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
545 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
546 configuration_ = Json::objectValue; |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
547 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
548 } |
3026 | 549 |
550 | |
3028 | 551 std::string OrthancConfiguration::GetPath(const std::string& key) const |
3026 | 552 { |
3028 | 553 if (path_.empty()) |
554 { | |
555 return key; | |
556 } | |
557 else | |
558 { | |
559 return path_ + "." + key; | |
560 } | |
3026 | 561 } |
3028 | 562 |
563 | |
564 bool OrthancConfiguration::IsSection(const std::string& key) const | |
3026 | 565 { |
3028 | 566 assert(configuration_.type() == Json::objectValue); |
567 | |
568 return (configuration_.isMember(key) && | |
569 configuration_[key].type() == Json::objectValue); | |
3026 | 570 } |
571 | |
572 | |
3028 | 573 void OrthancConfiguration::GetSection(OrthancConfiguration& target, |
574 const std::string& key) const | |
3026 | 575 { |
3028 | 576 assert(configuration_.type() == Json::objectValue); |
3026 | 577 |
3028 | 578 target.path_ = GetPath(key); |
3026 | 579 |
3028 | 580 if (!configuration_.isMember(key)) |
581 { | |
582 target.configuration_ = Json::objectValue; | |
583 } | |
584 else | |
585 { | |
586 if (configuration_[key].type() != Json::objectValue) | |
587 { | |
588 LogError("The configuration section \"" + target.path_ + | |
589 "\" is not an associative array as expected"); | |
590 | |
591 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
592 } | |
593 | |
594 target.configuration_ = configuration_[key]; | |
595 } | |
3026 | 596 } |
597 | |
598 | |
3028 | 599 bool OrthancConfiguration::LookupStringValue(std::string& target, |
600 const std::string& key) const | |
601 { | |
602 assert(configuration_.type() == Json::objectValue); | |
603 | |
604 if (!configuration_.isMember(key)) | |
605 { | |
606 return false; | |
607 } | |
3026 | 608 |
3028 | 609 if (configuration_[key].type() != Json::stringValue) |
610 { | |
611 LogError("The configuration option \"" + GetPath(key) + | |
612 "\" is not a string as expected"); | |
613 | |
614 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
615 } | |
616 | |
617 target = configuration_[key].asString(); | |
618 return true; | |
3026 | 619 } |
620 | |
621 | |
3028 | 622 bool OrthancConfiguration::LookupIntegerValue(int& target, |
623 const std::string& key) const | |
3026 | 624 { |
3028 | 625 assert(configuration_.type() == Json::objectValue); |
626 | |
627 if (!configuration_.isMember(key)) | |
628 { | |
629 return false; | |
630 } | |
631 | |
632 switch (configuration_[key].type()) | |
633 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
634 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
635 target = configuration_[key].asInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
636 return true; |
3028 | 637 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
638 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
639 target = configuration_[key].asUInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
640 return true; |
3028 | 641 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
642 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
643 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
644 "\" is not an integer as expected"); |
3028 | 645 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
646 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 647 } |
3026 | 648 } |
649 | |
650 | |
3028 | 651 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, |
652 const std::string& key) const | |
653 { | |
654 int tmp; | |
655 if (!LookupIntegerValue(tmp, key)) | |
656 { | |
657 return false; | |
658 } | |
3026 | 659 |
3028 | 660 if (tmp < 0) |
661 { | |
662 LogError("The configuration option \"" + GetPath(key) + | |
663 "\" is not a positive integer as expected"); | |
664 | |
665 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
666 } | |
667 else | |
668 { | |
669 target = static_cast<unsigned int>(tmp); | |
670 return true; | |
671 } | |
672 } | |
3026 | 673 |
674 | |
3028 | 675 bool OrthancConfiguration::LookupBooleanValue(bool& target, |
676 const std::string& key) const | |
3026 | 677 { |
3028 | 678 assert(configuration_.type() == Json::objectValue); |
679 | |
680 if (!configuration_.isMember(key)) | |
3026 | 681 { |
3028 | 682 return false; |
683 } | |
684 | |
685 if (configuration_[key].type() != Json::booleanValue) | |
686 { | |
687 LogError("The configuration option \"" + GetPath(key) + | |
688 "\" is not a Boolean as expected"); | |
3026 | 689 |
690 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
691 } | |
692 | |
3028 | 693 target = configuration_[key].asBool(); |
694 return true; | |
3026 | 695 } |
3028 | 696 |
697 | |
698 bool OrthancConfiguration::LookupFloatValue(float& target, | |
699 const std::string& key) const | |
700 { | |
701 assert(configuration_.type() == Json::objectValue); | |
702 | |
703 if (!configuration_.isMember(key)) | |
704 { | |
705 return false; | |
706 } | |
707 | |
708 switch (configuration_[key].type()) | |
709 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
710 case Json::realValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
711 target = configuration_[key].asFloat(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
712 return true; |
3028 | 713 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
714 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
715 target = static_cast<float>(configuration_[key].asInt()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
716 return true; |
3028 | 717 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
718 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
719 target = static_cast<float>(configuration_[key].asUInt()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
720 return true; |
3028 | 721 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
722 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
723 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
724 "\" is not an integer as expected"); |
3028 | 725 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
726 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 727 } |
728 } | |
3026 | 729 |
730 | |
3028 | 731 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
732 const std::string& key, | |
733 bool allowSingleString) const | |
3026 | 734 { |
3028 | 735 assert(configuration_.type() == Json::objectValue); |
736 | |
737 target.clear(); | |
738 | |
739 if (!configuration_.isMember(key)) | |
740 { | |
741 return false; | |
742 } | |
743 | |
744 switch (configuration_[key].type()) | |
745 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
746 case Json::arrayValue: |
3028 | 747 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
748 bool ok = true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
749 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
750 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
3028 | 751 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
752 if (configuration_[key][i].type() == Json::stringValue) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
753 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
754 target.push_back(configuration_[key][i].asString()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
755 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
756 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
757 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
758 ok = false; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
759 } |
3028 | 760 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
761 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
762 if (ok) |
3028 | 763 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
764 return true; |
3028 | 765 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
766 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
767 break; |
3028 | 768 } |
769 | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
770 case Json::stringValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
771 if (allowSingleString) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
772 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
773 target.push_back(configuration_[key].asString()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
774 return true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
775 } |
3028 | 776 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
777 break; |
3028 | 778 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
779 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
780 break; |
3028 | 781 } |
782 | |
3026 | 783 LogError("The configuration option \"" + GetPath(key) + |
3028 | 784 "\" is not a list of strings as expected"); |
3026 | 785 |
786 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
787 } | |
788 | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
789 |
3028 | 790 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target, |
791 const std::string& key, | |
792 bool allowSingleString) const | |
793 { | |
794 std::list<std::string> lst; | |
795 | |
796 if (LookupListOfStrings(lst, key, allowSingleString)) | |
797 { | |
798 target.clear(); | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
799 |
3028 | 800 for (std::list<std::string>::const_iterator |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
801 it = lst.begin(); it != lst.end(); ++it) |
3028 | 802 { |
803 target.insert(*it); | |
804 } | |
3026 | 805 |
3028 | 806 return true; |
807 } | |
808 else | |
809 { | |
810 return false; | |
811 } | |
3026 | 812 } |
813 | |
3028 | 814 |
815 std::string OrthancConfiguration::GetStringValue(const std::string& key, | |
816 const std::string& defaultValue) const | |
3026 | 817 { |
3028 | 818 std::string tmp; |
819 if (LookupStringValue(tmp, key)) | |
820 { | |
821 return tmp; | |
822 } | |
823 else | |
824 { | |
825 return defaultValue; | |
826 } | |
3026 | 827 } |
828 | |
829 | |
3028 | 830 int OrthancConfiguration::GetIntegerValue(const std::string& key, |
831 int defaultValue) const | |
3026 | 832 { |
3028 | 833 int tmp; |
834 if (LookupIntegerValue(tmp, key)) | |
835 { | |
836 return tmp; | |
837 } | |
838 else | |
839 { | |
840 return defaultValue; | |
841 } | |
3026 | 842 } |
843 | |
3028 | 844 |
845 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, | |
846 unsigned int defaultValue) const | |
3026 | 847 { |
3028 | 848 unsigned int tmp; |
849 if (LookupUnsignedIntegerValue(tmp, key)) | |
850 { | |
851 return tmp; | |
852 } | |
853 else | |
854 { | |
855 return defaultValue; | |
856 } | |
3026 | 857 } |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
858 |
3026 | 859 |
3028 | 860 bool OrthancConfiguration::GetBooleanValue(const std::string& key, |
861 bool defaultValue) const | |
3026 | 862 { |
3028 | 863 bool tmp; |
864 if (LookupBooleanValue(tmp, key)) | |
865 { | |
866 return tmp; | |
867 } | |
868 else | |
869 { | |
870 return defaultValue; | |
871 } | |
3026 | 872 } |
873 | |
3028 | 874 |
875 float OrthancConfiguration::GetFloatValue(const std::string& key, | |
876 float defaultValue) const | |
3026 | 877 { |
3028 | 878 float tmp; |
879 if (LookupFloatValue(tmp, key)) | |
880 { | |
881 return tmp; | |
882 } | |
883 else | |
884 { | |
885 return defaultValue; | |
886 } | |
3026 | 887 } |
888 | |
889 | |
3028 | 890 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target, |
891 const std::string& key) const | |
3026 | 892 { |
3028 | 893 assert(configuration_.type() == Json::objectValue); |
894 | |
895 target.clear(); | |
896 | |
897 if (!configuration_.isMember(key)) | |
898 { | |
899 return; | |
900 } | |
3026 | 901 |
3028 | 902 if (configuration_[key].type() != Json::objectValue) |
903 { | |
904 LogError("The configuration option \"" + GetPath(key) + | |
905 "\" is not a string as expected"); | |
906 | |
907 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
908 } | |
3026 | 909 |
3028 | 910 Json::Value::Members members = configuration_[key].getMemberNames(); |
911 | |
912 for (size_t i = 0; i < members.size(); i++) | |
3026 | 913 { |
3028 | 914 const Json::Value& value = configuration_[key][members[i]]; |
915 | |
916 if (value.type() == Json::stringValue) | |
3026 | 917 { |
3028 | 918 target[members[i]] = value.asString(); |
3026 | 919 } |
920 else | |
921 { | |
3028 | 922 LogError("The configuration option \"" + GetPath(key) + |
923 "\" is not a dictionary mapping strings to strings"); | |
924 | |
925 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
3026 | 926 } |
927 } | |
3028 | 928 } |
3026 | 929 |
3028 | 930 |
931 void OrthancImage::Clear() | |
932 { | |
933 if (image_ != NULL) | |
934 { | |
935 OrthancPluginFreeImage(GetGlobalContext(), image_); | |
936 image_ = NULL; | |
937 } | |
938 } | |
939 | |
940 | |
3236 | 941 void OrthancImage::CheckImageAvailable() const |
3028 | 942 { |
943 if (image_ == NULL) | |
944 { | |
945 LogError("Trying to access a NULL image"); | |
946 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
947 } | |
948 } | |
949 | |
950 | |
951 OrthancImage::OrthancImage() : | |
952 image_(NULL) | |
953 { | |
954 } | |
955 | |
956 | |
957 OrthancImage::OrthancImage(OrthancPluginImage* image) : | |
958 image_(image) | |
959 { | |
960 } | |
961 | |
962 | |
963 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
964 uint32_t width, | |
965 uint32_t height) | |
966 { | |
967 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); | |
968 | |
969 if (image_ == NULL) | |
970 { | |
971 LogError("Cannot create an image"); | |
972 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
973 } | |
974 } | |
975 | |
976 | |
977 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
978 uint32_t width, | |
979 uint32_t height, | |
980 uint32_t pitch, | |
981 void* buffer) | |
982 { | |
983 image_ = OrthancPluginCreateImageAccessor | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
984 (GetGlobalContext(), format, width, height, pitch, buffer); |
3028 | 985 |
986 if (image_ == NULL) | |
987 { | |
988 LogError("Cannot create an image accessor"); | |
989 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
990 } | |
991 } | |
992 | |
993 void OrthancImage::UncompressPngImage(const void* data, | |
994 size_t size) | |
995 { | |
996 Clear(); | |
997 | |
998 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); | |
999 | |
1000 if (image_ == NULL) | |
1001 { | |
1002 LogError("Cannot uncompress a PNG image"); | |
1003 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1004 } | |
1005 } | |
1006 | |
1007 | |
1008 void OrthancImage::UncompressJpegImage(const void* data, | |
1009 size_t size) | |
1010 { | |
1011 Clear(); | |
1012 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); | |
1013 if (image_ == NULL) | |
1014 { | |
1015 LogError("Cannot uncompress a JPEG image"); | |
1016 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1017 } | |
1018 } | |
1019 | |
1020 | |
1021 void OrthancImage::DecodeDicomImage(const void* data, | |
1022 size_t size, | |
1023 unsigned int frame) | |
1024 { | |
1025 Clear(); | |
1026 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); | |
1027 if (image_ == NULL) | |
1028 { | |
1029 LogError("Cannot uncompress a DICOM image"); | |
1030 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1031 } | |
1032 } | |
1033 | |
1034 | |
3236 | 1035 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const |
3028 | 1036 { |
1037 CheckImageAvailable(); | |
1038 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); | |
1039 } | |
1040 | |
1041 | |
3236 | 1042 unsigned int OrthancImage::GetWidth() const |
3028 | 1043 { |
1044 CheckImageAvailable(); | |
1045 return OrthancPluginGetImageWidth(GetGlobalContext(), image_); | |
1046 } | |
1047 | |
1048 | |
3236 | 1049 unsigned int OrthancImage::GetHeight() const |
3028 | 1050 { |
1051 CheckImageAvailable(); | |
1052 return OrthancPluginGetImageHeight(GetGlobalContext(), image_); | |
1053 } | |
1054 | |
1055 | |
3236 | 1056 unsigned int OrthancImage::GetPitch() const |
3028 | 1057 { |
1058 CheckImageAvailable(); | |
1059 return OrthancPluginGetImagePitch(GetGlobalContext(), image_); | |
1060 } | |
1061 | |
1062 | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1063 void* OrthancImage::GetBuffer() const |
3028 | 1064 { |
1065 CheckImageAvailable(); | |
1066 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); | |
1067 } | |
1068 | |
1069 | |
3236 | 1070 void OrthancImage::CompressPngImage(MemoryBuffer& target) const |
3028 | 1071 { |
1072 CheckImageAvailable(); | |
1073 | |
3320 | 1074 OrthancPlugins::MemoryBuffer answer; |
1075 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1076 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
1077 | |
3320 | 1078 target.Swap(answer); |
3028 | 1079 } |
1080 | |
1081 | |
1082 void OrthancImage::CompressJpegImage(MemoryBuffer& target, | |
3236 | 1083 uint8_t quality) const |
3028 | 1084 { |
1085 CheckImageAvailable(); | |
1086 | |
3320 | 1087 OrthancPlugins::MemoryBuffer answer; |
1088 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1089 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
1090 | |
3320 | 1091 target.Swap(answer); |
3028 | 1092 } |
1093 | |
1094 | |
3236 | 1095 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const |
3028 | 1096 { |
1097 CheckImageAvailable(); | |
1098 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), | |
1099 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | |
1100 } | |
1101 | |
1102 | |
1103 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, | |
3236 | 1104 uint8_t quality) const |
3028 | 1105 { |
1106 CheckImageAvailable(); | |
1107 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), | |
1108 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | |
1109 } | |
1110 | |
1111 | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1112 OrthancPluginImage* OrthancImage::Release() |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1113 { |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1114 CheckImageAvailable(); |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1115 OrthancPluginImage* tmp = image_; |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1116 image_ = NULL; |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1117 return tmp; |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1118 } |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3752
diff
changeset
|
1119 |
3028 | 1120 |
1121 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 | |
1122 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : | |
1123 matcher_(NULL), | |
1124 worklist_(worklist) | |
1125 { | |
1126 if (worklist_ == NULL) | |
1127 { | |
1128 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1129 } | |
1130 } | |
1131 | |
1132 | |
1133 void FindMatcher::SetupDicom(const void* query, | |
1134 uint32_t size) | |
1135 { | |
1136 worklist_ = NULL; | |
1137 | |
1138 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); | |
1139 if (matcher_ == NULL) | |
1140 { | |
1141 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1142 } | |
1143 } | |
1144 | |
1145 | |
1146 FindMatcher::~FindMatcher() | |
1147 { | |
1148 // The "worklist_" field | |
1149 | |
1150 if (matcher_ != NULL) | |
1151 { | |
1152 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); | |
1153 } | |
1154 } | |
1155 | |
1156 | |
1157 | |
1158 bool FindMatcher::IsMatch(const void* dicom, | |
1159 uint32_t size) const | |
1160 { | |
1161 int32_t result; | |
1162 | |
1163 if (matcher_ != NULL) | |
1164 { | |
1165 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); | |
1166 } | |
1167 else if (worklist_ != NULL) | |
1168 { | |
1169 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); | |
1170 } | |
1171 else | |
1172 { | |
1173 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1174 } | |
1175 | |
1176 if (result == 0) | |
1177 { | |
1178 return false; | |
1179 } | |
1180 else if (result == 1) | |
1181 { | |
1182 return true; | |
1183 } | |
1184 else | |
1185 { | |
1186 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1187 } | |
1188 } | |
1189 | |
1190 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | |
1191 | |
1192 void AnswerJson(const Json::Value& value, | |
1193 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1194 ) |
3028 | 1195 { |
1196 Json::StyledWriter writer; | |
1197 std::string bodyString = writer.write(value); | |
1198 | |
1199 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); | |
1200 } | |
1201 | |
1202 void AnswerString(const std::string& answer, | |
1203 const char* mimeType, | |
1204 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1205 ) |
3028 | 1206 { |
1207 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); | |
1208 } | |
1209 | |
1210 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) | |
1211 { | |
1212 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); | |
1213 } | |
1214 | |
1215 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) | |
1216 { | |
1217 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); | |
1218 } | |
1219 | |
1220 bool RestApiGetString(std::string& result, | |
1221 const std::string& uri, | |
1222 bool applyPlugins) | |
1223 { | |
1224 MemoryBuffer answer; | |
1225 if (!answer.RestApiGet(uri, applyPlugins)) | |
1226 { | |
1227 return false; | |
1228 } | |
1229 else | |
1230 { | |
1231 answer.ToString(result); | |
1232 return true; | |
1233 } | |
1234 } | |
1235 | |
1236 bool RestApiGetString(std::string& result, | |
1237 const std::string& uri, | |
1238 const std::map<std::string, std::string>& httpHeaders, | |
1239 bool applyPlugins) | |
1240 { | |
1241 MemoryBuffer answer; | |
1242 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) | |
1243 { | |
1244 return false; | |
1245 } | |
1246 else | |
1247 { | |
1248 answer.ToString(result); | |
1249 return true; | |
1250 } | |
1251 } | |
1252 | |
1253 | |
1254 | |
1255 bool RestApiGet(Json::Value& result, | |
1256 const std::string& uri, | |
1257 bool applyPlugins) | |
1258 { | |
1259 MemoryBuffer answer; | |
1260 | |
1261 if (!answer.RestApiGet(uri, applyPlugins)) | |
1262 { | |
1263 return false; | |
1264 } | |
1265 else | |
1266 { | |
1267 if (!answer.IsEmpty()) | |
1268 { | |
1269 answer.ToJson(result); | |
1270 } | |
1271 return true; | |
1272 } | |
1273 } | |
1274 | |
1275 | |
3478
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1276 bool RestApiPost(std::string& result, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1277 const std::string& uri, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1278 const void* body, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1279 size_t bodySize, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1280 bool applyPlugins) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1281 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1282 MemoryBuffer answer; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1283 |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1284 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1285 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1286 return false; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1287 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1288 else |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1289 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1290 if (!answer.IsEmpty()) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1291 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1292 result.assign(answer.GetData(), answer.GetSize()); |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1293 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1294 return true; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1295 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1296 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1297 |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1298 |
3028 | 1299 bool RestApiPost(Json::Value& result, |
1300 const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
1301 const void* body, |
3028 | 1302 size_t bodySize, |
1303 bool applyPlugins) | |
1304 { | |
1305 MemoryBuffer answer; | |
1306 | |
1307 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) | |
1308 { | |
1309 return false; | |
1310 } | |
1311 else | |
1312 { | |
1313 if (!answer.IsEmpty()) | |
1314 { | |
1315 answer.ToJson(result); | |
1316 } | |
1317 return true; | |
1318 } | |
1319 } | |
1320 | |
1321 | |
1322 bool RestApiPost(Json::Value& result, | |
1323 const std::string& uri, | |
1324 const Json::Value& body, | |
1325 bool applyPlugins) | |
1326 { | |
1327 Json::FastWriter writer; | |
1328 return RestApiPost(result, uri, writer.write(body), applyPlugins); | |
1329 } | |
1330 | |
1331 | |
1332 bool RestApiPut(Json::Value& result, | |
1333 const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
1334 const void* body, |
3028 | 1335 size_t bodySize, |
1336 bool applyPlugins) | |
1337 { | |
1338 MemoryBuffer answer; | |
1339 | |
1340 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) | |
1341 { | |
1342 return false; | |
1343 } | |
1344 else | |
1345 { | |
3422
8b4169a88039
ORTHANC_PLUGINS_API using visibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3421
diff
changeset
|
1346 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response |
3028 | 1347 { |
1348 answer.ToJson(result); | |
1349 } | |
1350 return true; | |
1351 } | |
1352 } | |
1353 | |
1354 | |
1355 bool RestApiPut(Json::Value& result, | |
1356 const std::string& uri, | |
1357 const Json::Value& body, | |
1358 bool applyPlugins) | |
1359 { | |
1360 Json::FastWriter writer; | |
1361 return RestApiPut(result, uri, writer.write(body), applyPlugins); | |
1362 } | |
1363 | |
1364 | |
1365 bool RestApiDelete(const std::string& uri, | |
1366 bool applyPlugins) | |
1367 { | |
1368 OrthancPluginErrorCode error; | |
1369 | |
1370 if (applyPlugins) | |
1371 { | |
1372 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); | |
1373 } | |
1374 else | |
1375 { | |
1376 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); | |
1377 } | |
1378 | |
1379 if (error == OrthancPluginErrorCode_Success) | |
1380 { | |
1381 return true; | |
1382 } | |
1383 else if (error == OrthancPluginErrorCode_UnknownResource || | |
1384 error == OrthancPluginErrorCode_InexistentItem) | |
1385 { | |
1386 return false; | |
1387 } | |
1388 else | |
1389 { | |
1390 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
1391 } | |
1392 } | |
1393 | |
1394 | |
1395 void ReportMinimalOrthancVersion(unsigned int major, | |
1396 unsigned int minor, | |
1397 unsigned int revision) | |
1398 { | |
1399 LogError("Your version of the Orthanc core (" + | |
1400 std::string(GetGlobalContext()->orthancVersion) + | |
1401 ") is too old to run this plugin (version " + | |
1402 boost::lexical_cast<std::string>(major) + "." + | |
1403 boost::lexical_cast<std::string>(minor) + "." + | |
1404 boost::lexical_cast<std::string>(revision) + | |
1405 " is required)"); | |
1406 } | |
1407 | |
1408 | |
1409 bool CheckMinimalOrthancVersion(unsigned int major, | |
1410 unsigned int minor, | |
1411 unsigned int revision) | |
1412 { | |
1413 if (!HasGlobalContext()) | |
1414 { | |
1415 LogError("Bad Orthanc context in the plugin"); | |
1416 return false; | |
1417 } | |
1418 | |
1419 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline")) | |
1420 { | |
1421 // Assume compatibility with the mainline | |
1422 return true; | |
1423 } | |
1424 | |
1425 // Parse the version of the Orthanc core | |
1426 int aa, bb, cc; | |
1427 if ( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1428 #ifdef _MSC_VER |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1429 sscanf_s |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1430 #else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1431 sscanf |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1432 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1433 (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1434 aa < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1435 bb < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1436 cc < 0) |
3028 | 1437 { |
1438 return false; | |
1439 } | |
1440 | |
1441 unsigned int a = static_cast<unsigned int>(aa); | |
1442 unsigned int b = static_cast<unsigned int>(bb); | |
1443 unsigned int c = static_cast<unsigned int>(cc); | |
1444 | |
1445 // Check the major version number | |
1446 | |
1447 if (a > major) | |
3026 | 1448 { |
1449 return true; | |
1450 } | |
1451 | |
3028 | 1452 if (a < major) |
1453 { | |
1454 return false; | |
1455 } | |
1456 | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1457 |
3028 | 1458 // Check the minor version number |
1459 assert(a == major); | |
1460 | |
1461 if (b > minor) | |
3026 | 1462 { |
1463 return true; | |
1464 } | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1465 |
3028 | 1466 if (b < minor) |
3026 | 1467 { |
3028 | 1468 return false; |
3026 | 1469 } |
1470 | |
3028 | 1471 // Check the patch level version number |
1472 assert(a == major && b == minor); | |
3026 | 1473 |
3028 | 1474 if (c >= revision) |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1475 { |
3028 | 1476 return true; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1477 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1478 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1479 { |
3028 | 1480 return false; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1481 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1482 } |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1483 |
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1484 |
3028 | 1485 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) |
1486 const char* AutodetectMimeType(const std::string& path) | |
3026 | 1487 { |
3028 | 1488 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
1489 |
3028 | 1490 if (mime == NULL) |
1491 { | |
1492 // Should never happen, just for safety | |
1493 return "application/octet-stream"; | |
1494 } | |
1495 else | |
1496 { | |
1497 return mime; | |
1498 } | |
2848 | 1499 } |
3026 | 1500 #endif |
1501 | |
1502 | |
1503 #if HAS_ORTHANC_PLUGIN_PEERS == 1 | |
3028 | 1504 size_t OrthancPeers::GetPeerIndex(const std::string& name) const |
3026 | 1505 { |
3028 | 1506 size_t index; |
1507 if (LookupName(index, name)) | |
1508 { | |
1509 return index; | |
1510 } | |
1511 else | |
1512 { | |
1513 LogError("Inexistent peer: " + name); | |
1514 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); | |
1515 } | |
3026 | 1516 } |
2059 | 1517 |
1518 | |
3028 | 1519 OrthancPeers::OrthancPeers() : |
1520 peers_(NULL), | |
1521 timeout_(0) | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1522 { |
3028 | 1523 peers_ = OrthancPluginGetPeers(GetGlobalContext()); |
3026 | 1524 |
3028 | 1525 if (peers_ == NULL) |
3026 | 1526 { |
1527 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1528 } | |
1529 | |
3028 | 1530 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); |
1531 | |
1532 for (uint32_t i = 0; i < count; i++) | |
1533 { | |
1534 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); | |
1535 if (name == NULL) | |
1536 { | |
1537 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1538 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1539 } | |
1540 | |
1541 index_[name] = i; | |
1542 } | |
1543 } | |
1544 | |
1545 | |
1546 OrthancPeers::~OrthancPeers() | |
1547 { | |
1548 if (peers_ != NULL) | |
1549 { | |
1550 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1551 } | |
1552 } | |
1553 | |
1554 | |
1555 bool OrthancPeers::LookupName(size_t& target, | |
1556 const std::string& name) const | |
1557 { | |
1558 Index::const_iterator found = index_.find(name); | |
1559 | |
1560 if (found == index_.end()) | |
1561 { | |
1562 return false; | |
1563 } | |
1564 else | |
1565 { | |
1566 target = found->second; | |
1567 return true; | |
1568 } | |
3026 | 1569 } |
3028 | 1570 |
1571 | |
1572 std::string OrthancPeers::GetPeerName(size_t index) const | |
1573 { | |
1574 if (index >= index_.size()) | |
1575 { | |
1576 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1577 } | |
1578 else | |
1579 { | |
1580 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1581 if (s == NULL) | |
1582 { | |
1583 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1584 } | |
1585 else | |
1586 { | |
1587 return s; | |
1588 } | |
1589 } | |
1590 } | |
1591 | |
1592 | |
1593 std::string OrthancPeers::GetPeerUrl(size_t index) const | |
1594 { | |
1595 if (index >= index_.size()) | |
1596 { | |
1597 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1598 } | |
1599 else | |
1600 { | |
1601 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1602 if (s == NULL) | |
1603 { | |
1604 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1605 } | |
1606 else | |
1607 { | |
1608 return s; | |
1609 } | |
1610 } | |
1611 } | |
1612 | |
1613 | |
1614 std::string OrthancPeers::GetPeerUrl(const std::string& name) const | |
1615 { | |
1616 return GetPeerUrl(GetPeerIndex(name)); | |
1617 } | |
1618 | |
1619 | |
1620 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1621 size_t index, | |
1622 const std::string& key) const | |
1623 { | |
1624 if (index >= index_.size()) | |
1625 { | |
1626 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1627 } | |
1628 else | |
1629 { | |
1630 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str()); | |
1631 if (s == NULL) | |
1632 { | |
1633 return false; | |
1634 } | |
1635 else | |
1636 { | |
1637 value.assign(s); | |
1638 return true; | |
1639 } | |
1640 } | |
1641 } | |
1642 | |
1643 | |
1644 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1645 const std::string& peer, | |
1646 const std::string& key) const | |
1647 { | |
1648 return LookupUserProperty(value, GetPeerIndex(peer), key); | |
1649 } | |
3026 | 1650 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1651 |
3028 | 1652 bool OrthancPeers::DoGet(MemoryBuffer& target, |
1653 size_t index, | |
1654 const std::string& uri) const | |
1655 { | |
1656 if (index >= index_.size()) | |
1657 { | |
1658 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1659 } | |
1660 | |
3320 | 1661 OrthancPlugins::MemoryBuffer answer; |
3028 | 1662 uint16_t status; |
1663 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1664 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1665 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1666 0, NULL, NULL, NULL, 0, timeout_); |
3028 | 1667 |
1668 if (code == OrthancPluginErrorCode_Success) | |
1669 { | |
3320 | 1670 target.Swap(answer); |
3028 | 1671 return (status == 200); |
1672 } | |
1673 else | |
1674 { | |
1675 return false; | |
1676 } | |
1677 } | |
1678 | |
1679 | |
1680 bool OrthancPeers::DoGet(MemoryBuffer& target, | |
1681 const std::string& name, | |
1682 const std::string& uri) const | |
1683 { | |
1684 size_t index; | |
1685 return (LookupName(index, name) && | |
1686 DoGet(target, index, uri)); | |
1687 } | |
1688 | |
1689 | |
1690 bool OrthancPeers::DoGet(Json::Value& target, | |
1691 size_t index, | |
1692 const std::string& uri) const | |
1693 { | |
1694 MemoryBuffer buffer; | |
1695 | |
1696 if (DoGet(buffer, index, uri)) | |
1697 { | |
1698 buffer.ToJson(target); | |
1699 return true; | |
1700 } | |
1701 else | |
1702 { | |
1703 return false; | |
1704 } | |
1705 } | |
1706 | |
1707 | |
1708 bool OrthancPeers::DoGet(Json::Value& target, | |
1709 const std::string& name, | |
1710 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1711 { |
3028 | 1712 MemoryBuffer buffer; |
1713 | |
1714 if (DoGet(buffer, name, uri)) | |
1715 { | |
1716 buffer.ToJson(target); | |
1717 return true; | |
1718 } | |
1719 else | |
1720 { | |
1721 return false; | |
1722 } | |
1723 } | |
1724 | |
1725 | |
1726 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1727 const std::string& name, | |
1728 const std::string& uri, | |
1729 const std::string& body) const | |
1730 { | |
1731 size_t index; | |
1732 return (LookupName(index, name) && | |
1733 DoPost(target, index, uri, body)); | |
1734 } | |
1735 | |
1736 | |
1737 bool OrthancPeers::DoPost(Json::Value& target, | |
1738 size_t index, | |
1739 const std::string& uri, | |
1740 const std::string& body) const | |
1741 { | |
1742 MemoryBuffer buffer; | |
1743 | |
1744 if (DoPost(buffer, index, uri, body)) | |
1745 { | |
1746 buffer.ToJson(target); | |
1747 return true; | |
1748 } | |
1749 else | |
1750 { | |
1751 return false; | |
1752 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1753 } |
3028 | 1754 |
1755 | |
1756 bool OrthancPeers::DoPost(Json::Value& target, | |
1757 const std::string& name, | |
1758 const std::string& uri, | |
1759 const std::string& body) const | |
1760 { | |
1761 MemoryBuffer buffer; | |
1762 | |
1763 if (DoPost(buffer, name, uri, body)) | |
1764 { | |
1765 buffer.ToJson(target); | |
1766 return true; | |
1767 } | |
1768 else | |
1769 { | |
1770 return false; | |
1771 } | |
1772 } | |
1773 | |
1774 | |
1775 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1776 size_t index, | |
1777 const std::string& uri, | |
1778 const std::string& body) const | |
1779 { | |
1780 if (index >= index_.size()) | |
1781 { | |
1782 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1783 } | |
1784 | |
3320 | 1785 OrthancPlugins::MemoryBuffer answer; |
3028 | 1786 uint16_t status; |
1787 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1788 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1789 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1790 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3028 | 1791 |
1792 if (code == OrthancPluginErrorCode_Success) | |
1793 { | |
3320 | 1794 target.Swap(answer); |
3028 | 1795 return (status == 200); |
1796 } | |
1797 else | |
1798 { | |
1799 return false; | |
1800 } | |
1801 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1802 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1803 |
3028 | 1804 bool OrthancPeers::DoPut(size_t index, |
1805 const std::string& uri, | |
1806 const std::string& body) const | |
1807 { | |
1808 if (index >= index_.size()) | |
1809 { | |
1810 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1811 } | |
1812 | |
3320 | 1813 OrthancPlugins::MemoryBuffer answer; |
3028 | 1814 uint16_t status; |
1815 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1816 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1817 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1818 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3026 | 1819 |
3028 | 1820 if (code == OrthancPluginErrorCode_Success) |
1821 { | |
1822 return (status == 200); | |
1823 } | |
1824 else | |
1825 { | |
1826 return false; | |
1827 } | |
1828 } | |
1829 | |
1830 | |
1831 bool OrthancPeers::DoPut(const std::string& name, | |
1832 const std::string& uri, | |
1833 const std::string& body) const | |
1834 { | |
1835 size_t index; | |
1836 return (LookupName(index, name) && | |
1837 DoPut(index, uri, body)); | |
1838 } | |
1839 | |
1840 | |
1841 bool OrthancPeers::DoDelete(size_t index, | |
1842 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1843 { |
3028 | 1844 if (index >= index_.size()) |
1845 { | |
1846 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1847 } | |
1848 | |
3320 | 1849 OrthancPlugins::MemoryBuffer answer; |
3028 | 1850 uint16_t status; |
1851 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3320 | 1852 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1853 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | |
1854 0, NULL, NULL, NULL, 0, timeout_); | |
3028 | 1855 |
1856 if (code == OrthancPluginErrorCode_Success) | |
1857 { | |
1858 return (status == 200); | |
1859 } | |
1860 else | |
1861 { | |
1862 return false; | |
1863 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1864 } |
3028 | 1865 |
1866 | |
1867 bool OrthancPeers::DoDelete(const std::string& name, | |
1868 const std::string& uri) const | |
3026 | 1869 { |
3028 | 1870 size_t index; |
1871 return (LookupName(index, name) && | |
1872 DoDelete(index, uri)); | |
1873 } | |
1874 #endif | |
1875 | |
1876 | |
1877 | |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1878 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1879 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1880 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1881 ** JOBS |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1882 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1883 |
3028 | 1884 #if HAS_ORTHANC_PLUGIN_JOB == 1 |
1885 void OrthancJob::CallbackFinalize(void* job) | |
1886 { | |
1887 if (job != NULL) | |
1888 { | |
1889 delete reinterpret_cast<OrthancJob*>(job); | |
1890 } | |
3026 | 1891 } |
3028 | 1892 |
1893 | |
1894 float OrthancJob::CallbackGetProgress(void* job) | |
1895 { | |
1896 assert(job != NULL); | |
1897 | |
1898 try | |
1899 { | |
1900 return reinterpret_cast<OrthancJob*>(job)->progress_; | |
1901 } | |
1902 catch (...) | |
1903 { | |
1904 return 0; | |
1905 } | |
1906 } | |
1907 | |
1908 | |
1909 const char* OrthancJob::CallbackGetContent(void* job) | |
1910 { | |
1911 assert(job != NULL); | |
1912 | |
1913 try | |
1914 { | |
1915 return reinterpret_cast<OrthancJob*>(job)->content_.c_str(); | |
1916 } | |
1917 catch (...) | |
1918 { | |
1919 return 0; | |
1920 } | |
1921 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1922 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1923 |
3028 | 1924 const char* OrthancJob::CallbackGetSerialized(void* job) |
1925 { | |
1926 assert(job != NULL); | |
1927 | |
1928 try | |
1929 { | |
1930 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job); | |
1931 | |
1932 if (tmp.hasSerialized_) | |
1933 { | |
1934 return tmp.serialized_.c_str(); | |
1935 } | |
1936 else | |
1937 { | |
1938 return NULL; | |
1939 } | |
1940 } | |
1941 catch (...) | |
1942 { | |
1943 return 0; | |
1944 } | |
1945 } | |
1946 | |
1947 | |
1948 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | |
1949 { | |
1950 assert(job != NULL); | |
1951 | |
1952 try | |
1953 { | |
1954 return reinterpret_cast<OrthancJob*>(job)->Step(); | |
1955 } | |
1956 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) | |
1957 { | |
1958 return OrthancPluginJobStepStatus_Failure; | |
1959 } | |
1960 catch (...) | |
1961 { | |
1962 return OrthancPluginJobStepStatus_Failure; | |
1963 } | |
1964 } | |
1965 | |
1966 | |
1967 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, | |
1968 OrthancPluginJobStopReason reason) | |
1969 { | |
1970 assert(job != NULL); | |
1971 | |
1972 try | |
1973 { | |
1974 reinterpret_cast<OrthancJob*>(job)->Stop(reason); | |
1975 return OrthancPluginErrorCode_Success; | |
1976 } | |
1977 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1978 { | |
1979 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1980 } | |
1981 catch (...) | |
1982 { | |
1983 return OrthancPluginErrorCode_Plugin; | |
1984 } | |
1985 } | |
1986 | |
1987 | |
1988 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1989 { |
3028 | 1990 assert(job != NULL); |
1991 | |
1992 try | |
1993 { | |
1994 reinterpret_cast<OrthancJob*>(job)->Reset(); | |
1995 return OrthancPluginErrorCode_Success; | |
1996 } | |
1997 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1998 { | |
1999 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2000 } | |
2001 catch (...) | |
2002 { | |
2003 return OrthancPluginErrorCode_Plugin; | |
2004 } | |
2005 } | |
2006 | |
2007 | |
2008 void OrthancJob::ClearContent() | |
2009 { | |
2010 Json::Value empty = Json::objectValue; | |
2011 UpdateContent(empty); | |
2012 } | |
2013 | |
2014 | |
2015 void OrthancJob::UpdateContent(const Json::Value& content) | |
2016 { | |
2017 if (content.type() != Json::objectValue) | |
2018 { | |
2019 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
2020 } | |
2021 else | |
2022 { | |
2023 Json::FastWriter writer; | |
2024 content_ = writer.write(content); | |
2025 } | |
2026 } | |
2027 | |
2028 | |
2029 void OrthancJob::ClearSerialized() | |
2030 { | |
2031 hasSerialized_ = false; | |
2032 serialized_.clear(); | |
3026 | 2033 } |
3028 | 2034 |
2035 | |
2036 void OrthancJob::UpdateSerialized(const Json::Value& serialized) | |
2037 { | |
2038 if (serialized.type() != Json::objectValue) | |
2039 { | |
2040 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
2041 } | |
2042 else | |
2043 { | |
2044 Json::FastWriter writer; | |
2045 serialized_ = writer.write(serialized); | |
2046 hasSerialized_ = true; | |
2047 } | |
2048 } | |
2049 | |
2050 | |
2051 void OrthancJob::UpdateProgress(float progress) | |
3026 | 2052 { |
3028 | 2053 if (progress < 0 || |
2054 progress > 1) | |
2055 { | |
2056 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2057 } | |
2058 | |
2059 progress_ = progress; | |
2060 } | |
2061 | |
2062 | |
2063 OrthancJob::OrthancJob(const std::string& jobType) : | |
2064 jobType_(jobType), | |
2065 progress_(0) | |
2066 { | |
2067 ClearContent(); | |
2068 ClearSerialized(); | |
2069 } | |
2070 | |
2071 | |
2072 OrthancPluginJob* OrthancJob::Create(OrthancJob* job) | |
2073 { | |
2074 if (job == NULL) | |
2075 { | |
2076 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | |
2077 } | |
2078 | |
2079 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2080 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2081 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2082 CallbackStep, CallbackStop, CallbackReset); |
3028 | 2083 |
2084 if (orthanc == NULL) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2085 { |
3026 | 2086 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2087 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2088 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2089 { |
3028 | 2090 return orthanc; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2091 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2092 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
2093 |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2094 |
3028 | 2095 std::string OrthancJob::Submit(OrthancJob* job, |
2096 int priority) | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2097 { |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2098 if (job == NULL) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2099 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2100 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2101 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2102 |
3028 | 2103 OrthancPluginJob* orthanc = Create(job); |
2104 | |
2105 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); | |
2106 | |
2107 if (id == NULL) | |
3026 | 2108 { |
3028 | 2109 LogError("Plugin cannot submit job"); |
2110 OrthancPluginFreeJob(GetGlobalContext(), orthanc); | |
3026 | 2111 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2112 } | |
2113 else | |
2114 { | |
3028 | 2115 std::string tmp(id); |
2116 tmp.assign(id); | |
2117 OrthancPluginFreeString(GetGlobalContext(), id); | |
3026 | 2118 |
3028 | 2119 return tmp; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2120 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2121 } |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2122 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2123 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2124 void OrthancJob::SubmitAndWait(Json::Value& result, |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2125 OrthancJob* job /* takes ownership */, |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2126 int priority) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2127 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2128 std::string id = Submit(job, priority); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2129 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2130 for (;;) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2131 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2132 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2133 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2134 Json::Value status; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2135 if (!RestApiGet(status, "/jobs/" + id, false) || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2136 !status.isMember("State") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2137 status["State"].type() != Json::stringValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2138 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2139 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2140 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2141 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2142 const std::string state = status["State"].asString(); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2143 if (state == "Success") |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2144 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2145 if (status.isMember("Content")) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2146 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2147 result = status["Content"]; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2148 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2149 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2150 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2151 result = Json::objectValue; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2152 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2153 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2154 return; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2155 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2156 else if (state == "Running") |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2157 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2158 continue; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2159 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2160 else if (!status.isMember("ErrorCode") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2161 status["ErrorCode"].type() != Json::intValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2162 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2163 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2164 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2165 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2166 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2167 if (!status.isMember("ErrorDescription") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2168 status["ErrorDescription"].type() != Json::stringValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2169 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2170 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2171 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2172 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2173 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2174 #if HAS_ORTHANC_EXCEPTION == 1 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2175 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()), |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2176 status["ErrorDescription"].asString()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2177 #else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2178 LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2179 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2180 #endif |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2181 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2182 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2183 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2184 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2185 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2186 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2187 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2188 const Json::Value& body, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2189 OrthancJob* job) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2190 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2191 static const char* KEY_SYNCHRONOUS = "Synchronous"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2192 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2193 static const char* KEY_PRIORITY = "Priority"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2194 |
3749
edabdf07ee83
replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3669
diff
changeset
|
2195 boost::movelib::unique_ptr<OrthancJob> protection(job); |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2196 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2197 if (body.type() != Json::objectValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2198 { |
3669 | 2199 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2200 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2201 "Expected a JSON object in the body"); |
3669 | 2202 #else |
2203 LogError("Expected a JSON object in the body"); | |
2204 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2205 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2206 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2207 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2208 bool synchronous = true; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2209 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2210 if (body.isMember(KEY_SYNCHRONOUS)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2211 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2212 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2213 { |
3669 | 2214 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2215 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2216 "Option \"" + std::string(KEY_SYNCHRONOUS) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2217 "\" must be Boolean"); |
3669 | 2218 #else |
2219 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); | |
2220 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2221 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2222 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2223 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2224 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2225 synchronous = body[KEY_SYNCHRONOUS].asBool(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2226 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2227 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2228 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2229 if (body.isMember(KEY_ASYNCHRONOUS)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2230 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2231 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2232 { |
3669 | 2233 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2234 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2235 "Option \"" + std::string(KEY_ASYNCHRONOUS) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2236 "\" must be Boolean"); |
3669 | 2237 #else |
2238 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); | |
2239 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2240 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2241 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2242 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2243 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2244 synchronous = !body[KEY_ASYNCHRONOUS].asBool(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2245 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2246 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2247 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2248 int priority = 0; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2249 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2250 if (body.isMember(KEY_PRIORITY)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2251 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2252 if (body[KEY_PRIORITY].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2253 { |
3669 | 2254 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2255 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2256 "Option \"" + std::string(KEY_PRIORITY) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2257 "\" must be an integer"); |
3669 | 2258 #else |
2259 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); | |
2260 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2261 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2262 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2263 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2264 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2265 priority = !body[KEY_PRIORITY].asInt(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2266 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2267 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2268 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2269 Json::Value result; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2270 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2271 if (synchronous) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2272 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2273 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2274 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2275 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2276 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2277 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2278 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2279 result = Json::objectValue; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2280 result["ID"] = id; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2281 result["Path"] = "/jobs/" + id; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2282 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2283 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2284 std::string s = result.toStyledString(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2285 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2286 s.size(), "application/json"); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2287 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2288 |
2817
473bf302d629
C++ wrappers around OrthancPluginJob and OrthancPluginPeers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2803
diff
changeset
|
2289 #endif |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2290 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2291 |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2292 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2293 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2294 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2295 ** METRICS |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2296 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2297 |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2298 #if HAS_ORTHANC_PLUGIN_METRICS == 1 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2299 MetricsTimer::MetricsTimer(const char* name) : |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2300 name_(name) |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2301 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2302 start_ = boost::posix_time::microsec_clock::universal_time(); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2303 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2304 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2305 MetricsTimer::~MetricsTimer() |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2306 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2307 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time(); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2308 const boost::posix_time::time_duration diff = stop - start_; |
3418 | 2309 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()), |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2310 OrthancPluginMetricsType_Timer); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2311 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2312 #endif |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2313 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2314 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2315 |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2316 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2317 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2318 ** HTTP CLIENT |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2319 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2320 |
3388 | 2321 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2322 class HttpClient::RequestBodyWrapper : public boost::noncopyable |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2323 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2324 private: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2325 static RequestBodyWrapper& GetObject(void* body) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2326 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2327 assert(body != NULL); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2328 return *reinterpret_cast<RequestBodyWrapper*>(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2329 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2330 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2331 IRequestBody& body_; |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2332 bool done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2333 std::string chunk_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2334 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2335 public: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2336 RequestBodyWrapper(IRequestBody& body) : |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2337 body_(body), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2338 done_(false) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2339 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2340 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2341 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2342 static uint8_t IsDone(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2343 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2344 return GetObject(body).done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2345 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2346 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2347 static const void* GetChunkData(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2348 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2349 return GetObject(body).chunk_.c_str(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2350 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2351 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2352 static uint32_t GetChunkSize(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2353 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2354 return static_cast<uint32_t>(GetObject(body).chunk_.size()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2355 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2356 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2357 static OrthancPluginErrorCode Next(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2358 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2359 RequestBodyWrapper& that = GetObject(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2360 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2361 if (that.done_) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2362 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2363 return OrthancPluginErrorCode_BadSequenceOfCalls; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2364 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2365 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2366 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2367 try |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2368 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2369 that.done_ = !that.body_.ReadNextChunk(that.chunk_); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2370 return OrthancPluginErrorCode_Success; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2371 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2372 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2373 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2374 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2375 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2376 catch (...) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2377 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2378 return OrthancPluginErrorCode_InternalError; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2379 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2380 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2381 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2382 }; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2383 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2384 |
3413 | 2385 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2386 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2387 const char* key, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2388 const char* value) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2389 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2390 assert(answer != NULL && key != NULL && value != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2391 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2392 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2393 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2394 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2395 return OrthancPluginErrorCode_Success; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2396 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2397 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2398 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2399 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2400 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2401 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2402 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2403 return OrthancPluginErrorCode_Plugin; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2404 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2405 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2406 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2407 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2408 |
3413 | 2409 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2410 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2411 const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2412 uint32_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2413 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2414 assert(answer != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2415 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2416 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2417 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2418 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2419 return OrthancPluginErrorCode_Success; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2420 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2421 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2422 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2423 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2424 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2425 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2426 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2427 return OrthancPluginErrorCode_Plugin; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2428 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2429 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2430 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2431 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2432 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2433 HttpClient::HttpClient() : |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2434 httpStatus_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2435 method_(OrthancPluginHttpMethod_Get), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2436 timeout_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2437 pkcs11_(false), |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2438 chunkedBody_(NULL), |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2439 allowChunkedTransfers_(true) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2440 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2441 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2442 |
3426
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2443 |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2444 void HttpClient::AddHeaders(const HttpHeaders& headers) |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2445 { |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2446 for (HttpHeaders::const_iterator it = headers.begin(); |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2447 it != headers.end(); ++it) |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2448 { |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2449 headers_[it->first] = it->second; |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2450 } |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2451 } |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2452 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2453 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2454 void HttpClient::SetCredentials(const std::string& username, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2455 const std::string& password) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2456 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2457 username_ = username; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2458 password_ = password; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2459 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2460 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2461 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2462 void HttpClient::ClearCredentials() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2463 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2464 username_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2465 password_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2466 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2467 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2468 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2469 void HttpClient::SetCertificate(const std::string& certificateFile, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2470 const std::string& keyFile, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2471 const std::string& keyPassword) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2472 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2473 certificateFile_ = certificateFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2474 certificateKeyFile_ = keyFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2475 certificateKeyPassword_ = keyPassword; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2476 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2477 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2478 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2479 void HttpClient::ClearCertificate() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2480 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2481 certificateFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2482 certificateKeyFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2483 certificateKeyPassword_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2484 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2485 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2486 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2487 void HttpClient::ClearBody() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2488 { |
3413 | 2489 fullBody_.clear(); |
2490 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2491 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2492 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2493 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2494 void HttpClient::SwapBody(std::string& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2495 { |
3413 | 2496 fullBody_.swap(body); |
2497 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2498 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2499 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2500 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2501 void HttpClient::SetBody(const std::string& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2502 { |
3413 | 2503 fullBody_ = body; |
2504 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2505 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2506 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2507 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2508 void HttpClient::SetBody(IRequestBody& body) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2509 { |
3413 | 2510 fullBody_.clear(); |
2511 chunkedBody_ = &body; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2512 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2513 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2514 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2515 namespace |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2516 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2517 class HeadersWrapper : public boost::noncopyable |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2518 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2519 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2520 std::vector<const char*> headersKeys_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2521 std::vector<const char*> headersValues_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2522 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2523 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2524 HeadersWrapper(const HttpClient::HttpHeaders& headers) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2525 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2526 headersKeys_.reserve(headers.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2527 headersValues_.reserve(headers.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2528 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2529 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2530 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2531 headersKeys_.push_back(it->first.c_str()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2532 headersValues_.push_back(it->second.c_str()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2533 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2534 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2535 |
3394 | 2536 void AddStaticString(const char* key, |
2537 const char* value) | |
2538 { | |
2539 headersKeys_.push_back(key); | |
2540 headersValues_.push_back(value); | |
2541 } | |
2542 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2543 uint32_t GetCount() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2544 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2545 return headersKeys_.size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2546 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2547 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2548 const char* const* GetKeys() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2549 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2550 return headersKeys_.empty() ? NULL : &headersKeys_[0]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2551 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2552 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2553 const char* const* GetValues() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2554 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2555 return headersValues_.empty() ? NULL : &headersValues_[0]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2556 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2557 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2558 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2559 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2560 class MemoryRequestBody : public HttpClient::IRequestBody |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2561 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2562 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2563 std::string body_; |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2564 bool done_; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2565 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2566 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2567 MemoryRequestBody(const std::string& body) : |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2568 body_(body), |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2569 done_(false) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2570 { |
3434 | 2571 if (body_.empty()) |
2572 { | |
2573 done_ = true; | |
2574 } | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2575 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2576 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2577 virtual bool ReadNextChunk(std::string& chunk) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2578 { |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2579 if (done_) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2580 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2581 return false; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2582 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2583 else |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2584 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2585 chunk.swap(body_); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2586 done_ = true; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2587 return true; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2588 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2589 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2590 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2591 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2592 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2593 // This class mimics Orthanc::ChunkedBuffer |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2594 class ChunkedBuffer : public boost::noncopyable |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2595 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2596 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2597 typedef std::list<std::string*> Content; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2598 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2599 Content content_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2600 size_t size_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2601 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2602 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2603 ChunkedBuffer() : |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2604 size_(0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2605 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2606 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2607 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2608 ~ChunkedBuffer() |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2609 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2610 Clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2611 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2612 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2613 void Clear() |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2614 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2615 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2616 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2617 assert(*it != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2618 delete *it; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2619 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2620 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2621 content_.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2622 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2623 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2624 void Flatten(std::string& target) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2625 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2626 target.resize(size_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2627 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2628 size_t pos = 0; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2629 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2630 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2631 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2632 assert(*it != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2633 size_t s = (*it)->size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2634 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2635 if (s != 0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2636 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2637 memcpy(&target[pos], (*it)->c_str(), s); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2638 pos += s; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2639 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2640 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2641 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2642 assert(size_ == 0 || |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2643 pos == target.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2644 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2645 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2646 void AddChunk(const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2647 size_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2648 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2649 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2650 size_ += size; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2651 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2652 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2653 void AddChunk(const std::string& chunk) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2654 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2655 content_.push_back(new std::string(chunk)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2656 size_ += chunk.size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2657 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2658 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2659 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2660 |
3413 | 2661 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2662 class MemoryAnswer : public HttpClient::IAnswer |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2663 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2664 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2665 HttpClient::HttpHeaders headers_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2666 ChunkedBuffer body_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2667 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2668 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2669 const HttpClient::HttpHeaders& GetHeaders() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2670 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2671 return headers_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2672 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2673 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2674 const ChunkedBuffer& GetBody() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2675 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2676 return body_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2677 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2678 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2679 virtual void AddHeader(const std::string& key, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2680 const std::string& value) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2681 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2682 headers_[key] = value; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2683 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2684 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2685 virtual void AddChunk(const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2686 size_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2687 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2688 body_.AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2689 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2690 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2691 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2692 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2693 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2694 |
3413 | 2695 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2696 void HttpClient::ExecuteWithStream(uint16_t& httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2697 IAnswer& answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2698 IRequestBody& body) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2699 { |
3394 | 2700 HeadersWrapper h(headers_); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2701 |
3434 | 2702 if (method_ == OrthancPluginHttpMethod_Post || |
2703 method_ == OrthancPluginHttpMethod_Put) | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2704 { |
3434 | 2705 // Automatically set the "Transfer-Encoding" header if absent |
2706 bool found = false; | |
2707 | |
2708 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) | |
3394 | 2709 { |
3434 | 2710 if (boost::iequals(it->first, "Transfer-Encoding")) |
2711 { | |
2712 found = true; | |
2713 break; | |
2714 } | |
3394 | 2715 } |
3434 | 2716 |
2717 if (!found) | |
2718 { | |
2719 h.AddStaticString("Transfer-Encoding", "chunked"); | |
2720 } | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2721 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2722 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2723 RequestBodyWrapper request(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2724 |
3413 | 2725 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2726 GetGlobalContext(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2727 &answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2728 AnswerAddChunkCallback, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2729 AnswerAddHeaderCallback, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2730 &httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2731 method_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2732 url_.c_str(), |
3394 | 2733 h.GetCount(), |
2734 h.GetKeys(), | |
2735 h.GetValues(), | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2736 &request, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2737 RequestBodyWrapper::IsDone, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2738 RequestBodyWrapper::GetChunkData, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2739 RequestBodyWrapper::GetChunkSize, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2740 RequestBodyWrapper::Next, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2741 username_.empty() ? NULL : username_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2742 password_.empty() ? NULL : password_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2743 timeout_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2744 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2745 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2746 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2747 pkcs11_ ? 1 : 0); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2748 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2749 if (error != OrthancPluginErrorCode_Success) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2750 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2751 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2752 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2753 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2754 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2755 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2756 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2757 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2758 HttpHeaders& answerHeaders, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2759 std::string& answerBody, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2760 const std::string& body) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2761 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2762 HeadersWrapper headers(headers_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2763 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2764 MemoryBuffer answerBodyBuffer, answerHeadersBuffer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2765 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2766 OrthancPluginErrorCode error = OrthancPluginHttpClient( |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2767 GetGlobalContext(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2768 *answerBodyBuffer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2769 *answerHeadersBuffer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2770 &httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2771 method_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2772 url_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2773 headers.GetCount(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2774 headers.GetKeys(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2775 headers.GetValues(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2776 body.empty() ? NULL : body.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2777 body.size(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2778 username_.empty() ? NULL : username_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2779 password_.empty() ? NULL : password_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2780 timeout_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2781 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2782 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2783 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2784 pkcs11_ ? 1 : 0); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2785 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2786 if (error != OrthancPluginErrorCode_Success) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2787 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2788 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2789 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2790 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2791 Json::Value v; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2792 answerHeadersBuffer.ToJson(v); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2793 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2794 if (v.type() != Json::objectValue) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2795 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2796 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2797 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2798 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2799 Json::Value::Members members = v.getMemberNames(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2800 answerHeaders.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2801 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2802 for (size_t i = 0; i < members.size(); i++) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2803 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2804 const Json::Value& h = v[members[i]]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2805 if (h.type() != Json::stringValue) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2806 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2807 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2808 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2809 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2810 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2811 answerHeaders[members[i]] = h.asString(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2812 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2813 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2814 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2815 answerBodyBuffer.ToString(answerBody); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2816 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2817 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2818 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2819 void HttpClient::Execute(IAnswer& answer) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2820 { |
3438
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2821 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2822 if (allowChunkedTransfers_) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2823 { |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2824 if (chunkedBody_ != NULL) |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2825 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2826 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2827 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2828 else |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2829 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2830 MemoryRequestBody wrapper(fullBody_); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2831 ExecuteWithStream(httpStatus_, answer, wrapper); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2832 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2833 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2834 return; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2835 } |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2836 #endif |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2837 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2838 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2839 // transfers are disabled. This results in higher memory usage |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2840 // (all chunks from the answer body are sent at once) |
3438
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2841 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2842 HttpHeaders answerHeaders; |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2843 std::string answerBody; |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2844 Execute(answerHeaders, answerBody); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2845 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2846 for (HttpHeaders::const_iterator it = answerHeaders.begin(); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2847 it != answerHeaders.end(); ++it) |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2848 { |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2849 answer.AddHeader(it->first, it->second); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2850 } |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2851 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2852 if (!answerBody.empty()) |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2853 { |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2854 answer.AddChunk(answerBody.c_str(), answerBody.size()); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2855 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2856 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2857 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2858 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2859 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2860 std::string& answerBody /* out */) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2861 { |
3413 | 2862 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2863 if (allowChunkedTransfers_) |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2864 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2865 MemoryAnswer answer; |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2866 Execute(answer); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2867 answerHeaders = answer.GetHeaders(); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2868 answer.GetBody().Flatten(answerBody); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2869 return; |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2870 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2871 #endif |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2872 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2873 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2874 // transfers are disabled. This results in higher memory usage |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2875 // (all chunks from the request body are sent at once) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2876 |
3413 | 2877 if (chunkedBody_ != NULL) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2878 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2879 ChunkedBuffer buffer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2880 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2881 std::string chunk; |
3413 | 2882 while (chunkedBody_->ReadNextChunk(chunk)) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2883 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2884 buffer.AddChunk(chunk); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2885 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2886 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2887 std::string body; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2888 buffer.Flatten(body); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2889 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2890 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2891 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2892 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2893 { |
3413 | 2894 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2895 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2896 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2897 |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2898 |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2899 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2900 Json::Value& answerBody /* out */) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2901 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2902 std::string body; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2903 Execute(answerHeaders, body); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2904 |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2905 Json::Reader reader; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2906 if (!reader.parse(body, answerBody)) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2907 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2908 LogError("Cannot convert HTTP answer body to JSON"); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2909 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2910 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2911 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2912 |
3434 | 2913 |
2914 void HttpClient::Execute() | |
2915 { | |
2916 HttpHeaders answerHeaders; | |
2917 std::string body; | |
2918 Execute(answerHeaders, body); | |
2919 } | |
2920 | |
3388 | 2921 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ |
3416 | 2922 |
2923 | |
2924 | |
2925 | |
2926 | |
2927 /****************************************************************** | |
2928 ** CHUNKED HTTP SERVER | |
2929 ******************************************************************/ | |
2930 | |
2931 namespace Internals | |
2932 { | |
2933 void NullRestCallback(OrthancPluginRestOutput* output, | |
2934 const char* url, | |
2935 const OrthancPluginHttpRequest* request) | |
2936 { | |
2937 } | |
2938 | |
2939 IChunkedRequestReader *NullChunkedRestCallback(const char* url, | |
2940 const OrthancPluginHttpRequest* request) | |
2941 { | |
2942 return NULL; | |
2943 } | |
2944 | |
2945 | |
2946 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 | |
2947 | |
2948 OrthancPluginErrorCode ChunkedRequestReaderAddChunk( | |
2949 OrthancPluginServerChunkedRequestReader* reader, | |
2950 const void* data, | |
2951 uint32_t size) | |
2952 { | |
2953 try | |
2954 { | |
2955 if (reader == NULL) | |
2956 { | |
2957 return OrthancPluginErrorCode_InternalError; | |
2958 } | |
2959 | |
2960 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size); | |
2961 return OrthancPluginErrorCode_Success; | |
2962 } | |
2963 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2964 { | |
2965 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2966 } | |
2967 catch (boost::bad_lexical_cast&) | |
2968 { | |
2969 return OrthancPluginErrorCode_BadFileFormat; | |
2970 } | |
2971 catch (...) | |
2972 { | |
2973 return OrthancPluginErrorCode_Plugin; | |
2974 } | |
2975 } | |
2976 | |
2977 | |
2978 OrthancPluginErrorCode ChunkedRequestReaderExecute( | |
2979 OrthancPluginServerChunkedRequestReader* reader, | |
2980 OrthancPluginRestOutput* output) | |
2981 { | |
2982 try | |
2983 { | |
2984 if (reader == NULL) | |
2985 { | |
2986 return OrthancPluginErrorCode_InternalError; | |
2987 } | |
2988 | |
2989 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output); | |
2990 return OrthancPluginErrorCode_Success; | |
2991 } | |
2992 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2993 { | |
2994 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2995 } | |
2996 catch (boost::bad_lexical_cast&) | |
2997 { | |
2998 return OrthancPluginErrorCode_BadFileFormat; | |
2999 } | |
3000 catch (...) | |
3001 { | |
3002 return OrthancPluginErrorCode_Plugin; | |
3003 } | |
3004 } | |
3005 | |
3006 | |
3007 void ChunkedRequestReaderFinalize( | |
3008 OrthancPluginServerChunkedRequestReader* reader) | |
3009 { | |
3010 if (reader != NULL) | |
3011 { | |
3012 delete reinterpret_cast<IChunkedRequestReader*>(reader); | |
3013 } | |
3014 } | |
3015 | |
3016 #else | |
3017 | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3018 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3019 const char* url, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3020 const OrthancPluginHttpRequest* request, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3021 RestCallback GetHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3022 ChunkedRestCallback PostHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3023 RestCallback DeleteHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3024 ChunkedRestCallback PutHandler) |
3416 | 3025 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3026 try |
3416 | 3027 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3028 std::string allowed; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3029 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3030 if (GetHandler != Internals::NullRestCallback) |
3416 | 3031 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3032 allowed += "GET"; |
3416 | 3033 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3034 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3035 if (PostHandler != Internals::NullChunkedRestCallback) |
3416 | 3036 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3037 if (!allowed.empty()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3038 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3039 allowed += ","; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3040 } |
3416 | 3041 |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3042 allowed += "POST"; |
3416 | 3043 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3044 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3045 if (DeleteHandler != Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3046 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3047 if (!allowed.empty()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3048 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3049 allowed += ","; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3050 } |
3416 | 3051 |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3052 allowed += "DELETE"; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3053 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3054 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3055 if (PutHandler != Internals::NullChunkedRestCallback) |
3416 | 3056 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3057 if (!allowed.empty()) |
3416 | 3058 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3059 allowed += ","; |
3416 | 3060 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3061 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3062 allowed += "PUT"; |
3416 | 3063 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3064 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3065 switch (request->method) |
3416 | 3066 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3067 case OrthancPluginHttpMethod_Get: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3068 if (GetHandler == Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3069 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3070 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3071 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3072 else |
3416 | 3073 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3074 GetHandler(output, url, request); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3075 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3076 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3077 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3078 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3079 case OrthancPluginHttpMethod_Post: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3080 if (PostHandler == Internals::NullChunkedRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3081 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3082 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
3416 | 3083 } |
3084 else | |
3085 { | |
3749
edabdf07ee83
replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3669
diff
changeset
|
3086 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3087 if (reader.get() == NULL) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3088 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3089 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3090 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3091 else |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3092 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3093 reader->AddChunk(request->body, request->bodySize); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3094 reader->Execute(output); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3095 } |
3416 | 3096 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3097 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3098 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3099 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3100 case OrthancPluginHttpMethod_Delete: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3101 if (DeleteHandler == Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3102 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3103 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3104 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3105 else |
3416 | 3106 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3107 DeleteHandler(output, url, request); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3108 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3109 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3110 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3111 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3112 case OrthancPluginHttpMethod_Put: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3113 if (PutHandler == Internals::NullChunkedRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3114 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3115 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
3416 | 3116 } |
3117 else | |
3118 { | |
3749
edabdf07ee83
replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3669
diff
changeset
|
3119 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3120 if (reader.get() == NULL) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3121 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3122 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3123 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3124 else |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3125 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3126 reader->AddChunk(request->body, request->bodySize); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3127 reader->Execute(output); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3128 } |
3416 | 3129 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3130 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3131 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3132 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3133 default: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3134 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
3416 | 3135 } |
3136 | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3137 return OrthancPluginErrorCode_Success; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3138 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3139 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3140 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3141 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3142 if (HasGlobalContext() && |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3143 e.HasDetails()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3144 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3145 // The "false" instructs Orthanc not to log the detailed |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3146 // error message. This is to avoid duplicating the details, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3147 // because "OrthancException" already does it on construction. |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3148 OrthancPluginSetHttpErrorDetails |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3149 (GetGlobalContext(), output, e.GetDetails(), false); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3150 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3151 #endif |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3152 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3153 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3154 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3155 catch (boost::bad_lexical_cast&) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3156 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3157 return OrthancPluginErrorCode_BadFileFormat; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3158 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3159 catch (...) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3160 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3161 return OrthancPluginErrorCode_Plugin; |
3416 | 3162 } |
3163 } | |
3164 #endif | |
3165 } | |
3664
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3166 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3167 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3168 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3169 OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup( |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3170 OrthancPluginStorageCommitmentFailureReason* target, |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3171 void* rawHandler, |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3172 const char* sopClassUid, |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3173 const char* sopInstanceUid) |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3174 { |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3175 assert(target != NULL && |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3176 rawHandler != NULL); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3177 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3178 try |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3179 { |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3180 IStorageCommitmentScpHandler& handler = *reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3181 *target = handler.Lookup(sopClassUid, sopInstanceUid); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3182 return OrthancPluginErrorCode_Success; |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3183 } |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3184 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3185 { |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3186 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3187 } |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3188 catch (...) |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3189 { |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3190 return OrthancPluginErrorCode_Plugin; |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3191 } |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3192 } |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3193 #endif |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3194 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3195 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3196 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3197 void IStorageCommitmentScpHandler::Destructor(void* rawHandler) |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3198 { |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3199 assert(rawHandler != NULL); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3200 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3201 } |
85acfcc15829
sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
3202 #endif |
3916
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3203 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3204 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3205 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3206 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) : |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3207 toFree_(false), |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3208 instance_(instance) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3209 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3210 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3211 #else |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3212 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) : |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3213 toFree_(false), |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3214 instance_(instance) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3215 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3216 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3217 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3218 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3219 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3220 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3221 DicomInstance::DicomInstance(const void* buffer, |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3222 size_t size) : |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3223 toFree_(true), |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3224 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size)) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3225 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3226 if (instance_ == NULL) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3227 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3228 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3229 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3230 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3231 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3232 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3233 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3234 DicomInstance::~DicomInstance() |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3235 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3236 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3237 if (toFree_ && |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3238 instance_ != NULL) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3239 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3240 OrthancPluginFreeDicomInstance( |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3241 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_)); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3242 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3243 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3244 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3245 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3246 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3247 std::string DicomInstance::GetRemoteAet() const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3248 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3249 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3250 if (s == NULL) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3251 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3252 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3253 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3254 else |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3255 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3256 return std::string(s); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3257 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3258 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3259 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3260 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3261 void DicomInstance::GetJson(Json::Value& target) const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3262 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3263 OrthancString s; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3264 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_)); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3265 s.ToJson(target); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3266 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3267 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3268 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3269 void DicomInstance::GetSimplifiedJson(Json::Value& target) const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3270 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3271 OrthancString s; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3272 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_)); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3273 s.ToJson(target); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3274 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3275 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3276 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3277 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3278 std::string DicomInstance::GetTransferSyntaxUid() const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3279 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3280 OrthancString s; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3281 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_)); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3282 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3283 std::string result; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3284 s.ToString(result); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3285 return result; |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3286 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3287 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3288 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3289 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3290 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3291 bool DicomInstance::HasPixelData() const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3292 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3293 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3294 if (result < 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3295 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3296 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3297 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3298 else |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3299 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3300 return (result != 0); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3301 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3302 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3303 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3304 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3305 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3306 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3307 void DicomInstance::GetRawFrame(std::string& target, |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3308 unsigned int frameIndex) const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3309 { |
3919
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3310 MemoryBuffer buffer; |
3916
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3311 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame( |
3919
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3312 GetGlobalContext(), *buffer, instance_, frameIndex); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3313 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3314 if (code == OrthancPluginErrorCode_Success) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3315 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3316 buffer.ToString(target); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3317 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3318 else |
3916
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3319 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3320 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3321 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3322 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3323 #endif |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3324 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3325 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3326 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3327 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3328 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3329 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame( |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3330 GetGlobalContext(), instance_, frameIndex); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3331 |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3332 if (image == NULL) |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3333 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3334 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3335 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3336 else |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3337 { |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3338 return new OrthancImage(image); |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3339 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3340 } |
0e3849268a55
new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3915
diff
changeset
|
3341 #endif |
3919
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3342 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3343 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3344 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3345 void DicomInstance::Serialize(std::string& target) const |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3346 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3347 MemoryBuffer buffer; |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3348 OrthancPluginErrorCode code = OrthancPluginSerializeDicomInstance( |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3349 GetGlobalContext(), *buffer, instance_); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3350 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3351 if (code == OrthancPluginErrorCode_Success) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3352 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3353 buffer.ToString(target); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3354 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3355 else |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3356 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3357 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3358 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3359 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3360 #endif |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3361 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3362 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3363 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3364 DicomInstance* DicomInstance::Transcode(const void* buffer, |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3365 size_t size, |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3366 const std::string& transferSyntax) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3367 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3368 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3369 GetGlobalContext(), buffer, size, transferSyntax.c_str()); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3370 |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3371 if (instance == NULL) |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3372 { |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3373 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3374 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3375 else |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3376 { |
3923
2434e98987ba
fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3921
diff
changeset
|
3377 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance)); |
3921 | 3378 result->toFree_ = true; |
3379 return result.release(); | |
3919
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3380 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3381 } |
6f11b3233a06
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3916
diff
changeset
|
3382 #endif |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3383 } |