IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OCApi.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 
21 #ifndef OC_OCAPI_H_
22 #define OC_OCAPI_H_
23 
24 #include <string>
25 #include <sstream>
26 #include <vector>
27 #include <map>
28 #include <memory>
29 #include <iterator>
30 #include <functional>
31 
32 #include "iotivity_config.h"
33 #include "iotivity_debug.h"
34 
35 #include "octypes.h"
36 #include "OCHeaderOption.h"
37 #include <OCException.h>
38 #include "StringConstants.h"
39 #include "oc_logger.hpp"
40 
41 #include <OCRepresentation.h>
42 
43 namespace OC
44 {
45  class OCResource;
46  class OCResourceRequest;
47  class OCResourceResponse;
48 } // namespace OC
49 
50 namespace OC
51 {
52 #if defined(_MSC_VER)
53  extern std::ostream& oclog();
54 #else
55  typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
56 
57  namespace detail
58  {
59  /* We'll want to provide some sort of explicit hook for custom logging at some
60  point; until then, this should do nicely (note that since these are lambdas,
61  later a special target could be captured, allowing much flexibility): */
62  auto oclog_target = []() -> log_target_t&
63  {
64  static OC::oc_log_stream ols(oc_make_ostream_logger);
65  static log_target_t os(ols);
66 
67  return os;
68  };
69  } // namespace OC::detail
70 
71  auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
72  {
73  return detail::oclog_target();
74  };
75 #endif
76 } // namespace OC
77 
78 namespace OC
79 {
80 
81  enum class OCPlatformStatus
82  {
83  PlatformUp,
85  };
86 
88  {
89  None
90  };
91 
92  typedef std::string URI;
93 
94  enum class ServiceType
95  {
96  InProc,
97  OutOfProc
98  };
99 
103  enum class ModeType
104  {
105  Server,
106  Client,
107  Both,
108  Gateway
109  };
110 
117  enum class QualityOfService : uint8_t
118  {
120  LowQos = OC_LOW_QOS,
121 
124 
127 
129  NaQos = OC_NA_QOS
130  };
131 
136  {
139 
142 
145 
148 
151 
153  std::string ipAddress;
154 
156  uint16_t port;
157 
160 
163 
175 
176  public:
177  PlatformConfig(const ServiceType serviceType_,
178  const ModeType mode_,
179  OCPersistentStorage *ps_)
180  : serviceType(serviceType_),
181  mode(mode_),
185  ipAddress(""),
186  port(0),
188  ps(ps_),
189  useLegacyCleanup(false)
190  {}
191  /* @deprecated: Use a non deprecated constructor. */
194  mode(ModeType::Both),
198  ipAddress("0.0.0.0"),
199  port(0),
201  ps(nullptr),
202  useLegacyCleanup(true)
203  {}
204  /* @deprecated: Use a non deprecated constructor. */
205  PlatformConfig(const ServiceType serviceType_,
206  const ModeType mode_,
207  OCConnectivityType serverConnectivity_,
208  OCConnectivityType clientConnectivity_,
209  const QualityOfService QoS_,
210  OCPersistentStorage *ps_ = nullptr)
211  : serviceType(serviceType_),
212  mode(mode_),
213  serverConnectivity(serverConnectivity_),
214  clientConnectivity(clientConnectivity_),
216  ipAddress(""),
217  port(0),
218  QoS(QoS_),
219  ps(ps_),
220  useLegacyCleanup(true)
221  {}
222  /* @deprecated: Use a non deprecated constructor. */
223  PlatformConfig(const ServiceType serviceType_,
224  const ModeType mode_,
225  const std::string& ipAddress_,
226  const uint16_t port_,
227  const QualityOfService QoS_,
228  OCPersistentStorage *ps_ = nullptr)
229  : serviceType(serviceType_),
230  mode(mode_),
234  ipAddress(ipAddress_),
235  port(port_),
236  QoS(QoS_),
237  ps(ps_),
238  useLegacyCleanup(true)
239  {}
240  /* @deprecated: Use a non deprecated constructor. */
241  PlatformConfig(const ServiceType serviceType_,
242  const ModeType mode_,
243  const std::string& ipAddress_,
244  const uint16_t port_,
245  const OCTransportAdapter transportType_,
246  const QualityOfService QoS_,
247  OCPersistentStorage *ps_ = nullptr)
248  : serviceType(serviceType_),
249  mode(mode_),
252  transportType(transportType_),
253  ipAddress(ipAddress_),
254  port(port_),
255  QoS(QoS_),
256  ps(ps_)
257  {}
258  PlatformConfig(const ServiceType serviceType_,
259  const ModeType mode_,
260  OCTransportAdapter transportType_,
261  const QualityOfService QoS_,
262  OCPersistentStorage *ps_ = nullptr)
263  : serviceType(serviceType_),
264  mode(mode_),
267  transportType(transportType_),
268  ipAddress(""),
269  port(0),
270  QoS(QoS_),
271  ps(ps_),
272  useLegacyCleanup(true)
273  {}
274  /* @deprecated: Use a non deprecated constructor. */
275  PlatformConfig(const ServiceType serviceType_,
276  const ModeType mode_,
277  OCConnectivityType serverConnectivity_,
278  OCConnectivityType clientConnectivity_,
279  OCTransportAdapter transportType_,
280  const QualityOfService QoS_,
281  OCPersistentStorage *ps_ = nullptr)
282  : serviceType(serviceType_),
283  mode(mode_),
284  serverConnectivity(serverConnectivity_),
285  clientConnectivity(clientConnectivity_),
286  transportType(transportType_),
287  ipAddress(""),
288  port(0),
289  QoS(QoS_),
290  ps(ps_),
291  useLegacyCleanup(true)
292  {}
293 
294  };
295 
297  {
298  RequestFlag = 1 << 1,
299  ObserverFlag = 1 << 2
300  };
301 
302  enum class ObserveType
303  {
304  Observe,
305  ObserveAll
306  };
307 
308  // Typedef for list of resource handles.
309  typedef std::vector<OCResourceHandle> ResourceHandles;
310 
311  // Typedef for header option vector.
312  // OCHeaderOption class is in HeaderOption namespace.
313  typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
314 
315  // Typedef for query parameter map.
316  typedef std::map<std::string, std::string> QueryParamsMap;
317 
318  // Typedef for query parameter map with Vector
319  typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
320 
321  // Typedef for list of observation IDs.
322  typedef std::vector<OCObservationId> ObservationIds;
323 
324  enum class ObserveAction
325  {
328  };
329 
330  typedef struct
331  {
332  // Action associated with observation request
334  // Identifier for observation being registered/unregistered
336 
338  std::string address;
339  uint16_t port;
340  } ObservationInfo;
341 
342  // const strings for different interfaces
343 
344  // Default interface
345  const std::string DEFAULT_INTERFACE = "oic.if.baseline";
346 
347  // Used in discovering (GET) links to other resources of a collection.
348  const std::string LINK_INTERFACE = "oic.if.ll";
349 
350  // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
351  const std::string BATCH_INTERFACE = "oic.if.b";
352 
353  // Used in GET, PUT, POST methods on links to other remote resources of a group.
354  const std::string GROUP_INTERFACE = "oic.mi.grp";
355 
356  //Typedef for list direct paired devices
357 
358  typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
359 
360  typedef std::function<void(const std::string&, const int)> FindErrorCallback;
361 
362  typedef std::function<void(std::vector<std::shared_ptr<OCResource>>)> FindResListCallback;
363 
364  typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
365 
366  typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
367 
368  typedef std::function<OCEntityHandlerResult(
369  const std::shared_ptr<OCResourceRequest>)> EntityHandler;
370 
371  typedef std::function<void(OCStackResult, const unsigned int,
372  const std::string&)> SubscribeCallback;
373 
374  typedef std::function<void(const HeaderOptions&,
375  const OCRepresentation&, const int)> GetCallback;
376 
377  typedef std::function<void(const HeaderOptions&,
378  const OCRepresentation&, const int)> PostCallback;
379 
380  typedef std::function<void(const HeaderOptions&,
381  const OCRepresentation&, const int)> PutCallback;
382 
383  typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
384 
385  typedef std::function<void(const HeaderOptions&,
386  const OCRepresentation&, const int, const int)> ObserveCallback;
387 
388  typedef std::function<void(const int, const std::string&,
389  std::shared_ptr<OCResource>)> MQTopicCallback;
390 } // namespace OC
391 
392 #endif
std::function< void(const HeaderOptions &, const int)> DeleteCallback
Definition: OCApi.h:383
OCResourceRequest provides APIs to extract details from a request URI.
Definition: OCResourceRequest.h:44
OCConnectivityType serverConnectivity
default flags for server.
Definition: OCApi.h:144
QualityOfService
Quality of Service attempts to abstract the guarantees provided by the underlying transport protocol...
Definition: OCApi.h:117
OCEntityHandlerResult
Possible returned values from entity handler.
Definition: octypes.h:1229
std::string URI
Definition: OCApi.h:92
const std::string GROUP_INTERFACE
Definition: OCApi.h:354
Acknowledgments are used to confirm delivery.
Definition: octypes.h:972
const std::string DEFAULT_INTERFACE
Definition: OCApi.h:345
value zero indicates discovery.
Definition: octypes.h:663
std::function< void(const int, const std::string &, std::shared_ptr< OCResource >)> MQTopicCallback
Definition: OCApi.h:389
OCAdvertisementStatus
Definition: OCApi.h:87
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, OCPersistentStorage *ps_)
Definition: OCApi.h:177
std::function< OCEntityHandlerResult(const std::shared_ptr< OCResourceRequest >)> EntityHandler
Definition: OCApi.h:369
OCConnectivityType connectivityType
Definition: OCApi.h:337
std::function< void(std::vector< std::shared_ptr< OCResource >>)> FindResListCallback
Definition: OCApi.h:362
ServiceType
Definition: OCApi.h:94
std::vector< HeaderOption::OCHeaderOption > HeaderOptions
Definition: OCApi.h:313
RequestHandlerFlag
Definition: OCApi.h:296
std::function< void(const std::string &, const int)> FindErrorCallback
Definition: OCApi.h:360
ObserveAction
Definition: OCApi.h:324
ServiceType serviceType
indicate InProc or OutOfProc.
Definition: OCApi.h:138
std::vector< OCResourceHandle > ResourceHandles
Definition: OCApi.h:309
std::string ipAddress
not used.
Definition: OCApi.h:153
ObserveType
Definition: OCApi.h:302
Packet delivery is best effort.
Definition: octypes.h:969
This file contains the declaration of classes and its members related to OCRepresentation.
OCResource represents an OC resource.
Definition: OCResource.h:107
ModeType mode
indicate whether we want to do server, client or both.
Definition: OCApi.h:141
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> PutCallback
Definition: OCApi.h:381
Definition: OCApi.h:330
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, const std::string &ipAddress_, const uint16_t port_, const OCTransportAdapter transportType_, const QualityOfService QoS_, OCPersistentStorage *ps_=nullptr)
Definition: OCApi.h:241
std::function< void(OCStackResult, const unsigned int, const std::string &)> SubscribeCallback
Definition: OCApi.h:372
Acknowledgments are used to confirm delivery.
uint16_t port
Definition: OCApi.h:339
Packet delivery is best effort.
Definition: octypes.h:966
QualityOfService QoS
indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined).
Definition: OCApi.h:159
use when defaults are ok.
Definition: octypes.h:832
Packet delivery is best effort.
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> GetCallback
Definition: OCApi.h:375
boost::iostreams::stream< OC::oc_log_stream > log_target_t
Definition: OCApi.h:55
No Quality is defined, let the stack decide.
Definition: octypes.h:975
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> PostCallback
Definition: OCApi.h:378
std::function< void(const OCRepresentation &)> FindPlatformCallback
Definition: OCApi.h:366
uint16_t port
not used.
Definition: OCApi.h:156
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, OCConnectivityType serverConnectivity_, OCConnectivityType clientConnectivity_, OCTransportAdapter transportType_, const QualityOfService QoS_, OCPersistentStorage *ps_=nullptr)
Definition: OCApi.h:275
OCTransportAdapter
These enums (OCTransportAdapter and OCTransportFlags) must be kept synchronized with OCConnectivityTy...
Definition: octypes.h:660
OCTransportAdapter transportType
transport type to initialize.
Definition: OCApi.h:150
OCStackResult
Declares Stack Results & Errors.
Definition: octypes.h:1054
This file contains the definition, types and APIs for resource(s) be implemented. ...
OCConnectivityType
This enum type includes elements of both OCTransportAdapter and OCTransportFlags. ...
Definition: octypes.h:829
Definition: OCApi.h:299
Data structure to provide the configuration.
Definition: OCApi.h:135
std::map< std::string, std::string > QueryParamsMap
Definition: OCApi.h:316
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, OCConnectivityType serverConnectivity_, OCConnectivityType clientConnectivity_, const QualityOfService QoS_, OCPersistentStorage *ps_=nullptr)
Definition: OCApi.h:205
Client server mode along with routing capabilities.
std::function< void(std::shared_ptr< OCResource >)> FindCallback
Definition: OCApi.h:358
std::function< void(const HeaderOptions &, const OCRepresentation &, const int, const int)> ObserveCallback
Definition: OCApi.h:386
auto oclog_target
Definition: OCApi.h:62
bool useLegacyCleanup
This flag allows legacy app to opt in the previous behavior of OCPlatform being cleaned up by the C++...
Definition: OCApi.h:174
std::function< void(const OCRepresentation &)> FindDeviceCallback
Definition: OCApi.h:364
const std::string BATCH_INTERFACE
Definition: OCApi.h:351
OCConnectivityType clientConnectivity
default flags for client.
Definition: OCApi.h:147
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, const std::string &ipAddress_, const uint16_t port_, const QualityOfService QoS_, OCPersistentStorage *ps_=nullptr)
Definition: OCApi.h:223
auto oclog
Definition: OCApi.h:71
ObserveAction action
Definition: OCApi.h:333
OCPlatformStatus
Definition: OCApi.h:81
No Quality is defined, let the stack decide.
Persistent storage handlers.
Definition: octypes.h:1197
PlatformConfig(const ServiceType serviceType_, const ModeType mode_, OCTransportAdapter transportType_, const QualityOfService QoS_, OCPersistentStorage *ps_=nullptr)
Definition: OCApi.h:258
PlatformConfig()
Definition: OCApi.h:192
OCObservationId obsId
Definition: OCApi.h:335
OCPersistentStorage * ps
persistant storage Handler structure (open/read/write/close/unlink).
Definition: OCApi.h:162
ModeType
Host Mode of Operation.
Definition: OCApi.h:103
Definition: OCApi.h:298
uint8_t OCObservationId
Unique identifier for each observation request.
Definition: octypes.h:1165
std::vector< OCObservationId > ObservationIds
Definition: OCApi.h:322
Definition: OCRepresentation.h:84
Packet delivery is best effort.
const std::string LINK_INTERFACE
Definition: OCApi.h:348
std::string address
Definition: OCApi.h:338
std::map< std::string, std::vector< std::string > > QueryParamsList
Definition: OCApi.h:319
OCResourceResponse provides APIs to set the response details.
Definition: OCResourceResponse.h:43