Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Oracle/OrthancRestApiCommand.h @ 2130:ed2c704b1119 StoneWebViewer-2.1
closing StoneWebViewer-2.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 17:08:23 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
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 | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
746 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
746 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * 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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
746 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "../Messages/IMessage.h" | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
26 #include "OracleCommandBase.h" |
746 | 27 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
28 #include <Enumerations.h> |
746 | 29 |
30 #include <map> | |
31 #include <json/value.h> | |
32 | |
33 namespace OrthancStone | |
34 { | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
35 class OrthancRestApiCommand : public OracleCommandBase |
746 | 36 { |
37 public: | |
38 typedef std::map<std::string, std::string> HttpHeaders; | |
39 | |
40 class SuccessMessage : public OriginMessage<OrthancRestApiCommand> | |
41 { | |
42 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); | |
43 | |
44 private: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
45 const HttpHeaders& headers_; |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
46 const std::string& answer_; |
746 | 47 |
48 public: | |
49 SuccessMessage(const OrthancRestApiCommand& command, | |
50 const HttpHeaders& answerHeaders, | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
51 const std::string& answer) : |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
52 OriginMessage(command), |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
53 headers_(answerHeaders), |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
54 answer_(answer) |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
55 { |
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 |
746 | 58 const std::string& GetAnswer() const |
59 { | |
60 return answer_; | |
61 } | |
62 | |
63 void ParseJsonBody(Json::Value& target) const; | |
64 | |
65 const HttpHeaders& GetAnswerHeaders() const | |
66 { | |
67 return headers_; | |
68 } | |
69 }; | |
70 | |
71 | |
72 private: | |
73 Orthanc::HttpMethod method_; | |
74 std::string uri_; | |
75 std::string body_; | |
76 HttpHeaders headers_; | |
77 unsigned int timeout_; | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
78 bool applyPlugins_; // Only makes sense for Stone as an Orthanc plugin |
746 | 79 |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
80 OrthancRestApiCommand(const OrthancRestApiCommand& other) : |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
81 method_(other.method_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
82 uri_(other.uri_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
83 body_(other.body_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
84 headers_(other.headers_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
85 timeout_(other.timeout_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
86 applyPlugins_(other.applyPlugins_) |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
87 { |
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 |
746 | 90 public: |
91 OrthancRestApiCommand(); | |
92 | |
1571 | 93 virtual Type GetType() const ORTHANC_OVERRIDE |
746 | 94 { |
95 return Type_OrthancRestApi; | |
96 } | |
97 | |
1571 | 98 virtual IOracleCommand* Clone() const ORTHANC_OVERRIDE |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
99 { |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
100 return new OrthancRestApiCommand(*this); |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
101 } |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
102 |
746 | 103 void SetMethod(Orthanc::HttpMethod method) |
104 { | |
105 method_ = method; | |
106 } | |
107 | |
108 void SetUri(const std::string& uri) | |
109 { | |
110 uri_ = uri; | |
111 } | |
112 | |
113 void SetBody(const std::string& body) | |
114 { | |
115 body_ = body; | |
116 } | |
117 | |
118 void SetBody(const Json::Value& json); | |
119 | |
819 | 120 void SwapBody(std::string& body) |
121 { | |
122 body_.swap(body); | |
123 } | |
124 | |
979 | 125 void SetHttpHeaders(const HttpHeaders& headers) |
126 { | |
127 headers_ = headers; | |
128 } | |
129 | |
746 | 130 void SetHttpHeader(const std::string& key, |
131 const std::string& value) | |
132 { | |
133 headers_[key] = value; | |
134 } | |
135 | |
136 Orthanc::HttpMethod GetMethod() const | |
137 { | |
138 return method_; | |
139 } | |
140 | |
141 const std::string& GetUri() const | |
142 { | |
143 return uri_; | |
144 } | |
145 | |
146 const std::string& GetBody() const; | |
147 | |
148 const HttpHeaders& GetHttpHeaders() const | |
149 { | |
150 return headers_; | |
151 } | |
152 | |
153 void SetTimeout(unsigned int seconds) | |
154 { | |
155 timeout_ = seconds; | |
156 } | |
157 | |
158 unsigned int GetTimeout() const | |
159 { | |
160 return timeout_; | |
161 } | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
162 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
163 void SetApplyPlugins(bool applyPlugins) |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
164 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
165 applyPlugins_ = applyPlugins; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
166 } |
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 bool IsApplyPlugins() const |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
169 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
170 return applyPlugins_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
171 } |
746 | 172 }; |
173 } |