IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OCResource.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_RESOURCE_H_
29 #define OC_RESOURCE_H_
30 
31 #include <memory>
32 #include <random>
33 #include <algorithm>
34 
35 #include <OCApi.h>
36 #include <ResourceInitException.h>
37 #include <IClientWrapper.h>
38 #include <InProcClientWrapper.h>
39 #include <OCRepresentation.h>
40 
41 namespace OC
42 {
43  class OCResource;
44  class OCResourceIdentifier;
45  std::ostream& operator <<(std::ostream& os, const OCResourceIdentifier& ri);
54  {
55  friend class OCResource;
56  friend std::ostream& operator <<(std::ostream& os, const OCResourceIdentifier& ri);
57 
58  public:
59  OCResourceIdentifier() = delete;
60 
62 
63 #if defined(_MSC_VER) && (_MSC_VER < 1900)
65  m_resourceUri(std::move(o.m_resourceUri)),
66  m_representation(o.m_representation)
67  {
68  }
69 #else
71 #endif
72 
74 
76 
77  bool operator==(const OCResourceIdentifier &other) const;
78 
79  bool operator!=(const OCResourceIdentifier &other) const;
80 
81  bool operator<(const OCResourceIdentifier &other) const;
82 
83  bool operator>(const OCResourceIdentifier &other) const;
84 
85  bool operator<=(const OCResourceIdentifier &other) const;
86 
87  bool operator>=(const OCResourceIdentifier &other) const;
88 
89  private:
90 
91  OCResourceIdentifier(const std::string& wireServerIdentifier,
92  const std::string& resourceUri );
93 
94  private:
95  std::string m_representation;
96  const std::string& m_resourceUri;
97  };
98 
108  {
109  friend class OCPlatform_impl;
110  friend class ListenOCContainer;
111  public:
112  typedef std::shared_ptr<OCResource> Ptr;
113 
114 #if defined(_MSC_VER) && (_MSC_VER < 1900)
115  OCResource(OCResource&& o):
116  m_clientWrapper(std::move(o.m_clientWrapper)),
117  m_uri(std::move(o.m_uri)),
118  m_resourceId(std::move(o.m_resourceId)),
119  m_devAddr(std::move(o.m_devAddr)),
120  m_useHostString(o.m_useHostString),
121  m_property(o.m_property),
122  m_isCollection(o.m_isCollection),
123  m_resourceTypes(std::move(o.m_resourceTypes)),
124  m_interfaces(std::move(o.m_interfaces)),
125  m_children(std::move(m_children)),
126  m_endpoints(std::move(m_endpoints)),
127  m_serverHeaderOptions(std::move(m_serverHeaderOptions)),
128  m_observeHandle(std::move(m_observeHandle)),
129  m_headerOptions(std::move(m_headerOptions))
130  {
131  }
132 #else
133  OCResource(OCResource&&) = default;
134 #endif
135  // Explicitly delete the copy ctor since VS2013 would try to generate one, and
136  // the standard says that defaulting the move ctor should delete the copy ctor.
137  OCResource(const OCResource&) = delete;
138 
139  // We cannot support copy/move assigns since OCResourceIdentifier doesn't.
140  OCResource& operator=(OCResource&&) = delete;
141  OCResource& operator=(const OCResource&) = delete;
142 
146  virtual ~OCResource(void);
147 
158  OCStackResult get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
170  OCStackResult get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler,
171  QualityOfService QoS);
172 
205  OCStackResult get(const std::string& resourceType, const std::string& resourceInterface,
206  const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
240  OCStackResult get(const std::string& resourceType, const std::string& resourceInterface,
241  const QueryParamsMap& queryParametersMap, GetCallback attributeHandler,
242  QualityOfService QoS);
243 
259  OCStackResult put(const OCRepresentation& representation,
260  const QueryParamsMap& queryParametersMap, PutCallback attributeHandler);
277  OCStackResult put(const OCRepresentation& representation,
278  const QueryParamsMap& queryParametersMap, PutCallback attributeHandler,
279  QualityOfService QoS);
280 
300  OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
301  const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
302  PutCallback attributeHandler);
322  OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
323  const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
324  PutCallback attributeHandler, QualityOfService QoS);
325 
340  OCStackResult post(const OCRepresentation& representation,
341  const QueryParamsMap& queryParametersMap, PostCallback attributeHandler);
357  OCStackResult post(const OCRepresentation& representation,
358  const QueryParamsMap& queryParametersMap, PostCallback attributeHandler,
359  QualityOfService QoS);
360 
380  OCStackResult post(const std::string& resourceType, const std::string& resourceInterface,
381  const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
382  PostCallback attributeHandler);
403  OCStackResult post(const std::string& resourceType, const std::string& resourceInterface,
404  const OCRepresentation& representation, const QueryParamsMap& queryParametersMap,
405  PostCallback attributeHandler, QualityOfService QoS);
406 
419 
433  OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
434  ObserveCallback observeHandler);
449  OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
450  ObserveCallback observeHandler, QualityOfService qos);
451 
461 
475  void setHeaderOptions(const HeaderOptions& headerOptions);
476 
480  void unsetHeaderOptions();
481 
487  std::string host() const;
488 
493  std::vector<std::string> getAllHosts() const;
494 
500 
505  std::string uri() const;
506 
512 
518  bool isObservable() const;
519 
525  std::string setHost(const std::string& host);
526 #ifdef WITH_MQ
527 
532  bool isPublish() const;
533 #endif
534 
539  std::vector<std::string> getResourceTypes() const;
540 
545  std::vector<std::string> getResourceInterfaces(void) const;
546 
547  // TODO-CA Revisit this since we are exposing two identifiers
557 
562  std::string sid() const;
563 
564 #ifdef WITH_MQ
565 
576  OCStackResult discoveryMQTopics(const QueryParamsMap& queryParametersMap,
577  MQTopicCallback attributeHandler,
578  QualityOfService qos);
593  OCStackResult createMQTopic(const OCRepresentation& rep,
594  const std::string& topicUri,
595  const QueryParamsMap& queryParametersMap,
596  MQTopicCallback attributeHandler,
597  QualityOfService qos);
598 #endif
599 #ifdef MQ_SUBSCRIBER
600 
612  OCStackResult subscribeMQTopic(ObserveType observeType,
613  const QueryParamsMap& queryParametersMap,
614  ObserveCallback observeHandler,
615  QualityOfService qos);
616 
626  OCStackResult unsubscribeMQTopic(QualityOfService qos);
627 
640  OCStackResult requestMQPublish(const QueryParamsMap& queryParametersMap,
641  PostCallback attributeHandler,
642  QualityOfService qos);
643 #endif
644 #ifdef MQ_PUBLISHER
645 
657  OCStackResult publishMQTopic(const OCRepresentation& rep,
658  const QueryParamsMap& queryParametersMap,
659  PostCallback attributeHandler,
660  QualityOfService qos);
661 #endif
662  // overloaded operators allow for putting into a 'set'
663  // the uniqueidentifier allows for putting into a hash
664  bool operator==(const OCResource &other) const;
665 
666  bool operator!=(const OCResource &other) const;
667 
668  bool operator<(const OCResource &other) const;
669 
670  bool operator>(const OCResource &other) const;
671 
672  bool operator<=(const OCResource &other) const;
673 
674  bool operator>=(const OCResource &other) const;
675 
676  private:
677  std::weak_ptr<IClientWrapper> m_clientWrapper;
678  std::string m_uri;
679  OCResourceIdentifier m_resourceId;
680  OCDevAddr m_devAddr;
681  bool m_useHostString;
682  bool m_isCollection;
683  uint8_t m_property;
684  std::vector<std::string> m_resourceTypes;
685  std::vector<std::string> m_interfaces;
686  std::vector<std::string> m_children;
687  std::vector<std::string> m_endpoints;
688  HeaderOptions m_serverHeaderOptions;
689  OCDoHandle m_observeHandle;
690  HeaderOptions m_headerOptions;
691 
692  private:
693  OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
694  const OCDevAddr& devAddr, const std::string& uri,
695  const std::string& serverId, uint8_t property,
696  const std::vector<std::string>& resourceTypes,
697  const std::vector<std::string>& interfaces);
698 
699  OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
700  const OCDevAddr& devAddr, const std::string& uri,
701  const std::string& serverId, uint8_t property,
702  const std::vector<std::string>& resourceTypes,
703  const std::vector<std::string>& interfaces,
704  const std::vector<std::string>& endpoints,
705  const HeaderOptions& serverHeaderOptions);
706 
707  OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
708  const std::string& host, const std::string& uri,
709  const std::string& serverId,
710  OCConnectivityType connectivityType, uint8_t property,
711  const std::vector<std::string>& resourceTypes,
712  const std::vector<std::string>& interfaces);
713 
714  OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
715  const std::string& host, const std::string& uri,
716  const std::string& serverId,
717  OCConnectivityType connectivityType, uint8_t property,
718  const std::vector<std::string>& resourceTypes,
719  const std::vector<std::string>& interfaces,
720  const std::vector<std::string>& endpoints);
721  };
722 
723 } // namespace OC
724 
725 #endif // OC_RESOURCE_H
726 
void unsetHeaderOptions()
Function to unset header options.
std::function< void(const HeaderOptions &, const int)> DeleteCallback
Definition: OCApi.h:383
OCStackResult deleteResource(DeleteCallback deleteHandler)
Function to perform DELETE operation.
QualityOfService
Quality of Service attempts to abstract the guarantees provided by the underlying transport protocol...
Definition: OCApi.h:117
bool operator<=(const OCResourceIdentifier &other) const
std::function< void(const int, const std::string &, std::shared_ptr< OCResource >)> MQTopicCallback
Definition: OCApi.h:389
std::string uri() const
Function to get the URI for this resource.
OCResourceIdentifier uniqueIdentifier() const
Function to get a unique identifier for this resource across network interfaces.
std::vector< HeaderOption::OCHeaderOption > HeaderOptions
Definition: OCApi.h:313
virtual ~OCResource(void)
Virtual destructor.
bool operator>(const OCResourceIdentifier &other) const
bool operator<(const OCResourceIdentifier &other) const
std::shared_ptr< OCResource > Ptr
Definition: OCResource.h:112
ObserveType
Definition: OCApi.h:302
OCResourceIdentifier & operator=(const OCResourceIdentifier &)=delete
This file contains the declaration of classes and its members related to OCRepresentation.
friend std::ostream & operator<<(std::ostream &os, const OCResourceIdentifier &ri)
OCResource represents an OC resource.
Definition: OCResource.h:107
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> PutCallback
Definition: OCApi.h:381
bool operator>=(const OCResource &other) const
OCResource & operator=(OCResource &&)=delete
friend class OCPlatform_impl
Definition: OCResource.h:109
OCStackResult cancelObserve()
Function to cancel the observation on the resource.
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> GetCallback
Definition: OCApi.h:375
std::function< void(const HeaderOptions &, const OCRepresentation &, const int)> PostCallback
Definition: OCApi.h:378
std::vector< std::string > getResourceInterfaces(void) const
Function to get the list of resource interfaces.
OCStackResult
Declares Stack Results & Errors.
Definition: octypes.h:1054
OCStackResult post(const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PostCallback attributeHandler)
Function to post on a resource.
void * OCDoHandle
Handle to an OCDoResource invocation.
Definition: octypes.h:1147
OCConnectivityType
This enum type includes elements of both OCTransportAdapter and OCTransportFlags. ...
Definition: octypes.h:829
std::string sid() const
Function to get a string representation of the resource's server ID.
OCConnectivityType connectivityType() const
Function to get the connectivity type of this resource.
bool operator!=(const OCResourceIdentifier &other) const
std::ostream & operator<<(std::ostream &os, const OCRepresentation::AttributeItem &ai)
std::map< std::string, std::string > QueryParamsMap
Definition: OCApi.h:316
HeaderOptions getServerHeaderOptions() const
Function to get the header options information from response.
std::function< void(const HeaderOptions &, const OCRepresentation &, const int, const int)> ObserveCallback
Definition: OCApi.h:386
std::vector< std::string > getResourceTypes() const
Function to get the list of resource types.
bool operator==(const OCResourceIdentifier &other) const
OCStackResult observe(ObserveType observeType, const QueryParamsMap &queryParametersMap, ObserveCallback observeHandler)
Function to set observation on the resource.
friend class ListenOCContainer
Definition: OCResource.h:110
OCResource(OCResource &&)=default
bool isObservable() const
Function to provide ability to check if this resource is observable or not.
OCStackResult put(const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PutCallback attributeHandler)
Function to set the representation of a resource (via PUT)
std::string setHost(const std::string &host)
Function to change host of this reource.
bool operator==(const OCResource &other) const
bool operator!=(const OCResource &other) const
OCResourceIdentifier represents the identity information for a server.
Definition: OCResource.h:53
void setHeaderOptions(const HeaderOptions &headerOptions)
Function to set header information.
Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
Definition: octypes.h:796
bool operator<(const OCResource &other) const
bool operator>=(const OCResourceIdentifier &other) const
std::vector< std::string > getAllHosts() const
Function to get the endpoints information of this resource.
Definition: OCRepresentation.h:84
bool operator>(const OCResource &other) const
std::string host() const
Function to get the host address of this resource.
bool operator<=(const OCResource &other) const