event/SocketMonitor: refactor to SocketEvent
Similar to commits1686f4e857
and30a5dd267b
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2018 Content Management AG
|
||||
* Copyright 2007-2020 CM4all GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* author: Max Kellermann <mk@cm4all.com>
|
||||
@@ -36,8 +36,8 @@ namespace ODBus {
|
||||
|
||||
WatchManager::Watch::Watch(EventLoop &event_loop,
|
||||
WatchManager &_parent, DBusWatch &_watch) noexcept
|
||||
:SocketMonitor(event_loop),
|
||||
parent(_parent), watch(_watch)
|
||||
:parent(_parent), watch(_watch),
|
||||
event(event_loop, BIND_THIS_METHOD(OnSocketReady))
|
||||
{
|
||||
Toggled();
|
||||
}
|
||||
@@ -45,30 +45,30 @@ WatchManager::Watch::Watch(EventLoop &event_loop,
|
||||
static constexpr unsigned
|
||||
DbusToLibevent(unsigned flags) noexcept
|
||||
{
|
||||
return ((flags & DBUS_WATCH_READABLE) != 0) * SocketMonitor::READ |
|
||||
((flags & DBUS_WATCH_WRITABLE) != 0) * SocketMonitor::WRITE;
|
||||
return ((flags & DBUS_WATCH_READABLE) != 0) * SocketEvent::READ |
|
||||
((flags & DBUS_WATCH_WRITABLE) != 0) * SocketEvent::WRITE;
|
||||
}
|
||||
|
||||
void
|
||||
WatchManager::Watch::Toggled() noexcept
|
||||
{
|
||||
if (SocketMonitor::IsDefined())
|
||||
SocketMonitor::Cancel();
|
||||
if (event.IsDefined())
|
||||
event.Cancel();
|
||||
|
||||
if (dbus_watch_get_enabled(&watch)) {
|
||||
SocketMonitor::Open(SocketDescriptor(dbus_watch_get_unix_fd(&watch)));
|
||||
SocketMonitor::Schedule(DbusToLibevent(dbus_watch_get_flags(&watch)));
|
||||
event.Open(SocketDescriptor(dbus_watch_get_unix_fd(&watch)));
|
||||
event.Schedule(DbusToLibevent(dbus_watch_get_flags(&watch)));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr unsigned
|
||||
LibeventToDbus(unsigned flags) noexcept
|
||||
{
|
||||
return ((flags & SocketMonitor::READ) != 0) * DBUS_WATCH_READABLE |
|
||||
((flags & SocketMonitor::WRITE) != 0) * DBUS_WATCH_WRITABLE;
|
||||
return ((flags & SocketEvent::READ) != 0) * DBUS_WATCH_READABLE |
|
||||
((flags & SocketEvent::WRITE) != 0) * DBUS_WATCH_WRITABLE;
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
WatchManager::Watch::OnSocketReady(unsigned events) noexcept
|
||||
{
|
||||
/* copy the "parent" reference to the stack, because the
|
||||
@@ -79,7 +79,6 @@ WatchManager::Watch::OnSocketReady(unsigned events) noexcept
|
||||
dbus_watch_handle(&watch, LibeventToDbus(events));
|
||||
|
||||
_parent.ScheduleDispatch();
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user