annotate StoneWebViewer/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h @ 1508:dd1d1cc0575d

use of OrthancPluginsExports.cmake, link against system-wide orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 08:15:08 +0200
parents StoneWebViewer/Resources/Orthanc/OrthancPluginCppWrapper.h@d8af188ab545
children b750b6eab453
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "OrthancPluginException.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <orthanc/OrthancCPlugin.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include <boost/noncopyable.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <boost/lexical_cast.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <boost/date_time/posix_time/posix_time.hpp>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <json/value.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <vector>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include <list>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <set>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include <map>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 * The definition of ORTHANC_PLUGINS_VERSION_IS_ABOVE below is for
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 * backward compatibility with Orthanc SDK <= 1.3.0.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 * $ hg diff -r Orthanc-1.3.0:Orthanc-1.3.1 ../../../Plugins/Include/orthanc/OrthancCPlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 #define ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(major, minor, revision) \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 (ORTHANC_VERSION_MAJOR > major || \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 (ORTHANC_VERSION_MAJOR == major && \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 (ORTHANC_VERSION_MINOR > minor || \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 (ORTHANC_VERSION_MINOR == minor && \
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ORTHANC_VERSION_REVISION >= revision))))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 // The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 # define HAS_ORTHANC_PLUGIN_FIND_MATCHER 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 # define HAS_ORTHANC_PLUGIN_FIND_MATCHER 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 4, 2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 # define HAS_ORTHANC_PLUGIN_PEERS 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 # define HAS_ORTHANC_PLUGIN_JOB 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 # define HAS_ORTHANC_PLUGIN_PEERS 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 # define HAS_ORTHANC_PLUGIN_JOB 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 # define HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 # define HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 # define HAS_ORTHANC_PLUGIN_METRICS 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 # define HAS_ORTHANC_PLUGIN_METRICS 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 1, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 # define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 # define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 # define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 # define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 # define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 # define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 namespace OrthancPlugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 typedef void (*RestCallback) (OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 const OrthancPluginHttpRequest* request);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 void SetGlobalContext(OrthancPluginContext* context);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 bool HasGlobalContext();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 OrthancPluginContext* GetGlobalContext();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 class OrthancImage;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 class MemoryBuffer : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 OrthancPluginMemoryBuffer buffer_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 void Check(OrthancPluginErrorCode code);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 bool CheckHttp(OrthancPluginErrorCode code);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 MemoryBuffer();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 // This constructor makes a copy of the given buffer in the memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 // handled by the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 MemoryBuffer(const void* buffer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 size_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ~MemoryBuffer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 OrthancPluginMemoryBuffer* operator*()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return &buffer_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 // This transfers ownership from "other" to "this"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 void Assign(OrthancPluginMemoryBuffer& other);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 void Swap(MemoryBuffer& other);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 OrthancPluginMemoryBuffer Release();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 const char* GetData() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 if (buffer_.size > 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 return reinterpret_cast<const char*>(buffer_.data);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 return NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 size_t GetSize() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 return buffer_.size;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 bool IsEmpty() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 return GetSize() == 0 || GetData() == NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 void Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 void ToString(std::string& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 void ToJson(Json::Value& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 bool RestApiGet(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 bool RestApiGet(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 const std::map<std::string, std::string>& httpHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 bool RestApiPost(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 bool RestApiPut(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 bool RestApiPost(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 bool RestApiPut(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 bool RestApiPost(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 return RestApiPost(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 bool RestApiPut(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 return RestApiPut(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 void CreateDicom(const Json::Value& tags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 OrthancPluginCreateDicomFlags flags);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 void CreateDicom(const Json::Value& tags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 const OrthancImage& pixelData,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 OrthancPluginCreateDicomFlags flags);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 void ReadFile(const std::string& path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 void GetDicomQuery(const OrthancPluginWorklistQuery* query);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 void DicomToJson(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 OrthancPluginDicomToJsonFormat format,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 OrthancPluginDicomToJsonFlags flags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 uint32_t maxStringLength);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 bool HttpGet(const std::string& url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 const std::string& username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 const std::string& password);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 bool HttpPost(const std::string& url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 const std::string& username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 const std::string& password);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 bool HttpPut(const std::string& url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 const std::string& username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 const std::string& password);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 void GetDicomInstance(const std::string& instanceId);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 class OrthancString : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 char* str_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 void Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 OrthancString() :
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 str_(NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ~OrthancString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 // This transfers ownership, warning: The string must have been
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 // allocated by the Orthanc core
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 void Assign(char* str);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 const char* GetContent() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 return str_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 void ToString(std::string& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 void ToJson(Json::Value& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 class OrthancConfiguration : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 Json::Value configuration_; // Necessarily a Json::objectValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 std::string path_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 std::string GetPath(const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 void LoadConfiguration();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 OrthancConfiguration();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 explicit OrthancConfiguration(bool load);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 const Json::Value& GetJson() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return configuration_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 bool IsSection(const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 void GetSection(OrthancConfiguration& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 bool LookupStringValue(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 bool LookupIntegerValue(int& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 bool LookupUnsignedIntegerValue(unsigned int& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 bool LookupBooleanValue(bool& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 bool LookupFloatValue(float& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 bool LookupListOfStrings(std::list<std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 bool allowSingleString) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 bool LookupSetOfStrings(std::set<std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 bool allowSingleString) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 std::string GetStringValue(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 const std::string& defaultValue) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 int GetIntegerValue(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 int defaultValue) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 unsigned int GetUnsignedIntegerValue(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 unsigned int defaultValue) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 bool GetBooleanValue(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 bool defaultValue) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 float GetFloatValue(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 float defaultValue) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 void GetDictionary(std::map<std::string, std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 class OrthancImage : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 OrthancPluginImage* image_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 void Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 void CheckImageAvailable() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 OrthancImage();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 explicit OrthancImage(OrthancPluginImage* image);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 OrthancImage(OrthancPluginPixelFormat format,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 uint32_t width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 uint32_t height);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 OrthancImage(OrthancPluginPixelFormat format,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 uint32_t width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 uint32_t height,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 uint32_t pitch,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 void* buffer);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 ~OrthancImage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 void UncompressPngImage(const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 size_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 void UncompressJpegImage(const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 size_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 void DecodeDicomImage(const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 size_t size,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 unsigned int frame);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 OrthancPluginPixelFormat GetPixelFormat() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 unsigned int GetWidth() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 unsigned int GetHeight() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 unsigned int GetPitch() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 void* GetBuffer() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 const OrthancPluginImage* GetObject() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 return image_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 void CompressPngImage(MemoryBuffer& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 void CompressJpegImage(MemoryBuffer& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 uint8_t quality) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 void AnswerPngImage(OrthancPluginRestOutput* output) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 void AnswerJpegImage(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 uint8_t quality) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 void* GetWriteableBuffer();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 OrthancPluginImage* Release();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 class FindMatcher : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 OrthancPluginFindMatcher* matcher_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 const OrthancPluginWorklistQuery* worklist_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 void SetupDicom(const void* query,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 uint32_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 explicit FindMatcher(const OrthancPluginWorklistQuery* worklist);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 FindMatcher(const void* query,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 uint32_t size)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 SetupDicom(query, size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 explicit FindMatcher(const MemoryBuffer& dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 SetupDicom(dicom.GetData(), dicom.GetSize());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 ~FindMatcher();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 bool IsMatch(const void* dicom,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 uint32_t size) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 bool IsMatch(const MemoryBuffer& dicom) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 return IsMatch(dicom.GetData(), dicom.GetSize());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 bool RestApiGet(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 bool RestApiGetString(std::string& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 bool RestApiGetString(std::string& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 const std::map<std::string, std::string>& httpHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 bool RestApiPost(std::string& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 bool RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 bool RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 inline bool RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 body.size(), applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 inline bool RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 const MemoryBuffer& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 return RestApiPost(result, uri, body.GetData(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 body.GetSize(), applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 bool RestApiPut(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 bool RestApiPut(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 inline bool RestApiPut(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 body.size(), applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 bool RestApiDelete(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 bool applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 bool HttpDelete(const std::string& url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 const std::string& username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 const std::string& password);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 void AnswerJson(const Json::Value& value,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 OrthancPluginRestOutput* output);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 void AnswerString(const std::string& answer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 const char* mimeType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 OrthancPluginRestOutput* output);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 void AnswerHttpError(uint16_t httpError,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 OrthancPluginRestOutput* output);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 void AnswerMethodNotAllowed(OrthancPluginRestOutput* output, const char* allowedMethods);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 const char* AutodetectMimeType(const std::string& path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 void LogError(const std::string& message);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 void LogWarning(const std::string& message);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 void LogInfo(const std::string& message);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 void ReportMinimalOrthancVersion(unsigned int major,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 unsigned int minor,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 unsigned int revision);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 bool CheckMinimalOrthancVersion(unsigned int major,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 unsigned int minor,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 unsigned int revision);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 namespace Internals
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 template <RestCallback Callback>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 const OrthancPluginHttpRequest* request)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 Callback(output, url, request);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 if (HasGlobalContext() &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 e.HasDetails())
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 // The "false" instructs Orthanc not to log the detailed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 // error message. This is to avoid duplicating the details,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 // because "OrthancException" already does it on construction.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 OrthancPluginSetHttpErrorDetails
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 (GetGlobalContext(), output, e.GetDetails(), false);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 return OrthancPluginErrorCode_BadFileFormat;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 return OrthancPluginErrorCode_Plugin;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 template <RestCallback Callback>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 void RegisterRestCallback(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 bool isThreadSafe)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 if (isThreadSafe)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 OrthancPluginRegisterRestCallbackNoLock
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 OrthancPluginRegisterRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 #if HAS_ORTHANC_PLUGIN_PEERS == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 class OrthancPeers : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 typedef std::map<std::string, uint32_t> Index;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 OrthancPluginPeers *peers_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 Index index_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 uint32_t timeout_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 size_t GetPeerIndex(const std::string& name) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 OrthancPeers();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 ~OrthancPeers();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 uint32_t GetTimeout() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 return timeout_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 void SetTimeout(uint32_t timeout)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 timeout_ = timeout;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 bool LookupName(size_t& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 const std::string& name) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 std::string GetPeerName(size_t index) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 std::string GetPeerUrl(size_t index) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 std::string GetPeerUrl(const std::string& name) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 size_t GetPeersCount() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 return index_.size();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 bool LookupUserProperty(std::string& value,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 bool LookupUserProperty(std::string& value,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 const std::string& peer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 const std::string& key) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 bool DoGet(MemoryBuffer& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 bool DoGet(MemoryBuffer& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 bool DoGet(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 bool DoGet(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 bool DoPost(MemoryBuffer& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 bool DoPost(MemoryBuffer& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 bool DoPost(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 bool DoPost(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 bool DoPut(size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 bool DoPut(const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 bool DoDelete(size_t index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 bool DoDelete(const std::string& name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 const std::string& uri) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 #if HAS_ORTHANC_PLUGIN_JOB == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 class OrthancJob : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 std::string jobType_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 std::string content_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 bool hasSerialized_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 std::string serialized_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 float progress_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 static void CallbackFinalize(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 static float CallbackGetProgress(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 static const char* CallbackGetContent(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 static const char* CallbackGetSerialized(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 static OrthancPluginJobStepStatus CallbackStep(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 static OrthancPluginErrorCode CallbackStop(void* job,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 OrthancPluginJobStopReason reason);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 static OrthancPluginErrorCode CallbackReset(void* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 protected:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 void ClearContent();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 void UpdateContent(const Json::Value& content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 void ClearSerialized();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 void UpdateSerialized(const Json::Value& serialized);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 void UpdateProgress(float progress);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 OrthancJob(const std::string& jobType);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 virtual ~OrthancJob()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 virtual OrthancPluginJobStepStatus Step() = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 virtual void Stop(OrthancPluginJobStopReason reason) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 virtual void Reset() = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 static OrthancPluginJob* Create(OrthancJob* job /* takes ownership */);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 static std::string Submit(OrthancJob* job /* takes ownership */,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 int priority);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 static void SubmitAndWait(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 OrthancJob* job /* takes ownership */,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 int priority);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 // Submit a job from a POST on the REST API with the same
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 // conventions as in the Orthanc core (according to the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 // "Synchronous" and "Priority" options)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 static void SubmitFromRestApiPost(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 OrthancJob* job);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 #if HAS_ORTHANC_PLUGIN_METRICS == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 inline void SetMetricsValue(char* name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 float value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 OrthancPluginSetMetricsValue(GetGlobalContext(), name,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 value, OrthancPluginMetricsType_Default);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 class MetricsTimer : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 std::string name_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 boost::posix_time::ptime start_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 explicit MetricsTimer(const char* name);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 ~MetricsTimer();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 class HttpClient : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 typedef std::map<std::string, std::string> HttpHeaders;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 class IRequestBody : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 virtual ~IRequestBody()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 virtual bool ReadNextChunk(std::string& chunk) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 class IAnswer : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 virtual ~IAnswer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 virtual void AddHeader(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 const std::string& value) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 virtual void AddChunk(const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 size_t size) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 class RequestBodyWrapper;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 uint16_t httpStatus_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 OrthancPluginHttpMethod method_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 std::string url_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 HttpHeaders headers_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 std::string username_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 std::string password_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 uint32_t timeout_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 std::string certificateFile_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 std::string certificateKeyFile_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 std::string certificateKeyPassword_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 bool pkcs11_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 std::string fullBody_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 IRequestBody* chunkedBody_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 bool allowChunkedTransfers_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 void ExecuteWithStream(uint16_t& httpStatus, // out
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 IAnswer& answer, // out
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 IRequestBody& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 void ExecuteWithoutStream(uint16_t& httpStatus, // out
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 HttpHeaders& answerHeaders, // out
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 std::string& answerBody, // out
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 const std::string& body) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 HttpClient();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 uint16_t GetHttpStatus() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 return httpStatus_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 void SetMethod(OrthancPluginHttpMethod method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 method_ = method;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 const std::string& GetUrl() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 return url_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 void SetUrl(const std::string& url)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 url_ = url;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 void SetHeaders(const HttpHeaders& headers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 headers_ = headers;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 void AddHeader(const std::string& key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 const std::string& value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 headers_[key] = value;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 void AddHeaders(const HttpHeaders& headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 void SetCredentials(const std::string& username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 const std::string& password);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 void ClearCredentials();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 void SetTimeout(unsigned int timeout) // 0 for default timeout
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 timeout_ = timeout;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 void SetCertificate(const std::string& certificateFile,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 const std::string& keyFile,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 const std::string& keyPassword);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 void ClearCertificate();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 void SetPkcs11(bool pkcs11)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 pkcs11_ = pkcs11;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 void ClearBody();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 void SwapBody(std::string& body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 void SetBody(const std::string& body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 void SetBody(IRequestBody& body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 // This function can be used to disable chunked transfers if the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 // remote server is Orthanc with a version <= 1.5.6.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 void SetChunkedTransfersAllowed(bool allow)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 allowChunkedTransfers_ = allow;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 bool IsChunkedTransfersAllowed() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 return allowChunkedTransfers_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 void Execute(IAnswer& answer);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 void Execute(HttpHeaders& answerHeaders /* out */,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 std::string& answerBody /* out */);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 void Execute(HttpHeaders& answerHeaders /* out */,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 Json::Value& answerBody /* out */);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 void Execute();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 class IChunkedRequestReader : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 virtual ~IChunkedRequestReader()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 virtual void AddChunk(const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 size_t size) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 virtual void Execute(OrthancPluginRestOutput* output) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 typedef IChunkedRequestReader* (*ChunkedRestCallback) (const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 const OrthancPluginHttpRequest* request);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 namespace Internals
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 void NullRestCallback(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 const OrthancPluginHttpRequest* request);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 IChunkedRequestReader *NullChunkedRestCallback(const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 const OrthancPluginHttpRequest* request);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 template <ChunkedRestCallback Callback>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 static OrthancPluginErrorCode ChunkedProtect(OrthancPluginServerChunkedRequestReader** reader,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 const OrthancPluginHttpRequest* request)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 if (reader == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 return OrthancPluginErrorCode_InternalError;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 *reader = reinterpret_cast<OrthancPluginServerChunkedRequestReader*>(Callback(url, request));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 if (*reader == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 return OrthancPluginErrorCode_Plugin;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 return OrthancPluginErrorCode_BadFileFormat;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 return OrthancPluginErrorCode_Plugin;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 OrthancPluginErrorCode ChunkedRequestReaderAddChunk(
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 OrthancPluginServerChunkedRequestReader* reader,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068 const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 uint32_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 OrthancPluginErrorCode ChunkedRequestReaderExecute(
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 OrthancPluginServerChunkedRequestReader* reader,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 OrthancPluginRestOutput* output);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 void ChunkedRequestReaderFinalize(
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 OrthancPluginServerChunkedRequestReader* reader);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 const OrthancPluginHttpRequest* request,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 RestCallback GetHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 ChunkedRestCallback PostHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 RestCallback DeleteHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 ChunkedRestCallback PutHandler);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 template<
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 RestCallback GetHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 ChunkedRestCallback PostHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 RestCallback DeleteHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 ChunkedRestCallback PutHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 >
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 inline OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 const char* url,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 const OrthancPluginHttpRequest* request)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 return ChunkedRestCompatibility(output, url, request, GetHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 PostHandler, DeleteHandler, PutHandler);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 // NB: We use a templated class instead of a templated function, because
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 // default values are only available in functions since C++11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 template<
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 RestCallback GetHandler = Internals::NullRestCallback,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 ChunkedRestCallback PostHandler = Internals::NullChunkedRestCallback,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 RestCallback DeleteHandler = Internals::NullRestCallback,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 ChunkedRestCallback PutHandler = Internals::NullChunkedRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 >
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 class ChunkedRestRegistration : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 static void Apply(const std::string& uri)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 OrthancPluginRegisterChunkedRestCallback(
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 GetGlobalContext(), uri.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 GetHandler == Internals::NullRestCallback ? NULL : Internals::Protect<GetHandler>,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 PostHandler == Internals::NullChunkedRestCallback ? NULL : Internals::ChunkedProtect<PostHandler>,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 DeleteHandler == Internals::NullRestCallback ? NULL : Internals::Protect<DeleteHandler>,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 PutHandler == Internals::NullChunkedRestCallback ? NULL : Internals::ChunkedProtect<PutHandler>,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 Internals::ChunkedRequestReaderAddChunk,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 Internals::ChunkedRequestReaderExecute,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128 Internals::ChunkedRequestReaderFinalize);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 OrthancPluginRegisterRestCallbackNoLock(
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 GetGlobalContext(), uri.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 Internals::ChunkedRestCompatibility<GetHandler, PostHandler, DeleteHandler, PutHandler>);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 class IStorageCommitmentScpHandler : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 virtual ~IStorageCommitmentScpHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 virtual OrthancPluginStorageCommitmentFailureReason Lookup(const std::string& sopClassUid,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 const std::string& sopInstanceUid) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 static OrthancPluginErrorCode Lookup(OrthancPluginStorageCommitmentFailureReason* target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 void* rawHandler,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 const char* sopClassUid,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 const char* sopInstanceUid);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 static void Destructor(void* rawHandler);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 class DicomInstance : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 bool toFree_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 const OrthancPluginDicomInstance* instance_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 OrthancPluginDicomInstance* instance_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 DicomInstance(const OrthancPluginDicomInstance* instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 DicomInstance(OrthancPluginDicomInstance* instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 DicomInstance(const void* buffer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 size_t size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 ~DicomInstance();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 std::string GetRemoteAet() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 const void* GetBuffer() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 return OrthancPluginGetInstanceData(GetGlobalContext(), instance_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 size_t GetSize() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 return static_cast<size_t>(OrthancPluginGetInstanceSize(GetGlobalContext(), instance_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 void GetJson(Json::Value& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 void GetSimplifiedJson(Json::Value& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 OrthancPluginInstanceOrigin GetOrigin() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 return OrthancPluginGetInstanceOrigin(GetGlobalContext(), instance_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207 std::string GetTransferSyntaxUid() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 bool HasPixelData() const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 unsigned int GetFramesCount() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 return OrthancPluginGetInstanceFramesCount(GetGlobalContext(), instance_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 void GetRawFrame(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 unsigned int frameIndex) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 OrthancImage* GetDecodedFrame(unsigned int frameIndex) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 void Serialize(std::string& target) const;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 static DicomInstance* Transcode(const void* buffer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 size_t size,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 const std::string& transferSyntax);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 }