Mercurial > hg > orthanc-stone
annotate Framework/Oracle/OrthancRestApiCommand.h @ 1134:87fbeb823375 broker
allocating messages from oracle commands on the stack
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Nov 2019 15:16:45 +0100 |
parents | 8e3763d1736a |
children | a0a33e5ea5bb |
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 | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
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 |
27 #include <Core/Enumerations.h> | |
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 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
39 class SuccessMessage : public OracleMessageBase |
746 | 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: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
48 SuccessMessage(OrthancRestApiCommand& command, |
746 | 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) : |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
51 OracleMessageBase(command), |
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 |
79 public: | |
80 OrthancRestApiCommand(); | |
81 | |
82 virtual Type GetType() const | |
83 { | |
84 return Type_OrthancRestApi; | |
85 } | |
86 | |
87 void SetMethod(Orthanc::HttpMethod method) | |
88 { | |
89 method_ = method; | |
90 } | |
91 | |
92 void SetUri(const std::string& uri) | |
93 { | |
94 uri_ = uri; | |
95 } | |
96 | |
97 void SetBody(const std::string& body) | |
98 { | |
99 body_ = body; | |
100 } | |
101 | |
102 void SetBody(const Json::Value& json); | |
103 | |
819 | 104 void SwapBody(std::string& body) |
105 { | |
106 body_.swap(body); | |
107 } | |
108 | |
979 | 109 void SetHttpHeaders(const HttpHeaders& headers) |
110 { | |
111 headers_ = headers; | |
112 } | |
113 | |
746 | 114 void SetHttpHeader(const std::string& key, |
115 const std::string& value) | |
116 { | |
117 headers_[key] = value; | |
118 } | |
119 | |
120 Orthanc::HttpMethod GetMethod() const | |
121 { | |
122 return method_; | |
123 } | |
124 | |
125 const std::string& GetUri() const | |
126 { | |
127 return uri_; | |
128 } | |
129 | |
130 const std::string& GetBody() const; | |
131 | |
132 const HttpHeaders& GetHttpHeaders() const | |
133 { | |
134 return headers_; | |
135 } | |
136 | |
137 void SetTimeout(unsigned int seconds) | |
138 { | |
139 timeout_ = seconds; | |
140 } | |
141 | |
142 unsigned int GetTimeout() const | |
143 { | |
144 return timeout_; | |
145 } | |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
146 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
147 void SetApplyPlugins(bool applyPlugins) |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
148 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
149 applyPlugins_ = applyPlugins; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
150 } |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
151 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
152 bool IsApplyPlugins() const |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
153 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
154 return applyPlugins_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
155 } |
746 | 156 }; |
157 } |