Imported Upstream version 0.9.2
[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             static RCSGetResponse defaultRes { std::make_shared< RequestHandler >() };
34
35             return defaultRes;
36         }
37
38         RCSGetResponse RCSGetResponse::create(const OCEntityHandlerResult& result,
39                 int errorCode)
40         {
41             return RCSGetResponse {
42                 std::make_shared< RequestHandler >( result, errorCode) };
43         }
44
45         RCSGetResponse RCSGetResponse::create(const RCSResourceAttributes& attrs)
46         {
47             return RCSGetResponse { std::make_shared< RequestHandler >(attrs) };
48         }
49
50         RCSGetResponse RCSGetResponse::create(const RCSResourceAttributes& attrs,
51                 const OCEntityHandlerResult& result, int errorCode)
52         {
53             return RCSGetResponse {
54                 std::make_shared< RequestHandler >(attrs, result, errorCode) };
55         }
56
57         RCSGetResponse RCSGetResponse::create(RCSResourceAttributes&& result)
58         {
59             return RCSGetResponse {
60                 std::make_shared< RequestHandler >(std::move(result)) };
61         }
62
63         RCSGetResponse RCSGetResponse::create(RCSResourceAttributes&& attrs,
64                 const OCEntityHandlerResult& result, int errorCode)
65         {
66             return RCSGetResponse { std::make_shared< RequestHandler >(
67                 std::move(attrs), result, errorCode) };
68         }
69
70         RCSGetResponse::RCSGetResponse(std::shared_ptr< RequestHandler >&& handler) :
71                 m_handler{ std::move(handler) }
72         {
73             assert(m_handler);
74         }
75
76         RequestHandler* RCSGetResponse::getHandler() const
77         {
78             return m_handler.get();
79         }
80
81
82         RCSSetResponse RCSSetResponse::defaultAction()
83         {
84             return std::make_shared< SetRequestHandler >();
85         }
86
87         RCSSetResponse RCSSetResponse::accept()
88         {
89             return defaultAction().setAcceptanceMethod(AcceptanceMethod::ACCEPT);
90         }
91
92         RCSSetResponse RCSSetResponse::accept(const OCEntityHandlerResult& result,
93                 int errorCode)
94         {
95             return create(result, errorCode).setAcceptanceMethod(AcceptanceMethod::ACCEPT);
96         }
97
98         RCSSetResponse RCSSetResponse::ignore()
99         {
100             return defaultAction().setAcceptanceMethod(AcceptanceMethod::IGNORE);
101         }
102
103         RCSSetResponse RCSSetResponse::ignore(const OCEntityHandlerResult& result,
104                 int errorCode)
105         {
106             return create(result, errorCode).setAcceptanceMethod(AcceptanceMethod::IGNORE);
107         }
108
109         RCSSetResponse RCSSetResponse::create(const OCEntityHandlerResult& result,
110                 int errorCode)
111         {
112             return std::make_shared< SetRequestHandler >(result, errorCode);
113         }
114
115         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs)
116         {
117             return std::make_shared< SetRequestHandler >(attrs);
118         }
119
120         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs,
121                 const OCEntityHandlerResult& result, int errorCode)
122         {
123             return std::make_shared< SetRequestHandler >(attrs, result, errorCode);
124         }
125
126         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& result)
127         {
128             return std::make_shared< SetRequestHandler >(std::move(result));
129         }
130
131         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& attrs,
132                 const OCEntityHandlerResult& result, int errorCode)
133         {
134             return std::make_shared< SetRequestHandler >(std::move(attrs), result, errorCode);
135         }
136
137         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler) :
138                 m_acceptanceMethod { AcceptanceMethod::DEFAULT },
139                 m_handler{ std::move(handler) }
140         {
141         }
142
143         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler,
144                 AcceptanceMethod method) :
145                 m_acceptanceMethod{ method },
146                 m_handler{ std::move(handler) }
147         {
148             assert(m_handler);
149         }
150
151         SetRequestHandler* RCSSetResponse::getHandler() const
152         {
153             return m_handler.get();
154         }
155
156         auto RCSSetResponse::getAcceptanceMethod() const -> AcceptanceMethod
157         {
158             return m_acceptanceMethod;
159         }
160
161         RCSSetResponse& RCSSetResponse::setAcceptanceMethod(AcceptanceMethod method)
162         {
163             m_acceptanceMethod = method;
164             return *this;
165         }
166     }
167 }