1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 declaration of classes and its members related to
28 #ifndef OC_RESOURCERESPONSE_H_
29 #define OC_RESOURCERESPONSE_H_
32 #include <IServerWrapper.h>
34 #include <OCRepresentation.h>
38 class InProcServerWrapper;
41 * @brief OCResourceResponse provides APIs to set the response details
43 class OCResourceResponse
46 typedef std::shared_ptr<OCResourceResponse> Ptr;
55 m_resourceHandle{nullptr},
60 #if defined(_MSC_VER) && (_MSC_VER < 1900)
61 OCResourceResponse(OCResourceResponse&& o):
62 m_newResourceUri(std::move(o.m_newResourceUri)),
63 m_errorCode(o.m_errorCode),
64 m_headerOptions(std::move(o.m_headerOptions)),
65 m_interface(std::move(o.m_interface)),
66 m_representation(std::move(o.m_representation)),
67 m_requestHandle(std::move(o.m_requestHandle)),
68 m_resourceHandle(std::move(o.m_resourceHandle)),
69 m_responseResult(std::move(o.m_responseResult))
72 OCResourceResponse& operator=(OCResourceResponse&& o)
74 m_newResourceUri = std::move(o.m_newResourceUri);
75 m_errorCode = o.m_errorCode;
76 m_headerOptions = std::move(o.m_headerOptions);
77 m_interface = std::move(o.m_interface);
78 m_representation = std::move(o.m_representation);
79 m_requestHandle = std::move(o.m_requestHandle);
80 m_resourceHandle = std::move(o.m_resourceHandle);
81 m_responseResult = std::move(o.m_responseResult);
84 OCResourceResponse(OCResourceResponse&&) = default;
85 OCResourceResponse& operator=(OCResourceResponse&&) = default;
87 virtual ~OCResourceResponse(void) {}
90 * This API sets the error code for this response
91 * @param eCode error code to set
93 void setErrorCode(const int eCode) { m_errorCode = eCode; }
96 * gets new resource uri
97 * @return std::string new resource uri
99 std::string getNewResourceUri(void)
101 return m_newResourceUri;
105 * sets new resource uri
106 * @param newResourceUri specifies the resource uri of the resource created
108 void setNewResourceUri(const std::string newResourceUri)
110 m_newResourceUri = newResourceUri;
114 * This API allows to set headerOptions in the response
115 * @param headerOptions HeaderOptions vector consisting of OCHeaderOption objects
117 void setHeaderOptions(const HeaderOptions& headerOptions)
119 m_headerOptions = headerOptions;
123 * This API allows to set request handle
125 * @param requestHandle - OCRequestHandle type used to set the request handle
127 void setRequestHandle(const OCRequestHandle& requestHandle)
129 m_requestHandle = requestHandle;
133 * This API allows to set the resource handle
135 * @param resourceHandle - OCResourceHandle type used to set the resource handle
137 void setResourceHandle(const OCResourceHandle& resourceHandle)
139 m_resourceHandle = resourceHandle;
143 * This API allows to set the EntityHandler response result
145 * @param responseResult - OCEntityHandlerResult type to set the result value
147 void setResponseResult(const OCEntityHandlerResult& responseResult)
149 m_responseResult = responseResult;
153 * API to set the entire resource attribute representation
154 * @param rep reference to the resource's representation
155 * @param interface specifies the interface
157 void setResourceRepresentation(OCRepresentation& rep, std::string iface) {
159 m_representation = rep;
163 * API to set the entire resource attribute representation
164 * @param rep rvalue reference to the resource's representation
165 * @param interface specifies the interface
167 void setResourceRepresentation(OCRepresentation&& rep, std::string iface) {
168 setResourceRepresentation(rep, iface);
172 * API to set the entire resource attribute representation
173 * @param rep reference to the resource's representation
175 void setResourceRepresentation(OCRepresentation& rep) {
177 m_interface = DEFAULT_INTERFACE;
178 m_representation = rep;
182 * API to set the entire resource attribute representation
183 * @param rep rvalue reference to the resource's representation
185 void setResourceRepresentation(OCRepresentation&& rep) {
186 // Call the above function
187 setResourceRepresentation(rep);
190 std::string m_newResourceUri;
192 HeaderOptions m_headerOptions;
193 std::string m_interface;
194 OCRepresentation m_representation;
195 OCRequestHandle m_requestHandle;
196 OCResourceHandle m_resourceHandle;
197 OCEntityHandlerResult m_responseResult;
200 friend class InProcServerWrapper;
202 OCRepPayload* getPayload() const
204 MessageContainer inf;
205 OCRepresentation first(m_representation);
207 if(m_interface==LINK_INTERFACE)
209 first.setInterfaceType(InterfaceType::LinkParent);
211 else if(m_interface==BATCH_INTERFACE)
213 first.setInterfaceType(InterfaceType::BatchParent);
217 first.setInterfaceType(InterfaceType::DefaultParent);
220 inf.addRepresentation(first);
222 for(const OCRepresentation& rep : m_representation.getChildren())
224 OCRepresentation cur(rep);
226 if(m_interface==LINK_INTERFACE)
228 cur.setInterfaceType(InterfaceType::LinkChild);
230 else if(m_interface==BATCH_INTERFACE)
232 cur.setInterfaceType(InterfaceType::BatchChild);
236 cur.setInterfaceType(InterfaceType::DefaultChild);
239 inf.addRepresentation(cur);
243 return inf.getPayload();
250 int getErrorCode() const
256 * Get the Response Representation
258 const OCRepresentation& getResourceRepresentation() const
260 return m_representation;
263 * This API allows to retrieve headerOptions from a response
265 const HeaderOptions& getHeaderOptions() const
267 return m_headerOptions;
271 * This API retrieves the request handle
273 * @return OCRequestHandle value
275 const OCRequestHandle& getRequestHandle() const
277 return m_requestHandle;
281 * This API retrieves the resource handle
283 * @return OCResourceHandle value
285 const OCResourceHandle& getResourceHandle() const
287 return m_resourceHandle;
291 * This API retrieves the entity handle response result
293 * @return OCEntityHandler result value
295 OCEntityHandlerResult getResponseResult() const
297 return m_responseResult;
303 #endif // OC_RESOURCERESPONSE_H_