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