annotate OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 5487:33f8e180edcf

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