annotate Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2056:e166a902b3c4

removal of warnings in msvc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 27 Jun 2016 17:35:58 +0200
parents 438f86ee19fc
children 54417b0831c4
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,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 const std::string& body,
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 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
134 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 bool RestApiPut(const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 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
141 }
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 class OrthancString : public boost::noncopyable
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 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 char* str_;
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 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 OrthancString(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 char* str);
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 ~OrthancString()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 Clear();
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 void Clear();
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 const char* GetContent() const
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 return str_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 void ToString(std::string& target) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 void ToJson(Json::Value& target) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 };
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 class OrthancConfiguration : public boost::noncopyable
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 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 Json::Value configuration_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 std::string path_;
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 std::string GetPath(const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 OrthancConfiguration() : context_(NULL)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 OrthancConfiguration(OrthancPluginContext* context);
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 OrthancPluginContext* GetContext() const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 const Json::Value& GetJson() const
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 return configuration_;
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 void GetSection(OrthancConfiguration& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 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 bool LookupStringValue(std::string& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 const std::string& key) const;
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 bool LookupIntegerValue(int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 bool LookupUnsignedIntegerValue(unsigned int& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 const std::string& key) 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 bool LookupBooleanValue(bool& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 bool LookupFloatValue(float& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const std::string& key) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 std::string GetStringValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 const std::string& defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 int GetIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 unsigned int GetUnsignedIntegerValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 unsigned int defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 bool GetBooleanValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 bool defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 float GetFloatValue(const std::string& key,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 float defaultValue) const;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 };
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 class OrthancImage
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 private:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 OrthancPluginContext* context_;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 OrthancPluginImage* image_;
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 void Clear();
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 void CheckImageAvailable();
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 public:
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 OrthancImage(OrthancPluginContext* context);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 OrthancPluginImage* image);
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 OrthancImage(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 OrthancPluginPixelFormat format,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 uint32_t width,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 uint32_t height);
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()
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 Clear();
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 void UncompressPngImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 size_t size);
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 void UncompressJpegImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 size_t size);
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 void DecodeDicomImage(const void* data,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 size_t size,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 unsigned int frame);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 OrthancPluginPixelFormat GetPixelFormat();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 unsigned int GetWidth();
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 unsigned int GetHeight();
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 unsigned int GetPitch();
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 const void* GetBuffer();
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 void CompressPngImage(MemoryBuffer& target);
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 CompressJpegImage(MemoryBuffer& target,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 uint8_t quality);
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 AnswerPngImage(OrthancPluginRestOutput* output);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 void AnswerJpegImage(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 uint8_t quality);
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
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 bool RestApiGetJson(Json::Value& result,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 bool applyPlugins);
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 bool RestApiPostJson(Json::Value& result,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 bool applyPlugins);
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 bool RestApiPutJson(Json::Value& result,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 const char* body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 size_t bodySize,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 inline bool RestApiPostJson(Json::Value& result,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 return RestApiPostJson(result, context, uri, body.empty() ? NULL : body.c_str(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 body.size(), applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 inline bool RestApiPutJson(Json::Value& result,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 const std::string& body,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 bool applyPlugins)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 return RestApiPutJson(result, context, uri, body.empty() ? NULL : body.c_str(),
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 body.size(), applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 bool RestApiDelete(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 bool applyPlugins);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 namespace Internals
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 const char* url,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 const OrthancPluginHttpRequest* request)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 try
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 Callback(output, url, request);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 return OrthancPluginErrorCode_Success;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 catch (OrthancPlugins::PluginException& e)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 return e.GetErrorCode();
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 #if HAS_ORTHANC_EXCEPTION == 1
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 catch (Orthanc::OrthancException& e)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
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 #endif
2056
e166a902b3c4 removal of warnings in msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2047
diff changeset
358 catch (boost::bad_lexical_cast&)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 return OrthancPluginErrorCode_BadFileFormat;
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 catch (...)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 return OrthancPluginErrorCode_Plugin;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 template <RestCallback Callback>
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 void RegisterRestCallback(OrthancPluginContext* context,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 const std::string& uri,
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 bool isThreadSafe)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 if (isThreadSafe)
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 OrthancPluginRegisterRestCallbackNoLock(context, uri.c_str(), Internals::Protect<Callback>);
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 else
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 OrthancPluginRegisterRestCallback(context, uri.c_str(), Internals::Protect<Callback>);
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 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }