IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OC::OCResource Class Reference

OCResource represents an OC resource. More...

Public Types

typedef std::shared_ptr
< OCResource
Ptr
 

Public Member Functions

 OCResource (OCResource &&)=default
 
 OCResource (const OCResource &)=delete
 
OCResourceoperator= (OCResource &&)=delete
 
OCResourceoperator= (const OCResource &)=delete
 
virtual ~OCResource (void)
 Virtual destructor. More...
 
OCStackResult get (const QueryParamsMap &queryParametersMap, GetCallback attributeHandler)
 Function to get the attributes of a resource. More...
 
OCStackResult get (const QueryParamsMap &queryParametersMap, GetCallback attributeHandler, QualityOfService QoS)
 Function to get the attributes of a resource. More...
 
OCStackResult get (const std::string &resourceType, const std::string &resourceInterface, const QueryParamsMap &queryParametersMap, GetCallback attributeHandler)
 Function to get the attributes of a resource. More...
 
OCStackResult get (const std::string &resourceType, const std::string &resourceInterface, const QueryParamsMap &queryParametersMap, GetCallback attributeHandler, QualityOfService QoS)
 Function to get the attributes of a resource. More...
 
OCStackResult put (const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PutCallback attributeHandler)
 Function to set the representation of a resource (via PUT) More...
 
OCStackResult put (const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PutCallback attributeHandler, QualityOfService QoS)
 Function to set the representation of a resource (via PUT) More...
 
OCStackResult put (const std::string &resourceType, const std::string &resourceInterface, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PutCallback attributeHandler)
 Function to set the attributes of a resource (via PUT) More...
 
OCStackResult put (const std::string &resourceType, const std::string &resourceInterface, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PutCallback attributeHandler, QualityOfService QoS)
 Function to set the attributes of a resource (via PUT) More...
 
OCStackResult post (const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PostCallback attributeHandler)
 Function to post on a resource. More...
 
OCStackResult post (const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PostCallback attributeHandler, QualityOfService QoS)
 Function to post on a resource. More...
 
OCStackResult post (const std::string &resourceType, const std::string &resourceInterface, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PostCallback attributeHandler)
 Function to post on a resource. More...
 
OCStackResult post (const std::string &resourceType, const std::string &resourceInterface, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, PostCallback attributeHandler, QualityOfService QoS)
 Function to post on a resource. More...
 
OCStackResult deleteResource (DeleteCallback deleteHandler)
 Function to perform DELETE operation. More...
 
OCStackResult deleteResource (DeleteCallback deleteHandler, QualityOfService QoS)
 
OCStackResult observe (ObserveType observeType, const QueryParamsMap &queryParametersMap, ObserveCallback observeHandler)
 Function to set observation on the resource. More...
 
OCStackResult observe (ObserveType observeType, const QueryParamsMap &queryParametersMap, ObserveCallback observeHandler, QualityOfService qos)
 Function to set observation on the resource. More...
 
OCStackResult cancelObserve ()
 Function to cancel the observation on the resource. More...
 
OCStackResult cancelObserve (QualityOfService qos)
 
void setHeaderOptions (const HeaderOptions &headerOptions)
 Function to set header information. More...
 
void unsetHeaderOptions ()
 Function to unset header options. More...
 
std::string host () const
 Function to get the host address of this resource. More...
 
std::vector< std::string > getAllHosts () const
 Function to get the endpoints information of this resource. More...
 
HeaderOptions getServerHeaderOptions () const
 Function to get the header options information from response. More...
 
std::string uri () const
 Function to get the URI for this resource. More...
 
OCConnectivityType connectivityType () const
 Function to get the connectivity type of this resource. More...
 
bool isObservable () const
 Function to provide ability to check if this resource is observable or not. More...
 
std::string setHost (const std::string &host)
 Function to change host of this reource. More...
 
std::vector< std::string > getResourceTypes () const
 Function to get the list of resource types. More...
 
