Mercurial > hg > orthanc-wsi
annotate Resources/Orthanc/Stone/IOrthancConnection.cpp @ 283:04ea47a422d1 iiif
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2023 21:21:48 +0200 |
parents | 20a730889ae2 |
children | 7020852a8fa9 |
rev | line source |
---|---|
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
283 | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
212 | 9 * modify it under the terms of the GNU Lesser General Public License |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
212 | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "IOrthancConnection.h" |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <OrthancException.h> |
212 | 27 #include <Toolbox.h> |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
223
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
29 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
30 # error You are using a version of the Orthanc framework that is too old |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
31 #endif |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
32 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
33 #if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
34 # include <json/reader.h> |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
35 #endif |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
36 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
37 |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 namespace OrthancStone |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 void IOrthancConnection::ParseJson(Json::Value& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 const std::string& content) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
223
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
43 bool ok; |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
44 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
45 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
46 ok = Orthanc::Toolbox::ReadJson(result, content); |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
47 #else |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
48 // Backward compatibility (for use in orthanc-wsi 1.0) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
49 Json::Reader reader; |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
50 ok = reader.parse(content, result); |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
51 #endif |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
52 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
53 if (!ok) |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 void IOrthancConnection::ParseJson(Json::Value& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 const void* content, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 size_t size) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 { |
223
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
64 bool ok; |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
65 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
66 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
67 ok = Orthanc::Toolbox::ReadJson(result, content, size); |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
68 #else |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
69 // Backward compatibility (for use in orthanc-wsi 1.0) |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
70 Json::Reader reader; |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
71 ok = reader.parse(reinterpret_cast<const char*>(content), |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
72 reinterpret_cast<const char*>(content) + size, result); |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
73 #endif |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
74 |
443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
75 if (!ok) |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 void IOrthancConnection::RestApiGet(Json::Value& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 IOrthancConnection& orthanc, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 const std::string& uri) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 std::string content; |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 orthanc.RestApiGet(content, uri); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 ParseJson(result, content); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 void IOrthancConnection::RestApiPost(Json::Value& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 IOrthancConnection& orthanc, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 const std::string& uri, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 const std::string& body) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 std::string content; |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 orthanc.RestApiPost(content, uri, body); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 ParseJson(result, content); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 void IOrthancConnection::RestApiPut(Json::Value& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 IOrthancConnection& orthanc, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 const std::string& uri, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 const std::string& body) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 std::string content; |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 orthanc.RestApiPut(content, uri, body); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 ParseJson(result, content); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |