From 91b6ad5a8450ebf9237298811939a37248c027b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Bjarni=20Bjarnason?= Date: Mon, 24 Jun 2024 10:34:45 +0000 Subject: [PATCH] wip updating dependencies --- exes/mqtt-bridge/inc/client.hpp | 27 +++++++++---------- exes/mqtt-bridge/tests/src/unit_tests.cpp | 1 + libs/confman/inc/public/tfc/confman.hpp | 9 +++++-- .../testing/examples/confman_example_item.cpp | 2 +- libs/ipc/inc/public/tfc/ipc/item.hpp | 4 +-- libs/ipc/src/item.cpp | 4 +-- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/exes/mqtt-bridge/inc/client.hpp b/exes/mqtt-bridge/inc/client.hpp index 22f836d0a4..49dceb1400 100644 --- a/exes/mqtt-bridge/inc/client.hpp +++ b/exes/mqtt-bridge/inc/client.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -102,8 +102,7 @@ class client { p_id = 0; } - auto pub_packet = async_mqtt::v5::publish_packet{ p_id.value(), async_mqtt::allocate_buffer(topic), - async_mqtt::allocate_buffer(payload), qos }; + auto pub_packet = async_mqtt::v5::publish_packet{ p_id.value(), topic, payload, qos }; co_return !(co_await endpoint_client_->send(pub_packet, asio::use_awaitable)); } @@ -116,10 +115,8 @@ class client { p_id = endpoint_client_->acquire_unique_packet_id(); - std::string_view topic_view{ topic }; - auto sub_packet = async_mqtt::v5::subscribe_packet{ - p_id.value(), { { async_mqtt::buffer(topic_view), async_mqtt::qos::at_most_once | async_mqtt::sub::nl::yes } } + p_id.value(), { { topic, async_mqtt::qos::at_most_once | async_mqtt::sub::nl::yes } } }; auto send_error = co_await endpoint_client_->send(sub_packet, asio::use_awaitable); @@ -145,7 +142,7 @@ class client { for (auto const& entry : suback_packet.entries()) { if (entry != async_mqtt::suback_reason_code::granted_qos_0) { logger_.error("Error subscribing to topic: {}, reason code: {}", topic.data(), - async_mqtt::suback_reason_code_to_str(entry)); + async_mqtt::suback_reason_code_to_string(entry)); co_return false; } } @@ -197,24 +194,24 @@ class client { if (config_.value().username.empty() || config_.value().password.empty()) { return async_mqtt::v5::connect_packet{ true, std::chrono::seconds(100).count(), - async_mqtt::allocate_buffer(config_.value().client_id), + config_.value().client_id, async_mqtt::will( - async_mqtt::allocate_buffer(mqtt_will_topic_), + mqtt_will_topic_, async_mqtt::buffer(std::string_view{ mqtt_will_payload_ }), { async_mqtt::qos::at_least_once | async_mqtt::pub::retain::no }), - async_mqtt::nullopt, - async_mqtt::nullopt, + std::nullopt, + std::nullopt, { async_mqtt::property::session_expiry_interval{ 0 } } }; } return async_mqtt::v5::connect_packet{ true, std::chrono::seconds(100).count(), - async_mqtt::allocate_buffer(config_.value().client_id), + config_.value().client_id, async_mqtt::will( - async_mqtt::allocate_buffer(mqtt_will_topic_), + mqtt_will_topic_, async_mqtt::buffer(std::string_view{ mqtt_will_payload_ }), { async_mqtt::qos::at_least_once | async_mqtt::pub::retain::no }), - async_mqtt::allocate_buffer(config_.value().username), - async_mqtt::allocate_buffer(config_.value().password), + config_.value().username, + config_.value().password, { async_mqtt::property::session_expiry_interval{ 0 } } }; } diff --git a/exes/mqtt-bridge/tests/src/unit_tests.cpp b/exes/mqtt-bridge/tests/src/unit_tests.cpp index a074638de7..0764d5546f 100644 --- a/exes/mqtt-bridge/tests/src/unit_tests.cpp +++ b/exes/mqtt-bridge/tests/src/unit_tests.cpp @@ -1,6 +1,7 @@ #include #include +#define ASYNC_MQTT_SEPARATE_COMPILATION #include #include #include diff --git a/libs/confman/inc/public/tfc/confman.hpp b/libs/confman/inc/public/tfc/confman.hpp index db403bb577..964c7e4a99 100644 --- a/libs/confman/inc/public/tfc/confman.hpp +++ b/libs/confman/inc/public/tfc/confman.hpp @@ -79,7 +79,7 @@ class config { auto operator->() const noexcept -> storage_t const* { return std::addressof(value()); } /// \return storage_t as json string - [[nodiscard]] auto string() const -> std::string { return glz::write_json(storage_.value()); } + [[nodiscard]] auto string() const -> std::expected { return glz::write_json(storage_.value()); } /// TODO can we do this differently, jsonforms requires object as root element /// an example of failure would be confman> as the json schema root element would be array @@ -99,7 +99,12 @@ class config { } auto set_changed() const noexcept -> std::error_code { - client_.set(this->string()); + auto value{ this->string() }; + if (!value.has_value()) { + logger_.error("Error writing string: {}", glz::format_error(value.error())); + return std::make_error_code(std::errc::io_error); + } + client_.set(value.value()); return storage_.set_changed(); } diff --git a/libs/confman/testing/examples/confman_example_item.cpp b/libs/confman/testing/examples/confman_example_item.cpp index c05517bc1f..863188ff6d 100644 --- a/libs/confman/testing/examples/confman_example_item.cpp +++ b/libs/confman/testing/examples/confman_example_item.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) { tfc::confman::config> const config{ dbus, "key" }; config->observe([](auto new_value, auto old_value) { - fmt::print("new value: {}, old value: {}\n", new_value.to_json(), old_value.to_json()); + fmt::print("new value: {}, old value: {}\n", new_value.to_json().value(), old_value.to_json().value()); }); fmt::print("Schema is: {}\n", config.schema()); diff --git a/libs/ipc/inc/public/tfc/ipc/item.hpp b/libs/ipc/inc/public/tfc/ipc/item.hpp index 82facd8fb4..e1e0a988a8 100644 --- a/libs/ipc/inc/public/tfc/ipc/item.hpp +++ b/libs/ipc/inc/public/tfc/ipc/item.hpp @@ -209,8 +209,8 @@ struct item; struct item { using time_point = std::chrono::time_point; - [[nodiscard]] static auto from_json(std::string_view json) -> std::expected; - [[nodiscard]] auto to_json() const -> std::string; + [[nodiscard]] static auto from_json(std::string_view json) -> std::expected; + [[nodiscard]] auto to_json() const -> std::expected; [[nodiscard]] auto id() const -> std::string; // ids diff --git a/libs/ipc/src/item.cpp b/libs/ipc/src/item.cpp index bf20b7f63e..7a5a4bd980 100644 --- a/libs/ipc/src/item.cpp +++ b/libs/ipc/src/item.cpp @@ -27,7 +27,7 @@ auto make() -> item { pcg_extras::seed_seq_from seed_source; return make(seed_source); } -auto item::from_json(std::string_view json) -> std::expected { +auto item::from_json(std::string_view json) -> std::expected { auto temporary = glz::read_json(json); if (!temporary.has_value()) { return temporary; @@ -36,7 +36,7 @@ auto item::from_json(std::string_view json) -> std::expectedlast_exchange = std::chrono::time_point_cast(std::chrono::system_clock::now()); return temporary; } -auto item::to_json() const -> std::string { +auto item::to_json() const -> std::expected { return glz::write_json(*this); } auto item::id() const -> std::string {