Added SeparateResponse class for the RCSResourceObject in RE.
[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              * @see create(const RCSResourceAttributes&)
64              * @see create(RCSResourceAttributes&&)
65              * @see create(const RCSResourceAttributes&, int)
66              * @see create(RCSResourceAttributes&&, int)
67              */
68             static RCSGetResponse create(int errorCode);
69
70             /**
71              * Creates a RCSGetResponse with custom attributes.
72              * This sends the passed attributes as the result attributes
73              * instead of the one the RCSResourceObject holds.
74              *
75              * @overload
76              * @param attrs The attributes to set.
77              *
78              * @see RCSResourceAttributes
79              * @see create(int)
80              * @see create(RCSResourceAttributes&&)
81              * @see create(const RCSResourceAttributes&, int)
82              * @see create(RCSResourceAttributes&&, int)
83              *
84              */
85             static RCSGetResponse create(const RCSResourceAttributes& attrs);
86
87             /**
88              * @overload
89              * @param attrs The attributes to set.
90              *
91              * @see RCSResourceAttributes
92              * @see create(int)
93              * @see create(const RCSResourceAttributes&)
94              * @see create(const RCSResourceAttributes&, int)
95              * @see create(RCSResourceAttributes&&, int)
96              */
97             static RCSGetResponse create(RCSResourceAttributes&& attrs);
98
99             /**
100              * Creates a RCSGetResponse with error code passed.
101              * This sends the passed attributes as the result attributes
102              * instead of the one the RCSResourceObject holds.
103              *
104              * @overload
105              * @param attrs The attributes to set.
106              * @param errorCode The error code for response.
107              *
108              * @see RCSResourceAttributes
109              * @see create(int)
110              * @see create(const RCSResourceAttributes&)
111              * @see create(RCSResourceAttributes&&)
112              * @see create(const RCSResourceAttributes&, int)
113              * @see create(RCSResourceAttributes&&, int)
114              */
115             static RCSGetResponse create(const RCSResourceAttributes& attrs, int errorCode);
116
117             /**
118              * @overload
119              * @param attrs The attributes to set.
120              * @param errorCode The error code for response.
121              *
122              * @see RCSResourceAttributes
123              * @see create(int)
124              * @see create(const RCSResourceAttributes&)
125              * @see create(RCSResourceAttributes&&)
126              * @see create(const RCSResourceAttributes&, int)
127              */
128             static RCSGetResponse create(RCSResourceAttributes&& attrs, int errorCode);
129
130             static RCSGetResponse separate();
131
132             bool isSeparate() const;
133
134             //! @cond
135             RequestHandler* getHandler() const;
136             //! @endcond
137
138         private:
139             RCSGetResponse();
140             RCSGetResponse(std::shared_ptr< RequestHandler >&&);
141
142         private:
143             std::shared_ptr< RequestHandler > m_handler;
144         };
145
146         /**
147          * This class provides factory methods to create the response for a received set request.
148          * The response consists of an error code and result attributes.
149          *
150          * AcceptanceMethod provides ways how the request will be handled.
151          *
152          * @see RCSResourceObject
153          */
154         class RCSSetResponse
155         {
156         public:
157             /**
158              * Options for handling a set request.
159              *
160              * This overrides SetRequestHandlerPolicy.
161              *
162              * @see SetRequestHandlerPolicy
163              *
164              */
165             enum class AcceptanceMethod
166             {
167                 /**
168                  * Follow SetRequestHandlerPolicy of the RCSResourceObject.
169                  */
170                 DEFAULT,
171
172                 /**
173                  * Accept the request attributes even if there is an unknown key or mismatched type.
174                  */
175                 ACCEPT,
176
177                 /**
178                  * Ignore the request attributes.
179                  */
180                 IGNORE
181             };
182
183             /**
184              * Creates a default RCSSetResponse that has AcceptanceMethod::DEFAULT.
185              * The response will have 200 for the errorCode.
186              * The attributes of RCSResourceObject will be set as the result attributes.
187              *
188              */
189             static RCSSetResponse defaultAction();
190
191             /**
192              * Creates a default RCSSetResponse that has AcceptanceMethod::ACCEPT.
193              * The response will have 200 for the errorCode.
194              * The attributes of RCSResourceObject will be set as the result attributes.
195              *
196              * @see accept(int)
197              */
198             static RCSSetResponse accept();
199
200             /**
201              * Creates a RCSSetResponse that has AcceptanceMethod::ACCEPT and error code passed.
202              * The attributes of the RCSResourceObject will be set as the result attributes.
203              *
204              * @overload
205              * @param errorCode The error code to set in response.
206              *
207              * @see accept()
208              */
209             static RCSSetResponse accept(int errorCode);
210
211             /**
212              * Creates a default RCSSetResponse that has AcceptanceMethod::IGNORE.
213              * The response will have 200 for the errorCode.
214              * The attributes of RCSResourceObject will be set as the result attributes.
215              *
216              */
217             static RCSSetResponse ignore();
218
219             /**
220              * Creates a RCSSetResponse that has AcceptanceMethod::IGNORE and error code passed.
221              * The attributes of the RCSResourceObject will be set as the result attributes.
222              *
223              * @param errorCode The error code to set in response.
224              *
225              */
226             static RCSSetResponse ignore(int errorCode);
227
228             /**
229              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT and error code passed.
230              * The attributes of the RCSResourceObject will be set as the result attributes.
231              *
232              * @overload
233              * @param errorCode The error code to set in response.
234              * @see create(const RCSResourceAttributes&)
235              * @see create(RCSResourceAttributes&&)
236              * @see create(const RCSResourceAttributes&, int)
237              * @see create(RCSResourceAttributes&&, int)
238              */
239             static RCSSetResponse create(int errorCode);
240
241             /**
242              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT with custom attributes.
243              * This sends the passed attributes as the result attributes
244              * instead of the one the RCSResourceObject holds.
245              *
246              * @overload
247              * @param attrs The attributes to set.
248              *
249              * @see RCSResourceAttributes
250              * @see create(int)
251              * @see create(RCSResourceAttributes&&)
252              * @see create(const RCSResourceAttributes&, int)
253              * @see create(RCSResourceAttributes&&, int)
254              */
255             static RCSSetResponse create(const RCSResourceAttributes& attrs);
256
257             /**
258              * @overload
259              * @param attrs The attributes to set.
260              * @see RCSResourceAttributes
261              * @see create(int)
262              * @see create(const RCSResourceAttributes&)
263              * @see create(const RCSResourceAttributes&, int)
264              * @see create(RCSResourceAttributes&&, int)
265              */
266             static RCSSetResponse create(RCSResourceAttributes&& attrs);
267
268             /**
269              * Creates a RCSSetResponse with error code passed.
270              * This sends the passed attributes as the result attributes
271              * instead of the one the RCSResourceObject holds.
272              *
273              * @overload
274              * @param attrs The attributes to set.
275              * @param errorCode The error code for response.
276              *
277              * @see RCSResourceAttributes
278              * @see create(int)
279              * @see create(const RCSResourceAttributes&)
280              * @see create(RCSResourceAttributes&&)
281              * @see create(RCSResourceAttributes&&, int)
282              */
283             static RCSSetResponse create(const RCSResourceAttributes& attrs, int errorCode);
284
285             /**
286              * @overload
287              * @param attrs The attributes to set.
288              * @param errorCode The error code for response.
289              * @see RCSResourceAttributes
290              * @see create(int)
291              * @see create(const RCSResourceAttributes&)
292              * @see create(RCSResourceAttributes&&)
293              * @see create(const RCSResourceAttributes&, int)
294              */
295             static RCSSetResponse create(RCSResourceAttributes&& attrs, int errorCode);
296
297             static RCSSetResponse separate();
298
299             bool isSeparate() const;
300
301             //! @cond
302             SetRequestHandler* getHandler() const;
303             //! @endcond
304
305             /**
306              * Returns the acceptance method.
307              *
308              */
309             AcceptanceMethod getAcceptanceMethod() const;
310
311             /**
312              * Sets the acceptance method for the RCSSetResponse.
313              *
314              * @param method AcceptanceMethod value to set
315              *
316              * @return The reference to this RCSSetResponse
317              *
318              * @see AcceptanceMethod
319              *
320              */
321             RCSSetResponse& setAcceptanceMethod(AcceptanceMethod method);
322
323         private:
324             RCSSetResponse();
325             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
326             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
327
328         private:
329             AcceptanceMethod m_acceptanceMethod;
330             std::shared_ptr< SetRequestHandler > m_handler;
331         };
332     }
333 }
334
335 #endif // SERVERBUILDER_RCSRESPONSE_H