Astarte device API for C++ 0.8.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
device_grpc.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_GRPC_H
6#define ASTARTE_DEVICE_SDK_DEVICE_GRPC_H
7
12
13#include <chrono>
14#include <filesystem>
15#include <list>
16#include <memory>
17#include <optional>
18#include <string>
19#include <string_view>
20
27
30
36class DeviceGrpc : public Device {
37 public:
43 DeviceGrpc(const std::string& server_addr, const std::string& node_uuid);
44
46 ~DeviceGrpc() override;
47
49 DeviceGrpc(DeviceGrpc& other) = delete;
50
52 DeviceGrpc(DeviceGrpc&& other) = delete;
53
55 auto operator=(DeviceGrpc& other) -> DeviceGrpc& = delete;
56
58 auto operator=(DeviceGrpc&& other) -> DeviceGrpc& = delete;
59
67 auto add_interface_from_file(const std::filesystem::path& json_file)
68 -> astarte_tl::expected<void, Error> override;
69
76 auto add_interface_from_str(std::string_view json) -> astarte_tl::expected<void, Error> override;
77
84 auto remove_interface(const std::string& interface_name)
85 -> astarte_tl::expected<void, Error> override;
86
95 auto connect() -> astarte_tl::expected<void, Error> override;
96
101 [[nodiscard]] auto is_connected() const -> bool override;
102
107 auto disconnect() -> astarte_tl::expected<void, Error> override;
108
118 auto send_individual(std::string_view interface_name, std::string_view path, const Data& data,
119 const std::chrono::system_clock::time_point* timestamp)
120 -> astarte_tl::expected<void, Error> override;
121
131 auto send_object(std::string_view interface_name, std::string_view path,
132 const DatastreamObject& object,
133 const std::chrono::system_clock::time_point* timestamp)
134 -> astarte_tl::expected<void, Error> override;
135
144 auto set_property(std::string_view interface_name, std::string_view path, const Data& data)
145 -> astarte_tl::expected<void, Error> override;
146
154 auto unset_property(std::string_view interface_name, std::string_view path)
155 -> astarte_tl::expected<void, Error> override;
156
167 auto poll_incoming(const std::chrono::milliseconds& timeout) -> std::optional<Message> override;
168
175 auto get_all_properties(const std::optional<Ownership>& ownership)
176 -> astarte_tl::expected<std::list<StoredProperty>, Error> override;
177
184 auto get_properties(std::string_view interface_name)
185 -> astarte_tl::expected<std::list<StoredProperty>, Error> override;
186
194 auto get_property(std::string_view interface_name, std::string_view path)
195 -> astarte_tl::expected<PropertyIndividual, Error> override;
196
197 private:
198 struct DeviceGrpcImpl;
199 std::shared_ptr<DeviceGrpcImpl> astarte_device_impl_;
200};
201
202} // namespace astarte::device::grpc
203
204#endif // ASTARTE_DEVICE_SDK_DEVICE_GRPC_H
Represents a single Astarte data value.
Definition data.hpp:61
Astarte object class, representing the Astarte object datastream data.
Definition object.hpp:33
Device(const Device &other)=delete
Device is non-copyable.
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
auto get_properties(std::string_view interface_name) -> astarte_tl::expected< std::list< StoredProperty >, Error > override
Retrieves all stored properties belonging to a specific interface.
auto unset_property(std::string_view interface_name, std::string_view path) -> astarte_tl::expected< void, Error > override
Unsets (deletes) a device property.
auto get_property(std::string_view interface_name, std::string_view path) -> astarte_tl::expected< PropertyIndividual, Error > override
Retrieves a specific property value.
auto add_interface_from_str(std::string_view json) -> astarte_tl::expected< void, Error > override
Adds an interface definition to the device from a JSON string.
DeviceGrpc(const std::string &server_addr, const std::string &node_uuid)
Constructor for the Astarte device class.
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 > override
Sends an aggregated object to an Astarte Interface.
DeviceGrpc(DeviceGrpc &&other)=delete
Device is non-moveable.
auto remove_interface(const std::string &interface_name) -> astarte_tl::expected< void, Error > override
Removes an installed interface from the device.
~DeviceGrpc() override
Virtual destructor.
auto operator=(DeviceGrpc &&other) -> DeviceGrpc &=delete
Device is non-moveable.
auto connect() -> astarte_tl::expected< void, Error > override
Connects the device to the Astarte platform.
auto operator=(DeviceGrpc &other) -> DeviceGrpc &=delete
Device is non-copyable.
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 > override
Sends an individual data point to an Astarte Interface.
auto add_interface_from_file(const std::filesystem::path &json_file) -> astarte_tl::expected< void, Error > override
Adds an interface definition to the device from a JSON file.
DeviceGrpc(DeviceGrpc &other)=delete
Device is non-copyable.
auto set_property(std::string_view interface_name, std::string_view path, const Data &data) -> astarte_tl::expected< void, Error > override
Updates a local device property and synchronize it with Astarte.
auto disconnect() -> astarte_tl::expected< void, Error > override
Disconnects the device from Astarte.
auto get_all_properties(const std::optional< Ownership > &ownership) -> astarte_tl::expected< std::list< StoredProperty >, Error > override
Retrieves all stored properties matching an ownership filter.
auto poll_incoming(const std::chrono::milliseconds &timeout) -> std::optional< Message > override
Polls for incoming messages from Astarte.
auto is_connected() const -> bool override
Checks connectivity status.
Astarte data class and its related methods.
Abstract Astarte device interface.
Error types and handling for the Astarte device library.
Astarte message class and its related methods.
Namespace for Astarte device functionality using the gRPC transport layer.
Definition device_grpc.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
Astarte object class and its related methods.
Astarte individual property class and its related methods.