summaryrefslogtreecommitdiff
path: root/libdbus-qeventloop
diff options
context:
space:
mode:
authorMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
committerMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
commit7bfa856f0673b81d4d0dafd6e02e07f10f07a023 (patch)
tree309ac66b5cbfe77df701fc9c7a0c7e5a68d147e7 /libdbus-qeventloop
parenta19a377ae930d54beb98dbe1f6171c6d39ddea80 (diff)
downloadlibresourceqt-7bfa856f0673b81d4d0dafd6e02e07f10f07a023.tar.gz
dbus-qeventloop update
Diffstat (limited to 'libdbus-qeventloop')
-rw-r--r--libdbus-qeventloop/dbusconnectioneventloop.cpp71
-rw-r--r--libdbus-qeventloop/dbusconnectioneventloop.h13
-rw-r--r--libdbus-qeventloop/libdbus-qeventloop.pro1
3 files changed, 77 insertions, 8 deletions
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;
+ }
+ }
+}
diff --git a/libdbus-qeventloop/dbusconnectioneventloop.h b/libdbus-qeventloop/dbusconnectioneventloop.h
index 8067e75..d44f667 100644
--- a/libdbus-qeventloop/dbusconnectioneventloop.h
+++ b/libdbus-qeventloop/dbusconnectioneventloop.h
@@ -48,18 +48,24 @@ class DBUSConnectionEventLoop : public QObject
{
Q_OBJECT
private:
+ static DBUSConnectionEventLoop classInstance;
+
Q_DISABLE_COPY(DBUSConnectionEventLoop)
+ DBUSConnectionEventLoop();
public:
- DBUSConnectionEventLoop();
virtual ~DBUSConnectionEventLoop();
-public:
/**
* Add new dbus connection into handler.
* \return true if everything went well.
*/
- bool addConnection(DBusConnection* conn);
+ static bool addConnection(DBusConnection* conn);
+ static void removeConnection(DBusConnection* conn);
+
+private:
+ bool internalAddConnection(DBusConnection* conn);
+ void internalRemoveConnection(DBusConnection* conn);
/**
* Helper class for dbus watcher
@@ -100,6 +106,7 @@ private slots:
protected:
void timerEvent(QTimerEvent *e);
+ void cleanup();
static dbus_bool_t addWatch(DBusWatch *watch, void *data);
static void removeWatch(DBusWatch *watch, void *data);
diff --git a/libdbus-qeventloop/libdbus-qeventloop.pro b/libdbus-qeventloop/libdbus-qeventloop.pro
index 5b0ef18..cbed3cf 100644
--- a/libdbus-qeventloop/libdbus-qeventloop.pro
+++ b/libdbus-qeventloop/libdbus-qeventloop.pro
@@ -14,6 +14,7 @@ HEADERS += dbusconnectioneventloop.h
QT = core
CONFIG += qt link_pkgconfig dll
PKGCONFIG += dbus-1
+DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT QT_NO_DEBUG_STREAM
# Install directives
headers.files = $$HEADERS