summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2003-11-24 19:11:55 +0000
committerZack Rusin <zack@kde.org>2003-11-24 19:11:55 +0000
commit27f6dca9ce4680dbbe8dc20a862f5ad63b709609 (patch)
treef3458e7b3c5a9ad1debfc178c50df26b2f7ba380
parent89d43511ec5718823d8faa98246e420af5f26d5a (diff)
As changelog says. Integration is pretty much there, so dbus should at least
use Qt for timeouts and watches comfortably now.
-rw-r--r--ChangeLog8
-rw-r--r--qt/connection.cpp7
-rw-r--r--qt/connection.h1
-rw-r--r--qt/integrator.cpp103
-rw-r--r--qt/integrator.h78
5 files changed, 124 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index f029944b..9947af20 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2003-11-24 Zack Rusin <zack@kde.org>
+ * qt/connection.h, qt/connection.cpp: removing initDbus method since
+ the integrator handles it now
+
+ * qt/integrator.h, qt/integrator.cpp: reworking handling of timeouts,
+ since QTimer wasn't really meant to be used the way DBusTimeout is
+
+2003-11-24 Zack Rusin <zack@kde.org>
+
* qt/integrator.h, qt/integrator.cpp, Makefile.am: Adding
Integrator class which integrates D-BUS with the Qt event loop,
diff --git a/qt/connection.cpp b/qt/connection.cpp
index 936db3eb..830987d6 100644
--- a/qt/connection.cpp
+++ b/qt/connection.cpp
@@ -42,23 +42,16 @@ Connection::Connection( const QString& host )
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 );
- initDbus();
}
bool Connection::isConnected() const
diff --git a/qt/connection.h b/qt/connection.h
index b9ff9438..c864cd7c 100644
--- a/qt/connection.h
+++ b/qt/connection.h
@@ -61,7 +61,6 @@ namespace DBusQt {
protected:
void init( const QString& host );
- void initDbus();
virtual void* virtual_hook( int id, void* data );
private:
friend class Internal::Integrator;
diff --git a/qt/integrator.cpp b/qt/integrator.cpp
index 8d49606b..ca793a0a 100644
--- a/qt/integrator.cpp
+++ b/qt/integrator.cpp
@@ -32,30 +32,91 @@ namespace DBusQt
{
namespace Internal {
-struct QtWatch {
- QtWatch(): readSocket( 0 ), writeSocket( 0 ) { }
+struct Watch {
+ Watch(): readSocket( 0 ), writeSocket( 0 ) { }
DBusWatch *watch;
QSocketNotifier *readSocket;
QSocketNotifier *writeSocket;
};
-struct DBusQtTimeout {
- DBusQtTimeout(): timer( 0 ), timeout( 0 ) { }
- ~DBusQtTimeout() {
- delete timer;
- }
- QTimer *timer;
- DBusTimeout *timeout;
-};
+//////////////////////////////////////////////////////////////
+dbus_bool_t dbusAddWatch( DBusWatch *watch, void *data )
+{
+ Integrator *con = static_cast<Integrator*>( data );
+ con->addWatch( watch );
+ return true;
+}
+void dbusRemoveWatch( DBusWatch *watch, void *data )
+{
+ Integrator *con = static_cast<Integrator*>( data );
+ con->removeWatch( watch );
+}
+
+void dbusToggleWatch( DBusWatch *watch, void *data )
+{
+ Integrator *itg = static_cast<Integrator*>( data );
+ if ( dbus_watch_get_enabled( watch ) )
+ itg->addWatch( watch );
+ else
+ itg->removeWatch( watch );
+}
+
+dbus_bool_t dbusAddTimeout( DBusTimeout *timeout, void *data )
+{
+ if ( !dbus_timeout_get_enabled(timeout) )
+ return true;
+
+ Integrator *itg = static_cast<Integrator*>( data );
+ itg->addTimeout( timeout );
+ return true;
+}
+
+void dbusRemoveTimeout( DBusTimeout *timeout, void *data )
+{
+ Integrator *itg = static_cast<Integrator*>( data );
+ itg->removeTimeout( timeout );
+}
+
+void dbusToggleTimeout( DBusTimeout *timeout, void *data )
+{
+ Integrator *itg = static_cast<Integrator*>( data );
+
+ if ( dbus_timeout_get_enabled( timeout ) )
+ itg->addTimeout( timeout );
+ else
+ itg->removeTimeout( timeout );
+}
void dbusWakeupMain( void* )
{
}
+/////////////////////////////////////////////////////////////
+
+Timeout::Timeout( QObject *parent, DBusTimeout *t )
+ : QObject( parent ), m_timeout( t )
+{
+ m_timer = new QTimer( this );
+ connect( m_timer, SIGNAL(timeout()),
+ SLOT(slotTimeout()) );
+}
+
+void Timeout::slotTimeout()
+{
+ emit timeout( m_timeout );
+}
+
+void Timeout::start()
+{
+ m_timer->start( dbus_timeout_get_interval( m_timeout ) );
+}
+
Integrator::Integrator( Connection *parent )
: QObject( parent ), m_parent( parent )
{
+ m_timeouts.setAutoDelete( true );
+
dbus_connection_set_watch_functions( m_parent->connection(),
dbusAddWatch,
dbusRemoveWatch,
@@ -82,12 +143,17 @@ void Integrator::slotWrite( int fd )
Q_UNUSED( fd );
}
+void Integrator::slotTimeout( DBusTimeout *timeout )
+{
+ dbus_timeout_handle( timeout );
+}
+
void Integrator::addWatch( DBusWatch *watch )
{
if ( !dbus_watch_get_enabled( watch ) )
return;
- QtWatch *qtwatch = new QtWatch;
+ Watch *qtwatch = new Watch;
qtwatch->watch = watch;
int flags = dbus_watch_get_flags( watch );
@@ -110,7 +176,7 @@ void Integrator::removeWatch( DBusWatch *watch )
{
int key = dbus_watch_get_fd( watch );
- QtWatch *qtwatch = m_watches.take( key );
+ Watch *qtwatch = m_watches.take( key );
if ( qtwatch ) {
delete qtwatch->readSocket; qtwatch->readSocket = 0;
@@ -119,6 +185,19 @@ void Integrator::removeWatch( DBusWatch *watch )
}
}
+void Integrator::addTimeout( DBusTimeout *timeout )
+{
+ Timeout *mt = new Timeout( this, timeout );
+ m_timeouts.insert( timeout, mt );
+ connect( mt, SIGNAL(timeout(DBusTimeout*)),
+ SLOT(slotTimeout(DBusTimeout*)) );
+ mt->start();
+}
+
+void Integrator::removeTimeout( DBusTimeout *timeout )
+{
+ m_timeouts.remove( timeout );
+}
}//end namespace Internal
}//end namespace DBusQt
diff --git a/qt/integrator.h b/qt/integrator.h
index f66cce64..71336e95 100644
--- a/qt/integrator.h
+++ b/qt/integrator.h
@@ -26,18 +26,36 @@
#include <qobject.h>
#include <qintdict.h>
-#include <qptrlist.h>
+#include <qptrdict.h>
#include "dbus/dbus.h"
+class QTimer;
+
namespace DBusQt
{
class Connection;
namespace Internal
{
- struct QtWatch;
- struct DBusQtTimeout;
+ struct Watch;
+
+ class Timeout : public QObject
+ {
+ Q_OBJECT
+ public:
+ Timeout( QObject *parent, DBusTimeout *t );
+ public:
+ void start();
+ signals:
+ void timeout( DBusTimeout* );
+ protected slots:
+ void slotTimeout();
+ private:
+ QTimer *m_timer;
+ DBusTimeout *m_timeout;
+ };
+
class Integrator : public QObject
{
Q_OBJECT
@@ -50,65 +68,19 @@ namespace DBusQt
protected slots:
void slotRead( int );
void slotWrite( int );
+ void slotTimeout( DBusTimeout *timeout );
- protected:
+ public:
void addWatch( DBusWatch* );
void removeWatch( DBusWatch* );
void addTimeout( DBusTimeout* );
void removeTimeout( DBusTimeout* );
private:
- QIntDict<QtWatch> m_watches;
- QPtrList<DBusQtTimeout> m_timeouts;
+ QIntDict<Watch> m_watches;
+ QPtrDict<Timeout> m_timeouts;
Connection* m_parent;
-
- private:
- friend dbus_bool_t dbusAddWatch( DBusWatch*, void* );
- friend void dbusRemoveWatch( DBusWatch*, void* );
- friend void dbusToggleWatch( DBusWatch*, void* );
-
- friend dbus_bool_t dbusAddTimeout( DBusTimeout*, void* );
- friend void dbusRemoveTimeout( DBusTimeout*, void* );
- friend void dbusToggleTimeout( DBusTimeout*, void* );
};
-
- //////////////////////////////////////////////////////////////
- //Friends
- dbus_bool_t dbusAddWatch( DBusWatch *watch, void *data )
- {
- Integrator *con = static_cast<Integrator*>( data );
- con->addWatch( watch );
- return true;
- }
- void dbusRemoveWatch( DBusWatch *watch, void *data )
- {
- Integrator *con = static_cast<Integrator*>( data );
- con->removeWatch( watch );
- }
-
- void dbusToggleWatch( DBusWatch*, void* )
- {
- //I don't know how to handle this one right now
-//#warning "FIXME: implement"
- }
-
- dbus_bool_t dbusAddTimeout( DBusTimeout *timeout, void *data )
- {
- Integrator *con = static_cast<Integrator*>( data );
- con->addTimeout( timeout );
- return true;
- }
-
- void dbusRemoveTimeout( DBusTimeout *timeout, void *data )
- {
- Integrator *con = static_cast<Integrator*>( data );
- }
-
- void dbusToggleTimeout( DBusTimeout *timeout, void *data )
- {
- Integrator *con = static_cast<Integrator*>( data );
- }
- /////////////////////////////////////////////////////////////
}
}