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 virtual ~OCResourceResponse(void) {}
63 * This API sets the error code for this response
64 * @param eCode error code to set
66 void setErrorCode(const int eCode) { m_errorCode = eCode; }
69 * gets new resource uri
70 * @return std::string new resource uri
72 std::string getNewResourceUri(void)
74 return m_newResourceUri;
78 * sets new resource uri
79 * @param newResourceUri specifies the resource uri of the resource created
81 void setNewResourceUri(const std::string newResourceUri)
83 m_newResourceUri = newResourceUri;
87 * This API allows to set headerOptions in the response
88 * @param headerOptions HeaderOptions vector consisting of OCHeaderOption objects
90 void setHeaderOptions(const HeaderOptions& headerOptions)
92 m_headerOptions = headerOptions;
96 * This API allows to set request handle
98 * @param requestHandle - OCRequestHandle type used to set the request handle
100 void setRequestHandle(const OCRequestHandle& requestHandle)
102 m_requestHandle = requestHandle;
106 * This API allows to set the resource handle
108 * @param resourceHandle - OCResourceHandle type used to set the resource handle
110 void setResourceHandle(const OCResourceHandle& resourceHandle)
112 m_resourceHandle = resourceHandle;
116 * This API allows to set the EntityHandler response result
118 * @param responseResult - OCEntityHandlerResult type to set the result value
120 void setResponseResult(const OCEntityHandlerResult& responseResult)
122 m_responseResult = responseResult;
126 * API to set the entire resource attribute representation
127 * @param attributeMap reference containing the name value pairs representing
128 * the resource's attributes
129 * @param interface specifies the interface
131 void setResourceRepresentation(OCRepresentation& rep, std::string interface) {
132 m_interface = interface;
133 m_representation = rep;
137 * API to set the entire resource attribute representation
138 * @param attributeMap rvalue reference containing the name value pairs representing
139 * the resource's attributes
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 attributeMap reference containing the name value pairs representing the resource's
151 void setResourceRepresentation(OCRepresentation& rep) {
153 m_interface = DEFAULT_INTERFACE;
154 m_representation = rep;
158 * API to set the entire resource attribute representation
159 * @param attributeMap rvalue reference containing the name value pairs representing the
160 * resource's attributes
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