Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Oracle/OrthancRestApiCommand.h @ 1515:b750b6eab453
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 20:52:35 +0200 |
parents | 244ad1e4e76a |
children | 85e117739eca |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
746 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
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 | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "../Messages/IMessage.h" | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
25 #include "OracleCommandBase.h" |
746 | 26 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
27 #include <Enumerations.h> |
746 | 28 |
29 #include <map> | |
30 #include <json/value.h> | |
31 | |
32 namespace OrthancStone | |
33 { | |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
34 class OrthancRestApiCommand : public OracleCommandBase |
746 | 35 { |
36 public: | |
37 typedef std::map<std::string, std::string> HttpHeaders; | |
38 | |
39 class SuccessMessage : public OriginMessage<OrthancRestApiCommand> | |
40 { | |
41 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); | |
42 | |
43 private: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
44 const HttpHeaders& headers_; |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
45 const std::string& answer_; |
746 | 46 |
47 public: | |
48 SuccessMessage(const OrthancRestApiCommand& command, | |
49 const HttpHeaders& answerHeaders, | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
50 const std::string& answer) : |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
51 OriginMessage(command), |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
52 headers_(answerHeaders), |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
53 answer_(answer) |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
54 { |
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 |
746 | 57 const std::string& GetAnswer() const |
58 { | |
59 return answer_; | |
60 } | |
61 | |
62 void ParseJsonBody(Json::Value& target) const; | |
63 | |
64 const HttpHeaders& GetAnswerHeaders() const | |
65 { | |
66 return headers_; | |
67 } | |
68 }; | |
69 | |
70 | |
71 private: | |
72 Orthanc::HttpMethod method_; | |
73 std::string uri_; | |
74 std::string body_; | |
75 HttpHeaders headers_; | |
76 unsigned int timeout_; | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
77 bool applyPlugins_; // Only makes sense for Stone as an Orthanc plugin |
746 | 78 |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
79 OrthancRestApiCommand(const OrthancRestApiCommand& other) : |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
80 method_(other.method_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
81 uri_(other.uri_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
82 body_(other.body_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
83 headers_(other.headers_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
84 timeout_(other.timeout_), |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
85 applyPlugins_(other.applyPlugins_) |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
86 { |
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 |
746 | 89 public: |
90 OrthancRestApiCommand(); | |
91 | |
92 virtual Type GetType() const | |
93 { | |
94 return Type_OrthancRestApi; | |
95 } | |
96 | |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
97 virtual IOracleCommand* Clone() const |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
98 { |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
99 return new OrthancRestApiCommand(*this); |
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 |
746 | 102 void SetMethod(Orthanc::HttpMethod method) |
103 { | |
104 method_ = method; | |
105 } | |
106 | |
107 void SetUri(const std::string& uri) | |
108 { | |
109 uri_ = uri; | |
110 } | |
111 | |
112 void SetBody(const std::string& body) | |
113 { | |
114 body_ = body; | |
115 } | |
116 | |
117 void SetBody(const Json::Value& json); | |
118 | |
819 | 119 void SwapBody(std::string& body) |
120 { | |
121 body_.swap(body); | |
122 } | |
123 | |
979 | 124 void SetHttpHeaders(const HttpHeaders& headers) |
125 { | |
126 headers_ = headers; | |
127 } | |
128 | |
746 | 129 void SetHttpHeader(const std::string& key, |
130 const std::string& value) | |
131 { | |
132 headers_[key] = value; | |
133 } | |
134 | |
135 Orthanc::HttpMethod GetMethod() const | |
136 { | |
137 return method_; | |
138 } | |
139 | |
140 const std::string& GetUri() const | |
141 { | |
142 return uri_; | |
143 } | |
144 | |
145 const std::string& GetBody() const; | |
146 | |
147 const HttpHeaders& GetHttpHeaders() const | |
148 { | |
149 return headers_; | |
150 } | |
151 | |
152 void SetTimeout(unsigned int seconds) | |
153 { | |
154 timeout_ = seconds; | |
155 } | |
156 | |
157 unsigned int GetTimeout() const | |
158 { | |
159 return timeout_; | |
160 } | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
161 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
162 void SetApplyPlugins(bool applyPlugins) |
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 applyPlugins_ = 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 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
167 bool IsApplyPlugins() const |
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 return applyPlugins_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
170 } |
746 | 171 }; |
172 } |