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