annotate RenderingPlugin/Sources/OrthancPluginConnection.cpp @ 1885:ddaee6b96501

retrieving rt-struct info
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Jan 2022 19:04:05 +0100
parents
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1885
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "OrthancPluginConnection.h"
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <OrthancException.h>
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancStone
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 void OrthancPluginConnection::RestApiGet(std::string& result,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 const std::string& uri)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 OrthancPlugins::MemoryBuffer tmp;
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 if (tmp.RestApiGet(uri, false))
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 tmp.ToString(result);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 else
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 void OrthancPluginConnection::RestApiPost(std::string& result,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const std::string& uri,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 const std::string& body)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 OrthancPlugins::MemoryBuffer tmp;
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if (tmp.RestApiPost(uri, body.empty() ? NULL : body.c_str(), body.size(), false))
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 tmp.ToString(result);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 else
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 void OrthancPluginConnection::RestApiPut(std::string& result,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const std::string& uri,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 const std::string& body)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 OrthancPlugins::MemoryBuffer tmp;
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (tmp.RestApiPut(uri, body.empty() ? NULL : body.c_str(), body.size(), false))
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 tmp.ToString(result);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 else
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void OrthancPluginConnection::RestApiDelete(const std::string& uri)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (!OrthancPlugins::RestApiDelete(uri, false))
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }