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;
51 virtual ~OCResourceResponse(void) {}
54 * This API sets the error code for this response
55 * @param eCode error code to set
57 void setErrorCode(const int eCode) { m_errorCode = eCode; }
60 * gets new resource uri
61 * @return std::string new resource uri
63 std::string getNewResourceUri(void)
65 return m_newResourceUri;
69 * sets new resource uri
70 * @param newResourceUri specifies the resource uri of the resource created
72 void setNewResourceUri(const std::string newResourceUri)
74 m_newResourceUri = newResourceUri;
78 * This API allows to set headerOptions in the response
79 * @param headerOptions HeaderOptions vector consisting of OCHeaderOption objects
81 void setHeaderOptions(const HeaderOptions& headerOptions)
83 m_headerOptions = headerOptions;
87 * This API allows to set request handle
89 * @param requestHandle - OCRequestHandle type used to set the request handle
91 void setRequestHandle(const OCRequestHandle& requestHandle)
93 m_requestHandle = requestHandle;
97 * This API allows to set the resource handle
99 * @param resourceHandle - OCResourceHandle type used to set the resource handle
101 void setResourceHandle(const OCResourceHandle& resourceHandle)
103 m_resourceHandle = resourceHandle;
107 * This API allows to set the EntityHandler response result
109 * @param responseResult - OCEntityHandlerResult type to set the result value
111 void setResponseResult(const OCEntityHandlerResult& responseResult)
113 m_responseResult = responseResult;
117 * API to set the entire resource attribute representation
118 * @param attributeMap reference containing the name value pairs representing
119 * the resource's attributes
120 * @param interface specifies the interface
122 void setResourceRepresentation(OCRepresentation& rep, std::string interface) {
123 m_interface = interface;
124 m_representation = rep;
128 * API to set the entire resource attribute representation
129 * @param attributeMap rvalue 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 setResourceRepresentation(rep, interface);
138 * API to set the entire resource attribute representation
139 * @param attributeMap reference containing the name value pairs representing the resource's
142 void setResourceRepresentation(OCRepresentation& rep) {
144 m_interface = DEFAULT_INTERFACE;
145 m_representation = rep;
149 * API to set the entire resource attribute representation
150 * @param attributeMap rvalue reference containing the name value pairs representing the
151 * resource's attributes
153 void setResourceRepresentation(OCRepresentation&& rep) {
154 // Call the above function
155 setResourceRepresentation(rep);
158 std::string m_newResourceUri;
160 HeaderOptions m_headerOptions;
161 std::string m_interface;
162 OCRepresentation m_representation;
163 OCRequestHandle m_requestHandle;
164 OCResourceHandle m_resourceHandle;
165 OCEntityHandlerResult m_responseResult;
168 friend class InProcServerWrapper;
170 std::string getPayload() const
172 MessageContainer inf;
173 OCRepresentation first(m_representation);
175 if(m_interface==LINK_INTERFACE)
177 first.setInterfaceType(InterfaceType::LinkParent);
179 else if(m_interface==BATCH_INTERFACE)
181 first.setInterfaceType(InterfaceType::BatchParent);
185 first.setInterfaceType(InterfaceType::DefaultParent);
188 inf.addRepresentation(first);
190 for(const OCRepresentation& rep : m_representation.getChildren())
192 OCRepresentation cur(rep);
194 if(m_interface==LINK_INTERFACE)
196 cur.setInterfaceType(InterfaceType::LinkChild);
198 else if(m_interface==BATCH_INTERFACE)
200 cur.setInterfaceType(InterfaceType::BatchChild);
204 cur.setInterfaceType(InterfaceType::DefaultChild);
207 inf.addRepresentation(cur);
211 return inf.getJSONRepresentation(OCInfoFormat::ExcludeOC);
218 int getErrorCode() const;
221 * Get the Response Representation
223 const OCRepresentation& getResourceRepresentation() const
225 return m_representation;
228 * This API allows to retrieve headerOptions from a response
230 const HeaderOptions& getHeaderOptions() const
232 return m_headerOptions;
236 * This API retrieves the request handle
238 * @return OCRequestHandle value
240 const OCRequestHandle& getRequestHandle() const
242 return m_requestHandle;
246 * This API retrieves the resource handle
248 * @return OCResourceHandle value
250 const OCResourceHandle& getResourceHandle() const
252 return m_resourceHandle;
256 * This API retrieves the entity handle response result
258 * @return OCEntityHandler result value
260 const OCEntityHandlerResult getResponseResult() const
262 return m_responseResult;
268 #endif //__OCRESOURCERESPONSE_H