79d42c3a712b7e43ed03bf05ea20b327426a08f4
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / serverBuilder / src / RCSResponse.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include <RCSResponse.h>
22
23 #include <RequestHandler.h>
24
25 #include <cassert>
26
27 namespace OIC
28 {
29     namespace Service
30     {
31         RCSGetResponse RCSGetResponse::defaultAction()
32         {
33             return std::make_shared< RequestHandler >();
34         }
35
36         RCSGetResponse RCSGetResponse::create(int errorCode)
37         {
38             return RCSGetResponse {
39                 std::make_shared< RequestHandler >( errorCode) };
40         }
41
42         RCSGetResponse RCSGetResponse::create(const RCSResourceAttributes& attrs)
43         {
44             return RCSGetResponse { std::make_shared< RequestHandler >(attrs) };
45         }
46
47         RCSGetResponse RCSGetResponse::create(const RCSResourceAttributes& attrs, int errorCode)
48         {
49             return RCSGetResponse { std::make_shared< RequestHandler >(attrs, errorCode) };
50         }
51
52         RCSGetResponse RCSGetResponse::create(RCSResourceAttributes&& result)
53         {
54             return RCSGetResponse {
55                 std::make_shared< RequestHandler >(std::move(result)) };
56         }
57
58         RCSGetResponse RCSGetResponse::create(RCSResourceAttributes&& attrs, int errorCode)
59         {
60             return RCSGetResponse { std::make_shared< RequestHandler >(
61                 std::move(attrs), errorCode) };
62         }
63
64         RCSGetResponse RCSGetResponse::separate()
65         {
66             return RCSGetResponse();
67         }
68
69         bool RCSGetResponse::isSeparate() const
70         {
71             return !m_handler;
72         }
73
74         RCSGetResponse::RCSGetResponse()
75         {
76         }
77
78         RCSGetResponse::RCSGetResponse(std::shared_ptr< RequestHandler >&& handler) :
79                 m_handler{ std::move(handler) }
80         {
81             assert(m_handler);
82         }
83
84         RequestHandler* RCSGetResponse::getHandler() const
85         {
86             return m_handler.get();
87         }
88
89
90         RCSSetResponse RCSSetResponse::defaultAction()
91         {
92             return std::make_shared< SetRequestHandler >();
93         }
94
95         RCSSetResponse RCSSetResponse::accept()
96         {
97             return defaultAction().setAcceptanceMethod(AcceptanceMethod::ACCEPT);
98         }
99
100         RCSSetResponse RCSSetResponse::accept(int errorCode)
101         {
102             return create(errorCode).setAcceptanceMethod(AcceptanceMethod::ACCEPT);
103         }
104
105         RCSSetResponse RCSSetResponse::ignore()
106         {
107             return defaultAction().setAcceptanceMethod(AcceptanceMethod::IGNORE);
108         }
109
110         RCSSetResponse RCSSetResponse::ignore(int errorCode)
111         {
112             return create(errorCode).setAcceptanceMethod(AcceptanceMethod::IGNORE);
113         }
114
115         RCSSetResponse RCSSetResponse::create(int errorCode)
116         {
117             return std::make_shared< SetRequestHandler >(errorCode);
118         }
119
120         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs)
121         {
122             return std::make_shared< SetRequestHandler >(attrs);
123         }
124
125         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs, int errorCode)
126         {
127             return std::make_shared< SetRequestHandler >(attrs, errorCode);
128         }
129
130         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& result)
131         {
132             return std::make_shared< SetRequestHandler >(std::move(result));
133         }
134
135         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& attrs, int errorCode)
136         {
137             return std::make_shared< SetRequestHandler >(std::move(attrs), errorCode);
138         }
139
140         RCSSetResponse RCSSetResponse::separate()
141         {
142             return RCSSetResponse();
143         }
144
145         RCSSetResponse::RCSSetResponse() :
146                 m_acceptanceMethod { AcceptanceMethod::DEFAULT }
147         {
148         }
149
150         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler) :
151                 m_acceptanceMethod { AcceptanceMethod::DEFAULT },
152                 m_handler{ std::move(handler) }
153         {
154         }
155
156         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler,
157                 AcceptanceMethod method) :
158                 m_acceptanceMethod{ method },
159                 m_handler{ std::move(handler) }
160         {
161             assert(m_handler);
162         }
163
164         bool RCSSetResponse::isSeparate() const
165         {
166             return !m_handler;
167         }
168
169
170         SetRequestHandler* RCSSetResponse::getHandler() const
171         {
172             return m_handler.get();
173         }
174
175         auto RCSSetResponse::getAcceptanceMethod() const -> AcceptanceMethod
176         {
177             return m_acceptanceMethod;
178         }
179
180         RCSSetResponse& RCSSetResponse::setAcceptanceMethod(AcceptanceMethod method)
181         {
182             m_acceptanceMethod = method;
183             return *this;
184         }
185     }
186 }