1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 * This file contains the declaration of classes and its members related to RCSResponse
27 #ifndef SERVERBUILDER_RCSRESPONSE_H
28 #define SERVERBUILDER_RCSRESPONSE_H
36 class RCSResourceAttributes;
39 class SetRequestHandler;
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.
45 * @see RCSResourceObject
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.
56 static RCSGetResponse defaultAction();
59 * Creates a RCSGetResponse with error code passed.
60 * The attributes of the RCSResourceObject will be set as the result attributes.
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)
68 static RCSGetResponse create(int errorCode);
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.
76 * @param attrs The attributes to set.
78 * @see RCSResourceAttributes
80 * @see create(RCSResourceAttributes&&)
81 * @see create(const RCSResourceAttributes&, int)
82 * @see create(RCSResourceAttributes&&, int)
85 static RCSGetResponse create(const RCSResourceAttributes& attrs);
89 * @param attrs The attributes to set.
91 * @see RCSResourceAttributes
93 * @see create(const RCSResourceAttributes&)
94 * @see create(const RCSResourceAttributes&, int)
95 * @see create(RCSResourceAttributes&&, int)
97 static RCSGetResponse create(RCSResourceAttributes&& attrs);
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.
105 * @param attrs The attributes to set.
106 * @param errorCode The error code for response.
108 * @see RCSResourceAttributes
110 * @see create(const RCSResourceAttributes&)
111 * @see create(RCSResourceAttributes&&)
112 * @see create(const RCSResourceAttributes&, int)
113 * @see create(RCSResourceAttributes&&, int)
115 static RCSGetResponse create(const RCSResourceAttributes& attrs, int errorCode);
119 * @param attrs The attributes to set.
120 * @param errorCode The error code for response.
122 * @see RCSResourceAttributes
124 * @see create(const RCSResourceAttributes&)
125 * @see create(RCSResourceAttributes&&)
126 * @see create(const RCSResourceAttributes&, int)
128 static RCSGetResponse create(RCSResourceAttributes&& attrs, int errorCode);
131 * Creates a RCSGetResponse for the separate response.
132 * The separate response is to delay sending actual response to the client.
134 * @note A separate response needs to be set with RCSSeparateResponse
135 * to send the result of the request.
137 * @see RCSSeparateResponse
139 static RCSGetResponse separate();
142 * Returns whether it is a separate response.
146 bool isSeparate() const;
149 RequestHandler* getHandler() const;
154 RCSGetResponse(std::shared_ptr< RequestHandler >&&);
157 std::shared_ptr< RequestHandler > m_handler;
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.
164 * AcceptanceMethod provides ways how the request will be handled.
166 * @see RCSResourceObject
172 * Options for handling a set request.
174 * This overrides SetRequestHandlerPolicy.
176 * @see SetRequestHandlerPolicy
179 enum class AcceptanceMethod
182 * Follow SetRequestHandlerPolicy of the RCSResourceObject.
187 * Accept the request attributes even if there is an unknown key or mismatched type.
192 * Ignore the request attributes.
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.
203 static RCSSetResponse defaultAction();
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.
212 static RCSSetResponse accept();
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.
219 * @param errorCode The error code to set in response.
223 static RCSSetResponse accept(int errorCode);
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.
231 static RCSSetResponse ignore();
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.
237 * @param errorCode The error code to set in response.
240 static RCSSetResponse ignore(int errorCode);
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.
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)
253 static RCSSetResponse create(int errorCode);
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.
261 * @param attrs The attributes to set.
263 * @see RCSResourceAttributes
265 * @see create(RCSResourceAttributes&&)
266 * @see create(const RCSResourceAttributes&, int)
267 * @see create(RCSResourceAttributes&&, int)
269 static RCSSetResponse create(const RCSResourceAttributes& attrs);
273 * @param attrs The attributes to set.
274 * @see RCSResourceAttributes
276 * @see create(const RCSResourceAttributes&)
277 * @see create(const RCSResourceAttributes&, int)
278 * @see create(RCSResourceAttributes&&, int)
280 static RCSSetResponse create(RCSResourceAttributes&& attrs);
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.
288 * @param attrs The attributes to set.
289 * @param errorCode The error code for response.
291 * @see RCSResourceAttributes
293 * @see create(const RCSResourceAttributes&)
294 * @see create(RCSResourceAttributes&&)
295 * @see create(RCSResourceAttributes&&, int)
297 static RCSSetResponse create(const RCSResourceAttributes& attrs, int errorCode);
301 * @param attrs The attributes to set.
302 * @param errorCode The error code for response.
303 * @see RCSResourceAttributes
305 * @see create(const RCSResourceAttributes&)
306 * @see create(RCSResourceAttributes&&)
307 * @see create(const RCSResourceAttributes&, int)
309 static RCSSetResponse create(RCSResourceAttributes&& attrs, int errorCode);
312 * Creates a RCSSetResponse for a separate response.
313 * The separate response is to delay sending actual response to the client.
315 * @note A separate response needs to be set with RCSSeparateResponse
316 * to send the result of the request.
318 * @see RCSSeparateResponse
320 static RCSSetResponse separate();
323 * Returns whether it is a separate response.
327 bool isSeparate() const;
330 SetRequestHandler* getHandler() const;
334 * Returns the acceptance method.
337 AcceptanceMethod getAcceptanceMethod() const;
340 * Sets the acceptance method for the RCSSetResponse.
342 * @param method AcceptanceMethod value to set
344 * @return The reference to this RCSSetResponse
346 * @see AcceptanceMethod
349 RCSSetResponse& setAcceptanceMethod(AcceptanceMethod method);
353 RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
354 RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
357 AcceptanceMethod m_acceptanceMethod;
358 std::shared_ptr< SetRequestHandler > m_handler;
363 #endif // SERVERBUILDER_RCSRESPONSE_H