Astarte device API for C++ 0.8.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 <optional>
20#include <string>
21#include <string_view>
22
29
30// NOLINTBEGIN(modernize-concat-nested-namespaces) Not nested for doxygen
32namespace astarte {
34namespace device {
35// NOLINTEND(modernize-concat-nested-namespaces)
36
44class Device {
45 public:
47 virtual ~Device() = default;
48
50 Device(const Device& other) = delete;
51
56 Device(Device&& other) = default;
57
59 auto operator=(const Device& other) -> Device& = delete;
60
66 auto operator=(Device&& other) -> Device& = default;
67
75 virtual auto add_interface_from_file(const std::filesystem::path& json_file)
76 -> astarte_tl::expected<void, Error> = 0;
77
84 virtual auto add_interface_from_str(std::string_view json)
85 -> astarte_tl::expected<void, Error> = 0;
86
93 virtual auto remove_interface(const std::string& interface_name)
94 -> astarte_tl::expected<void, Error> = 0;
95
104 virtual auto connect() -> astarte_tl::expected<void, Error> = 0;
105
110 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
111
116 virtual auto disconnect() -> astarte_tl::expected<void, Error> = 0;
117
127 virtual auto send_individual(std::string_view interface_name, std::string_view path,
128 const Data& data,
129 const std::chrono::system_clock::time_point* timestamp)
130 -> astarte_tl::expected<void, Error> = 0;
131
141 virtual auto send_object(std::string_view interface_name, std::string_view path,
142 const DatastreamObject& object,
143 const std::chrono::system_clock::time_point* timestamp)
144 -> astarte_tl::expected<void, Error> = 0;
145
154 virtual auto set_property(std::string_view interface_name, std::string_view path,
155 const Data& data) -> astarte_tl::expected<void, Error> = 0;
156
164 virtual auto unset_property(std::string_view interface_name, std::string_view path)
165 -> astarte_tl::expected<void, Error> = 0;
166
177 virtual auto poll_incoming(const std::chrono::milliseconds& timeout)
178 -> std::optional<Message> = 0;
179
186 virtual auto get_all_properties(const std::optional<Ownership>& ownership)
187 -> astarte_tl::expected<std::list<StoredProperty>, Error> = 0;
188
195 virtual auto get_properties(std::string_view interface_name)
196 -> astarte_tl::expected<std::list<StoredProperty>, Error> = 0;
197
205 virtual auto get_property(std::string_view interface_name, std::string_view path)
206 -> astarte_tl::expected<PropertyIndividual, Error> = 0;
207
208 protected:
209 Device() = default;
210};
211
212} // namespace device
213} // namespace astarte
214
215#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.