diff options
author | Zack Rusin <zack@kde.org> | 2004-01-26 07:46:55 +0000 |
---|---|---|
committer | Zack Rusin <zack@kde.org> | 2004-01-26 07:46:55 +0000 |
commit | ada66f2de9e6b512430f6390c8bf69b0d46dcfc4 (patch) | |
tree | fb13541bbedb0affe11027ad18aa0dc65580b454 /qt | |
parent | ebfe2f74c588e225c1da6c8cb608c69c7cbc6350 (diff) |
Slightily modified patch from Alex (blarf). I'll have to rething the access
to dbus internals from the wrappers.
Diffstat (limited to 'qt')
-rw-r--r-- | qt/connection.cpp | 22 | ||||
-rw-r--r-- | qt/connection.h | 5 | ||||
-rw-r--r-- | qt/message.cpp | 95 | ||||
-rw-r--r-- | qt/message.h | 8 | ||||
-rw-r--r-- | qt/server.cpp | 5 |
5 files changed, 120 insertions, 15 deletions
diff --git a/qt/connection.cpp b/qt/connection.cpp index 0dc7e33..58bfeb7 100644 --- a/qt/connection.cpp +++ b/qt/connection.cpp @@ -33,9 +33,11 @@ struct Connection::Private int connectionSlot; DBusError error; Integrator *integrator; + int timeout; }; -Connection::Connection( const QString& host ) +Connection::Connection( const QString& host, QObject *parent ) + : QObject( parent ) { d = new Private; @@ -46,6 +48,7 @@ Connection::Connection( const QString& host ) 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()), @@ -94,12 +97,29 @@ 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()) ); } +void Connection::send( const Message& ) +{ +} + +void Connection::sendWithReply( const Message& ) +{ +} + +Message Connection::sendWithReplyAndBlock( const Message &m ) +{ + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block( d->connection, m.message(), d->timeout, &d->error ); + return Message( reply ); +} + ///////////////////////////////////////////////////////// #include "connection.moc" diff --git a/qt/connection.h b/qt/connection.h index 2b9a05c..fd954b6 100644 --- a/qt/connection.h +++ b/qt/connection.h @@ -39,7 +39,8 @@ namespace DBusQt { { Q_OBJECT public: - Connection( const QString& host = QString::null ); + Connection( const QString& host = QString::null, + QObject* parent = 0); bool isConnected() const; bool isAuthenticated() const; @@ -54,7 +55,7 @@ namespace DBusQt { void flush(); void send( const Message& ); void sendWithReply( const Message& ); - void sendWithReplyAndBlock( const Message& ); + Message sendWithReplyAndBlock( const Message& ); protected slots: void dispatchRead(); diff --git a/qt/message.cpp b/qt/message.cpp index 7814955..55d4e78 100644 --- a/qt/message.cpp +++ b/qt/message.cpp @@ -29,6 +29,7 @@ struct Message::iterator::IteratorData { DBusMessageIter *iter; QVariant var; bool end; + DBusMessage *mesg; }; /** @@ -44,10 +45,16 @@ Message::iterator::iterator() * Constructs iterator for the message. * @param msg message whose fields we want to iterate */ -Message::iterator::iterator( DBusMessage* msg) +Message::iterator::iterator( DBusMessage* msg ) { d = new IteratorData; - dbus_message_iter_init( msg, d->iter ); + d->mesg = msg; + d->iter = static_cast<DBusMessageIter *>( malloc( sizeof(DBusMessageIter) ) ); + dbus_message_iter_init( d->mesg, d->iter ); + if ( !d->iter ) { + qDebug("No iterator??"); + } + fillVar(); d->end = false; } @@ -68,6 +75,7 @@ Message::iterator::iterator( const iterator& itr ) */ Message::iterator::~iterator() { + free( d->iter ); delete d; d=0; } @@ -169,6 +177,33 @@ Message::iterator::operator!=( const iterator& it ) return !operator==( it ); } +QVariant Message::iterator::marshallBaseType( DBusMessageIter* i ) +{ + QVariant ret; + switch (dbus_message_iter_get_arg_type(i)) { + case DBUS_TYPE_INT32: + ret = QVariant( dbus_message_iter_get_int32(i) ); + break; + case DBUS_TYPE_UINT32: + ret = QVariant( dbus_message_iter_get_uint32(i) ); + break; + case DBUS_TYPE_DOUBLE: + ret = QVariant( dbus_message_iter_get_double(i) ); + break; + case DBUS_TYPE_STRING: + { + char *str = dbus_message_iter_get_string(i); + ret = QVariant( QString::fromLatin1(str) ); + dbus_free(str); + } + break; + default: + ret = QVariant(); + break; + } + return ret; +} + /** * Fills QVariant based on what current DBusMessageIter helds. */ @@ -177,17 +212,49 @@ Message::iterator::fillVar() { switch ( dbus_message_iter_get_arg_type( d->iter ) ) { case DBUS_TYPE_INT32: - d->var = QVariant( dbus_message_iter_get_int32( d->iter ) ); - break; case DBUS_TYPE_UINT32: - d->var = QVariant( dbus_message_iter_get_uint32( d->iter ) ); - break; case DBUS_TYPE_DOUBLE: - d->var = QVariant( dbus_message_iter_get_double( d->iter ) ); - break; case DBUS_TYPE_STRING: - d->var = QVariant( QString(dbus_message_iter_get_string( d->iter )) ); + d->var = marshallBaseType( d->iter ); + break; + case DBUS_TYPE_ARRAY: { + switch ( dbus_message_iter_get_array_type( d->iter ) ) { + case DBUS_TYPE_STRING: { + QStringList tempList; + int count; + char** charArray; + dbus_message_iter_get_string_array( d->iter, &charArray, &count ); + for ( int i=0; i < count; i++ ) { + tempList.append( QString( charArray[i] ) ); + } + d->var = QVariant( tempList ); + dbus_free( charArray ); + break; + } + default: + qDebug( "Array of type not implemented" ); + d->var = QVariant(); + break; + } + break; + } + case DBUS_TYPE_DICT: { + qDebug( "Got a hash!" ); + QMap<QString, QVariant> tempMap; + DBusMessageIter dictIter; + dbus_message_iter_init_dict_iterator( d->iter, &dictIter ); + do { + char *key = dbus_message_iter_get_dict_key( &dictIter ); + tempMap[key] = marshallBaseType( &dictIter ); + dbus_free( key ); + dbus_message_iter_next( &dictIter ); + } while( dbus_message_iter_has_next( &dictIter ) ); + d->var = QVariant( tempMap ); break; + qDebug( "Hash/Dict type not implemented" ); + d->var = QVariant(); + break; + } default: qDebug( "not implemented" ); d->var = QVariant(); @@ -209,6 +276,12 @@ struct Message::Private { DBusMessage *msg; }; +Message::Message( DBusMessage *m ) +{ + d = new Private; + d->msg = m; +} + /** * */ @@ -269,7 +342,9 @@ Message Message::operator=( const Message& other ) */ Message::~Message() { - dbus_message_unref( d->msg ); + if ( d->msg ) { + dbus_message_unref( d->msg ); + } delete d; d=0; } diff --git a/qt/message.h b/qt/message.h index a74a77a..2524a7a 100644 --- a/qt/message.h +++ b/qt/message.h @@ -25,6 +25,7 @@ #include <qvariant.h> #include <qstring.h> +#include <qstringlist.h> #include "dbus/dbus.h" @@ -36,7 +37,7 @@ namespace DBusQt { class iterator { public: iterator(); - iterator( const iterator & ); + iterator( const iterator& ); iterator( DBusMessage* msg ); ~iterator(); @@ -49,13 +50,15 @@ namespace DBusQt { bool operator!=( const iterator& it ); QVariant var() const; - private: + protected: + QVariant marshallBaseType( DBusMessageIter* i ); void fillVar(); struct IteratorData; IteratorData *d; }; Message( int messageType ); + Message( DBusMessage * );//hide this one from the public implementation Message( const QString& service, const QString& path, const QString& interface, const QString& method ); Message( const Message& replayingTo ); @@ -115,6 +118,7 @@ namespace DBusQt { //Message& operator<<(); protected: + friend class Connection; DBusMessage* message() const; private: diff --git a/qt/server.cpp b/qt/server.cpp index fe2edf8..5d6c3ba 100644 --- a/qt/server.cpp +++ b/qt/server.cpp @@ -58,6 +58,11 @@ bool Server::isConnected() const return dbus_server_get_is_connected( d->server ); } +void Server::disconnect() +{ + dbus_server_disconnect( d->server ); +} + QString Server::address() const { //FIXME: leak? |