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

Interface for an Astarte device. More...

#include <device.hpp>

+ Inheritance diagram for astarte::device::Device:

Public Member Functions

virtual ~Device ()=default
 Virtual destructor.
 
 Device (const Device &other)=delete
 Device is non-copyable.
 
 Device (Device &&other)=default
 Move constructor.
 
auto operator= (const Device &other) -> Device &=delete
 Device is non-copyable.
 
auto operator= (Device &&other) -> Device &=default
 Move assignment operator.
 
virtual auto add_interface_from_file (const std::filesystem::path &json_file) -> astarte_tl::expected< void, Error >=0
 Adds an interface definition to the device from a JSON file.
 
virtual auto add_interface_from_str (std::string_view json) -> astarte_tl::expected< void, Error >=0
 Adds an interface definition to the device from a JSON string.
 
virtual auto remove_interface (const std::string &interface_name) -> astarte_tl::expected< void, Error >=0
 Removes an installed interface from the device.
 
virtual auto connect () -> astarte_tl::expected< void, Error >=0
 Connects the device to the Astarte platform.
 
virtual auto is_connected () const -> bool=0
 Checks connectivity status.
 
virtual auto disconnect () -> astarte_tl::expected< void, Error >=0
 Disconnects the device from Astarte.
 
virtual auto send_individual (std::string_view interface_name, std::string_view path, const Data &data, const std::chrono::system_clock::time_point *timestamp) -> astarte_tl::expected< void, Error >=0
 Sends an individual data point to an Astarte Interface.
 
virtual auto send_object (std::string_view interface_name, std::string_view path, const DatastreamObject &object, const std::chrono::system_clock::time_point *timestamp) -> astarte_tl::expected< void, Error >=0
 Sends an aggregated object to an Astarte Interface.
 
virtual auto set_property (std::string_view interface_name, std::string_view path, const Data &data) -> astarte_tl::expected< void, Error >=0
 Updates a local device property and synchronize it with Astarte.
 
virtual auto unset_property (std::string_view interface_name, std::string_view path) -> astarte_tl::expected< void, Error >=0
 Unsets (deletes) a device property.
 
virtual auto poll_incoming (const std::chrono::milliseconds &timeout) -> std::optional< Message >=0
 Polls for incoming messages from Astarte.
 
virtual auto get_all_properties (const std::optional< Ownership > &ownership) -> astarte_tl::expected< std::list< StoredProperty >, Error >=0
 Retrieves all stored properties matching an ownership filter.
 
virtual auto get_properties (std::string_view interface_name) -> astarte_tl::expected< std::list< StoredProperty >, Error >=0
 Retrieves all stored properties belonging to a specific interface.
 
virtual auto get_property (std::string_view interface_name, std::string_view path) -> astarte_tl::expected< PropertyIndividual, Error >=0
 Retrieves a specific property value.
 

Detailed Description

Interface for an Astarte device.

This abstract class normalizes interactions with the Astarte IoT platform, hiding transport-specific implementation details (e.g., MQTT, gRPC) from the user. Users should instantiate a concrete implementation of this class.

Constructor & Destructor Documentation

◆ ~Device()

virtual astarte::device::Device::~Device ( )
virtualdefault

Virtual destructor.

◆ Device() [1/2]

astarte::device::Device::Device ( const Device & other)
delete

Device is non-copyable.

◆ Device() [2/2]

astarte::device::Device::Device ( Device && other)
default

Move constructor.

Parameters
[in,out]otherThe device instance to move data from.

Member Function Documentation

◆ add_interface_from_file()

virtual auto astarte::device::Device::add_interface_from_file ( const std::filesystem::path & json_file) -> astarte_tl::expected< void, Error >
pure virtual

Adds an interface definition to the device from a JSON file.

Parses the JSON file to validate and register a new Astarte Interface.

Parameters
[in]json_fileThe filesystem path to the .json interface definition.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ add_interface_from_str()

virtual auto astarte::device::Device::add_interface_from_str ( std::string_view json) -> astarte_tl::expected< void, Error >
pure virtual

Adds an interface definition to the device from a JSON string.

Parameters
[in]jsonThe interface definition as a JSON string view.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ connect()

virtual auto astarte::device::Device::connect ( ) -> astarte_tl::expected< void, Error >
pure virtual

Connects the device to the Astarte platform.

This is an asynchronous operation. It initializes the transport layer and starts a background routine to maintain connectivity.

Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ disconnect()

