annotate Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2058:43cd2ab060c7

cont OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Jun 2016 08:20:23 +0200
parents 54417b0831c4
children 8e67325eaa3f
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 # include <OrthancException.h>
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;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
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 class MemoryBuffer : public boost::noncopyable
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 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 OrthancPluginMemoryBuffer buffer_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 MemoryBuffer(OrthancPluginContext* context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ~MemoryBuffer()
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 Clear();
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 OrthancPluginMemoryBuffer* operator*()
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 return &buffer_;
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 // This transfers ownership
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 void Assign(OrthancPluginMemoryBuffer& other);
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 const char* GetData() const
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 if (buffer_.size > 0)
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 return reinterpret_cast<const char*>(buffer_.data);
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 else
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 NULL;
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 }
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 size_t GetSize() const
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 return buffer_.size;
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 void ToString(std::string& target) const;
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 ToJson(Json::Value& target) const;
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 bool RestApiGet(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 bool RestApiPost(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 bool RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 bool applyPlugins);
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 bool RestApiPost(const std::string& uri,
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
130 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
131 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
132
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
133 bool RestApiPut(const std::string& uri,
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 RestApiPost(const std::string& uri,
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 bool applyPlugins)
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 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
142 }
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 bool RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 bool applyPlugins)
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 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
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 class OrthancString : public boost::noncopyable
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 char* str_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 OrthancString(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 char* str);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 ~OrthancString()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 Clear();
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 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const char* GetContent() const
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 return str_;
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 void ToString(std::string& target) const;
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 ToJson(Json::Value& target) const;
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
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 class OrthancConfiguration : public boost::noncopyable
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 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 Json::Value configuration_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 std::string path_;
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 std::string GetPath(const std::string& key) const;
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 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 OrthancConfiguration() : context_(NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 OrthancConfiguration(OrthancPluginContext* context);
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 OrthancPluginContext* GetContext() 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 const Json::Value& GetJson() const
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 return configuration_;
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 void GetSection(OrthancConfiguration& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 bool LookupStringValue(std::string& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 const std::string& key) 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 bool LookupIntegerValue(int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 bool LookupUnsignedIntegerValue(unsigned int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 bool LookupBooleanValue(bool& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 bool LookupFloatValue(float& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 std::string GetStringValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 const std::string& defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 int GetIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 unsigned int GetUnsignedIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 unsigned int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 bool GetBooleanValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 bool defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 float GetFloatValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 float defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 };
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 class OrthancImage
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 OrthancPluginImage* image_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 void Clear();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 void CheckImageAvailable();
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 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 OrthancImage(OrthancPluginContext* context);
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 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 OrthancPluginImage* image);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 OrthancPluginPixelFormat format,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 uint32_t width,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 uint32_t height);
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 ~OrthancImage()
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 Clear();
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 void UncompressPngImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 size_t size);
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 void UncompressJpegImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 size_t size);
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 void DecodeDicomImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 size_t size,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 unsigned int frame);
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 OrthancPluginPixelFormat GetPixelFormat();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 unsigned int GetWidth();
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 unsigned int GetHeight();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 unsigned int GetPitch();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 const void* GetBuffer();
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 void CompressPngImage(MemoryBuffer& target);
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 CompressJpegImage(MemoryBuffer& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 uint8_t quality);
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 void AnswerPngImage(OrthancPluginRestOutput* output);
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 void AnswerJpegImage(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 uint8_t quality);
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
296 bool RestApiGet(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
297 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
298 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
299 bool applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
301 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
302 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
303 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
304 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
305 size_t bodySize,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
306 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
307
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
308 bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
309 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
310 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
311 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
312 bool applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
314 inline bool RestApiPost(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
315 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
316 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
317 const std::string& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
318 bool applyPlugins)
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
319 {
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
320 return RestApiPost(result, context, uri, body.empty() ? NULL : body.c_str(),
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
321 body.size(), applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
322 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
324 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
325 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
326 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
327 const char* body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
328 size_t bodySize,
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 bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
332 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
333 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
334 const Json::Value& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
335 bool applyPlugins);
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
336
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
337 inline bool RestApiPut(Json::Value& result,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
338 OrthancPluginContext* context,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
339 const std::string& uri,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
340 const std::string& body,
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
341 bool applyPlugins)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
343 return RestApiPut(result, context, uri, body.empty() ? NULL : body.c_str(),
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2057
diff changeset
344 body.size(), applyPlugins);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
2057
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
355 inline void LogError(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
356 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
357 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
358 OrthancPluginLogError(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
359 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
360
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
361 inline void LogWarning(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
362 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
363 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
364 OrthancPluginLogWarning(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
365 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
366
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
367 inline void LogInfo(OrthancPluginContext* context,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
368 const std::string& message)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
369 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
370 OrthancPluginLogInfo(context, message.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
371 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2056
diff changeset
372
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 namespace Internals
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 const char* url,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 const OrthancPluginHttpRequest* request)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 try
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Callback(output, url, request);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 return OrthancPluginErrorCode_Success;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 catch (OrthancPlugins::PluginException& e)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 return e.GetErrorCode();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 #if HAS_ORTHANC_EXCEPTION == 1
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 catch (Orthanc::OrthancException& e)
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 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 #endif
2056
e166a902b3c4 removal of warnings in msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
396 catch (boost::bad_lexical_cast&)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 return OrthancPluginErrorCode_BadFileFormat;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 catch (...)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 return OrthancPluginErrorCode_Plugin;
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 void RegisterRestCallback(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 bool isThreadSafe)
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 if (isThreadSafe)
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 OrthancPluginRegisterRestCallbackNoLock(context, uri.c_str(), Internals::Protect<Callback>);
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 else
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 OrthancPluginRegisterRestCallback(context, uri.c_str(), Internals::Protect<Callback>);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
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 }