Skip to content

Commit

Permalink
Fixed lifetime issue with connection and match
Browse files Browse the repository at this point in the history
  • Loading branch information
SindriTh committed Dec 8, 2023
1 parent b946ef2 commit ae88af4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions exes/ttui/src/dbus_screen_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ void DBusScreenManager::SetupComponents() {
}

void DBusScreenManager::SetupDBusConnection() {
auto connection = std::make_shared<sdbusplus::asio::connection>(ctx, tfc::dbus::sd_bus_open_system_mon());
auto match = std::make_unique<sdbusplus::bus::match::match>(
*connection,
"",
std::bind(&DBusScreenManager::match_callback, this, std::placeholders::_1)
);
connection =
std::make_shared<sdbusplus::asio::connection>(ctx, tfc::dbus::sd_bus_open_system_mon());
match = std::make_unique<sdbusplus::bus::match::match>(
*connection,
"",
[this](sdbusplus::message_t& msg) { this->match_callback(msg); }
);
auto mc = connection->new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus.Monitoring",
"BecomeMonitor");
mc.append<std::vector<std::string>, uint32_t>({ "path=/com/skaginn3x/Signals" }, 0);
Expand Down Expand Up @@ -96,7 +97,7 @@ void DBusScreenManager::match_callback(sdbusplus::message_t& msg) {
}
}

ftxui::Component DBusScreenManager::left_menu() {
auto DBusScreenManager::left_menu() -> ftxui::Component {
auto option = ftxui::MenuOption::Vertical();

option.on_enter = [this] {
Expand All @@ -109,8 +110,8 @@ ftxui::Component DBusScreenManager::left_menu() {
return ftxui::Menu(&noticed_interfaces, &left_menu_selected, option);
}

ftxui::Component DBusScreenManager::right_menu() {
auto DBusScreenManager::right_menu() -> ftxui::Component {
auto option = ftxui::MenuOption::Vertical();
option.on_enter = screen.ExitLoopClosure();
// option.on_enter = screen.ExitLoopClosure();
return ftxui::Menu(&entries, &right_menu_selected, option);
}
2 changes: 2 additions & 0 deletions exes/ttui/src/dbus_screen_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DBusScreenManager {
int left_menu_selected = 0;
int right_menu_selected = 0;
asio::io_context ctx{};
std::shared_ptr<sdbusplus::asio::connection> connection;
std::__detail::__unique_ptr_t<sdbusplus::bus::match::match> match;

void SetupComponents();
void SetupDBusConnection();
Expand Down

0 comments on commit ae88af4

Please sign in to comment.