std::vector< std::string > getResourceInterfaces (void) const
 Function to get the list of resource interfaces. More...
 
OCResourceIdentifier uniqueIdentifier () const
 Function to get a unique identifier for this resource across network interfaces. More...
 
std::string sid () const
 Function to get a string representation of the resource's server ID. More...
 
bool operator== (const OCResource &other) const
 
bool operator!= (const OCResource &other) const
 
bool operator< (const OCResource &other) const
 
bool operator> (const OCResource &other) const
 
bool operator<= (const OCResource &other) const
 
bool operator>= (const OCResource &other) const
 

Friends

class OCPlatform_impl
 
class ListenOCContainer
 

Detailed Description

OCResource represents an OC resource.

A resource could be a light controller, temperature sensor, smoke detector, etc. A resource comes with a well-defined contract or interface onto which you can perform different operations, such as turning on the light, getting the current temperature or subscribing for event notifications from the smoke detector. A resource can be composed of one or more resources.

Member Typedef Documentation

typedef std::shared_ptr<OCResource> OC::OCResource::Ptr

Constructor & Destructor Documentation

OC::OCResource::OCResource ( OCResource &&  )
default
OC::OCResource::OCResource ( const OCResource )
delete
virtual OC::OCResource::~OCResource ( void  )
virtual

Virtual destructor.

Member Function Documentation

OCStackResult OC::OCResource::cancelObserve ( )

Function to cancel the observation on the resource.

Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::cancelObserve ( QualityOfService  qos)
OCConnectivityType OC::OCResource::connectivityType ( ) const

Function to get the connectivity type of this resource.

Returns
enum connectivity type (flags and adapter)
OCStackResult OC::OCResource::deleteResource ( DeleteCallback  deleteHandler)

Function to perform DELETE operation.

Parameters
deleteHandlerhandles callback The callback function will have headerOptions and result from this Delete operation. This will have error codes
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::deleteResource ( DeleteCallback  deleteHandler,
QualityOfService  QoS 
)
OCStackResult OC::OCResource::get ( const QueryParamsMap queryParametersMap,
GetCallback  attributeHandler 
)

Function to get the attributes of a resource.

Parameters
queryParametersMapmap which can have the query parameter name and value
attributeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Get operation This will have error codes
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::get ( const QueryParamsMap queryParametersMap,
GetCallback  attributeHandler,
QualityOfService  QoS 
)

Function to get the attributes of a resource.

Parameters
queryParametersMapmap which can have the query parameter name and value
attributeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Get operation This will have error codes
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::get ( const std::string &  resourceType,
const std::string &  resourceInterface,
const QueryParamsMap queryParametersMap,
GetCallback  attributeHandler 
)

Function to get the attributes of a resource.

Parameters
resourceTyperesourceType of the resource operate on
resourceInterfaceinterface type of the resource to operate on
queryParametersMapmap which can have the query parameter name and value
attributeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will be invoked with a list of URIs if 'get' is invoked on a resource container (list will be empty if not a container) The callback function will also have the result from this Get operation. This will have error codes
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
Example:
Consider resource "a/home" (with link interface and resource type as home) contains links to "a/kitchen" and "a/room".
  1. get("home", Link_Interface, &onGet)
Callback onGet will receive a) Empty attribute map because there are no attributes for a/home b) list with full URI of "a/kitchen" and "a/room" resources and their properties c) error code for GET operation
Note
A resource may contain single or multiple resource types. Also, a resource may contain single or multiple interfaces. Currently, single GET request is allowed to do operate on single resource type or resource interface. In future, a single GET can operate on multiple resource types and interfaces.
A client can traverse a tree or graph by doing successive GETs on the returned resources at a node.
OCStackResult OC::OCResource::get ( const std::string &  resourceType,
const std::string &  resourceInterface,
const QueryParamsMap queryParametersMap,
GetCallback  attributeHandler,
QualityOfService  QoS 
)

