IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OCResourceResponse.h
Go to the documentation of this file.
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 
28 #ifndef OC_RESOURCERESPONSE_H_
29 #define OC_RESOURCERESPONSE_H_
30 
31 #include "OCApi.h"
32 #include <IServerWrapper.h>
33 #include <ocstack.h>
34 #include <OCRepresentation.h>
35 
36 namespace OC
37 {
38  class InProcServerWrapper;
39 
44  {
45  public:
46  typedef std::shared_ptr<OCResourceResponse> Ptr;
47 
49  m_newResourceUri{},
50  m_headerOptions{},
51  m_interface{},
52  m_representation{},
53  m_requestHandle{nullptr},
54  m_resourceHandle{nullptr},
55  m_responseResult{}
56  {
57  }
58 
59 #if defined(_MSC_VER) && (_MSC_VER < 1900)
61  m_newResourceUri(std::move(o.m_newResourceUri)),
62  m_headerOptions(std::move(o.m_headerOptions)),
63  m_interface(std::move(o.m_interface)),
64  m_representation(std::move(o.m_representation)),
65  m_requestHandle(std::move(o.m_requestHandle)),
66  m_resourceHandle(std::move(o.m_resourceHandle)),
67  m_responseResult(std::move(o.m_responseResult))
68  {
69  }
71  {
72  m_newResourceUri = std::move(o.m_newResourceUri);
73  m_headerOptions = std::move(o.m_headerOptions);
74  m_interface = std::move(o.m_interface);
75  m_representation = std::move(o.m_representation);
76  m_requestHandle = std::move(o.m_requestHandle);
77  m_resourceHandle = std::move(o.m_resourceHandle);
78  m_responseResult = std::move(o.m_responseResult);
79  }
80 #else
83 #endif
84  virtual ~OCResourceResponse(void) {}
85 
90  std::string getNewResourceUri(void)
91  {
92  return m_newResourceUri;
93  }
94 
99  void setNewResourceUri(const std::string newResourceUri)
100  {
101  m_newResourceUri = newResourceUri;
102  }
103 
108  void setHeaderOptions(const HeaderOptions& headerOptions)
109  {
110  m_headerOptions = headerOptions;
111  }
112 
118  void setRequestHandle(const OCRequestHandle& requestHandle)
119  {
120  m_requestHandle = requestHandle;
121  }
122 
128  void setResourceHandle(const OCResourceHandle& resourceHandle)
129  {
130  m_resourceHandle = resourceHandle;
131  }
132 
138  void setResponseResult(const OCEntityHandlerResult& responseResult)
139  {
140  m_responseResult = responseResult;
141  }
142 
148  void setResourceRepresentation(OCRepresentation& rep, std::string iface) {
149  m_interface = iface;
150  m_representation = rep;
151  }
152 
158  void setResourceRepresentation(OCRepresentation&& rep, std::string iface) {
159  setResourceRepresentation(rep, iface);
160  }
161 
167  // Call the default
168  m_interface = DEFAULT_INTERFACE;
169  m_representation = rep;
170  }
171 
177  // Call the above function
179  }
180  private:
181  std::string m_newResourceUri;
182  HeaderOptions m_headerOptions;
183  std::string m_interface;
184  OCRepresentation m_representation;
185  OCRequestHandle m_requestHandle;
186  OCResourceHandle m_resourceHandle;
187  OCEntityHandlerResult m_responseResult;
188 
189  private:
190  friend class InProcServerWrapper;
191 
192  OCRepPayload* getPayload() const
193  {
194  MessageContainer inf;
195  OCRepresentation first(m_representation);
196 
197  if(m_interface==LINK_INTERFACE)
198  {
199  first.setInterfaceType(InterfaceType::LinkParent);
200  }
201  else if(m_interface==BATCH_INTERFACE)
202  {
203  first.setInterfaceType(InterfaceType::BatchParent);
204  }
205  else
206  {
207  first.setInterfaceType(InterfaceType::DefaultParent);
208  }
209 
210  inf.addRepresentation(first);
211 
212  for(const OCRepresentation& rep : m_representation.getChildren())
213  {
214  OCRepresentation cur(rep);
215 
216  if(m_interface==LINK_INTERFACE)
217  {
218  cur.setInterfaceType(InterfaceType::LinkChild);
219  }
220  else if(m_interface==BATCH_INTERFACE)
221  {
222  cur.setInterfaceType(InterfaceType::BatchChild);
223  }
224  else
225  {
226  cur.setInterfaceType(InterfaceType::DefaultChild);
227  }
228 
229  inf.addRepresentation(cur);
230 
231  }
232 
233  return inf.getPayload();
234  }
235  public:
236 
241  {
242  return m_representation;
243  }
248  {
249  return m_headerOptions;
250  }
251 
258  {
259  return m_requestHandle;
260  }
261 
268  {
269  return m_resourceHandle;
270  }
271 
278  {
279  return m_responseResult;
280  }
281  };
282 
283 } // namespace OC
284 
285 #endif // OC_RESOURCERESPONSE_H_
OCResourceResponse()
Definition: OCResourceResponse.h:48
friend class InProcServerWrapper
Definition: OCResourceResponse.h:190
void setResourceRepresentation(OCRepresentation &&rep)
API to set the entire resource attribute representation.
Definition: OCResourceResponse.h:176
OCEntityHandlerResult
Possible returned values from entity handler.
Definition: octypes.h:1229
void setNewResourceUri(const std::string newResourceUri)
sets new resource uri
Definition: OCResourceResponse.h:99
const OCResourceHandle & getResourceHandle() const
This API retrieves the resource handle.
Definition: OCResourceResponse.h:267
const std::string DEFAULT_INTERFACE
Definition: OCApi.h:345
const std::vector< OCRepresentation > & getChildren() const
OCEntityHandlerResult getResponseResult() const
This API retrieves the entity handle response result.
Definition: OCResourceResponse.h:277
std::vector< HeaderOption::OCHeaderOption > HeaderOptions
Definition: OCApi.h:313
Definition: OCRepresentation.h:59
Definition: octypes.h:1523
This file contains the declaration of classes and its members related to OCRepresentation.
void * OCResourceHandle
Handle to an OCResource object owned by the OCStack.
Definition: octypes.h:1152
void setResponseResult(const OCEntityHandlerResult &responseResult)
This API allows to set the EntityHandler response result.
Definition: OCResourceResponse.h:138
virtual ~OCResourceResponse(void)
Definition: OCResourceResponse.h:84
void setResourceRepresentation(OCRepresentation &rep)
API to set the entire resource attribute representation.
Definition: OCResourceResponse.h:166
OCRepPayload * getPayload() const
OCResourceResponse & operator=(OCResourceResponse &&)=default
std::shared_ptr< OCResourceResponse > Ptr
Definition: OCResourceResponse.h:46
std::string getNewResourceUri(void)
gets new resource uri
Definition: OCResourceResponse.h:90
const std::string BATCH_INTERFACE
Definition: OCApi.h:351
void * OCRequestHandle
Handle to an OCRequest object owned by the OCStack.
Definition: octypes.h:1157
void setResourceRepresentation(OCRepresentation &rep, std::string iface)
API to set the entire resource attribute representation.
Definition: OCResourceResponse.h:148
void setResourceHandle(const OCResourceHandle &resourceHandle)
This API allows to set the resource handle.
Definition: OCResourceResponse.h:128
const OCRepresentation & getResourceRepresentation() const
Get the Response Representation.
Definition: OCResourceResponse.h:240
void setHeaderOptions(const HeaderOptions &headerOptions)
This API allows to set headerOptions in the response.
Definition: OCResourceResponse.h:108
void addRepresentation(const OCRepresentation &rep)
const OCRequestHandle & getRequestHandle() const
This API retrieves the request handle.
Definition: OCResourceResponse.h:257
void setResourceRepresentation(OCRepresentation &&rep, std::string iface)
API to set the entire resource attribute representation.
Definition: OCResourceResponse.h:158
void setRequestHandle(const OCRequestHandle &requestHandle)
This API allows to set request handle.
Definition: OCResourceResponse.h:118
Definition: OCRepresentation.h:84
const std::string LINK_INTERFACE
Definition: OCApi.h:348
const HeaderOptions & getHeaderOptions() const
This API allows to retrieve headerOptions from a response.
Definition: OCResourceResponse.h:247
OCResourceResponse provides APIs to set the response details.
Definition: OCResourceResponse.h:43