summaryrefslogtreecommitdiff
path: root/qt
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2004-04-27 05:35:01 +0000
committerZack Rusin <zack@kde.org>2004-04-27 05:35:01 +0000
commite8a46365c791a450ec71daf86e6ca921ee57f80c (patch)
tree55768b38a1036b150de24197b86618b38ca530ff /qt
parent4e243ba4b4697bdc9a4dfa312d6a092d80839941 (diff)
Committing Haralds stuff together with some of my backlog for connection.
Diffstat (limited to 'qt')
-rw-r--r--qt/connection.cpp60
-rw-r--r--qt/connection.h12
2 files changed, 53 insertions, 19 deletions
diff --git a/qt/connection.cpp b/qt/connection.cpp
index 54c4689e..de5c6278 100644
--- a/qt/connection.cpp
+++ b/qt/connection.cpp
@@ -29,30 +29,60 @@ using Internal::Integrator;
struct Connection::Private
{
+ Private( Connection *qq );
+ void setConnection( DBusConnection *c );
DBusConnection *connection;
int connectionSlot;
DBusError error;
Integrator *integrator;
int timeout;
+ Connection *q;
};
+Connection::Private::Private( Connection *qq )
+ : connection( 0 ), connectionSlot( 0 ), integrator( 0 ),
+ timeout( -1 ), q( qq )
+{
+ dbus_error_init( &error );
+}
+
+void Connection::Private::setConnection( DBusConnection *c )
+{
+ if (!c) {
+ qDebug( "error: %s, %s", error.name, error.message );
+ dbus_error_free( &error );
+ return;
+ }
+ connection = c;
+ integrator = new Integrator( c, q );
+ connect( integrator, SIGNAL(readReady()), q, SLOT(dispatchRead()) );
+}
+
+Connection::Connection( QObject *parent )
+ : QObject( parent )
+{
+ d = new Private( this );
+}
+
Connection::Connection( const QString& host, QObject *parent )
: QObject( parent )
{
- d = new Private;
+ d = new Private( this );
if ( !host.isEmpty() )
init( host );
}
+Connection::Connection(DBusBusType type, QObject* parent)
+ : QObject( parent )
+{
+ d = new Private(this);
+ d->setConnection( dbus_bus_get(type, &d->error) );
+}
+
void Connection::init( const QString& host )
{
- dbus_error_init( &d->error );
- d->timeout = -1;
- d->connection = dbus_connection_open( host.ascii(), &d->error );
- d->integrator = new Integrator( d->connection, this );
- connect( d->integrator, SIGNAL(readReady()),
- SLOT(dispatchRead()) );
+ d->setConnection( dbus_connection_open( host.ascii(), &d->error) );
//dbus_connection_allocate_data_slot( &d->connectionSlot );
//dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 );
}
@@ -96,17 +126,13 @@ DBusConnection* Connection::connection() const
Connection::Connection( DBusConnection *connection, QObject *parent )
: QObject( parent )
{
- d = new Private;
- dbus_error_init( &d->error );
- d->timeout = -1;
- d->connection = connection;
- d->integrator = new Integrator( d->connection, this );
- connect( d->integrator, SIGNAL(readReady()),
- SLOT(dispatchRead()) );
+ d = new Private(this);
+ d->setConnection(connection);
}
-void Connection::send( const Message& )
+void Connection::send( const Message &m )
{
+ dbus_connection_send(d->connection, m.message(), 0);
}
void Connection::sendWithReply( const Message& )
@@ -117,6 +143,10 @@ Message Connection::sendWithReplyAndBlock( const Message &m )
{
DBusMessage *reply;
reply = dbus_connection_send_with_reply_and_block( d->connection, m.message(), d->timeout, &d->error );
+ if (dbus_error_is_set(&d->error)) {
+ qDebug("error: %s, %s", d->error.name, d->error.message);
+ dbus_error_free(&d->error);
+ }
return Message( reply );
}
diff --git a/qt/connection.h b/qt/connection.h
index fd954b64..285fa66b 100644
--- a/qt/connection.h
+++ b/qt/connection.h
@@ -39,8 +39,10 @@ namespace DBusQt {
{
Q_OBJECT
public:
- Connection( const QString& host = QString::null,
- QObject* parent = 0);
+ Connection( QObject *parent =0 );
+ Connection( const QString& host,
+ QObject *parent = 0 );
+ Connection( DBusBusType type, QObject* parent = 0 );
bool isConnected() const;
bool isAuthenticated() const;
@@ -62,11 +64,13 @@ namespace DBusQt {
protected:
void init( const QString& host );
- virtual void* virtual_hook( int id, void* data );
+ virtual void *virtual_hook( int id, void *data );
+
private:
friend class Internal::Integrator;
- DBusConnection* connection() const;
+ DBusConnection *connection() const;
Connection( DBusConnection *connection, QObject *parent );
+
private:
struct Private;
Private *d;