Function to get the attributes of a resource.

Parameters
resourceTyperesourceType of the resource operate on
resourceInterfaceinterface type of the resource to operate on
queryParametersMapmap which can have the query parameter name and value
attributeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will be invoked with a list of URIs if 'get' is invoked on a resource container (list will be empty if not a container) The callback function will also have the result from this Get operation. This will have error codes
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure. note OCStackResult is defined in ocstack.h.
Example:
Consider resource "a/home" (with link interface and resource type as home) contains links to "a/kitchen" and "a/room".
  1. get("home", Link_Interface, &onGet)
Callback onGet will receive a) Empty attribute map because there are no attributes for a/home b) list with full URI of "a/kitchen" and "a/room" resources and their properties c) error code for GET operation
Note
A resource may contain single or multiple resource types. Also, a resource may contain single or multiple interfaces. Currently, single GET request is allowed to do operate on single resource type or resource interface. In future, a single GET can operate on multiple resource types and interfaces.
A client can traverse a tree or graph by doing successive GETs on the returned resources at a node.
std::vector<std::string> OC::OCResource::getAllHosts ( ) const

Function to get the endpoints information of this resource.

Returns
std::vector<std::string> endpoints information
std::vector<std::string> OC::OCResource::getResourceInterfaces ( void  ) const

Function to get the list of resource interfaces.

Returns
vector of resource interface
std::vector<std::string> OC::OCResource::getResourceTypes ( ) const

Function to get the list of resource types.

Returns
vector of resource types
HeaderOptions OC::OCResource::getServerHeaderOptions ( ) const

Function to get the header options information from response.

Returns
headerOptions HeaderOptions vector consisting of OCHeaderOption objects
std::string OC::OCResource::host ( ) const

Function to get the host address of this resource.

Returns
std::string host address
Note
This might or might not be exposed in future due to security concerns
bool OC::OCResource::isObservable ( ) const

Function to provide ability to check if this resource is observable or not.

Returns
bool true indicates resource is observable; false indicates resource is not observable.
OCStackResult OC::OCResource::observe ( ObserveType  observeType,
const QueryParamsMap queryParametersMap,
ObserveCallback  observeHandler 
)

Function to set observation on the resource.

Parameters
observeTypeallows the client to specify how it wants to observe.
queryParametersMapmap which can have the query parameter name and value
observeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this observe operation This will have error codes
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::observe ( ObserveType  observeType,
const QueryParamsMap queryParametersMap,
ObserveCallback  observeHandler,
QualityOfService  qos 
)

Function to set observation on the resource.

Parameters
observeTypeallows the client to specify how it wants to observe.
queryParametersMapmap which can have the query parameter name and value
observeHandlerhandles callback The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this observe operation This will have error codes
qosthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
bool OC::OCResource::operator!= ( const OCResource other) const
bool OC::OCResource::operator< ( const OCResource other) const
bool OC::OCResource::operator<= ( const OCResource other) const
OCResource& OC::OCResource::operator= ( OCResource &&  )
delete
OCResource& OC::OCResource::operator= ( const OCResource )
delete
bool OC::OCResource::operator== ( const OCResource other) const
bool OC::OCResource::operator> ( const OCResource other) const
bool OC::OCResource::operator>= ( const OCResource other) const
OCStackResult OC::OCResource::post ( const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PostCallback  attributeHandler 
)

Function to post on a resource.

Parameters
representationwhich can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes
queryParametersMapmap which can have the query parameter name and value
attributeHandlerattribute handler
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::post ( const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PostCallback  attributeHandler,
QualityOfService  QoS 
)

Function to post on a resource.

Parameters
representationwhich can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes
queryParametersMapmap which can have the query parameter name and value
attributeHandlerattribute handler
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::post ( const std::string &  resourceType,
const std::string &  resourceInterface,
const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PostCallback  attributeHandler 
)

Function to post on a resource.

