Skip to content

Commit

Permalink
Fixed signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Haefner committed Jul 28, 2021
1 parent e29cbbb commit a25f598
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ Dispatcher::~Dispatcher()

void Dispatcher::notify_clients(const std::string& busname, ConnectionState state)
{
auto range = d->stubs_.equal_range(busname);
std::for_each(d->stubs_.begin(), d->stubs_.end(), [busname, state](auto& entry){

std::for_each(range.first, range.second, [state](auto& entry){
entry.second->connection_state_changed(state);
if (busname == entry.second->busname())
entry.second->connection_state_changed(state);
});
}

Expand Down Expand Up @@ -595,6 +595,8 @@ void Dispatcher::unregister_signal_match(const std::string& match_string)
DBusError err;
dbus_error_init(&err);

d->signal_matches_.erase(iter);

dbus_bus_remove_match(conn_, match_string.c_str(), &err);
if (dbus_error_is_set(&err))
throw RuntimeError("dbus_bus_remove_match", std::move(err));
Expand Down Expand Up @@ -658,27 +660,18 @@ DBusHandlerResult Dispatcher::try_handle_signal(DBusMessage* msg)

// ordinary signals...

// here we expect that pathname is the same as busname, just with / instead of .
char originator[256];
strncpy(originator, dbus_message_get_path(msg)+1, sizeof(originator));
originator[sizeof(originator)-1] = '\0';
bool handled = false;
auto range = d->stubs_.equal_range(dbus_message_get_path(msg));

char* p = originator;
while(*++p)
for (auto iter = range.first; iter != range.second; ++iter)
{
if (*p == '/')
*p = '.';
iter->second->try_handle_signal(msg);
handled = true;
}

auto range = d->stubs_.equal_range(originator);
if (range.first != range.second)
{
std::for_each(range.first, range.second, [msg](auto& entry){
entry.second->try_handle_signal(msg);
});

if (handled)
return DBUS_HANDLER_RESULT_HANDLED;
}

// else
// nobody interested in signal - go on with other filters
}
Expand All @@ -703,8 +696,7 @@ void Dispatcher::add_client(StubBase& clnt)
{
clnt.disp_ = this;

//std::cout << "Adding stub: " << clnt.busname() << std::endl;
d->stubs_.insert(std::make_pair(clnt.busname(), &clnt));
d->stubs_.insert(std::make_pair(clnt.objectpath(), &clnt));

// send connected request from event loop
auto iter = d->busnames_.find(clnt.busname());
Expand Down

0 comments on commit a25f598

Please sign in to comment.