annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3028:ff65c925f57a

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