Astarte device API for C++ 0.8.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
AstarteDeviceSdk::AstarteDevice Class Referenceabstract

Interface for an Astarte device. More...

#include <device.hpp>

+ Inheritance diagram for AstarteDeviceSdk::AstarteDevice:

Public Member Functions

virtual ~AstarteDevice ()=default
 Virtual destructor.
 
 AstarteDevice (const AstarteDevice &other)=delete
 Copy constructor for the Astarte device class.
 
 AstarteDevice (AstarteDevice &&other)=default
 Move constructor for the Astarte device class.
 
auto operator= (const AstarteDevice &other) -> AstarteDevice &=delete
 Copy assignment operator for the Astarte device class.
 
auto operator= (AstarteDevice &&other) -> AstarteDevice &=default
 Move assignment operator for the Astarte device class.
 
virtual auto add_interface_from_file (const std::filesystem::path &json_file) -> astarte_tl::expected< void, AstarteError >=0
 Add an interface for the device from a JSON file.
 
virtual auto add_interface_from_str (std::string_view json) -> astarte_tl::expected< void, AstarteError >=0
 Add an interface for the device from a JSON string view.
 
virtual auto remove_interface (const std::string &interface_name) -> astarte_tl::expected< void, AstarteError >=0
 Remove an installed interface.
 
virtual auto connect () -> astarte_tl::expected< void, AstarteError >=0
 Connect the device to Astarte.
 
virtual auto is_connected () const -> bool=0
 Check if the device is connected to the Astarte message hub.
 
virtual auto disconnect () -> astarte_tl::expected< void, AstarteError >=0
 Disconnect the device from Astarte.
 
virtual auto send_individual (std::string_view interface_name, std::string_view path, const AstarteData &data, const std::chrono::system_clock::time_point *timestamp) -> astarte_tl::expected< void, AstarteError >=0
 Send an individual data payload to Astarte.
 
virtual auto send_object (std::string_view interface_name, std::string_view path, const AstarteDatastreamObject &object, const std::chrono::system_clock::time_point *timestamp) -> astarte_tl::expected< void, AstarteError >=0
 Send an aggregate object data payload to Astarte.
 
virtual auto set_property (std::string_view interface_name, std::string_view path, const AstarteData &data) -> astarte_tl::expected< void, AstarteError >=0
 Set a device property on Astarte.
 
virtual auto unset_property (std::string_view interface_name, std::string_view path) -> astarte_tl::expected< void, AstarteError >=0
 Unset a device property on Astarte.
 
virtual auto poll_incoming (const std::chrono::milliseconds &timeout) -> std::optional< AstarteMessage >=0
 Poll for incoming messages from Astarte.
 

Protected Member Functions

 AstarteDevice ()=default
 Protected default constructor.
 

Detailed Description

Interface for an Astarte device.

This class defines a transport independent abstract class to be used by derived classes to implement transport dependent device classes.

Constructor & Destructor Documentation

◆ ~AstarteDevice()

virtual AstarteDeviceSdk::AstarteDevice::~AstarteDevice ( )
virtualdefault

Virtual destructor.

Ensures proper cleanup of derived classes through a base pointer.

◆ AstarteDevice() [1/3]

AstarteDeviceSdk::AstarteDevice::AstarteDevice ( const AstarteDevice & other)
delete

Copy constructor for the Astarte device class.

◆ AstarteDevice() [2/3]

AstarteDeviceSdk::AstarteDevice::AstarteDevice ( AstarteDevice && other)
default

Move constructor for the Astarte device class.

Parameters
otherObject to move.

◆ AstarteDevice() [3/3]

AstarteDeviceSdk::AstarteDevice::AstarteDevice ( )
protecteddefault

Protected default constructor.

Prevents direct instantiation of the interface.

Member Function Documentation

◆ add_interface_from_file()

virtual auto AstarteDeviceSdk::AstarteDevice::add_interface_from_file ( const std::filesystem::path & json_file) -> astarte_tl::expected< void, AstarteError >
pure virtual

