dbus/qt message.h,1.1,1.2 message.cpp,1.1,1.2

Zack Rusin zack@pdx.freedesktop.org
Sun, 23 Nov 2003 00:02:40 -0800


Update of /cvs/dbus/dbus/qt
In directory pdx:/tmp/cvs-serv1900

Modified Files:
	message.h message.cpp 
Log Message:
thanksgiving break, lets start working on those bindings.


Index: message.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/message.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- message.h	11 Feb 2003 21:14:16 -0000	1.1
+++ message.h	23 Nov 2003 08:02:38 -0000	1.2
@@ -23,7 +23,8 @@
 
 #include <qvariant.h>
 #include <qstring.h>
-#include <dbus.h>
+
+#include "dbus/dbus.h"
 
 namespace DBus {
 
@@ -52,20 +53,43 @@
       IteratorData *d;
     };
 
-    Message( const QString& service, const QString& name );
-    Message( const QString& name,
-             const Message& replayingTo );
-    Message( const Message& other );
+    Message( int messageType );
+    Message( const QString& service, const QString& path,
+             const QString& interface, const QString& method );
+    Message( const Message& replayingTo );
+    Message( const QString& path, const QString& interface,
+             const QString& name );
+    Message( const Message& replayingTo, const QString& errorName,
+             const QString& errorMessage );
+
+    Message operator=( const Message& other );
 
     virtual ~Message();
 
+    int type() const;
+
+    void setPath( const QString& );
+    QString path() const;
+
+    void setInterface( const QString& );
+    QString interface() const;
+
+    void setMember( const QString& );
+    QString member() const;
+
+    void setErrorName( const QString& );
+    QString errorName() const;
+
+    void setDestination( const QString& );
+    QString destination() const;
+
     bool    setSender( const QString& sender );
-    void    setError( bool error );
+    QString    sender() const;
+
+    QString signature() const;
 
     QString name() const;
     QString service() const;
-    QString sender() const;
-    bool    isError() const;
 
     virtual void append( const QVariant& var );
 
@@ -76,6 +100,25 @@
 
     QVariant at( int i );
 
+
+  public:
+    Message& operator<<( bool );
+    Message& operator<<( Q_INT8 );
+    Message& operator<<( Q_INT32 );
+    Message& operator<<( Q_UINT32 );
+    Message& operator<<( Q_INT64 );
+    Message& operator<<( Q_UINT64 );
+    Message& operator<<( double );
+    Message& operator<<( const QString& );
+    Message& operator<<( const QVariant& );
+    //Message& operator<<();
+    //Message& operator<<();
+    //Message& operator<<();
+    //Message& operator<<();
+    //Message& operator<<();
+    //Message& operator<<();
+    //Message& operator<<();
+
   protected:
     DBusMessage* message() const;
 

Index: message.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/message.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- message.cpp	11 Feb 2003 21:14:16 -0000	1.1
+++ message.cpp	23 Nov 2003 08:02:38 -0000	1.2
@@ -22,7 +22,6 @@
  */
 #include "message.h"
 
