From 7bfa856f0673b81d4d0dafd6e02e07f10f07a023 Mon Sep 17 00:00:00 2001 From: Martin Wolf Date: Wed, 7 Apr 2010 13:33:26 +0300 Subject: dbus-qeventloop update --- libdbus-qeventloop/dbusconnectioneventloop.cpp | 71 ++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) (limited to 'libdbus-qeventloop/dbusconnectioneventloop.cpp') diff --git a/libdbus-qeventloop/dbusconnectioneventloop.cpp b/libdbus-qeventloop/dbusconnectioneventloop.cpp index 0bce26e..e759d36 100644 --- a/libdbus-qeventloop/dbusconnectioneventloop.cpp +++ b/libdbus-qeventloop/dbusconnectioneventloop.cpp @@ -5,12 +5,41 @@ #include "dbusconnectioneventloop.h" +DBUSConnectionEventLoop DBUSConnectionEventLoop::classInstance; + +bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn) +{ + return classInstance.internalAddConnection(conn); +} + +void DBUSConnectionEventLoop::removeConnection(DBusConnection* conn) +{ + classInstance.internalRemoveConnection(conn); +} + DBUSConnectionEventLoop::DBUSConnectionEventLoop() : QObject() { + MYDEBUG(); } DBUSConnectionEventLoop::~DBUSConnectionEventLoop() { + MYDEBUG(); + cleanup(); +} + +void DBUSConnectionEventLoop::cleanup() +{ + MYDEBUG(); + + Connections::iterator it; + for (it = connections.begin(); it != connections.end(); ++it) { + MYDEBUGC("Cleaning connection %p", *it); + + dbus_connection_set_watch_functions(*it, NULL, NULL, NULL, NULL, NULL); + dbus_connection_set_timeout_functions(*it, NULL, NULL, NULL, NULL, NULL); + dbus_connection_set_wakeup_main_function(*it, NULL, NULL, NULL); + } } // Handle a socket being ready to read. @@ -122,11 +151,12 @@ void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data) DBUSConnectionEventLoop::Watcher &watcher = it.value(); if (watcher.watch == watch) { - if (watcher.read) + if (watcher.read) { delete watcher.read; - - if (watcher.write) + } + if (watcher.write) { delete watcher.write; + } loop->watchers.erase(it); @@ -229,14 +259,28 @@ void DBUSConnectionEventLoop::wakeupMain(void *data) } // The initialization point -bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn) +bool DBUSConnectionEventLoop::internalAddConnection(DBusConnection* conn) { - bool rc; + MYDEBUG(); + + bool rc = true; if (conn == NULL) { return false; } + MYDEBUGC("Adding connection %p", conn); + + // Check if connection is in list + Connections::iterator it; + for (it = connections.begin(); it != connections.end(); ++it) { + if( *it == conn ) { + MYDEBUGC("Connection already in list, skipping"); + // Skip adding duplicate connection + return true; + } + } + // Add new connection connections.append(conn); if ( @@ -265,3 +309,20 @@ bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn) return rc; } + +void DBUSConnectionEventLoop::internalRemoveConnection(DBusConnection* conn) +{ + MYDEBUG(); + + Connections::iterator it; + for (it = connections.begin(); it != connections.end(); ++it) { + if( *it == conn ) { + dbus_connection_set_watch_functions(*it, NULL, NULL, NULL, NULL, NULL); + dbus_connection_set_timeout_functions(*it, NULL, NULL, NULL, NULL, NULL); + dbus_connection_set_wakeup_main_function(*it, NULL, NULL, NULL); + + connections.erase(it); + return; + } + } +} -- cgit v1.2.3