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 __OCRESOURCERESPONSE_H
29 #define __OCRESOURCERESPONSE_H
32 #include <IServerWrapper.h>
34 #include <OCRepresentation.h>
40 class InProcServerWrapper;
43 * @brief OCResourceResponse provides APIs to set the response details
45 class OCResourceResponse
48 typedef std::shared_ptr<OCResourceResponse> Ptr;
56 m_requestHandle{nullptr},
57 m_resourceHandle{nullptr},
62 OCResourceResponse(OCResourceResponse&&) = default;
63 OCResourceResponse& operator=(OCResourceResponse&&) = default;
64 virtual ~OCResourceResponse(void) {}
67 * This API sets the error code for this response
68 * @param eCode error code to set
70 void setErrorCode(const int eCode) { m_errorCode = eCode; }
73 * gets new resource uri
74 * @return std::string new resource uri
76 std::string getNewResourceUri(void)
78 return m_newResourceUri;
82 * sets new resource uri
83 * @param newResourceUri specifies the resource uri of the resource created
85 void setNewResourceUri(const std::string newResourceUri)
87 m_newResourceUri = newResourceUri;
91 * This API allows to set headerOptions in the response
92 * @param headerOptions HeaderOptions vector consisting of OCHeaderOption objects
94 void setHeaderOptions(const HeaderOptions& headerOptions)
96 m_headerOptions = headerOptions;
100 * This API allows to set request handle
102 * @param requestHandle - OCRequestHandle type used to set the request handle
104 void setRequestHandle(const OCRequestHandle& requestHandle)
106 m_requestHandle = requestHandle;
110 * This API allows to set the resource handle
112 * @param resourceHandle - OCResourceHandle type used to set the resource handle
114 void setResourceHandle(const OCResourceHandle& resourceHandle)
116 m_resourceHandle = resourceHandle;
120 * This API allows to set the EntityHandler response result
122 * @param responseResult - OCEntityHandlerResult type to set the result value
124 void setResponseResult(const OCEntityHandlerResult& responseResult)
126 m_responseResult = responseResult;
130 * API to set the entire resource attribute representation
131 * @param rep reference to the resource's representation
132 * @param interface specifies the interface
134 void setResourceRepresentation(OCRepresentation& rep, std::string interface) {
135 m_interface = interface;
136 m_representation = rep;
140 * API to set the entire resource attribute representation
141 * @param rep rvalue reference to the resource's representation
142 * @param interface specifies the interface
144 void setResourceRepresentation(OCRepresentation&& rep, std::string interface) {
145 setResourceRepresentation(rep, interface);
149 * API to set the entire resource attribute representation
150 * @param rep reference to the resource's representation
152 void setResourceRepresentation(OCRepresentation& rep) {
154 m_interface = DEFAULT_INTERFACE;
155 m_representation = rep;
159 * API to set the entire resource attribute representation
160 * @param rep rvalue reference to the resource's representation
162 void setResourceRepresentation(OCRepresentation&& rep) {
163 // Call the above function
164 setResourceRepresentation(rep);
167 std::string m_newResourceUri;
169 HeaderOptions m_headerOptions;
170 std::string m_interface;
171 OCRepresentation m_representation;
172 OCRequestHandle m_requestHandle;
173 OCResourceHandle m_resourceHandle;
174 OCEntityHandlerResult m_responseResult;
177 friend class InProcServerWrapper;
179 std::string getPayload() const
181 MessageContainer inf;
182 OCRepresentation first(m_representation);
184 if(m_interface==LINK_INTERFACE)
186 first.setInterfaceType(InterfaceType::LinkParent);
188 else if(m_interface==BATCH_INTERFACE)
190 first.setInterfaceType(InterfaceType::BatchParent);
194 first.setInterfaceType(InterfaceType::DefaultParent);
197 inf.addRepresentation(first);
199 for(const OCRepresentation& rep : m_representation.getChildren())
201 OCRepresentation cur(rep);
203 if(m_interface==LINK_INTERFACE)
205 cur.setInterfaceType(InterfaceType::LinkChild);
207 else if(m_interface==BATCH_INTERFACE)
209 cur.setInterfaceType(InterfaceType::BatchChild);
213 cur.setInterfaceType(InterfaceType::DefaultChild);
216 inf.addRepresentation(cur);
220 return inf.getJSONRepresentation(OCInfoFormat::ExcludeOC);
227 int getErrorCode() const;
230 * Get the Response Representation
232 const OCRepresentation& getResourceRepresentation() const
234 return m_representation;
237 * This API allows to retrieve headerOptions from a response
239 const HeaderOptions& getHeaderOptions() const
241 return m_headerOptions;
245 * This API retrieves the request handle
247 * @return OCRequestHandle value
249 const OCRequestHandle& getRequestHandle() const
251 return m_requestHandle;
255 * This API retrieves the resource handle
257 * @return OCResourceHandle value
259 const OCResourceHandle& getResourceHandle() const
261 return m_resourceHandle;
265 * This API retrieves the entity handle response result
267 * @return OCEntityHandler result value
269 const OCEntityHandlerResult getResponseResult() const
271 return m_responseResult;
277 #endif //__OCRESOURCERESPONSE_H