Mercurial > hg > orthanc-stone
annotate Applications/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 1620:1151e25d7311
Unregistering emscripten wheel and key events
in the ViewerViewport destructor, to prevent
callbacks being executed after the object has been
deleted.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 02 Nov 2020 17:56:49 +0100 |
parents | 4fb8fdf03314 |
children | 754ef576d945 |
rev | line source |
---|---|
1538
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1538
diff
changeset
|
11 * |
1538
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * General Public License for more details. |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "OrthancPluginCppWrapper.h" |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <boost/algorithm/string/predicate.hpp> |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include <boost/move/unique_ptr.hpp> |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <boost/thread.hpp> |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include <json/reader.h> |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <json/writer.h> |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 namespace OrthancPlugins |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 static OrthancPluginContext* globalContext_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 void SetGlobalContext(OrthancPluginContext* context) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 if (context == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 else if (globalContext_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 globalContext_ = context; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 bool HasGlobalContext() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 return globalContext_ != NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 OrthancPluginContext* GetGlobalContext() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 if (globalContext_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 return globalContext_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 void MemoryBuffer::Check(OrthancPluginErrorCode code) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 if (code != OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 // Prevent using garbage information |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 buffer_.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 buffer_.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 if (code != OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 // Prevent using garbage information |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 buffer_.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 buffer_.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 else if (code == OrthancPluginErrorCode_UnknownResource || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 code == OrthancPluginErrorCode_InexistentItem) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 MemoryBuffer::MemoryBuffer() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 buffer_.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 buffer_.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 MemoryBuffer::MemoryBuffer(const void* buffer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 size_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 uint32_t s = static_cast<uint32_t>(size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 if (static_cast<size_t>(s) != size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 else if (OrthancPluginCreateMemoryBuffer(GetGlobalContext(), &buffer_, s) != |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 memcpy(buffer_.data, buffer, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 void MemoryBuffer::Clear() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 if (buffer_.data != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 buffer_.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 buffer_.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 buffer_.data = other.data; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 buffer_.size = other.size; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 other.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 other.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 void MemoryBuffer::Swap(MemoryBuffer& other) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 std::swap(buffer_.data, other.buffer_.data); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 std::swap(buffer_.size, other.buffer_.size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 OrthancPluginMemoryBuffer MemoryBuffer::Release() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 OrthancPluginMemoryBuffer result = buffer_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 buffer_.data = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 buffer_.size = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 return result; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 void MemoryBuffer::ToString(std::string& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 if (buffer_.size == 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 target.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 void MemoryBuffer::ToJson(Json::Value& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 if (buffer_.data == NULL || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 buffer_.size == 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 const char* tmp = reinterpret_cast<const char*>(buffer_.data); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 Json::Reader reader; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 if (!reader.parse(tmp, tmp + buffer_.size, target)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 LogError("Cannot convert some memory buffer to JSON"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 bool MemoryBuffer::RestApiGet(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 if (applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 bool MemoryBuffer::RestApiGet(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 const std::map<std::string, std::string>& httpHeaders, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 std::vector<const char*> headersKeys; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 std::vector<const char*> headersValues; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 for (std::map<std::string, std::string>::const_iterator |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 it = httpHeaders.begin(); it != httpHeaders.end(); it++) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 headersKeys.push_back(it->first.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 headersValues.push_back(it->second.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 return CheckHttp(OrthancPluginRestApiGet2( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 (headersKeys.empty() ? NULL : &headersKeys[0]), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 bool MemoryBuffer::RestApiPost(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 const void* body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 size_t bodySize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 const char* b = reinterpret_cast<const char*>(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 if (applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 bool MemoryBuffer::RestApiPut(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 const void* body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 size_t bodySize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 const char* b = reinterpret_cast<const char*>(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 if (applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 bool MemoryBuffer::RestApiPost(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 const Json::Value& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 return RestApiPost(uri, writer.write(body), applyPlugins); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 bool MemoryBuffer::RestApiPut(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 const Json::Value& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 return RestApiPut(uri, writer.write(body), applyPlugins); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 void MemoryBuffer::CreateDicom(const Json::Value& tags, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 OrthancPluginCreateDicomFlags flags) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 std::string s = writer.write(tags); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 void MemoryBuffer::CreateDicom(const Json::Value& tags, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 const OrthancImage& pixelData, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 OrthancPluginCreateDicomFlags flags) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 std::string s = writer.write(tags); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 void MemoryBuffer::ReadFile(const std::string& path) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 void OrthancString::Assign(char* str) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 if (str != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 str_ = str; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 void OrthancString::Clear() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 if (str_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 OrthancPluginFreeString(GetGlobalContext(), str_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 str_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 void OrthancString::ToString(std::string& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 if (str_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 target.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 target.assign(str_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 void OrthancString::ToJson(Json::Value& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 if (str_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 LogError("Cannot convert an empty memory buffer to JSON"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 Json::Reader reader; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 if (!reader.parse(str_, target)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 LogError("Cannot convert some memory buffer to JSON"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 void MemoryBuffer::DicomToJson(Json::Value& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 OrthancPluginDicomToJsonFormat format, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 OrthancPluginDicomToJsonFlags flags, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 uint32_t maxStringLength) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 OrthancString str; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 str.Assign(OrthancPluginDicomBufferToJson |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 str.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
412 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
413 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
414 bool MemoryBuffer::HttpGet(const std::string& url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 const std::string& username, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 const std::string& password) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 username.empty() ? NULL : username.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 password.empty() ? NULL : password.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
423 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 bool MemoryBuffer::HttpPost(const std::string& url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 const std::string& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 const std::string& username, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 const std::string& password) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
432 body.c_str(), body.size(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 username.empty() ? NULL : username.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 password.empty() ? NULL : password.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 bool MemoryBuffer::HttpPut(const std::string& url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 const std::string& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 const std::string& username, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 const std::string& password) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 body.empty() ? NULL : body.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
446 body.size(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
447 username.empty() ? NULL : username.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
448 password.empty() ? NULL : password.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
449 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 void MemoryBuffer::GetDicomInstance(const std::string& instanceId) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
453 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
454 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
456 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
457 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
459 bool HttpDelete(const std::string& url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
460 const std::string& username, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
461 const std::string& password) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
462 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
463 OrthancPluginErrorCode error = OrthancPluginHttpDelete |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
464 (GetGlobalContext(), url.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
465 username.empty() ? NULL : username.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
466 password.empty() ? NULL : password.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
467 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
468 if (error == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
469 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
470 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
471 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 else if (error == OrthancPluginErrorCode_UnknownResource || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 error == OrthancPluginErrorCode_InexistentItem) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
474 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
476 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
477 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
478 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
480 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 void LogError(const std::string& message) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
485 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
486 if (HasGlobalContext()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 OrthancPluginLogError(GetGlobalContext(), message.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
490 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
491 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 void LogWarning(const std::string& message) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
495 if (HasGlobalContext()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
497 OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 void LogInfo(const std::string& message) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 if (HasGlobalContext()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
506 OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
508 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
509 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
510 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
511 void OrthancConfiguration::LoadConfiguration() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
512 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
513 OrthancString str; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
514 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
515 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
516 if (str.GetContent() == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
517 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
518 LogError("Cannot access the Orthanc configuration"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
519 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
520 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
521 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
522 str.ToJson(configuration_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
523 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
524 if (configuration_.type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
525 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
526 LogError("Unable to read the Orthanc configuration"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
527 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
528 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
529 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
530 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
531 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
532 OrthancConfiguration::OrthancConfiguration() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
533 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
534 LoadConfiguration(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
535 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
536 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
537 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
538 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
539 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
540 if (loadConfiguration) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
541 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
542 LoadConfiguration(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
543 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
544 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
545 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
546 configuration_ = Json::objectValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
548 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
549 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
550 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
551 std::string OrthancConfiguration::GetPath(const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
552 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
553 if (path_.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
554 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
555 return key; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
556 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
557 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
558 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
559 return path_ + "." + key; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
560 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
561 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
562 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
563 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
564 bool OrthancConfiguration::IsSection(const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
565 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
566 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
567 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
568 return (configuration_.isMember(key) && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
569 configuration_[key].type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
570 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
571 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
572 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
573 void OrthancConfiguration::GetSection(OrthancConfiguration& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
574 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
575 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
576 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
577 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
578 target.path_ = GetPath(key); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
579 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
580 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
581 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
582 target.configuration_ = Json::objectValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
583 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
584 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
585 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
586 if (configuration_[key].type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
587 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
588 LogError("The configuration section \"" + target.path_ + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
589 "\" is not an associative array as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
590 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
591 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
592 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
593 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
594 target.configuration_ = configuration_[key]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
595 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
596 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
597 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
598 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
599 bool OrthancConfiguration::LookupStringValue(std::string& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
600 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
601 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
602 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
603 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
604 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
605 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
606 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
607 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
608 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
609 if (configuration_[key].type() != Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
610 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
611 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
612 "\" is not a string as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
613 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
614 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
615 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
616 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
617 target = configuration_[key].asString(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
618 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
619 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
620 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
621 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
622 bool OrthancConfiguration::LookupIntegerValue(int& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
623 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
624 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
625 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
626 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
627 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
628 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
629 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
630 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
631 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
632 switch (configuration_[key].type()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
633 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
634 case Json::intValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
635 target = configuration_[key].asInt(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
636 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
637 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
638 case Json::uintValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
639 target = configuration_[key].asUInt(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
640 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
641 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
642 default: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
643 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
644 "\" is not an integer as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
645 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
646 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
647 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
648 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
649 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
650 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
651 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
652 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
653 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
654 int tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
655 if (!LookupIntegerValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
656 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
657 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
658 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
659 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
660 if (tmp < 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
661 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
662 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
663 "\" is not a positive integer as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
664 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
665 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
666 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
667 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
668 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
669 target = static_cast<unsigned int>(tmp); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
670 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
671 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
672 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
673 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
674 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
675 bool OrthancConfiguration::LookupBooleanValue(bool& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
676 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
677 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
678 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
679 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
680 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
681 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
682 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
683 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
684 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
685 if (configuration_[key].type() != Json::booleanValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
686 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
687 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
688 "\" is not a Boolean as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
689 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
690 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
691 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
692 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
693 target = configuration_[key].asBool(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
694 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
695 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
696 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
697 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
698 bool OrthancConfiguration::LookupFloatValue(float& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
699 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
700 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
701 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
702 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
703 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
704 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
705 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
706 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
707 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
708 switch (configuration_[key].type()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
709 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
710 case Json::realValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
711 target = configuration_[key].asFloat(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
712 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
713 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
714 case Json::intValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
715 target = static_cast<float>(configuration_[key].asInt()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
716 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
717 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
718 case Json::uintValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
719 target = static_cast<float>(configuration_[key].asUInt()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
720 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
721 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
722 default: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
723 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
724 "\" is not an integer as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
725 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
726 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
727 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
728 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
729 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
730 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
731 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
732 const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
733 bool allowSingleString) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
734 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
735 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
736 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
737 target.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
738 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
739 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
740 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
741 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
742 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
743 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
744 switch (configuration_[key].type()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
745 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
746 case Json::arrayValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
747 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
748 bool ok = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
749 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
750 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
751 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
752 if (configuration_[key][i].type() == Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
753 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
754 target.push_back(configuration_[key][i].asString()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
755 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
756 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
757 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
758 ok = false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
759 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
760 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
761 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
762 if (ok) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
763 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
764 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
765 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
766 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
767 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
768 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
769 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
770 case Json::stringValue: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
771 if (allowSingleString) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
772 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
773 target.push_back(configuration_[key].asString()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
774 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
775 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
776 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
777 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
778 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
779 default: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
780 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
781 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
782 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
783 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
784 "\" is not a list of strings as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
785 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
786 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
787 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
788 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
789 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
790 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
791 const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
792 bool allowSingleString) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
793 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
794 std::list<std::string> lst; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
795 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
796 if (LookupListOfStrings(lst, key, allowSingleString)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
797 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
798 target.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
799 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
800 for (std::list<std::string>::const_iterator |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
801 it = lst.begin(); it != lst.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
802 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
803 target.insert(*it); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
804 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
805 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
806 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
807 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
808 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
809 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
810 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
811 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
812 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
813 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
814 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
815 std::string OrthancConfiguration::GetStringValue(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
816 const std::string& defaultValue) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
817 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
818 std::string tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
819 if (LookupStringValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
820 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
821 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
822 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
823 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
824 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
825 return defaultValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
826 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
827 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
828 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
829 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
830 int OrthancConfiguration::GetIntegerValue(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
831 int defaultValue) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
832 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
833 int tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
834 if (LookupIntegerValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
835 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
836 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
837 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
838 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
839 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
840 return defaultValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
841 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
842 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
843 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
844 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
845 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
846 unsigned int defaultValue) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
847 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
848 unsigned int tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
849 if (LookupUnsignedIntegerValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
850 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
851 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
852 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
853 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
854 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
855 return defaultValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
856 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
857 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
858 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
859 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
860 bool OrthancConfiguration::GetBooleanValue(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
861 bool defaultValue) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
862 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
863 bool tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
864 if (LookupBooleanValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
865 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
866 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
867 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
868 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
869 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
870 return defaultValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
871 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
872 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
873 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
874 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
875 float OrthancConfiguration::GetFloatValue(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
876 float defaultValue) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
877 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
878 float tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
879 if (LookupFloatValue(tmp, key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
880 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
881 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
882 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
883 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
884 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
885 return defaultValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
886 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
887 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
888 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
889 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
890 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
891 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
892 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
893 assert(configuration_.type() == Json::objectValue); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
894 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
895 target.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
896 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
897 if (!configuration_.isMember(key)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
898 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
899 return; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
900 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
901 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
902 if (configuration_[key].type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
903 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
904 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
905 "\" is not a string as expected"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
906 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
907 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
908 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
909 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
910 Json::Value::Members members = configuration_[key].getMemberNames(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
911 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
912 for (size_t i = 0; i < members.size(); i++) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
913 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
914 const Json::Value& value = configuration_[key][members[i]]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
915 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
916 if (value.type() == Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
917 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
918 target[members[i]] = value.asString(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
919 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
920 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
921 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
922 LogError("The configuration option \"" + GetPath(key) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
923 "\" is not a dictionary mapping strings to strings"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
924 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
925 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
926 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
927 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
928 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
929 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
930 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
931 void OrthancImage::Clear() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
932 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
933 if (image_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
934 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
935 OrthancPluginFreeImage(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
936 image_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
937 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
938 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
939 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
940 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
941 void OrthancImage::CheckImageAvailable() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
942 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
943 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
944 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
945 LogError("Trying to access a NULL image"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
946 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
947 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
948 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
949 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
950 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
951 OrthancImage::OrthancImage() : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
952 image_(NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
953 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
954 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
955 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
956 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
957 OrthancImage::OrthancImage(OrthancPluginImage* image) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
958 image_(image) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
959 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
960 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
961 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
962 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
963 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
964 uint32_t width, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
965 uint32_t height) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
966 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
967 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
968 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
969 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
970 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
971 LogError("Cannot create an image"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
972 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
973 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
974 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
975 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
976 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
977 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
978 uint32_t width, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
979 uint32_t height, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
980 uint32_t pitch, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
981 void* buffer) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
982 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
983 image_ = OrthancPluginCreateImageAccessor |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
984 (GetGlobalContext(), format, width, height, pitch, buffer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
985 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
986 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
987 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
988 LogError("Cannot create an image accessor"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
989 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
990 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
991 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
992 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
993 void OrthancImage::UncompressPngImage(const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
994 size_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
995 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
996 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
997 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
998 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
999 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1000 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1001 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1002 LogError("Cannot uncompress a PNG image"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1003 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1004 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1005 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1006 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1007 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1008 void OrthancImage::UncompressJpegImage(const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1009 size_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1010 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1011 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1012 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1013 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1014 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1015 LogError("Cannot uncompress a JPEG image"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1016 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1017 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1018 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1019 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1020 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1021 void OrthancImage::DecodeDicomImage(const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1022 size_t size, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1023 unsigned int frame) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1024 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1025 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1026 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1027 if (image_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1028 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1029 LogError("Cannot uncompress a DICOM image"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1030 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1031 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1032 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1033 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1034 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1035 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1036 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1037 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1038 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1039 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1040 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1041 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1042 unsigned int OrthancImage::GetWidth() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1043 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1044 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1045 return OrthancPluginGetImageWidth(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1046 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1047 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1048 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1049 unsigned int OrthancImage::GetHeight() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1050 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1051 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1052 return OrthancPluginGetImageHeight(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1053 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1054 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1055 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1056 unsigned int OrthancImage::GetPitch() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1057 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1058 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1059 return OrthancPluginGetImagePitch(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1060 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1061 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1062 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1063 void* OrthancImage::GetBuffer() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1064 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1065 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1066 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1067 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1068 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1069 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1070 void OrthancImage::CompressPngImage(MemoryBuffer& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1071 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1072 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1073 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1074 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1075 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1076 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1077 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1078 target.Swap(answer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1079 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1080 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1081 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1082 void OrthancImage::CompressJpegImage(MemoryBuffer& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1083 uint8_t quality) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1084 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1085 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1086 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1087 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1088 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1089 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1090 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1091 target.Swap(answer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1092 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1093 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1094 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1095 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1096 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1097 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1098 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1099 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1100 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1101 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1102 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1103 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1104 uint8_t quality) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1105 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1106 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1107 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1108 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1109 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1110 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1111 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1112 OrthancPluginImage* OrthancImage::Release() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1113 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1114 CheckImageAvailable(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1115 OrthancPluginImage* tmp = image_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1116 image_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1117 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1118 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1119 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1120 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1121 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1122 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1123 matcher_(NULL), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1124 worklist_(worklist) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1125 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1126 if (worklist_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1127 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1128 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1129 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1130 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1131 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1132 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1133 void FindMatcher::SetupDicom(const void* query, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1134 uint32_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1135 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1136 worklist_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1137 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1138 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1139 if (matcher_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1140 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1141 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1142 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1143 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1144 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1145 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1146 FindMatcher::~FindMatcher() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1147 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1148 // The "worklist_" field |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1149 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1150 if (matcher_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1151 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1152 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1153 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1154 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1155 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1156 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1157 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1158 bool FindMatcher::IsMatch(const void* dicom, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1159 uint32_t size) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1160 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1161 int32_t result; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1162 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1163 if (matcher_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1164 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1165 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1166 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1167 else if (worklist_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1168 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1169 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1170 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1171 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1172 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1173 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1174 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1175 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1176 if (result == 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1177 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1178 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1179 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1180 else if (result == 1) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1181 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1182 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1183 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1184 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1185 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1186 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1187 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1188 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1189 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1190 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1191 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1192 void AnswerJson(const Json::Value& value, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1193 OrthancPluginRestOutput* output |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1194 ) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1195 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1196 Json::StyledWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1197 std::string bodyString = writer.write(value); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1198 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1199 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1200 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1201 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1202 void AnswerString(const std::string& answer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1203 const char* mimeType, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1204 OrthancPluginRestOutput* output |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1205 ) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1206 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1207 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1208 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1209 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1210 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1211 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1212 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1213 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1214 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1215 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1216 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1217 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1218 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1219 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1220 bool RestApiGetString(std::string& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1221 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1222 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1223 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1224 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1225 if (!answer.RestApiGet(uri, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1226 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1227 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1228 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1229 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1230 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1231 answer.ToString(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1232 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1233 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1234 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1235 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1236 bool RestApiGetString(std::string& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1237 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1238 const std::map<std::string, std::string>& httpHeaders, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1239 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1240 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1241 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1242 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1243 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1244 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1245 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1246 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1247 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1248 answer.ToString(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1249 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1250 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1251 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1252 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1253 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1254 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1255 bool RestApiGet(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1256 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1257 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1258 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1259 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1260 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1261 if (!answer.RestApiGet(uri, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1262 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1263 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1264 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1265 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1266 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1267 if (!answer.IsEmpty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1268 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1269 answer.ToJson(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1270 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1271 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1272 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1273 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1274 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1275 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1276 bool RestApiPost(std::string& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1277 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1278 const void* body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1279 size_t bodySize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1280 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1281 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1282 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1283 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1284 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1285 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1286 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1287 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1288 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1289 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1290 if (!answer.IsEmpty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1291 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1292 result.assign(answer.GetData(), answer.GetSize()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1293 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1294 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1295 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1296 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1297 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1298 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1299 bool RestApiPost(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1300 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1301 const void* body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1302 size_t bodySize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1303 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1304 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1305 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1306 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1307 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1308 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1309 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1310 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1311 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1312 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1313 if (!answer.IsEmpty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1314 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1315 answer.ToJson(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1316 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1317 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1318 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1319 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1320 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1321 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1322 bool RestApiPost(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1323 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1324 const Json::Value& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1325 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1326 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1327 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1328 return RestApiPost(result, uri, writer.write(body), applyPlugins); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1329 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1330 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1331 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1332 bool RestApiPut(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1333 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1334 const void* body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1335 size_t bodySize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1336 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1337 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1338 MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1339 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1340 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1341 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1342 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1343 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1344 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1345 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1346 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1347 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1348 answer.ToJson(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1349 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1350 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1351 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1352 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1353 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1354 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1355 bool RestApiPut(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1356 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1357 const Json::Value& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1358 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1359 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1360 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1361 return RestApiPut(result, uri, writer.write(body), applyPlugins); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1362 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1363 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1364 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1365 bool RestApiDelete(const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1366 bool applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1367 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1368 OrthancPluginErrorCode error; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1369 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1370 if (applyPlugins) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1371 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1372 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1373 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1374 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1375 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1376 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1377 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1378 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1379 if (error == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1380 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1381 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1382 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1383 else if (error == OrthancPluginErrorCode_UnknownResource || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1384 error == OrthancPluginErrorCode_InexistentItem) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1385 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1386 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1387 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1388 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1389 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1390 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1391 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1392 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1393 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1394 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1395 void ReportMinimalOrthancVersion(unsigned int major, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1396 unsigned int minor, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1397 unsigned int revision) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1398 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1399 LogError("Your version of the Orthanc core (" + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1400 std::string(GetGlobalContext()->orthancVersion) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1401 ") is too old to run this plugin (version " + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1402 boost::lexical_cast<std::string>(major) + "." + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1403 boost::lexical_cast<std::string>(minor) + "." + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1404 boost::lexical_cast<std::string>(revision) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1405 " is required)"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1406 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1407 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1408 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1409 bool CheckMinimalOrthancVersion(unsigned int major, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1410 unsigned int minor, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1411 unsigned int revision) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1412 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1413 if (!HasGlobalContext()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1414 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1415 LogError("Bad Orthanc context in the plugin"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1416 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1417 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1418 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1419 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline")) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1420 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1421 // Assume compatibility with the mainline |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1422 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1423 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1424 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1425 // Parse the version of the Orthanc core |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1426 int aa, bb, cc; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1427 if ( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1428 #ifdef _MSC_VER |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1429 sscanf_s |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1430 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1431 sscanf |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1432 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1433 (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1434 aa < 0 || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1435 bb < 0 || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1436 cc < 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1437 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1438 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1439 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1440 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1441 unsigned int a = static_cast<unsigned int>(aa); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1442 unsigned int b = static_cast<unsigned int>(bb); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1443 unsigned int c = static_cast<unsigned int>(cc); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1444 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1445 // Check the major version number |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1446 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1447 if (a > major) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1448 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1449 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1450 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1451 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1452 if (a < major) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1453 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1454 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1455 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1456 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1457 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1458 // Check the minor version number |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1459 assert(a == major); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1460 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1461 if (b > minor) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1462 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1463 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1464 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1465 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1466 if (b < minor) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1467 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1468 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1469 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1470 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1471 // Check the patch level version number |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1472 assert(a == major && b == minor); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1473 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1474 if (c >= revision) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1475 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1476 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1477 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1478 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1479 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1480 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1481 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1482 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1483 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1484 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1485 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1486 const char* AutodetectMimeType(const std::string& path) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1487 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1488 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1489 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1490 if (mime == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1491 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1492 // Should never happen, just for safety |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1493 return "application/octet-stream"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1494 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1495 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1496 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1497 return mime; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1498 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1499 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1500 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1501 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1502 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1503 #if HAS_ORTHANC_PLUGIN_PEERS == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1504 size_t OrthancPeers::GetPeerIndex(const std::string& name) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1505 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1506 size_t index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1507 if (LookupName(index, name)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1508 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1509 return index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1510 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1511 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1512 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1513 LogError("Inexistent peer: " + name); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1514 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1515 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1516 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1517 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1518 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1519 OrthancPeers::OrthancPeers() : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1520 peers_(NULL), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1521 timeout_(0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1522 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1523 peers_ = OrthancPluginGetPeers(GetGlobalContext()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1524 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1525 if (peers_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1526 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1527 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1528 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1529 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1530 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1531 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1532 for (uint32_t i = 0; i < count; i++) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1533 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1534 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1535 if (name == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1536 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1537 OrthancPluginFreePeers(GetGlobalContext(), peers_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1538 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1539 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1540 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1541 index_[name] = i; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1542 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1543 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1544 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1545 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1546 OrthancPeers::~OrthancPeers() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1547 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1548 if (peers_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1549 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1550 OrthancPluginFreePeers(GetGlobalContext(), peers_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1551 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1552 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1553 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1554 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1555 bool OrthancPeers::LookupName(size_t& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1556 const std::string& name) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1557 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1558 Index::const_iterator found = index_.find(name); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1559 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1560 if (found == index_.end()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1561 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1562 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1563 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1564 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1565 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1566 target = found->second; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1567 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1568 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1569 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1570 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1571 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1572 std::string OrthancPeers::GetPeerName(size_t index) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1573 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1574 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1575 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1576 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1577 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1578 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1579 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1580 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1581 if (s == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1582 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1583 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1584 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1585 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1586 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1587 return s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1588 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1589 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1590 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1591 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1592 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1593 std::string OrthancPeers::GetPeerUrl(size_t index) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1594 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1595 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1596 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1597 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1598 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1599 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1600 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1601 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1602 if (s == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1603 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1604 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1605 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1606 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1607 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1608 return s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1609 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1610 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1611 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1612 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1613 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1614 std::string OrthancPeers::GetPeerUrl(const std::string& name) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1615 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1616 return GetPeerUrl(GetPeerIndex(name)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1617 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1618 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1619 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1620 bool OrthancPeers::LookupUserProperty(std::string& value, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1621 size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1622 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1623 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1624 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1625 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1626 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1627 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1628 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1629 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1630 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1631 if (s == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1632 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1633 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1634 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1635 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1636 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1637 value.assign(s); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1638 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1639 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1640 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1641 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1642 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1643 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1644 bool OrthancPeers::LookupUserProperty(std::string& value, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1645 const std::string& peer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1646 const std::string& key) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1647 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1648 return LookupUserProperty(value, GetPeerIndex(peer), key); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1649 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1650 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1651 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1652 bool OrthancPeers::DoGet(MemoryBuffer& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1653 size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1654 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1655 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1656 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1657 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1658 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1659 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1660 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1661 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1662 uint16_t status; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1663 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1664 (GetGlobalContext(), *answer, NULL, &status, peers_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1665 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1666 0, NULL, NULL, NULL, 0, timeout_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1667 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1668 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1669 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1670 target.Swap(answer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1671 return (status == 200); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1672 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1673 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1674 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1675 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1676 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1677 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1678 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1679 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1680 bool OrthancPeers::DoGet(MemoryBuffer& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1681 const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1682 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1683 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1684 size_t index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1685 return (LookupName(index, name) && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1686 DoGet(target, index, uri)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1687 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1688 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1689 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1690 bool OrthancPeers::DoGet(Json::Value& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1691 size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1692 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1693 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1694 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1695 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1696 if (DoGet(buffer, index, uri)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1697 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1698 buffer.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1699 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1700 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1701 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1702 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1703 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1704 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1705 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1706 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1707 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1708 bool OrthancPeers::DoGet(Json::Value& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1709 const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1710 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1711 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1712 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1713 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1714 if (DoGet(buffer, name, uri)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1715 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1716 buffer.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1717 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1718 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1719 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1720 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1721 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1722 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1723 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1724 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1725 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1726 bool OrthancPeers::DoPost(MemoryBuffer& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1727 const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1728 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1729 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1730 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1731 size_t index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1732 return (LookupName(index, name) && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1733 DoPost(target, index, uri, body)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1734 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1735 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1736 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1737 bool OrthancPeers::DoPost(Json::Value& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1738 size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1739 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1740 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1741 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1742 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1743 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1744 if (DoPost(buffer, index, uri, body)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1745 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1746 buffer.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1747 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1748 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1749 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1750 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1751 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1752 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1753 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1754 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1755 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1756 bool OrthancPeers::DoPost(Json::Value& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1757 const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1758 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1759 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1760 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1761 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1762 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1763 if (DoPost(buffer, name, uri, body)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1764 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1765 buffer.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1766 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1767 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1768 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1769 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1770 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1771 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1772 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1773 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1774 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1775 bool OrthancPeers::DoPost(MemoryBuffer& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1776 size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1777 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1778 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1779 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1780 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1781 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1782 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1783 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1784 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1785 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1786 uint16_t status; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1787 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1788 (GetGlobalContext(), *answer, NULL, &status, peers_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1789 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1790 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1791 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1792 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1793 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1794 target.Swap(answer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1795 return (status == 200); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1796 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1797 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1798 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1799 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1800 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1801 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1802 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1803 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1804 bool OrthancPeers::DoPut(size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1805 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1806 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1807 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1808 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1809 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1810 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1811 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1812 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1813 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1814 uint16_t status; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1815 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1816 (GetGlobalContext(), *answer, NULL, &status, peers_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1817 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1818 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1819 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1820 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1821 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1822 return (status == 200); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1823 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1824 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1825 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1826 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1827 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1828 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1829 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1830 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1831 bool OrthancPeers::DoPut(const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1832 const std::string& uri, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1833 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1834 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1835 size_t index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1836 return (LookupName(index, name) && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1837 DoPut(index, uri, body)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1838 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1839 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1840 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1841 bool OrthancPeers::DoDelete(size_t index, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1842 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1843 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1844 if (index >= index_.size()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1845 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1846 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1847 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1848 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1849 OrthancPlugins::MemoryBuffer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1850 uint16_t status; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1851 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1852 (GetGlobalContext(), *answer, NULL, &status, peers_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1853 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1854 0, NULL, NULL, NULL, 0, timeout_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1855 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1856 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1857 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1858 return (status == 200); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1859 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1860 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1861 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1862 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1863 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1864 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1865 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1866 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1867 bool OrthancPeers::DoDelete(const std::string& name, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1868 const std::string& uri) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1869 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1870 size_t index; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1871 return (LookupName(index, name) && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1872 DoDelete(index, uri)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1873 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1874 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1875 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1876 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1877 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1878 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1879 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1880 /****************************************************************** |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1881 ** JOBS |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1882 ******************************************************************/ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1883 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1884 #if HAS_ORTHANC_PLUGIN_JOB == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1885 void OrthancJob::CallbackFinalize(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1886 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1887 if (job != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1888 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1889 delete reinterpret_cast<OrthancJob*>(job); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1890 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1891 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1892 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1893 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1894 float OrthancJob::CallbackGetProgress(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1895 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1896 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1897 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1898 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1899 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1900 return reinterpret_cast<OrthancJob*>(job)->progress_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1901 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1902 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1903 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1904 return 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1905 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1906 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1907 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1908 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1909 const char* OrthancJob::CallbackGetContent(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1910 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1911 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1912 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1913 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1914 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1915 return reinterpret_cast<OrthancJob*>(job)->content_.c_str(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1916 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1917 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1918 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1919 return 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1920 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1921 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1922 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1923 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1924 const char* OrthancJob::CallbackGetSerialized(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1925 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1926 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1927 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1928 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1929 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1930 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1931 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1932 if (tmp.hasSerialized_) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1933 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1934 return tmp.serialized_.c_str(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1935 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1936 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1937 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1938 return NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1939 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1940 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1941 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1942 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1943 return 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1944 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1945 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1946 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1947 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1948 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1949 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1950 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1951 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1952 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1953 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1954 return reinterpret_cast<OrthancJob*>(job)->Step(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1955 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1956 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1957 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1958 return OrthancPluginJobStepStatus_Failure; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1959 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1960 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1961 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1962 return OrthancPluginJobStepStatus_Failure; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1963 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1964 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1965 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1966 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1967 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1968 OrthancPluginJobStopReason reason) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1969 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1970 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1971 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1972 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1973 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1974 reinterpret_cast<OrthancJob*>(job)->Stop(reason); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1975 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1976 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1977 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1978 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1979 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1980 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1981 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1982 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1983 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1984 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1985 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1986 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1987 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1988 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1989 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1990 assert(job != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1991 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1992 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1993 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1994 reinterpret_cast<OrthancJob*>(job)->Reset(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1995 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1996 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1997 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1998 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1999 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2000 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2001 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2002 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2003 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2004 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2005 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2006 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2007 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2008 void OrthancJob::ClearContent() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2009 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2010 Json::Value empty = Json::objectValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2011 UpdateContent(empty); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2012 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2013 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2014 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2015 void OrthancJob::UpdateContent(const Json::Value& content) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2016 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2017 if (content.type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2018 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2019 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2020 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2021 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2022 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2023 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2024 content_ = writer.write(content); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2025 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2026 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2027 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2028 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2029 void OrthancJob::ClearSerialized() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2030 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2031 hasSerialized_ = false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2032 serialized_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2033 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2034 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2035 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2036 void OrthancJob::UpdateSerialized(const Json::Value& serialized) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2037 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2038 if (serialized.type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2039 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2040 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2041 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2042 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2043 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2044 Json::FastWriter writer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2045 serialized_ = writer.write(serialized); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2046 hasSerialized_ = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2047 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2048 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2049 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2050 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2051 void OrthancJob::UpdateProgress(float progress) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2052 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2053 if (progress < 0 || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2054 progress > 1) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2055 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2056 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2057 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2058 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2059 progress_ = progress; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2060 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2061 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2062 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2063 OrthancJob::OrthancJob(const std::string& jobType) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2064 jobType_(jobType), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2065 progress_(0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2066 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2067 ClearContent(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2068 ClearSerialized(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2069 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2070 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2071 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2072 OrthancPluginJob* OrthancJob::Create(OrthancJob* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2073 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2074 if (job == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2075 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2076 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2077 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2078 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2079 OrthancPluginJob* orthanc = OrthancPluginCreateJob( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2080 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2081 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2082 CallbackStep, CallbackStop, CallbackReset); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2083 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2084 if (orthanc == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2085 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2086 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2087 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2088 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2089 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2090 return orthanc; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2091 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2092 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2093 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2094 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2095 std::string OrthancJob::Submit(OrthancJob* job, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2096 int priority) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2097 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2098 if (job == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2099 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2100 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2101 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2102 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2103 OrthancPluginJob* orthanc = Create(job); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2104 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2105 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2106 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2107 if (id == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2108 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2109 LogError("Plugin cannot submit job"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2110 OrthancPluginFreeJob(GetGlobalContext(), orthanc); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2111 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2112 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2113 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2114 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2115 std::string tmp(id); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2116 tmp.assign(id); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2117 OrthancPluginFreeString(GetGlobalContext(), id); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2118 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2119 return tmp; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2120 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2121 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2122 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2123 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2124 void OrthancJob::SubmitAndWait(Json::Value& result, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2125 OrthancJob* job /* takes ownership */, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2126 int priority) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2127 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2128 std::string id = Submit(job, priority); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2129 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2130 for (;;) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2131 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2132 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2133 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2134 Json::Value status; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2135 if (!RestApiGet(status, "/jobs/" + id, false) || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2136 !status.isMember("State") || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2137 status["State"].type() != Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2138 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2139 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2140 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2141 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2142 const std::string state = status["State"].asString(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2143 if (state == "Success") |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2144 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2145 if (status.isMember("Content")) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2146 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2147 result = status["Content"]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2148 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2149 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2150 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2151 result = Json::objectValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2152 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2153 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2154 return; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2155 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2156 else if (state == "Running") |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2157 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2158 continue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2159 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2160 else if (!status.isMember("ErrorCode") || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2161 status["ErrorCode"].type() != Json::intValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2162 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2163 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2164 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2165 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2166 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2167 if (!status.isMember("ErrorDescription") || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2168 status["ErrorDescription"].type() != Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2169 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2170 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2171 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2172 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2173 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2174 #if HAS_ORTHANC_EXCEPTION == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2175 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2176 status["ErrorDescription"].asString()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2177 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2178 LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2179 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2180 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2181 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2182 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2183 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2184 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2185 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2186 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2187 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2188 const Json::Value& body, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2189 OrthancJob* job) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2190 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2191 static const char* KEY_SYNCHRONOUS = "Synchronous"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2192 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2193 static const char* KEY_PRIORITY = "Priority"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2194 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2195 boost::movelib::unique_ptr<OrthancJob> protection(job); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2196 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2197 if (body.type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2198 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2199 #if HAS_ORTHANC_EXCEPTION == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2200 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2201 "Expected a JSON object in the body"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2202 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2203 LogError("Expected a JSON object in the body"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2204 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2205 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2206 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2207 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2208 bool synchronous = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2209 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2210 if (body.isMember(KEY_SYNCHRONOUS)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2211 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2212 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2213 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2214 #if HAS_ORTHANC_EXCEPTION == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2215 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2216 "Option \"" + std::string(KEY_SYNCHRONOUS) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2217 "\" must be Boolean"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2218 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2219 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2220 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2221 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2222 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2223 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2224 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2225 synchronous = body[KEY_SYNCHRONOUS].asBool(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2226 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2227 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2228 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2229 if (body.isMember(KEY_ASYNCHRONOUS)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2230 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2231 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2232 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2233 #if HAS_ORTHANC_EXCEPTION == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2234 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2235 "Option \"" + std::string(KEY_ASYNCHRONOUS) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2236 "\" must be Boolean"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2237 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2238 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2239 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2240 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2241 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2242 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2243 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2244 synchronous = !body[KEY_ASYNCHRONOUS].asBool(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2245 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2246 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2247 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2248 int priority = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2249 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2250 if (body.isMember(KEY_PRIORITY)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2251 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2252 if (body[KEY_PRIORITY].type() != Json::booleanValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2253 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2254 #if HAS_ORTHANC_EXCEPTION == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2255 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2256 "Option \"" + std::string(KEY_PRIORITY) + |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2257 "\" must be an integer"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2258 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2259 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2260 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2261 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2262 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2263 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2264 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2265 priority = !body[KEY_PRIORITY].asInt(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2266 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2267 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2268 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2269 Json::Value result; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2270 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2271 if (synchronous) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2272 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2273 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2274 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2275 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2276 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2277 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2278 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2279 result = Json::objectValue; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2280 result["ID"] = id; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2281 result["Path"] = "/jobs/" + id; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2282 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2283 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2284 std::string s = result.toStyledString(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2285 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2286 s.size(), "application/json"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2287 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2288 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2289 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2290 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2291 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2292 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2293 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2294 /****************************************************************** |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2295 ** METRICS |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2296 ******************************************************************/ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2297 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2298 #if HAS_ORTHANC_PLUGIN_METRICS == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2299 MetricsTimer::MetricsTimer(const char* name) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2300 name_(name) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2301 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2302 start_ = boost::posix_time::microsec_clock::universal_time(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2303 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2304 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2305 MetricsTimer::~MetricsTimer() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2306 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2307 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2308 const boost::posix_time::time_duration diff = stop - start_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2309 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2310 OrthancPluginMetricsType_Timer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2311 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2312 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2313 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2314 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2315 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2316 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2317 /****************************************************************** |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2318 ** HTTP CLIENT |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2319 ******************************************************************/ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2320 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2321 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2322 class HttpClient::RequestBodyWrapper : public boost::noncopyable |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2323 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2324 private: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2325 static RequestBodyWrapper& GetObject(void* body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2326 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2327 assert(body != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2328 return *reinterpret_cast<RequestBodyWrapper*>(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2329 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2330 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2331 IRequestBody& body_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2332 bool done_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2333 std::string chunk_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2334 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2335 public: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2336 RequestBodyWrapper(IRequestBody& body) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2337 body_(body), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2338 done_(false) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2339 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2340 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2341 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2342 static uint8_t IsDone(void* body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2343 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2344 return GetObject(body).done_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2345 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2346 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2347 static const void* GetChunkData(void* body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2348 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2349 return GetObject(body).chunk_.c_str(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2350 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2351 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2352 static uint32_t GetChunkSize(void* body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2353 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2354 return static_cast<uint32_t>(GetObject(body).chunk_.size()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2355 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2356 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2357 static OrthancPluginErrorCode Next(void* body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2358 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2359 RequestBodyWrapper& that = GetObject(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2360 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2361 if (that.done_) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2362 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2363 return OrthancPluginErrorCode_BadSequenceOfCalls; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2364 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2365 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2366 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2367 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2368 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2369 that.done_ = !that.body_.ReadNextChunk(that.chunk_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2370 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2371 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2372 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2373 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2374 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2375 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2376 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2377 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2378 return OrthancPluginErrorCode_InternalError; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2379 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2380 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2381 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2382 }; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2383 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2384 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2385 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2386 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2387 const char* key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2388 const char* value) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2389 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2390 assert(answer != NULL && key != NULL && value != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2391 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2392 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2393 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2394 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2395 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2396 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2397 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2398 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2399 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2400 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2401 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2402 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2403 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2404 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2405 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2406 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2407 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2408 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2409 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2410 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2411 const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2412 uint32_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2413 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2414 assert(answer != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2415 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2416 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2417 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2418 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2419 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2420 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2421 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2422 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2423 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2424 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2425 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2426 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2427 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2428 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2429 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2430 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2431 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2432 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2433 HttpClient::HttpClient() : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2434 httpStatus_(0), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2435 method_(OrthancPluginHttpMethod_Get), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2436 timeout_(0), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2437 pkcs11_(false), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2438 chunkedBody_(NULL), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2439 allowChunkedTransfers_(true) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2440 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2441 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2442 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2443 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2444 void HttpClient::AddHeaders(const HttpHeaders& headers) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2445 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2446 for (HttpHeaders::const_iterator it = headers.begin(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2447 it != headers.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2448 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2449 headers_[it->first] = it->second; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2450 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2451 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2452 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2453 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2454 void HttpClient::SetCredentials(const std::string& username, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2455 const std::string& password) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2456 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2457 username_ = username; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2458 password_ = password; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2459 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2460 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2461 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2462 void HttpClient::ClearCredentials() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2463 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2464 username_.empty(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2465 password_.empty(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2466 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2467 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2468 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2469 void HttpClient::SetCertificate(const std::string& certificateFile, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2470 const std::string& keyFile, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2471 const std::string& keyPassword) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2472 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2473 certificateFile_ = certificateFile; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2474 certificateKeyFile_ = keyFile; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2475 certificateKeyPassword_ = keyPassword; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2476 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2477 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2478 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2479 void HttpClient::ClearCertificate() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2480 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2481 certificateFile_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2482 certificateKeyFile_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2483 certificateKeyPassword_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2484 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2485 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2486 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2487 void HttpClient::ClearBody() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2488 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2489 fullBody_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2490 chunkedBody_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2491 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2492 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2493 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2494 void HttpClient::SwapBody(std::string& body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2495 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2496 fullBody_.swap(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2497 chunkedBody_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2498 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2499 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2500 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2501 void HttpClient::SetBody(const std::string& body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2502 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2503 fullBody_ = body; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2504 chunkedBody_ = NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2505 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2506 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2507 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2508 void HttpClient::SetBody(IRequestBody& body) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2509 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2510 fullBody_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2511 chunkedBody_ = &body; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2512 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2513 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2514 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2515 namespace |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2516 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2517 class HeadersWrapper : public boost::noncopyable |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2518 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2519 private: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2520 std::vector<const char*> headersKeys_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2521 std::vector<const char*> headersValues_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2522 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2523 public: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2524 HeadersWrapper(const HttpClient::HttpHeaders& headers) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2525 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2526 headersKeys_.reserve(headers.size()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2527 headersValues_.reserve(headers.size()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2528 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2529 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2530 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2531 headersKeys_.push_back(it->first.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2532 headersValues_.push_back(it->second.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2533 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2534 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2535 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2536 void AddStaticString(const char* key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2537 const char* value) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2538 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2539 headersKeys_.push_back(key); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2540 headersValues_.push_back(value); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2541 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2542 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2543 uint32_t GetCount() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2544 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2545 return headersKeys_.size(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2546 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2547 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2548 const char* const* GetKeys() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2549 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2550 return headersKeys_.empty() ? NULL : &headersKeys_[0]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2551 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2552 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2553 const char* const* GetValues() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2554 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2555 return headersValues_.empty() ? NULL : &headersValues_[0]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2556 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2557 }; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2558 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2559 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2560 class MemoryRequestBody : public HttpClient::IRequestBody |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2561 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2562 private: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2563 std::string body_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2564 bool done_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2565 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2566 public: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2567 MemoryRequestBody(const std::string& body) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2568 body_(body), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2569 done_(false) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2570 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2571 if (body_.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2572 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2573 done_ = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2574 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2575 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2576 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2577 virtual bool ReadNextChunk(std::string& chunk) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2578 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2579 if (done_) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2580 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2581 return false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2582 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2583 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2584 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2585 chunk.swap(body_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2586 done_ = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2587 return true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2588 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2589 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2590 }; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2591 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2592 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2593 // This class mimics Orthanc::ChunkedBuffer |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2594 class ChunkedBuffer : public boost::noncopyable |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2595 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2596 private: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2597 typedef std::list<std::string*> Content; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2598 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2599 Content content_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2600 size_t size_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2601 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2602 public: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2603 ChunkedBuffer() : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2604 size_(0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2605 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2606 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2607 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2608 ~ChunkedBuffer() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2609 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2610 Clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2611 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2612 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2613 void Clear() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2614 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2615 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2616 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2617 assert(*it != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2618 delete *it; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2619 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2620 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2621 content_.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2622 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2623 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2624 void Flatten(std::string& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2625 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2626 target.resize(size_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2627 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2628 size_t pos = 0; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2629 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2630 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2631 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2632 assert(*it != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2633 size_t s = (*it)->size(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2634 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2635 if (s != 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2636 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2637 memcpy(&target[pos], (*it)->c_str(), s); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2638 pos += s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2639 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2640 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2641 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2642 assert(size_ == 0 || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2643 pos == target.size()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2644 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2645 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2646 void AddChunk(const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2647 size_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2648 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2649 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2650 size_ += size; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2651 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2652 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2653 void AddChunk(const std::string& chunk) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2654 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2655 content_.push_back(new std::string(chunk)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2656 size_ += chunk.size(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2657 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2658 }; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2659 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2660 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2661 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2662 class MemoryAnswer : public HttpClient::IAnswer |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2663 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2664 private: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2665 HttpClient::HttpHeaders headers_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2666 ChunkedBuffer body_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2667 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2668 public: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2669 const HttpClient::HttpHeaders& GetHeaders() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2670 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2671 return headers_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2672 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2673 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2674 const ChunkedBuffer& GetBody() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2675 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2676 return body_; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2677 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2678 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2679 virtual void AddHeader(const std::string& key, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2680 const std::string& value) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2681 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2682 headers_[key] = value; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2683 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2684 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2685 virtual void AddChunk(const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2686 size_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2687 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2688 body_.AddChunk(data, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2689 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2690 }; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2691 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2692 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2693 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2694 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2695 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2696 void HttpClient::ExecuteWithStream(uint16_t& httpStatus, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2697 IAnswer& answer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2698 IRequestBody& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2699 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2700 HeadersWrapper h(headers_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2701 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2702 if (method_ == OrthancPluginHttpMethod_Post || |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2703 method_ == OrthancPluginHttpMethod_Put) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2704 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2705 // Automatically set the "Transfer-Encoding" header if absent |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2706 bool found = false; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2707 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2708 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2709 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2710 if (boost::iequals(it->first, "Transfer-Encoding")) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2711 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2712 found = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2713 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2714 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2715 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2716 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2717 if (!found) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2718 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2719 h.AddStaticString("Transfer-Encoding", "chunked"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2720 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2721 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2722 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2723 RequestBodyWrapper request(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2724 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2725 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2726 GetGlobalContext(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2727 &answer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2728 AnswerAddChunkCallback, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2729 AnswerAddHeaderCallback, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2730 &httpStatus, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2731 method_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2732 url_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2733 h.GetCount(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2734 h.GetKeys(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2735 h.GetValues(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2736 &request, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2737 RequestBodyWrapper::IsDone, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2738 RequestBodyWrapper::GetChunkData, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2739 RequestBodyWrapper::GetChunkSize, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2740 RequestBodyWrapper::Next, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2741 username_.empty() ? NULL : username_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2742 password_.empty() ? NULL : password_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2743 timeout_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2744 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2745 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2746 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2747 pkcs11_ ? 1 : 0); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2748 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2749 if (error != OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2750 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2751 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2752 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2753 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2754 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2755 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2756 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2757 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2758 HttpHeaders& answerHeaders, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2759 std::string& answerBody, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2760 const std::string& body) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2761 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2762 HeadersWrapper headers(headers_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2763 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2764 MemoryBuffer answerBodyBuffer, answerHeadersBuffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2765 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2766 OrthancPluginErrorCode error = OrthancPluginHttpClient( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2767 GetGlobalContext(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2768 *answerBodyBuffer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2769 *answerHeadersBuffer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2770 &httpStatus, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2771 method_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2772 url_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2773 headers.GetCount(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2774 headers.GetKeys(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2775 headers.GetValues(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2776 body.empty() ? NULL : body.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2777 body.size(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2778 username_.empty() ? NULL : username_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2779 password_.empty() ? NULL : password_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2780 timeout_, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2781 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2782 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2783 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2784 pkcs11_ ? 1 : 0); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2785 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2786 if (error != OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2787 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2788 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2789 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2790 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2791 Json::Value v; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2792 answerHeadersBuffer.ToJson(v); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2793 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2794 if (v.type() != Json::objectValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2795 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2796 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2797 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2798 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2799 Json::Value::Members members = v.getMemberNames(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2800 answerHeaders.clear(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2801 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2802 for (size_t i = 0; i < members.size(); i++) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2803 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2804 const Json::Value& h = v[members[i]]; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2805 if (h.type() != Json::stringValue) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2806 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2807 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2808 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2809 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2810 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2811 answerHeaders[members[i]] = h.asString(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2812 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2813 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2814 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2815 answerBodyBuffer.ToString(answerBody); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2816 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2817 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2818 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2819 void HttpClient::Execute(IAnswer& answer) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2820 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2821 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2822 if (allowChunkedTransfers_) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2823 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2824 if (chunkedBody_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2825 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2826 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2827 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2828 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2829 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2830 MemoryRequestBody wrapper(fullBody_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2831 ExecuteWithStream(httpStatus_, answer, wrapper); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2832 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2833 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2834 return; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2835 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2836 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2837 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2838 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2839 // transfers are disabled. This results in higher memory usage |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2840 // (all chunks from the answer body are sent at once) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2841 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2842 HttpHeaders answerHeaders; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2843 std::string answerBody; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2844 Execute(answerHeaders, answerBody); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2845 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2846 for (HttpHeaders::const_iterator it = answerHeaders.begin(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2847 it != answerHeaders.end(); ++it) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2848 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2849 answer.AddHeader(it->first, it->second); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2850 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2851 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2852 if (!answerBody.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2853 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2854 answer.AddChunk(answerBody.c_str(), answerBody.size()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2855 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2856 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2857 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2858 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2859 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2860 std::string& answerBody /* out */) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2861 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2862 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2863 if (allowChunkedTransfers_) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2864 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2865 MemoryAnswer answer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2866 Execute(answer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2867 answerHeaders = answer.GetHeaders(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2868 answer.GetBody().Flatten(answerBody); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2869 return; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2870 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2871 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2872 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2873 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2874 // transfers are disabled. This results in higher memory usage |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2875 // (all chunks from the request body are sent at once) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2876 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2877 if (chunkedBody_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2878 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2879 ChunkedBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2880 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2881 std::string chunk; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2882 while (chunkedBody_->ReadNextChunk(chunk)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2883 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2884 buffer.AddChunk(chunk); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2885 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2886 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2887 std::string body; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2888 buffer.Flatten(body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2889 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2890 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2891 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2892 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2893 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2894 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2895 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2896 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2897 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2898 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2899 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2900 Json::Value& answerBody /* out */) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2901 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2902 std::string body; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2903 Execute(answerHeaders, body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2904 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2905 Json::Reader reader; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2906 if (!reader.parse(body, answerBody)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2907 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2908 LogError("Cannot convert HTTP answer body to JSON"); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2909 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2910 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2911 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2912 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2913 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2914 void HttpClient::Execute() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2915 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2916 HttpHeaders answerHeaders; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2917 std::string body; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2918 Execute(answerHeaders, body); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2919 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2920 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2921 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2922 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2923 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2924 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2925 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2926 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2927 /****************************************************************** |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2928 ** CHUNKED HTTP SERVER |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2929 ******************************************************************/ |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2930 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2931 namespace Internals |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2932 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2933 void NullRestCallback(OrthancPluginRestOutput* output, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2934 const char* url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2935 const OrthancPluginHttpRequest* request) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2936 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2937 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2938 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2939 IChunkedRequestReader *NullChunkedRestCallback(const char* url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2940 const OrthancPluginHttpRequest* request) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2941 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2942 return NULL; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2943 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2944 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2945 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2946 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2947 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2948 OrthancPluginErrorCode ChunkedRequestReaderAddChunk( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2949 OrthancPluginServerChunkedRequestReader* reader, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2950 const void* data, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2951 uint32_t size) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2952 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2953 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2954 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2955 if (reader == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2956 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2957 return OrthancPluginErrorCode_InternalError; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2958 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2959 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2960 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2961 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2962 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2963 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2964 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2965 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2966 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2967 catch (boost::bad_lexical_cast&) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2968 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2969 return OrthancPluginErrorCode_BadFileFormat; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2970 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2971 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2972 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2973 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2974 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2975 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2976 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2977 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2978 OrthancPluginErrorCode ChunkedRequestReaderExecute( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2979 OrthancPluginServerChunkedRequestReader* reader, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2980 OrthancPluginRestOutput* output) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2981 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2982 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2983 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2984 if (reader == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2985 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2986 return OrthancPluginErrorCode_InternalError; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2987 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2988 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2989 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2990 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2991 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2992 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2993 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2994 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2995 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2996 catch (boost::bad_lexical_cast&) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2997 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2998 return OrthancPluginErrorCode_BadFileFormat; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2999 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3000 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3001 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3002 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3003 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3004 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3005 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3006 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3007 void ChunkedRequestReaderFinalize( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3008 OrthancPluginServerChunkedRequestReader* reader) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3009 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3010 if (reader != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3011 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3012 delete reinterpret_cast<IChunkedRequestReader*>(reader); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3013 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3014 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3015 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3016 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3017 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3018 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3019 const char* url, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3020 const OrthancPluginHttpRequest* request, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3021 RestCallback GetHandler, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3022 ChunkedRestCallback PostHandler, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3023 RestCallback DeleteHandler, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3024 ChunkedRestCallback PutHandler) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3025 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3026 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3027 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3028 std::string allowed; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3029 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3030 if (GetHandler != Internals::NullRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3031 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3032 allowed += "GET"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3033 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3034 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3035 if (PostHandler != Internals::NullChunkedRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3036 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3037 if (!allowed.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3038 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3039 allowed += ","; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3040 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3041 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3042 allowed += "POST"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3043 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3044 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3045 if (DeleteHandler != Internals::NullRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3046 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3047 if (!allowed.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3048 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3049 allowed += ","; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3050 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3051 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3052 allowed += "DELETE"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3053 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3054 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3055 if (PutHandler != Internals::NullChunkedRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3056 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3057 if (!allowed.empty()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3058 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3059 allowed += ","; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3060 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3061 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3062 allowed += "PUT"; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3063 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3064 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3065 switch (request->method) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3066 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3067 case OrthancPluginHttpMethod_Get: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3068 if (GetHandler == Internals::NullRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3069 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3070 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3071 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3072 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3073 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3074 GetHandler(output, url, request); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3075 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3076 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3077 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3078 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3079 case OrthancPluginHttpMethod_Post: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3080 if (PostHandler == Internals::NullChunkedRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3081 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3082 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3083 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3084 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3085 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3086 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3087 if (reader.get() == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3088 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3089 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3090 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3091 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3092 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3093 reader->AddChunk(request->body, request->bodySize); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3094 reader->Execute(output); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3095 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3096 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3097 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3098 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3099 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3100 case OrthancPluginHttpMethod_Delete: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3101 if (DeleteHandler == Internals::NullRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3102 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3103 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3104 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3105 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3106 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3107 DeleteHandler(output, url, request); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3108 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3109 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3110 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3111 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3112 case OrthancPluginHttpMethod_Put: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3113 if (PutHandler == Internals::NullChunkedRestCallback) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3114 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3115 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3116 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3117 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3118 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3119 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3120 if (reader.get() == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3121 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3122 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3123 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3124 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3125 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3126 reader->AddChunk(request->body, request->bodySize); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3127 reader->Execute(output); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3128 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3129 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3130 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3131 break; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3132 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3133 default: |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3134 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3135 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3136 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3137 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3138 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3139 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3140 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3141 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3142 if (HasGlobalContext() && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3143 e.HasDetails()) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3144 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3145 // The "false" instructs Orthanc not to log the detailed |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3146 // error message. This is to avoid duplicating the details, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3147 // because "OrthancException" already does it on construction. |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3148 OrthancPluginSetHttpErrorDetails |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3149 (GetGlobalContext(), output, e.GetDetails(), false); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3150 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3151 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3152 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3153 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3154 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3155 catch (boost::bad_lexical_cast&) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3156 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3157 return OrthancPluginErrorCode_BadFileFormat; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3158 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3159 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3160 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3161 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3162 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3163 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3164 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3165 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3166 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3167 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3168 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3169 OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3170 OrthancPluginStorageCommitmentFailureReason* target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3171 void* rawHandler, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3172 const char* sopClassUid, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3173 const char* sopInstanceUid) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3174 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3175 assert(target != NULL && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3176 rawHandler != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3177 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3178 try |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3179 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3180 IStorageCommitmentScpHandler& handler = *reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3181 *target = handler.Lookup(sopClassUid, sopInstanceUid); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3182 return OrthancPluginErrorCode_Success; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3183 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3184 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3185 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3186 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3187 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3188 catch (...) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3189 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3190 return OrthancPluginErrorCode_Plugin; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3191 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3192 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3193 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3194 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3195 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3196 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3197 void IStorageCommitmentScpHandler::Destructor(void* rawHandler) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3198 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3199 assert(rawHandler != NULL); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3200 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3201 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3202 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3203 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3204 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3205 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3206 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3207 toFree_(false), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3208 instance_(instance) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3209 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3210 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3211 #else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3212 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3213 toFree_(false), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3214 instance_(instance) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3215 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3216 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3217 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3218 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3219 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3220 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3221 DicomInstance::DicomInstance(const void* buffer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3222 size_t size) : |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3223 toFree_(true), |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3224 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size)) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3225 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3226 if (instance_ == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3227 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3228 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3229 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3230 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3231 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3232 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3233 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3234 DicomInstance::~DicomInstance() |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3235 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3236 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3237 if (toFree_ && |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3238 instance_ != NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3239 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3240 OrthancPluginFreeDicomInstance( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3241 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3242 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3243 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3244 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3245 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3246 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3247 std::string DicomInstance::GetRemoteAet() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3248 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3249 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3250 if (s == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3251 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3252 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3253 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3254 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3255 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3256 return std::string(s); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3257 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3258 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3259 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3260 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3261 void DicomInstance::GetJson(Json::Value& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3262 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3263 OrthancString s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3264 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3265 s.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3266 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3267 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3268 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3269 void DicomInstance::GetSimplifiedJson(Json::Value& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3270 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3271 OrthancString s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3272 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3273 s.ToJson(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3274 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3275 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3276 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3277 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3278 std::string DicomInstance::GetTransferSyntaxUid() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3279 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3280 OrthancString s; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3281 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3282 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3283 std::string result; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3284 s.ToString(result); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3285 return result; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3286 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3287 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3288 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3289 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3290 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3291 bool DicomInstance::HasPixelData() const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3292 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3293 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3294 if (result < 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3295 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3296 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3297 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3298 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3299 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3300 return (result != 0); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3301 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3302 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3303 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3304 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3305 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3306 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3307 void DicomInstance::GetRawFrame(std::string& target, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3308 unsigned int frameIndex) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3309 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3310 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3311 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3312 GetGlobalContext(), *buffer, instance_, frameIndex); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3313 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3314 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3315 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3316 buffer.ToString(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3317 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3318 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3319 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3320 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3321 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3322 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3323 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3324 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3325 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3326 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3327 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3328 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3329 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3330 GetGlobalContext(), instance_, frameIndex); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3331 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3332 if (image == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3333 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3334 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3335 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3336 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3337 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3338 return new OrthancImage(image); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3339 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3340 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3341 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3342 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3343 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3344 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3345 void DicomInstance::Serialize(std::string& target) const |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3346 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3347 MemoryBuffer buffer; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3348 OrthancPluginErrorCode code = OrthancPluginSerializeDicomInstance( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3349 GetGlobalContext(), *buffer, instance_); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3350 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3351 if (code == OrthancPluginErrorCode_Success) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3352 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3353 buffer.ToString(target); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3354 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3355 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3356 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3357 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3358 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3359 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3360 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3361 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3362 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3363 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3364 DicomInstance* DicomInstance::Transcode(const void* buffer, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3365 size_t size, |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3366 const std::string& transferSyntax) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3367 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3368 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3369 GetGlobalContext(), buffer, size, transferSyntax.c_str()); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3370 |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3371 if (instance == NULL) |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3372 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3373 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3374 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3375 else |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3376 { |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3377 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance)); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3378 result->toFree_ = true; |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3379 return result.release(); |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3380 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3381 } |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3382 #endif |
d1806b4e4839
moving OrthancStone/Samples/ as Applications/Samples/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3383 } |