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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the classes for creating Get & Set response for the Get & Set request.
26 #ifndef SERVERBUILDER_RCSRESPONSE_H
27 #define SERVERBUILDER_RCSRESPONSE_H
38 class RCSResourceAttributes;
41 class SetRequestHandler;
44 * This class provides factory methods to create the response for a received get request.
45 * The response consists of a result code, an error code and result attributes.
47 * @see RCSResourceObject
53 * Creates a default RCSGetResponse.
54 * The response will have OC_EH_OK for the result and 200 for the errorCode.
55 * The attributes of RCSResourceObject will be set as the result attributes.
58 static RCSGetResponse defaultAction();
61 * Creates a RCSGetResponse with a result and error code passed.
62 * The attributes of the RCSResourceObject will be set as the result attributes.
64 * @param result The response result.
65 * @param errorCode The error code to set in response.
68 static RCSGetResponse create(const OCEntityHandlerResult& result, 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.
75 * @param attrs The attributes to set.
77 * @see RCSResourceAttributes
80 static RCSGetResponse create(const RCSResourceAttributes& attrs);
85 static RCSGetResponse create(RCSResourceAttributes&& attrs);
88 * Creates a RCSGetResponse with a result and error code passed.
89 * This sends the passed attributes as the result attributes
90 * instead of the one the RCSResourceObject holds.
92 * @param attrs The attributes to set.
93 * @param result The response result.
94 * @param errorCode The error code for response.
96 * @see RCSResourceAttributes
99 static RCSGetResponse create(const RCSResourceAttributes& attrs,
100 const OCEntityHandlerResult& result, int errorCode);
105 static RCSGetResponse create(RCSResourceAttributes&& attrs,
106 const OCEntityHandlerResult& result, int errorCode);
109 RequestHandler* getHandler() const;
113 RCSGetResponse(std::shared_ptr< RequestHandler >&&);
116 std::shared_ptr< RequestHandler > m_handler;
120 * This class provides factory methods to create the response for a received set request.
121 * The response consists of a result code, an error code and result attributes.
123 * AcceptanceMethod provides ways how to handle attributes from a request.
125 * @see RCSResourceObject
131 * Options for handling a set request.
133 * This overrides SetRequestHandlerPolicy.
135 * @see SetRequestHandlerPolicy
138 enum class AcceptanceMethod
141 * Follow SetRequestHandlerPolicy of the RCSResourceObject.
146 * Accept the request attributes even if there is an unknown key or mismatched type.
151 * Ignore the request attributes.
157 * Creates a default RCSSetResponse that has AcceptanceMethod::DEFAULT.
158 * The response will have OC_EH_OK for the result and 200 for the errorCode.
159 * The attributes of RCSResourceObject will be set as the result attributes.
162 static RCSSetResponse defaultAction();
165 * Creates a default RCSSetResponse that has AcceptanceMethod::ACCEPT.
166 * The response will have OC_EH_OK for the result and 200 for the errorCode.
167 * The attributes of RCSResourceObject will be set as the result attributes.
170 static RCSSetResponse accept();
173 * Creates a RCSSetResponse that has AcceptanceMethod::ACCEPT
174 * with a result and error code passed.
175 * The attributes of the RCSResourceObject will be set as the result attributes.
177 * @param result The response result.
178 * @param errorCode The error code to set in response.
181 static RCSSetResponse accept(const OCEntityHandlerResult& result, int errorCode);
184 * Creates a default RCSSetResponse that has AcceptanceMethod::IGNORE.
185 * The response will have OC_EH_OK for the result and 200 for the errorCode.
186 * The attributes of RCSResourceObject will be set as the result attributes.
189 static RCSSetResponse ignore();
192 * Creates a RCSSetResponse that has AcceptanceMethod::IGNORE
193 * with a result and error code passed.
194 * The attributes of the RCSResourceObject will be set as the result attributes.
196 * @param result The response result.
197 * @param errorCode The error code to set in response.
200 static RCSSetResponse ignore(const OCEntityHandlerResult& result, int errorCode);
203 * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT
204 * with a result and error code passed.
205 * The attributes of the RCSResourceObject will be set as the result attributes.
207 * @param result The response result.
208 * @param errorCode The error code to set in response.
211 static RCSSetResponse create(const OCEntityHandlerResult& result, int errorCode);
214 * Creates a RCSSetResponse that has AcceptanceMethod::DEFAULT with custom attributes.
215 * This sends the passed attributes as the result attributes
216 * instead of the one the RCSResourceObject holds.
218 * @param attrs The attributes to set.
220 * @see RCSResourceAttributes
223 static RCSSetResponse create(const RCSResourceAttributes& attrs);
228 static RCSSetResponse create(RCSResourceAttributes &&attrs);
231 * Creates a RCSSetResponse with a result and error code passed.
232 * This sends the passed attributes as the result attributes
233 * instead of the one the RCSResourceObject holds.
235 * @param attrs The attributes to set.
236 * @param result The response result.
237 * @param errorCode The error code for response.
239 * @see RCSResourceAttributes
242 static RCSSetResponse create(const RCSResourceAttributes& attrs,
243 const OCEntityHandlerResult& result, int errorCode);
249 static RCSSetResponse create(RCSResourceAttributes &&attrs,
250 const OCEntityHandlerResult &result, int errorCode);
254 SetRequestHandler* getHandler() const;
258 * Returns the acceptance method.
261 AcceptanceMethod getAcceptanceMethod() const;
264 * Sets the acceptance method for the RCSSetResponse.
266 * @param method - AcceptanceMethod value to set
268 * @return The reference to this RCSSetResponse
270 * @see AcceptanceMethod
273 RCSSetResponse& setAcceptanceMethod(AcceptanceMethod method);
276 RCSSetResponse(std::shared_ptr< SetRequestHandler >&&);
277 RCSSetResponse(std::shared_ptr< SetRequestHandler >&&, AcceptanceMethod);
280 AcceptanceMethod m_acceptanceMethod;
281 std::shared_ptr< SetRequestHandler > m_handler;
286 #endif // SERVERBUILDER_RCSRESPONSE_H