b40cd9f24eb45d97195acdc80b5e2b96740d1ed3
[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  * @file
23  *
24  * This file contains the classes for creating Get & Set response for the Get & Set request.
25  */
26 #ifndef SERVERBUILDER_RCSRESPONSE_H
27 #define SERVERBUILDER_RCSRESPONSE_H
28
29 #include <cstdint>
30 #include <memory>
31
32 #include <octypes.h>
33
34 namespace OIC
35 {
36     namespace Service
37     {
38         //forward declaration of classes
39         class ResourceAttributes;
40
41         class RequestHandler;
42         class SetRequestHandler;
43
44         /**
45          * @class   RCSGetResponse
46          * @brief   This class provides APIs to create the response for the recieved Get request.
47          */
48         class RCSGetResponse
49         {
50         public:
51                 /**
52                 * Create RCSGetResponse with default response.
53                 *
54                 * @return RCSGetResponse - instance of RCSGetResponse
55                 */
56             static RCSGetResponse defaultAction();
57
58                 /**
59                 * Create RCSGetResponse using OCEntityHandlerResult value and error code provided.
60                 *
61                 * @param result -OCEntityHandlerResult
62                 *
63                 * @param errorCode - error code to set in response
64                 *
65                 * @return RCSGetResponse - instance of RCSGetResponse
66                 *
67                 * NOTE : OCEntityHandlerResult is defined in octypes.h
68                 */
69                 static RCSGetResponse create(const OCEntityHandlerResult &result, int errorCode);
70
71                 /**
72                 * Create RCSGetResponse using resource attributes.
73                 *
74                 * @param attrs -ResourceAttributes to set
75                 *
76                 * @return RCSGetResponse - instance of RCSGetResponse
77                 *
78                 * @see ResourceAttributes
79                 *
80                 * NOTE : ResourceAttributes is defined in ResourceAttributes.h
81                 */
82                 static RCSGetResponse create(const ResourceAttributes &attrs);
83                 /**
84                 * Create RCSGetResponse using ResourceAttributes, OCEntityHandlerResult and error code.
85                 *
86                 * @param attrs - ResourceAttributes to set
87                 *
88                 * @param result - OCEntityHandlerResult
89                 *
90                 * @param errorCode - error code for response
91                 *
92                 * @return RCSGetResponse - instance of RCSGetResponse
93                 *
94                 * @see ResourceAttributes
95                 *
96                 *NOTE : OCEntityHandlerResult is defined in octypes.h.
97                 *           ResourceAttributes is defined in ResourceAttributes.h.
98                 */
99                 static RCSGetResponse create(const ResourceAttributes &attrs,
100                                              const OCEntityHandlerResult &result, int errorCode);
101
102                 /**
103                 * Create RCSGetResponse using ResourceAttributes value.
104                 *
105                 * @param attrs - ResourceAttributes to set
106                 *
107                 * @return RCSGetResponse - instance of RCSGetResponse
108                 *
109                 * @see ResourceAttributes
110                 *
111                 *NOTE : ResourceAttributes is defined in ResourceAttributes.h.
112                 */
113                 static RCSGetResponse create(ResourceAttributes &&attrs);
114                 /**
115                 * Create RCSGetResponse using ResourceAttributes value.
116                 *
117                 * @param attrs - ResourceAttributes to set
118                 *
119                 * @param result - OCEntityHandlerResult
120                 *
121                 * @param errorCode - error code for response
122                 *
123                 * @return RCSGetResponse - instance of RCSGetResponse
124                 *
125                 * @see ResourceAttributes
126                 *
127                 *NOTE : OCEntityHandlerResult is defined in octypes.h.
128                 *           ResourceAttributes is defined in ResourceAttributes.h.
129                 */
130                 static RCSGetResponse create(ResourceAttributes &&attrs, const OCEntityHandlerResult &result,
131                                              int errorCode);
132
133                 /**
134                 * Get the request handler.
135                 *
136                 * @return RequestHandler - RequestHandler pointer.
137                 *
138                 */
139             RequestHandler* getHandler() const;
140
141         private:
142             RCSGetResponse(std::shared_ptr< RequestHandler >&&);
143
144         private:
145             std::shared_ptr< RequestHandler > m_handler;
146         };
147
148         /**
149          * @class   RCSSetResponse
150          * @brief   This class provides API to create a response for received Set request.
151          */
152         class RCSSetResponse
153         {
154         public:
155                 /**
156                  * AcceptanceMethod enum provides values for different acceptance method policy to be
157                  * used in setting response.
158                  */
159                 enum class AcceptanceMethod
160             {
161                 DEFAULT,
162                 ACCEPT,
163                 IGNORE
164             };
165
166                 /**
167                 * Create default RCSSetResponse with default response.
168                 *
169                 * @return RCSSetResponse - instance of RCSSetResponse
170                 */
171             static RCSSetResponse defaultAction();
172
173                 /**
174                 * Internally it invokes the defaultAction() API.
175                 *  It sets the AcceptanceMethod as ACCEPT.
176                 *
177                 * @return RCSSetResponse - instance of RCSSetResponse
178                 *
179                 * @see AcceptanceMethod
180                 */
181             static RCSSetResponse accept();
182                 /**
183                 * Internally it invokes the create(const OCEntityHandlerResult&, int errorCode) API.
184                 * It sets the AcceptanceMethod as ACCEPT.
185                 *
186                 * @param result - OCEntityHandlerResult value.
187                 *
188                 * @param errorCode - error code for the response
189                 *
190                 * @return RCSSetResponse - instance of RCSSetResponse
191                 *
192                 * @see AcceptanceMethod
193                 *
194                 *NOTE : OCEntityHandlerResult is defined in octypes.h
195                 */
196                 static RCSSetResponse accept(const OCEntityHandlerResult &result, int errorCode);
197
198                 /**
199                 * Internally it invokes the defaultAction() API.
200                 * It sets the AcceptanceMethod as IGNORE.
201                 *
202                 * @return RCSSetResponse - instance of RCSSetResponse.
203                 *
204                 *  @see AcceptanceMethod
205                 */
206             static RCSSetResponse ignore();
207                 /**
208                 * Internaly it invokes the create(const OCEntityHandlerResult&, int errorCode) API.
209                 * It sets the AcceptanceMethod as IGNORE.
210                 *
211                 * @param result - OCEntityHandlerResult value.
212                 *
213                 * @param errorCode - error code for the response.
214                 *
215                 * @return RCSSetResponse - instance of RCSSetResponse.
216                 *
217                 *  @see AcceptanceMethod
218                 *
219                 *NOTE : OCEntityHandlerResult is defined in octypes.h
220                 */
221                 static RCSSetResponse ignore(const OCEntityHandlerResult &result, int errorCode);
222
223                 /**
224                 * Create RCSSetResponse with OCEntityHandlerResult and errorCode.
225                 *
226                 * @param result - OCEntityHandlerResult value
227                 *
228                 * @param errorCode - error code for the response
229                 *
230                 * @return RCSSetResponse - instance of RCSSetResponse
231                 *
232                 *NOTE : OCEntityHandlerResult is defined in octypes.h
233                 */
234                 static RCSSetResponse create(const OCEntityHandlerResult &result, int errorCode);
235
236                 /**
237                 * Create RCSSetResponse with ResourceAttributes.
238                 *
239                 * @param attrs - ResourceAttributes to set
240                 *
241                 * @return RCSSetResponse - instance of RCSSetResponse
242                 *
243                 * @see ResourceAttributes
244                 */
245                 static RCSSetResponse create(const ResourceAttributes &attrs);
246                 /**
247                 * Create RCSSetResponse with ResourceAttributes, OCEntityHandlerResult and errorCode.
248                 *
249                 * @param attrs - ResourceAttributes to set.
250                 *
251                 * @param result - OCEntityHandlerResult value
252                 *
253                 * @param errorCode - error code for the response
254                 *
255                 * @return RCSSetResponse - instance of RCSSetResponse
256                 *
257                 * @see ResourceAttributes
258                 *
259                 *NOTE : OCEntityHandlerResult is defined in octypes.h.
260                 */
261                 static RCSSetResponse create(const ResourceAttributes &attrs,
262                                              const OCEntityHandlerResult &result, int errorCode);
263
264                 /**
265                 * Create RCSSetResponse with ResourceAttributes.
266                 *
267                 * @param attrs - ResourceAttributes value to set
268                 *
269                 * @return RCSSetResponse - instance of RCSSetResponse
270                 *
271                 * @see ResourceAttributes
272                 */
273                 static RCSSetResponse create(ResourceAttributes &&attrs);
274                 /**
275                 * Create RCSSetResponse with ResourceAttributes, OCEntityHandlerResult and errorCode.
276                 *
277                 * @param attrs - ResourceAttributes value to set
278                 *
279                 * @param result - OCEntityHandlerResult value
280                 *
281                 * @param errorCode - error code for the response
282                 *
283                 * @return RCSSetResponse - instance of RCSSetResponse
284                 *
285                 * @see ResourceAttributes
286                 *
287                 *NOTE : OCEntityHandlerResult is defined in octypes.h.
288                 */
289                 static RCSSetResponse create(ResourceAttributes &&attrs, const OCEntityHandlerResult &result,
290                                              int errorCode);
291
292                 /**
293                 * API to get the set request handler.
294                 *
295                 * @return SetRequestHandler - pointer to SetRequestHandler.
296                 *
297                 */
298             SetRequestHandler* getHandler() const;
299
300                 /**
301                 * API to get the acceptance method of the  RCSSetResponse.
302                 *
303                 * @return AcceptanceMethod - acceptance methods enum value.
304                 *
305                 * @see AcceptanceMethod
306                 *
307                 */
308             AcceptanceMethod getAcceptanceMethod() const;
309
310                 /**
311                 * API to get the acceptance method of the  RCSSetResponse.
312                 *
313                 * @param method - AcceptanceMethod value to set
314                 *
315                 * @return RCSSetResponse - reference to RCSSetResponse
316                 *
317                 * @see AcceptanceMethod
318                 *
319                 */
320                 RCSSetResponse &setAcceptanceMethod(AcceptanceMethod method);
321
322         private:
323             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
324             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
325
326         private:
327             AcceptanceMethod m_acceptanceMethod;
328             std::shared_ptr< SetRequestHandler > m_handler;
329         };
330     }
331 }
332
333 #endif // SERVERBUILDER_RCSRESPONSE_H