annotate OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 4914:4b10cbf3ccc8

typo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Feb 2022 22:14:31 +0100
parents 43e613a7756b
children 8785d8442f90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4846
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4846
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
4122
4bb7522a63e0 do not enforce openssl exception in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 *
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "OrthancPluginCppWrapper.h"
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
3749
edabdf07ee83 replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3669
diff changeset
25 #include <boost/algorithm/string/predicate.hpp>
edabdf07ee83 replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3669
diff changeset
26 #include <boost/move/unique_ptr.hpp>
3437
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
27 #include <boost/thread.hpp>
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
28
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
29
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <json/reader.h>
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
31 #include <json/version.h>
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
32 #include <json/writer.h>
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
34 #if !defined(JSONCPP_VERSION_MAJOR) || !defined(JSONCPP_VERSION_MINOR)
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
35 # error Cannot access the version of JsonCpp
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
36 #endif
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
37
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
38
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
39 /**
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
40 * We use deprecated "Json::Reader", "Json::StyledWriter" and
4396
d07a65100a95 fix comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4394
diff changeset
41 * "Json::FastWriter" if JsonCpp < 1.7.0. This choice is rather
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
42 * arbitrary, but if Json >= 1.9.0, gcc generates explicit deprecation
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
43 * warnings (clang was warning in earlier versions). For reference,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
44 * these classes seem to have been deprecated since JsonCpp 1.4.0 (on
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
45 * February 2015) by the following changeset:
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
46 * https://github.com/open-source-parsers/jsoncpp/commit/8df98f6112890d6272734975dd6d70cf8999bb22
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
47 **/
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
48 #if (JSONCPP_VERSION_MAJOR >= 2 || \
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
49 (JSONCPP_VERSION_MAJOR == 1 && JSONCPP_VERSION_MINOR >= 8))
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
50 # define JSONCPP_USE_DEPRECATED 0
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
51 #else
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
52 # define JSONCPP_USE_DEPRECATED 1
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
53 #endif
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
54
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
3916
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
56 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
57 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
58 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
59
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
60
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 namespace OrthancPlugins
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
63 static OrthancPluginContext* globalContext_ = NULL;
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
64
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
65
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
66 void SetGlobalContext(OrthancPluginContext* context)
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
67 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
68 if (context == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
69 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
70 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
71 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
72 else if (globalContext_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
73 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
74 globalContext_ = context;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
75 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
76 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
77 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
78 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
79 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
80 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
81
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
82
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
83 bool HasGlobalContext()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
84 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
85 return globalContext_ != NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
86 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
87
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
88
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
89 OrthancPluginContext* GetGlobalContext()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
90 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
91 if (globalContext_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
92 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
93 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
94 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
95 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
96 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
97 return globalContext_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
98 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
99 }
2958
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
100
bb7a66efbeb1 OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2851
diff changeset
101
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
102 void MemoryBuffer::Check(OrthancPluginErrorCode code)
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
103 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
104 if (code != OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
105 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
106 // Prevent using garbage information
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
107 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
108 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
110 }
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
111 }
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
112
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
113
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
114 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code)
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
115 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
116 if (code != OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
117 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
118 // Prevent using garbage information
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
119 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
120 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
121 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
122
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
123 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
124 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
125 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
126 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
127 else if (code == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
128 code == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
129 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
130 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
131 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
132 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
133 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
134 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
135 }
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
136 }
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
137
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
138
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
139 MemoryBuffer::MemoryBuffer()
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 buffer_.data = NULL;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 buffer_.size = 0;
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
145
3934
0b59e2706366 guard on SDK version in OrthancPlugins::MemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
146 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
147 MemoryBuffer::MemoryBuffer(const void* buffer,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
148 size_t size)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
149 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
150 uint32_t s = static_cast<uint32_t>(size);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
151 if (static_cast<size_t>(s) != size)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
152 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
153 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
154 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
155 else if (OrthancPluginCreateMemoryBuffer(GetGlobalContext(), &buffer_, s) !=
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
156 OrthancPluginErrorCode_Success)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
157 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
158 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
159 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
160 else
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
161 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
162 memcpy(buffer_.data, buffer, size);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
163 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
164 }
3934
0b59e2706366 guard on SDK version in OrthancPlugins::MemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
165 #endif
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
166
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3923
diff changeset
167
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
168 void MemoryBuffer::Clear()
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
169 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
170 if (buffer_.data != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
171 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
172 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
173 buffer_.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
174 buffer_.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
175 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
176 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
178
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
179 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
180 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
181 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
182
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
183 buffer_.data = other.data;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
184 buffer_.size = other.size;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
185
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
186 other.data = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
187 other.size = 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
188 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
189
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
190
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
191 void MemoryBuffer::Swap(MemoryBuffer& other)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
192 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
193 std::swap(buffer_.data, other.buffer_.data);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
194 std::swap(buffer_.size, other.buffer_.size);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
195 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
196
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
197
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
198 OrthancPluginMemoryBuffer MemoryBuffer::Release()
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
200 OrthancPluginMemoryBuffer result = buffer_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
201
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
202 buffer_.data = NULL;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
203 buffer_.size = 0;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
204
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
205 return result;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
206 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
207
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
208
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
209 void MemoryBuffer::ToString(std::string& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
210 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
211 if (buffer_.size == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
212 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
213 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
214 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
215 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
216 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
217 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
218 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
219 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
220
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
221
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
222 void MemoryBuffer::ToJson(Json::Value& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
223 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
224 if (buffer_.data == NULL ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
225 buffer_.size == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
226 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
227 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
228 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
229
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
230 if (!ReadJson(target, buffer_.data, buffer_.size))
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
231 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
232 LogError("Cannot convert some memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
233 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
234 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
235 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
236
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
237
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
238 bool MemoryBuffer::RestApiGet(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
239 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
240 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
241 Clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
242
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
243 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
244 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
245 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
246 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
247 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
248 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
249 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
250 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
253 bool MemoryBuffer::RestApiGet(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
254 const std::map<std::string, std::string>& httpHeaders,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
255 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
256 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
257 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
258
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
259 std::vector<const char*> headersKeys;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
260 std::vector<const char*> headersValues;
3039
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
261
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
262 for (std::map<std::string, std::string>::const_iterator
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
263 it = httpHeaders.begin(); it != httpHeaders.end(); it++)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
264 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
265 headersKeys.push_back(it->first.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
266 headersValues.push_back(it->second.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
267 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
268
3039
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
269 return CheckHttp(OrthancPluginRestApiGet2(
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
270 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(),
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
271 (headersKeys.empty() ? NULL : &headersKeys[0]),
0293cb3d8a37 fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3028
diff changeset
272 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
273 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
274
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
275 bool MemoryBuffer::RestApiPost(const std::string& uri,
3400
0faae6f6e3c5 fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3399
diff changeset
276 const void* body,
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
277 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
278 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
279 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
280 Clear();
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
281
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
282 // Cast for compatibility with Orthanc SDK <= 1.5.6
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
283 const char* b = reinterpret_cast<const char*>(body);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
284
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
285 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
286 {
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
287 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
288 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
289 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
290 {
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
291 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
292 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
293 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
294
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
295
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
296 bool MemoryBuffer::RestApiPut(const std::string& uri,
3400
0faae6f6e3c5 fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3399
diff changeset
297 const void* body,
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
298 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
299 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
300 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
301 Clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
302
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
303 // Cast for compatibility with Orthanc SDK <= 1.5.6
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
304 const char* b = reinterpret_cast<const char*>(body);
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
305
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
306 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
307 {
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
308 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
309 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
310 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
311 {
3405
408ffcb4038f reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3404
diff changeset
312 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize));
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
313 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
314 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
315
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
316
4444
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
317 static bool ReadJsonInternal(Json::Value& target,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
318 const void* buffer,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
319 size_t size,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
320 bool collectComments)
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
321 {
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
322 #if JSONCPP_USE_DEPRECATED == 1
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
323 Json::Reader reader;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
324 return reader.parse(reinterpret_cast<const char*>(buffer),
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
325 reinterpret_cast<const char*>(buffer) + size, target, collectComments);
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
326 #else
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
327 Json::CharReaderBuilder builder;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
328 builder.settings_["collectComments"] = collectComments;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
329
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
330 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
331 assert(reader.get() != NULL);
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
332
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
333 JSONCPP_STRING err;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
334 if (reader->parse(reinterpret_cast<const char*>(buffer),
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
335 reinterpret_cast<const char*>(buffer) + size, &target, &err))
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
336 {
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
337 return true;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
338 }
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
339 else
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
340 {
4445
5e6b5fef92f8 fix LOG() in OrthancPluginCppWrapper.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4444
diff changeset
341 LogError("Cannot parse JSON: " + std::string(err));
4444
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
342 return false;
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
343 }
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
344 #endif
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
345 }
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
346
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
347
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
348 bool ReadJson(Json::Value& target,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
349 const std::string& source)
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
350 {
4397
3aeb5171fbd4 new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4396
diff changeset
351 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size());
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
352 }
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
353
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
354
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
355 bool ReadJson(Json::Value& target,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
356 const void* buffer,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
357 size_t size)
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
358 {
4444
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
359 return ReadJsonInternal(target, buffer, size, true);
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
360 }
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
361
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
362
4444
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
363 bool ReadJsonWithoutComments(Json::Value& target,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
364 const std::string& source)
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
365 {
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
366 return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size());
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
367 }
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
368
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
369
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
370 bool ReadJsonWithoutComments(Json::Value& target,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
371 const void* buffer,
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
372 size_t size)
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
373 {
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
374 return ReadJsonInternal(target, buffer, size, false);
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
375 }
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
376
11ea0a05115b new function in OrthancPluginCppWrapper: ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
377
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
378 void WriteFastJson(std::string& target,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
379 const Json::Value& source)
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
380 {
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
381 #if JSONCPP_USE_DEPRECATED == 1
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
382 Json::FastWriter writer;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
383 target = writer.write(source);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
384 #else
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
385 Json::StreamWriterBuilder builder;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
386 builder.settings_["indentation"] = "";
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
387 target = Json::writeString(builder, source);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
388 #endif
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
389 }
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
390
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
391
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
392 void WriteStyledJson(std::string& target,
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
393 const Json::Value& source)
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
394 {
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
395 #if JSONCPP_USE_DEPRECATED == 1
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
396 Json::StyledWriter writer;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
397 target = writer.write(source);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
398 #else
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
399 Json::StreamWriterBuilder builder;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
400 builder.settings_["indentation"] = " ";
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
401 target = Json::writeString(builder, source);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
402 #endif
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
403 }
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
404
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
405
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
406 bool MemoryBuffer::RestApiPost(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
407 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
408 bool applyPlugins)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
409 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
410 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
411 WriteFastJson(s, body);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
412 return RestApiPost(uri, s, applyPlugins);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
413 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
414
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
415
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
416 bool MemoryBuffer::RestApiPut(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
417 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
418 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
419 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
420 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
421 WriteFastJson(s, body);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
422 return RestApiPut(uri, s, applyPlugins);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
423 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
424
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
425
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
426 void MemoryBuffer::CreateDicom(const Json::Value& tags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
427 OrthancPluginCreateDicomFlags flags)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
428 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
429 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
430
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
431 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
432 WriteFastJson(s, tags);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
433
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
434 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
435 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
436
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
437 void MemoryBuffer::CreateDicom(const Json::Value& tags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
438 const OrthancImage& pixelData,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
439 OrthancPluginCreateDicomFlags flags)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
440 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
441 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
442
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
443 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
444 WriteFastJson(s, tags);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
445
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
446 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
447 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
448
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
449
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
450 void MemoryBuffer::ReadFile(const std::string& path)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
451 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
452 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
453 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str()));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
454 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
455
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
456
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
457 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
458 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
459 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
460 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
461 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
462
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
463
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
464 void OrthancString::Assign(char* str)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
465 {
3440
77702c19a2fa fix issue #143
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3438
diff changeset
466 Clear();
77702c19a2fa fix issue #143
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3438
diff changeset
467
77702c19a2fa fix issue #143
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3438
diff changeset
468 if (str != NULL)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
469 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
470 str_ = str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
471 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
472 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
473
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
474
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
475 void OrthancString::Clear()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
476 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
477 if (str_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
478 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
479 OrthancPluginFreeString(GetGlobalContext(), str_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
480 str_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
481 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
482 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
483
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
484
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
485 void OrthancString::ToString(std::string& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
486 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
487 if (str_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
488 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
489 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
490 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
491 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
492 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
493 target.assign(str_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
494 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
495 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
496
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
497
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
498 void OrthancString::ToJson(Json::Value& target) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
499 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
500 if (str_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
501 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
502 LogError("Cannot convert an empty memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
503 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
504 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
505
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
506 if (!ReadJson(target, str_))
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
507 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
508 LogError("Cannot convert some memory buffer to JSON");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
509 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
510 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
511 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
512
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
513
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
514 void MemoryBuffer::DicomToJson(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
515 OrthancPluginDicomToJsonFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
516 OrthancPluginDicomToJsonFlags flags,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
517 uint32_t maxStringLength)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
518 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
519 OrthancString str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
520 str.Assign(OrthancPluginDicomBufferToJson
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
521 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
522 str.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
523 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
524
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
525
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
526 bool MemoryBuffer::HttpGet(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
527 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
528 const std::string& password)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 {
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 Clear();
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
531 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
532 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
533 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
534 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
535
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
536
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
537 bool MemoryBuffer::HttpPost(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
538 const std::string& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
539 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
540 const std::string& password)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
541 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
542 Clear();
4837
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
543
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
544 if (body.size() > 0xffffffffu)
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
545 {
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
546 LogError("Cannot handle body size > 4GB");
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
547 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
548 }
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
549
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
550 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
551 body.c_str(), body.size(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
552 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
553 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
554 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
555
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
556
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
557 bool MemoryBuffer::HttpPut(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
558 const std::string& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
559 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
560 const std::string& password)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
561 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
562 Clear();
4837
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
563
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
564 if (body.size() > 0xffffffffu)
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
565 {
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
566 LogError("Cannot handle body size > 4GB");
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
567 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
568 }
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
569
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
570 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
571 body.empty() ? NULL : body.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
572 body.size(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
573 username.empty() ? NULL : username.c_str(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
574 password.empty() ? NULL : password.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
575 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
576
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
577
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
578 void MemoryBuffer::GetDicomInstance(const std::string& instanceId)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
579 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
580 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
581 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
582 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
583
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
584
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
585 bool HttpDelete(const std::string& url,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
586 const std::string& username,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
587 const std::string& password)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
588 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
589 OrthancPluginErrorCode error = OrthancPluginHttpDelete
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
590 (GetGlobalContext(), url.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
591 username.empty() ? NULL : username.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
592 password.empty() ? NULL : password.c_str());
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
593
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
594 if (error == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
595 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
596 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
597 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
598 else if (error == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
599 error == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
600 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
601 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
602 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
603 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
604 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
605 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
606 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
607 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
608
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
609
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
610 void LogError(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
611 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
612 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
613 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
614 OrthancPluginLogError(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
615 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
616 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
617
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
618
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
619 void LogWarning(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
620 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
621 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
622 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
623 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
624 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
625 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
626
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
627
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
628 void LogInfo(const std::string& message)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
629 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
630 if (HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
631 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
632 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
633 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
634 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
635
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
636
3421
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
637 void OrthancConfiguration::LoadConfiguration()
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
638 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
639 OrthancString str;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
640 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext()));
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
641
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
642 if (str.GetContent() == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
643 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
644 LogError("Cannot access the Orthanc configuration");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
645 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
646 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
647
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
648 str.ToJson(configuration_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
649
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
650 if (configuration_.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
651 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
652 LogError("Unable to read the Orthanc configuration");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
653 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
654 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
655 }
3421
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
656
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
657
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
658 OrthancConfiguration::OrthancConfiguration()
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
659 {
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
660 LoadConfiguration();
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
661 }
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
662
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
663
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
664 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration)
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
665 {
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
666 if (loadConfiguration)
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
667 {
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
668 LoadConfiguration();
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
669 }
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
670 else
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
671 {
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
672 configuration_ = Json::objectValue;
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
673 }
decbede6e3ad OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
674 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
675
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
676
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
677 std::string OrthancConfiguration::GetPath(const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
678 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
679 if (path_.empty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
680 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
681 return key;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
682 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
683 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
684 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
685 return path_ + "." + key;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
686 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
687 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
688
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
689
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
690 bool OrthancConfiguration::IsSection(const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
691 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
692 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
693
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
694 return (configuration_.isMember(key) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
695 configuration_[key].type() == Json::objectValue);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
696 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
697
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
698
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
699 void OrthancConfiguration::GetSection(OrthancConfiguration& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
700 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
701 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
702 assert(configuration_.type() == Json::objectValue);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
703
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
704 target.path_ = GetPath(key);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
705
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
706 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
707 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
708 target.configuration_ = Json::objectValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
709 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
710 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
711 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
712 if (configuration_[key].type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
713 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
714 LogError("The configuration section \"" + target.path_ +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
715 "\" is not an associative array as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
716
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
717 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
718 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
719
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
720 target.configuration_ = configuration_[key];
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
721 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
722 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
723
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
724
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
725 bool OrthancConfiguration::LookupStringValue(std::string& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
726 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
727 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
728 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
729
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
730 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
731 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
732 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
733 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
734
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
735 if (configuration_[key].type() != Json::stringValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
736 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
737 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
738 "\" is not a string as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
739
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
740 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
741 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
742
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
743 target = configuration_[key].asString();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
744 return true;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
745 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
746
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
747
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
748 bool OrthancConfiguration::LookupIntegerValue(int& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
749 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
750 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
751 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
752
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
753 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
754 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
755 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
756 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
757
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
758 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
759 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
760 case Json::intValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
761 target = configuration_[key].asInt();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
762 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
763
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
764 case Json::uintValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
765 target = configuration_[key].asUInt();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
766 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
767
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
768 default:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
769 LogError("The configuration option \"" + GetPath(key) +
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
770 "\" is not an integer as expected");
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
771
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
772 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
773 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
774 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
775
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
776
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
777 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
778 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
779 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
780 int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
781 if (!LookupIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
782 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
783 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
784 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
785
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
786 if (tmp < 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
787 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
788 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
789 "\" is not a positive integer as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
790
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
791 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
792 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
793 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
794 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
795 target = static_cast<unsigned int>(tmp);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
796 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
797 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
798 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
799
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
800
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
801 bool OrthancConfiguration::LookupBooleanValue(bool& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
802 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
803 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
804 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
805
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
806 if (!configuration_.isMember(key))
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
807 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
808 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
809 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
810
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
811 if (configuration_[key].type() != Json::booleanValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
812 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
813 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
814 "\" is not a Boolean as expected");
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
815
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
816 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
817 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
818
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
819 target = configuration_[key].asBool();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
820 return true;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
821 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
822
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
823
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
824 bool OrthancConfiguration::LookupFloatValue(float& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
825 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
826 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
827 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
828
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
829 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
830 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
831 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
832 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
833
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
834 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
835 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
836 case Json::realValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
837 target = configuration_[key].asFloat();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
838 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
839
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
840 case Json::intValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
841 target = static_cast<float>(configuration_[key].asInt());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
842 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
843
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
844 case Json::uintValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
845 target = static_cast<float>(configuration_[key].asUInt());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
846 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
847
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
848 default:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
849 LogError("The configuration option \"" + GetPath(key) +
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
850 "\" is not an integer as expected");
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
851
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
852 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
853 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
854 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
855
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
856
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
857 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
858 const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
859 bool allowSingleString) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
860 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
861 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
862
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
863 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
864
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
865 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
866 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
867 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
868 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
869
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
870 switch (configuration_[key].type())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
871 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
872 case Json::arrayValue:
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
873 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
874 bool ok = true;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
875
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
876 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
877 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
878 if (configuration_[key][i].type() == Json::stringValue)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
879 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
880 target.push_back(configuration_[key][i].asString());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
881 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
882 else
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
883 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
884 ok = false;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
885 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
886 }
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
887
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
888 if (ok)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
889 {
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
890 return true;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
891 }
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
892
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
893 break;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
894 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
895
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
896 case Json::stringValue:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
897 if (allowSingleString)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
898 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
899 target.push_back(configuration_[key].asString());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
900 return true;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
901 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
902
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
903 break;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
904
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
905 default:
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
906 break;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
907 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
908
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
909 LogError("The configuration option \"" + GetPath(key) +
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
910 "\" is not a list of strings as expected");
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
911
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
912 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
913 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
914
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
916 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
917 const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
918 bool allowSingleString) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
919 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
920 std::list<std::string> lst;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
921
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
922 if (LookupListOfStrings(lst, key, allowSingleString))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
923 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
924 target.clear();
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
926 for (std::list<std::string>::const_iterator
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
927 it = lst.begin(); it != lst.end(); ++it)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
928 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
929 target.insert(*it);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
930 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
931
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
932 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
933 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
934 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
935 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
936 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
937 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
938 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
939
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
940
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
941 std::string OrthancConfiguration::GetStringValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
942 const std::string& defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
943 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
944 std::string tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
945 if (LookupStringValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
946 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
947 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
948 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
949 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
950 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
951 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
952 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
953 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
954
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
955
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
956 int OrthancConfiguration::GetIntegerValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
957 int defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
958 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
959 int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
960 if (LookupIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
961 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
962 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
963 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
964 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
965 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
966 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
967 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
968 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
969
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
970
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
971 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
972 unsigned int defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
973 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
974 unsigned int tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
975 if (LookupUnsignedIntegerValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
976 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
977 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
978 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
979 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
980 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
981 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
982 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
983 }
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
984
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
985
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
986 bool OrthancConfiguration::GetBooleanValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
987 bool defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
988 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
989 bool tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
990 if (LookupBooleanValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
991 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
992 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
993 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
994 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
995 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
996 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
997 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
998 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
999
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1000
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1001 float OrthancConfiguration::GetFloatValue(const std::string& key,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1002 float defaultValue) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1003 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1004 float tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1005 if (LookupFloatValue(tmp, key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1006 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1007 return tmp;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1008 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1009 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1010 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1011 return defaultValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1012 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1013 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1014
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1015
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1016 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1017 const std::string& key) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1018 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1019 assert(configuration_.type() == Json::objectValue);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1020
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1021 target.clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1022
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1023 if (!configuration_.isMember(key))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1024 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1025 return;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1026 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1027
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1028 if (configuration_[key].type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1029 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1030 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1031 "\" is not a string as expected");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1032
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1033 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1034 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1035
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1036 Json::Value::Members members = configuration_[key].getMemberNames();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1037
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1038 for (size_t i = 0; i < members.size(); i++)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1039 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1040 const Json::Value& value = configuration_[key][members[i]];
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1041
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1042 if (value.type() == Json::stringValue)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1043 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1044 target[members[i]] = value.asString();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1045 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1046 else
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1047 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1048 LogError("The configuration option \"" + GetPath(key) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1049 "\" is not a dictionary mapping strings to strings");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1050
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1051 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1052 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1053 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1054 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1055
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1056
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1057 void OrthancImage::Clear()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1058 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1059 if (image_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1060 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1061 OrthancPluginFreeImage(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1062 image_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1063 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1064 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1065
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1066
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1067 void OrthancImage::CheckImageAvailable() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1068 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1069 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1070 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1071 LogError("Trying to access a NULL image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1072 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1073 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1074 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1075
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1076
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1077 OrthancImage::OrthancImage() :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1078 image_(NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1079 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1080 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1081
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1082
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1083 OrthancImage::OrthancImage(OrthancPluginImage* image) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1084 image_(image)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1085 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1086 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1087
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1088
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1089 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1090 uint32_t width,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1091 uint32_t height)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1092 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1093 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1094
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1095 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1096 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1097 LogError("Cannot create an image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1098 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1099 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1100 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1101
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1102
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1103 OrthancImage::OrthancImage(OrthancPluginPixelFormat format,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1104 uint32_t width,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1105 uint32_t height,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1106 uint32_t pitch,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1107 void* buffer)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1108 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1109 image_ = OrthancPluginCreateImageAccessor
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1110 (GetGlobalContext(), format, width, height, pitch, buffer);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1111
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1112 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1113 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1114 LogError("Cannot create an image accessor");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1115 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1116 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1117 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1118
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1119 void OrthancImage::UncompressPngImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1120 size_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1121 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1122 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1123
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1124 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1125
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1126 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1127 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1128 LogError("Cannot uncompress a PNG image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1129 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1130 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1131 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1132
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1133
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1134 void OrthancImage::UncompressJpegImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1135 size_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1136 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1137 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1138 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1139 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1140 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1141 LogError("Cannot uncompress a JPEG image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1142 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1143 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1144 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1145
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1146
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1147 void OrthancImage::DecodeDicomImage(const void* data,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1148 size_t size,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1149 unsigned int frame)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1150 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1151 Clear();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1152 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1153 if (image_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1154 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1155 LogError("Cannot uncompress a DICOM image");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1156 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1157 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1158 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1159
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1160
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1161 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1162 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1163 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1164 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1165 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1166
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1167
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1168 unsigned int OrthancImage::GetWidth() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1169 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1170 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1171 return OrthancPluginGetImageWidth(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1172 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1173
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1174
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1175 unsigned int OrthancImage::GetHeight() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1176 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1177 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1178 return OrthancPluginGetImageHeight(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1179 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1180
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1181
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1182 unsigned int OrthancImage::GetPitch() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1183 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1184 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1185 return OrthancPluginGetImagePitch(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1186 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1187
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1188
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1189 void* OrthancImage::GetBuffer() const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1190 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1191 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1192 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1193 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1194
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1195
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1196 void OrthancImage::CompressPngImage(MemoryBuffer& target) const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1197 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1198 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1199
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1200 OrthancPlugins::MemoryBuffer answer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1201 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(),
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1202 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1203
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1204 target.Swap(answer);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1205 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1206
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1207
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1208 void OrthancImage::CompressJpegImage(MemoryBuffer& target,
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1209 uint8_t quality) const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1210 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1211 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1212
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1213 OrthancPlugins::MemoryBuffer answer;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1214 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(),
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1215 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1216
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1217 target.Swap(answer);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1218 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1219
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1220
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1221 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1222 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1223 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1224 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1225 GetWidth(), GetHeight(), GetPitch(), GetBuffer());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1226 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1227
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1228
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1229 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output,
3236
872efde28e58 more constness
Alain Mazy <alain@mazy.be>
parents: 3179
diff changeset
1230 uint8_t quality) const
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1231 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1232 CheckImageAvailable();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1233 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1234 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1235 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1236
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1237
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1238 OrthancPluginImage* OrthancImage::Release()
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1239 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1240 CheckImageAvailable();
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1241 OrthancPluginImage* tmp = image_;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1242 image_ = NULL;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1243 return tmp;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1244 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3752
diff changeset
1245
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1246
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1247 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1248 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1249 matcher_(NULL),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1250 worklist_(worklist)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1251 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1252 if (worklist_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1253 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1254 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1255 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1256 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1257
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1258
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1259 void FindMatcher::SetupDicom(const void* query,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1260 uint32_t size)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1261 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1262 worklist_ = NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1263
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1264 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1265 if (matcher_ == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1266 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1267 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1268 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1269 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1270
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1271
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1272 FindMatcher::~FindMatcher()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1273 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1274 // The "worklist_" field
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1275
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1276 if (matcher_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1277 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1278 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1279 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1280 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1281
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1282
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1283
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1284 bool FindMatcher::IsMatch(const void* dicom,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1285 uint32_t size) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1286 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1287 int32_t result;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1288
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1289 if (matcher_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1290 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1291 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1292 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1293 else if (worklist_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1294 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1295 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1296 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1297 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1298 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1299 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1300 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1301
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1302 if (result == 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1303 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1304 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1305 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1306 else if (result == 1)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1307 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1308 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1309 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1310 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1311 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1312 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1313 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1314 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1315
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1316 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1317
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1318 void AnswerJson(const Json::Value& value,
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1319 OrthancPluginRestOutput* output)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1320 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1321 std::string bodyString;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1322 WriteStyledJson(bodyString, value);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1323 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1324 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1325
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1326 void AnswerString(const std::string& answer,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1327 const char* mimeType,
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1328 OrthancPluginRestOutput* output)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1329 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1330 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1331 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1332
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1333 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1334 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1335 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1336 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1337
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1338 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1339 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1340 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1341 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1342
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1343 bool RestApiGetString(std::string& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1344 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1345 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1346 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1347 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1348 if (!answer.RestApiGet(uri, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1349 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1350 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1351 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1352 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1353 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1354 answer.ToString(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1355 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1356 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1357 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1358
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1359 bool RestApiGetString(std::string& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1360 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1361 const std::map<std::string, std::string>& httpHeaders,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1362 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1363 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1364 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1365 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1366 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1367 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1368 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1369 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1370 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1371 answer.ToString(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1372 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1373 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1374 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1375
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1376
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1377
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1378 bool RestApiGet(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1379 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1380 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1381 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1382 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1383
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1384 if (!answer.RestApiGet(uri, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1385 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1386 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1387 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1388 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1389 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1390 if (!answer.IsEmpty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1391 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1392 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1393 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1394 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1395 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1396 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1397
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1398
3478
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1399 bool RestApiPost(std::string& result,
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1400 const std::string& uri,
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1401 const void* body,
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1402 size_t bodySize,
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1403 bool applyPlugins)
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1404 {
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1405 MemoryBuffer answer;
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1406
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1407 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1408 {
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1409 return false;
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1410 }
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1411 else
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1412 {
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1413 if (!answer.IsEmpty())
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1414 {
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1415 result.assign(answer.GetData(), answer.GetSize());
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1416 }
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1417 return true;
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1418 }
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1419 }
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1420
f93a9c6c00c5 added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents: 3443
diff changeset
1421
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1422 bool RestApiPost(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1423 const std::string& uri,
3400
0faae6f6e3c5 fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3399
diff changeset
1424 const void* body,
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1425 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1426 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1427 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1428 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1429
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1430 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1431 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1432 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1433 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1434 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1435 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1436 if (!answer.IsEmpty())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1437 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1438 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1439 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1440 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1441 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1442 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1443
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1444
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1445 bool RestApiPost(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1446 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1447 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1448 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1449 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1450 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1451 WriteFastJson(s, body);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1452 return RestApiPost(result, uri, s, applyPlugins);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1453 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1454
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1455
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1456 bool RestApiPut(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1457 const std::string& uri,
3400
0faae6f6e3c5 fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3399
diff changeset
1458 const void* body,
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1459 size_t bodySize,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1460 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1461 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1462 MemoryBuffer answer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1463
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1464 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1465 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1466 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1467 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1468 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1469 {
3422
8b4169a88039 ORTHANC_PLUGINS_API using visibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3421
diff changeset
1470 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1471 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1472 answer.ToJson(result);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1473 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1474 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1475 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1476 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1477
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1478
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1479 bool RestApiPut(Json::Value& result,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1480 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1481 const Json::Value& body,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1482 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1483 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1484 std::string s;
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1485 WriteFastJson(s, body);
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
1486 return RestApiPut(result, uri, s, applyPlugins);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1487 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1488
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1489
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1490 bool RestApiDelete(const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1491 bool applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1492 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1493 OrthancPluginErrorCode error;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1494
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1495 if (applyPlugins)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1496 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1497 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1498 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1499 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1500 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1501 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1502 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1503
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1504 if (error == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1505 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1506 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1507 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1508 else if (error == OrthancPluginErrorCode_UnknownResource ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1509 error == OrthancPluginErrorCode_InexistentItem)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1510 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1511 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1512 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1513 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1514 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1515 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1516 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1517 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1518
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1519
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1520 void ReportMinimalOrthancVersion(unsigned int major,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1521 unsigned int minor,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1522 unsigned int revision)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1523 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1524 LogError("Your version of the Orthanc core (" +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1525 std::string(GetGlobalContext()->orthancVersion) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1526 ") is too old to run this plugin (version " +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1527 boost::lexical_cast<std::string>(major) + "." +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1528 boost::lexical_cast<std::string>(minor) + "." +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1529 boost::lexical_cast<std::string>(revision) +
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1530 " is required)");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1531 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1532
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1533
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1534 bool CheckMinimalOrthancVersion(unsigned int major,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1535 unsigned int minor,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1536 unsigned int revision)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1537 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1538 if (!HasGlobalContext())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1539 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1540 LogError("Bad Orthanc context in the plugin");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1541 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1542 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1543
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1544 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline"))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1545 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1546 // Assume compatibility with the mainline
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1547 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1548 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1549
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1550 // Parse the version of the Orthanc core
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1551 int aa, bb, cc;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1552 if (
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1553 #ifdef _MSC_VER
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1554 sscanf_s
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1555 #else
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1556 sscanf
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1557 #endif
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1558 (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 ||
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1559 aa < 0 ||
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1560 bb < 0 ||
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1561 cc < 0)
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1562 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1563 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1564 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1565
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1566 unsigned int a = static_cast<unsigned int>(aa);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1567 unsigned int b = static_cast<unsigned int>(bb);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1568 unsigned int c = static_cast<unsigned int>(cc);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1569
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1570 // Check the major version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1571
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1572 if (a > major)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1573 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1574 return true;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1575 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1576
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1577 if (a < major)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1578 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1579 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1580 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1581
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1582
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1583 // Check the minor version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1584 assert(a == major);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1585
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1586 if (b > minor)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1587 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1588 return true;
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1589 }
2792
57e2d65d37ce OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1590
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1591 if (b < minor)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1592 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1593 return false;
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1594 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1595
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1596 // Check the patch level version number
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1597 assert(a == major && b == minor);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1598
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1599 if (c >= revision)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1601 return true;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1605 return false;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 }
2058
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1608
43cd2ab060c7 cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2048
diff changeset
1609
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1610 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1611 const char* AutodetectMimeType(const std::string& path)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1612 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1613 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str());
2062
40ffd0e8676a generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
1614
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1615 if (mime == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1616 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1617 // Should never happen, just for safety
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1618 return "application/octet-stream";
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1619 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1620 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1621 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1622 return mime;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1623 }
2848
dd3914a44b87 added accessors in C++ wrappers
am@osimis.io
parents: 2823
diff changeset
1624 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1625 #endif
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1626
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1627
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1628 #if HAS_ORTHANC_PLUGIN_PEERS == 1
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1629 size_t OrthancPeers::GetPeerIndex(const std::string& name) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1630 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1631 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1632 if (LookupName(index, name))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1633 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1634 return index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1635 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1636 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1637 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1638 LogError("Inexistent peer: " + name);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1639 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1640 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1641 }
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
1642
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2058
diff changeset
1643
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1644 OrthancPeers::OrthancPeers() :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1645 peers_(NULL),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1646 timeout_(0)
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
1647 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1648 peers_ = OrthancPluginGetPeers(GetGlobalContext());
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1649
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1650 if (peers_ == NULL)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1651 {
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1652 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1653 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1654
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1655 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1656
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1657 for (uint32_t i = 0; i < count; i++)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1658 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1659 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1660 if (name == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1661 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1662 OrthancPluginFreePeers(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1663 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1664 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1665
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1666 index_[name] = i;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1667 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1668 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1669
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1670
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1671 OrthancPeers::~OrthancPeers()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1672 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1673 if (peers_ != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1674 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1675 OrthancPluginFreePeers(GetGlobalContext(), peers_);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1676 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1677 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1678
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1679
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1680 bool OrthancPeers::LookupName(size_t& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1681 const std::string& name) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1682 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1683 Index::const_iterator found = index_.find(name);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1684
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1685 if (found == index_.end())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1686 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1687 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1688 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1689 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1690 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1691 target = found->second;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1692 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1693 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1694 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1695
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1696
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1697 std::string OrthancPeers::GetPeerName(size_t index) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1698 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1699 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1700 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1701 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1702 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1703 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1704 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1705 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1706 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1707 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1708 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1709 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1710 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1711 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1712 return s;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1713 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1714 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1715 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1716
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1717
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1718 std::string OrthancPeers::GetPeerUrl(size_t index) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1719 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1720 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1721 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1722 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1723 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1724 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1725 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1726 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1727 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1728 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1729 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1730 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1731 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1732 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1733 return s;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1734 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1735 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1736 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1737
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1738
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1739 std::string OrthancPeers::GetPeerUrl(const std::string& name) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1740 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1741 return GetPeerUrl(GetPeerIndex(name));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1742 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1743
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1744
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1745 bool OrthancPeers::LookupUserProperty(std::string& value,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1746 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1747 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1748 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1749 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1750 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1751 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1752 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1753 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1754 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1755 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1756 if (s == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1757 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1758 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1759 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1760 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1761 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1762 value.assign(s);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1763 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1764 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1765 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1766 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1767
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1768
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1769 bool OrthancPeers::LookupUserProperty(std::string& value,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1770 const std::string& peer,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1771 const std::string& key) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1772 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1773 return LookupUserProperty(value, GetPeerIndex(peer), key);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1774 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1775
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
1776
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1777 bool OrthancPeers::DoGet(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1778 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1779 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1780 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1781 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1782 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1783 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1784 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1785
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1786 OrthancPlugins::MemoryBuffer answer;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1787 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1788 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1789 (GetGlobalContext(), *answer, NULL, &status, peers_,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1790 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1791 0, NULL, NULL, NULL, 0, timeout_);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1792
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1793 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1794 {
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1795 target.Swap(answer);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1796 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1797 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1798 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1799 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1800 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1801 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1802 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1803
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1804
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1805 bool OrthancPeers::DoGet(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1806 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1807 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1808 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1809 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1810 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1811 DoGet(target, index, uri));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1812 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1813
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1814
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1815 bool OrthancPeers::DoGet(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1816 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1817 const std::string& uri) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1818 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1819 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1820
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1821 if (DoGet(buffer, index, uri))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1822 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1823 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1824 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1825 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1826 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1827 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1828 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1829 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1830 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1831
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1832
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1833 bool OrthancPeers::DoGet(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1834 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1835 const std::string& uri) const
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1836 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1837 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1838
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1839 if (DoGet(buffer, name, uri))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1840 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1841 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1842 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1843 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1844 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1845 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1846 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1847 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1848 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1849
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1850
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1851 bool OrthancPeers::DoPost(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1852 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1853 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1854 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1855 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1856 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1857 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1858 DoPost(target, index, uri, body));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1859 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1860
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1861
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1862 bool OrthancPeers::DoPost(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1863 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1864 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1865 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1866 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1867 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1868
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1869 if (DoPost(buffer, index, uri, body))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1870 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1871 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1872 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1873 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1874 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1875 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1876 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1877 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1878 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1879
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1880
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1881 bool OrthancPeers::DoPost(Json::Value& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1882 const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1883 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1884 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1885 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1886 MemoryBuffer buffer;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1887
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1888 if (DoPost(buffer, name, uri, body))
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1889 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1890 buffer.ToJson(target);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1891 return true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1892 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1893 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1894 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1895 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1896 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1897 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1898
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1899
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1900 bool OrthancPeers::DoPost(MemoryBuffer& target,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1901 size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1902 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1903 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1904 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1905 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1906 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1907 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1908 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1909
4837
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1910 if (body.size() > 0xffffffffu)
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1911 {
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1912 LogError("Cannot handle body size > 4GB");
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1913 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1914 }
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1915
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1916 OrthancPlugins::MemoryBuffer answer;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1917 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1918 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1919 (GetGlobalContext(), *answer, NULL, &status, peers_,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1920 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1921 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1922
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1923 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1924 {
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1925 target.Swap(answer);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1926 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1927 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1928 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1929 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1930 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1931 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1932 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1933
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1934
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1935 bool OrthancPeers::DoPut(size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1936 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1937 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1938 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1939 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1940 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1941 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1942 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1943
4837
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1944 if (body.size() > 0xffffffffu)
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1945 {
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1946 LogError("Cannot handle body size > 4GB");
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1947 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1948 }
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
1949
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1950 OrthancPlugins::MemoryBuffer answer;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1951 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1952 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1953 (GetGlobalContext(), *answer, NULL, &status, peers_,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1954 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
1955 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
1956
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1957 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1958 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1959 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1960 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1961 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1962 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1963 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1964 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1965 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1966
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1967
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1968 bool OrthancPeers::DoPut(const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1969 const std::string& uri,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1970 const std::string& body) const
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1971 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1972 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1973 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1974 DoPut(index, uri, body));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1975 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1976
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1977
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1978 bool OrthancPeers::DoDelete(size_t index,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1979 const std::string& uri) const
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1980 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1981 if (index >= index_.size())
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1982 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1983 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1984 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1985
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1986 OrthancPlugins::MemoryBuffer answer;
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1987 uint16_t status;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1988 OrthancPluginErrorCode code = OrthancPluginCallPeerApi
3320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1989 (GetGlobalContext(), *answer, NULL, &status, peers_,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1990 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3319
diff changeset
1991 0, NULL, NULL, NULL, 0, timeout_);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1992
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1993 if (code == OrthancPluginErrorCode_Success)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1994 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1995 return (status == 200);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1996 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1997 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1998 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
1999 return false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2000 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2001 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2002
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2003
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2004 bool OrthancPeers::DoDelete(const std::string& name,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2005 const std::string& uri) const
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2006 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2007 size_t index;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2008 return (LookupName(index, name) &&
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2009 DoDelete(index, uri));
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2010 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2011 #endif
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2012
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2013
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2014
3397
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2015
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2016
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2017 /******************************************************************
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2018 ** JOBS
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2019 ******************************************************************/
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2020
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2021 #if HAS_ORTHANC_PLUGIN_JOB == 1
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2022 void OrthancJob::CallbackFinalize(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2023 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2024 if (job != NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2025 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2026 delete reinterpret_cast<OrthancJob*>(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2027 }
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2028 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2029
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2030
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2031 float OrthancJob::CallbackGetProgress(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2032 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2033 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2034
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2035 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2036 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2037 return reinterpret_cast<OrthancJob*>(job)->progress_;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2038 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2039 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2040 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2041 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2042 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2043 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2044
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2045
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2046 const char* OrthancJob::CallbackGetContent(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2047 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2048 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2049
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2050 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2051 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2052 return reinterpret_cast<OrthancJob*>(job)->content_.c_str();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2053 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2054 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2055 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2056 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2057 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2058 }
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2059
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2060
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2061 const char* OrthancJob::CallbackGetSerialized(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2062 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2063 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2064
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2065 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2066 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2067 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2068
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2069 if (tmp.hasSerialized_)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2070 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2071 return tmp.serialized_.c_str();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2072 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2073 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2074 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2075 return NULL;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2076 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2077 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2078 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2079 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2080 return 0;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2081 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2082 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2083
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2084
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2085 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2086 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2087 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2088
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2089 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2090 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2091 return reinterpret_cast<OrthancJob*>(job)->Step();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2092 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2093 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2094 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2095 return OrthancPluginJobStepStatus_Failure;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2096 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2097 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2098 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2099 return OrthancPluginJobStepStatus_Failure;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2100 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2101 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2102
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2103
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2104 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2105 OrthancPluginJobStopReason reason)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2106 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2107 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2108
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2109 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2110 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2111 reinterpret_cast<OrthancJob*>(job)->Stop(reason);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2112 return OrthancPluginErrorCode_Success;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2113 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2114 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2115 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2116 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2117 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2118 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2119 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2120 return OrthancPluginErrorCode_Plugin;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2121 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2122 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2123
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2124
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2125 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2127 assert(job != NULL);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2128
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2129 try
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2130 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2131 reinterpret_cast<OrthancJob*>(job)->Reset();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2132 return OrthancPluginErrorCode_Success;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2133 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2134 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2135 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2136 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2137 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2138 catch (...)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2139 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2140 return OrthancPluginErrorCode_Plugin;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2141 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2142 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2143
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2144
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2145 void OrthancJob::ClearContent()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2146 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2147 Json::Value empty = Json::objectValue;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2148 UpdateContent(empty);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2149 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2150
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2151
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2152 void OrthancJob::UpdateContent(const Json::Value& content)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2153 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2154 if (content.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2155 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2156 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2157 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2158 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2159 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
2160 WriteFastJson(content_, content);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2161 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2162 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2163
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2164
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2165 void OrthancJob::ClearSerialized()
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2166 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2167 hasSerialized_ = false;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2168 serialized_.clear();
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2169 }
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2170
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2171
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2172 void OrthancJob::UpdateSerialized(const Json::Value& serialized)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2173 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2174 if (serialized.type() != Json::objectValue)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2175 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2176 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2177 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2178 else
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2179 {
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
2180 WriteFastJson(serialized_, serialized);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2181 hasSerialized_ = true;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2182 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2183 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2184
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2185
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2186 void OrthancJob::UpdateProgress(float progress)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2187 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2188 if (progress < 0 ||
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2189 progress > 1)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2190 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2191 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2192 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2193
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2194 progress_ = progress;
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2195 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2196
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2197
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2198 OrthancJob::OrthancJob(const std::string& jobType) :
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2199 jobType_(jobType),
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2200 progress_(0)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2201 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2202 ClearContent();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2203 ClearSerialized();
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2204 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2205
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2206
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2207 OrthancPluginJob* OrthancJob::Create(OrthancJob* job)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2208 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2209 if (job == NULL)
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2210 {
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2211 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2212 }
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2213
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2214 OrthancPluginJob* orthanc = OrthancPluginCreateJob(
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2215 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2216 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2217 CallbackStep, CallbackStop, CallbackReset);
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2218
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2219 if (orthanc == NULL)
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2220 {
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2221 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2222 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2223 else
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2224 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2225 return orthanc;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2226 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2227 }
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2177
diff changeset
2228
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
2229
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2230 std::string OrthancJob::Submit(OrthancJob* job,
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2231 int priority)
2264
8e5e0de75839 primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2263
diff changeset
2232 {
3437
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2233 if (job == NULL)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2234 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2235 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer);
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2236 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2237
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2238 OrthancPluginJob* orthanc = Create(job);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2239
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2240 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2241
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2242 if (id == NULL)
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2243 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2244 LogError("Plugin cannot submit job");
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2245 OrthancPluginFreeJob(GetGlobalContext(), orthanc);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2246 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2247 }
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2248 else
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2249 {
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2250 std::string tmp(id);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2251 tmp.assign(id);
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2252 OrthancPluginFreeString(GetGlobalContext(), id);
3026
c358bdb37c13 more plugin helpers
amazy
parents: 2988
diff changeset
2253
3028
ff65c925f57a fix indentation
am@osimis.io
parents: 3026
diff changeset
2254 return tmp;
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2255 }
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2256 }
3437
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2257
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2258
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2259 void OrthancJob::SubmitAndWait(Json::Value& result,
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2260 OrthancJob* job /* takes ownership */,
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2261 int priority)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2262 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2263 std::string id = Submit(job, priority);
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2264
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2265 for (;;)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2266 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2267 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2268
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2269 Json::Value status;
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2270 if (!RestApiGet(status, "/jobs/" + id, false) ||
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2271 !status.isMember("State") ||
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2272 status["State"].type() != Json::stringValue)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2273 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2274 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem);
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2275 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2276
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2277 const std::string state = status["State"].asString();
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2278 if (state == "Success")
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2279 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2280 if (status.isMember("Content"))
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2281 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2282 result = status["Content"];
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2283 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2284 else
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2285 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2286 result = Json::objectValue;
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2287 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2288
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2289 return;
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2290 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2291 else if (state == "Running")
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2292 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2293 continue;
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2294 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2295 else if (!status.isMember("ErrorCode") ||
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2296 status["ErrorCode"].type() != Json::intValue)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2297 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2298 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError);
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2299 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2300 else
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2301 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2302 if (!status.isMember("ErrorDescription") ||
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2303 status["ErrorDescription"].type() != Json::stringValue)
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2304 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2305 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2306 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2307 else
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2308 {
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2309 #if HAS_ORTHANC_EXCEPTION == 1
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2310 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()),
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2311 status["ErrorDescription"].asString());
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2312 #else
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2313 LogError("Exception while executing the job: " + status["ErrorDescription"].asString());
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2314 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2315 #endif
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2316 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2317 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2318 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2319 }
dbaf439c8888 OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3434
diff changeset
2320
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2321
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2322 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2323 const Json::Value& body,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2324 OrthancJob* job)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2325 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2326 static const char* KEY_SYNCHRONOUS = "Synchronous";
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2327 static const char* KEY_ASYNCHRONOUS = "Asynchronous";
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2328 static const char* KEY_PRIORITY = "Priority";
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2329
3749
edabdf07ee83 replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3669
diff changeset
2330 boost::movelib::unique_ptr<OrthancJob> protection(job);
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2331
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2332 if (body.type() != Json::objectValue)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2333 {
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2334 #if HAS_ORTHANC_EXCEPTION == 1
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2335 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2336 "Expected a JSON object in the body");
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2337 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2338 LogError("Expected a JSON object in the body");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2339 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2340 #endif
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2341 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2342
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2343 bool synchronous = true;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2344
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2345 if (body.isMember(KEY_SYNCHRONOUS))
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2346 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2347 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2348 {
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2349 #if HAS_ORTHANC_EXCEPTION == 1
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2350 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2351 "Option \"" + std::string(KEY_SYNCHRONOUS) +
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2352 "\" must be Boolean");
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2353 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2354 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2355 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2356 #endif
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2357 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2358 else
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2359 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2360 synchronous = body[KEY_SYNCHRONOUS].asBool();
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2361 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2362 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2363
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2364 if (body.isMember(KEY_ASYNCHRONOUS))
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2365 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2366 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2367 {
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2368 #if HAS_ORTHANC_EXCEPTION == 1
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2369 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2370 "Option \"" + std::string(KEY_ASYNCHRONOUS) +
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2371 "\" must be Boolean");
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2372 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2373 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2374 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2375 #endif
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2376 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2377 else
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2378 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2379 synchronous = !body[KEY_ASYNCHRONOUS].asBool();
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2380 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2381 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2382
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2383 int priority = 0;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2384
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2385 if (body.isMember(KEY_PRIORITY))
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2386 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2387 if (body[KEY_PRIORITY].type() != Json::booleanValue)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2388 {
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2389 #if HAS_ORTHANC_EXCEPTION == 1
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2390 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2391 "Option \"" + std::string(KEY_PRIORITY) +
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2392 "\" must be an integer");
3669
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2393 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2394 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2395 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3667
diff changeset
2396 #endif
3667
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2397 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2398 else
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2399 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2400 priority = !body[KEY_PRIORITY].asInt();
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2401 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2402 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2403
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2404 Json::Value result;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2405
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2406 if (synchronous)
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2407 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2408 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority);
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2409 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2410 else
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2411 {
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2412 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority);
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2413
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2414 result = Json::objectValue;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2415 result["ID"] = id;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2416 result["Path"] = "/jobs/" + id;
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2417 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2418
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2419 std::string s = result.toStyledString();
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2420 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(),
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2421 s.size(), "application/json");
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2422 }
c8d8c3b5f47c OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2423
2817
473bf302d629 C++ wrappers around OrthancPluginJob and OrthancPluginPeers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2803
diff changeset
2424 #endif
3179
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2425
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2426
3397
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2427
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2428
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2429 /******************************************************************
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2430 ** METRICS
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2431 ******************************************************************/
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2432
3179
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2433 #if HAS_ORTHANC_PLUGIN_METRICS == 1
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2434 MetricsTimer::MetricsTimer(const char* name) :
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2435 name_(name)
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2436 {
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2437 start_ = boost::posix_time::microsec_clock::universal_time();
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2438 }
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2439
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2440 MetricsTimer::~MetricsTimer()
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2441 {
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2442 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time();
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2443 const boost::posix_time::time_duration diff = stop - start_;
3418
e2b032584a83 fix for msvc 2008
s.jodogne@gmail.com
parents: 3416
diff changeset
2444 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()),
3179
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2445 OrthancPluginMetricsType_Timer);
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2446 }
fca730c267d7 New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
2447 #endif
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2448
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2449
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2450
3397
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2451
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2452 /******************************************************************
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2453 ** HTTP CLIENT
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2454 ******************************************************************/
9019279dbfd7 new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3394
diff changeset
2455
3388
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3387
diff changeset
2456 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2457 class HttpClient::RequestBodyWrapper : public boost::noncopyable
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2458 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2459 private:
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2460 static RequestBodyWrapper& GetObject(void* body)
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2461 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2462 assert(body != NULL);
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2463 return *reinterpret_cast<RequestBodyWrapper*>(body);
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2464 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2465
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2466 IRequestBody& body_;
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2467 bool done_;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2468 std::string chunk_;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2469
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2470 public:
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2471 RequestBodyWrapper(IRequestBody& body) :
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2472 body_(body),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2473 done_(false)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2474 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2475 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2476
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2477 static uint8_t IsDone(void* body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2478 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2479 return GetObject(body).done_;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2480 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2481
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2482 static const void* GetChunkData(void* body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2483 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2484 return GetObject(body).chunk_.c_str();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2485 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2486
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2487 static uint32_t GetChunkSize(void* body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2488 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2489 return static_cast<uint32_t>(GetObject(body).chunk_.size());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2490 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2491
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2492 static OrthancPluginErrorCode Next(void* body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2493 {
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2494 RequestBodyWrapper& that = GetObject(body);
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2495
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2496 if (that.done_)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2497 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2498 return OrthancPluginErrorCode_BadSequenceOfCalls;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2499 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2500 else
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2501 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2502 try
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2503 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2504 that.done_ = !that.body_.ReadNextChunk(that.chunk_);
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2505 return OrthancPluginErrorCode_Success;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2506 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2507 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2508 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2509 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2510 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2511 catch (...)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2512 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2513 return OrthancPluginErrorCode_InternalError;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2514 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2515 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2516 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2517 };
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2518
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2519
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2520 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2521 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2522 const char* key,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2523 const char* value)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2524 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2525 assert(answer != NULL && key != NULL && value != NULL);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2526
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2527 try
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2528 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2529 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2530 return OrthancPluginErrorCode_Success;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2531 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2532 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2533 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2534 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2535 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2536 catch (...)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2537 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2538 return OrthancPluginErrorCode_Plugin;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2539 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2540 }
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2541 #endif
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2542
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2543
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2544 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2545 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2546 const void* data,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2547 uint32_t size)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2548 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2549 assert(answer != NULL);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2550
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2551 try
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2552 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2553 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2554 return OrthancPluginErrorCode_Success;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2555 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2556 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2557 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2558 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2559 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2560 catch (...)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2561 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2562 return OrthancPluginErrorCode_Plugin;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2563 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2564 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2565 #endif
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2566
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2567
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2568 HttpClient::HttpClient() :
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2569 httpStatus_(0),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2570 method_(OrthancPluginHttpMethod_Get),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2571 timeout_(0),
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2572 pkcs11_(false),
3443
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2573 chunkedBody_(NULL),
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2574 allowChunkedTransfers_(true)
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2575 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2576 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2577
3426
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2578
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2579 void HttpClient::AddHeaders(const HttpHeaders& headers)
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2580 {
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2581 for (HttpHeaders::const_iterator it = headers.begin();
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2582 it != headers.end(); ++it)
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2583 {
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2584 headers_[it->first] = it->second;
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2585 }
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2586 }
00737cd21f40 OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3422
diff changeset
2587
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2588
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2589 void HttpClient::SetCredentials(const std::string& username,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2590 const std::string& password)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2591 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2592 username_ = username;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2593 password_ = password;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2594 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2595
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2596
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2597 void HttpClient::ClearCredentials()
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2598 {
4846
b2e08d83e21d fix OrthancPlugins::HttpClient::ClearCredentials()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4838
diff changeset
2599 username_.clear();
b2e08d83e21d fix OrthancPlugins::HttpClient::ClearCredentials()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4838
diff changeset
2600 password_.clear();
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2601 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2602
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2603
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2604 void HttpClient::SetCertificate(const std::string& certificateFile,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2605 const std::string& keyFile,
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2606 const std::string& keyPassword)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2607 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2608 certificateFile_ = certificateFile;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2609 certificateKeyFile_ = keyFile;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2610 certificateKeyPassword_ = keyPassword;
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2611 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2612
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2613
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2614 void HttpClient::ClearCertificate()
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2615 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2616 certificateFile_.clear();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2617 certificateKeyFile_.clear();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2618 certificateKeyPassword_.clear();
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2619 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2620
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2621
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2622 void HttpClient::ClearBody()
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2623 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2624 fullBody_.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2625 chunkedBody_ = NULL;
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2626 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2627
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2628
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2629 void HttpClient::SwapBody(std::string& body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2630 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2631 fullBody_.swap(body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2632 chunkedBody_ = NULL;
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2633 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2634
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2635
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2636 void HttpClient::SetBody(const std::string& body)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2637 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2638 fullBody_ = body;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2639 chunkedBody_ = NULL;
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2640 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2641
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2642
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2643 void HttpClient::SetBody(IRequestBody& body)
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2644 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2645 fullBody_.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2646 chunkedBody_ = &body;
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2647 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2648
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2649
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2650 namespace
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2651 {
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2652 class HeadersWrapper : public boost::noncopyable
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2653 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2654 private:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2655 std::vector<const char*> headersKeys_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2656 std::vector<const char*> headersValues_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2657
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2658 public:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2659 HeadersWrapper(const HttpClient::HttpHeaders& headers)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2660 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2661 headersKeys_.reserve(headers.size());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2662 headersValues_.reserve(headers.size());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2663
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2664 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2665 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2666 headersKeys_.push_back(it->first.c_str());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2667 headersValues_.push_back(it->second.c_str());
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2668 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2669 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2670
3394
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2671 void AddStaticString(const char* key,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2672 const char* value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2673 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2674 headersKeys_.push_back(key);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2675 headersValues_.push_back(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2676 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2677
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2678 uint32_t GetCount() const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2679 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2680 return headersKeys_.size();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2681 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2682
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2683 const char* const* GetKeys() const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2684 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2685 return headersKeys_.empty() ? NULL : &headersKeys_[0];
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2686 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2687
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2688 const char* const* GetValues() const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2689 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2690 return headersValues_.empty() ? NULL : &headersValues_[0];
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2691 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2692 };
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2693
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2694
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2695 class MemoryRequestBody : public HttpClient::IRequestBody
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2696 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2697 private:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2698 std::string body_;
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2699 bool done_;
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2700
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2701 public:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2702 MemoryRequestBody(const std::string& body) :
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2703 body_(body),
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2704 done_(false)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2705 {
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2706 if (body_.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2707 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2708 done_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2709 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2710 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2711
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2712 virtual bool ReadNextChunk(std::string& chunk)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2713 {
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2714 if (done_)
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2715 {
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2716 return false;
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2717 }
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2718 else
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2719 {
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2720 chunk.swap(body_);
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2721 done_ = true;
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2722 return true;
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
2723 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2724 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2725 };
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2726
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2727
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2728 // This class mimics Orthanc::ChunkedBuffer
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2729 class ChunkedBuffer : public boost::noncopyable
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2730 {
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2731 private:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2732 typedef std::list<std::string*> Content;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2733
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2734 Content content_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2735 size_t size_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2736
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2737 public:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2738 ChunkedBuffer() :
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2739 size_(0)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2740 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2741 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2742
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2743 ~ChunkedBuffer()
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2744 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2745 Clear();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2746 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2747
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2748 void Clear()
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2749 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2750 for (Content::iterator it = content_.begin(); it != content_.end(); ++it)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2751 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2752 assert(*it != NULL);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2753 delete *it;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2754 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2755
4651
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2756 size_ = 0;
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2757 content_.clear();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2758 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2759
4651
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2760 /**
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2761 * Since Orthanc 1.9.3, this function also clears the content of
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2762 * the ChunkedBuffer in order to mimic the behavior of the
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2763 * original class "Orthanc::ChunkedBuffer". This prevents the
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2764 * forgetting of calling "Clear()" in order to reduce memory
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2765 * consumption.
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2766 **/
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2767 void Flatten(std::string& target)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2768 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2769 target.resize(size_);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2770
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2771 size_t pos = 0;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2772
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2773 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2774 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2775 assert(*it != NULL);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2776 size_t s = (*it)->size();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2777
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2778 if (s != 0)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2779 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2780 memcpy(&target[pos], (*it)->c_str(), s);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2781 pos += s;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2782 }
4651
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2783
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2784 delete *it;
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2785 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2786
4651
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2787 assert(pos == target.size());
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2788
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2789 size_ = 0;
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2790 content_.clear();
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2791 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2792
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2793 void AddChunk(const void* data,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2794 size_t size)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2795 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2796 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size));
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2797 size_ += size;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2798 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2799
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2800 void AddChunk(const std::string& chunk)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2801 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2802 content_.push_back(new std::string(chunk));
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2803 size_ += chunk.size();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2804 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2805 };
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2806
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2807
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2808 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2809 class MemoryAnswer : public HttpClient::IAnswer
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2810 {
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2811 private:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2812 HttpClient::HttpHeaders headers_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2813 ChunkedBuffer body_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2814
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2815 public:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2816 const HttpClient::HttpHeaders& GetHeaders() const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2817 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2818 return headers_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2819 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2820
4651
365f51fae413 reduce memory consumption of OrthancPlugins::HttpClient::Execute() in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4445
diff changeset
2821 ChunkedBuffer& GetBody()
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2822 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2823 return body_;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2824 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2825
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2826 virtual void AddHeader(const std::string& key,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2827 const std::string& value)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2828 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2829 headers_[key] = value;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2830 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2831
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2832 virtual void AddChunk(const void* data,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2833 size_t size)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2834 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2835 body_.AddChunk(data, size);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2836 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2837 };
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2838 #endif
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2839 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2840
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2841
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2842 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2843 void HttpClient::ExecuteWithStream(uint16_t& httpStatus,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2844 IAnswer& answer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2845 IRequestBody& body) const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2846 {
3394
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2847 HeadersWrapper h(headers_);
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2848
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2849 if (method_ == OrthancPluginHttpMethod_Post ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2850 method_ == OrthancPluginHttpMethod_Put)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2851 {
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2852 // Automatically set the "Transfer-Encoding" header if absent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2853 bool found = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2854
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2855 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
3394
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2856 {
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2857 if (boost::iequals(it->first, "Transfer-Encoding"))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2858 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2859 found = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2860 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2861 }
3394
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2862 }
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2863
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2864 if (!found)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2865 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2866 h.AddStaticString("Transfer-Encoding", "chunked");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
2867 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2868 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2869
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2870 RequestBodyWrapper request(body);
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2871
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
2872 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient(
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2873 GetGlobalContext(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2874 &answer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2875 AnswerAddChunkCallback,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2876 AnswerAddHeaderCallback,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2877 &httpStatus,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2878 method_,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2879 url_.c_str(),
3394
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2880 h.GetCount(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2881 h.GetKeys(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3393
diff changeset
2882 h.GetValues(),
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2883 &request,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2884 RequestBodyWrapper::IsDone,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2885 RequestBodyWrapper::GetChunkData,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2886 RequestBodyWrapper::GetChunkSize,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2887 RequestBodyWrapper::Next,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2888 username_.empty() ? NULL : username_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2889 password_.empty() ? NULL : password_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2890 timeout_,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2891 certificateFile_.empty() ? NULL : certificateFile_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2892 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2893 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2894 pkcs11_ ? 1 : 0);
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2895
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2896 if (error != OrthancPluginErrorCode_Success)
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2897 {
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2898 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2899 }
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3320
diff changeset
2900 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2901 #endif
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2902
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2903
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2904 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2905 HttpHeaders& answerHeaders,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2906 std::string& answerBody,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2907 const std::string& body) const
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2908 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2909 HeadersWrapper headers(headers_);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2910
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2911 MemoryBuffer answerBodyBuffer, answerHeadersBuffer;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2912
4837
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2913 if (body.size() > 0xffffffffu)
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2914 {
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2915 LogError("Cannot handle body size > 4GB");
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2916 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2917 }
a678ff1b8278 CPP Wrapper: fail when trying to use body > 4GB
Alain Mazy <am@osimis.io>
parents: 4651
diff changeset
2918
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2919 OrthancPluginErrorCode error = OrthancPluginHttpClient(
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2920 GetGlobalContext(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2921 *answerBodyBuffer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2922 *answerHeadersBuffer,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2923 &httpStatus,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2924 method_,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2925 url_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2926 headers.GetCount(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2927 headers.GetKeys(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2928 headers.GetValues(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2929 body.empty() ? NULL : body.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2930 body.size(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2931 username_.empty() ? NULL : username_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2932 password_.empty() ? NULL : password_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2933 timeout_,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2934 certificateFile_.empty() ? NULL : certificateFile_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2935 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2936 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(),
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2937 pkcs11_ ? 1 : 0);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2938
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2939 if (error != OrthancPluginErrorCode_Success)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2940 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2941 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2942 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2943
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2944 Json::Value v;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2945 answerHeadersBuffer.ToJson(v);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2946
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2947 if (v.type() != Json::objectValue)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2948 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2949 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2950 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2951
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2952 Json::Value::Members members = v.getMemberNames();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2953 answerHeaders.clear();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2954
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2955 for (size_t i = 0; i < members.size(); i++)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2956 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2957 const Json::Value& h = v[members[i]];
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2958 if (h.type() != Json::stringValue)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2959 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2960 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2961 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2962 else
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2963 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2964 answerHeaders[members[i]] = h.asString();
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2965 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2966 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2967
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2968 answerBodyBuffer.ToString(answerBody);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2969 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2970
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2971
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2972 void HttpClient::Execute(IAnswer& answer)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2973 {
3438
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2974 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3443
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2975 if (allowChunkedTransfers_)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2976 {
3443
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2977 if (chunkedBody_ != NULL)
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2978 {
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2979 ExecuteWithStream(httpStatus_, answer, *chunkedBody_);
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2980 }
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2981 else
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2982 {
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2983 MemoryRequestBody wrapper(fullBody_);
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2984 ExecuteWithStream(httpStatus_, answer, wrapper);
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2985 }
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2986
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2987 return;
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
2988 }
3443
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2989 #endif
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2990
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2991 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2992 // transfers are disabled. This results in higher memory usage
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
2993 // (all chunks from the answer body are sent at once)
3438
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2994
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2995 HttpHeaders answerHeaders;
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2996 std::string answerBody;
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2997 Execute(answerHeaders, answerBody);
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2998
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
2999 for (HttpHeaders::const_iterator it = answerHeaders.begin();
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3000 it != answerHeaders.end(); ++it)
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3001 {
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3002 answer.AddHeader(it->first, it->second);
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3003 }
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3004
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3005 if (!answerBody.empty())
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3006 {
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3007 answer.AddChunk(answerBody.c_str(), answerBody.size());
d97ef941d521 compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3437
diff changeset
3008 }
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3009 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3010
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3011
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3012 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */,
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3013 std::string& answerBody /* out */)
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3014 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
3015 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1
3443
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3016 if (allowChunkedTransfers_)
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3017 {
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3018 MemoryAnswer answer;
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3019 Execute(answer);
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3020 answerHeaders = answer.GetHeaders();
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3021 answer.GetBody().Flatten(answerBody);
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3022 return;
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3023 }
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3024 #endif
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3025
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3026 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3027 // transfers are disabled. This results in higher memory usage
0371b65d5f76 OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3440
diff changeset
3028 // (all chunks from the request body are sent at once)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3029
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
3030 if (chunkedBody_ != NULL)
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3031 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3032 ChunkedBuffer buffer;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3033
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3034 std::string chunk;
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
3035 while (chunkedBody_->ReadNextChunk(chunk))
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3036 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3037 buffer.AddChunk(chunk);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3038 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3039
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3040 std::string body;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3041 buffer.Flatten(body);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3042
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3043 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3044 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3045 else
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3046 {
3413
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3410
diff changeset
3047 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_);
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3048 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3049 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
3050
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3051
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3052 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */,
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3053 Json::Value& answerBody /* out */)
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3054 {
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3055 std::string body;
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3056 Execute(answerHeaders, body);
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3057
4394
f7104e9d044c functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
3058 if (!ReadJson(answerBody, body))
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3059 {
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3060 LogError("Cannot convert HTTP answer body to JSON");
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3061 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3062 }
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3063 }
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3418
diff changeset
3064
3434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3065
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3066 void HttpClient::Execute()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3067 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3068 HttpHeaders answerHeaders;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3069 std::string body;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3070 Execute(answerHeaders, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3071 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3433
diff changeset
3072
3388
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3387
diff changeset
3073 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3074
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3075
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3076
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3077
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3078
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3079 /******************************************************************
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3080 ** CHUNKED HTTP SERVER
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3081 ******************************************************************/
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3082
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3083 namespace Internals
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3084 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3085 void NullRestCallback(OrthancPluginRestOutput* output,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3086 const char* url,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3087 const OrthancPluginHttpRequest* request)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3088 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3089 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3090
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3091 IChunkedRequestReader *NullChunkedRestCallback(const char* url,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3092 const OrthancPluginHttpRequest* request)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3093 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3094 return NULL;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3095 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3096
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3097
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3098 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3099
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3100 OrthancPluginErrorCode ChunkedRequestReaderAddChunk(
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3101 OrthancPluginServerChunkedRequestReader* reader,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3102 const void* data,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3103 uint32_t size)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3104 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3105 try
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3106 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3107 if (reader == NULL)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3108 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3109 return OrthancPluginErrorCode_InternalError;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3110 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3111
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3112 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size);
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3113 return OrthancPluginErrorCode_Success;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3114 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3115 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3116 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3117 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3118 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3119 catch (boost::bad_lexical_cast&)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3120 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3121 return OrthancPluginErrorCode_BadFileFormat;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3122 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3123 catch (...)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3124 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3125 return OrthancPluginErrorCode_Plugin;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3126 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3127 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3128
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3129
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3130 OrthancPluginErrorCode ChunkedRequestReaderExecute(
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3131 OrthancPluginServerChunkedRequestReader* reader,
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3132 OrthancPluginRestOutput* output)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3133 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3134 try
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3135 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3136 if (reader == NULL)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3137 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3138 return OrthancPluginErrorCode_InternalError;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3139 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3140
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3141 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output);
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3142 return OrthancPluginErrorCode_Success;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3143 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3144 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3145 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3146 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3147 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3148 catch (boost::bad_lexical_cast&)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3149 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3150 return OrthancPluginErrorCode_BadFileFormat;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3151 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3152 catch (...)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3153 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3154 return OrthancPluginErrorCode_Plugin;
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3155 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3156 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3157
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3158
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3159 void ChunkedRequestReaderFinalize(
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3160 OrthancPluginServerChunkedRequestReader* reader)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3161 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3162 if (reader != NULL)
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3163 {
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3164 delete reinterpret_cast<IChunkedRequestReader*>(reader);
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3165 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3166 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3167
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3168 #else
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3169
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3170 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3171 const char* url,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3172 const OrthancPluginHttpRequest* request,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3173 RestCallback GetHandler,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3174 ChunkedRestCallback PostHandler,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3175 RestCallback DeleteHandler,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3176 ChunkedRestCallback PutHandler)
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3177 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3178 try
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3179 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3180 std::string allowed;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3181
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3182 if (GetHandler != Internals::NullRestCallback)
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3183 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3184 allowed += "GET";
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3185 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3186
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3187 if (PostHandler != Internals::NullChunkedRestCallback)
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3188 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3189 if (!allowed.empty())
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3190 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3191 allowed += ",";
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3192 }
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3193
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3194 allowed += "POST";
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3195 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3196
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3197 if (DeleteHandler != Internals::NullRestCallback)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3198 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3199 if (!allowed.empty())
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3200 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3201 allowed += ",";
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3202 }
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3203
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3204 allowed += "DELETE";
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3205 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3206
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3207 if (PutHandler != Internals::NullChunkedRestCallback)
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3208 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3209 if (!allowed.empty())
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3210 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3211 allowed += ",";
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3212 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3213
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3214 allowed += "PUT";
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3215 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3216
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3217 switch (request->method)
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3218 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3219 case OrthancPluginHttpMethod_Get:
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3220 if (GetHandler == Internals::NullRestCallback)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3221 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3222 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3223 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3224 else
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3225 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3226 GetHandler(output, url, request);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3227 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3228
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3229 break;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3230
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3231 case OrthancPluginHttpMethod_Post:
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3232 if (PostHandler == Internals::NullChunkedRestCallback)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3233 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3234 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3235 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3236 else
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3237 {
3749
edabdf07ee83 replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3669
diff changeset
3238 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PostHandler(url, request));
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3239 if (reader.get() == NULL)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3240 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3241 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3242 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3243 else
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3244 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3245 reader->AddChunk(request->body, request->bodySize);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3246 reader->Execute(output);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3247 }
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3248 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3249
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3250 break;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3251
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3252 case OrthancPluginHttpMethod_Delete:
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3253 if (DeleteHandler == Internals::NullRestCallback)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3254 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3255 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3256 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3257 else
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3258 {
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3259 DeleteHandler(output, url, request);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3260 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3261
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3262 break;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3263
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3264 case OrthancPluginHttpMethod_Put:
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3265 if (PutHandler == Internals::NullChunkedRestCallback)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3266 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3267 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str());
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3268 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3269 else
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3270 {
3749
edabdf07ee83 replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3669
diff changeset
3271 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PutHandler(url, request));
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3272 if (reader.get() == NULL)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3273 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3274 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3275 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3276 else
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3277 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3278 reader->AddChunk(request->body, request->bodySize);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3279 reader->Execute(output);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3280 }
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3281 }
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3282
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3283 break;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3284
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3285 default:
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3286 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3287 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3288
3433
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3289 return OrthancPluginErrorCode_Success;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3290 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3291 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3292 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3293 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3294 if (HasGlobalContext() &&
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3295 e.HasDetails())
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3296 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3297 // The "false" instructs Orthanc not to log the detailed
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3298 // error message. This is to avoid duplicating the details,
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3299 // because "OrthancException" already does it on construction.
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3300 OrthancPluginSetHttpErrorDetails
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3301 (GetGlobalContext(), output, e.GetDetails(), false);
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3302 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3303 #endif
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3304
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3305 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3306 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3307 catch (boost::bad_lexical_cast&)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3308 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3309 return OrthancPluginErrorCode_BadFileFormat;
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3310 }
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3311 catch (...)
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3312 {
caa526bb65cc fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3426
diff changeset
3313 return OrthancPluginErrorCode_Plugin;
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3314 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3315 }
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3316 #endif
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
3317 }
3664
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3318
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3319
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3320 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3321 OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup(
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3322 OrthancPluginStorageCommitmentFailureReason* target,
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3323 void* rawHandler,
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3324 const char* sopClassUid,
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3325 const char* sopInstanceUid)
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3326 {
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3327 assert(target != NULL &&
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3328 rawHandler != NULL);
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3329
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3330 try
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3331 {
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3332 IStorageCommitmentScpHandler& handler = *reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler);
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3333 *target = handler.Lookup(sopClassUid, sopInstanceUid);
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3334 return OrthancPluginErrorCode_Success;
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3335 }
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3336 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3337 {
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3338 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3339 }
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3340 catch (...)
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3341 {
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3342 return OrthancPluginErrorCode_Plugin;
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3343 }
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3344 }
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3345 #endif
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3346
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3347
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3348 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3349 void IStorageCommitmentScpHandler::Destructor(void* rawHandler)
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3350 {
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3351 assert(rawHandler != NULL);
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3352 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler);
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3353 }
85acfcc15829 sample storage commitment plugin, C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
3354 #endif
3916
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3355
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3356
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3357 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3358 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) :
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3359 toFree_(false),
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3360 instance_(instance)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3361 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3362 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3363 #else
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3364 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) :
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3365 toFree_(false),
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3366 instance_(instance)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3367 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3368 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3369 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3370
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3371
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3372 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3373 DicomInstance::DicomInstance(const void* buffer,
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3374 size_t size) :
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3375 toFree_(true),
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3376 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size))
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3377 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3378 if (instance_ == NULL)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3379 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3380 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3381 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3382 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3383 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3384
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3385
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3386 DicomInstance::~DicomInstance()
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3387 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3388 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3389 if (toFree_ &&
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3390 instance_ != NULL)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3391 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3392 OrthancPluginFreeDicomInstance(
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3393 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_));
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3394 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3395 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3396 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3397
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3398
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3399 std::string DicomInstance::GetRemoteAet() const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3400 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3401 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3402 if (s == NULL)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3403 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3404 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3405 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3406 else
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3407 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3408 return std::string(s);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3409 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3410 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3411
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3412
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3413 void DicomInstance::GetJson(Json::Value& target) const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3414 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3415 OrthancString s;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3416 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_));
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3417 s.ToJson(target);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3418 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3419
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3420
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3421 void DicomInstance::GetSimplifiedJson(Json::Value& target) const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3422 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3423 OrthancString s;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3424 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_));
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3425 s.ToJson(target);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3426 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3427
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3428
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3429 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3430 std::string DicomInstance::GetTransferSyntaxUid() const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3431 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3432 OrthancString s;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3433 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_));
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3434
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3435 std::string result;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3436 s.ToString(result);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3437 return result;
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3438 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3439 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3440
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3441
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3442 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3443 bool DicomInstance::HasPixelData() const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3444 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3445 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3446 if (result < 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3447 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3448 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3449 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3450 else
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3451 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3452 return (result != 0);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3453 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3454 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3455 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3456
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3457
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3458 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3459 void DicomInstance::GetRawFrame(std::string& target,
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3460 unsigned int frameIndex) const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3461 {
3919
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3462 MemoryBuffer buffer;
3916
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3463 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame(
3919
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3464 GetGlobalContext(), *buffer, instance_, frameIndex);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3465
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3466 if (code == OrthancPluginErrorCode_Success)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3467 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3468 buffer.ToString(target);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3469 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3470 else
3916
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3471 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3472 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3473 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3474 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3475 #endif
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3476
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3477
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3478 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3479 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3480 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3481 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame(
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3482 GetGlobalContext(), instance_, frameIndex);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3483
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3484 if (image == NULL)
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3485 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3486 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3487 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3488 else
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3489 {
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3490 return new OrthancImage(image);
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3491 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3492 }
0e3849268a55 new plugin SDK primitives related to OrthancPluginDicomInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
3493 #endif
3919
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3494
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3495
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3496 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3497 void DicomInstance::Serialize(std::string& target) const
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3498 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3499 MemoryBuffer buffer;
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3500 OrthancPluginErrorCode code = OrthancPluginSerializeDicomInstance(
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3501 GetGlobalContext(), *buffer, instance_);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3502
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3503 if (code == OrthancPluginErrorCode_Success)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3504 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3505 buffer.ToString(target);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3506 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3507 else
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3508 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3509 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3510 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3511 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3512 #endif
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3513
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3514
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3515 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3516 DicomInstance* DicomInstance::Transcode(const void* buffer,
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3517 size_t size,
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3518 const std::string& transferSyntax)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3519 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3520 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance(
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3521 GetGlobalContext(), buffer, size, transferSyntax.c_str());
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3522
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3523 if (instance == NULL)
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3524 {
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3525 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3526 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3527 else
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3528 {
3923
2434e98987ba fix for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3921
diff changeset
3529 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance));
3921
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3919
diff changeset
3530 result->toFree_ = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3919
diff changeset
3531 return result.release();
3919
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3532 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3533 }
6f11b3233a06 OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3916
diff changeset
3534 #endif
2047
438f86ee19fc toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3535 }