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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file OCResourceResponse.h
23 /// @brief This file contains the declaration of classes and its members related to
26 #ifndef __OCRESOURCERESPONSE_H
27 #define __OCRESOURCERESPONSE_H
30 #include <IServerWrapper.h>
32 #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 attributeMap reference containing the name value pairs representing
130 * the resource's attributes
131 * @param interface specifies the interface
133 void setResourceRepresentation(OCRepresentation& rep, std::string interface) {
134 m_interface = interface;
135 m_representation = rep;
139 * API to set the entire resource attribute representation
140 * @param attributeMap rvalue reference containing the name value pairs representing
141 * the resource's attributes
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 attributeMap reference containing the name value pairs representing the resource's
153 void setResourceRepresentation(OCRepresentation& rep) {
155 m_interface = DEFAULT_INTERFACE;
156 m_representation = rep;
160 * API to set the entire resource attribute representation
161 * @param attributeMap rvalue reference containing the name value pairs representing the
162 * resource's attributes
164 void setResourceRepresentation(OCRepresentation&& rep) {
165 // Call the above function
166 setResourceRepresentation(rep);
169 std::string m_newResourceUri;
171 HeaderOptions m_headerOptions;
172 std::string m_interface;
173 OCRepresentation m_representation;
174 OCRequestHandle m_requestHandle;
175 OCResourceHandle m_resourceHandle;
176 OCEntityHandlerResult m_responseResult;
179 friend class InProcServerWrapper;
181 std::string getPayload() const
183 MessageContainer inf;
184 OCRepresentation first(m_representation);
186 if(m_interface==LINK_INTERFACE)
188 first.setInterfaceType(InterfaceType::LinkParent);
190 else if(m_interface==BATCH_INTERFACE)
192 first.setInterfaceType(InterfaceType::BatchParent);
196 first.setInterfaceType(InterfaceType::DefaultParent);
199 inf.addRepresentation(first);
201 for(const OCRepresentation& rep : m_representation.getChildren())
203 OCRepresentation cur(rep);
205 if(m_interface==LINK_INTERFACE)
207 cur.setInterfaceType(InterfaceType::LinkChild);
209 else if(m_interface==BATCH_INTERFACE)
211 cur.setInterfaceType(InterfaceType::BatchChild);
215 cur.setInterfaceType(InterfaceType::DefaultChild);
218 inf.addRepresentation(cur);
222 return inf.getJSONRepresentation(OCInfoFormat::ExcludeOC);
229 int getErrorCode() const;
232 * Get the Response Representation
234 const OCRepresentation& getResourceRepresentation() const
236 return m_representation;
239 * This API allows to retrieve headerOptions from a response
241 const HeaderOptions& getHeaderOptions() const
243 return m_headerOptions;
247 * This API retrieves the request handle
249 * @return OCRequestHandle value
251 const OCRequestHandle& getRequestHandle() const
253 return m_requestHandle;
257 * This API retrieves the resource handle
259 * @return OCResourceHandle value
261 const OCResourceHandle& getResourceHandle() const
263 return m_resourceHandle;
267 * This API retrieves the entity handle response result
269 * @return OCEntityHandler result value
271 const OCEntityHandlerResult getResponseResult() const
273 return m_responseResult;
279 #endif //__OCRESOURCERESPONSE_H