Update comments for documents of resource-encapsulation
[platform/upstream/iotivity.git] / service / resource-encapsulation / include / RCSResponse.h
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
22 /**
23  * @file
24  *
25  * This file contains the declaration of classes and its members related to RCSResponse
26  */
27 #ifndef SERVERBUILDER_RCSRESPONSE_H
28 #define SERVERBUILDER_RCSRESPONSE_H
29
30 #include <memory>
31
32 namespace OIC
33 {
34     namespace Service
35     {
36         class RCSResourceAttributes;
37
38         class RequestHandler;
39         class SetRequestHandler;
40
41         /**
42          * This class provides factory methods to create the response for a received get request.
43          * The response consists of an error code and result attributes.
44          *
45          * @see RCSResourceObject
46          */
47         class RCSGetResponse
48         {
49         public:
50             /**
51              * Creates a default RCSGetResponse.
52              * The response will have 200 for the errorCode and the attributes of RCSResourceObject
53              * will be set as the result attributes.
54              *
55              */
56             static RCSGetResponse defaultAction();
57
58             /**
59              * Creates a RCSGetResponse with error code passed.
60              * The attributes of the RCSResourceObject will be set as the result attributes.
61              *
62              * @param errorCode The error code to set in response.
63              *
64              */
65             static RCSGetResponse create(int errorCode);
66
67             /**
68              * Creates a RCSGetResponse with custom attributes.
69              * This sends the passed attributes as the result attributes
70              * instead of the one the RCSResourceObject holds.
71              *
72              * @param attrs The attributes to set.
73              *
74              * @see RCSResourceAttributes
75              *
76              */
77             static RCSGetResponse create(const RCSResourceAttributes& attrs);
78
79             /**
80              * @override
81              */
82             static RCSGetResponse create(RCSResourceAttributes&& attrs);
83
84             /**
85              * Creates a RCSGetResponse with error code passed.
86              * This sends the passed attributes as the result attributes
87              * instead of the one the RCSResourceObject holds.
88              *
89              * @param attrs The attributes to set.
90              * @param errorCode The error code for response.
91              *
92              * @see RCSResourceAttributes
93              *
94              */
95             static RCSGetResponse create(const RCSResourceAttributes& attrs, int errorCode);
96
97             /**
98              * @override
99              */
100             static RCSGetResponse create(RCSResourceAttributes&& attrs, int errorCode);
101
102             //! @cond
103             RequestHandler* getHandler() const;
104             //! @endcond
105
106         private:
107             RCSGetResponse(std::shared_ptr< RequestHandler >&&);
108
109         private:
110             std::shared_ptr< RequestHandler > m_handler;
111         };
112
113         /**
114          * This class provides factory methods to create the response for a received set request.
115          * The response consists of an error code and result attributes.
116          *
117          * AcceptanceMethod provides ways how the request will be handled.
118          *
119          * @see RCSResourceObject
120          */
121         class RCSSetResponse
122         {
123         public:
124             /**
125              * Options for handling a set request.
126              *
127              * This overrides SetRequestHandlerPolicy.
128              *
129              * @see SetRequestHandlerPolicy
130              *
131              */
132             enum class AcceptanceMethod
133             {
134                 /**
135                  * Follow SetRequestHandlerPolicy of the RCSResourceObject.
136                  */
137                 DEFAULT,
138
139                 /**
140                  * Accept the request attributes even if there is an unknown key or mismatched type.
141                  */
142                 ACCEPT,
143
144                 /**
145                  * Ignore the request attributes.
146                  */
147                 IGNORE
148             };
149
150             /**
151              * Creates a default RCSSetResponse that has AcceptanceMethod::DEFAULT.
152              * The response will have 200 for the errorCode.
153              * The attributes of RCSResourceObject will be set as the result attributes.
154              *
155              */
156             static RCSSetResponse defaultAction();
157
158             /**
159              * Creates a default RCSSetResponse that has AcceptanceMethod::ACCEPT.
160              * The response will have 200 for the errorCode.
161              * The attributes of RCSResourceObject will be set as the result attributes.
162              *
163              */
164             static RCSSetResponse accept();
165
166             /**
167              * Creates a RCSSetResponse that has AcceptanceMethod::ACCEPT and error code passed.
168              * The attributes of the RCSResourceObject will be set as the result attributes.
169              *
170              * @param errorCode The error code to set in response.
171              *
172              */
173             static RCSSetResponse accept(int errorCode);
174
175             /**
176              * Creates a default RCSSetResponse that has AcceptanceMethod::IGNORE.
177              * The response will have 200 for the errorCode.
178              * The attributes of RCSResourceObject will be set as the result attributes.
179              *
180              */
181             static RCSSetResponse ignore();
182
183             /**
184              * Creates a RCSSetResponse that has AcceptanceMethod::IGNORE and error code passed.
185              * The attributes of the RCSResourceObject will be set as the result attributes.
186              *
187              * @param errorCode The error code to set in response.
188              *
189              */
190             static RCSSetResponse ignore(int errorCode);
191
192             /**
193              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT and error code passed.
194              * The attributes of the RCSResourceObject will be set as the result attributes.
195              *
196              * @param errorCode The error code to set in response.
197              *
198              */
199             static RCSSetResponse create(int errorCode);
200
201             /**
202              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT with custom attributes.
203              * This sends the passed attributes as the result attributes
204              * instead of the one the RCSResourceObject holds.
205              *
206              * @param attrs The attributes to set.
207              *
208              * @see RCSResourceAttributes
209              *
210              */
211             static RCSSetResponse create(const RCSResourceAttributes& attrs);
212
213             /**
214              * @override
215              */
216             static RCSSetResponse create(RCSResourceAttributes&& attrs);
217
218             /**
219              * Creates a RCSSetResponse with error code passed.
220              * This sends the passed attributes as the result attributes
221              * instead of the one the RCSResourceObject holds.
222              *
223              * @param attrs The attributes to set.
224              * @param errorCode The error code for response.
225              *
226              * @see RCSResourceAttributes
227              *
228              */
229             static RCSSetResponse create(const RCSResourceAttributes& attrs, int errorCode);
230
231             /**
232              * @override
233              */
234             static RCSSetResponse create(RCSResourceAttributes&& attrs, int errorCode);
235
236
237             //! @cond
238             SetRequestHandler* getHandler() const;
239             //! @endcond
240
241             /**
242              * Returns the acceptance method.
243              *
244              */
245             AcceptanceMethod getAcceptanceMethod() const;
246
247             /**
248              * Sets the acceptance method for the RCSSetResponse.
249              *
250              * @param method AcceptanceMethod value to set
251              *
252              * @return The reference to this RCSSetResponse
253              *
254              * @see AcceptanceMethod
255              *
256              */
257             RCSSetResponse& setAcceptanceMethod(AcceptanceMethod method);
258
259         private:
260             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
261             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
262
263         private:
264             AcceptanceMethod m_acceptanceMethod;
265             std::shared_ptr< SetRequestHandler > m_handler;
266         };
267     }
268 }
269
270 #endif // SERVERBUILDER_RCSRESPONSE_H