diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | qt/dbus-qt.h | 80 | ||||
-rw-r--r-- | qt/dbus-qthread.cc | 85 |
3 files changed, 171 insertions, 0 deletions
@@ -1,3 +1,9 @@ +2002-12-24 Zack Rusin <zack@kde.org> + + * qt/dbus-qthread.cc: adding - integrates QMutex into Dbus + * qt/dbus-qt.h: skeleton with two sample implemenatation of the + main loop stuff + 2002-12-24 Havoc Pennington <hp@pobox.com> * glib/dbus-gthread.c: fix include diff --git a/qt/dbus-qt.h b/qt/dbus-qt.h new file mode 100644 index 00000000..aaa343fe --- /dev/null +++ b/qt/dbus-qt.h @@ -0,0 +1,80 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* + * dbus-qt.h Qt integration + * + * Copyright (C) 2002 DBus Developers + * + * Licensed under the Academic Free License version 1.2 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ +#ifndef DBUS_QT_H +#define DBUS_QT_H + +#include <dbus/dbus.h> +/* + * Two approaches - one presented below a DBusQtConnection + * object which is a Qt wrapper around DBusConnection +class DBusQtConnection : public QObject { + Q_OBJECT +public: + DBusQtConnection( QObject *parent=0, const char *address=0 ); + + bool open( const char *address ); + bool isConnected() const; + int getNumberOfMessages() const; + +public slots: + void disconnect(); + void flush(); + void sendMessage( DBusMessage *message ); + +signals: + void message( DBusMessage* message ); + void error( const char* error ); +private: + DBusConnection *mConnection; + QSocketNotifier *mReadNotifier; + QSocketNotifier *mWriteNotifier; +}; + * + * Second approach is to have a static Qt dispatcher like: +class DBusQtNotifier : public QObject { + Q_OBJECT +public: + static DBusQtNotifier* dbus_qt_notifier (); + void addConnection (DBusConnection* connection); +signals: + void message (DBusConnection* connection, DBusMessage* message); + +private: + DBusQtNotifier (QObject *parent); +private slots: + void processNotifiers( int socket ); +private: + //implemnted in terms of QSocketNotifiers + QAsciiDict<DBusConnection> mReadNotifiers; + QAsciiDict<DBusConnection> mWriteNotifiers; +}; + * + * First one gives us a full wrapper for DBusConnection (the Qt way), + * the other exposes DBusConnection, so would be easier to maintain + * and keep up while DBus evolves. + * + */ + +#endif /* DBUS_QT_H */ diff --git a/qt/dbus-qthread.cc b/qt/dbus-qthread.cc new file mode 100644 index 00000000..ab266284 --- /dev/null +++ b/qt/dbus-qthread.cc @@ -0,0 +1,85 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-qthread.c Qt threads integration + * + * Copyright (C) 2002 Zack Rusin <zack@kde.org> + * + * Licensed under the Academic Free License version 1.2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include <qmutex.h> +#include <dbus/dbus.h> + +static DBusMutex * dbus_qmutex_new (void); +static void dbus_qmutex_free (DBusMutex *mutex); +static dbus_bool_t dbus_qmutex_lock (DBusMutex *mutex); +static dbus_bool_t dbus_qmutex_unlock (DBusMutex *mutex); + + +static const DBusThreadFunctions functions = +{ + DBUS_THREAD_FUNCTIONS_NEW_MASK | + DBUS_THREAD_FUNCTIONS_FREE_MASK | + DBUS_THREAD_FUNCTIONS_LOCK_MASK | + DBUS_THREAD_FUNCTIONS_UNLOCK_MASK, + dbus_qmutex_new, + dbus_qmutex_free, + dbus_qmutex_lock, + dbus_qmutex_unlock +}; + +static DBusMutex * +dbus_qmutex_new (void) +{ + QMutex *mutex; + mutex = new QMutex; + return static_cast<DBusMutex*>( mutex ); +} + +static void +dbus_qmutex_free (DBusMutex *mutex) +{ + QMutex * qmutex = static_cast<QMutex*>(mutex); + delete mutex; +} + +static dbus_bool_t +dbus_qmutex_lock (DBusMutex *mutex) +{ + QMutex *qmutex = static_cast<QMutex*>(mutex); + qmutex->lock(); + return TRUE; +} + +static dbus_bool_t +dbus_qmutex_unlock (DBusMutex *mutex) +{ + QMutex *qmutex = static_cast<QMutex*>(mutex); + qmutex->unlock(); + return TRUE; +} + +extern "C" { + +void +dbus_qthread_init (void) +{ + //Do we want to do anything else here? + dbus_threads_init (&functions); +} + +} |