IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OIC::Service::RCSRemoteResourceObject Class Reference

This represents a remote resource and provides simple ways to interact with it. More...

Public Types

typedef std::shared_ptr
< RCSRemoteResourceObject
Ptr
 
typedef std::function< void(ResourceState) > StateChangedCallback
 Callback definition to be invoked when monitoring state is changed. More...
 
typedef std::function< void(const
RCSResourceAttributes &attrs,
int eCode) > 
CacheUpdatedCallback
 Callback definition to be invoked when cache is updated. More...
 
typedef std::function< void(const
RCSResourceAttributes &attrs,
int eCode) > 
RemoteAttributesGetCallback
 Callback definition to be invoked when the response of getRemoteAttributes is received. More...
 
typedef std::function< void(const
HeaderOpts &headerOpts, const
RCSRepresentation &rep, int
eCode) > 
GetCallback
 Callback definition to be invoked when the response of get is received. More...
 
typedef std::function< void(const
RCSResourceAttributes &attrs,
int eCode) > 
RemoteAttributesSetCallback
 Callback definition to be invoked when the response of setRemoteAttributes is received. More...
 
typedef std::function< void(const
HeaderOpts &headerOpts, const
RCSRepresentation &rep, int
eCode) > 
SetCallback
 Callback definition to be invoked when the response of set is received. More...
 

Public Member Functions

 ~RCSRemoteResourceObject ()
 
bool isMonitoring () const
 Returns whether monitoring is enabled. More...
 
bool isCaching () const
 Returns whether caching is enabled. More...
 
bool isObservable () const
 Returns whether the resource is observable. More...
 
void startMonitoring (StateChangedCallback cb)
 Starts monitoring the resource. More...
 
void stopMonitoring ()
 Stops monitoring the resource. More...
 
ResourceState getState () const
 Returns the current state of the resource. More...
 
void startCaching ()
 Starts caching attributes of the resource. More...
 
void startCaching (CacheUpdatedCallback cb, CacheMode mode=CacheMode::OBSERVE_WITH_POLLING)
 Starts caching attributes for the resource. More...
 
void stopCaching ()
 Stops caching. More...
 
CacheState getCacheState () const
 Returns the current cache state. More...
 
bool isCachedAvailable () const
 Returns whether cached data is available. More...
 
RCSResourceAttributes getCachedAttributes () const
 Gets the cached RCSResourceAttributes data. More...
 
RCSResourceAttributes::Value getCachedAttribute (const std::string &key) const
 Gets a particular cached a ResourceAttribute Value. More...
 
void getRemoteAttributes (RemoteAttributesGetCallback cb)
 Gets resource attributes directly from the server. More...
 
void get (GetCallback cb)
 Gets resource representation with empty query parameters directly from the server. More...
 
void get (const RCSQueryParams &queryParams, GetCallback cb)
 Gets resource representation directly from the server. More...
 
void setRemoteAttributes (const RCSResourceAttributes &attributes, RemoteAttributesSetCallback cb)
 Sends a set request with resource attributes to the server. More...
 
void set (const RCSResourceAttributes &attributes, SetCallback cb)
 Sends a set request with resource attributes to the server. More...
 
void set (const RCSQueryParams &queryParams, const RCSResourceAttributes &attributes, SetCallback cb)
 Sends a set request with resource attributes to the server. More...
 
void set (const RCSQueryParams &queryParams, const RCSRepresentation &rep, SetCallback cb)
 Sends a set request with resource representation to the server. More...
 
std::string getUri () const
 Returns the uri of the resource. More...
 
std::string getAddress () const
 Returns the address of the resource . More...
 
std::vector< std::string > getTypes () const
 Returns the resource types of the resource. More...
 
std::vector< std::string > getInterfaces () const
 Returns the resource interfaces of the resource. More...
 

Static Public Member Functions

static RCSRemoteResourceObject::Ptr fromOCResource (std::shared_ptr< OC::OCResource > ocResource)
 Creates an instance from an OCResource instance. More...
 
static std::shared_ptr
< OC::OCResource
toOCResource (RCSRemoteResourceObject::Ptr rcsResource)
 Returns an equivalent OCResource using RCSRemoteResourceObject instance. More...
 

Detailed Description

This represents a remote resource and provides simple ways to interact with it.

Basically this is a client of a remote resource that runs on other device.

The class supports features to help get information of a remote resource such as monitoring and caching.

See Also
RCSDiscoveryManager

Member Typedef Documentation

typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) > OIC::Service::RCSRemoteResourceObject::CacheUpdatedCallback

Callback definition to be invoked when cache is updated.

