diff options
Diffstat (limited to 'libdbus-qeventloop/dbusconnectioneventloop.cpp')
-rw-r--r-- | libdbus-qeventloop/dbusconnectioneventloop.cpp | 138 |
1 files changed, 61 insertions, 77 deletions
diff --git a/libdbus-qeventloop/dbusconnectioneventloop.cpp b/libdbus-qeventloop/dbusconnectioneventloop.cpp index 2c040b2..0bce26e 100644 --- a/libdbus-qeventloop/dbusconnectioneventloop.cpp +++ b/libdbus-qeventloop/dbusconnectioneventloop.cpp @@ -16,16 +16,14 @@ DBUSConnectionEventLoop::~DBUSConnectionEventLoop() // Handle a socket being ready to read. void DBUSConnectionEventLoop::readSocket(int fd) { - MYDEBUG(); + MYDEBUG(); Watchers::const_iterator it = watchers.find(fd); - while( it != watchers.end() && it.key() == fd ) - { + while (it != watchers.end() && it.key() == fd) { const Watcher &watcher = it.value(); - if( watcher.read && watcher.read->isEnabled() ) - { + if (watcher.read && watcher.read->isEnabled()) { watcher.read->setEnabled(false); dbus_watch_handle(watcher.watch, DBUS_WATCH_READABLE); watcher.read->setEnabled(true); @@ -41,16 +39,14 @@ void DBUSConnectionEventLoop::readSocket(int fd) // Handle a socket being ready to write. void DBUSConnectionEventLoop::writeSocket(int fd) { - MYDEBUG(); + MYDEBUG(); Watchers::const_iterator it = watchers.find(fd); - while( it != watchers.end() && it.key() == fd ) - { + while (it != watchers.end() && it.key() == fd) { const Watcher &watcher = it.value(); - if( watcher.write && watcher.write->isEnabled() ) - { + if (watcher.write && watcher.write->isEnabled()) { watcher.write->setEnabled(false); dbus_watch_handle(watcher.watch, DBUS_WATCH_WRITABLE); watcher.write->setEnabled(true); @@ -63,30 +59,30 @@ void DBUSConnectionEventLoop::writeSocket(int fd) void DBUSConnectionEventLoop::dispatch() { - MYDEBUG(); + MYDEBUG(); - for( Connections::const_iterator it = connections.constBegin(); it != connections.constEnd(); ++it ) - while( dbus_connection_dispatch(*it) == DBUS_DISPATCH_DATA_REMAINS ) + for (Connections::const_iterator it = connections.constBegin(); it != connections.constEnd(); ++it) + while (dbus_connection_dispatch(*it) == DBUS_DISPATCH_DATA_REMAINS) ; } // Handle timer events. void DBUSConnectionEventLoop::timerEvent(QTimerEvent *e) { - MYDEBUG(); - MYDEBUGC("TimerID: %d", e->timerId()); + MYDEBUG(); + MYDEBUGC("TimerID: %d", e->timerId()); DBusTimeout *timeout = timeouts.value(e->timerId()); - if( timeout ) + if (timeout) dbus_timeout_handle(timeout); } dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); + DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); int fd = dbus_watch_get_unix_fd(watch); unsigned int flags = dbus_watch_get_flags(watch); @@ -95,15 +91,13 @@ dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) DBUSConnectionEventLoop::Watcher watcher; watcher.watch = watch; - if( flags & DBUS_WATCH_READABLE ) - { + if (flags & DBUS_WATCH_READABLE) { watcher.read = new QSocketNotifier(fd, QSocketNotifier::Read, loop); watcher.read->setEnabled(enabled); loop->connect(watcher.read, SIGNAL(activated(int)), SLOT(readSocket(int))); } - if( flags & DBUS_WATCH_WRITABLE ) - { + if (flags & DBUS_WATCH_WRITABLE) { watcher.write = new QSocketNotifier(fd, QSocketNotifier::Write, loop); watcher.write->setEnabled(enabled); loop->connect(watcher.write, SIGNAL(activated(int)), SLOT(writeSocket(int))); @@ -116,24 +110,22 @@ dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); + DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); int fd = dbus_watch_get_unix_fd(watch); DBUSConnectionEventLoop::Watchers::iterator it = loop->watchers.find(fd); - while( it != loop->watchers.end() && it.key() == fd ) - { - DBUSConnectionEventLoop::Watcher &watcher = it.value(); + while (it != loop->watchers.end() && it.key() == fd) { + DBUSConnectionEventLoop::Watcher &watcher = it.value(); - if( watcher.watch == watch ) - { - if( watcher.read ) + if (watcher.watch == watch) { + if (watcher.read) delete watcher.read; - if( watcher.write ) + if (watcher.write) delete watcher.write; loop->watchers.erase(it); @@ -147,9 +139,9 @@ void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data) void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop*>(data); + DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop*>(data); int fd = dbus_watch_get_unix_fd(watch); unsigned int flags = dbus_watch_get_flags(watch); @@ -157,16 +149,14 @@ void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) DBUSConnectionEventLoop::Watchers::const_iterator it = loop->watchers.find(fd); - while( it != loop->watchers.end() && it.key() == fd ) - { + while (it != loop->watchers.end() && it.key() == fd) { const DBUSConnectionEventLoop::Watcher &watcher = it.value(); - if( watcher.watch == watch ) - { - if( flags & DBUS_WATCH_READABLE && watcher.read ) + if (watcher.watch == watch) { + if (flags & DBUS_WATCH_READABLE && watcher.read) watcher.read->setEnabled(enabled); - if( flags & DBUS_WATCH_WRITABLE && watcher.write ) + if (flags & DBUS_WATCH_WRITABLE && watcher.write) watcher.write->setEnabled(enabled); return; @@ -178,14 +168,14 @@ void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); // Nothing to do if the timeout is disabled. - if( !dbus_timeout_get_enabled(timeout) ) + if (!dbus_timeout_get_enabled(timeout)) return true; // Pretend it is successful if there is no application instance. - if( !QCoreApplication::instance() ) + if (!QCoreApplication::instance()) return true; DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); @@ -195,7 +185,7 @@ dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data MYDEBUGC("Adding timeout %d with interval %d!", id, timerInterval); - if( !id ) + if (!id) return false; loop->timeouts[id] = timeout; @@ -205,16 +195,14 @@ dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data void DBUSConnectionEventLoop::removeTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); + DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); - DBUSConnectionEventLoop::Timeouts::iterator it = loop->timeouts.begin(); + DBUSConnectionEventLoop::Timeouts::iterator it = loop->timeouts.begin(); - while( it != loop->timeouts.end() ) - { - if( it.value() == timeout ) - { + while (it != loop->timeouts.end()) { + if (it.value() == timeout) { loop->killTimer(it.key()); it = loop->timeouts.erase(it); } @@ -225,17 +213,17 @@ void DBUSConnectionEventLoop::removeTimeout(DBusTimeout *timeout, void *data) void DBUSConnectionEventLoop::toggleTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop::removeTimeout(timeout, data); - DBUSConnectionEventLoop::addTimeout(timeout, data); + DBUSConnectionEventLoop::removeTimeout(timeout, data); + DBUSConnectionEventLoop::addTimeout(timeout, data); } void DBUSConnectionEventLoop::wakeupMain(void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); + DBUSConnectionEventLoop *loop = reinterpret_cast<DBUSConnectionEventLoop *>(data); QTimer::singleShot(0, loop, SLOT(dispatch())); } @@ -245,35 +233,31 @@ bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn) { bool rc; - if( conn == NULL ) - { - return false; - } + if (conn == NULL) { + return false; + } connections.append(conn); - if( - !dbus_connection_set_watch_functions(conn, - DBUSConnectionEventLoop::addWatch, - DBUSConnectionEventLoop::removeWatch, - DBUSConnectionEventLoop::toggleWatch, - this, 0) - ) - { + if ( + !dbus_connection_set_watch_functions(conn, + DBUSConnectionEventLoop::addWatch, + DBUSConnectionEventLoop::removeWatch, + DBUSConnectionEventLoop::toggleWatch, + this, 0) + ) { rc = false; } - else if( - !dbus_connection_set_timeout_functions(conn, - DBUSConnectionEventLoop::addTimeout, - DBUSConnectionEventLoop::removeTimeout, - DBUSConnectionEventLoop::toggleTimeout, - this, 0) - ) - { + else if ( + !dbus_connection_set_timeout_functions(conn, + DBUSConnectionEventLoop::addTimeout, + DBUSConnectionEventLoop::removeTimeout, + DBUSConnectionEventLoop::toggleTimeout, + this, 0) + ) { rc = false; } - else - { + else { rc = true; } |