comparison Framework/Oracle/OrthancRestApiCommand.h @ 746:d716bfb3e07c

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 22 May 2019 12:48:57 +0200
parents
children a68cd7ae8838
comparison
equal deleted inserted replaced
745:c44c1d2d3598 746:d716bfb3e07c
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"
25 #include "OracleCommandWithPayload.h"
26
27 #include <Core/Enumerations.h>
28
29 #include <map>
30 #include <json/value.h>
31
32 namespace OrthancStone
33 {
34 class OrthancRestApiCommand : public OracleCommandWithPayload
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:
44 HttpHeaders headers_;
45 std::string answer_;
46
47 public:
48 SuccessMessage(const OrthancRestApiCommand& command,
49 const HttpHeaders& answerHeaders,
50 std::string& answer /* will be swapped to avoid a memcpy() */);
51
52 const std::string& GetAnswer() const
53 {
54 return answer_;
55 }
56
57 void ParseJsonBody(Json::Value& target) const;
58
59 const HttpHeaders& GetAnswerHeaders() const
60 {
61 return headers_;
62 }
63 };
64
65
66 private:
67 Orthanc::HttpMethod method_;
68 std::string uri_;
69 std::string body_;
70 HttpHeaders headers_;
71 unsigned int timeout_;
72
73 public:
74 OrthancRestApiCommand();
75
76 virtual Type GetType() const
77 {
78 return Type_OrthancRestApi;
79 }
80
81 void SetMethod(Orthanc::HttpMethod method)
82 {
83 method_ = method;
84 }
85
86 void SetUri(const std::string& uri)
87 {
88 uri_ = uri;
89 }
90
91 void SetBody(const std::string& body)
92 {
93 body_ = body;
94 }
95
96 void SetBody(const Json::Value& json);
97
98 void SetHttpHeader(const std::string& key,
99 const std::string& value)
100 {
101 headers_[key] = value;
102 }
103
104 Orthanc::HttpMethod GetMethod() const
105 {
106 return method_;
107 }
108
109 const std::string& GetUri() const
110 {
111 return uri_;
112 }
113
114 const std::string& GetBody() const;
115
116 const HttpHeaders& GetHttpHeaders() const
117 {
118 return headers_;
119 }
120
121 void SetTimeout(unsigned int seconds)
122 {
123 timeout_ = seconds;
124 }
125
126 unsigned int GetTimeout() const
127 {
128 return timeout_;
129 }
130 };
131 }