Parameters
attrsthe updated attributes
typedef std::function< void(const HeaderOpts& headerOpts, const RCSRepresentation& rep, int eCode) > OIC::Service::RCSRemoteResourceObject::GetCallback

Callback definition to be invoked when the response of get is received.

Parameters
HeaderOpts
repthe result representation
eCodethe error code received from the resource
See Also
get
typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) > OIC::Service::RCSRemoteResourceObject::RemoteAttributesGetCallback

Callback definition to be invoked when the response of getRemoteAttributes is received.

Parameters
attrsthe result attributes
eCodethe error code received from the resource
See Also
getRemoteAttributes
typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) > OIC::Service::RCSRemoteResourceObject::RemoteAttributesSetCallback

Callback definition to be invoked when the response of setRemoteAttributes is received.

Parameters
attrsthe result attributes
eCodethe error code received from the resource
See Also
setRemoteAttributes
typedef std::function< void(const HeaderOpts& headerOpts, const RCSRepresentation& rep, int eCode) > OIC::Service::RCSRemoteResourceObject::SetCallback

Callback definition to be invoked when the response of set is received.

Parameters
HeaderOpts
repthe result representation
eCodethe error code received from the resource
See Also
set

Callback definition to be invoked when monitoring state is changed.

See Also
startMonitioring
ResourceState

Constructor & Destructor Documentation

OIC::Service::RCSRemoteResourceObject::~RCSRemoteResourceObject ( )

Member Function Documentation

static RCSRemoteResourceObject::Ptr OIC::Service::RCSRemoteResourceObject::fromOCResource ( std::shared_ptr< OC::OCResource ocResource)
static

Creates an instance from an OCResource instance.

Exceptions
RCSInvalidParameterExceptionIf ocResource is nullptr.
void OIC::Service::RCSRemoteResourceObject::get ( GetCallback  cb)

Gets resource representation with empty query parameters directly from the server.

Parameters
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
Note
The callback will be invoked in an internal thread.
void OIC::Service::RCSRemoteResourceObject::get ( const RCSQueryParams queryParams,
GetCallback  cb 
)

Gets resource representation directly from the server.

The response could be different by the query parameters, it depends on server.

Parameters
queryParamsQuery parameters
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
Note
The callback will be invoked in an internal thread.
std::string OIC::Service::RCSRemoteResourceObject::getAddress ( ) const

Returns the address of the resource .

RCSResourceAttributes::Value OIC::Service::RCSRemoteResourceObject::getCachedAttribute ( const std::string &  key) const

Gets a particular cached a ResourceAttribute Value.

Precondition
Cache should be available.
Returns
A requested attribute value.
Exceptions
BadRequestExceptionIf the precondition is not fulfilled.
InvalidKeyExceptionIf key doesn't match the key of any value.
See Also
RCSResourceAttributes::Value
isCachedAvailable()
startCaching()
startCaching(CacheUpdatedCallback)
RCSResourceAttributes OIC::Service::RCSRemoteResourceObject::getCachedAttributes ( ) const

Gets the cached RCSResourceAttributes data.

Precondition
Cache should be available.
Returns
The cached attributes.
Exceptions
BadRequestExceptionIf the precondition is not fulfilled.
See Also
RCSResourceAttributes
isCachedAvailable()
startCaching()
startCaching(CacheUpdatedCallback)
CacheState OIC::Service::RCSRemoteResourceObject::getCacheState ( ) const

Returns the current cache state.

std::vector< std::string > OIC::Service::RCSRemoteResourceObject::getInterfaces ( ) const

Returns the resource interfaces of the resource.

void OIC::Service::RCSRemoteResourceObject::getRemoteAttributes ( RemoteAttributesGetCallback  cb)

Gets resource attributes directly from the server.

This API send a get request to the resource of interest and provides the attributes to the caller in the RemoteAttributesGetCallback.

Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
Note
The callback will be invoked in an internal thread.
ResourceState OIC::Service::RCSRemoteResourceObject::getState ( ) const

Returns the current state of the resource.

See Also
startMonitoring
std::vector< std::string > OIC::Service::RCSRemoteResourceObject::getTypes ( ) const

Returns the resource types of the resource.

std::string OIC::Service::RCSRemoteResourceObject::getUri ( ) const

Returns the uri of the resource.

bool OIC::Service::RCSRemoteResourceObject::isCachedAvailable ( ) const

Returns whether cached data is available.

Cache will be available always once cache state had been CacheState::READY even if current state is CacheState::LOST_SIGNAL.

See Also
getCacheState()
bool OIC::Service::RCSRemoteResourceObject::isCaching ( ) const

Returns whether caching is enabled.

See Also
startCaching()
bool OIC::Service::RCSRemoteResourceObject::isMonitoring ( ) const

