Skip to content

Commit

Permalink
wip updating dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jbbjarnason committed Jun 24, 2024
1 parent 004b593 commit 91b6ad5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
27 changes: 12 additions & 15 deletions exes/mqtt-bridge/inc/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <tuple>

#include <async_mqtt/all.hpp>
#include <async_mqtt/buffer.hpp>
#include <async_mqtt/error.hpp>
#include <boost/asio.hpp>

#include <tfc/logger.hpp>
Expand Down Expand Up @@ -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));
}
Expand All @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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 } } };
}

Expand Down
1 change: 1 addition & 0 deletions exes/mqtt-bridge/tests/src/unit_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <chrono>
#include <string>

#define ASYNC_MQTT_SEPARATE_COMPILATION
#include <async_mqtt/all.hpp>
#include <boost/asio.hpp>
#include <boost/program_options.hpp>
Expand Down
9 changes: 7 additions & 2 deletions libs/confman/inc/public/tfc/confman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, glz::error_ctx> { 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<std::vector<int>> as the json schema root element would be array
Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion libs/confman/testing/examples/confman_example_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, char** argv) {

tfc::confman::config<tfc::confman::observable<tfc::ipc::item::item>> 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());
Expand Down
4 changes: 2 additions & 2 deletions libs/ipc/inc/public/tfc/ipc/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ struct item;
struct item {
using time_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>;

[[nodiscard]] static auto from_json(std::string_view json) -> std::expected<item, glz::parse_error>;
[[nodiscard]] auto to_json() const -> std::string;
[[nodiscard]] static auto from_json(std::string_view json) -> std::expected<item, glz::error_ctx>;
[[nodiscard]] auto to_json() const -> std::expected<std::string, glz::error_ctx>;
[[nodiscard]] auto id() const -> std::string;

// ids
Expand Down
4 changes: 2 additions & 2 deletions libs/ipc/src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ auto make() -> item {
pcg_extras::seed_seq_from<std::random_device> seed_source;
return make(seed_source);
}
auto item::from_json(std::string_view json) -> std::expected<item, glz::parse_error> {
auto item::from_json(std::string_view json) -> std::expected<item, glz::error_ctx> {
auto temporary = glz::read_json<item>(json);
if (!temporary.has_value()) {
return temporary;
Expand All @@ -36,7 +36,7 @@ auto item::from_json(std::string_view json) -> std::expected<item, glz::parse_er
temporary->last_exchange = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
return temporary;
}
auto item::to_json() const -> std::string {
auto item::to_json() const -> std::expected<std::string, glz::error_ctx> {
return glz::write_json(*this);
}
auto item::id() const -> std::string {
Expand Down

0 comments on commit 91b6ad5

Please sign in to comment.