annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2803:579acc5e5412

OrthancConfiguration::GetDictionary
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 Aug 2018 15:14:33 +0200
parents 4df3c64402ba
children 473bf302d629
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.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
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 {
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
42 void MemoryBuffer::Check(OrthancPluginErrorCode code)
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
43 {
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
44 if (code != OrthancPluginErrorCode_Success)
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
45 {
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
46 // Prevent using garbage information
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
47 buffer_.data = NULL;
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
48 buffer_.size = 0;
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
49 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
50 }
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
51 }
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
52
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
53
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
54 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
55 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
56 if (code != OrthancPluginErrorCode_Success)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
57 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
58 // Prevent using garbage information
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
59 buffer_.data = NULL;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
60 buffer_.size = 0;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
61 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
62
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
63 if (code == OrthancPluginErrorCode_Success)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
64 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
65 return true;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
66 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
67 else if (code == OrthancPluginErrorCode_UnknownResource ||
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
68 code == OrthancPluginErrorCode_InexistentItem)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
69 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
70 return false;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
71 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
72 else
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
73 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
74 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
75 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
76 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
77
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
78
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 MemoryBuffer::MemoryBuffer(OrthancPluginContext* context) :
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 context_(context)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 buffer_.data = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 buffer_.size = 0;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 void MemoryBuffer::Clear()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (buffer_.data != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 OrthancPluginFreeMemoryBuffer(context_, &buffer_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 buffer_.data = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 buffer_.size = 0;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 buffer_.data = other.data;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 buffer_.size = other.size;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 other.data = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 other.size = 0;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
110 OrthancPluginMemoryBuffer MemoryBuffer::Release()
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
111 {
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
112 OrthancPluginMemoryBuffer result = buffer_;
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
113
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
114 buffer_.data = NULL;
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
115 buffer_.size = 0;
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
116
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
117 return result;
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
118 }
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
119
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
120
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 void MemoryBuffer::ToString(std::string& target) const
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 if (buffer_.size == 0)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 target.clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 void MemoryBuffer::ToJson(Json::Value& target) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (buffer_.data == NULL ||
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 buffer_.size == 0)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
139 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 const char* tmp = reinterpret_cast<const char*>(buffer_.data);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 Json::Reader reader;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 if (!reader.parse(tmp, tmp + buffer_.size, target))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
148 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 bool MemoryBuffer::RestApiGet(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
160 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(context_, &buffer_, uri.c_str()));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
164 return CheckHttp(OrthancPluginRestApiGet(context_, &buffer_, uri.c_str()));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 bool MemoryBuffer::RestApiPost(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
178 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(context_, &buffer_, uri.c_str(), body, bodySize));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
182 return CheckHttp(OrthancPluginRestApiPost(context_, &buffer_, uri.c_str(), body, bodySize));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 bool MemoryBuffer::RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 if (applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
196 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(context_, &buffer_, uri.c_str(), body, bodySize));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
200 return CheckHttp(OrthancPluginRestApiPut(context_, &buffer_, uri.c_str(), body, bodySize));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
205 bool MemoryBuffer::RestApiPost(const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
206 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
207 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
208 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
209 Json::FastWriter writer;
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
210 return RestApiPost(uri, writer.write(body), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
211 }
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
212
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
213
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
214 bool MemoryBuffer::RestApiPut(const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
215 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
216 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
217 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
218 Json::FastWriter writer;
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
219 return RestApiPut(uri, writer.write(body), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
220 }
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
221
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
222
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
223 void MemoryBuffer::CreateDicom(const Json::Value& tags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
224 OrthancPluginCreateDicomFlags flags)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
225 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
226 Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
227
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
228 Json::FastWriter writer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
229 std::string s = writer.write(tags);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
230
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
231 Check(OrthancPluginCreateDicom(context_, &buffer_, s.c_str(), NULL, flags));
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
232 }
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
233
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
234
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
235 void MemoryBuffer::ReadFile(const std::string& path)
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
236 {
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
237 Clear();
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
238 Check(OrthancPluginReadFile(context_, &buffer_, path.c_str()));
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
239 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
240
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
241
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
242 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query)
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
243 {
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
244 Clear();
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
245 Check(OrthancPluginWorklistGetDicomQuery(context_, &buffer_, query));
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
246 }
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
247
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
248
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
249 void OrthancString::Assign(char* str)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
251 if (str == NULL)
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
252 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
253 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
254 }
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
255 else
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
256 {
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
257 Clear();
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
258 str_ = str;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
259 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 void OrthancString::Clear()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 if (str_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 OrthancPluginFreeString(context_, str_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 str_ = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 void OrthancString::ToString(std::string& target) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 if (str_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 target.clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 target.assign(str_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 void OrthancString::ToJson(Json::Value& target) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 if (str_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 OrthancPluginLogError(context_, "Cannot convert an empty memory buffer to JSON");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
291 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 Json::Reader reader;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 if (!reader.parse(str_, target))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
298 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
301
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
302
2206
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
303 void MemoryBuffer::DicomToJson(Json::Value& target,
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
304 OrthancPluginDicomToJsonFormat format,
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
305 OrthancPluginDicomToJsonFlags flags,
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
306 uint32_t maxStringLength)
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
307 {
2206
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
308 OrthancString str(context_);
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
309 str.Assign(OrthancPluginDicomBufferToJson(context_, GetData(), GetSize(), format, flags, maxStringLength));
27106f7e3759 more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2205
diff changeset
310 str.ToJson(target);
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
311 }
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
312
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
313
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
314 bool MemoryBuffer::HttpGet(const std::string& url,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
315 const std::string& username,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
316 const std::string& password)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
317 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
318 Clear();
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
319 return CheckHttp(OrthancPluginHttpGet(context_, &buffer_, url.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
320 username.empty() ? NULL : username.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
321 password.empty() ? NULL : password.c_str()));
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
322 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
323
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
324
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
325 bool MemoryBuffer::HttpPost(const std::string& url,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
326 const std::string& body,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
327 const std::string& username,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
328 const std::string& password)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
329 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
330 Clear();
2267
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
331 return CheckHttp(OrthancPluginHttpPost(context_, &buffer_, url.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
332 body.c_str(), body.size(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
333 username.empty() ? NULL : username.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
334 password.empty() ? NULL : password.c_str()));
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
335 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
336
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
337
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
338 bool MemoryBuffer::HttpPut(const std::string& url,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
339 const std::string& body,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
340 const std::string& username,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
341 const std::string& password)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
342 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
343 Clear();
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
344 return CheckHttp(OrthancPluginHttpPut(context_, &buffer_, url.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
345 body.empty() ? NULL : body.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
346 body.size(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
347 username.empty() ? NULL : username.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
348 password.empty() ? NULL : password.c_str()));
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
349 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
350
2796
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
351
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
352 void MemoryBuffer::GetDicomInstance(const std::string& instanceId)
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
353 {
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
354 Clear();
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
355 Check(OrthancPluginGetDicomForInstance(context_, &buffer_, instanceId.c_str()));
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
356 }
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
357
4df3c64402ba MemoryBuffer::GetDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2792
diff changeset
358
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
359 bool HttpDelete(OrthancPluginContext* context_,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
360 const std::string& url,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
361 const std::string& username,
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
362 const std::string& password)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
363 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
364 OrthancPluginErrorCode error = OrthancPluginHttpDelete
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
365 (context_, url.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
366 username.empty() ? NULL : username.c_str(),
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
367 password.empty() ? NULL : password.c_str());
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
368
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
369 if (error == OrthancPluginErrorCode_Success)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
370 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
371 return true;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
372 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
373 else if (error == OrthancPluginErrorCode_UnknownResource ||
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
374 error == OrthancPluginErrorCode_InexistentItem)
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
375 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
376 return false;
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
377 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
378 else
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
379 {
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
380 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
381 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
382 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
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 OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) :
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 context_(context)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
388 OrthancString str(context);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
389 str.Assign(OrthancPluginGetConfiguration(context));
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 if (str.GetContent() == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 OrthancPluginLogError(context, "Cannot access the Orthanc configuration");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
394 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 str.ToJson(configuration_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 if (configuration_.type() != Json::objectValue)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 OrthancPluginLogError(context, "Unable to read the Orthanc configuration");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
402 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 OrthancPluginContext* OrthancConfiguration::GetContext() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 if (context_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
411 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 return context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 std::string OrthancConfiguration::GetPath(const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 if (path_.empty())
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 return key;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 return path_ + "." + key;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
2167
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
433 bool OrthancConfiguration::IsSection(const std::string& key) const
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
434 {
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
435 assert(configuration_.type() == Json::objectValue);
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
436
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
437 return (configuration_.isMember(key) &&
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
438 configuration_[key].type() == Json::objectValue);
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
439 }
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
440
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2112
diff changeset
441
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 void OrthancConfiguration::GetSection(OrthancConfiguration& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 assert(configuration_.type() == Json::objectValue);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 target.context_ = context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 target.path_ = GetPath(key);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 if (!configuration_.isMember(key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 target.configuration_ = Json::objectValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 if (configuration_[key].type() != Json::objectValue)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 std::string s = "The configuration section \"" + target.path_ + "\" is not an associative array as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
464 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 target.configuration_ = configuration_[key];
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 bool OrthancConfiguration::LookupStringValue(std::string& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 assert(configuration_.type() == Json::objectValue);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 if (!configuration_.isMember(key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 if (configuration_[key].type() != Json::stringValue)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 std::string s = "The configuration option \"" + GetPath(key) + "\" is not a string as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
490 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 target = configuration_[key].asString();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 bool OrthancConfiguration::LookupIntegerValue(int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 assert(configuration_.type() == Json::objectValue);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 if (!configuration_.isMember(key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 switch (configuration_[key].type())
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 case Json::intValue:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 target = configuration_[key].asInt();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 case Json::uintValue:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 target = configuration_[key].asUInt();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 default:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
525 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 int tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 if (!LookupIntegerValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 if (tmp < 0)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 std::string s = "The configuration option \"" + GetPath(key) + "\" is not a positive integer as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
547 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 target = static_cast<unsigned int>(tmp);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 bool OrthancConfiguration::LookupBooleanValue(bool& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 assert(configuration_.type() == Json::objectValue);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 if (!configuration_.isMember(key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 if (configuration_[key].type() != Json::booleanValue)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 std::string s = "The configuration option \"" + GetPath(key) + "\" is not a Boolean as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
575 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 target = configuration_[key].asBool();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 bool OrthancConfiguration::LookupFloatValue(float& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 const std::string& key) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 assert(configuration_.type() == Json::objectValue);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 if (!configuration_.isMember(key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 switch (configuration_[key].type())
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 case Json::realValue:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 target = configuration_[key].asFloat();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 case Json::intValue:
2112
82461d1e8e17 removal warning with MSVC
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2109
diff changeset
600 target = static_cast<float>(configuration_[key].asInt());
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 case Json::uintValue:
2112
82461d1e8e17 removal warning with MSVC
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2109
diff changeset
604 target = static_cast<float>(configuration_[key].asUInt());
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 default:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 if (context_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 std::string s = "The configuration option \"" + GetPath(key) + "\" is not an integer as expected";
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 OrthancPluginLogError(context_, s.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
614 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
618
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
619 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target,
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
620 const std::string& key,
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
621 bool allowSingleString) const
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
622 {
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
623 assert(configuration_.type() == Json::objectValue);
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
624
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
625 target.clear();
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
626
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
627 if (!configuration_.isMember(key))
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
628 {
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
629 return false;
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
630 }
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
631
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
632 switch (configuration_[key].type())
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
633 {
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
634 case Json::arrayValue:
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
635 {
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
636 bool ok = true;
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
637
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
638 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++)
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
639 {
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
640 if (configuration_[key][i].type() == Json::stringValue)
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
641 {
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
642 target.push_back(configuration_[key][i].asString());
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
643 }
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
644 else
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
645 {
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
646 ok = false;
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
647 }
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
648 }
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
649
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
650 if (ok)
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
651 {
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
652 return true;
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
653 }
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
654
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
655 break;
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
656 }
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
657
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
658 case Json::stringValue:
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
659 if (allowSingleString)
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
660 {
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
661 target.push_back(configuration_[key].asString());
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
662 return true;
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
663 }
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
664
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
665 break;
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
666
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
667 default:
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
668 break;
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
669 }
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
670
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
671 if (context_ != NULL)
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
672 {
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
673 std::string s = ("The configuration option \"" + GetPath(key) +
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
674 "\" is not a list of strings as expected");
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
675 OrthancPluginLogError(context_, s.c_str());
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
676 }
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
677
2265
e46b0ee6c19d allowSingleString in OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2264
diff changeset
678 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2263
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
679 }
b9775db0fd9b OrthancPlugins::OrthancConfiguration::LookupListOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
680
2266
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
681
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
682 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target,
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
683 const std::string& key,
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
684 bool allowSingleString) const
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
685 {
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
686 std::list<std::string> lst;
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
687
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
688 if (LookupListOfStrings(lst, key, allowSingleString))
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
689 {
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
690 target.clear();
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
691
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
692 for (std::list<std::string>::const_iterator
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
693 it = lst.begin(); it != lst.end(); ++it)
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
694 {
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
695 target.insert(*it);
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
696 }
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
697
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
698 return true;
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
699 }
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
700 else
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
701 {
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
702 return false;
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
703 }
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
704 }
a344e47e9c9a OrthancConfiguration::LookupSetOfStrings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2265
diff changeset
705
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 std::string OrthancConfiguration::GetStringValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 const std::string& defaultValue) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 std::string tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 if (LookupStringValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 return tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 return defaultValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 int OrthancConfiguration::GetIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 int defaultValue) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 int tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 if (LookupIntegerValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 return tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 return defaultValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 unsigned int defaultValue) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 unsigned int tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 if (LookupUnsignedIntegerValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 return tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 return defaultValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 bool OrthancConfiguration::GetBooleanValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 bool defaultValue) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 bool tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 if (LookupBooleanValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 return tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 return defaultValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 float OrthancConfiguration::GetFloatValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 float defaultValue) const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 float tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 if (LookupFloatValue(tmp, key))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 return tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 return defaultValue;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781
2803
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
782 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target,
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
783 const std::string& key) const
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
784 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
785 assert(configuration_.type() == Json::objectValue);
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
786
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
787 target.clear();
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
788
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
789 if (!configuration_.isMember(key))
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
790 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
791 return;
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
792 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
793
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
794 if (configuration_[key].type() != Json::objectValue)
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
795 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
796 if (context_ != NULL)
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
797 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
798 std::string s = "The configuration option \"" + GetPath(key) + "\" is not a string as expected";
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
799 OrthancPluginLogError(context_, s.c_str());
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
800 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
801
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
802 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
803 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
804
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
805 Json::Value::Members members = configuration_[key].getMemberNames();
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
806
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
807 for (size_t i = 0; i < members.size(); i++)
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
808 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
809 const Json::Value& value = configuration_[key][members[i]];
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
810
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
811 if (value.type() == Json::stringValue)
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
812 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
813 target[members[i]] = value.asString();
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
814 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
815 else
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
816 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
817 if (context_ != NULL)
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
818 {
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
819 std::string s = "The configuration option \"" + GetPath(key) + "\" is not a dictionary mapping strings to strings";
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
820 OrthancPluginLogError(context_, s.c_str());
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
821 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
822
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
823 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
824 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
825 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
826 }
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
827
579acc5e5412 OrthancConfiguration::GetDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2796
diff changeset
828
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 void OrthancImage::Clear()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 if (image_ != NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 OrthancPluginFreeImage(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 image_ = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 void OrthancImage::CheckImageAvailable()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 if (image_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 OrthancPluginLogError(context_, "Trying to access a NULL image");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
844 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
2048
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
849 OrthancImage::OrthancImage(OrthancPluginContext* context) :
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 context_(context),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 image_(NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 if (context == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
855 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
2048
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
860 OrthancImage::OrthancImage(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
861 OrthancPluginImage* image) :
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 context_(context),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 image_(image)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 if (context == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
867 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871
2048
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
872 OrthancImage::OrthancImage(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
873 OrthancPluginPixelFormat format,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
874 uint32_t width,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
875 uint32_t height) :
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 context_(context)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 if (context == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
880 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 image_ = OrthancPluginCreateImage(context, format, width, height);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 void OrthancImage::UncompressPngImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 size_t size)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 image_ = OrthancPluginUncompressImage(context_, data, size, OrthancPluginImageFormat_Png);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 if (image_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 OrthancPluginLogError(context_, "Cannot uncompress a PNG image");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
897 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 void OrthancImage::UncompressJpegImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 size_t size)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 image_ = OrthancPluginUncompressImage(context_, data, size, OrthancPluginImageFormat_Jpeg);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 if (image_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 OrthancPluginLogError(context_, "Cannot uncompress a JPEG image");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
910 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 void OrthancImage::DecodeDicomImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 size_t size,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 unsigned int frame)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 image_ = OrthancPluginDecodeDicomImage(context_, data, size, frame);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 if (image_ == NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 OrthancPluginLogError(context_, "Cannot uncompress a DICOM image");
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
924 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 OrthancPluginPixelFormat OrthancImage::GetPixelFormat()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 return OrthancPluginGetImagePixelFormat(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 unsigned int OrthancImage::GetWidth()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 return OrthancPluginGetImageWidth(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 unsigned int OrthancImage::GetHeight()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 return OrthancPluginGetImageHeight(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 unsigned int OrthancImage::GetPitch()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 return OrthancPluginGetImagePitch(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 const void* OrthancImage::GetBuffer()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 return OrthancPluginGetImageBuffer(context_, image_);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 void OrthancImage::CompressPngImage(MemoryBuffer& target)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 OrthancPluginMemoryBuffer tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 OrthancPluginCompressPngImage(context_, &tmp, GetPixelFormat(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 target.Assign(tmp);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 void OrthancImage::CompressJpegImage(MemoryBuffer& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 uint8_t quality)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 OrthancPluginMemoryBuffer tmp;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 OrthancPluginCompressJpegImage(context_, &tmp, GetPixelFormat(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 target.Assign(tmp);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 OrthancPluginCompressAndAnswerPngImage(context_, output, GetPixelFormat(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 uint8_t quality)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 OrthancPluginCompressAndAnswerJpegImage(context_, output, GetPixelFormat(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005
2231
61e0564d03bb backwards compatibility within OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2215
diff changeset
1006
61e0564d03bb backwards compatibility within OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2215
diff changeset
1007 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1008 FindMatcher::FindMatcher(OrthancPluginContext* context,
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1009 const OrthancPluginWorklistQuery* worklist) :
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1010 context_(context),
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1011 matcher_(NULL),
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1012 worklist_(worklist)
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1013 {
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1014 if (worklist_ == NULL)
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1015 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
1016 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1017 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1018 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1019
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1020
2215
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1021 void FindMatcher::SetupDicom(OrthancPluginContext* context,
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1022 const void* query,
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1023 uint32_t size)
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1024 {
2215
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1025 context_ = context;
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1026 worklist_ = NULL;
028214a95194 refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2213
diff changeset
1027
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1028 matcher_ = OrthancPluginCreateFindMatcher(context_, query, size);
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1029 if (matcher_ == NULL)
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1030 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
1031 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1032 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1033 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1034
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1035
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1036 FindMatcher::~FindMatcher()
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1037 {
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1038 // The "worklist_" field
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1039
2212
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1040 if (matcher_ != NULL)
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1041 {
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1042 OrthancPluginFreeFindMatcher(context_, matcher_);
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1043 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1044 }
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1045
c02f6ec404d8 OrthancPlugins::FindMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2206
diff changeset
1046
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1047
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1048 bool FindMatcher::IsMatch(const void* dicom,
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1049 uint32_t size) const
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1050 {
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1051 int32_t result;
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1052
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1053 if (matcher_ != NULL)
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1054 {
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1055 result = OrthancPluginFindMatcherIsMatch(context_, matcher_, dicom, size);
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1056 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1057 else if (worklist_ != NULL)
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1058 {
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1059 result = OrthancPluginWorklistIsMatch(context_, worklist_, dicom, size);
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1060 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1061 else
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1062 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
1063 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1064 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1065
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1066 if (result == 0)
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1067 {
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1068 return false;
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1069 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1070 else if (result == 1)
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1071 {
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1072 return true;
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1073 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1074 else
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1075 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
1076 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1077 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1078 }
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1079
2231
61e0564d03bb backwards compatibility within OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2215
diff changeset
1080 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */
2213
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1081
95d1d758abb7 FindMatcher::IsMatch
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2212
diff changeset
1082
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1083 bool RestApiGet(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1084 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1085 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1086 bool applyPlugins)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 MemoryBuffer answer(context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 if (!answer.RestApiGet(uri, applyPlugins))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 answer.ToJson(result);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1101 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1102 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1103 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1104 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1105 size_t bodySize,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1106 bool applyPlugins)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 MemoryBuffer answer(context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 answer.ToJson(result);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1121 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1122 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1123 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1124 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1125 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1126 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1127 Json::FastWriter writer;
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1128 return RestApiPost(result, context, uri, writer.write(body), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1129 }
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1130
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1131
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1132 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1133 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1134 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1135 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1136 size_t bodySize,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1137 bool applyPlugins)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 MemoryBuffer answer(context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins))
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 answer.ToJson(result);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1152 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1153 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1154 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1155 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1156 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1157 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1158 Json::FastWriter writer;
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1159 return RestApiPut(result, context, uri, writer.write(body), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1160 }
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1161
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1162
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 OrthancPluginErrorCode error;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 if (applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 error = OrthancPluginRestApiDeleteAfterPlugins(context, uri.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 error = OrthancPluginRestApiDelete(context, uri.c_str());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 if (error == OrthancPluginErrorCode_Success)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 return true;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 else if (error == OrthancPluginErrorCode_UnknownResource ||
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 error == OrthancPluginErrorCode_InexistentItem)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 return false;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 {
2234
a78d15509a1c cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2231
diff changeset
1189 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 }
2109
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1192
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1193
2268
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2267
diff changeset
1194 void ReportMinimalOrthancVersion(OrthancPluginContext* context,
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2267
diff changeset
1195 unsigned int major,
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2267
diff changeset
1196 unsigned int minor,
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2267
diff changeset
1197 unsigned int revision)
2109
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1198 {
2267
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1199 std::string s = ("Your version of the Orthanc core (" +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1200 std::string(context->orthancVersion) +
2268
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2267
diff changeset
1201 ") is too old to run this plugin (version " +
2267
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1202 boost::lexical_cast<std::string>(major) + "." +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1203 boost::lexical_cast<std::string>(minor) + "." +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1204 boost::lexical_cast<std::string>(revision) +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1205 " is required)");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1206
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2266
diff changeset
1207 OrthancPluginLogError(context, s.c_str());
2109
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1208 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1209
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1210
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1211 bool CheckMinimalOrthancVersion(OrthancPluginContext* context,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1212 unsigned int major,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1213 unsigned int minor,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1214 unsigned int revision)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1215 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1216 if (context == NULL)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1217 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1218 OrthancPluginLogError(context, "Bad Orthanc context in the plugin");
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1219 return false;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1220 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1221
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1222 if (!strcmp(context->orthancVersion, "mainline"))
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1223 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1224 // Assume compatibility with the mainline
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1225 return true;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1226 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1227
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1228 // Parse the version of the Orthanc core
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1229 int aa, bb, cc;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1230 if (
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1231 #ifdef _MSC_VER
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1232 sscanf_s
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1233 #else
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1234 sscanf
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1235 #endif
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1236 (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 ||
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1237 aa < 0 ||
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1238 bb < 0 ||
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1239 cc < 0)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1240 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1241 throw false;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1242 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1243
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1244 unsigned int a = static_cast<unsigned int>(aa);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1245 unsigned int b = static_cast<unsigned int>(bb);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1246 unsigned int c = static_cast<unsigned int>(cc);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1247
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1248 // Check the major version number
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1249
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1250 if (a > major)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1251 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1252 return true;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1253 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1254
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1255 if (a < major)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1256 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1257 return false;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1258 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1259
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1260
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1261 // Check the minor version number
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1262 assert(a == major);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1263
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1264 if (b > minor)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1265 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1266 return true;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1267 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1268
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1269 if (b < minor)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1270 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1271 return false;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1272 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1273
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1274 // Check the patch level version number
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1275 assert(a == major && b == minor);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1276
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1277 if (c >= revision)
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1278 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1279 return true;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1280 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1281 else
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1282 {
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1283 return false;
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1284 }
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
1285 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287