Rename ResourceAttributes to RCSResourceAttributes
[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 RCSResourceAttributes;
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 -RCSResourceAttributes to set
75              *
76              * @return RCSGetResponse - instance of RCSGetResponse
77              *
78              * @see RCSResourceAttributes
79              *
80              * NOTE : RCSResourceAttributes is defined in RCSResourceAttributes.h
81              */
82             static RCSGetResponse create(const RCSResourceAttributes &attrs);
83             /**
84              * Create RCSGetResponse using RCSResourceAttributes, OCEntityHandlerResult and error code.
85              *
86              * @param attrs - RCSResourceAttributes 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 RCSResourceAttributes
95              *
96              *NOTE : OCEntityHandlerResult is defined in octypes.h.
97              *           RCSResourceAttributes is defined in RCSResourceAttributes.h.
98              */
99             static RCSGetResponse create(const RCSResourceAttributes &attrs,
100                     const OCEntityHandlerResult &result, int errorCode);
101
102             /**
103              * Create RCSGetResponse using RCSResourceAttributes value.
104              *
105              * @param attrs - RCSResourceAttributes to set
106              *
107              * @return RCSGetResponse - instance of RCSGetResponse
108              *
109              * @see RCSResourceAttributes
110              *
111              *NOTE : RCSResourceAttributes is defined in RCSResourceAttributes.h.
112              */
113             static RCSGetResponse create(RCSResourceAttributes &&attrs);
114             /**
115              * Create RCSGetResponse using RCSResourceAttributes value.
116              *
117              * @param attrs - RCSResourceAttributes 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 RCSResourceAttributes
126              *
127              *NOTE : OCEntityHandlerResult is defined in octypes.h.
128              *           RCSResourceAttributes is defined in RCSResourceAttributes.h.
129              */
130             static RCSGetResponse create(RCSResourceAttributes &&attrs,
131                     const OCEntityHandlerResult &result, 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, ACCEPT, IGNORE
162             };
163
164             /**
165              * Create default RCSSetResponse with default response.
166              *
167              * @return RCSSetResponse - instance of RCSSetResponse
168              */
169             static RCSSetResponse defaultAction();
170
171             /**
172              * Internally it invokes the defaultAction() API.
173              *  It sets the AcceptanceMethod as ACCEPT.
174              *
175              * @return RCSSetResponse - instance of RCSSetResponse
176              *
177              * @see AcceptanceMethod
178              */
179             static RCSSetResponse accept();
180             /**
181              * Internally it invokes the create(const OCEntityHandlerResult&, int errorCode) API.
182              * It sets the AcceptanceMethod as ACCEPT.
183              *
184              * @param result - OCEntityHandlerResult value.
185              *
186              * @param errorCode - error code for the response
187              *
188              * @return RCSSetResponse - instance of RCSSetResponse
189              *
190              * @see AcceptanceMethod
191              *
192              *NOTE : OCEntityHandlerResult is defined in octypes.h
193              */
194             static RCSSetResponse accept(const OCEntityHandlerResult &result, int errorCode);
195
196             /**
197              * Internally it invokes the defaultAction() API.
198              * It sets the AcceptanceMethod as IGNORE.
199              *
200              * @return RCSSetResponse - instance of RCSSetResponse.
201              *
202              *  @see AcceptanceMethod
203              */
204             static RCSSetResponse ignore();
205             /**
206              * Internaly it invokes the create(const OCEntityHandlerResult&, int errorCode) API.
207              * It sets the AcceptanceMethod as IGNORE.
208              *
209              * @param result - OCEntityHandlerResult value.
210              *
211              * @param errorCode - error code for the response.
212              *
213              * @return RCSSetResponse - instance of RCSSetResponse.
214              *
215              *  @see AcceptanceMethod
216              *
217              *NOTE : OCEntityHandlerResult is defined in octypes.h
218              */
219             static RCSSetResponse ignore(const OCEntityHandlerResult &result, int errorCode);
220
221             /**
222              * Create RCSSetResponse with OCEntityHandlerResult and errorCode.
223              *
224              * @param result - OCEntityHandlerResult value
225              *
226              * @param errorCode - error code for the response
227              *
228              * @return RCSSetResponse - instance of RCSSetResponse
229              *
230              *NOTE : OCEntityHandlerResult is defined in octypes.h
231              */
232             static RCSSetResponse create(const OCEntityHandlerResult &result, int errorCode);
233
234             /**
235              * Create RCSSetResponse with RCSResourceAttributes.
236              *
237              * @param attrs - RCSResourceAttributes to set
238              *
239              * @return RCSSetResponse - instance of RCSSetResponse
240              *
241              * @see RCSResourceAttributes
242              */
243             static RCSSetResponse create(const RCSResourceAttributes &attrs);
244             /**
245              * Create RCSSetResponse with RCSResourceAttributes, OCEntityHandlerResult and errorCode.
246              *
247              * @param attrs - RCSResourceAttributes to set.
248              *
249              * @param result - OCEntityHandlerResult value
250              *
251              * @param errorCode - error code for the response
252              *
253              * @return RCSSetResponse - instance of RCSSetResponse
254              *
255              * @see RCSResourceAttributes
256              *
257              *NOTE : OCEntityHandlerResult is defined in octypes.h.
258              */
259             static RCSSetResponse create(const RCSResourceAttributes &attrs,
260                     const OCEntityHandlerResult &result, int errorCode);
261
262             /**
263              * Create RCSSetResponse with RCSResourceAttributes.
264              *
265              * @param attrs - RCSResourceAttributes value to set
266              *
267              * @return RCSSetResponse - instance of RCSSetResponse
268              *
269              * @see RCSResourceAttributes
270              */
271             static RCSSetResponse create(RCSResourceAttributes &&attrs);
272             /**
273              * Create RCSSetResponse with RCSResourceAttributes, OCEntityHandlerResult and errorCode.
274              *
275              * @param attrs - RCSResourceAttributes value to set
276              *
277              * @param result - OCEntityHandlerResult value
278              *
279              * @param errorCode - error code for the response
280              *
281              * @return RCSSetResponse - instance of RCSSetResponse
282              *
283              * @see RCSResourceAttributes
284              *
285              *NOTE : OCEntityHandlerResult is defined in octypes.h.
286              */
287             static RCSSetResponse create(RCSResourceAttributes &&attrs,
288                     const OCEntityHandlerResult &result, int errorCode);
289
290             /**
291              * API to get the set request handler.
292              *
293              * @return SetRequestHandler - pointer to SetRequestHandler.
294              *
295              */
296             SetRequestHandler* getHandler() const;
297
298             /**
299              * API to get the acceptance method of the  RCSSetResponse.
300              *
301              * @return AcceptanceMethod - acceptance methods enum value.
302              *
303              * @see AcceptanceMethod
304              *
305              */
306             AcceptanceMethod getAcceptanceMethod() const;
307
308             /**
309              * API to get the acceptance method of the  RCSSetResponse.
310              *
311              * @param method - AcceptanceMethod value to set
312              *
313              * @return RCSSetResponse - reference to RCSSetResponse
314              *
315              * @see AcceptanceMethod
316              *
317              */
318             RCSSetResponse &setAcceptanceMethod(AcceptanceMethod method);
319
320         private:
321             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
322             RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
323
324         private:
325             AcceptanceMethod m_acceptanceMethod;
326             std::shared_ptr< SetRequestHandler > m_handler;
327         };
328     }
329 }
330
331 #endif // SERVERBUILDER_RCSRESPONSE_H