CPP Device Virtualization API Reference for Oracle Internet of Things Cloud Service Client Software Library. Release 21.1.1.0.0-3. E92477-09
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
iotdcl::AbstractVirtualDevice< V > Class Template Referenceabstract

AbstractVirtualDevice is a representation of a device model implemented by an endpoint. More...

#include <AbstractVirtualDevice.hpp>

Public Member Functions

virtual ~AbstractVirtualDevice ()
 Destructor.
 
virtual const DeviceModelgetDeviceModel ()=0
 Get the device model of this device object. More...
 
virtual const std::string & getEndpointId () const =0
 Get the endpoint id of the device. More...
 
template<typename T >
V & set (const std::string &attributeName, T &value)
 Set the value of an attribute. More...
 
template<typename T >
get (const std::string &attributeName)
 Get the value of an attribute. More...
 
virtual V & update (void)=0
 Set a mark for beginning an update transaction. More...
 
virtual void finish (void)=0
 Causes the values set in an update transaction to be sent to the server and clears the update-transaction mark. More...
 
virtual void setOnChange (const ChangeCallback *callback)=0
 Set a callback that is invoked when the value of any attribute in the device model is changed from the outside. More...
 
virtual void setOnError (const ErrorCallback *callback)=0
 Set a callback that is invoked if an error occurs when setting the value of any attribute in the device model, or an error occurs when raising an. More...
 
virtual void setOnChange (const std::string &attributeName, const ChangeCallback *callback)=0
 Set a callback that is invoked when the value of the given attribute in the device model is changed from the outside. More...
 
virtual void setOnError (const std::string &attributeName, const ErrorCallback *callback)=0
 Set a callback that is invoked if an error occurs when setting the value of any attribute in the device model or an error occurs when raising an. More...
 

Detailed Description

template<class V>
class iotdcl::AbstractVirtualDevice< V >

AbstractVirtualDevice is a representation of a device model implemented by an endpoint.

A device model is a specification of the attributes, formats, and resources available on the endpoint.

The iotdcl::AbstractVirtualDevice API is common to both the enterprise client and the device client. The semantics of the API are also the same. The processing model on the enterprise client is different, however, from the processing model on the device client.

On the enterprise client, an enterprise application calls the iotdcl::AbstractVirtualDevice set methods in order to affect a change on the physical device. The enterprise client application receives confirmation of that the change was accepted via a iotdcl::ChangeCallback. The iotdcl::ChangeCallback indicates to the enterprise client that the value of the attribute on the device has changed. This callback may come as a result of the enterprise client calling set() on the attribute, or it may come unsolicited as a result of the device-client updating the value from the physical device.

The enterprise client may also receive an iotdcl::ErrorCallback if the attribute value change was not accepted. This could be because the request timed out, the connection failed, or the change was explicitly rejected. The iotdcl::ErrorCallback indicates to the enterprise client that it should roll-back the attribute value to the last known value.

On the device client, the application will call set() on a iotdcl::AbstractVirtualDevice attribute. This will cause a message to be sent to the server. The iotdcl::ErrorCallback is invoked if there is an error sending the message to the server. Any enterprise application that is monitoring the device will be notified via the iotdcl::ChangeCallback that the value has changed. When the client-library receives a request from the server, the request is forwarded to a handler which invokes the iotdcl::ChangeCallback on the requested attribute. A GET request simply calls get() on the attribute.

Member Function Documentation

template<class V>
virtual void iotdcl::AbstractVirtualDevice< V >::finish ( void  )
pure virtual

Causes the values set in an update transaction to be sent to the server and clears the update-transaction mark.

See Also
update()
template<class V>
template<typename T >
T iotdcl::AbstractVirtualDevice< V >::get ( const std::string &  attributeName)
inline

Get the value of an attribute.

This method returns the current value held by the virtual device model. For an enterprise client, no REST API call is made to the server. For a device client, no call is made to the physical device.

Parameters
attributeNamethe name of an attribute from the device type model
Returns
the attribute value
template<class V>
virtual const DeviceModel& iotdcl::AbstractVirtualDevice< V >::getDeviceModel ( )
pure virtual

Get the device model of this device object.

Returns
the device model
template<class V>
virtual const std::string& iotdcl::AbstractVirtualDevice< V >::getEndpointId ( ) const
pure virtual