-#include <kdebug.h>
 
 namespace DBus {
 
@@ -48,7 +47,7 @@
 Message::iterator::iterator( DBusMessage* msg)
 {
   d = new IteratorData;
-  d->iter = dbus_message_get_fields_iter( msg );
+  dbus_message_iter_init( msg, d->iter );
   d->end = false;
 }
 
@@ -59,7 +58,6 @@
 Message::iterator::iterator( const iterator& itr )
 {
   d = new IteratorData;
-  dbus_message_iter_ref( itr.d->iter );
   d->iter = itr.d->iter;
   d->var  = itr.d->var;
   d->end  = itr.d->end;
@@ -70,7 +68,6 @@
  */
 Message::iterator::~iterator()
 {
-  dbus_message_iter_unref( d->iter );
   delete d; d=0;
 }
 
@@ -82,13 +79,10 @@
 Message::iterator&
 Message::iterator::operator=( const iterator& itr )
 {
-  //in case we'll ever go fot exception safety
-  dbus_message_iter_ref( itr.d->iter );
   IteratorData *tmp = new IteratorData;
   tmp->iter = itr.d->iter;
   tmp->var  = itr.d->var;
   tmp->end  = itr.d->end;
-  dbus_message_iter_unref( d->iter );
   delete d; d=tmp;
   return *this;
 }
@@ -181,7 +175,7 @@
 void
 Message::iterator::fillVar()
 {
-  switch ( dbus_message_iter_get_field_type( d->iter ) ) {
+  switch ( dbus_message_iter_get_arg_type( d->iter ) ) {
   case DBUS_TYPE_INT32:
     d->var = QVariant( dbus_message_iter_get_int32( d->iter ) );
     break;
@@ -194,24 +188,8 @@
   case DBUS_TYPE_STRING:
     d->var = QVariant( QString(dbus_message_iter_get_string( d->iter )) );
     break;
-  case DBUS_TYPE_BYTE_ARRAY:
-    {
-      QByteArray a;
-      int len;
-      char *ar;
-      ar = reinterpret_cast<char*>( dbus_message_iter_get_byte_array( d->iter, &len ) );
-      a.setRawData( ar, len );
-      QDataStream stream( a, IO_ReadOnly );
-      stream >> d->var;
-      a.resetRawData( ar, len );
-    }
-    break;
-  case DBUS_TYPE_STRING_ARRAY:
-#warning "String array not implemented"
-    //d->var = QVariant( dbus_message_iter_get_string_array );
-    break;
   default:
-    kdWarning()<<k_funcinfo<<" Serious problem!! "<<endl;
+    qDebug( "not implemented" );
     d->var = QVariant();
     break;
   }
@@ -232,14 +210,25 @@
 };
 
 /**
+ *
+ */
+Message::Message( int messageType )
+{
+  d = new MessagePrivate;
+  d->msg = dbus_message_new( messageType );
+}
+
+/**
  * Constructs a new Message with the given service and name.
  * @param service service service that the message should be sent to
  * @param name name of the message
  */
-Message::Message( const QString& service, const QString& name )
+Message::Message( const QString& service, const QString& path,
+                  const QString& interface, const QString& method )
 {
   d = new MessagePrivate;
-  d->msg = dbus_message_new( service.latin1(), name.latin1() );
+  d->msg = dbus_message_new_method_call( service.latin1(), path.latin1(),
+                                         interface.latin1(), method.latin1() );
 }
 
 /**
@@ -249,22 +238,32 @@
  * @param replayingTo original_message the message which the created
  * message is a reply to.
  */
-Message::Message( const QString& name, const Message& replayingTo )
+Message::Message( const Message& replayingTo )
 {
   d = new MessagePrivate;
-  d->msg = dbus_message_new_reply( name.latin1(), replayingTo );
+  d->msg = dbus_message_new_method_return( replayingTo.d->msg );
 }
 
-/**
- * Creates a message just like @p other
- * @param other the copied message
- */
-Message::Message( const Message& other )
+Message:: Message( const QString& path, const QString& interface,
+                   const QString& name )
 {
   d = new MessagePrivate;
-  d->msg = dbus_message_new_from_message( other );
+  d->msg = dbus_message_new_signal( path.ascii(), interface.ascii(),
+                                    name.ascii() );
 }
 
+Message::Message( const Message& replayingTo, const QString& errorName,
+                  const QString& errorMessage )
+{
+  d = new MessagePrivate;
+  d->msg = dbus_message_new_error( replayingTo.d->msg, errorName.utf8(),
+                                   errorMessage.utf8() );
+}
+
+Message Message::operator=( const Message& other )
+{
+  //FIXME: ref the other.d->msg instead of copying it?
+}
 /**
  * Destructs message.
  */
@@ -274,46 +273,70 @@
   delete d; d=0;
 }
 
-/**
- * Sets the message sender.
- * @param sender the sender
- * @return false if unsuccessful
- */
-bool
-Message::setSender( const QString& sender )
+int Message::type() const
 {
-  return dbus_message_set_sender( d->msg, sender.latin1() );
+  return dbus_message_get_type( d->msg );
 }
 
-/**
- * Sets a flag indicating that the message is an error reply
- * message, i.e. an "exception" rather than a normal response.
- * @param error true if this is an error message.
- */
-void
-Message::setError( bool error )
+void Message::setPath( const QString& path )
 {
-  return dbus_message_set_is_error( d->msg, error );
+  dbus_message_set_path( d->msg, path.ascii() );
 }
 
-/**
- * Returns name of this message.
- * @return name
- */
-QString
-Message::name() const
+QString Message::path() const
 {
-  return dbus_message_get_name( d->msg );
+  return dbus_message_get_path( d->msg );
+}
+
+void Message::setInterface( const QString& iface )
+{
+  dbus_message_set_interface( d->msg, iface.ascii() );
+}
+
+QString Message::interface() const
+{
+  return dbus_message_get_interface( d->msg );
+}
+
+void Message::setMember( const QString& member )
+{
+  dbus_message_set_member( d->msg, member.ascii() );
+}
+
+QString Message::member() const
+{
+  return dbus_message_get_member( d->msg );
+}
+
+void Message::setErrorName( const QString& err )
+{
+  dbus_message_set_error_name( d->msg, err );
+}
+
+QString Message::errorName() const
+{
+  return dbus_message_get_error_name( d->msg );
+}
+
+void Message::setDestination( const QString& dest )
+{
+  dbus_message_set_destination( d->msg, dest );
+}
+
+QString Message::destination() const
+{
+  return dbus_message_get_destination( d->msg );
 }
 
 /**
- * Returns service associated with this message.
- * @return service
+ * Sets the message sender.
+ * @param sender the sender
+ * @return false if unsuccessful
  */
-QString
-Message::service() const
+bool
+Message::setSender( const QString& sender )
 {
-  return dbus_message_get_service( d->msg );
+  return dbus_message_set_sender( d->msg, sender.latin1() );
 }
 
 /**
@@ -326,14 +349,9 @@
   return dbus_message_get_sender( d->msg );
 }
 
-/**
- * Checks whether this message is an error indicating message.
- * @return true if this is an error message
- */
-bool
-Message::isError() const
+QString Message::signature() const
 {
-  return dbus_message_get_is_error( d->msg );
+  return dbus_message_get_signature( d->msg );
 }
 
 /**