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>
38 class InProcServerWrapper;
41 * @brief OCResourceResponse provides APIs to set the response details
43 class OCResourceResponse
46 typedef std::shared_ptr<OCResourceResponse> Ptr;
54 m_requestHandle{nullptr},
55 m_resourceHandle{nullptr},
60 OCResourceResponse(OCResourceResponse&&) = default;
61 OCResourceResponse& operator=(OCResourceResponse&&) = default;
62 virtual ~OCResourceResponse(void) {}
65 * This API sets the error code for this response
66 * @param eCode error code to set
68 void setErrorCode(const int eCode) { m_errorCode = eCode; }
71 * gets new resource uri
72 * @return std::string new resource uri
74 std::string getNewResourceUri(void)
76 return m_newResourceUri;
80 * sets new resource uri
81 * @param newResourceUri specifies the resource uri of the resource created
83 void setNewResourceUri(const std::string newResourceUri)
85 m_newResourceUri = newResourceUri;
89 * This API allows to set headerOptions in the response
90 * @param headerOptions HeaderOptions vector consisting of OCHeaderOption objects
92 void setHeaderOptions(const HeaderOptions& headerOptions)
94 m_headerOptions = headerOptions;
98 * This API allows to set request handle
100 * @param requestHandle - OCRequestHandle type used to set the request handle
102 void setRequestHandle(const OCRequestHandle& requestHandle)
104 m_requestHandle = requestHandle;
108 * This API allows to set the resource handle
110 * @param resourceHandle - OCResourceHandle type used to set the resource handle
112 void setResourceHandle(const OCResourceHandle& resourceHandle)
114 m_resourceHandle = resourceHandle;
118 * This API allows to set the EntityHandler response result
120 * @param responseResult - OCEntityHandlerResult type to set the result value
122 void setResponseResult(const OCEntityHandlerResult& responseResult)
124 m_responseResult = responseResult;
128 * API to set the entire resource attribute representation
129 * @param rep reference to the resource's representation
130 * @param interface specifies the interface
132 void setResourceRepresentation(OCRepresentation& rep, std::string interface) {
133 m_interface = interface;
134 m_representation = rep;
138 * API to set the entire resource attribute representation
139 * @param rep rvalue reference to the resource's representation
140 * @param interface specifies the interface
142 void setResourceRepresentation(OCRepresentation&& rep, std::string interface) {
143 setResourceRepresentation(rep, interface);
147 * API to set the entire resource attribute representation
148 * @param rep reference to the resource's representation
150 void setResourceRepresentation(OCRepresentation& rep) {
152 m_interface = DEFAULT_INTERFACE;
153 m_representation = rep;
157 * API to set the entire resource attribute representation
158 * @param rep rvalue reference to the resource's representation
160 void setResourceRepresentation(OCRepresentation&& rep) {
161 // Call the above function
162 setResourceRepresentation(rep);
165 std::string m_newResourceUri;
167 HeaderOptions m_headerOptions;
168 std::string m_interface;
169 OCRepresentation m_representation;
170 OCRequestHandle m_requestHandle;
171 OCResourceHandle m_resourceHandle;
172 OCEntityHandlerResult m_responseResult;
175 friend class InProcServerWrapper;
177 std::string getPayload() const
179 MessageContainer inf;
180 OCRepresentation first(m_representation);
182 if(m_interface==LINK_INTERFACE)
184 first.setInterfaceType(InterfaceType::LinkParent);
186 else if(m_interface==BATCH_INTERFACE)
188 first.setInterfaceType(InterfaceType::BatchParent);
192 first.setInterfaceType(InterfaceType::DefaultParent);
195 inf.addRepresentation(first);
197 for(const OCRepresentation& rep : m_representation.getChildren())
199 OCRepresentation cur(rep);
201 if(m_interface==LINK_INTERFACE)
203 cur.setInterfaceType(InterfaceType::LinkChild);
205 else if(m_interface==BATCH_INTERFACE)
207 cur.setInterfaceType(InterfaceType::BatchChild);
211 cur.setInterfaceType(InterfaceType::DefaultChild);
214 inf.addRepresentation(cur);
218 return inf.getJSONRepresentation(OCInfoFormat::ExcludeOC);
225 int getErrorCode() const
231 * Get the Response Representation
233 const OCRepresentation& getResourceRepresentation() const
235 return m_representation;
238 * This API allows to retrieve headerOptions from a response
240 const HeaderOptions& getHeaderOptions() const
242 return m_headerOptions;
246 * This API retrieves the request handle
248 * @return OCRequestHandle value
250 const OCRequestHandle& getRequestHandle() const
252 return m_requestHandle;
256 * This API retrieves the resource handle
258 * @return OCResourceHandle value
260 const OCResourceHandle& getResourceHandle() const
262 return m_resourceHandle;
266 * This API retrieves the entity handle response result
268 * @return OCEntityHandler result value
270 const OCEntityHandlerResult getResponseResult() const
272 return m_responseResult;
278 #endif //__OCRESOURCERESPONSE_H