From 63a1458aaf2d5fcd0425ec3f6c0dc89d68059206 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 24 Nov 2003 05:21:12 +0000 Subject: Seperating integration with D-BUS from Connection to the internal Integrator class. I simply hated the interfaces in the public Connection when it had to contain a bunch of friends and protected members that were never really meant to be seen. --- qt/connection.cpp | 78 +++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 57 deletions(-) (limited to 'qt/connection.cpp') diff --git a/qt/connection.cpp b/qt/connection.cpp index 8486ebb2..936db3eb 100644 --- a/qt/connection.cpp +++ b/qt/connection.cpp @@ -22,41 +22,43 @@ */ #include "connection.h" -#include -#include - using namespace DBusQt; -struct QtWatch { - QtWatch(): readSocket( 0 ), writeSocket( 0 ) { } - - DBusWatch *watch; - QSocketNotifier *readSocket; - QSocketNotifier *writeSocket; -}; +#include "integrator.h" +using Internal::Integrator; struct Connection::Private { DBusConnection *connection; int connectionSlot; DBusError error; - QIntDict watches; + Integrator *integrator; }; Connection::Connection( const QString& host ) { d = new Private; - dbus_error_init( &d->error ); + d->integrator = new Integrator( this ); + connect( d->integrator, SIGNAL(readReady()), + SLOT(dispatchRead()) ); + + initDbus(); if ( !host.isEmpty() ) init( host ); } +void Connection::initDbus() +{ +} + void Connection::init( const QString& host ) { + dbus_error_init( &d->error ); d->connection = dbus_connection_open( host.ascii(), &d->error ); - dbus_connection_allocate_data_slot( &d->connectionSlot ); - dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 ); + //dbus_connection_allocate_data_slot( &d->connectionSlot ); + //dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 ); + initDbus(); } bool Connection::isConnected() const @@ -84,55 +86,17 @@ void Connection::flush() dbus_connection_flush( d->connection ); } -void Connection::slotRead( int fd ) +void Connection::dispatchRead() { - Q_UNUSED( fd ); while ( dbus_connection_dispatch( d->connection ) == DBUS_DISPATCH_DATA_REMAINS ) ; } -void Connection::slotWrite( int fd ) +DBusConnection* Connection::connection() const { - Q_UNUSED( fd ); + return d->connection; } -void Connection::addWatch( DBusWatch *watch ) -{ - if ( !dbus_watch_get_enabled( watch ) ) - return; - - QtWatch *qtwatch = new QtWatch; - qtwatch->watch = watch; - - int flags = dbus_watch_get_flags( watch ); - int fd = dbus_watch_get_fd( watch ); - - if ( flags & DBUS_WATCH_READABLE ) { - qtwatch->readSocket = new QSocketNotifier( fd, QSocketNotifier::Read, this ); - QObject::connect( qtwatch->readSocket, SIGNAL(activated(int)), SLOT(slotRead(int)) ); - } - - if (flags & DBUS_WATCH_WRITABLE) { - qtwatch->writeSocket = new QSocketNotifier( fd, QSocketNotifier::Write, this ); - QObject::connect( qtwatch->writeSocket, SIGNAL(activated(int)), SLOT(slotWrite(int)) ); - } - - d->watches.insert( fd, qtwatch ); - -} - -void Connection::removeWatch( DBusWatch *watch ) -{ - int key = dbus_watch_get_fd( watch ); - - QtWatch *qtwatch = d->watches.take( key ); - - if ( qtwatch ) { - delete qtwatch->readSocket; qtwatch->readSocket = 0; - delete qtwatch->writeSocket; qtwatch->writeSocket = 0; - delete qtwatch; - } -} - - ///////////////////////////////////////////////////////// + +#include "connection.moc" -- cgit