IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RCSRemoteResourceObject.h
Go to the documentation of this file.
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 
27 #ifndef RCSREMOTERESOURCEOBJECT_H
28 #define RCSREMOTERESOURCEOBJECT_H
29 
30 #include <vector>
31 
32 #include "RCSResourceAttributes.h"
33 #include "RCSRepresentation.h"
34 
35 namespace OC
36 {
37  class OCResource;
38 
39  namespace HeaderOption
40  {
41  class OCHeaderOption;
42  }
43 }
44 
45 namespace OIC
46 {
47  namespace Service
48  {
49 
51 
52  typedef std::vector< OC::HeaderOption::OCHeaderOption > HeaderOpts;
53 
60  enum class CacheState
61  {
62  NONE,
63  UNREADY,
65  READY,
66  LOST_SIGNAL,
67  };
68 
69  enum class CacheMode
70  {
73  };
74 
81  enum class ResourceState
82  {
83  NONE,
84  REQUESTED,
86  ALIVE,
87  LOST_SIGNAL,
88  DESTROYED
89  };
90 
91  class PrimitiveResource;
92 
99  {
100  public:
101  typedef std::unordered_map< std::string, std::string > Map;
102 
103  public:
104 
110  RCSQueryParams& setResourceInterface(std::string interface);
111 
117  RCSQueryParams& setResourceType(std::string type);
118 
128  RCSQueryParams& put(std::string key, std::string value);
129 
133  std::string getResourceInterface() const;
134 
138  std::string getResourceType() const;
139 
147  std::string get(const std::string& key) const;
148 
152  const Map& getAll() const;
153 
154  private:
155  std::string m_resourceInterface;
156  std::string m_resourceType;
157 
158  std::unordered_map< std::string, std::string > m_map;
159  };
160 
173  {
174  public:
175  typedef std::shared_ptr< RCSRemoteResourceObject > Ptr;
176 
183  typedef std::function< void(ResourceState) > StateChangedCallback;
184 
190  typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) >
192 
202  typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) >
204 
214  typedef std::function< void(const HeaderOpts& headerOpts,
215  const RCSRepresentation& rep, int eCode) > GetCallback;
216 
226  typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) >
228 
238  typedef std::function< void(const HeaderOpts& headerOpts,
239  const RCSRepresentation& rep, int eCode) > SetCallback;
240 
241  private:
242  typedef int CacheID;
243  typedef unsigned int BrokerID;
244 
245  public:
247  RCSRemoteResourceObject(std::shared_ptr< PrimitiveResource >);
249 
251 
258  std::shared_ptr< OC::OCResource > ocResource);
259 
265  static std::shared_ptr< OC::OCResource > toOCResource(
266  RCSRemoteResourceObject::Ptr rcsResource);
267 
273  bool isMonitoring() const;
274 
281  bool isCaching() const;
282 
287  bool isObservable() const;
288 
309 
318  void stopMonitoring();
319 
325  ResourceState getState() const;
326 
343  void startCaching();
344 
367 
376  void stopCaching();
377 
382  CacheState getCacheState() const;
383 
392  bool isCachedAvailable() const;
393 
410 
427  RCSResourceAttributes::Value getCachedAttribute(const std::string& key) const;
428 
441 
452  void get(GetCallback cb);
453 
467  void get(const RCSQueryParams& queryParams, GetCallback cb);
468 
485  void setRemoteAttributes(const RCSResourceAttributes& attributes,
487 
504  void set(const RCSResourceAttributes& attributes, SetCallback cb);
505 
523  void set(const RCSQueryParams& queryParams, const RCSResourceAttributes& attributes,
524  SetCallback cb);
525 
543  void set(const RCSQueryParams& queryParams, const RCSRepresentation &rep,
544  SetCallback cb);
545 
550  std::string getUri() const;
551 
556  std::string getAddress() const;
557 
562  std::vector< std::string > getTypes() const;
563 
568  std::vector< std::string > getInterfaces() const;
569 
570  private:
571  std::shared_ptr< PrimitiveResource > m_primitiveResource;
572  CacheID m_cacheId;
573  BrokerID m_brokerId;
574  };
575  }
576 }
577 #endif // RCSREMOTERESOURCEOBJECT_H
bool isObservable() const
Returns whether the resource is observable.
void getRemoteAttributes(RemoteAttributesGetCallback cb)
Gets resource attributes directly from the server.
CacheState getCacheState() const
Returns the current cache state.
std::function< void(const HeaderOpts &headerOpts, const RCSRepresentation &rep, int eCode) > GetCallback
Callback definition to be invoked when the response of get is received.
Definition: RCSRemoteResourceObject.h:215
Monitoring is started and checking state is in progress.
bool isCaching() const
Returns whether caching is enabled.
void startMonitoring(StateChangedCallback cb)
Starts monitoring the resource.
bool isCachedAvailable() const
Returns whether cached data is available.
const Map & getAll() const
Returns all params.
RCSQueryParams & put(std::string key, std::string value)
Sets a resource type of the resource to operate on.
std::function< void(ResourceState) > StateChangedCallback
Callback definition to be invoked when monitoring state is changed.
Definition: RCSRemoteResourceObject.h:183
static std::shared_ptr< OC::OCResource > toOCResource(RCSRemoteResourceObject::Ptr rcsResource)
Returns an equivalent OCResource using RCSRemoteResourceObject instance.
This file contains the declaration of classes and its members related to RCSResourceAttributes.
This class describes a resource representation.
Definition: RCSRepresentation.h:42
std::string getResourceType() const
Returns the resource type.
std::vector< std::string > getInterfaces() const
Returns the resource interfaces of the resource.
ResourceState
The states of monitoring.
Definition: RCSRemoteResourceObject.h:81
std::function< void(const RCSResourceAttributes &attrs, int eCode) > RemoteAttributesGetCallback
Callback definition to be invoked when the response of getRemoteAttributes is received.
Definition: RCSRemoteResourceObject.h:203
RCSResourceAttributes getCachedAttributes() const
Gets the cached RCSResourceAttributes data.
std::vector< std::string > getTypes() const
Returns the resource types of the resource.
Caching is started, but the data is not ready yet.
std::function< void(const RCSResourceAttributes &attrs, int eCode) > RemoteAttributesSetCallback
Callback definition to be invoked when the response of setRemoteAttributes is received.
Definition: RCSRemoteResourceObject.h:227
Value holds a value among various types at a time.
Definition: RCSResourceAttributes.h:432
void startCaching()
Starts caching attributes of the resource.
std::string getUri() const
Returns the uri of the resource.
std::string getAddress() const
Returns the address of the resource .
std::shared_ptr< RCSRemoteResourceObject > Ptr
Definition: RCSRemoteResourceObject.h:175
std::vector< OC::HeaderOption::OCHeaderOption > HeaderOpts
Definition: RCSRemoteResourceObject.h:50
std::unordered_map< std::string, std::string > Map
Definition: RCSRemoteResourceObject.h:101
This represents the attributes for a resource.
Definition: RCSResourceAttributes.h:195
The resource is alive.
void stopMonitoring()
Stops monitoring the resource.
CacheMode
Definition: RCSRemoteResourceObject.h:69
Failed to reach the resource.
ResourceState getState() const
Returns the current state of the resource.
bool isMonitoring() const
Returns whether monitoring is enabled.
This is to specify query parameters for requests to the server.
Definition: RCSRemoteResourceObject.h:98
static RCSRemoteResourceObject::Ptr fromOCResource(std::shared_ptr< OC::OCResource > ocResource)
Creates an instance from an OCResource instance.
RCSQueryParams & setResourceInterface(std::string interface)
Sets an interface of the resource to operate on.
Caching is not started.
This structure will be used to define the vendor specific header options to be included in communicat...
Definition: octypes.h:1258
std::function< void(const RCSResourceAttributes &attrs, int eCode) > CacheUpdatedCallback
Callback definition to be invoked when cache is updated.
Definition: RCSRemoteResourceObject.h:191
RCSResourceAttributes::Value getCachedAttribute(const std::string &key) const
Gets a particular cached a ResourceAttribute Value.
void setRemoteAttributes(const RCSResourceAttributes &attributes, RemoteAttributesSetCallback cb)
Sends a set request with resource attributes to the server.
This represents a remote resource and provides simple ways to interact with it.
Definition: RCSRemoteResourceObject.h:172
std::string getResourceInterface() const
Returns the resource interface.
RCSQueryParams & setResourceType(std::string type)
Sets a resource type of the resource to operate on.
void set(const RCSResourceAttributes &attributes, SetCallback cb)
Sends a set request with resource attributes to the server.
CacheState
The states of caching.
Definition: RCSRemoteResourceObject.h:60
std::function< void(const HeaderOpts &headerOpts, const RCSRepresentation &rep, int eCode) > SetCallback
Callback definition to be invoked when the response of set is received.
Definition: RCSRemoteResourceObject.h:239