9a91c61fc2d5f53624e7e6809679ffb661835919
[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(std::shared_ptr< RequestHandler >&& handler) :
65                 m_handler{ std::move(handler) }
66         {
67             assert(m_handler);
68         }
69
70         RequestHandler* RCSGetResponse::getHandler() const
71         {
72             return m_handler.get();
73         }
74
75
76         RCSSetResponse RCSSetResponse::defaultAction()
77         {
78             return std::make_shared< SetRequestHandler >();
79         }
80
81         RCSSetResponse RCSSetResponse::accept()
82         {
83             return defaultAction().setAcceptanceMethod(AcceptanceMethod::ACCEPT);
84         }
85
86         RCSSetResponse RCSSetResponse::accept(int errorCode)
87         {
88             return create(errorCode).setAcceptanceMethod(AcceptanceMethod::ACCEPT);
89         }
90
91         RCSSetResponse RCSSetResponse::ignore()
92         {
93             return defaultAction().setAcceptanceMethod(AcceptanceMethod::IGNORE);
94         }
95
96         RCSSetResponse RCSSetResponse::ignore(int errorCode)
97         {
98             return create(errorCode).setAcceptanceMethod(AcceptanceMethod::IGNORE);
99         }
100
101         RCSSetResponse RCSSetResponse::create(int errorCode)
102         {
103             return std::make_shared< SetRequestHandler >(errorCode);
104         }
105
106         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs)
107         {
108             return std::make_shared< SetRequestHandler >(attrs);
109         }
110
111         RCSSetResponse RCSSetResponse::create(const RCSResourceAttributes& attrs, int errorCode)
112         {
113             return std::make_shared< SetRequestHandler >(attrs, errorCode);
114         }
115
116         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& result)
117         {
118             return std::make_shared< SetRequestHandler >(std::move(result));
119         }
120
121         RCSSetResponse RCSSetResponse::create(RCSResourceAttributes&& attrs, int errorCode)
122         {
123             return std::make_shared< SetRequestHandler >(std::move(attrs), errorCode);
124         }
125
126         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler) :
127                 m_acceptanceMethod { AcceptanceMethod::DEFAULT },
128                 m_handler{ std::move(handler) }
129         {
130         }
131
132         RCSSetResponse::RCSSetResponse(std::shared_ptr< SetRequestHandler >&& handler,
133                 AcceptanceMethod method) :
134                 m_acceptanceMethod{ method },
135                 m_handler{ std::move(handler) }
136         {
137             assert(m_handler);
138         }
139
140         SetRequestHandler* RCSSetResponse::getHandler() const
141         {
142             return m_handler.get();
143         }
144
145         auto RCSSetResponse::getAcceptanceMethod() const -> AcceptanceMethod
146         {
147             return m_acceptanceMethod;
148         }
149
150         RCSSetResponse& RCSSetResponse::setAcceptanceMethod(AcceptanceMethod method)
151         {
152             m_acceptanceMethod = method;
153             return *this;
154         }
155     }
156 }