Get the endpoint id of the device.

Returns
the device endpoint id
template<class V>
template<typename T >
V& iotdcl::AbstractVirtualDevice< V >::set ( const std::string &  attributeName,
T &  value 
)
inline

Set the value of an attribute.

This method is used by the application to synchronize the iotdcl::AbstractVirtualDevice state with the physical device. This results in a REST API call to the server. For an enterprise client, an endpoint resource REST API call is made to the server. For a device client, an endpoint DATA message REST API call is made to the server. The value is validated according to the constraints in the device model.

Parameters
attributeNamethe name of an attribute from the device type model
valuethe value to set
Returns
this iotdcl::AbstractVirtualDevice instance
template<class V>
virtual void iotdcl::AbstractVirtualDevice< V >::setOnChange ( const ChangeCallback callback)
pure virtual

Set a callback that is invoked when the value of any attribute in the device model is changed from the outside.

Local attribute changes don't provoke the callback invocation.

Note that it is possible to set a callback for all attributes and to set a callback for a specific attribute via setOnChange(const std::string&,const ChangeCallback*). If there is a callback for the specific attribute and for all attributes, both callbacks will be invoked.

Parameters
callbacka callback to invoke when an attribute value changes, if NULL, the existing callback will be removed
See Also
AbstractVirtualDevice.setOnChange(const std::string,const ChangeCallback*)
template<class V>
virtual void iotdcl::AbstractVirtualDevice< V >::setOnChange ( const std::string &  attributeName,
const ChangeCallback callback 
)
pure virtual

Set a callback that is invoked when the value of the given attribute in the device model is changed from the outside.

Local attribute changes don't provoke the callback invocation. This is a convenience for calling

DeviceField deviceField = deviceModel.getAttribute("temperature");
deviceField.setOnChange(temperatureChangeCallback);

Note that it is possible to set a callback for a specific attribute and to set a callback for all attributes via setOnChange(const ChangeCallback *). If there is a callback for the specific attribute and for all attributes, both callbacks will be invoked.

Parameters
attributeNamethe name of an attribute from the device type model
callbacka callback to invoke when an attribute value changes, if NULL, the existing callback will be removed
template<class V>
virtual void iotdcl::AbstractVirtualDevice< V >::setOnError ( const ErrorCallback callback)
pure virtual

Set a callback that is invoked if an error occurs when setting the value of any attribute in the device model, or an error occurs when raising an.

Alert

.

Note that it is possible to set a callback for all attributes and to set a callback for a specific attribute via setOnError(const std::string &, const ErrorCallback*). If there is a callback for the specific attribute and for all attributes, both callbacks will be invoked.

Parameters
callbacka callback to invoke when there is an error setting a value, if NULL, the existing callback will be removed
See Also
AbstractVirtualDevice.setOnError(const std::string &, const ErrorCallback*)
template<class V>
virtual void iotdcl::AbstractVirtualDevice< V >::setOnError ( const std::string &  attributeName,
const ErrorCallback callback 
)
pure virtual

Set a callback that is invoked if an error occurs when setting the value of any attribute in the device model or an error occurs when raising an.

Alert

. This is a convenience for calling

DeviceField deviceField = deviceModel.getAttribute("temperature");
deviceField.setOnError(temperatureErrorCallback);

Note that it is possible to set a callback for a specific attribute and to set a callback for all attributes via setOnError(const ErrorCallback*). If there is a callback for the specific attribute and for all attributes, both callbacks will be invoked.

Parameters
attributeNamethe name of an attribute from the device type model
callbacka callback to invoke when there is an error setting the attribute value, if NULL, the existing callback will be removed
template<class V>
virtual V& iotdcl::AbstractVirtualDevice< V >::update ( void  )
pure virtual

Set a mark for beginning an update transaction.

By default, each call to "set" automatically sends the value to the server. The update() call allows more than one value to be set on this iotdcl::AbstractVirtualDevice object without sending values to the server. The values are sent to the server when the finish() method is called, which also marks the end of the update transaction. For example

virtualDevice.update().set("min", 10).set("max", 20).finish();
Returns
this iotdcl::AbstractVirtualDevice instance
See Also
finish()

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