Add an interface for the device from a JSON file.

Parameters
json_fileThe path to the .json interface file.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ add_interface_from_str()

virtual auto AstarteDeviceSdk::AstarteDevice::add_interface_from_str ( std::string_view json) -> astarte_tl::expected< void, AstarteError >
pure virtual

Add an interface for the device from a JSON string view.

Parameters
jsonThe interface definition as a JSON string view.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ connect()

virtual auto AstarteDeviceSdk::AstarteDevice::connect ( ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Connect the device to Astarte.

This is an asynchronous function. It starts a management process that will handle the device's connectivity in the background.

Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ disconnect()

virtual auto AstarteDeviceSdk::AstarteDevice::disconnect ( ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Disconnect the device from Astarte.

Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ is_connected()

virtual auto AstarteDeviceSdk::AstarteDevice::is_connected ( ) const -> bool
nodiscardpure virtual

Check if the device is connected to the Astarte message hub.

Returns
True if the device is connected, false otherwise.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ operator=() [1/2]

auto AstarteDeviceSdk::AstarteDevice::operator= ( AstarteDevice && other) -> AstarteDevice &=default
default

Move assignment operator for the Astarte device class.

Parameters
otherObject to move.
Returns
Moved object.

◆ operator=() [2/2]

auto AstarteDeviceSdk::AstarteDevice::operator= ( const AstarteDevice & other) -> AstarteDevice &=delete
delete

Copy assignment operator for the Astarte device class.

◆ poll_incoming()

virtual auto AstarteDeviceSdk::AstarteDevice::poll_incoming ( const std::chrono::milliseconds & timeout) -> std::optional< AstarteMessage >
pure virtual

Poll for incoming messages from Astarte.

Parameters
timeoutThe maximum time to block waiting for a message.
Returns
An std::optional containing the received AstarteMessage if one was available, or std::nullopt if the timeout was reached.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ remove_interface()

virtual auto AstarteDeviceSdk::AstarteDevice::remove_interface ( const std::string & interface_name) -> astarte_tl::expected< void, AstarteError >
pure virtual

Remove an installed interface.

Parameters
interface_nameThe interface name.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ send_individual()

virtual auto AstarteDeviceSdk::AstarteDevice::send_individual ( std::string_view interface_name,
std::string_view path,
const AstarteData & data,
const std::chrono::system_clock::time_point * timestamp ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Send an individual data payload to Astarte.

Parameters
interface_nameThe name of the target interface.
pathThe specific endpoint path within the interface.
dataThe data payload to send.
timestampAn optional timestamp for the data point. If nullptr, Astarte will assign one.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ send_object()

virtual auto AstarteDeviceSdk::AstarteDevice::send_object ( std::string_view interface_name,
std::string_view path,
const AstarteDatastreamObject & object,
const std::chrono::system_clock::time_point * timestamp ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Send an aggregate object data payload to Astarte.

Parameters
interface_nameThe name of the target interface.
pathThe common base path for the data object.
objectThe aggregate data object to send.
timestampAn optional timestamp for the data. If nullptr, Astarte will assign one.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ set_property()

virtual auto AstarteDeviceSdk::AstarteDevice::set_property ( std::string_view interface_name,
std::string_view path,
const AstarteData & data ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Set a device property on Astarte.

Parameters
interface_nameThe name of the interface containing the property.
pathThe full path to the property.
dataThe value to set for the property.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.

◆ unset_property()

virtual auto AstarteDeviceSdk::AstarteDevice::unset_property ( std::string_view interface_name,
std::string_view path ) -> astarte_tl::expected< void, AstarteError >
pure virtual

Unset a device property on Astarte.

Parameters
interface_nameThe name of the interface containing the property.
pathThe full path to the property to unset.
Returns
An error if generated.

Implemented in AstarteDeviceSdk::AstarteDeviceGrpc.


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