Astarte device API for C++ 0.9.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
device.hpp
Go to the documentation of this file.
1// (C) Copyright 2025, SECO Mind Srl
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef ASTARTE_DEVICE_SDK_DEVICE_H
6#define ASTARTE_DEVICE_SDK_DEVICE_H
7
16
17#include <chrono>
18#include <filesystem>
19#include <list>
20#include <optional>
21#include <string>
22#include <string_view>
23
30
31// NOLINTBEGIN(modernize-concat-nested-namespaces) Not nested for doxygen
33namespace astarte {
35namespace device {
36// NOLINTEND(modernize-concat-nested-namespaces)
37
45class Device {
46 public:
48 virtual ~Device() = default;
49
51 Device(const Device& other) = delete;
52
57 Device(Device&& other) = default;
58
60 auto operator=(const Device& other) -> Device& = delete;
61
67 auto operator=(Device&& other) -> Device& = default;
68
76 virtual auto add_interface_from_file(const std::filesystem::path& json_file)
77 -> astarte_tl::expected<void, Error> = 0;
78
85 virtual auto add_interface_from_str(std::string_view json)
86 -> astarte_tl::expected<void, Error> = 0;
87
94 virtual auto remove_interface(const std::string& interface_name)
95 -> astarte_tl::expected<void, Error> = 0;
96
105 virtual auto connect() -> astarte_tl::expected<void, Error> = 0;
106
111 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
112
117 virtual auto disconnect() -> astarte_tl::expected<void, Error> = 0;
118
128 virtual auto send_individual(std::string_view interface_name, std::string_view path,
129 const Data& data,
130 const std::chrono::system_clock::time_point* timestamp)
131 -> astarte_tl::expected<void, Error> = 0;
132
142 virtual auto send_object(std::string_view interface_name, std::string_view path,
143 const DatastreamObject& object,
144 const std::chrono::system_clock::time_point* timestamp)
145 -> astarte_tl::expected<void, Error> = 0;
146
155 virtual auto set_property(std::string_view interface_name, std::string_view path,
156 const Data& data) -> astarte_tl::expected<void, Error> = 0;
157
165 virtual auto unset_property(std::string_view interface_name, std::string_view path)
166 -> astarte_tl::expected<void, Error> = 0;
167
178 virtual auto poll_incoming(const std::chrono::milliseconds& timeout)
179 -> std::optional<Message> = 0;
180
187 virtual auto get_all_properties(const std::optional<Ownership>& ownership)
188 -> astarte_tl::expected<std::list<StoredProperty>, Error> = 0;
189
196 virtual auto get_properties(std::string_view interface_name)
197 -> astarte_tl::expected<std::list<StoredProperty>, Error> = 0;
198
206 virtual auto get_property(std::string_view interface_name, std::string_view path)
207 -> astarte_tl::expected<PropertyIndividual, Error> = 0;
208
209 protected:
210 Device() = default;
211};
212
213} // namespace device
214} // namespace astarte
215
216#endif // ASTARTE_DEVICE_SDK_DEVICE_H
Represents a single Astarte data value.
Definition data.hpp:61
Astarte object class, representing the Astarte object datastream data.
Definition object.hpp:33
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 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.
Device(const Device &other)=delete
Device is non-copyable.
virtual auto remove_interface(const std::string &interface_name) -> astarte_tl::expected< void, Error >=0
Removes an installed interface from the device.
virtual auto poll_incoming(const std::chrono::milliseconds &timeout) -> std::optional< Message >=0
Polls for incoming messages from Astarte.
virtual auto get_property(std::string_view interface_name, std::string_view path) -> astarte_tl::expected< PropertyIndividual, Error >=0
Retrieves a specific property value.
virtual auto disconnect() -> astarte_tl::expected< void, Error >=0
Disconnects the device from 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 get_properties(std::string_view interface_name) -> astarte_tl::expected< std::list< StoredProperty >, Error >=0
Retrieves all stored properties belonging to a specific interface.
auto operator=(const Device &other) -> Device &=delete
Device is non-copyable.
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 is_connected() const -> bool=0
Checks connectivity status.
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 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 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 connect() -> astarte_tl::expected< void, Error >=0
Connects the device to the Astarte platform.
virtual ~Device()=default
Virtual destructor.
auto operator=(Device &&other) -> Device &=default
Move assignment operator.
Device(Device &&other)=default
Move constructor.
Astarte message class, represents a full message for/from Astarte.
Definition msg.hpp:37
Representing the Astarte individual property data.
Definition property.hpp:22
Represents a stored property on the device.
Definition stored_property.hpp:33
Astarte data class and its related methods.
Error types and handling for the Astarte device library.
Astarte message class and its related methods.
Umbrella namespace for the Astarte device library.
Definition data.hpp:29
Ownership
Possible Astarte ownership.
Definition ownership.hpp:23
std::variant< DataSerializationError, InternalError, FileOpenError, InvalidInputError, InterfaceValidationError, InvalidInterfaceVersionError, InvalidInterfaceTypeError, InvalidInterfaceOwnershipeError, InvalidInterfaceAggregationError, InvalidAstarteTypeError, InvalidReliabilityError, InvalidRetentionError, InvalidDatabaseRetentionPolicyError, OperationRefusedError, GrpcLibError, MsgHubError, mqtt::JsonParsingError, mqtt::DeviceRegistrationError, mqtt::PairingApiError, mqtt::MqttError, mqtt::InvalidUrlError, mqtt::RetrieveBrokerUrlError, mqtt::ReadCredentialError, mqtt::WriteCredentialError, mqtt::PairingConfigError, mqtt::CryptoError, mqtt::UuidError, mqtt::HttpError, mqtt::MqttConnectionError > Error
Variant type representing any error from the Astarte device library.
Definition errors.hpp:80
Global namespace for all Astarte related functionality.
Definition data.hpp:29
Astarte object class and its related methods.
Ownership definitions for communication with Astarte.
Astarte stored property class.