annotate Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2167:aa2915963531

"Folders" sub-configuration in ServeFolders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Nov 2016 14:19:42 +0100
parents d5c29fd74ffa
children fead5549aaa7
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * License, or (at your option) any later version.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * in the program, then also delete it here.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * 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
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * 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
26 * General Public License for more details.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * 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
29 * 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
30 **/
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 #pragma once
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <orthanc/OrthancCPlugin.h>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <boost/noncopyable.hpp>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <boost/lexical_cast.hpp>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <json/value.h>
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 #if HAS_ORTHANC_EXCEPTION == 1
2060
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
41 # include "../../../Core/OrthancException.h"
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #endif
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace OrthancPlugins
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 typedef void (*RestCallback) (OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const char* url,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const OrthancPluginHttpRequest* request);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 class PluginException
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 OrthancPluginErrorCode code_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 PluginException(OrthancPluginErrorCode code) : code_(code)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 OrthancPluginErrorCode GetErrorCode() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return code_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 const char* GetErrorDescription(OrthancPluginContext* context) const;
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
68
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
69 static void Check(OrthancPluginErrorCode code);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 class MemoryBuffer : public boost::noncopyable
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 OrthancPluginMemoryBuffer buffer_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2060
diff changeset
79 void Check(OrthancPluginErrorCode code);
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2060
diff changeset
80
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 MemoryBuffer(OrthancPluginContext* context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ~MemoryBuffer()
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 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
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 OrthancPluginMemoryBuffer* operator*()
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 return &buffer_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 // This transfers ownership
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 void Assign(OrthancPluginMemoryBuffer& other);
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 const char* GetData() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if (buffer_.size > 0)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return reinterpret_cast<const char*>(buffer_.data);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 else
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 return NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
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 size_t GetSize() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return buffer_.size;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 void ToString(std::string& target) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 void ToJson(Json::Value& target) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 bool RestApiGet(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 bool applyPlugins);
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 bool RestApiPost(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 bool applyPlugins);
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 bool RestApiPost(const std::string& uri,
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
134 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
135 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
136
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
137 bool RestApiPut(const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
138 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
139 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
140
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
141 bool RestApiPost(const std::string& uri,
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return RestApiPost(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins);
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 bool RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 bool applyPlugins)
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 return RestApiPut(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
154
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
155 void CreateDicom(const Json::Value& tags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
156 OrthancPluginCreateDicomFlags flags);
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2060
diff changeset
157
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2060
diff changeset
158 void ReadFile(const std::string& path);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
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 class OrthancString : public boost::noncopyable
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 char* str_;
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 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 OrthancString(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 char* str);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 ~OrthancString()
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 const char* GetContent() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 return str_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
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 void ToString(std::string& target) const;
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 void ToJson(Json::Value& target) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 class OrthancConfiguration : public boost::noncopyable
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 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 OrthancPluginContext* context_;
2167
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2109
diff changeset
194 Json::Value configuration_; // Necessarily a Json::objectValue
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 std::string path_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 std::string GetPath(const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 OrthancConfiguration() : context_(NULL)
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 OrthancConfiguration(OrthancPluginContext* context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 OrthancPluginContext* GetContext() const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 const Json::Value& GetJson() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 return configuration_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
2167
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2109
diff changeset
213 bool IsSection(const std::string& key) const;
aa2915963531 "Folders" sub-configuration in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2109
diff changeset
214
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 void GetSection(OrthancConfiguration& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 bool LookupStringValue(std::string& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 bool LookupIntegerValue(int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 bool LookupUnsignedIntegerValue(unsigned int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 bool LookupBooleanValue(bool& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 bool LookupFloatValue(float& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 std::string GetStringValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 const std::string& defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 int GetIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 unsigned int GetUnsignedIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 unsigned int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 bool GetBooleanValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 bool defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 float GetFloatValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 float defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 class OrthancImage
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 OrthancPluginImage* image_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 void CheckImageAvailable();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 OrthancImage(OrthancPluginContext* context);
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 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 OrthancPluginImage* image);
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 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 OrthancPluginPixelFormat format,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 uint32_t width,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 uint32_t height);
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 ~OrthancImage()
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 Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
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 void UncompressPngImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 size_t size);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 void UncompressJpegImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 size_t size);
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 void DecodeDicomImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 size_t size,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 unsigned int frame);
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 OrthancPluginPixelFormat GetPixelFormat();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 unsigned int GetWidth();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 unsigned int GetHeight();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 unsigned int GetPitch();
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 const void* GetBuffer();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 void CompressPngImage(MemoryBuffer& 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 void CompressJpegImage(MemoryBuffer& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 uint8_t quality);
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 void AnswerPngImage(OrthancPluginRestOutput* output);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 void AnswerJpegImage(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 uint8_t quality);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
307 bool RestApiGet(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
308 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
309 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
310 bool applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
312 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
313 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
314 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
315 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
316 size_t bodySize,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
317 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
318
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
319 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
320 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
321 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
322 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
323 bool applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
325 inline bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
326 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
327 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
328 const std::string& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
329 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
330 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
331 return RestApiPost(result, context, uri, body.empty() ? NULL : body.c_str(),
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
332 body.size(), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
333 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
335 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
336 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
337 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
338 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
339 size_t bodySize,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
340 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
341
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
342 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
343 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
344 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
345 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
346 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
347
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
348 inline bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
349 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
350 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
351 const std::string& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
352 bool applyPlugins)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 {
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
354 return RestApiPut(result, context, uri, body.empty() ? NULL : body.c_str(),
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
355 body.size(), applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
2057
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
366 inline void LogError(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
367 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
368 {
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
369 if (context != NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
370 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
371 OrthancPluginLogError(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
372 }
2057
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
373 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
374
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
375 inline void LogWarning(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
376 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
377 {
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
378 if (context != NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
379 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
380 OrthancPluginLogWarning(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
381 }
2057
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
382 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
383
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
384 inline void LogInfo(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
385 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
386 {
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
387 if (context != NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
388 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
389 OrthancPluginLogInfo(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
390 }
2057
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
391 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
392
2109
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
393 bool CheckMinimalOrthancVersion(OrthancPluginContext* context,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
394 unsigned int major,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
395 unsigned int minor,
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
396 unsigned int revision);
d5c29fd74ffa OrthancPlugins::CheckMinimalOrthancVersion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2062
diff changeset
397
2047
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 namespace Internals
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 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 const char* url,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 const OrthancPluginHttpRequest* request)
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 try
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 Callback(output, url, request);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 return OrthancPluginErrorCode_Success;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 catch (OrthancPlugins::PluginException& e)
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 return e.GetErrorCode();
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 #if HAS_ORTHANC_EXCEPTION == 1
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 catch (Orthanc::OrthancException& e)
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 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
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 #endif
2056
e166a902b3c4 removal of warnings in msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
421 catch (boost::bad_lexical_cast&)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 return OrthancPluginErrorCode_BadFileFormat;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 catch (...)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 return OrthancPluginErrorCode_Plugin;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 void RegisterRestCallback(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 bool isThreadSafe)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 if (isThreadSafe)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 OrthancPluginRegisterRestCallbackNoLock(context, uri.c_str(), Internals::Protect<Callback>);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 OrthancPluginRegisterRestCallback(context, uri.c_str(), Internals::Protect<Callback>);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
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 }