Parameters
resourceTyperesource type of the resource to operate on
resourceInterfaceinterface type of the resource to operate on
representationrepresentation of the resource
queryParametersMapMap which can have the query parameter name and value
attributeHandlerattribute handler The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes. The Representation parameter maps which can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::post ( const std::string &  resourceType,
const std::string &  resourceInterface,
const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PostCallback  attributeHandler,
QualityOfService  QoS 
)

Function to post on a resource.

Parameters
resourceTyperesource type of the resource to operate on
resourceInterfaceinterface type of the resource to operate on
representationrepresentation of the resource
queryParametersMapMap which can have the query parameter name and value
attributeHandlerattribute handler The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes. The Representation parameter maps which can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::put ( const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PutCallback  attributeHandler 
)

Function to set the representation of a resource (via PUT)

Parameters
representationwhich can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes
queryParametersMapmap which can have the query parameter name and value
attributeHandlerattribute handler
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::put ( const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PutCallback  attributeHandler,
QualityOfService  QoS 
)

Function to set the representation of a resource (via PUT)

Parameters
representationwhich can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes
queryParametersMapmap which can have the query parameter name and value
attributeHandlerattribute handler
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::put ( const std::string &  resourceType,
const std::string &  resourceInterface,
const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PutCallback  attributeHandler 
)

Function to set the attributes of a resource (via PUT)

Parameters
resourceTyperesource type of the resource to operate on
resourceInterfaceinterface type of the resource to operate on
representationrepresentation of the resource
queryParametersMapMap which can have the query parameter name and value
attributeHandlerattribute handler The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes. The Representation parameter maps which can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
OCStackResult OC::OCResource::put ( const std::string &  resourceType,
const std::string &  resourceInterface,
const OCRepresentation representation,
const QueryParamsMap queryParametersMap,
PutCallback  attributeHandler,
QualityOfService  QoS 
)

Function to set the attributes of a resource (via PUT)

Parameters
resourceTyperesource type of the resource to operate on
resourceInterfaceinterface type of the resource to operate on
representationrepresentation of the resource
queryParametersMapMap which can have the query parameter name and value
attributeHandlerattribute handler The callback function will be invoked with a map of attribute name and values. The callback function will also have the result from this Put operation This will have error codes. The Representation parameter maps which can either have all the attribute names and values (which will represent entire state of the resource) or a set of attribute names and values which needs to be modified
QoSthe quality of communication
Returns
Returns OC_STACK_OK on success, some other value upon failure.
Note
OCStackResult is defined in ocstack.h.
void OC::OCResource::setHeaderOptions ( const HeaderOptions headerOptions)

Function to set header information.

Parameters
headerOptionsstd::vector where header information(header optionID and optionData is passed
Note
Once the headers information is set, it will be applicable to GET, PUT and observe request. setHeaderOptions can be used multiple times if headers need to be modifed by the client. Latest headers will be used to send in the request.
Initial support is only for two headers. If headerMap consists of more than two header options, they will be ignored.
Use unsetHeaderOptions API to clear the header information.
std::string OC::OCResource::setHost ( const std::string &  host)

Function to change host of this reource.

Returns
std::string New host Address. not observable.
std::string OC::OCResource::sid ( ) const

Function to get a string representation of the resource's server ID.

This is unique per- server independent on how it was discovered.

OCResourceIdentifier OC::OCResource::uniqueIdentifier ( ) const

Function to get a unique identifier for this resource across network interfaces.

This will be guaranteed unique for every resource-per-server independent of how this was discovered.

Returns
OCResourceIdentifier object, which can be used for all comparison and hashing.
void OC::OCResource::unsetHeaderOptions ( )

Function to unset header options.

std::string OC::OCResource::uri ( ) const

Function to get the URI for this resource.

Returns
std::string resource URI

Friends And Related Function Documentation

friend class ListenOCContainer
friend
friend class OCPlatform_impl
friend

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