virtual auto astarte::device::Device::disconnect ( ) -> astarte_tl::expected< void, Error >
pure virtual

Disconnects the device from Astarte.

Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ get_all_properties()

virtual auto astarte::device::Device::get_all_properties ( const std::optional< Ownership > & ownership) -> astarte_tl::expected< std::list< StoredProperty >, Error >
pure virtual

Retrieves all stored properties matching an ownership filter.

Parameters
[in]ownershipOptional filter, if std::nullopt, returns all properties.
Returns
An expected containing the list of properties on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ get_properties()

virtual auto astarte::device::Device::get_properties ( std::string_view interface_name) -> astarte_tl::expected< std::list< StoredProperty >, Error >
pure virtual

Retrieves all stored properties belonging to a specific interface.

Parameters
[in]interface_nameThe name of the interface to query.
Returns
An expected containing the list of properties on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ get_property()

virtual auto astarte::device::Device::get_property ( std::string_view interface_name,
std::string_view path ) -> astarte_tl::expected< PropertyIndividual, Error >
pure virtual

Retrieves a specific property value.

Parameters
[in]interface_nameThe name of the interface.
[in]pathThe exact path of the property.
Returns
An expected containing the property on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ is_connected()

virtual auto astarte::device::Device::is_connected ( ) const -> bool
nodiscardpure virtual

Checks connectivity status.

Returns
True if the device is fully connected to Astarte, false otherwise.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ operator=() [1/2]

auto astarte::device::Device::operator= ( const Device & other) -> Device &=delete
delete

Device is non-copyable.

◆ operator=() [2/2]

auto astarte::device::Device::operator= ( Device && other) -> Device &=default
default

Move assignment operator.

Parameters
[in,out]otherThe device instance to move data from.
Returns
A reference to this device.

◆ poll_incoming()

virtual auto astarte::device::Device::poll_incoming ( const std::chrono::milliseconds & timeout) -> std::optional< Message >
pure virtual

Polls for incoming messages from Astarte.

This method blocks the calling thread until a message is received or the timeout expires.

Parameters
[in]timeoutThe maximum duration to block waiting for a message.
Returns
std::optional containing the Message if received, or std::nullopt if the timeout was reached.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ remove_interface()

virtual auto astarte::device::Device::remove_interface ( const std::string & interface_name) -> astarte_tl::expected< void, Error >
pure virtual

Removes an installed interface from the device.

Parameters
[in]interface_nameThe name of the interface to remove.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ send_individual()

virtual auto astarte::device::Device::send_individual ( std::string_view interface_name,
std::string_view path,
const Data & data,
const std::chrono::system_clock::time_point * timestamp ) -> astarte_tl::expected< void, Error >
pure virtual

Sends an individual data point to an Astarte Interface.

Parameters
[in]interface_nameThe name of the target interface.
[in]pathThe specific mapping path within the interface (e.g., "/sensors/temp").
[in]dataThe value payload to transmit.
[in]timestampOptional timestamp. Should match the interface timestamp configuration.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ send_object()

virtual auto astarte::device::Device::send_object ( std::string_view interface_name,
std::string_view path,
const DatastreamObject & object,
const std::chrono::system_clock::time_point * timestamp ) -> astarte_tl::expected< void, Error >
pure virtual

Sends an aggregated object to an Astarte Interface.

Parameters
[in]interface_nameThe name of the target interface.
[in]pathThe common base path for the object aggregation.
[in]objectThe map of keys and values constituting the object.
[in]timestampOptional timestamp. Should match the interface timestamp configuration.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ set_property()

virtual auto astarte::device::Device::set_property ( std::string_view interface_name,
std::string_view path,
const Data & data ) -> astarte_tl::expected< void, Error >
pure virtual

Updates a local device property and synchronize it with Astarte.

Parameters
[in]interface_nameThe name of the interface containing the property.
[in]pathThe specific path of the property.
[in]dataThe new value for the property.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.

◆ unset_property()

virtual auto astarte::device::Device::unset_property ( std::string_view interface_name,
std::string_view path ) -> astarte_tl::expected< void, Error >
pure virtual

Unsets (deletes) a device property.

Parameters
[in]interface_nameThe name of the interface containing the property.
[in]pathThe specific path of the property to unset.
Returns
An expected containing void on success or Error on failure.

Implemented in astarte::device::grpc::DeviceGrpc, and astarte::device::mqtt::DeviceMqtt.


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