Returns whether monitoring is enabled.

See Also
startMonitoring()
bool OIC::Service::RCSRemoteResourceObject::isObservable ( ) const

Returns whether the resource is observable.

void OIC::Service::RCSRemoteResourceObject::set ( const RCSResourceAttributes attributes,
SetCallback  cb 
)

Sends a set request with resource attributes to the server.

The SetRequest behavior depends on query parameters and the server.

Parameters
attributesAttributes to set
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
See Also
RCSResourceObject
RCSResourceObject::SetRequestHandlerPolicy
Note
The callback will be invoked in an internal thread.
void OIC::Service::RCSRemoteResourceObject::set ( const RCSQueryParams queryParams,
const RCSResourceAttributes attributes,
SetCallback  cb 
)

Sends a set request with resource attributes to the server.

The SetRequest behavior depends on query parameters and the server.

Parameters
queryParamsQuery parameters
attributesAttributes to set
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
See Also
RCSResourceObject
RCSResourceObject::SetRequestHandlerPolicy
Note
The callback will be invoked in an internal thread.
void OIC::Service::RCSRemoteResourceObject::set ( const RCSQueryParams queryParams,
const RCSRepresentation rep,
SetCallback  cb 
)

Sends a set request with resource representation to the server.

The SetRequest behavior depends on query parameters and the server.

Parameters
queryParamsQuery parameters
repRepresentation to set
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
See Also
RCSResourceObject
RCSResourceObject::SetRequestHandlerPolicy
Note
The callback will be invoked in an internal thread.
void OIC::Service::RCSRemoteResourceObject::setRemoteAttributes ( const RCSResourceAttributes attributes,
RemoteAttributesSetCallback  cb 
)

Sends a set request with resource attributes to the server.

The SetRequest behavior depends on the server, whether updating its attributes or not.

Parameters
attributesAttributes to set
cbA callback to receive the response.
Exceptions
PlatformExceptionIf the operation failed
InvalidParameterExceptionIf cb is an empty function or null.
See Also
RCSResourceObject
RCSResourceObject::SetRequestHandlerPolicy
Note
The callback will be invoked in an internal thread.
void OIC::Service::RCSRemoteResourceObject::startCaching ( )

Starts caching attributes of the resource.

This will start caching for the resource. Once caching started it will look for the data updation on the resource and updates the cache data accordingly.

It is equivalent to calling startCaching(CacheUpdatedCallback) with an empty function.

See Also
getCacheState()
getCachedAttributes()
getCachedAttribute(const std::string&) const
Exceptions
BadRequestException
void OIC::Service::RCSRemoteResourceObject::startCaching ( CacheUpdatedCallback  cb,
CacheMode  mode = CacheMode::OBSERVE_WITH_POLLING 
)

Starts caching attributes for the resource.

This will start data caching for the resource. Once caching started it will look for the data updation on the resource and updates the cached data accordingly.

Parameters
cbIf non-empty function, it will be invoked whenever the cache updated.
modeif CacheMode is OBSERVE_ONLY, it will be invoked when receive observe response only.
Exceptions
BadRequestExceptionIf caching is already started.
Note
The callback will be invoked in an internal thread.
See Also
CacheUpdatedCallback
getCacheState()
isCachedAvailable()
getCachedAttributes()
getCachedAttribute(const std::string&) const
void OIC::Service::RCSRemoteResourceObject::startMonitoring ( StateChangedCallback  cb)

Starts monitoring the resource.

Monitoring provides a feature to check the presence of a resource, even when the server is not announcing Presence using startPresnece.

Parameters
cbA Callback to get changed resource state.
Exceptions
InvalidParameterExceptionIf cb is an empty function or null.
BadRequestExceptionIf monitoring is already started.
Note
The callback will be invoked in an internal thread.
See Also
StateChangedCallback
ResourceState
isMonitoring()
stopMonitoring()
void OIC::Service::RCSRemoteResourceObject::stopCaching ( )

Stops caching.

It does nothing if caching is not started.

See Also
startCaching()
startCaching(CacheUpdatedCallback)
void OIC::Service::RCSRemoteResourceObject::stopMonitoring ( )

Stops monitoring the resource.

It does nothing if monitoring is not started.

See Also
startMonitoring()
static std::shared_ptr< OC::OCResource > OIC::Service::RCSRemoteResourceObject::toOCResource ( RCSRemoteResourceObject::Ptr  rcsResource)
static

Returns an equivalent OCResource using RCSRemoteResourceObject instance.

Exceptions
RCSInvalidParameterExceptionIf rcsResource is nullptr.

The documentation for this class was generated from the following file: