Qt 4.8
Public Functions | Public Variables | List of all members
QDBusMarshaller Class Reference

#include <qdbusargument_p.h>

Inheritance diagram for QDBusMarshaller:
QDBusArgumentPrivate

Public Functions

void append (uchar arg)
 
void append (bool arg)
 
void append (short arg)
 
void append (ushort arg)
 
void append (int arg)
 
void append (uint arg)
 
void append (qlonglong arg)
 
void append (qulonglong arg)
 
void append (double arg)
 
void append (const QString &arg)
 
void append (const QDBusObjectPath &arg)
 
void append (const QDBusSignature &arg)
 
void append (const QDBusUnixFileDescriptor &arg)
 
void append (const QStringList &arg)
 
void append (const QByteArray &arg)
 
bool append (const QDBusVariant &arg)
 
bool appendCrossMarshalling (QDBusDemarshaller *arg)
 
bool appendRegisteredType (const QVariant &arg)
 
bool appendVariantInternal (const QVariant &arg)
 
QDBusMarshallerbeginArray (int id)
 
QDBusMarshallerbeginCommon (int code, const char *signature)
 
QDBusMarshallerbeginMap (int kid, int vid)
 
QDBusMarshallerbeginMapEntry ()
 
QDBusMarshallerbeginStructure ()
 
void close ()
 
QString currentSignature ()
 
QDBusMarshallerendArray ()
 
QDBusMarshallerendCommon ()
 
QDBusMarshallerendMap ()
 
QDBusMarshallerendMapEntry ()
 
QDBusMarshallerendStructure ()
 
void error (const QString &message)
 
void open (QDBusMarshaller &sub, int code, const char *signature)
 
 QDBusMarshaller (int flags)
 
 ~QDBusMarshaller ()
 
- Public Functions inherited from QDBusArgumentPrivate
QDBusDemarshallerdemarshaller ()
 
QDBusMarshallermarshaller ()
 
 QDBusArgumentPrivate (int flags=0)
 
 ~QDBusArgumentPrivate ()
 

Public Variables

QByteArrayba
 
char closeCode
 
QString errorString
 
DBusMessageIter iterator
 
bool ok
 
QDBusMarshallerparent
 
- Public Variables inherited from QDBusArgumentPrivate
int capabilities
 
enum QDBusArgumentPrivate::Direction direction
 
DBusMessage * message
 
QAtomicInt ref
 

Additional Inherited Members

- Public Types inherited from QDBusArgumentPrivate
enum  Direction { Marshalling, Demarshalling }
 
- Static Public Functions inherited from QDBusArgumentPrivate
static bool checkRead (QDBusArgumentPrivate *d)
 
static bool checkReadAndDetach (QDBusArgumentPrivate *&d)
 
static bool checkWrite (QDBusArgumentPrivate *&d)
 
static QDBusArgument create (QDBusArgumentPrivate *d)
 
static QByteArray createSignature (int id)
 
static QDBusArgumentPrivated (QDBusArgument &q)
 

Detailed Description

Definition at line 105 of file qdbusargument_p.h.

Constructors and Destructors

◆ QDBusMarshaller()

QDBusMarshaller::QDBusMarshaller ( int  flags)
inline

Definition at line 108 of file qdbusargument_p.h.

Referenced by beginCommon().

108  : QDBusArgumentPrivate(flags), parent(0), ba(0), closeCode(0), ok(true)
109  { direction = Marshalling; }
QByteArray * ba
QDBusMarshaller * parent
enum QDBusArgumentPrivate::Direction direction
QDBusArgumentPrivate(int flags=0)

◆ ~QDBusMarshaller()

QDBusMarshaller::~QDBusMarshaller ( )

Definition at line 59 of file qdbusmarshaller.cpp.

60 {
61  close();
62 }

Functions

◆ append() [1/16]

void QDBusMarshaller::append ( uchar  arg)
inline

Definition at line 71 of file qdbusmarshaller.cpp.

Referenced by append(), appendVariantInternal(), QDBusArgument::operator<<(), and QDBusMessagePrivate::toDBusMessage().

