Astarte device API for C++ 0.8.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
ownership.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_OWNERSHIP_H
6#define ASTARTE_DEVICE_SDK_OWNERSHIP_H
7
12
13#include <cstdint>
14#include <ostream>
15#include <string>
16
19
20namespace astarte::device {
21
23enum Ownership : int8_t {
28};
29
36inline auto ownership_from_str(const std::string& ownership)
37 -> astarte_tl::expected<Ownership, Error> {
38 if (ownership == "device") {
39 return Ownership::kDevice;
40 }
41 if (ownership == "server") {
42 return Ownership::kServer;
43 }
44 return astarte_tl::unexpected(
45 InvalidInterfaceOwnershipeError("interface ownership not valid: " + ownership));
46}
47
48} // namespace astarte::device
49
51template <>
52struct astarte_fmt::formatter<astarte::device::Ownership> {
60 template <typename ParseContext>
61 constexpr auto parse(ParseContext& ctx) const {
62 return ctx.begin();
63 }
64
73 template <typename FormatContext>
74 auto format(const astarte::device::Ownership& ownership, FormatContext& ctx) const {
75 auto out = ctx.out();
76
77 switch (ownership) {
79 astarte_fmt::format_to(out, "device");
80 break;
82 astarte_fmt::format_to(out, "server");
83 break;
84 }
85
86 return out;
87 }
88};
89
97inline auto operator<<(std::ostream& out, const astarte::device::Ownership ownership)
98 -> std::ostream& {
99 out << astarte_fmt::format("{}", ownership);
100 return out;
101}
102
103#endif // ASTARTE_DEVICE_SDK_OWNERSHIP_H
Error indicating that the provided interface ownership is incorrect.
Definition errors.hpp:385
Error types and handling for the Astarte device library.
Data formatting utilities for Astarte types.
Umbrella namespace for the Astarte device library.
Definition data.hpp:29
Ownership
Possible Astarte ownership.
Definition ownership.hpp:23
@ kServer
Ownership is retained by the Astarte cloud server.
Definition ownership.hpp:27
@ kDevice
Ownership is retained by the device.
Definition ownership.hpp:25
auto ownership_from_str(const std::string &ownership) -> astarte_tl::expected< Ownership, Error >
Converts a string to an Ownership enum.
Definition ownership.hpp:36
Global namespace for all Astarte related functionality.
Definition data.hpp:29
auto operator<<(std::ostream &out, const astarte::device::Ownership ownership) -> std::ostream &
Stream insertion operator for Ownership.
Definition ownership.hpp:97
constexpr auto parse(ParseContext &ctx) const
Parses the format string. Default implementation.
Definition ownership.hpp:61
auto format(const astarte::device::Ownership &ownership, FormatContext &ctx) const
Formats the astarte::device::Ownership object.
Definition ownership.hpp:74
Base formatter struct declaration for Doxygen.
Definition formatter.hpp:48