openthread-br  0.3.0-72c0388
response.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef OTBR_REST_RESPONSE_HPP_
35 #define OTBR_REST_RESPONSE_HPP_
36 
37 #include <chrono>
38 #include <string>
39 #include <vector>
40 
41 #include "rest/types.hpp"
42 
43 using std::chrono::duration_cast;
44 using std::chrono::microseconds;
45 using std::chrono::seconds;
46 using std::chrono::steady_clock;
47 
48 namespace otbr {
49 namespace rest {
50 
56 class Response
57 {
58 public:
64  Response(void);
65 
72  void SetBody(std::string &aBody);
73 
79  std::string GetBody(void) const;
80 
87  void SetResponsCode(std::string &aCode);
88 
94  void SetCallback(void);
95 
101  bool NeedCallback(void);
102 
107  void SetComplete();
108 
114  bool IsComplete();
115 
122  void SetStartTime(steady_clock::time_point aStartTime);
123 
129  steady_clock::time_point GetStartTime() const;
130 
136  std::string Serialize(void) const;
137 
138 private:
139  bool mCallback;
140  std::vector<std::string> mHeaderField;
141  std::vector<std::string> mHeaderValue;
142  std::string mCode;
143  std::string mProtocol;
144  std::string mBody;
145  bool mComplete;
146  steady_clock::time_point mStartTime;
147 };
148 
149 } // namespace rest
150 } // namespace otbr
151 
152 #endif // OTBR_REST_RESPONSE_HPP_
otbr::rest::Response
Definition: response.hpp:56
otbr::rest::Response::IsComplete
bool IsComplete()
Definition: response.cpp:79
otbr::rest::Response::Serialize
std::string Serialize(void) const
Definition: response.cpp:109
otbr::rest::Response::SetResponsCode
void SetResponsCode(std::string &aCode)
Definition: response.cpp:84
otbr::rest::Response::GetBody
std::string GetBody(void) const
Definition: response.cpp:99
otbr::rest::Response::SetComplete
void SetComplete()
Definition: response.cpp:64
types.hpp
otbr::rest::Response::SetCallback
void SetCallback(void)
Definition: response.cpp:89
otbr::rest::Response::Response
Response(void)
Definition: response.cpp:43
otbr::rest::Response::SetBody
void SetBody(std::string &aBody)
Definition: response.cpp:94
otbr::rest::Response::NeedCallback
bool NeedCallback(void)
Definition: response.cpp:104
otbr::rest::Response::GetStartTime
steady_clock::time_point GetStartTime() const
Definition: response.cpp:74
otbr::rest::Response::SetStartTime
void SetStartTime(steady_clock::time_point aStartTime)
Definition: response.cpp:69