annotate RenderingPlugin/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 2134:93258466311b deep-learning

integration mainline->deep-learning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 21:31:37 +0200
parents 2965172977a4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2133
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2124
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
2114
c23eef785569 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2108
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
1638
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
13 *
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "OrthancPluginCppWrapper.h"
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <boost/algorithm/string/predicate.hpp>
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <boost/move/unique_ptr.hpp>
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <boost/thread.hpp>
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
29
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
30
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <json/reader.h>
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
32 #include <json/version.h>
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <json/writer.h>
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
35 #if !defined(JSONCPP_VERSION_MAJOR) || !defined(JSONCPP_VERSION_MINOR)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
36 # error Cannot access the version of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
37 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
38
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
39
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
40 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
41 * We use deprecated "Json::Reader", "Json::StyledWriter" and
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
42 * "Json::FastWriter" if JsonCpp < 1.7.0. This choice is rather
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
43 * arbitrary, but if Json >= 1.9.0, gcc generates explicit deprecation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
44 * warnings (clang was warning in earlier versions). For reference,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
45 * these classes seem to have been deprecated since JsonCpp 1.4.0 (on
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
46 * February 2015) by the following changeset:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
47 * https://github.com/open-source-parsers/jsoncpp/commit/8df98f6112890d6272734975dd6d70cf8999bb22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
48 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
49 #if (JSONCPP_VERSION_MAJOR >= 2 || \
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
50 (JSONCPP_VERSION_MAJOR == 1 && JSONCPP_VERSION_MINOR >= 8))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
51 # define JSONCPP_USE_DEPRECATED 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
52 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
53 # define JSONCPP_USE_DEPRECATED 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
54 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
55
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 namespace OrthancPlugins
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 static OrthancPluginContext* globalContext_ = NULL;
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
65 static std::string pluginName_;
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 void SetGlobalContext(OrthancPluginContext* context)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (context == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 else if (globalContext_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 globalContext_ = context;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
84
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
85 void SetGlobalContext(OrthancPluginContext* context,
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
86 const char* pluginName)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
87 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
88 SetGlobalContext(context);
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
89 pluginName_ = pluginName;
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
90 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
91
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
92
2101
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2081
diff changeset
93 void ResetGlobalContext()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2081
diff changeset
94 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2081
diff changeset
95 globalContext_ = NULL;
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
96 pluginName_.clear();
2101
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2081
diff changeset
97 }
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 bool HasGlobalContext()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return globalContext_ != NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 OrthancPluginContext* GetGlobalContext()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (globalContext_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return globalContext_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
118 #if HAS_ORTHANC_PLUGIN_LOG_MESSAGE == 1
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
119 void LogMessage(OrthancPluginLogLevel level,
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
120 const char* file,
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
121 uint32_t line,
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
122 const std::string& message)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
123 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
124 if (HasGlobalContext())
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
125 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
126 #if HAS_ORTHANC_PLUGIN_LOG_MESSAGE == 1
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
127 const char* pluginName = (pluginName_.empty() ? NULL : pluginName_.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
128 OrthancPluginLogMessage(GetGlobalContext(), message.c_str(), pluginName, file, line, OrthancPluginLogCategory_Generic, level);
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
129 #else
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
130 switch (level)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
131 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
132 case OrthancPluginLogLevel_Error:
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
133 OrthancPluginLogError(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
134 break;
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
135
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
136 case OrthancPluginLogLevel_Warning:
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
137 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
138 break;
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
139
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
140 case OrthancPluginLogLevel_Info:
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
141 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
142 break;
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
143
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
144 default:
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
145 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
146 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
147 #endif
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
148 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
149 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
150 #endif
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
151
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
152
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
153 void LogError(const std::string& message)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
154 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
155 if (HasGlobalContext())
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
156 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
157 OrthancPluginLogError(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
158 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
159 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
160
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
161 void LogWarning(const std::string& message)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
162 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
163 if (HasGlobalContext())
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
164 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
165 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
166 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
167 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
168
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
169 void LogInfo(const std::string& message)
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
170 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
171 if (HasGlobalContext())
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
172 {
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
173 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
174 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
175 }
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
176
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
177
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 void MemoryBuffer::Check(OrthancPluginErrorCode code)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 if (code != OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 // Prevent using garbage information
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 buffer_.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 buffer_.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 if (code != OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 // Prevent using garbage information
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 buffer_.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 buffer_.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 else if (code == OrthancPluginErrorCode_UnknownResource ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 code == OrthancPluginErrorCode_InexistentItem)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 MemoryBuffer::MemoryBuffer()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 buffer_.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 buffer_.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 MemoryBuffer::MemoryBuffer(const void* buffer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 size_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 uint32_t s = static_cast<uint32_t>(size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (static_cast<size_t>(s) != size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 else if (OrthancPluginCreateMemoryBuffer(GetGlobalContext(), &buffer_, s) !=
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 memcpy(buffer_.data, buffer, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 void MemoryBuffer::Clear()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (buffer_.data != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 buffer_.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 buffer_.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 buffer_.data = other.data;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 buffer_.size = other.size;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 other.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 other.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 void MemoryBuffer::Swap(MemoryBuffer& other)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 std::swap(buffer_.data, other.buffer_.data);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 std::swap(buffer_.size, other.buffer_.size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 OrthancPluginMemoryBuffer MemoryBuffer::Release()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 OrthancPluginMemoryBuffer result = buffer_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 buffer_.data = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 buffer_.size = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 return result;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 void MemoryBuffer::ToString(std::string& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 if (buffer_.size == 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 target.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 void MemoryBuffer::ToJson(Json::Value& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 if (buffer_.data == NULL ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 buffer_.size == 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
306 if (!ReadJson(target, buffer_.data, buffer_.size))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
308 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 bool MemoryBuffer::RestApiGet(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 if (applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
329 // helper class to convert std::map of headers to the plugin SDK C structure
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
330 class PluginHttpHeaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
331 {
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
332 private:
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
333 std::vector<const char*> headersKeys_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
334 std::vector<const char*> headersValues_;
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
335
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
336 public:
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
337 explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders)
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
338 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
339 for (std::map<std::string, std::string>::const_iterator
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
340 it = httpHeaders.begin(); it != httpHeaders.end(); ++it)
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
341 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
342 headersKeys_.push_back(it->first.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
343 headersValues_.push_back(it->second.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
344 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
345 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
346
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
347 const char* const* GetKeys()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
348 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
349 return (headersKeys_.empty() ? NULL : &headersKeys_[0]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
350 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
351
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
352 const char* const* GetValues()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
353 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
354 return (headersValues_.empty() ? NULL : &headersValues_[0]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
355 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
356
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
357 uint32_t GetSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
358 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
359 return static_cast<uint32_t>(headersKeys_.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
360 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
361 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
362
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 bool MemoryBuffer::RestApiGet(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 const std::map<std::string, std::string>& httpHeaders,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
369 PluginHttpHeaders headers(httpHeaders);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 return CheckHttp(OrthancPluginRestApiGet2(
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
372 GetGlobalContext(), &buffer_, uri.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
373 headers.GetSize(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
374 headers.GetKeys(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
375 headers.GetValues(), applyPlugins));
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 bool MemoryBuffer::RestApiPost(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 const void* body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 size_t bodySize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 // Cast for compatibility with Orthanc SDK <= 1.5.6
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 const char* b = reinterpret_cast<const char*>(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 if (applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
398 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
399
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
400 bool MemoryBuffer::RestApiPost(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
401 const void* body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
402 size_t bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
403 const std::map<std::string, std::string>& httpHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
404 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
405 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
406 MemoryBuffer answerHeaders;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
407 uint16_t httpStatus;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
408
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
409 PluginHttpHeaders headers(httpHeaders);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
410
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
411 return CheckHttp(OrthancPluginCallRestApi(GetGlobalContext(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
412 &buffer_,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
413 *answerHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
414 &httpStatus,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
415 OrthancPluginHttpMethod_Post,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
416 uri.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
417 headers.GetSize(), headers.GetKeys(), headers.GetValues(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
418 body, bodySize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
419 applyPlugins));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
420 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
421
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
422
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
423 bool MemoryBuffer::RestApiPost(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
424 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
425 const std::map<std::string, std::string>& httpHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
426 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
427 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
428 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
429 WriteFastJson(s, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
430 return RestApiPost(uri, s.c_str(), s.size(), httpHeaders, applyPlugins);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
431 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
432 #endif
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 bool MemoryBuffer::RestApiPut(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 const void* body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 size_t bodySize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 // Cast for compatibility with Orthanc SDK <= 1.5.6
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 const char* b = reinterpret_cast<const char*>(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 if (applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
455 static bool ReadJsonInternal(Json::Value& target,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
456 const void* buffer,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
457 size_t size,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
458 bool collectComments)
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
459 {
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
460 #if JSONCPP_USE_DEPRECATED == 1
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
461 Json::Reader reader;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
462 return reader.parse(reinterpret_cast<const char*>(buffer),
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
463 reinterpret_cast<const char*>(buffer) + size, target, collectComments);
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
464 #else
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
465 Json::CharReaderBuilder builder;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
466 builder.settings_["collectComments"] = collectComments;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
467
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
468 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
469 assert(reader.get() != NULL);
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
470
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
471 JSONCPP_STRING err;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
472 if (reader->parse(reinterpret_cast<const char*>(buffer),
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
473 reinterpret_cast<const char*>(buffer) + size, &target, &err))
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
474 {
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
475 return true;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
476 }
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
477 else
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
478 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
479 ORTHANC_PLUGINS_LOG_ERROR("Cannot parse JSON: " + std::string(err));
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
480 return false;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
481 }
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
482 #endif
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
483 }
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
484
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
485
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
486 bool ReadJson(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
487 const std::string& source)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
488 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
489 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
490 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
492
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
493 bool ReadJson(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
494 const void* buffer,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
495 size_t size)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
496 {
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
497 return ReadJsonInternal(target, buffer, size, true);
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
498 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
499
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
500
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
501 bool ReadJsonWithoutComments(Json::Value& target,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
502 const std::string& source)
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
503 {
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
504 return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size());
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
505 }
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
506
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
507
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
508 bool ReadJsonWithoutComments(Json::Value& target,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
509 const void* buffer,
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
510 size_t size)
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
511 {
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
512 return ReadJsonInternal(target, buffer, size, false);
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
513 }
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
514
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
515
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
516 void WriteFastJson(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
517 const Json::Value& source)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
518 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
519 #if JSONCPP_USE_DEPRECATED == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
520 Json::FastWriter writer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
521 target = writer.write(source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
522 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
523 Json::StreamWriterBuilder builder;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
524 builder.settings_["indentation"] = "";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
525 target = Json::writeString(builder, source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
526 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
527 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
528
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
529
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
530 void WriteStyledJson(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
531 const Json::Value& source)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
532 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
533 #if JSONCPP_USE_DEPRECATED == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
534 Json::StyledWriter writer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
535 target = writer.write(source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
536 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
537 Json::StreamWriterBuilder builder;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
538 builder.settings_["indentation"] = " ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
539 target = Json::writeString(builder, source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
540 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
541 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
542
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
543
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 bool MemoryBuffer::RestApiPost(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 const Json::Value& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
548 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
549 WriteFastJson(s, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
550 return RestApiPost(uri, s, applyPlugins);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 bool MemoryBuffer::RestApiPut(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 const Json::Value& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
558 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
559 WriteFastJson(s, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
560 return RestApiPut(uri, s, applyPlugins);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 void MemoryBuffer::CreateDicom(const Json::Value& tags,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 OrthancPluginCreateDicomFlags flags)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
569 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
570 WriteFastJson(s, tags);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 void MemoryBuffer::CreateDicom(const Json::Value& tags,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 const OrthancImage& pixelData,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 OrthancPluginCreateDicomFlags flags)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
581 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
582 WriteFastJson(s, tags);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 void MemoryBuffer::ReadFile(const std::string& path)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 void OrthancString::Assign(char* str)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 if (str != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 str_ = str;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 void OrthancString::Clear()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 if (str_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 OrthancPluginFreeString(GetGlobalContext(), str_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 str_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 void OrthancString::ToString(std::string& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 if (str_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 target.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 target.assign(str_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 void OrthancString::ToJson(Json::Value& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 if (str_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
640 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
644 if (!ReadJson(target, str_))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
646 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
652 void OrthancString::ToJsonWithoutComments(Json::Value& target) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
653 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
654 if (str_ == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
655 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
656 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
657 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
658 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
659
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
660 if (!ReadJsonWithoutComments(target, str_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
661 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
662 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
663 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
664 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
665 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
666
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
667
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 void MemoryBuffer::DicomToJson(Json::Value& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 OrthancPluginDicomToJsonFormat format,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 OrthancPluginDicomToJsonFlags flags,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 uint32_t maxStringLength)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 OrthancString str;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 str.Assign(OrthancPluginDicomBufferToJson
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 str.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 bool MemoryBuffer::HttpGet(const std::string& url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 const std::string& username,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 const std::string& password)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 username.empty() ? NULL : username.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 password.empty() ? NULL : password.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 bool MemoryBuffer::HttpPost(const std::string& url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 const std::string& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 const std::string& username,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 const std::string& password)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 Clear();
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
697
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
698 if (body.size() > 0xffffffffu)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
699 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
700 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
701 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
702 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
703
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 body.c_str(), body.size(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 username.empty() ? NULL : username.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 password.empty() ? NULL : password.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 bool MemoryBuffer::HttpPut(const std::string& url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 const std::string& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 const std::string& username,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 const std::string& password)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 Clear();
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
717
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
718 if (body.size() > 0xffffffffu)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
719 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
720 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
721 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
722 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
723
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 body.empty() ? NULL : body.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 body.size(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 username.empty() ? NULL : username.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 password.empty() ? NULL : password.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 void MemoryBuffer::GetDicomInstance(const std::string& instanceId)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 bool HttpDelete(const std::string& url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 const std::string& username,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 const std::string& password)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 OrthancPluginErrorCode error = OrthancPluginHttpDelete
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 (GetGlobalContext(), url.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 username.empty() ? NULL : username.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 password.empty() ? NULL : password.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 if (error == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 else if (error == OrthancPluginErrorCode_UnknownResource ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 error == OrthancPluginErrorCode_InexistentItem)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 void OrthancConfiguration::LoadConfiguration()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 OrthancString str;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext()));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 if (str.GetContent() == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
770 ORTHANC_PLUGINS_LOG_ERROR("Cannot access the Orthanc configuration");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
774 str.ToJsonWithoutComments(configuration_);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 if (configuration_.type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
778 ORTHANC_PLUGINS_LOG_ERROR("Unable to read the Orthanc configuration");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 OrthancConfiguration::OrthancConfiguration()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 LoadConfiguration();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 if (loadConfiguration)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 LoadConfiguration();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 configuration_ = Json::objectValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
802 OrthancConfiguration::OrthancConfiguration(const Json::Value& configuration, const std::string& path) :
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
803 configuration_(configuration),
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
804 path_(path)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
805 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
806 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
807
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 std::string OrthancConfiguration::GetPath(const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 if (path_.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 return key;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 return path_ + "." + key;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 bool OrthancConfiguration::IsSection(const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 return (configuration_.isMember(key) &&
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 configuration_[key].type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 void OrthancConfiguration::GetSection(OrthancConfiguration& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 target.path_ = GetPath(key);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 target.configuration_ = Json::objectValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 if (configuration_[key].type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
846 ORTHANC_PLUGINS_LOG_ERROR("The configuration section \"" + target.path_ +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
847 "\" is not an associative array as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 target.configuration_ = configuration_[key];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 bool OrthancConfiguration::LookupStringValue(std::string& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 if (configuration_[key].type() != Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
869 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
870 "\" is not a string as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 target = configuration_[key].asString();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 bool OrthancConfiguration::LookupIntegerValue(int& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 switch (configuration_[key].type())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 case Json::intValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 target = configuration_[key].asInt();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 case Json::uintValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 target = configuration_[key].asUInt();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 default:
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
901 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
902 "\" is not an integer as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 int tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 if (!LookupIntegerValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 if (tmp < 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
920 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
921 "\" is not a positive integer as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 target = static_cast<unsigned int>(tmp);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 bool OrthancConfiguration::LookupBooleanValue(bool& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 if (configuration_[key].type() != Json::booleanValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
945 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
946 "\" is not a Boolean as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 target = configuration_[key].asBool();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 bool OrthancConfiguration::LookupFloatValue(float& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 switch (configuration_[key].type())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 case Json::realValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 target = configuration_[key].asFloat();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 case Json::intValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 target = static_cast<float>(configuration_[key].asInt());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 case Json::uintValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 target = static_cast<float>(configuration_[key].asUInt());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 default:
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
981 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
982 "\" is not an integer as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 bool allowSingleString) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 target.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 switch (configuration_[key].type())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 case Json::arrayValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 bool ok = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 if (configuration_[key][i].type() == Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012 target.push_back(configuration_[key][i].asString());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 ok = false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 if (ok)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 case Json::stringValue:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 if (allowSingleString)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 target.push_back(configuration_[key].asString());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 default:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1041 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1042 "\" is not a list of strings as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 bool allowSingleString) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 std::list<std::string> lst;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 if (LookupListOfStrings(lst, key, allowSingleString))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 target.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 for (std::list<std::string>::const_iterator
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 it = lst.begin(); it != lst.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 target.insert(*it);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 std::string OrthancConfiguration::GetStringValue(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074 const std::string& defaultValue) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 std::string tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 if (LookupStringValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 return defaultValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 int OrthancConfiguration::GetIntegerValue(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 int defaultValue) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 int tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 if (LookupIntegerValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 return defaultValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 unsigned int defaultValue) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 unsigned int tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 if (LookupUnsignedIntegerValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 return defaultValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 bool OrthancConfiguration::GetBooleanValue(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 bool defaultValue) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 bool tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 if (LookupBooleanValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128 return defaultValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 float OrthancConfiguration::GetFloatValue(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 float defaultValue) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 float tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137 if (LookupFloatValue(tmp, key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 return defaultValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 assert(configuration_.type() == Json::objectValue);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 target.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 if (!configuration_.isMember(key))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 return;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 if (configuration_[key].type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1162 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1163 "\" is not an object as expected");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 Json::Value::Members members = configuration_[key].getMemberNames();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 for (size_t i = 0; i < members.size(); i++)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 const Json::Value& value = configuration_[key][members[i]];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 if (value.type() == Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 target[members[i]] = value.asString();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1180 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1181 "\" is not a dictionary mapping strings to strings");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 void OrthancImage::Clear()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 if (image_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 OrthancPluginFreeImage(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 image_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 void OrthancImage::CheckImageAvailable() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1203 ORTHANC_PLUGINS_LOG_ERROR("Trying to access a NULL image");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 OrthancImage::OrthancImage() :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 image_(NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 OrthancImage::OrthancImage(OrthancPluginImage* image) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 image_(image)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 uint32_t width,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 uint32_t height)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1229 ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 uint32_t width,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 uint32_t height,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 uint32_t pitch,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 void* buffer)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 image_ = OrthancPluginCreateImageAccessor
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 (GetGlobalContext(), format, width, height, pitch, buffer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1246 ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image accessor");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 void OrthancImage::UncompressPngImage(const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 size_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1260 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a PNG image");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 void OrthancImage::UncompressJpegImage(const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 size_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1273 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a JPEG image");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 void OrthancImage::DecodeDicomImage(const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 size_t size,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 unsigned int frame)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 if (image_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1287 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a DICOM image");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 unsigned int OrthancImage::GetWidth() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 return OrthancPluginGetImageWidth(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307 unsigned int OrthancImage::GetHeight() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 return OrthancPluginGetImageHeight(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 unsigned int OrthancImage::GetPitch() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 return OrthancPluginGetImagePitch(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 void* OrthancImage::GetBuffer() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 void OrthancImage::CompressPngImage(MemoryBuffer& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 target.Swap(answer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 void OrthancImage::CompressJpegImage(MemoryBuffer& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 uint8_t quality) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349 target.Swap(answer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362 uint8_t quality) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 OrthancPluginImage* OrthancImage::Release()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 CheckImageAvailable();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 OrthancPluginImage* tmp = image_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 image_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 matcher_(NULL),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 worklist_(worklist)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 if (worklist_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 void FindMatcher::SetupDicom(const void* query,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 uint32_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 worklist_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 if (matcher_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 FindMatcher::~FindMatcher()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 // The "worklist_" field
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 if (matcher_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 bool FindMatcher::IsMatch(const void* dicom,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 uint32_t size) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 int32_t result;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 if (matcher_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 else if (worklist_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434 if (result == 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438 else if (result == 1)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1441 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1443 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1450 void AnswerJson(const Json::Value& value,
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1451 OrthancPluginRestOutput* output)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1453 std::string bodyString;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1454 WriteStyledJson(bodyString, value);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458 void AnswerString(const std::string& answer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 const char* mimeType,
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1460 OrthancPluginRestOutput* output)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1472 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 bool RestApiGetString(std::string& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 if (!answer.RestApiGet(uri, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 answer.ToString(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 bool RestApiGetString(std::string& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493 const std::map<std::string, std::string>& httpHeaders,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 answer.ToString(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1509 bool RestApiGet(Json::Value& result,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1510 const std::string& uri,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1511 const std::map<std::string, std::string>& httpHeaders,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1512 bool applyPlugins)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1513 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1514 MemoryBuffer answer;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1515
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1516 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins))
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1517 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1518 return false;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1519 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1520 else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1521 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1522 if (!answer.IsEmpty())
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1523 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1524 answer.ToJson(result);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1525 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1526 return true;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1527 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1528 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
1529
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 bool RestApiGet(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 if (!answer.RestApiGet(uri, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 if (!answer.IsEmpty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 answer.ToJson(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 bool RestApiPost(std::string& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 const void* body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 size_t bodySize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 if (!answer.IsEmpty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 result.assign(answer.GetData(), answer.GetSize());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1574
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1575 bool RestApiPost(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 const void* body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 size_t bodySize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1589 if (!answer.IsEmpty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1590 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591 answer.ToJson(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1592 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1593 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1597 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1598 bool RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1599 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1600 const Json::Value& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1601 const std::map<std::string, std::string>& httpHeaders,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1602 bool applyPlugins)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1603 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1604 MemoryBuffer answer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1605
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1606 if (!answer.RestApiPost(uri, body, httpHeaders, applyPlugins))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1607 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1608 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1609 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1610 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1611 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1612 if (!answer.IsEmpty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1613 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1614 answer.ToJson(result);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1615 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1616 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1617 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1618 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1619 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1620
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622 bool RestApiPost(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1624 const Json::Value& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1626 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1627 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1628 WriteFastJson(s, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1629 return RestApiPost(result, uri, s, applyPlugins);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 bool RestApiPut(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1634 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635 const void* body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636 size_t bodySize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1641 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 answer.ToJson(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1653 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1656 bool RestApiPut(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 const Json::Value& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1659 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1661 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1662 WriteFastJson(s, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
1663 return RestApiPut(result, uri, s, applyPlugins);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1666
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 bool RestApiDelete(const std::string& uri,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 bool applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670 OrthancPluginErrorCode error;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1672 if (applyPlugins)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1677 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 if (error == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685 else if (error == OrthancPluginErrorCode_UnknownResource ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 error == OrthancPluginErrorCode_InexistentItem)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1689 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1691 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1692 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1693 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1694 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1695
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1696
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1697 void ReportMinimalOrthancVersion(unsigned int major,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1698 unsigned int minor,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699 unsigned int revision)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1701 ORTHANC_PLUGINS_LOG_ERROR("Your version of the Orthanc core (" +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1702 std::string(GetGlobalContext()->orthancVersion) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1703 ") is too old to run this plugin (version " +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1704 boost::lexical_cast<std::string>(major) + "." +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1705 boost::lexical_cast<std::string>(minor) + "." +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1706 boost::lexical_cast<std::string>(revision) +
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1707 " is required)");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1708 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1710 bool CheckMinimalVersion(const char* version,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1711 unsigned int major,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1712 unsigned int minor,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1713 unsigned int revision)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 {
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1715 if (!strcmp(version, "mainline"))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717 // Assume compatibility with the mainline
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1719 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1720
2081
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1721 #ifdef _MSC_VER
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1722 #define ORTHANC_SCANF sscanf_s
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1723 #else
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1724 #define ORTHANC_SCANF sscanf
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1725 #endif
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1726
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1727 // Parse the version
2081
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1728 int aa, bb, cc = 0;
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1729 if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 &&
3ef91da06636 fix compatibility with Emscripten 3.1.47
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
1730 ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) ||
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1731 aa < 0 ||
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1732 bb < 0 ||
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1733 cc < 0)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1734 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1735 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1736 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1737
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1738 unsigned int a = static_cast<unsigned int>(aa);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1739 unsigned int b = static_cast<unsigned int>(bb);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1740 unsigned int c = static_cast<unsigned int>(cc);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1742 // Check the major version number
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1743
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1744 if (a > major)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1745 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1746 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1747 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1748
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1749 if (a < major)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1750 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1751 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1752 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1753
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1754 // Check the minor version number
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1755 assert(a == major);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1756
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1757 if (b > minor)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1758 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1759 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1760 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1761
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1762 if (b < minor)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1763 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1764 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1767 // Check the patch level version number
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1768 assert(a == major && b == minor);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1770 if (c >= revision)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1771 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1772 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1773 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1774 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1775 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1776 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1777 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1778 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1779
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1780
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1781 bool CheckMinimalOrthancVersion(unsigned int major,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1782 unsigned int minor,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1783 unsigned int revision)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1784 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1785 if (!HasGlobalContext())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1786 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1787 ORTHANC_PLUGINS_LOG_ERROR("Bad Orthanc context in the plugin");
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1788 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1789 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1790
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1791 return CheckMinimalVersion(GetGlobalContext()->orthancVersion,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1792 major, minor, revision);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1793 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1794
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
1795
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1796 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1797 const char* AutodetectMimeType(const std::string& path)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1798 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1799 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1800
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 if (mime == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 // Should never happen, just for safety
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1804 return "application/octet-stream";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1807 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808 return mime;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1810 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1811 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1812
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814 #if HAS_ORTHANC_PLUGIN_PEERS == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1815 size_t OrthancPeers::GetPeerIndex(const std::string& name) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1816 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1817 size_t index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1818 if (LookupName(index, name))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1819 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1820 return index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1821 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1822 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1823 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
1824 ORTHANC_PLUGINS_LOG_ERROR("Inexistent peer: " + name);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1825 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1826 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1827 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1828
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1829
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1830 OrthancPeers::OrthancPeers() :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1831 peers_(NULL),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1832 timeout_(0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1833 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1834 peers_ = OrthancPluginGetPeers(GetGlobalContext());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1835
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1836 if (peers_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1837 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1838 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1839 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1843 for (uint32_t i = 0; i < count; i++)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1844 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1845 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846 if (name == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1848 OrthancPluginFreePeers(GetGlobalContext(), peers_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1849 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1850 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1851
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1852 index_[name] = i;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1853 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1854 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1855
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1856
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1857 OrthancPeers::~OrthancPeers()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1858 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1859 if (peers_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1860 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1861 OrthancPluginFreePeers(GetGlobalContext(), peers_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1862 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1863 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1864
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1865
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1866 bool OrthancPeers::LookupName(size_t& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1867 const std::string& name) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1868 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1869 Index::const_iterator found = index_.find(name);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1870
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1871 if (found == index_.end())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1872 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1873 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1874 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1875 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1876 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1877 target = found->second;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1878 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1879 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1880 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1881
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1882
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1883 std::string OrthancPeers::GetPeerName(size_t index) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1884 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1885 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1886 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1887 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1888 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1889 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1890 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1891 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1892 if (s == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1893 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1894 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1895 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1896 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1897 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1898 return s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1899 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1900 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1901 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1902
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1903
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1904 std::string OrthancPeers::GetPeerUrl(size_t index) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1905 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1906 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1907 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1908 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1909 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1910 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1911 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1912 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1913 if (s == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1914 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1915 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1916 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1917 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1918 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1919 return s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1920 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1921 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1922 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1923
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1924
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1925 std::string OrthancPeers::GetPeerUrl(const std::string& name) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1926 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1927 return GetPeerUrl(GetPeerIndex(name));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1928 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1929
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1930
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1931 bool OrthancPeers::LookupUserProperty(std::string& value,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1932 size_t index,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1933 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1934 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1935 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1936 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1937 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1938 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1939 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1940 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1941 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1942 if (s == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1943 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1944 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1945 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1946 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1947 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1948 value.assign(s);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1949 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1950 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1951 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1952 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1953
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1954
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1955 bool OrthancPeers::LookupUserProperty(std::string& value,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1956 const std::string& peer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1957 const std::string& key) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1958 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1959 return LookupUserProperty(value, GetPeerIndex(peer), key);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1960 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1961
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1962
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1963 bool OrthancPeers::DoGet(MemoryBuffer& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1964 size_t index,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1965 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1966 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1967 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1968 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1969 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1970 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1971 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1972
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1973 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1974 uint16_t status;
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1975 PluginHttpHeaders pluginHeaders(headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1976
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1977 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1978 (GetGlobalContext(), *answer, NULL, &status, peers_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1979 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(),
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1980 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1981
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1982 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1983 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1984 target.Swap(answer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1985 return (status == 200);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1986 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1987 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1988 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1989 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1990 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1991 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1992
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1993
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1994 bool OrthancPeers::DoGet(MemoryBuffer& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1995 const std::string& name,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1996 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
1997 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1998 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1999 size_t index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2000 return (LookupName(index, name) &&
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2001 DoGet(target, index, uri, headers));
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2002 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2003
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2004
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005 bool OrthancPeers::DoGet(Json::Value& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2006 size_t index,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2007 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2008 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2009 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2010 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2011
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2012 if (DoGet(buffer, index, uri, headers))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2013 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2014 buffer.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2015 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2016 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2017 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2018 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2019 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2020 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2021 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2022
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2023
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2024 bool OrthancPeers::DoGet(Json::Value& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2025 const std::string& name,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2026 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2027 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2028 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2029 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2030
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2031 if (DoGet(buffer, name, uri, headers))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2032 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2033 buffer.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2034 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2035 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2036 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2037 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2038 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2039 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2040 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2041
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2042
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2043 bool OrthancPeers::DoPost(MemoryBuffer& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2044 const std::string& name,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2045 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2046 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2047 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2048 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2049 size_t index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2050 return (LookupName(index, name) &&
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2051 DoPost(target, index, uri, body, headers));
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2052 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2053
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2054
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2055 bool OrthancPeers::DoPost(Json::Value& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2056 size_t index,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2057 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2058 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2059 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2060 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2061 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2062
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2063 if (DoPost(buffer, index, uri, body, headers))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2064 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2065 buffer.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2066 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2067 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2068 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2069 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2070 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2071 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2072 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2073
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2074
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2075 bool OrthancPeers::DoPost(Json::Value& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2076 const std::string& name,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2077 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2078 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2079 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2080 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2081 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2082
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2083 if (DoPost(buffer, name, uri, body, headers))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2084 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2085 buffer.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2086 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2087 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2088 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2089 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2090 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2091 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2092 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2093
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2094
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2095 bool OrthancPeers::DoPost(MemoryBuffer& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2096 size_t index,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2097 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2098 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2099 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2100 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2101 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2102 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2103 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2104 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2105
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2106 if (body.size() > 0xffffffffu)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2107 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2108 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2109 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2110 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2111
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2112 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2113 uint16_t status;
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2114 PluginHttpHeaders pluginHeaders(headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2115
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2116 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2117 (GetGlobalContext(), *answer, NULL, &status, peers_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2118 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(),
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2119 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2120
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2121 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2122 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2123 target.Swap(answer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2124 return (status == 200);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2125 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2127 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2128 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2129 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2130 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2131
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2132
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2133 bool OrthancPeers::DoPut(size_t index,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2134 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2135 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2136 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2137 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2138 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2139 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2140 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2141 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2142
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2143 if (body.size() > 0xffffffffu)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2144 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2145 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2146 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2147 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2148
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2149 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2150 uint16_t status;
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2151 PluginHttpHeaders pluginHeaders(headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2152
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2153 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2154 (GetGlobalContext(), *answer, NULL, &status, peers_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2155 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2156 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2157
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2158 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2159 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2160 return (status == 200);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2161 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2162 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2163 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2164 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2165 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2166 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2167
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2168
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2169 bool OrthancPeers::DoPut(const std::string& name,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2170 const std::string& uri,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2171 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2172 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2173 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2174 size_t index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2175 return (LookupName(index, name) &&
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2176 DoPut(index, uri, body, headers));
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2177 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2178
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2179
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2180 bool OrthancPeers::DoDelete(size_t index,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2181 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2182 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2183 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2184 if (index >= index_.size())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2185 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2186 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2187 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2188
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2189 OrthancPlugins::MemoryBuffer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2190 uint16_t status;
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2191 PluginHttpHeaders pluginHeaders(headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2192
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2193 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2194 (GetGlobalContext(), *answer, NULL, &status, peers_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2195 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(),
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2196 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2197
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2198 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2199 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2200 return (status == 200);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2201 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2202 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2203 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2204 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2205 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2206 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2207
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2208
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2209 bool OrthancPeers::DoDelete(const std::string& name,
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2210 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2211 const std::map<std::string, std::string>& headers) const
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2212 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2213 size_t index;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2214 return (LookupName(index, name) &&
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
2215 DoDelete(index, uri, headers));
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2216 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2217 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2218
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2219
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2220
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2221
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2222
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2223 /******************************************************************
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2224 ** JOBS
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2225 ******************************************************************/
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2226
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2227 #if HAS_ORTHANC_PLUGIN_JOB == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2228 void OrthancJob::CallbackFinalize(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2229 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2230 if (job != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2231 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2232 delete reinterpret_cast<OrthancJob*>(job);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2233 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2234 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2235
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2236
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2237 float OrthancJob::CallbackGetProgress(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2238 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2239 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2240
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2241 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2242 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2243 return reinterpret_cast<OrthancJob*>(job)->progress_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2244 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2245 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2246 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2247 return 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2248 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2249 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2250
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2251
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2252 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2253 static OrthancPluginErrorCode CopyStringToMemoryBuffer(OrthancPluginMemoryBuffer* target,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2254 const std::string& source)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2255 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2256 if (OrthancPluginCreateMemoryBuffer(globalContext_, target, source.size()) != OrthancPluginErrorCode_Success)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2257 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2258 return OrthancPluginErrorCode_NotEnoughMemory;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2259 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2260 else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2261 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2262 if (!source.empty())
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2263 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2264 memcpy(target->data, source.c_str(), source.size());
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2265 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2266
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2267 return OrthancPluginErrorCode_Success;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2268 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2269 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2270 #endif
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2271
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2272
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2273 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2274 OrthancPluginErrorCode OrthancJob::CallbackGetContent(OrthancPluginMemoryBuffer* target,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2275 void* job)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2276 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2277 assert(job != NULL);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2278 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2279 return CopyStringToMemoryBuffer(target, that.content_);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2280 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2281 #else
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2282 const char* OrthancJob::CallbackGetContent(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2283 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2284 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2285
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2286 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2287 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2288 return reinterpret_cast<OrthancJob*>(job)->content_.c_str();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2289 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2290 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2291 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2292 return 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2293 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2294 }
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2295 #endif
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2296
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2297
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2298 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2299 int32_t OrthancJob::CallbackGetSerialized(OrthancPluginMemoryBuffer* target,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2300 void* job)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2301 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2302 assert(job != NULL);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2303 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2304
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2305 if (that.hasSerialized_)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2306 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2307 if (CopyStringToMemoryBuffer(target, that.serialized_) == OrthancPluginErrorCode_Success)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2308 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2309 return 1;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2310 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2311 else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2312 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2313 return -1;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2314 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2315 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2316 else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2317 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2318 return 0;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2319 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2320 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2321 #else
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2322 const char* OrthancJob::CallbackGetSerialized(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2323 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2324 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2325
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2326 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2327 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2328 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2329
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2330 if (tmp.hasSerialized_)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2331 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2332 return tmp.serialized_.c_str();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2333 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2334 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2335 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2336 return NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2337 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2338 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2339 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2340 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2341 return 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2342 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2343 }
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2344 #endif
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2345
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2346
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2347 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2348 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2349 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2350
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2351 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2352 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2353 return reinterpret_cast<OrthancJob*>(job)->Step();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2354 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2355 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2356 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2357 return OrthancPluginJobStepStatus_Failure;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2358 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2359 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2360 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2361 return OrthancPluginJobStepStatus_Failure;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2362 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2363 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2364
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2365
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2366 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2367 OrthancPluginJobStopReason reason)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2368 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2369 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2370
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2371 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2372 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2373 reinterpret_cast<OrthancJob*>(job)->Stop(reason);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2374 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2375 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2376 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2377 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2378 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2379 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2380 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2381 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2382 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2383 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2384 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2385
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2386
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2387 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2388 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2389 assert(job != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2390
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2391 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2392 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2393 reinterpret_cast<OrthancJob*>(job)->Reset();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2394 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2395 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2396 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2397 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2398 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2399 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2400 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2401 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2402 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2403 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2404 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2405
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2406
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2407 void OrthancJob::ClearContent()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2408 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2409 Json::Value empty = Json::objectValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2410 UpdateContent(empty);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2411 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2412
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2413
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2414 void OrthancJob::UpdateContent(const Json::Value& content)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2415 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2416 if (content.type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2417 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2418 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2419 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2420 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2421 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
2422 WriteFastJson(content_, content);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2423 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2424 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2425
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2426
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2427 void OrthancJob::ClearSerialized()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2428 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2429 hasSerialized_ = false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2430 serialized_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2431 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2432
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2433
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2434 void OrthancJob::UpdateSerialized(const Json::Value& serialized)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2435 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2436 if (serialized.type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2437 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2438 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2439 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2440 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2441 {
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
2442 WriteFastJson(serialized_, serialized);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2443 hasSerialized_ = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2444 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2445 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2446
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2447
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2448 void OrthancJob::UpdateProgress(float progress)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2449 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2450 if (progress < 0 ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2451 progress > 1)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2452 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2453 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2454 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2455
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2456 progress_ = progress;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2457 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2458
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2459
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2460 OrthancJob::OrthancJob(const std::string& jobType) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2461 jobType_(jobType),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2462 progress_(0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2463 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2464 ClearContent();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2465 ClearSerialized();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2466 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2467
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2468
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2469 OrthancPluginJob* OrthancJob::Create(OrthancJob* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2470 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2471 if (job == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2472 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2473 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2474 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2475
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2476 OrthancPluginJob* orthanc =
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2477 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2478 OrthancPluginCreateJob2
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2479 #else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2480 OrthancPluginCreateJob
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2481 #endif
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2482 (GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(),
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2483 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
2484 CallbackStep, CallbackStop, CallbackReset);
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2485
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2486 if (orthanc == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2487 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2488 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2489 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2490 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2491 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2492 return orthanc;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2493 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2494 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2495
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2496
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2497 std::string OrthancJob::Submit(OrthancJob* job,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2498 int priority)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2499 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2500 if (job == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2501 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2502 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2503 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2504
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2505 OrthancPluginJob* orthanc = Create(job);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2506
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2507 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2508
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2509 if (id == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2510 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2511 ORTHANC_PLUGINS_LOG_ERROR("Plugin cannot submit job");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2512 OrthancPluginFreeJob(GetGlobalContext(), orthanc);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2513 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2514 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2515 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2516 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2517 std::string tmp(id);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2518 tmp.assign(id);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2519 OrthancPluginFreeString(GetGlobalContext(), id);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2520
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2521 return tmp;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2522 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2523 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2524
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2525
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2526 void OrthancJob::SubmitAndWait(Json::Value& result,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2527 OrthancJob* job /* takes ownership */,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2528 int priority)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2529 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2530 std::string id = Submit(job, priority);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2531
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2532 for (;;)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2533 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2534 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2535
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2536 Json::Value status;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2537 if (!RestApiGet(status, "/jobs/" + id, false) ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2538 !status.isMember("State") ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2539 status["State"].type() != Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2540 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2541 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2542 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2543
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2544 const std::string state = status["State"].asString();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2545 if (state == "Success")
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2546 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2547 if (status.isMember("Content"))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2548 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2549 result = status["Content"];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2550 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2551 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2552 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2553 result = Json::objectValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2554 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2555
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2556 return;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2557 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2558 else if (state == "Running")
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2559 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2560 continue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2561 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2562 else if (!status.isMember("ErrorCode") ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2563 status["ErrorCode"].type() != Json::intValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2564 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2565 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2566 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2567 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2568 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2569 if (!status.isMember("ErrorDescription") ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2570 status["ErrorDescription"].type() != Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2571 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2572 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2573 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2574 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2575 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2576 #if HAS_ORTHANC_EXCEPTION == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2577 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2578 status["ErrorDescription"].asString());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2579 #else
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2580 ORTHANC_PLUGINS_LOG_ERROR("Exception while executing the job: " + status["ErrorDescription"].asString());
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2581 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2582 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2583 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2584 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2585 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2586 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2587
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2588
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2589 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2590 const Json::Value& body,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2591 OrthancJob* job)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2592 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2593 static const char* KEY_SYNCHRONOUS = "Synchronous";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2594 static const char* KEY_ASYNCHRONOUS = "Asynchronous";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2595 static const char* KEY_PRIORITY = "Priority";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2596
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2597 boost::movelib::unique_ptr<OrthancJob> protection(job);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2598
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2599 if (body.type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2600 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2601 #if HAS_ORTHANC_EXCEPTION == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2602 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2603 "Expected a JSON object in the body");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2604 #else
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2605 ORTHANC_PLUGINS_LOG_ERROR("Expected a JSON object in the body");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2606 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2607 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2608 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2609
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2610 bool synchronous = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2611
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2612 if (body.isMember(KEY_SYNCHRONOUS))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2613 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2614 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2615 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2616 #if HAS_ORTHANC_EXCEPTION == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2617 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2618 "Option \"" + std::string(KEY_SYNCHRONOUS) +
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2619 "\" must be Boolean");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2620 #else
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2621 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2622 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2623 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2624 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2625 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2626 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2627 synchronous = body[KEY_SYNCHRONOUS].asBool();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2628 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2629 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2630
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2631 if (body.isMember(KEY_ASYNCHRONOUS))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2632 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2633 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2634 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2635 #if HAS_ORTHANC_EXCEPTION == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2636 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2637 "Option \"" + std::string(KEY_ASYNCHRONOUS) +
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2638 "\" must be Boolean");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2639 #else
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2640 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2641 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2642 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2643 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2644 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2645 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2646 synchronous = !body[KEY_ASYNCHRONOUS].asBool();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2647 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2648 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2649
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2650 int priority = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2651
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2652 if (body.isMember(KEY_PRIORITY))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2653 {
2108
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2101
diff changeset
2654 if (body[KEY_PRIORITY].type() != Json::intValue)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2655 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2656 #if HAS_ORTHANC_EXCEPTION == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2657 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2658 "Option \"" + std::string(KEY_PRIORITY) +
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2659 "\" must be an integer");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2660 #else
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
2661 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2662 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2663 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2664 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2665 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2666 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2667 priority = !body[KEY_PRIORITY].asInt();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2668 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2669 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2670
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2671 Json::Value result;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2672
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2673 if (synchronous)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2674 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2675 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2676 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2677 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2678 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2679 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2680
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2681 result = Json::objectValue;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2682 result["ID"] = id;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2683 result["Path"] = "/jobs/" + id;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2684 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2685
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2686 std::string s = result.toStyledString();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2687 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2688 s.size(), "application/json");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2689 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2690
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2691 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2692
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2693
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2694
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2695
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2696 /******************************************************************
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2697 ** METRICS
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2698 ******************************************************************/
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2699
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2700 #if HAS_ORTHANC_PLUGIN_METRICS == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2701 MetricsTimer::MetricsTimer(const char* name) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2702 name_(name)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2703 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2704 start_ = boost::posix_time::microsec_clock::universal_time();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2705 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2706
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2707 MetricsTimer::~MetricsTimer()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2708 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2709 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2710 const boost::posix_time::time_duration diff = stop - start_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2711 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2712 OrthancPluginMetricsType_Timer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2713 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2714 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2715
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2716
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2717
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2718
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2719 /******************************************************************
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2720 ** HTTP CLIENT
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2721 ******************************************************************/
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2722
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2723 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2724 class HttpClient::RequestBodyWrapper : public boost::noncopyable
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2725 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2726 private:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2727 static RequestBodyWrapper& GetObject(void* body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2728 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2729 assert(body != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2730 return *reinterpret_cast<RequestBodyWrapper*>(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2731 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2732
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2733 IRequestBody& body_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2734 bool done_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2735 std::string chunk_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2736
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2737 public:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2738 RequestBodyWrapper(IRequestBody& body) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2739 body_(body),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2740 done_(false)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2741 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2742 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2743
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2744 static uint8_t IsDone(void* body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2745 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2746 return GetObject(body).done_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2747 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2748
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2749 static const void* GetChunkData(void* body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2750 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2751 return GetObject(body).chunk_.c_str();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2752 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2753
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2754 static uint32_t GetChunkSize(void* body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2755 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2756 return static_cast<uint32_t>(GetObject(body).chunk_.size());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2757 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2758
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2759 static OrthancPluginErrorCode Next(void* body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2760 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2761 RequestBodyWrapper& that = GetObject(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2762
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2763 if (that.done_)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2764 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2765 return OrthancPluginErrorCode_BadSequenceOfCalls;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2766 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2767 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2768 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2769 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2770 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2771 that.done_ = !that.body_.ReadNextChunk(that.chunk_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2772 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2773 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2774 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2775 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2776 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2777 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2778 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2779 {
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
2780 return OrthancPluginErrorCode_Plugin;
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2781 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2782 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2783 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2784 };
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2785
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2786
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2787 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2788 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2789 const char* key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2790 const char* value)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2791 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2792 assert(answer != NULL && key != NULL && value != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2793
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2794 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2795 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2796 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2797 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2798 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2799 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2800 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2801 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2802 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2803 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2804 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2805 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2806 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2807 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2808 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2809
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2810
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2811 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2812 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2813 const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2814 uint32_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2815 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2816 assert(answer != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2817
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2818 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2819 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2820 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2821 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2822 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2823 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2824 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2825 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2826 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2827 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2828 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2829 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2830 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2831 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2832 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2833
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2834
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2835 HttpClient::HttpClient() :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2836 httpStatus_(0),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2837 method_(OrthancPluginHttpMethod_Get),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2838 timeout_(0),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2839 pkcs11_(false),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2840 chunkedBody_(NULL),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2841 allowChunkedTransfers_(true)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2842 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2843 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2844
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2845
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2846 void HttpClient::AddHeaders(const HttpHeaders& headers)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2847 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2848 for (HttpHeaders::const_iterator it = headers.begin();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2849 it != headers.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2850 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2851 headers_[it->first] = it->second;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2852 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2853 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2854
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2855
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2856 void HttpClient::SetCredentials(const std::string& username,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2857 const std::string& password)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2858 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2859 username_ = username;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2860 password_ = password;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2861 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2862
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2863
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2864 void HttpClient::ClearCredentials()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2865 {
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2866 username_.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
2867 password_.clear();
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2868 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2869
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2870
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2871 void HttpClient::SetCertificate(const std::string& certificateFile,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2872 const std::string& keyFile,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2873 const std::string& keyPassword)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2874 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2875 certificateFile_ = certificateFile;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2876 certificateKeyFile_ = keyFile;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2877 certificateKeyPassword_ = keyPassword;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2878 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2879
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2880
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2881 void HttpClient::ClearCertificate()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2882 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2883 certificateFile_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2884 certificateKeyFile_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2885 certificateKeyPassword_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2886 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2887
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2888
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2889 void HttpClient::ClearBody()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2890 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2891 fullBody_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2892 chunkedBody_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2893 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2894
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2895
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2896 void HttpClient::SwapBody(std::string& body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2897 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2898 fullBody_.swap(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2899 chunkedBody_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2900 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2901
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2902
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2903 void HttpClient::SetBody(const std::string& body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2904 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2905 fullBody_ = body;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2906 chunkedBody_ = NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2907 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2908
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2909
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2910 void HttpClient::SetBody(IRequestBody& body)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2911 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2912 fullBody_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2913 chunkedBody_ = &body;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2914 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2915
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2916
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2917 namespace
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2918 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2919 class HeadersWrapper : public boost::noncopyable
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2920 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2921 private:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2922 std::vector<const char*> headersKeys_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2923 std::vector<const char*> headersValues_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2924
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2925 public:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2926 HeadersWrapper(const HttpClient::HttpHeaders& headers)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2927 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2928 headersKeys_.reserve(headers.size());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2929 headersValues_.reserve(headers.size());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2930
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2931 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2932 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2933 headersKeys_.push_back(it->first.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2934 headersValues_.push_back(it->second.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2935 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2936 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2937
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2938 void AddStaticString(const char* key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2939 const char* value)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2940 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2941 headersKeys_.push_back(key);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2942 headersValues_.push_back(value);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2943 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2944
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2945 uint32_t GetCount() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2946 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2947 return headersKeys_.size();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2948 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2949
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2950 const char* const* GetKeys() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2951 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2952 return headersKeys_.empty() ? NULL : &headersKeys_[0];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2953 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2954
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2955 const char* const* GetValues() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2956 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2957 return headersValues_.empty() ? NULL : &headersValues_[0];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2958 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2959 };
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2960
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2961
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2962 class MemoryRequestBody : public HttpClient::IRequestBody
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2963 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2964 private:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2965 std::string body_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2966 bool done_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2967
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2968 public:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2969 MemoryRequestBody(const std::string& body) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2970 body_(body),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2971 done_(false)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2972 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2973 if (body_.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2974 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2975 done_ = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2976 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2977 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2978
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2979 virtual bool ReadNextChunk(std::string& chunk)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2980 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2981 if (done_)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2982 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2983 return false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2984 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2985 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2986 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2987 chunk.swap(body_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2988 done_ = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2989 return true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2990 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2991 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2992 };
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2993
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2994
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2995 // This class mimics Orthanc::ChunkedBuffer
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2996 class ChunkedBuffer : public boost::noncopyable
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2997 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2998 private:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2999 typedef std::list<std::string*> Content;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3000
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3001 Content content_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3002 size_t size_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3003
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3004 public:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3005 ChunkedBuffer() :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3006 size_(0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3007 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3008 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3009
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3010 ~ChunkedBuffer()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3011 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3012 Clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3013 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3014
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3015 void Clear()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3016 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3017 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3018 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3019 assert(*it != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3020 delete *it;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3021 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3022
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3023 size_ = 0;
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3024 content_.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3025 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3026
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3027 /**
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3028 * Since Orthanc 1.9.3, this function also clears the content of
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3029 * the ChunkedBuffer in order to mimic the behavior of the
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3030 * original class "Orthanc::ChunkedBuffer". This prevents the
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3031 * forgetting of calling "Clear()" in order to reduce memory
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3032 * consumption.
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3033 **/
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3034 void Flatten(std::string& target)
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3035 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3036 target.resize(size_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3037
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3038 size_t pos = 0;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3039
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3040 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3041 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3042 assert(*it != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3043 size_t s = (*it)->size();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3044
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3045 if (s != 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3046 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3047 memcpy(&target[pos], (*it)->c_str(), s);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3048 pos += s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3049 }
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3050
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3051 delete *it;
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3052 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3053
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3054 assert(pos == target.size());
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3055
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3056 size_ = 0;
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3057 content_.clear();
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3058 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3059
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3060 void AddChunk(const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3061 size_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3062 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3063 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3064 size_ += size;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3065 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3066
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3067 void AddChunk(const std::string& chunk)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3068 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3069 content_.push_back(new std::string(chunk));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3070 size_ += chunk.size();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3071 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3072 };
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3073
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3074
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3075 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3076 class MemoryAnswer : public HttpClient::IAnswer
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3077 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3078 private:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3079 HttpClient::HttpHeaders headers_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3080 ChunkedBuffer body_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3081
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3082 public:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3083 const HttpClient::HttpHeaders& GetHeaders() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3084 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3085 return headers_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3086 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3087
1771
f302bbddf94d sync, trying to fix DicomVolumeImageReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
3088 ChunkedBuffer& GetBody()
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3089 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3090 return body_;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3091 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3092
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3093 virtual void AddHeader(const std::string& key,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3094 const std::string& value)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3095 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3096 headers_[key] = value;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3097 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3098
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3099 virtual void AddChunk(const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3100 size_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3101 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3102 body_.AddChunk(data, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3103 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3104 };
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3105 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3106 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3107
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3108
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3109 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3110 void HttpClient::ExecuteWithStream(uint16_t& httpStatus,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3111 IAnswer& answer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3112 IRequestBody& body) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3113 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3114 HeadersWrapper h(headers_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3115
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3116 if (method_ == OrthancPluginHttpMethod_Post ||
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3117 method_ == OrthancPluginHttpMethod_Put)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3118 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3119 // Automatically set the "Transfer-Encoding" header if absent
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3120 bool found = false;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3121
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3122 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3123 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3124 if (boost::iequals(it->first, "Transfer-Encoding"))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3125 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3126 found = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3127 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3128 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3129 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3130
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3131 if (!found)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3132 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3133 h.AddStaticString("Transfer-Encoding", "chunked");
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3134 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3135 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3136
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3137 RequestBodyWrapper request(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3138
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3139 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3140 GetGlobalContext(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3141 &answer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3142 AnswerAddChunkCallback,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3143 AnswerAddHeaderCallback,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3144 &httpStatus,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3145 method_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3146 url_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3147 h.GetCount(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3148 h.GetKeys(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3149 h.GetValues(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3150 &request,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3151 RequestBodyWrapper::IsDone,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3152 RequestBodyWrapper::GetChunkData,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3153 RequestBodyWrapper::GetChunkSize,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3154 RequestBodyWrapper::Next,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3155 username_.empty() ? NULL : username_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3156 password_.empty() ? NULL : password_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3157 timeout_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3158 certificateFile_.empty() ? NULL : certificateFile_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3159 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3160 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3161 pkcs11_ ? 1 : 0);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3162
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3163 if (error != OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3164 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3165 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3166 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3167 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3168 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3169
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3170
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3171 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3172 HttpHeaders& answerHeaders,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3173 std::string& answerBody,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3174 const std::string& body) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3175 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3176 HeadersWrapper headers(headers_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3177
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3178 MemoryBuffer answerBodyBuffer, answerHeadersBuffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3179
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
3180 if (body.size() > 0xffffffffu)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
3181 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
3182 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
1868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
3183 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
3184 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1771
diff changeset
3185
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3186 OrthancPluginErrorCode error = OrthancPluginHttpClient(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3187 GetGlobalContext(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3188 *answerBodyBuffer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3189 *answerHeadersBuffer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3190 &httpStatus,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3191 method_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3192 url_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3193 headers.GetCount(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3194 headers.GetKeys(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3195 headers.GetValues(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3196 body.empty() ? NULL : body.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3197 body.size(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3198 username_.empty() ? NULL : username_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3199 password_.empty() ? NULL : password_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3200 timeout_,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3201 certificateFile_.empty() ? NULL : certificateFile_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3202 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3203 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3204 pkcs11_ ? 1 : 0);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3205
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3206 if (error != OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3207 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3208 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3209 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3210
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3211 Json::Value v;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3212 answerHeadersBuffer.ToJson(v);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3213
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3214 if (v.type() != Json::objectValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3215 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3216 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3217 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3218
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3219 Json::Value::Members members = v.getMemberNames();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3220 answerHeaders.clear();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3221
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3222 for (size_t i = 0; i < members.size(); i++)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3223 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3224 const Json::Value& h = v[members[i]];
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3225 if (h.type() != Json::stringValue)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3226 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3227 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3228 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3229 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3230 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3231 answerHeaders[members[i]] = h.asString();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3232 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3233 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3234
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3235 answerBodyBuffer.ToString(answerBody);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3236 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3237
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3238
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3239 void HttpClient::Execute(IAnswer& answer)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3240 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3241 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3242 if (allowChunkedTransfers_)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3243 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3244 if (chunkedBody_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3245 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3246 ExecuteWithStream(httpStatus_, answer, *chunkedBody_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3247 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3248 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3249 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3250 MemoryRequestBody wrapper(fullBody_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3251 ExecuteWithStream(httpStatus_, answer, wrapper);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3252 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3253
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3254 return;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3255 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3256 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3257
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3258 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3259 // transfers are disabled. This results in higher memory usage
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3260 // (all chunks from the answer body are sent at once)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3261
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3262 HttpHeaders answerHeaders;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3263 std::string answerBody;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3264 Execute(answerHeaders, answerBody);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3265
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3266 for (HttpHeaders::const_iterator it = answerHeaders.begin();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3267 it != answerHeaders.end(); ++it)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3268 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3269 answer.AddHeader(it->first, it->second);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3270 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3271
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3272 if (!answerBody.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3273 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3274 answer.AddChunk(answerBody.c_str(), answerBody.size());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3275 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3276 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3277
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3278
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3279 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3280 std::string& answerBody /* out */)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3281 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3282 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3283 if (allowChunkedTransfers_)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3284 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3285 MemoryAnswer answer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3286 Execute(answer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3287 answerHeaders = answer.GetHeaders();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3288 answer.GetBody().Flatten(answerBody);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3289 return;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3290 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3291 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3292
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3293 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3294 // transfers are disabled. This results in higher memory usage
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3295 // (all chunks from the request body are sent at once)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3296
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3297 if (chunkedBody_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3298 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3299 ChunkedBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3300
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3301 std::string chunk;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3302 while (chunkedBody_->ReadNextChunk(chunk))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3303 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3304 buffer.AddChunk(chunk);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3305 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3306
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3307 std::string body;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3308 buffer.Flatten(body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3309
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3310 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3311 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3312 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3313 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3314 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3315 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3316 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3317
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3318
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3319 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3320 Json::Value& answerBody /* out */)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3321 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3322 std::string body;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3323 Execute(answerHeaders, body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3324
1736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1638
diff changeset
3325 if (!ReadJson(answerBody, body))
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3326 {
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2119
diff changeset
3327 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert HTTP answer body to JSON");
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3328 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3329 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3330 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3331
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3332
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3333 void HttpClient::Execute()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3334 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3335 HttpHeaders answerHeaders;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3336 std::string body;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3337 Execute(answerHeaders, body);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3338 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3339
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3340 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3341
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3342
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3343
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3344
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3345
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3346 /******************************************************************
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3347 ** CHUNKED HTTP SERVER
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3348 ******************************************************************/
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3349
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3350 namespace Internals
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3351 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3352 void NullRestCallback(OrthancPluginRestOutput* output,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3353 const char* url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3354 const OrthancPluginHttpRequest* request)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3355 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3356 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3357
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3358 IChunkedRequestReader *NullChunkedRestCallback(const char* url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3359 const OrthancPluginHttpRequest* request)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3360 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3361 return NULL;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3362 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3363
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3364
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3365 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3366
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3367 OrthancPluginErrorCode ChunkedRequestReaderAddChunk(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3368 OrthancPluginServerChunkedRequestReader* reader,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3369 const void* data,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3370 uint32_t size)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3371 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3372 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3373 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3374 if (reader == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3375 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3376 return OrthancPluginErrorCode_InternalError;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3377 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3378
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3379 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3380 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3381 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3382 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3383 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3384 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3385 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3386 catch (boost::bad_lexical_cast&)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3387 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3388 return OrthancPluginErrorCode_BadFileFormat;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3389 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3390 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3391 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3392 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3393 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3394 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3395
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3396
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3397 OrthancPluginErrorCode ChunkedRequestReaderExecute(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3398 OrthancPluginServerChunkedRequestReader* reader,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3399 OrthancPluginRestOutput* output)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3400 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3401 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3402 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3403 if (reader == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3404 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3405 return OrthancPluginErrorCode_InternalError;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3406 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3407
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3408 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3409 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3410 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3411 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3412 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3413 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3414 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3415 catch (boost::bad_lexical_cast&)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3416 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3417 return OrthancPluginErrorCode_BadFileFormat;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3418 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3419 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3420 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3421 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3422 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3423 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3424
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3425
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3426 void ChunkedRequestReaderFinalize(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3427 OrthancPluginServerChunkedRequestReader* reader)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3428 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3429 if (reader != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3430 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3431 delete reinterpret_cast<IChunkedRequestReader*>(reader);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3432 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3433 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3434
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3435 #else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3436
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3437 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3438 const char* url,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3439 const OrthancPluginHttpRequest* request,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3440 RestCallback GetHandler,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3441 ChunkedRestCallback PostHandler,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3442 RestCallback DeleteHandler,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3443 ChunkedRestCallback PutHandler)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3444 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3445 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3446 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3447 std::string allowed;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3448
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3449 if (GetHandler != Internals::NullRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3450 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3451 allowed += "GET";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3452 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3453
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3454 if (PostHandler != Internals::NullChunkedRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3455 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3456 if (!allowed.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3457 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3458 allowed += ",";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3459 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3460
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3461 allowed += "POST";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3462 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3463
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3464 if (DeleteHandler != Internals::NullRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3465 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3466 if (!allowed.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3467 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3468 allowed += ",";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3469 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3470
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3471 allowed += "DELETE";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3472 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3473
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3474 if (PutHandler != Internals::NullChunkedRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3475 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3476 if (!allowed.empty())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3477 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3478 allowed += ",";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3479 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3480
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3481 allowed += "PUT";
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3482 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3483
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3484 switch (request->method)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3485 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3486 case OrthancPluginHttpMethod_Get:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3487 if (GetHandler == Internals::NullRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3488 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3489 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3490 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3491 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3492 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3493 GetHandler(output, url, request);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3494 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3495
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3496 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3497
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3498 case OrthancPluginHttpMethod_Post:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3499 if (PostHandler == Internals::NullChunkedRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3500 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3501 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3502 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3503 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3504 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3505 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PostHandler(url, request));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3506 if (reader.get() == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3507 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3508 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3509 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3510 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3511 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3512 reader->AddChunk(request->body, request->bodySize);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3513 reader->Execute(output);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3514 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3515 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3516
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3517 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3518
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3519 case OrthancPluginHttpMethod_Delete:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3520 if (DeleteHandler == Internals::NullRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3521 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3522 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3523 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3524 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3525 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3526 DeleteHandler(output, url, request);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3527 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3528
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3529 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3530
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3531 case OrthancPluginHttpMethod_Put:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3532 if (PutHandler == Internals::NullChunkedRestCallback)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3533 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3534 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3535 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3536 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3537 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3538 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PutHandler(url, request));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3539 if (reader.get() == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3540 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3541 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3542 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3543 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3544 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3545 reader->AddChunk(request->body, request->bodySize);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3546 reader->Execute(output);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3547 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3548 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3549
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3550 break;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3551
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3552 default:
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3553 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3554 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3555
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3556 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3557 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3558 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3559 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3560 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3561 if (HasGlobalContext() &&
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3562 e.HasDetails())
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3563 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3564 // The "false" instructs Orthanc not to log the detailed
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3565 // error message. This is to avoid duplicating the details,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3566 // because "OrthancException" already does it on construction.
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3567 OrthancPluginSetHttpErrorDetails
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3568 (GetGlobalContext(), output, e.GetDetails(), false);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3569 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3570 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3571
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3572 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3573 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3574 catch (boost::bad_lexical_cast&)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3575 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3576 return OrthancPluginErrorCode_BadFileFormat;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3577 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3578 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3579 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3580 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3581 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3582 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3583 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3584 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3585
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3586
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3587 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3588 OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3589 OrthancPluginStorageCommitmentFailureReason* target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3590 void* rawHandler,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3591 const char* sopClassUid,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3592 const char* sopInstanceUid)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3593 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3594 assert(target != NULL &&
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3595 rawHandler != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3596
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3597 try
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3598 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3599 IStorageCommitmentScpHandler& handler = *reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3600 *target = handler.Lookup(sopClassUid, sopInstanceUid);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3601 return OrthancPluginErrorCode_Success;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3602 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3603 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3604 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3605 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3606 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3607 catch (...)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3608 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3609 return OrthancPluginErrorCode_Plugin;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3610 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3611 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3612 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3613
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3614
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3615 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3616 void IStorageCommitmentScpHandler::Destructor(void* rawHandler)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3617 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3618 assert(rawHandler != NULL);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3619 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3620 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3621 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3622
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3623
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3624 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3625 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3626 toFree_(false),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3627 instance_(instance)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3628 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3629 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3630 #else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3631 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3632 toFree_(false),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3633 instance_(instance)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3634 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3635 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3636 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3637
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3638
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3639 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3640 DicomInstance::DicomInstance(const void* buffer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3641 size_t size) :
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3642 toFree_(true),
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3643 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size))
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3644 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3645 if (instance_ == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3646 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3647 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3648 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3649 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3650 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3651
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3652
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3653 DicomInstance::~DicomInstance()
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3654 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3655 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3656 if (toFree_ &&
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3657 instance_ != NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3658 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3659 OrthancPluginFreeDicomInstance(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3660 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3661 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3662 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3663 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3664
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3665
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3666 std::string DicomInstance::GetRemoteAet() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3667 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3668 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3669 if (s == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3670 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3671 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3672 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3673 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3674 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3675 return std::string(s);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3676 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3677 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3678
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3679
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3680 void DicomInstance::GetJson(Json::Value& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3681 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3682 OrthancString s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3683 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3684 s.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3685 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3686
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3687
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3688 void DicomInstance::GetSimplifiedJson(Json::Value& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3689 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3690 OrthancString s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3691 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3692 s.ToJson(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3693 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3694
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3695
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3696 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3697 std::string DicomInstance::GetTransferSyntaxUid() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3698 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3699 OrthancString s;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3700 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3701
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3702 std::string result;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3703 s.ToString(result);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3704 return result;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3705 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3706 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3707
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3708
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3709 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3710 bool DicomInstance::HasPixelData() const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3711 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3712 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3713 if (result < 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3714 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3715 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3716 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3717 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3718 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3719 return (result != 0);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3720 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3721 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3722 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3723
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3724
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3725 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3726 void DicomInstance::GetRawFrame(std::string& target,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3727 unsigned int frameIndex) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3728 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3729 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3730 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3731 GetGlobalContext(), *buffer, instance_, frameIndex);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3732
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3733 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3734 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3735 buffer.ToString(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3736 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3737 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3738 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3739 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3740 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3741 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3742 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3743
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3744
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3745 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3746 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3747 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3748 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3749 GetGlobalContext(), instance_, frameIndex);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3750
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3751 if (image == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3752 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3753 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3754 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3755 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3756 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3757 return new OrthancImage(image);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3758 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3759 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3760 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3761
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3762
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3763 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3764 void DicomInstance::Serialize(std::string& target) const
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3765 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3766 MemoryBuffer buffer;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3767 OrthancPluginErrorCode code = OrthancPluginSerializeDicomInstance(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3768 GetGlobalContext(), *buffer, instance_);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3769
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3770 if (code == OrthancPluginErrorCode_Success)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3771 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3772 buffer.ToString(target);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3773 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3774 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3775 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3776 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3777 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3778 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3779 #endif
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3780
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3781
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3782 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3783 DicomInstance* DicomInstance::Transcode(const void* buffer,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3784 size_t size,
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3785 const std::string& transferSyntax)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3786 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3787 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance(
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3788 GetGlobalContext(), buffer, size, transferSyntax.c_str());
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3789
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3790 if (instance == NULL)
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3791 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3792 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3793 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3794 else
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3795 {
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3796 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance));
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3797 result->toFree_ = true;
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3798 return result.release();
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3799 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3800 }
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3801 #endif
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3802
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3803
2077
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3804 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 1)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3805 DicomInstance* DicomInstance::Load(const std::string& instanceId,
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3806 OrthancPluginLoadDicomInstanceMode mode)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3807 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3808 OrthancPluginDicomInstance* instance = OrthancPluginLoadDicomInstance(
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3809 GetGlobalContext(), instanceId.c_str(), mode);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3810
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3811 if (instance == NULL)
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3812 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3813 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3814 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3815 else
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3816 {
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3817 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance));
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3818 result->toFree_ = true;
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3819 return result.release();
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3820 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3821 }
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3822 #endif
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3823
07964689cb0b upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1955
diff changeset
3824
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3825 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3826 static std::vector<std::string> WebDavConvertPath(uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3827 const char* const* pathItems)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3828 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3829 std::vector<std::string> result(pathSize);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3830
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3831 for (uint32_t i = 0; i < pathSize; i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3832 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3833 result[i] = pathItems[i];
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3834 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3835
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3836 return result;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3837 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3838 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3839
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3840
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3841 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3842 static OrthancPluginErrorCode WebDavIsExistingFolder(uint8_t* isExisting,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3843 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3844 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3845 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3846 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3847 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3848
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3849 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3850 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3851 *isExisting = (that.IsExistingFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3852 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3853 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3854 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3855 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3856 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3857 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3858 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3859 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3860 return OrthancPluginErrorCode_Plugin;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3861 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3862 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3863 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3864
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3865
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3866 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3867 static OrthancPluginErrorCode WebDavListFolder(uint8_t* isExisting,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3868 OrthancPluginWebDavCollection* collection,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3869 OrthancPluginWebDavAddFile addFile,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3870 OrthancPluginWebDavAddFolder addFolder,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3871 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3872 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3873 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3874 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3875 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3876
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3877 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3878 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3879 std::list<IWebDavCollection::FileInfo> files;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3880 std::list<IWebDavCollection::FolderInfo> subfolders;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3881
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3882 if (!that.ListFolder(files, subfolders, WebDavConvertPath(pathSize, pathItems)))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3883 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3884 *isExisting = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3885 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3886 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3887 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3888 *isExisting = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3890 for (std::list<IWebDavCollection::FileInfo>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3891 it = files.begin(); it != files.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3892 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3893 OrthancPluginErrorCode code = addFile(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3894 collection, it->GetName().c_str(), it->GetContentSize(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3895 it->GetMimeType().c_str(), it->GetDateTime().c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3896
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3897 if (code != OrthancPluginErrorCode_Success)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3898 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3899 return code;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3900 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3901 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3902
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3903 for (std::list<IWebDavCollection::FolderInfo>::const_iterator it =
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3904 subfolders.begin(); it != subfolders.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3905 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3906 OrthancPluginErrorCode code = addFolder(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3907 collection, it->GetName().c_str(), it->GetDateTime().c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3908
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3909 if (code != OrthancPluginErrorCode_Success)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3910 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3911 return code;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3912 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3913 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3914 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3915
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3916 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3917 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3918 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3919 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3920 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3921 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3922 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3923 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3924 return OrthancPluginErrorCode_Plugin;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3925 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3926 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3927 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3928
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3929
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3930 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3931 static OrthancPluginErrorCode WebDavRetrieveFile(OrthancPluginWebDavCollection* collection,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3932 OrthancPluginWebDavRetrieveFile retrieveFile,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3933 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3934 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3935 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3936 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3937 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3939 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3940 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3941 std::string content, mime, dateTime;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3942
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3943 if (that.GetFile(content, mime, dateTime, WebDavConvertPath(pathSize, pathItems)))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3944 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3945 return retrieveFile(collection, content.empty() ? NULL : content.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3946 content.size(), mime.c_str(), dateTime.c_str());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3947 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3948 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3949 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3950 // Inexisting file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3951 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3952 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3953 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3954 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3955 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3956 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3957 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3958 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3959 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3960 return OrthancPluginErrorCode_InternalError;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3961 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3962 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3963 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3964
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3965
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3966 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3967 static OrthancPluginErrorCode WebDavStoreFileCallback(uint8_t* isReadOnly, /* out */
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3968 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3969 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3970 const void* data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3971 uint64_t size,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3972 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3973 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3974 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3975
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3976 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3977 {
1936
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3978 if (static_cast<uint64_t>(static_cast<size_t>(size)) != size)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3979 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3980 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3981 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3982
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3983 *isReadOnly = (that.StoreFile(WebDavConvertPath(pathSize, pathItems), data,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1913
diff changeset
3984 static_cast<size_t>(size)) ? 1 : 0);
1913
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3985 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3986 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3987 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3988 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3989 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3990 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3991 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3992 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3993 return OrthancPluginErrorCode_InternalError;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3994 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3995 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3996 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3997
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3998
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
3999 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4000 static OrthancPluginErrorCode WebDavCreateFolderCallback(uint8_t* isReadOnly, /* out */
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4001 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4002 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4003 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4004 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4005 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4006
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4007 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4008 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4009 *isReadOnly = (that.CreateFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4010 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4011 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4012 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4013 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4014 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4015 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4016 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4017 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4018 return OrthancPluginErrorCode_InternalError;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4019 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4020 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4021 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4024 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4025 static OrthancPluginErrorCode WebDavDeleteItemCallback(uint8_t* isReadOnly, /* out */
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4026 uint32_t pathSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4027 const char* const* pathItems,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4028 void* payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4029 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4030 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4031
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4032 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4033 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4034 *isReadOnly = (that.DeleteItem(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4035 return OrthancPluginErrorCode_Success;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4036 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4037 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4038 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4039 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4040 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4041 catch (...)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4042 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4043 return OrthancPluginErrorCode_InternalError;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4044 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4045 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4046 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4047
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4048
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4049 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4050 void IWebDavCollection::Register(const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4051 IWebDavCollection& collection)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4052 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4053 OrthancPluginErrorCode code = OrthancPluginRegisterWebDavCollection(
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4054 GetGlobalContext(), uri.c_str(), WebDavIsExistingFolder, WebDavListFolder, WebDavRetrieveFile,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4055 WebDavStoreFileCallback, WebDavCreateFolderCallback, WebDavDeleteItemCallback, &collection);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4056
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4057 if (code != OrthancPluginErrorCode_Success)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4058 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4059 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4060 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4061 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1877
diff changeset
4062 #endif
1955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4063
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4064 void GetHttpHeaders(std::map<std::string, std::string>& result, const OrthancPluginHttpRequest* request)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4065 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4066 result.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4067
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4068 for (uint32_t i = 0; i < request->headersCount; ++i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4069 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4070 result[request->headersKeys[i]] = request->headersValues[i];
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4071 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
4072 }
2119
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4073
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4074 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4075 static void SetPluginProperty(const std::string& pluginIdentifier,
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4076 _OrthancPluginProperty property,
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4077 const std::string& value)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4078 {
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4079 _OrthancPluginSetPluginProperty params;
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4080 params.plugin = pluginIdentifier.c_str();
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4081 params.property = property;
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4082 params.value = value.c_str();
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4083
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4084 GetGlobalContext()->InvokeService(GetGlobalContext(), _OrthancPluginService_SetPluginProperty, &params);
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4085 }
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4086 #endif
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4087
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4088 void SetRootUri(const std::string& pluginIdentifier,
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4089 const std::string& uri)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4090 {
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4091 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4092 OrthancPluginSetRootUri2(GetGlobalContext(), pluginIdentifier.c_str(), uri.c_str());
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4093 #else
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4094 SetPluginProperty(pluginIdentifier, _OrthancPluginProperty_RootUri, uri);
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4095 #endif
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4096 }
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4097
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4098 void SetDescription(const std::string& pluginIdentifier,
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4099 const std::string& description)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4100 {
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4101 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4102 OrthancPluginSetDescription2(GetGlobalContext(), pluginIdentifier.c_str(), description.c_str());
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4103 #else
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4104 SetPluginProperty(pluginIdentifier, _OrthancPluginProperty_Description, description);
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4105 #endif
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4106 }
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4107
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4108 void ExtendOrthancExplorer(const std::string& pluginIdentifier,
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4109 const std::string& javascript)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4110 {
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4111 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4112 OrthancPluginExtendOrthancExplorer2(GetGlobalContext(), pluginIdentifier.c_str(), javascript.c_str());
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4113 #else
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4114 SetPluginProperty(pluginIdentifier, _OrthancPluginProperty_OrthancExplorer, javascript);
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4115 #endif
11bc8a304038 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
4116 }
1538
d1806b4e4839 moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4117 }