dbus/qt connection.cpp,1.2,1.3 connection.h,1.3,1.4 integrator.cpp,1.1,1.2 integrator.h,1.1,1.2
Zack Rusin
zack@pdx.freedesktop.org
Mon, 24 Nov 2003 11:11:57 -0800
Update of /cvs/dbus/dbus/qt
In directory pdx:/tmp/cvs-serv14903/qt
Modified Files:
connection.cpp connection.h integrator.cpp integrator.h
Log Message:
As changelog says. Integration is pretty much there, so dbus should at least
use Qt for timeouts and watches comfortably now.
Index: connection.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/connection.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- connection.cpp 24 Nov 2003 05:21:12 -0000 1.2
+++ connection.cpp 24 Nov 2003 19:11:55 -0000 1.3
@@ -42,23 +42,16 @@
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
Index: connection.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/connection.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- connection.h 24 Nov 2003 05:21:12 -0000 1.3
+++ connection.h 24 Nov 2003 19:11:55 -0000 1.4
@@ -61,7 +61,6 @@
protected:
void init( const QString& host );
- void initDbus();
virtual void* virtual_hook( int id, void* data );
private:
friend class Internal::Integrator;
Index: integrator.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/integrator.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- integrator.cpp 24 Nov 2003 05:21:12 -0000 1.1
+++ integrator.cpp 24 Nov 2003 19:11:55 -0000 1.2
@@ -32,30 +32,91 @@
{
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 @@
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 @@
{
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::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
Index: integrator.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/integrator.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- integrator.h 24 Nov 2003 05:21:12 -0000 1.1
+++ integrator.h 24 Nov 2003 19:11:55 -0000 1.2
@@ -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 @@
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 );
- }
- /////////////////////////////////////////////////////////////
}
}