Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Oracle/OrthancRestApiCommand.h @ 1871:7053b8a0aaec
upgrade to year 2022
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 11:18:48 +0100 |
parents | 3889ae96d2e9 |
children | 07964689cb0b |
rev | line source |
---|---|
746 | 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 |
746 | 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 |
746 | 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:
1571
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/>. |
746 | 21 **/ |
22 | |
23 | |
24 #pragma once | |
25 | |
26 #include "../Messages/IMessage.h" | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
27 #include "OracleCommandBase.h" |
746 | 28 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
29 #include <Enumerations.h> |
746 | 30 |
31 #include <map> | |
32 #include <json/value.h> | |
33 | |
34 namespace OrthancStone | |
35 { | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
36 class OrthancRestApiCommand : public OracleCommandBase |
746 | 37 { |
38 public: | |
39 typedef std::map<std::string, std::string> HttpHeaders; | |
40 | |
41 class SuccessMessage : public OriginMessage<OrthancRestApiCommand> | |
42 { | |
43 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); | |
44 | |
45 private: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
46 const HttpHeaders& headers_; |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
47 const std::string& answer_; |
746 | 48 |
49 public: | |
50 SuccessMessage(const OrthancRestApiCommand& command, | |
51 const HttpHeaders& answerHeaders, | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
52 const std::string& answer) : |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
53 OriginMessage(command), |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
54 headers_(answerHeaders), |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
55 answer_(answer) |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
56 { |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
57 } |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
58 |
746 | 59 const std::string& GetAnswer() const |
60 { | |
61 return answer_; | |
62 } | |
63 | |
64 void ParseJsonBody(Json::Value& target) const; | |
65 | |
66 const HttpHeaders& GetAnswerHeaders() const | |
67 { | |
68 return headers_; | |
69 } | |
70 }; | |
71 | |
72 | |
73 private: | |
74 Orthanc::HttpMethod method_; | |
75 std::string uri_; | |
76 std::string body_; | |
77 HttpHeaders headers_; | |
78 unsigned int timeout_; | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
79 bool applyPlugins_; // Only makes sense for Stone as an Orthanc plugin |
746 | 80 |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
81 OrthancRestApiCommand(const OrthancRestApiCommand& other) : |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
82 method_(other.method_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
83 uri_(other.uri_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
84 body_(other.body_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
85 headers_(other.headers_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
86 timeout_(other.timeout_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
87 applyPlugins_(other.applyPlugins_) |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
88 { |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
89 } |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
90 |
746 | 91 public: |
92 OrthancRestApiCommand(); | |
93 | |
1571 | 94 virtual Type GetType() const ORTHANC_OVERRIDE |
746 | 95 { |
96 return Type_OrthancRestApi; | |
97 } | |
98 | |
1571 | 99 virtual IOracleCommand* Clone() const ORTHANC_OVERRIDE |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
100 { |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
101 return new OrthancRestApiCommand(*this); |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
102 } |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
103 |
746 | 104 void SetMethod(Orthanc::HttpMethod method) |
105 { | |
106 method_ = method; | |
107 } | |
108 | |
109 void SetUri(const std::string& uri) | |
110 { | |
111 uri_ = uri; | |
112 } | |
113 | |
114 void SetBody(const std::string& body) | |
115 { | |
116 body_ = body; | |
117 } | |
118 | |
119 void SetBody(const Json::Value& json); | |
120 | |
819 | 121 void SwapBody(std::string& body) |
122 { | |
123 body_.swap(body); | |
124 } | |
125 | |
979 | 126 void SetHttpHeaders(const HttpHeaders& headers) |
127 { | |
128 headers_ = headers; | |
129 } | |
130 | |
746 | 131 void SetHttpHeader(const std::string& key, |
132 const std::string& value) | |
133 { | |
134 headers_[key] = value; | |
135 } | |
136 | |
137 Orthanc::HttpMethod GetMethod() const | |
138 { | |
139 return method_; | |
140 } | |
141 | |
142 const std::string& GetUri() const | |
143 { | |
144 return uri_; | |
145 } | |
146 | |
147 const std::string& GetBody() const; | |
148 | |
149 const HttpHeaders& GetHttpHeaders() const | |
150 { | |
151 return headers_; | |
152 } | |
153 | |
154 void SetTimeout(unsigned int seconds) | |
155 { | |
156 timeout_ = seconds; | |
157 } | |
158 | |
159 unsigned int GetTimeout() const | |
160 { | |
161 return timeout_; | |
162 } | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
163 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
164 void SetApplyPlugins(bool applyPlugins) |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
165 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
166 applyPlugins_ = applyPlugins; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
167 } |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
168 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
169 bool IsApplyPlugins() const |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
170 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
171 return applyPlugins_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
172 } |
746 | 173 }; |
174 } |