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