d94b555ecd18d5177cc3e7ddce08c702dac99aab
[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             /**
131              * Creates a RCSGetResponse for the separate response.
132              * The separate response is to delay sending actual response to the client.
133              *
134              * @note A separate response needs to be set with RCSSeparateResponse
135              * to send the result of the request.
136              *
137              * @see RCSSeparateResponse
138              */
139             static RCSGetResponse separate();
140
141             /**
142              * Returns whether it is a separate response.
143              *
144              * @see separate()
145              */
146             bool isSeparate() const;
147
148             //! @cond
149             RequestHandler* getHandler() const;
150             //! @endcond
151
152         private:
153             RCSGetResponse();
154             RCSGetResponse(std::shared_ptr< RequestHandler >&&);
155
156         private:
157             std::shared_ptr< RequestHandler > m_handler;
158         };
159
160         /**
161          * This class provides factory methods to create the response for a received set request.
162          * The response consists of an error code and result attributes.
163          *
164          * AcceptanceMethod provides ways how the request will be handled.
165          *
166          * @see RCSResourceObject
167          */
168         class RCSSetResponse
169         {
170         public:
171             /**
172              * Options for handling a set request.
173              *
174              * This overrides SetRequestHandlerPolicy.
175              *
176              * @see SetRequestHandlerPolicy
177              *
178              */
179             enum class AcceptanceMethod
180             {
181                 /**
182                  * Follow SetRequestHandlerPolicy of the RCSResourceObject.
183                  */
184                 DEFAULT,
185
186                 /**
187                  * Accept the request attributes even if there is an unknown key or mismatched type.
188                  */
189                 ACCEPT,
190
191                 /**
192                  * Ignore the request attributes.
193                  */
194                 IGNORE
195             };
196
197             /**
198              * Creates a default RCSSetResponse that has AcceptanceMethod::DEFAULT.
199              * The response will have 200 for the errorCode.
200              * The attributes of RCSResourceObject will be set as the result attributes.
201              *
202              */
203             static RCSSetResponse defaultAction();
204
205             /**
206              * Creates a default RCSSetResponse that has AcceptanceMethod::ACCEPT.
207              * The response will have 200 for the errorCode.
208              * The attributes of RCSResourceObject will be set as the result attributes.
209              *
210              * @see accept(int)
211              */
212             static RCSSetResponse accept();
213
214             /**
215              * Creates a RCSSetResponse that has AcceptanceMethod::ACCEPT and error code passed.
216              * The attributes of the RCSResourceObject will be set as the result attributes.
217              *
218              * @overload
219              * @param errorCode The error code to set in response.
220              *
221              * @see accept()
222              */
223             static RCSSetResponse accept(int errorCode);
224
225             /**
226              * Creates a default RCSSetResponse that has AcceptanceMethod::IGNORE.
227              * The response will have 200 for the errorCode.
228              * The attributes of RCSResourceObject will be set as the result attributes.
229              *
230              */
231             static RCSSetResponse ignore();
232
233             /**
234              * Creates a RCSSetResponse that has AcceptanceMethod::IGNORE and error code passed.
235              * The attributes of the RCSResourceObject will be set as the result attributes.
236              *
237              * @param errorCode The error code to set in response.
238              *
239              */
240             static RCSSetResponse ignore(int errorCode);
241
242             /**
243              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT and error code passed.
244              * The attributes of the RCSResourceObject will be set as the result attributes.
245              *
246              * @overload
247              * @param errorCode The error code to set in response.
248              * @see create(const RCSResourceAttributes&)
249              * @see create(RCSResourceAttributes&&)
250              * @see create(const RCSResourceAttributes&, int)
251              * @see create(RCSResourceAttributes&&, int)
252              */
253             static RCSSetResponse create(int errorCode);
254
255             /**
256              * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT with custom attributes.
257              * This sends the passed attributes as the result attributes
258              * instead of the one the RCSResourceObject holds.
259              *
260              * @overload
261              * @param attrs The attributes to set.
262              *
263              * @see RCSResourceAttributes
264              * @see create(int)
265              * @see create(RCSResourceAttributes&&)
266              * @see create(const RCSResourceAttributes&, int)
267              * @see create(RCSResourceAttributes&&, int)
268              */
269             static RCSSetResponse create(const RCSResourceAttributes& attrs);
270
271             /**
272              * @overload
273              * @param attrs The attributes to set.
274              * @see RCSResourceAttributes
275              * @see create(int)
276              * @see create(const RCSResourceAttributes&)
277              * @see create(const RCSResourceAttributes&, int)
278              * @see create(RCSResourceAttributes&&, int)
279              */
280             static RCSSetResponse create(RCSResourceAttributes&& attrs);
281
282             /**
283              * Creates a RCSSetResponse with error code passed.
284              * This sends the passed attributes as the result attributes
285              * instead of the one the RCSResourceObject holds.
286              *
287              * @overload
288              * @param attrs The attributes to set.
289              * @param errorCode The error code for response.
290              *
291              * @see RCSResourceAttributes
292              * @see create(int)
293              * @see create(const RCSResourceAttributes&)
294              * @see create(RCSResourceAttributes&&)
295              * @see create(RCSResourceAttributes&&, int)
296              */
297             static RCSSetResponse create(const RCSResourceAttributes& attrs, int errorCode);
298
299             /**
300              * @overload
301              * @param attrs The attributes to set.
302              * @param errorCode The error code for response.
303              * @see RCSResourceAttributes
304              * @see create(int)
305              * @see create(const RCSResourceAttributes&)
306              * @see create(RCSResourceAttributes&&)
307              * @see create(const RCSResourceAttributes&, int)
308              */
309             static RCSSetResponse create(RCSResourceAttributes&& attrs, int errorCode);
310
311             /**
312              * Creates a RCSSetResponse for a separate response.
313              * The separate response is to delay sending actual response to the client.
314              *
315              * @note A separate response needs to be set with RCSSeparateResponse
316              * to send the result of the request.
317              *
318              * @see RCSSeparateResponse
319              */
320             static RCSSetResponse separate();
321
322             /**
323              * Returns whether it is a separate response.
324              *
325              * @see separate()
326              */
327             bool isSeparate() const;
328
329             //! @cond
330             SetRequestHandler* getHandler() const;
331             //! @endcond
332
333             /**
334              * Returns the acceptance method.
335              *
336              */
337             AcceptanceMethod getAcceptanceMethod() const;
338
339             /**
340              * Sets the acceptance method for the RCSSetResponse.
341              *
342              * @param method AcceptanceMethod value to set
343              *
344              * @return The reference to this RCSSetResponse
345              *
346              * @see AcceptanceMethod
347              *
348              */
349             RCSSetResponse& setAcceptanceMethod(AcceptanceMethod method);
350
351         private:
352             RCSSetResponse();
353             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
354             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
355
356         private:
357             AcceptanceMethod m_acceptanceMethod;
358             std::shared_ptr< SetRequestHandler > m_handler;
359         };
360     }
361 }
362
363 #endif // SERVERBUILDER_RCSRESPONSE_H