Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp @ 2043:f3d756e5503f deep-learning
fix build on wasm
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 10 Feb 2023 09:13:49 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1504 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1504 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1504 | 21 **/ |
22 | |
23 | |
24 #include "IOrthancConnection.h" | |
25 | |
26 #include <OrthancException.h> | |
1737
ef2f56c0311c
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
27 #include <Toolbox.h> |
1504 | 28 |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
29 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
30 # error You are using a version of the Orthanc framework that is too old |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
31 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
32 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
33 #if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
34 # include <json/reader.h> |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
35 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
36 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
37 |
1504 | 38 namespace OrthancStone |
39 { | |
40 void IOrthancConnection::ParseJson(Json::Value& result, | |
41 const std::string& content) | |
42 { | |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
43 bool ok; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
44 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
45 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
46 ok = Orthanc::Toolbox::ReadJson(result, content); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
47 #else |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
48 // Backward compatibility (for use in orthanc-wsi 1.0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
49 Json::Reader reader; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
50 ok = reader.parse(content, result); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
51 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
52 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
53 if (!ok) |
1504 | 54 { |
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
56 } | |
57 } | |
58 | |
59 | |
60 void IOrthancConnection::ParseJson(Json::Value& result, | |
61 const void* content, | |
62 size_t size) | |
63 { | |
1740
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
64 bool ok; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
65 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
66 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
67 ok = Orthanc::Toolbox::ReadJson(result, content, size); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
68 #else |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
69 // Backward compatibility (for use in orthanc-wsi 1.0) |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
70 Json::Reader reader; |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
71 ok = reader.parse(reinterpret_cast<const char*>(content), |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
72 reinterpret_cast<const char*>(content) + size, result); |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
73 #endif |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
74 |
84d1402c98fe
backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
75 if (!ok) |
1504 | 76 { |
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
78 } | |
79 } | |
80 | |
81 | |
82 void IOrthancConnection::RestApiGet(Json::Value& result, | |
83 IOrthancConnection& orthanc, | |
84 const std::string& uri) | |
85 { | |
86 std::string content; | |
87 orthanc.RestApiGet(content, uri); | |
88 ParseJson(result, content); | |
89 } | |
90 | |
91 | |
92 void IOrthancConnection::RestApiPost(Json::Value& result, | |
93 IOrthancConnection& orthanc, | |
94 const std::string& uri, | |
95 const std::string& body) | |
96 { | |
97 std::string content; | |
98 orthanc.RestApiPost(content, uri, body); | |
99 ParseJson(result, content); | |
100 } | |
101 | |
102 | |
103 void IOrthancConnection::RestApiPut(Json::Value& result, | |
104 IOrthancConnection& orthanc, | |
105 const std::string& uri, | |
106 const std::string& body) | |
107 { | |
108 std::string content; | |
109 orthanc.RestApiPut(content, uri, body); | |
110 ParseJson(result, content); | |
111 } | |
112 } |