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