annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3102:9b18c8d4d459

'fix' for Orthanc issue #21: added a select file button + a warning specific for Firefox users
author Alain Mazy <alain@mazy.be>
date Thu, 10 Jan 2019 10:10:26 +0100
parents 4e43e67f8ecf
children fca730c267d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3039
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
2850
am@osimis.io
parents: 2848
diff changeset
23 *
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancPluginCppWrapper.h"
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <json/reader.h>
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
37 #include <json/writer.h>
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace OrthancPlugins
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
42 static OrthancPluginContext* globalContext_ = NULL;
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
43
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
44
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
45 void SetGlobalContext(OrthancPluginContext* context)
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
46 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
47 if (context == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
48 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
49 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
50 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
51 else if (globalContext_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
52 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
53 globalContext_ = context;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
54 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
55 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
56 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
57 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
58 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
59 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
60
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
61
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
62 bool HasGlobalContext()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
63 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
64 return globalContext_ != NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
65 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
66
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
67
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
68 OrthancPluginContext* GetGlobalContext()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
69 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
70 if (globalContext_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
71 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
72 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
73 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
74 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
75 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
76 return globalContext_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
77 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
78 }
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
79
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
80
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
81 void MemoryBuffer::Check(OrthancPluginErrorCode code)
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
82 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
83 if (code != OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
84 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
85 // Prevent using garbage information
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
86 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
87 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
88 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
89 }
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
90 }
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
91
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
92
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
93 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code)
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
94 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
95 if (code != OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
96 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
97 // Prevent using garbage information
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
98 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
99 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
100 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
101
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
102 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
103 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
104 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
105 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
106 else if (code == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
107 code == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
108 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
109 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
110 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
111 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
112 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
113 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
114 }
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
115 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
116
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
117
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
118 MemoryBuffer::MemoryBuffer()
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 buffer_.data = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 buffer_.size = 0;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
124
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
125 void MemoryBuffer::Clear()
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
126 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
127 if (buffer_.data != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
128 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
129 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
130 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
131 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
132 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
133 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
135
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
136 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
137 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
138 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
139
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
140 buffer_.data = other.data;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
141 buffer_.size = other.size;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
142
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
143 other.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
144 other.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
145 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
146
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
147
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
148 OrthancPluginMemoryBuffer MemoryBuffer::Release()
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
150 OrthancPluginMemoryBuffer result = buffer_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
151
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
152 buffer_.data = NULL;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
153 buffer_.size = 0;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
154
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
155 return result;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
156 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
157
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
158
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
159 void MemoryBuffer::ToString(std::string& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
160 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
161 if (buffer_.size == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
162 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
163 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
164 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
165 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
166 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
167 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
168 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
169 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
170
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
171
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
172 void MemoryBuffer::ToJson(Json::Value& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
173 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
174 if (buffer_.data == NULL ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
175 buffer_.size == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
176 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
177 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
178 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
179
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
180 const char* tmp = reinterpret_cast<const char*>(buffer_.data);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
181
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
182 Json::Reader reader;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
183 if (!reader.parse(tmp, tmp + buffer_.size, target))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
184 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
185 LogError("Cannot convert some memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
186 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
187 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
188 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
189
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
190
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
191 bool MemoryBuffer::RestApiGet(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
192 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
193 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
194 Clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
195
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
196 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
197 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
198 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
199 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
200 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
201 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
202 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
203 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
206 bool MemoryBuffer::RestApiGet(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
207 const std::map<std::string, std::string>& httpHeaders,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
208 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
209 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
210 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
211
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
212 std::vector<const char*> headersKeys;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
213 std::vector<const char*> headersValues;
3039
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
214
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
215 for (std::map<std::string, std::string>::const_iterator
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
216 it = httpHeaders.begin(); it != httpHeaders.end(); it++)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
217 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
218 headersKeys.push_back(it->first.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
219 headersValues.push_back(it->second.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
220 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
221
3039
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
222 return CheckHttp(OrthancPluginRestApiGet2(
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
223 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(),
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
224 (headersKeys.empty() ? NULL : &headersKeys[0]),
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
225 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
226 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
227
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
228 bool MemoryBuffer::RestApiPost(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
229 const char* body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
230 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
231 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
232 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
233 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
234
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
235 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
236 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
237 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
238 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
239 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
240 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
241 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
242 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
243 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
244
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
245
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
246 bool MemoryBuffer::RestApiPut(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
247 const char* body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
248 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
249 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
250 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
251 Clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
252
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
253 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
254 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
255 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
256 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
257 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
258 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
259 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
260 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
261 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
262
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
263
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
264 bool MemoryBuffer::RestApiPost(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
265 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
266 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
267 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
268 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
269 return RestApiPost(uri, writer.write(body), applyPlugins);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
270 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
271
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
272
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
273 bool MemoryBuffer::RestApiPut(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
274 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
275 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
276 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
277 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
278 return RestApiPut(uri, writer.write(body), applyPlugins);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
279 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
280
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
281
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
282 void MemoryBuffer::CreateDicom(const Json::Value& tags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
283 OrthancPluginCreateDicomFlags flags)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
284 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
285 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
286
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
287 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
288 std::string s = writer.write(tags);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
289
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
290 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
291 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
292
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
293 void MemoryBuffer::CreateDicom(const Json::Value& tags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
294 const OrthancImage& pixelData,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
295 OrthancPluginCreateDicomFlags flags)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
296 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
297 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
298
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
299 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
300 std::string s = writer.write(tags);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
301
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
302 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
303 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
304
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
305
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
306 void MemoryBuffer::ReadFile(const std::string& path)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
307 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
308 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
309 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
310 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
311
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
312
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
313 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
314 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
315 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
316 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
317 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
318
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
319
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
320 void OrthancString::Assign(char* str)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
321 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
322 if (str == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
323 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
324 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
325 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
326 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
327 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
328 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
329 str_ = str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
330 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
331 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
332
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
333
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
334 void OrthancString::Clear()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
335 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
336 if (str_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
337 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
338 OrthancPluginFreeString(GetGlobalContext(), str_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
339 str_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
340 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
341 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
342
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
343
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
344 void OrthancString::ToString(std::string& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
345 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
346 if (str_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
347 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
348 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
349 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
350 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
351 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
352 target.assign(str_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
353 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
354 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
355
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
356
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
357 void OrthancString::ToJson(Json::Value& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
358 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
359 if (str_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
360 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
361 LogError("Cannot convert an empty memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
362 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
363 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
364
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
365 Json::Reader reader;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
366 if (!reader.parse(str_, target))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
367 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
368 LogError("Cannot convert some memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
369 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
370 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
371 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
372
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
373
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
374 void MemoryBuffer::DicomToJson(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
375 OrthancPluginDicomToJsonFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
376 OrthancPluginDicomToJsonFlags flags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
377 uint32_t maxStringLength)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
378 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
379 OrthancString str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
380 str.Assign(OrthancPluginDicomBufferToJson
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
381 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
382 str.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
383 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
384
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
385
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
386 bool MemoryBuffer::HttpGet(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
387 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
388 const std::string& password)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 Clear();
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
391 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
392 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
393 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
394 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
395
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
396
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
397 bool MemoryBuffer::HttpPost(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
398 const std::string& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
399 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
400 const std::string& password)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
401 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
402 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
403 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
404 body.c_str(), body.size(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
405 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
406 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
407 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
408
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
409
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
410 bool MemoryBuffer::HttpPut(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
411 const std::string& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
412 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
413 const std::string& password)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
414 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
415 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
416 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
417 body.empty() ? NULL : body.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
418 body.size(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
419 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
420 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
421 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
422
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
423
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
424 void MemoryBuffer::GetDicomInstance(const std::string& instanceId)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
425 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
426 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
427 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
428 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
429
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
430
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
431 bool HttpDelete(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
432 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
433 const std::string& password)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
434 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
435 OrthancPluginErrorCode error = OrthancPluginHttpDelete
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
436 (GetGlobalContext(), url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
437 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
438 password.empty() ? NULL : password.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
439
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
440 if (error == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
441 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
442 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
443 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
444 else if (error == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
445 error == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
446 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
447 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
448 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
449 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
450 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
451 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
452 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
453 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
454
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
455
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
456 void LogError(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
457 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
458 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
459 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
460 OrthancPluginLogError(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
461 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
462 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
463
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
464
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
465 void LogWarning(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
466 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
467 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
468 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
469 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
470 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
471 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
472
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
473
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
474 void LogInfo(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
475 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
476 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
477 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
478 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
479 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
480 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
481
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
482
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
483 OrthancConfiguration::OrthancConfiguration()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
484 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
485 OrthancString str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
486 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
487
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
488 if (str.GetContent() == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
489 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
490 LogError("Cannot access the Orthanc configuration");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
491 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
492 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
493
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
494 str.ToJson(configuration_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
495
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
496 if (configuration_.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
497 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
498 LogError("Unable to read the Orthanc configuration");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
499 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
500 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
501 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
502
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
503
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
504 std::string OrthancConfiguration::GetPath(const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
505 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
506 if (path_.empty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
507 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
508 return key;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
509 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
510 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
511 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
512 return path_ + "." + key;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
513 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
514 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
515
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
516
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
517 bool OrthancConfiguration::IsSection(const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
518 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
519 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
520
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
521 return (configuration_.isMember(key) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
522 configuration_[key].type() == Json::objectValue);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
523 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
524
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
525
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
526 void OrthancConfiguration::GetSection(OrthancConfiguration& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
527 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
528 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
529 assert(configuration_.type() == Json::objectValue);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
530
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
531 target.path_ = GetPath(key);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
532
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
533 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
534 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
535 target.configuration_ = Json::objectValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
536 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
537 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
538 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
539 if (configuration_[key].type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
540 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
541 LogError("The configuration section \"" + target.path_ +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
542 "\" is not an associative array as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
543
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
544 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
545 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
546
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
547 target.configuration_ = configuration_[key];
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
548 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
549 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
550
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
551
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
552 bool OrthancConfiguration::LookupStringValue(std::string& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
553 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
554 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
555 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
556
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
557 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
558 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
559 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
560 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
561
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
562 if (configuration_[key].type() != Json::stringValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
563 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
564 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
565 "\" is not a string as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
566
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
567 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
568 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
569
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
570 target = configuration_[key].asString();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
571 return true;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
572 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
573
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
574
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
575 bool OrthancConfiguration::LookupIntegerValue(int& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
576 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
577 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
578 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
579
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
580 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
581 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
582 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
583 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
584
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
585 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
586 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
587 case Json::intValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
588 target = configuration_[key].asInt();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
589 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
590
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
591 case Json::uintValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
592 target = configuration_[key].asUInt();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
593 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
594
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
595 default:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
596 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
597 "\" is not an integer as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
598
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
599 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
600 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
601 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
602
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
603
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
604 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
605 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
606 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
607 int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
608 if (!LookupIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
609 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
610 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
611 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
612
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
613 if (tmp < 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
614 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
615 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
616 "\" is not a positive integer as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
617
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
618 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
619 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
620 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
621 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
622 target = static_cast<unsigned int>(tmp);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
623 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
624 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
625 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
626
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
627
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
628 bool OrthancConfiguration::LookupBooleanValue(bool& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
629 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
630 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
631 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
632
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
633 if (!configuration_.isMember(key))
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
634 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
635 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
636 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
637
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
638 if (configuration_[key].type() != Json::booleanValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
639 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
640 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
641 "\" is not a Boolean as expected");
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
642
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
643 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
644 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
645
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
646 target = configuration_[key].asBool();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
647 return true;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
648 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
649
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
650
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
651 bool OrthancConfiguration::LookupFloatValue(float& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
652 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
653 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
654 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
655
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
656 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
657 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
658 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
659 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
660
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
661 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
662 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
663 case Json::realValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
664 target = configuration_[key].asFloat();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
665 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
666
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
667 case Json::intValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
668 target = static_cast<float>(configuration_[key].asInt());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
669 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
670
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
671 case Json::uintValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
672 target = static_cast<float>(configuration_[key].asUInt());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
673 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
674
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
675 default:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
676 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
677 "\" is not an integer as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
678
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
679 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
680 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
681 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
682
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
683
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
684 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
685 const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
686 bool allowSingleString) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
687 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
688 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
689
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
690 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
691
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
692 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
693 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
694 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
695 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
696
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
697 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
698 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
699 case Json::arrayValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
700 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
701 bool ok = true;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
702
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
703 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
704 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
705 if (configuration_[key][i].type() == Json::stringValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
706 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
707 target.push_back(configuration_[key][i].asString());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
708 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
709 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
710 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
711 ok = false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
712 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
713 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
714
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
715 if (ok)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
716 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
717 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
718 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
719
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
720 break;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
721 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
722
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
723 case Json::stringValue:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
724 if (allowSingleString)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
725 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
726 target.push_back(configuration_[key].asString());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
727 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
728 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
729
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
730 break;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
731
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
732 default:
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
733 break;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
734 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
735
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
736 LogError("The configuration option \"" + GetPath(key) +
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
737 "\" is not a list of strings as expected");
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
738
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
739 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
740 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
741
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
743 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
744 const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
745 bool allowSingleString) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
746 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
747 std::list<std::string> lst;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
748
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
749 if (LookupListOfStrings(lst, key, allowSingleString))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
750 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
751 target.clear();
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
753 for (std::list<std::string>::const_iterator
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
754 it = lst.begin(); it != lst.end(); ++it)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
755 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
756 target.insert(*it);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
757 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
758
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
759 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
760 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
761 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
762 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
763 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
764 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
765 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
766
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
767
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
768 std::string OrthancConfiguration::GetStringValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
769 const std::string& defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
770 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
771 std::string tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
772 if (LookupStringValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
773 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
774 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
775 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
776 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
777 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
778 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
779 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
780 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
781
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
782
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
783 int OrthancConfiguration::GetIntegerValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
784 int defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
785 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
786 int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
787 if (LookupIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
788 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
789 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
790 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
791 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
792 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
793 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
794 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
795 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
796
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
797
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
798 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
799 unsigned int defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
800 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
801 unsigned int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
802 if (LookupUnsignedIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
803 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
804 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
805 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
806 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
807 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
808 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
809 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
810 }
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
811
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
812
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
813 bool OrthancConfiguration::GetBooleanValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
814 bool defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
815 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
816 bool tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
817 if (LookupBooleanValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
818 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
819 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
820 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
821 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
822 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
823 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
824 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
825 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
826
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
827
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
828 float OrthancConfiguration::GetFloatValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
829 float defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
830 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
831 float tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
832 if (LookupFloatValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
833 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
834 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
835 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
836 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
837 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
838 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
839 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
840 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
841
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
842
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
843 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
844 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
845 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
846 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
847
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
848 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
849
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
850 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
851 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
852 return;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
853 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
854
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
855 if (configuration_[key].type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
856 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
857 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
858 "\" is not a string as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
859
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
860 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
861 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
862
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
863 Json::Value::Members members = configuration_[key].getMemberNames();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
864
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
865 for (size_t i = 0; i < members.size(); i++)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
866 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
867 const Json::Value& value = configuration_[key][members[i]];
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
868
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
869 if (value.type() == Json::stringValue)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
870 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
871 target[members[i]] = value.asString();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
872 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
873 else
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
874 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
875 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
876 "\" is not a dictionary mapping strings to strings");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
877
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
878 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
879 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
880 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
881 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
882
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
883
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
884 void OrthancImage::Clear()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
885 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
886 if (image_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
887 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
888 OrthancPluginFreeImage(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
889 image_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
890 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
891 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
892
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
893
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
894 void OrthancImage::CheckImageAvailable()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
895 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
896 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
897 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
898 LogError("Trying to access a NULL image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
899 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
900 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
901 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
902
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
903
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
904 OrthancImage::OrthancImage() :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
905 image_(NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
906 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
907 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
908
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
909
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
910 OrthancImage::OrthancImage(OrthancPluginImage* image) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
911 image_(image)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
912 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
913 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
914
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
915
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
916 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
917 uint32_t width,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
918 uint32_t height)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
919 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
920 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
921
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
922 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
923 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
924 LogError("Cannot create an image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
925 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
926 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
927 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
928
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
929
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
930 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
931 uint32_t width,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
932 uint32_t height,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
933 uint32_t pitch,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
934 void* buffer)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
935 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
936 image_ = OrthancPluginCreateImageAccessor
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
937 (GetGlobalContext(), format, width, height, pitch, buffer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
938
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
939 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
940 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
941 LogError("Cannot create an image accessor");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
942 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
943 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
944 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
945
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
946 void OrthancImage::UncompressPngImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
947 size_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
948 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
949 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
950
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
951 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
952
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
953 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
954 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
955 LogError("Cannot uncompress a PNG image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
956 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
957 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
958 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
959
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
960
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
961 void OrthancImage::UncompressJpegImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
962 size_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
963 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
964 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
965 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
966 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
967 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
968 LogError("Cannot uncompress a JPEG image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
969 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
970 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
971 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
972
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
973
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
974 void OrthancImage::DecodeDicomImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
975 size_t size,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
976 unsigned int frame)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
977 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
978 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
979 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
980 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
981 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
982 LogError("Cannot uncompress a DICOM image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
983 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
984 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
985 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
986
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
987
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
988 OrthancPluginPixelFormat OrthancImage::GetPixelFormat()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
989 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
990 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
991 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
992 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
993
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
994
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
995 unsigned int OrthancImage::GetWidth()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
996 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
997 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
998 return OrthancPluginGetImageWidth(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
999 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1000
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1001
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1002 unsigned int OrthancImage::GetHeight()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1003 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1004 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1005 return OrthancPluginGetImageHeight(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1006 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1007
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1008
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1009 unsigned int OrthancImage::GetPitch()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1010 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1011 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1012 return OrthancPluginGetImagePitch(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1013 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1014
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1015
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1016 const void* OrthancImage::GetBuffer()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1017 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1018 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1019 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1020 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1021
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1022
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1023 void OrthancImage::CompressPngImage(MemoryBuffer& target)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1024 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1025 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1026
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1027 OrthancPluginMemoryBuffer tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1028 OrthancPluginCompressPngImage(GetGlobalContext(), &tmp, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1029 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1030
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1031 target.Assign(tmp);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1032 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1033
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1034
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1035 void OrthancImage::CompressJpegImage(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1036 uint8_t quality)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1037 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1038 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1039
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1040 OrthancPluginMemoryBuffer tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1041 OrthancPluginCompressJpegImage(GetGlobalContext(), &tmp, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1042 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1043
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1044 target.Assign(tmp);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1045 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1046
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1047
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1048 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1049 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1050 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1051 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1052 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1053 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1054
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1055
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1056 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1057 uint8_t quality)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1058 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1059 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1060 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1061 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1062 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1063
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1064
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1065
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1066 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1067 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1068 matcher_(NULL),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1069 worklist_(worklist)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1070 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1071 if (worklist_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1072 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1073 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1074 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1075 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1076
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1077
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1078 void FindMatcher::SetupDicom(const void* query,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1079 uint32_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1080 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1081 worklist_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1082
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1083 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1084 if (matcher_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1085 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1086 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1087 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1088 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1089
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1090
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1091 FindMatcher::~FindMatcher()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1092 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1093 // The "worklist_" field
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1094
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1095 if (matcher_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1096 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1097 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1098 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1099 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1100
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1101
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1102
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1103 bool FindMatcher::IsMatch(const void* dicom,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1104 uint32_t size) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1105 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1106 int32_t result;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1107
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1108 if (matcher_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1109 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1110 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1111 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1112 else if (worklist_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1113 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1114 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1115 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1116 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1117 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1118 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1119 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1120
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1121 if (result == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1122 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1123 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1124 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1125 else if (result == 1)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1126 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1127 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1128 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1129 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1130 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1131 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1132 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1133 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1134
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1135 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1136
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1137 void AnswerJson(const Json::Value& value,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1138 OrthancPluginRestOutput* output
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1139 )
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1140 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1141 Json::StyledWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1142 std::string bodyString = writer.write(value);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1143
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1144 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1145 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1146
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1147 void AnswerString(const std::string& answer,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1148 const char* mimeType,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1149 OrthancPluginRestOutput* output
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1150 )
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1151 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1152 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1153 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1154
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1155 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1156 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1157 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1158 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1159
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1160 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1161 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1162 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1163 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1164
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1165 bool RestApiGetString(std::string& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1166 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1167 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1168 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1169 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1170 if (!answer.RestApiGet(uri, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1171 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1172 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1173 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1174 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1175 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1176 answer.ToString(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1177 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1178 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1179 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1180
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1181 bool RestApiGetString(std::string& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1182 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1183 const std::map<std::string, std::string>& httpHeaders,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1184 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1185 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1186 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1187 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1188 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1189 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1190 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1191 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1192 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1193 answer.ToString(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1194 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1195 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1196 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1197
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1198
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1199
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1200 bool RestApiGet(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1201 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1202 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1203 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1204 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1205
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1206 if (!answer.RestApiGet(uri, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1207 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1208 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1209 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1210 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1211 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1212 if (!answer.IsEmpty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1213 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1214 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1215 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1216 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1217 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1218 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1219
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1220
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1221 bool RestApiPost(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1222 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1223 const char* body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1224 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1225 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1226 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1227 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1228
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1229 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1230 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1231 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1232 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1233 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1234 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1235 if (!answer.IsEmpty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1236 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1237 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1238 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1239 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1240 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1241 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1242
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1243
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1244 bool RestApiPost(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1245 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1246 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1247 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1248 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1249 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1250 return RestApiPost(result, uri, writer.write(body), applyPlugins);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1251 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1252
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1253
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1254 bool RestApiPut(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1255 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1256 const char* body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1257 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1258 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1259 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1260 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1261
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1262 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1263 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1264 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1265 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1266 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1267 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1268 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthand returns an empty response
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1269 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1270 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1271 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1272 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1273 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1274 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1275
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1276
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1277 bool RestApiPut(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1278 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1279 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1280 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1281 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1282 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1283 return RestApiPut(result, uri, writer.write(body), applyPlugins);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1284 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1285
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1286
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1287 bool RestApiDelete(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1288 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1289 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1290 OrthancPluginErrorCode error;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1291
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1292 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1293 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1294 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1295 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1296 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1297 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1298 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1299 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1300
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1301 if (error == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1302 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1303 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1304 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1305 else if (error == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1306 error == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1307 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1308 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1309 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1310 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1311 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1312 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1313 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1314 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1315
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1316
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1317 void ReportMinimalOrthancVersion(unsigned int major,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1318 unsigned int minor,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1319 unsigned int revision)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1320 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1321 LogError("Your version of the Orthanc core (" +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1322 std::string(GetGlobalContext()->orthancVersion) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1323 ") is too old to run this plugin (version " +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1324 boost::lexical_cast<std::string>(major) + "." +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1325 boost::lexical_cast<std::string>(minor) + "." +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1326 boost::lexical_cast<std::string>(revision) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1327 " is required)");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1328 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1329
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1330
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1331 bool CheckMinimalOrthancVersion(unsigned int major,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1332 unsigned int minor,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1333 unsigned int revision)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1334 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1335 if (!HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1336 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1337 LogError("Bad Orthanc context in the plugin");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1338 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1339 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1340
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1341 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline"))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1342 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1343 // Assume compatibility with the mainline
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1344 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1345 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1346
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1347 // Parse the version of the Orthanc core
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1348 int aa, bb, cc;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1349 if (
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1350 #ifdef _MSC_VER
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1351 sscanf_s
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1352 #else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1353 sscanf
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1354 #endif
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1355 (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1356 aa < 0 ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1357 bb < 0 ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1358 cc < 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1359 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1360 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1361 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1362
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1363 unsigned int a = static_cast<unsigned int>(aa);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1364 unsigned int b = static_cast<unsigned int>(bb);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1365 unsigned int c = static_cast<unsigned int>(cc);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1366
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1367 // Check the major version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1368
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1369 if (a > major)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1370 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1371 return true;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1372 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1373
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1374 if (a < major)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1375 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1376 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1377 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1378
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1379
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1380 // Check the minor version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1381 assert(a == major);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1382
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1383 if (b > minor)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1384 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1385 return true;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1386 }
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1387
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1388 if (b < minor)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1389 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1390 return false;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1391 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1392
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1393 // Check the patch level version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1394 assert(a == major && b == minor);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1395
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1396 if (c >= revision)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1398 return true;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1402 return false;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 }
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1405
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1406
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1407 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1408 const char* AutodetectMimeType(const std::string& path)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1409 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1410 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str());
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
1411
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1412 if (mime == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1413 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1414 // Should never happen, just for safety
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1415 return "application/octet-stream";
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1416 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1417 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1418 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1419 return mime;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1420 }
2848
dd3914a44b87 added accessors in C++ wrappers
am@osimis.io
parents: 2823
diff changeset
1421 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1422 #endif
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1423
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1424
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1425 #if HAS_ORTHANC_PLUGIN_PEERS == 1
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1426 size_t OrthancPeers::GetPeerIndex(const std::string& name) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1427 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1428 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1429 if (LookupName(index, name))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1430 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1431 return index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1432 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1433 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1434 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1435 LogError("Inexistent peer: " + name);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1436 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1437 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1438 }
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
1439
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
1440
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1441 OrthancPeers::OrthancPeers() :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1442 peers_(NULL),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1443 timeout_(0)
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
1444 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1445 peers_ = OrthancPluginGetPeers(GetGlobalContext());
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1446
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1447 if (peers_ == NULL)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1448 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1449 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1450 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1451
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1452 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1453
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1454 for (uint32_t i = 0; i < count; i++)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1455 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1456 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1457 if (name == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1458 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1459 OrthancPluginFreePeers(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1460 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1461 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1462
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1463 index_[name] = i;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1464 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1465 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1466
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1467
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1468 OrthancPeers::~OrthancPeers()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1469 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1470 if (peers_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1471 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1472 OrthancPluginFreePeers(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1473 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1474 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1475
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1476
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1477 bool OrthancPeers::LookupName(size_t& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1478 const std::string& name) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1479 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1480 Index::const_iterator found = index_.find(name);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1481
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1482 if (found == index_.end())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1483 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1484 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1485 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1486 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1487 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1488 target = found->second;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1489 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1490 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1491 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1492
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1493
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1494 std::string OrthancPeers::GetPeerName(size_t index) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1495 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1496 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1497 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1498 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1499 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1500 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1501 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1502 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1503 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1504 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1505 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1506 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1507 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1508 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1509 return s;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1510 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1511 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1512 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1513
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1514
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1515 std::string OrthancPeers::GetPeerUrl(size_t index) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1516 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1517 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1518 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1519 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1520 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1521 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1522 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1523 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1524 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1525 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1526 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1527 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1528 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1529 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1530 return s;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1531 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1532 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1533 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1534
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1535
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1536 std::string OrthancPeers::GetPeerUrl(const std::string& name) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1537 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1538 return GetPeerUrl(GetPeerIndex(name));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1539 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1540
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1541
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1542 bool OrthancPeers::LookupUserProperty(std::string& value,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1543 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1544 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1545 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1546 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1547 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1548 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1549 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1550 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1551 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1552 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1553 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1554 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1555 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1556 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1557 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1558 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1559 value.assign(s);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1560 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1561 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1562 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1563 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1564
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1565
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1566 bool OrthancPeers::LookupUserProperty(std::string& value,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1567 const std::string& peer,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1568 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1569 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1570 return LookupUserProperty(value, GetPeerIndex(peer), key);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1571 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1572
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
1573
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1574 bool OrthancPeers::DoGet(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1575 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1576 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1577 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1578 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1579 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1580 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1581 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1582
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1583 OrthancPluginMemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1584 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1585 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1586 (GetGlobalContext(), &answer, NULL, &status, peers_,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1587 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1588 0, NULL, NULL, NULL, 0, timeout_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1589
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1590 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1591 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1592 target.Assign(answer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1593 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1594 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1595 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1596 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1597 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1598 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1599 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1600
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1601
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1602 bool OrthancPeers::DoGet(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1603 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1604 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1605 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1606 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1607 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1608 DoGet(target, index, uri));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1609 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1610
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1611
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1612 bool OrthancPeers::DoGet(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1613 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1614 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1615 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1616 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1617
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1618 if (DoGet(buffer, index, uri))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1619 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1620 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1621 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1622 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1623 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1624 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1625 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1626 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1627 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1628
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1629
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1630 bool OrthancPeers::DoGet(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1631 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1632 const std::string& uri) const
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1634 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1635
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1636 if (DoGet(buffer, name, uri))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1637 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1638 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1639 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1640 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1641 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1642 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1643 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1644 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1645 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1646
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1647
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1648 bool OrthancPeers::DoPost(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1649 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1650 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1651 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1652 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1653 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1654 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1655 DoPost(target, index, uri, body));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1656 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1657
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1658
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1659 bool OrthancPeers::DoPost(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1660 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1661 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1662 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1663 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1664 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1665
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1666 if (DoPost(buffer, index, uri, body))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1667 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1668 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1669 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1670 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1671 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1672 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1673 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1674 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1676
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1677
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1678 bool OrthancPeers::DoPost(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1679 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1680 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1681 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1682 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1683 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1684
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1685 if (DoPost(buffer, name, uri, body))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1686 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1687 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1688 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1689 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1690 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1691 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1692 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1693 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1694 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1695
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1696
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1697 bool OrthancPeers::DoPost(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1698 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1699 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1700 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1701 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1702 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1703 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1704 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1705 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1706
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1707 OrthancPluginMemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1708 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1709 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1710 (GetGlobalContext(), &answer, NULL, &status, peers_,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1711 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1712 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1713
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1714 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1715 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1716 target.Assign(answer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1717 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1718 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1719 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1720 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1721 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1722 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1723 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1724
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1725
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1726 bool OrthancPeers::DoPut(size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1727 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1728 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1729 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1730 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1731 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1732 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1733 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1734
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1735 OrthancPluginMemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1736 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1737 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1738 (GetGlobalContext(), &answer, NULL, &status, peers_,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1739 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1740 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1741
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1742 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1743 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1744 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1745 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1746 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1747 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1748 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1749 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1750 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1751 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1752
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1753
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1754 bool OrthancPeers::DoPut(const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1755 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1756 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1757 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1758 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1759 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1760 DoPut(index, uri, body));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1761 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1762
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1763
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1764 bool OrthancPeers::DoDelete(size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1765 const std::string& uri) const
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1767 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1768 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1769 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1770 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1771
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1772 OrthancPluginMemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1773 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1774 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1775 (GetGlobalContext(), &answer, NULL, &status, peers_,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1776 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1777 0, NULL, NULL, NULL, 0, timeout_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1778
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1779 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1780 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1781 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1782 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1783 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1784 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1785 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1786 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1787 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1789
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1790
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1791 bool OrthancPeers::DoDelete(const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1792 const std::string& uri) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1793 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1794 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1795 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1796 DoDelete(index, uri));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1797 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1798 #endif
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1799
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1800
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1801
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1802 #if HAS_ORTHANC_PLUGIN_JOB == 1
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1803 void OrthancJob::CallbackFinalize(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1804 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1805 if (job != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1806 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1807 delete reinterpret_cast<OrthancJob*>(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1808 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1809 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1810
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1811
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1812 float OrthancJob::CallbackGetProgress(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1813 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1814 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1815
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1816 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1817 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1818 return reinterpret_cast<OrthancJob*>(job)->progress_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1819 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1820 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1821 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1822 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1823 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1824 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1825
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1826
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1827 const char* OrthancJob::CallbackGetContent(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1828 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1829 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1830
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1831 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1832 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1833 return reinterpret_cast<OrthancJob*>(job)->content_.c_str();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1834 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1835 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1836 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1837 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1838 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1839 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1842 const char* OrthancJob::CallbackGetSerialized(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1843 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1844 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1845
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1846 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1847 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1848 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1849
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1850 if (tmp.hasSerialized_)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1851 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1852 return tmp.serialized_.c_str();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1853 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1854 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1855 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1856 return NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1857 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1858 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1859 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1860 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1861 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1862 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1863 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1864
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1865
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1866 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1867 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1868 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1869
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1870 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1871 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1872 return reinterpret_cast<OrthancJob*>(job)->Step();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1873 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1874 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1875 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1876 return OrthancPluginJobStepStatus_Failure;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1877 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1878 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1879 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1880 return OrthancPluginJobStepStatus_Failure;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1881 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1882 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1883
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1884
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1885 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1886 OrthancPluginJobStopReason reason)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1887 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1888 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1889
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1890 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1891 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1892 reinterpret_cast<OrthancJob*>(job)->Stop(reason);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1893 return OrthancPluginErrorCode_Success;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1894 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1895 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1896 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1897 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1898 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1899 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1900 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1901 return OrthancPluginErrorCode_Plugin;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1902 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1903 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1904
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1905
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1906 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1907 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1908 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1909
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1910 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1911 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1912 reinterpret_cast<OrthancJob*>(job)->Reset();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1913 return OrthancPluginErrorCode_Success;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1914 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1915 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1916 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1917 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1918 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1919 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1920 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1921 return OrthancPluginErrorCode_Plugin;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1922 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1923 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1924
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1925
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1926 void OrthancJob::ClearContent()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1927 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1928 Json::Value empty = Json::objectValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1929 UpdateContent(empty);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1930 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1931
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1932
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1933 void OrthancJob::UpdateContent(const Json::Value& content)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1934 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1935 if (content.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1936 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1937 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1938 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1939 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1940 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1941 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1942 content_ = writer.write(content);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1943 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1944 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1945
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1946
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1947 void OrthancJob::ClearSerialized()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1948 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1949 hasSerialized_ = false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1950 serialized_.clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1951 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1952
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1953
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1954 void OrthancJob::UpdateSerialized(const Json::Value& serialized)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1955 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1956 if (serialized.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1957 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1958 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1959 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1960 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1961 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1962 Json::FastWriter writer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1963 serialized_ = writer.write(serialized);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1964 hasSerialized_ = true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1965 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1966 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1967
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1968
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1969 void OrthancJob::UpdateProgress(float progress)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1970 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1971 if (progress < 0 ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1972 progress > 1)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1973 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1974 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1975 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1976
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1977 progress_ = progress;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1978 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1979
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1980
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1981 OrthancJob::OrthancJob(const std::string& jobType) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1982 jobType_(jobType),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1983 progress_(0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1984 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1985 ClearContent();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1986 ClearSerialized();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1987 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1988
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1989
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1990 OrthancPluginJob* OrthancJob::Create(OrthancJob* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1991 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1992 if (job == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1993 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1994 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1995 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1996
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1997 OrthancPluginJob* orthanc = OrthancPluginCreateJob(
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1998 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1999 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2000 CallbackStep, CallbackStop, CallbackReset);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2001
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2002 if (orthanc == NULL)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2003 {
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2004 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2006 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2007 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2008 return orthanc;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2009 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2010 }
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
2011
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
2012
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2013 std::string OrthancJob::Submit(OrthancJob* job,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2014 int priority)
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
2015 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2016 OrthancPluginJob* orthanc = Create(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2017
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2018 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2019
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2020 if (id == NULL)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2021 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2022 LogError("Plugin cannot submit job");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2023 OrthancPluginFreeJob(GetGlobalContext(), orthanc);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2024 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2025 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2026 else
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2027 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2028 std::string tmp(id);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2029 tmp.assign(id);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2030 OrthancPluginFreeString(GetGlobalContext(), id);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2031
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2032 return tmp;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2033 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2034 }
2817
473bf302d629 C++ wrappers around OrthancPluginJob and OrthancPluginPeers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2803
diff changeset
2035 #endif
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2036 }