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
12
13#include <chrono>
14#include <filesystem>
15#include <optional>
16#include <string>
17#include <string_view>
18
20#include "astarte_device_sdk/errors.hpp"
23
25namespace AstarteDeviceSdk {
26
33 public:
38 virtual ~AstarteDevice() = default;
40 AstarteDevice(const AstarteDevice& other) = delete;
45 AstarteDevice(AstarteDevice&& other) = default;
47 auto operator=(const AstarteDevice& other) -> AstarteDevice& = delete;
53 auto operator=(AstarteDevice&& other) -> AstarteDevice& = default;
59 virtual auto add_interface_from_file(const std::filesystem::path& json_file)
60 -> astarte_tl::expected<void, AstarteError> = 0;
66 virtual auto add_interface_from_str(std::string_view json)
67 -> astarte_tl::expected<void, AstarteError> = 0;
73 virtual auto remove_interface(const std::string& interface_name)
74 -> astarte_tl::expected<void, AstarteError> = 0;
81 virtual auto connect() -> astarte_tl::expected<void, AstarteError> = 0;
86 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
91 virtual auto disconnect() -> astarte_tl::expected<void, AstarteError> = 0;
100 virtual auto send_individual(std::string_view interface_name, std::string_view path,
101 const AstarteData& data,
102 const std::chrono::system_clock::time_point* timestamp)
103 -> astarte_tl::expected<void, AstarteError> = 0;
112 virtual auto send_object(std::string_view interface_name, std::string_view path,
113 const AstarteDatastreamObject& object,
114 const std::chrono::system_clock::time_point* timestamp)
115 -> astarte_tl::expected<void, AstarteError> = 0;
123 virtual auto set_property(std::string_view interface_name, std::string_view path,
124 const AstarteData& data)
125 -> astarte_tl::expected<void, AstarteError> = 0;
132 virtual auto unset_property(std::string_view interface_name, std::string_view path)
133 -> astarte_tl::expected<void, AstarteError> = 0;
140 virtual auto poll_incoming(const std::chrono::milliseconds& timeout)
141 -> std::optional<AstarteMessage> = 0;
142
143 protected:
148 AstarteDevice() = default;
149};
150
151} // namespace AstarteDeviceSdk
152
153#endif // ASTARTE_DEVICE_SDK_DEVICE_H
Astarte data class, representing the basic Astarte types.
Definition data.hpp:40
Astarte object class, representing the Astarte object datastream data.
Definition object.hpp:22
auto operator=(AstarteDevice &&other) -> AstarteDevice &=default
Move assignment operator for the Astarte device class.
AstarteDevice(AstarteDevice &&other)=default
Move constructor for the Astarte device class.
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 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 connect() -> astarte_tl::expected< void, AstarteError >=0
Connect the device to Astarte.
AstarteDevice(const AstarteDevice &other)=delete
Copy constructor for the Astarte device class.
virtual auto poll_incoming(const std::chrono::milliseconds &timeout) -> std::optional< AstarteMessage >=0
Poll for incoming messages from Astarte.
virtual auto disconnect() -> astarte_tl::expected< void, AstarteError >=0
Disconnect the device from 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 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 remove_interface(const std::string &interface_name) -> astarte_tl::expected< void, AstarteError >=0
Remove an installed interface.
virtual ~AstarteDevice()=default
Virtual destructor.
virtual auto is_connected() const -> bool=0
Check if the device is connected to the Astarte message hub.
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.
auto operator=(const AstarteDevice &other) -> AstarteDevice &=delete
Copy assignment operator for the Astarte device class.
Astarte message class, represents a full message for/from Astarte.
Definition msg.hpp:25
Astarte data class and its related methods.
Astarte message class and its related methods.
Umbrella namespace for the Astarte device SDK.
Definition data.hpp:23
std::variant< AstarteInternalError, AstarteFileOpenError, AstarteInvalidInputError, AstarteOperationRefusedError, AstarteGrpcLibError, AstarteMsgHubError > AstarteError
A variant type representing any possible error from the Astarte device library.
Definition errors.hpp:41
Astarte object class and its related methods.