dbus/qt connection.cpp,1.5,1.6 connection.h,1.6,1.7 message.cpp,1.6,1.7 message.h,1.6,1.7 server.cpp,1.2,1.3
Zack Rusin
zack@pdx.freedesktop.org
Sun, 25 Jan 2004 23:46:57 -0800
Update of /cvs/dbus/dbus/qt
In directory pdx:/tmp/cvs-serv19854
Modified Files:
connection.cpp connection.h message.cpp message.h server.cpp
Log Message:
Slightily modified patch from Alex (blarf). I'll have to rething the access
to dbus internals from the wrappers.
Index: connection.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/connection.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- connection.cpp 2 Dec 2003 10:44:22 -0000 1.5
+++ connection.cpp 26 Jan 2004 07:46:55 -0000 1.6
@@ -33,9 +33,11 @@
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 @@
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 @@
: 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"
Index: connection.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/connection.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- connection.h 2 Dec 2003 10:44:22 -0000 1.6
+++ connection.h 26 Jan 2004 07:46:55 -0000 1.7
@@ -39,7 +39,8 @@
{
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 @@
void flush();
void send( const Message& );
void sendWithReply( const Message& );
- void sendWithReplyAndBlock( const Message& );
+ Message sendWithReplyAndBlock( const Message& );
protected slots:
void dispatchRead();
Index: message.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/message.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- message.cpp 2 Dec 2003 10:44:22 -0000 1.6
+++ message.cpp 26 Jan 2004 07:46:55 -0000 1.7
@@ -29,6 +29,7 @@
DBusMessageIter *iter;
QVariant var;
bool end;
+ DBusMessage *mesg;
};
/**
@@ -44,10 +45,16 @@
* 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()
{
+ free( d->iter );
delete d; d=0;
}
@@ -169,6 +177,33 @@
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 @@
{
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 @@
DBusMessage *msg;
};
+Message::Message( DBusMessage *m )
+{
+ d = new Private;
+ d->msg = m;
+}
+
/**
*
*/
@@ -269,7 +342,9 @@
*/
Message::~Message()
{
- dbus_message_unref( d->msg );
+ if ( d->msg ) {
+ dbus_message_unref( d->msg );
+ }
delete d; d=0;
}
Index: message.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/message.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- message.h 2 Dec 2003 10:44:22 -0000 1.6
+++ message.h 26 Jan 2004 07:46:55 -0000 1.7
@@ -25,6 +25,7 @@
#include <qvariant.h>
#include <qstring.h>
+#include <qstringlist.h>
#include "dbus/dbus.h"
@@ -36,7 +37,7 @@
class iterator {
public:
iterator();
- iterator( const iterator & );
+ iterator( const iterator& );
iterator( DBusMessage* msg );
~iterator();
@@ -49,13 +50,15 @@
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 @@
//Message& operator<<();
protected:
+ friend class Connection;
DBusMessage* message() const;
private:
Index: server.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/server.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- server.cpp 2 Dec 2003 10:44:22 -0000 1.2
+++ server.cpp 26 Jan 2004 07:46:55 -0000 1.3
@@ -58,6 +58,11 @@
return dbus_server_get_is_connected( d->server );
}
+void Server::disconnect()
+{
+ dbus_server_disconnect( d->server );
+}
+
QString Server::address() const
{
//FIXME: leak?