72 {
73  qIterAppend(&iterator, ba, DBUS_TYPE_BYTE, &arg);
74 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [2/16]

void QDBusMarshaller::append ( bool  arg)
inline

Definition at line 76 of file qdbusmarshaller.cpp.

77 {
78  dbus_bool_t cast = arg;
79  qIterAppend(&iterator, ba, DBUS_TYPE_BOOLEAN, &cast);
80 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [3/16]

void QDBusMarshaller::append ( short  arg)
inline

Definition at line 82 of file qdbusmarshaller.cpp.

83 {
84  qIterAppend(&iterator, ba, DBUS_TYPE_INT16, &arg);
85 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [4/16]

void QDBusMarshaller::append ( ushort  arg)
inline

Definition at line 87 of file qdbusmarshaller.cpp.

88 {
89  qIterAppend(&iterator, ba, DBUS_TYPE_UINT16, &arg);
90 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [5/16]

void QDBusMarshaller::append ( int  arg)
inline

Definition at line 92 of file qdbusmarshaller.cpp.

93 {
94  qIterAppend(&iterator, ba, DBUS_TYPE_INT32, &arg);
95 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [6/16]

void QDBusMarshaller::append ( uint  arg)
inline

Definition at line 97 of file qdbusmarshaller.cpp.

98 {
99  qIterAppend(&iterator, ba, DBUS_TYPE_UINT32, &arg);
100 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [7/16]

void QDBusMarshaller::append ( qlonglong  arg)
inline

Definition at line 102 of file qdbusmarshaller.cpp.

103 {
104  qIterAppend(&iterator, ba, DBUS_TYPE_INT64, &arg);
105 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [8/16]

void QDBusMarshaller::append ( qulonglong  arg)
inline

Definition at line 107 of file qdbusmarshaller.cpp.

108 {
109  qIterAppend(&iterator, ba, DBUS_TYPE_UINT64, &arg);
110 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [9/16]

void QDBusMarshaller::append ( double  arg)
inline

Definition at line 112 of file qdbusmarshaller.cpp.

113 {
114  qIterAppend(&iterator, ba, DBUS_TYPE_DOUBLE, &arg);
115 }
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba

◆ append() [10/16]

void QDBusMarshaller::append ( const QString arg)

Definition at line 117 of file qdbusmarshaller.cpp.

118 {
119  QByteArray data = arg.toUtf8();
120  const char *cdata = data.constData();
121  qIterAppend(&iterator, ba, DBUS_TYPE_STRING, &cdata);
122 }
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
static const char * data(const QByteArray &arr)
QByteArray * ba
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ append() [11/16]

void QDBusMarshaller::append ( const QDBusObjectPath arg)
inline

Definition at line 124 of file qdbusmarshaller.cpp.

125 {
126  QByteArray data = arg.path().toUtf8();
127  if (!ba && data.isEmpty())
128  error(QLatin1String("Invalid object path passed in arguments"));
129  const char *cdata = data.constData();
130  qIterAppend(&iterator, ba, DBUS_TYPE_OBJECT_PATH, &cdata);
131 }
void error(const QString &message)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
static const char * data(const QByteArray &arr)
QString path() const
Returns this object path.
QByteArray * ba
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ append() [12/16]

void QDBusMarshaller::append ( const QDBusSignature arg)
inline

Definition at line 133 of file qdbusmarshaller.cpp.

134 {
135  QByteArray data = arg.signature().toUtf8();
136  if (!ba && data.isEmpty())
137  error(QLatin1String("Invalid signature passed in arguments"));
138  const char *cdata = data.constData();
139  qIterAppend(&iterator, ba, DBUS_TYPE_SIGNATURE, &cdata);
140 }
void error(const QString &message)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
static const char * data(const QByteArray &arr)
QByteArray * ba
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QString signature() const
Returns this signature.

◆ append() [13/16]

void QDBusMarshaller::append ( const QDBusUnixFileDescriptor arg)
inline

Definition at line 142 of file qdbusmarshaller.cpp.

143 {
144  int fd = arg.fileDescriptor();
145  if (!ba && fd == -1) {
146  error(QLatin1String("Invalid file descriptor passed in arguments"));
147  } else {
149  }
150 }
void error(const QString &message)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define DBUS_TYPE_UNIX_FD
DBusMessageIter iterator
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray * ba
int fileDescriptor() const
Returns the Unix file descriptor contained by this QDBusUnixFileDescriptor object.

◆ append() [14/16]

void QDBusMarshaller::append ( const QStringList arg)
inline

Definition at line 210 of file qdbusmarshaller.cpp.

211 {
212  if (ba) {
213  *ba += DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
214  return;
215  }
216 
218  open(sub, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING);
221  for ( ; it != end; ++it)
222  sub.append(*it);
223  // don't call sub.close(): it auto-closes
224 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QByteArray * ba
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
void open(QDBusMarshaller &sub, int code, const char *signature)
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ append() [15/16]

void QDBusMarshaller::append ( const QByteArray arg)
inline

Definition at line 152 of file qdbusmarshaller.cpp.

153 {
154  if (ba) {
155  *ba += DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
156  return;
157  }
158 
159  const char* cdata = arg.constData();
160  DBusMessageIter subiterator;
161  q_dbus_message_iter_open_container(&iterator, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING,
162  &subiterator);
163  q_dbus_message_iter_append_fixed_array(&subiterator, DBUS_TYPE_BYTE, &cdata, arg.length());
164  q_dbus_message_iter_close_container(&iterator, &subiterator);
165 }
DBusMessageIter iterator
QByteArray * ba
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ append() [16/16]

bool QDBusMarshaller::append ( const QDBusVariant arg)
inline

Definition at line 167 of file qdbusmarshaller.cpp.

168 {
169  if (ba) {
170  *ba += DBUS_TYPE_VARIANT_AS_STRING;
171  return true;
172  }
173 
174  const QVariant &value = arg.variant();
175  QVariant::Type id = QVariant::Type(value.userType());
176  if (id == QVariant::Invalid) {
177  qWarning("QDBusMarshaller: cannot add a null QDBusVariant");
178  error(QLatin1String("Variant containing QVariant::Invalid passed in arguments"));
179  return false;
180  }
181 
182  QByteArray tmpSignature;
183  const char *signature = 0;
184  if (int(id) == QDBusMetaTypeId::argument) {
185  // take the signature from the QDBusArgument object we're marshalling
186  tmpSignature =
188  signature = tmpSignature.constData();
189  } else {
190  // take the signatuer from the metatype we're marshalling
191  signature = QDBusMetaType::typeToSignature(id);
192  }
193  if (!signature) {
194  qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
195  "Use qDBusRegisterMetaType to register it",
196  QVariant::typeToName( id ), id);
197  error(QString::fromLatin1("Unregistered type %1 passed in arguments")
199  return false;
200  }
201 
203  open(sub, DBUS_TYPE_VARIANT, signature);
204  bool isOk = sub.appendVariantInternal(value);
205  // don't call sub.close(): it auto-closes
206 
207  return isOk;
208 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void error(const QString &message)
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
Q_CORE_EXPORT void qWarning(const char *,...)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QByteArray * ba
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QVariant variant() const
Returns this D-Bus variant as a QVariant object.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void open(QDBusMarshaller &sub, int code, const char *signature)
static int argument
QString currentSignature()

◆ appendCrossMarshalling()

bool QDBusMarshaller::appendCrossMarshalling ( QDBusDemarshaller arg)

Definition at line 511 of file qdbusmarshaller.cpp.

Referenced by appendCrossMarshalling(), and appendVariantInternal().

512 {
513  int code = q_dbus_message_iter_get_arg_type(&demarshaller->iterator);
514  if (QDBusUtil::isValidBasicType(code)) {
515  // easy: just append
516  // do exactly like the D-BUS docs suggest
517  // (see apidocs for q_dbus_message_iter_get_basic)
518 
519  qlonglong value;
520  q_dbus_message_iter_get_basic(&demarshaller->iterator, &value);
521  q_dbus_message_iter_next(&demarshaller->iterator);
522  q_dbus_message_iter_append_basic(&iterator, code, &value);
523  return true;
524  }
525 
526  if (code == DBUS_TYPE_ARRAY) {
527  int element = q_dbus_message_iter_get_element_type(&demarshaller->iterator);
528  if (QDBusUtil::isValidFixedType(element) && element != DBUS_TYPE_UNIX_FD) {
529  // another optimization: fixed size arrays
530  // code is exactly like QDBusDemarshaller::toByteArray
531  DBusMessageIter sub;
532  q_dbus_message_iter_recurse(&demarshaller->iterator, &sub);
533  q_dbus_message_iter_next(&demarshaller->iterator);
534  int len;
535  void* data;
536  q_dbus_message_iter_get_fixed_array(&sub,&data,&len);
537 
538  char signature[2] = { char(element), 0 };
539  q_dbus_message_iter_open_container(&iterator, DBUS_TYPE_ARRAY, signature, &sub);
540  q_dbus_message_iter_append_fixed_array(&sub, element, &data, len);
541  q_dbus_message_iter_close_container(&iterator, &sub);
542 
543  return true;
544  }
545  }
546 
547  // We have to recurse
549 
550  QDBusMarshaller mrecursed(capabilities); // create on the stack makes it autoclose
551  QByteArray subSignature;
552  const char *sig = 0;
553  if (code == DBUS_TYPE_VARIANT || code == DBUS_TYPE_ARRAY) {
554  subSignature = drecursed->currentSignature().toLatin1();
555  if (!subSignature.isEmpty())
556  sig = subSignature.constData();
557  }
558  open(mrecursed, code, sig);
559 
560  while (!drecursed->atEnd()) {
561  if (!mrecursed.appendCrossMarshalling(drecursed)) {
562  delete drecursed;
563  return false;
564  }
565  }
566 
567  delete drecursed;
568  return true;
569 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define DBUS_TYPE_UNIX_FD
QDBusDemarshaller * demarshaller()
DBusMessageIter iterator
static const char * data(const QByteArray &arr)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
bool isValidFixedType(int c)
Returns true if c is a valid, fixed D-Bus type.
Definition: qdbusutil.cpp:554
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isValidBasicType(int c)
Returns true if c is a valid, basic D-Bus type.
Definition: qdbusutil.cpp:542
DBusMessageIter iterator
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void open(QDBusMarshaller &sub, int code, const char *signature)
qint64 qlonglong
Definition: qglobal.h:951
QDBusDemarshaller * beginCommon()

◆ appendRegisteredType()

bool QDBusMarshaller::appendRegisteredType ( const QVariant arg)

Definition at line 504 of file qdbusmarshaller.cpp.

Referenced by appendVariantInternal().

505 {
506  ref.ref(); // reference up
508  return QDBusMetaType::marshall(self, arg.userType(), arg.constData());
509 }
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
static QDBusArgument create(QDBusArgumentPrivate *d)
bool ref()
Atomically increments the value of this QAtomicInt.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
const void * constData() const
Definition: qvariant.cpp:3065
static bool marshall(QDBusArgument &, int id, const void *data)
Executes the marshalling of type id (whose data is contained in data) to the D-Bus marshalling argume...

◆ appendVariantInternal()

bool QDBusMarshaller::appendVariantInternal ( const QVariant arg)

Definition at line 361 of file qdbusmarshaller.cpp.

Referenced by append(), QDBusArgument::appendVariant(), and QDBusMessagePrivate::toDBusMessage().

362 {
363  int id = arg.userType();
364  if (id == QVariant::Invalid) {
365  qWarning("QDBusMarshaller: cannot add an invalid QVariant");
366  error(QLatin1String("Variant containing QVariant::Invalid passed in arguments"));
367  return false;
368  }
369 
370  // intercept QDBusArgument parameters here
371  if (id == QDBusMetaTypeId::argument) {
372  QDBusArgument dbusargument = qvariant_cast<QDBusArgument>(arg);
374  if (!d->message)
375  return false; // can't append this one...
376 
378  demarshaller.message = q_dbus_message_ref(d->message);
379 
380  if (d->direction == Demarshalling) {
381  // it's demarshalling; just copy
382  demarshaller.iterator = static_cast<QDBusDemarshaller *>(d)->iterator;
383  } else {
384  // it's marshalling; start over
385  if (!q_dbus_message_iter_init(demarshaller.message, &demarshaller.iterator))
386  return false; // error!
387  }
388 
390  }
391 
392  const char *signature = QDBusMetaType::typeToSignature( QVariant::Type(id) );
393  if (!signature) {
394  qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
395  "Use qDBusRegisterMetaType to register it",
397  error(QString::fromLatin1("Unregistered type %1 passed in arguments")
399  return false;
400  }
401 
402  switch (*signature) {
403 #ifdef __OPTIMIZE__
404  case DBUS_TYPE_BYTE:
405  case DBUS_TYPE_INT16:
406  case DBUS_TYPE_UINT16:
407  case DBUS_TYPE_INT32:
408  case DBUS_TYPE_UINT32:
409  case DBUS_TYPE_INT64:
410  case DBUS_TYPE_UINT64:
411  case DBUS_TYPE_DOUBLE:
412  qIterAppend(&iterator, ba, *signature, arg.constData());
413  return true;
414  case DBUS_TYPE_BOOLEAN:
415  append( arg.toBool() );
416  return true;
417 #else
418  case DBUS_TYPE_BYTE:
419  append( qvariant_cast<uchar>(arg) );
420  return true;
421  case DBUS_TYPE_BOOLEAN:
422  append( arg.toBool() );
423  return true;
424  case DBUS_TYPE_INT16:
425  append( qvariant_cast<short>(arg) );
426  return true;
427  case DBUS_TYPE_UINT16:
428  append( qvariant_cast<ushort>(arg) );
429  return true;
430  case DBUS_TYPE_INT32:
431  append( static_cast<dbus_int32_t>(arg.toInt()) );
432  return true;
433  case DBUS_TYPE_UINT32:
434  append( static_cast<dbus_uint32_t>(arg.toUInt()) );
435  return true;
436  case DBUS_TYPE_INT64:
437  append( arg.toLongLong() );
438  return true;
439  case DBUS_TYPE_UINT64:
440  append( arg.toULongLong() );
441  return true;
442  case DBUS_TYPE_DOUBLE:
443  append( arg.toDouble() );
444  return true;
445 #endif
446 
447  case DBUS_TYPE_STRING:
448  append( arg.toString() );
449  return true;
450  case DBUS_TYPE_OBJECT_PATH:
451  append( qvariant_cast<QDBusObjectPath>(arg) );
452  return true;
453  case DBUS_TYPE_SIGNATURE:
454  append( qvariant_cast<QDBusSignature>(arg) );
455  return true;
456 
457  // compound types:
458  case DBUS_TYPE_VARIANT:
459  // nested QVariant
460  return append( qvariant_cast<QDBusVariant>(arg) );
461 
462  case DBUS_TYPE_ARRAY:
463  // could be many things
464  // find out what kind of array it is
465  switch (arg.type()) {
467  append( arg.toStringList() );
468  return true;
469 
470  case QVariant::ByteArray:
471  append( arg.toByteArray() );
472  return true;
473 
474  default:
475  ; // fall through
476  }
477  // fall through
478 
479  case DBUS_TYPE_STRUCT:
480  case DBUS_STRUCT_BEGIN_CHAR:
481  return appendRegisteredType( arg );
482 
483  case DBUS_TYPE_DICT_ENTRY:
484  case DBUS_DICT_ENTRY_BEGIN_CHAR:
485  qFatal("QDBusMarshaller::appendVariantInternal got a DICT_ENTRY!");
486  return false;
487 
488  case DBUS_TYPE_UNIX_FD:
490  append(qvariant_cast<QDBusUnixFileDescriptor>(arg));
491  return true;
492  }
493  // fall through
494 
495  default:
496  qWarning("QDBusMarshaller::appendVariantInternal: Found unknown D-BUS type '%s'",
497  signature);
498  return false;
499  }
500 
501  return true;
502 }
DBusMessage * message
static QDBusArgumentPrivate * d(QDBusArgument &q)
bool appendCrossMarshalling(QDBusDemarshaller *arg)
void error(const QString &message)
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
#define DBUS_TYPE_UNIX_FD
QDBusDemarshaller * demarshaller()
DBusMessageIter iterator
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
Q_CORE_EXPORT void qWarning(const char *,...)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QByteArray * ba
void append(uchar arg)
Q_CORE_EXPORT void qFatal(const char *,...)
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
DBusMessageIter iterator
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
bool appendRegisteredType(const QVariant &arg)
static int argument

◆ beginArray()

QDBusMarshaller * QDBusMarshaller::beginArray ( int  id)
inline

Definition at line 231 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::beginArray().

232 {
233  const char *signature = QDBusMetaType::typeToSignature( QVariant::Type(id) );
234  if (!signature) {
235  qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
236  "Use qDBusRegisterMetaType to register it",
238  error(QString::fromLatin1("Unregistered type %1 passed in arguments")
240  return this;
241  }
242 
243  return beginCommon(DBUS_TYPE_ARRAY, signature);
244 }
QDBusMarshaller * beginCommon(int code, const char *signature)
void error(const QString &message)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
Q_CORE_EXPORT void qWarning(const char *,...)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ beginCommon()

QDBusMarshaller * QDBusMarshaller::beginCommon ( int  code,
const char *  signature 
)

Definition at line 316 of file qdbusmarshaller.cpp.

Referenced by beginArray(), beginMap(), beginMapEntry(), and beginStructure().

317 {
319  open(*d, code, signature);
320  return d;
321 }
static QDBusArgumentPrivate * d(QDBusArgument &q)
QDBusMarshaller(int flags)
void open(QDBusMarshaller &sub, int code, const char *signature)

◆ beginMap()

QDBusMarshaller * QDBusMarshaller::beginMap ( int  kid,
int  vid 
)
inline

Definition at line 246 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::beginMap().

247 {
248  const char *ksignature = QDBusMetaType::typeToSignature( QVariant::Type(kid) );
249  if (!ksignature) {
250  qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
251  "Use qDBusRegisterMetaType to register it",
252  QVariant::typeToName( QVariant::Type(kid) ), kid);
253  error(QString::fromLatin1("Unregistered type %1 passed in arguments")
255  return this;
256  }
257  if (ksignature[1] != 0 || !QDBusUtil::isValidBasicType(*ksignature)) {
258  qWarning("QDBusMarshaller: type '%s' (%d) cannot be used as the key type in a D-BUS map.",
259  QVariant::typeToName( QVariant::Type(kid) ), kid);
260  error(QString::fromLatin1("Type %1 passed in arguments cannot be used as a key in a map")
262  return this;
263  }
264 
265  const char *vsignature = QDBusMetaType::typeToSignature( QVariant::Type(vid) );
266  if (!vsignature) {
267  const char *typeName = QVariant::typeToName(QVariant::Type(vid));
268  qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
269  "Use qDBusRegisterMetaType to register it",
270  typeName, vid);
271  error(QString::fromLatin1("Unregistered type %1 passed in arguments")
272  .arg(QLatin1String(typeName)));
273  return this;
274  }
275 
276  QByteArray signature;
277  signature = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING;
278  signature += ksignature;
279  signature += vsignature;
280  signature += DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
281  return beginCommon(DBUS_TYPE_ARRAY, signature);
282 }
QDBusMarshaller * beginCommon(int code, const char *signature)
void error(const QString &message)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
const char * typeName
Definition: qmetatype.cpp:239
Q_CORE_EXPORT void qWarning(const char *,...)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
bool isValidBasicType(int c)
Returns true if c is a valid, basic D-Bus type.
Definition: qdbusutil.cpp:542
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ beginMapEntry()

QDBusMarshaller * QDBusMarshaller::beginMapEntry ( )
inline

Definition at line 284 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::beginMapEntry().

285 {
286  return beginCommon(DBUS_TYPE_DICT_ENTRY, 0);
287 }
QDBusMarshaller * beginCommon(int code, const char *signature)

◆ beginStructure()

QDBusMarshaller * QDBusMarshaller::beginStructure ( )
inline

Definition at line 226 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::beginStructure().

227 {
228  return beginCommon(DBUS_TYPE_STRUCT, 0);
229 }
QDBusMarshaller * beginCommon(int code, const char *signature)

◆ close()

void QDBusMarshaller::close ( )

Definition at line 342 of file qdbusmarshaller.cpp.

Referenced by ~QDBusMarshaller().

343 {
344  if (ba) {
345  if (closeCode)
346  *ba += closeCode;
347  } else if (parent) {
348  q_dbus_message_iter_close_container(&parent->iterator, &iterator);
349  }
350 }
DBusMessageIter iterator
QByteArray * ba
QDBusMarshaller * parent

◆ currentSignature()

QString QDBusMarshaller::currentSignature ( )
inline

Definition at line 64 of file qdbusmarshaller.cpp.

Referenced by append(), and QDBusArgument::currentSignature().

65 {
66  if (message)
67  return QString::fromUtf8(q_dbus_message_get_signature(message));
68  return QString();
69 }
DBusMessage * message
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302

◆ endArray()

QDBusMarshaller * QDBusMarshaller::endArray ( )
inline

Definition at line 326 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::endArray().

327 { return endCommon(); }
QDBusMarshaller * endCommon()

◆ endCommon()

QDBusMarshaller * QDBusMarshaller::endCommon ( )

Definition at line 335 of file qdbusmarshaller.cpp.

Referenced by endArray(), endMap(), endMapEntry(), and endStructure().

336 {
337  QDBusMarshaller *retval = parent;
338  delete this;
339  return retval;
340 }
QDBusMarshaller * parent

◆ endMap()

QDBusMarshaller * QDBusMarshaller::endMap ( )
inline

Definition at line 329 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::endMap().

330 { return endCommon(); }
QDBusMarshaller * endCommon()

◆ endMapEntry()

QDBusMarshaller * QDBusMarshaller::endMapEntry ( )
inline

Definition at line 332 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::endMapEntry().

333 { return endCommon(); }
QDBusMarshaller * endCommon()

◆ endStructure()

QDBusMarshaller * QDBusMarshaller::endStructure ( )
inline

Definition at line 323 of file qdbusmarshaller.cpp.

Referenced by QDBusArgument::endStructure().

324 { return endCommon(); }
QDBusMarshaller * endCommon()

◆ error()

void QDBusMarshaller::error ( const QString message)

Definition at line 352 of file qdbusmarshaller.cpp.

Referenced by append(), appendVariantInternal(), beginArray(), beginMap(), and error().

353 {
354  ok = false;
355  if (parent)
356  parent->error(msg);
357  else
358  errorString = msg;
359 }
void error(const QString &message)
QDBusMarshaller * parent

◆ open()

void QDBusMarshaller::open ( QDBusMarshaller sub,
int  code,
const char *  signature 
)

Definition at line 289 of file qdbusmarshaller.cpp.

Referenced by append(), appendCrossMarshalling(), and beginCommon().

290 {
291  sub.parent = this;
292  sub.ba = ba;
293  sub.ok = true;
295 
296  if (ba)
297  switch (code) {
298  case DBUS_TYPE_ARRAY:
299  *ba += char(code);
300  *ba += signature;
301  // fall through
302 
303  case DBUS_TYPE_DICT_ENTRY:
304  sub.closeCode = 0;
305  break;
306 
307  case DBUS_TYPE_STRUCT:
308  *ba += DBUS_STRUCT_BEGIN_CHAR;
309  sub.closeCode = DBUS_STRUCT_END_CHAR;
310  break;
311  }
312  else
313  q_dbus_message_iter_open_container(&iterator, code, signature, &sub.iterator);
314 }
DBusMessageIter iterator
QByteArray * ba
QDBusMarshaller * parent

Properties

◆ ba

QByteArray* QDBusMarshaller::ba

◆ closeCode

char QDBusMarshaller::closeCode

Definition at line 154 of file qdbusargument_p.h.

Referenced by close(), and open().

◆ errorString

QString QDBusMarshaller::errorString

Definition at line 153 of file qdbusargument_p.h.

Referenced by error(), and QDBusMessagePrivate::toDBusMessage().

◆ iterator

DBusMessageIter QDBusMarshaller::iterator

◆ ok

bool QDBusMarshaller::ok

◆ parent

QDBusMarshaller* QDBusMarshaller::parent

Definition at line 151 of file qdbusargument_p.h.

Referenced by close(), endCommon(), error(), and open().


The documentation for this class was generated from the following files: