Qt 4.8
Public Types | Static Public Functions | List of all members
QDBusMetaType Class Reference

Meta-type registration system for the QtDBus module. More...

#include <qdbusmetatype.h>

Public Types

typedef void(* DemarshallFunction) (const QDBusArgument &, void *)
 
typedef void(* MarshallFunction) (QDBusArgument &, const void *)
 

Static Public Functions

static bool demarshall (const QDBusArgument &, int id, void *data)
 Executes the demarshalling of type id (whose data will be placed in data) from the D-Bus marshalling argument arg. More...
 
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 argument arg. More...
 
static void registerMarshallOperators (int typeId, MarshallFunction, DemarshallFunction)
 Registers the marshalling and demarshalling functions for meta type id. More...
 
static int signatureToType (const char *signature)
 
static const char * typeToSignature (int type)
 Returns the D-Bus signature equivalent to the supplied meta type id type. More...
 

Detailed Description

Meta-type registration system for the QtDBus module.

Warning
This function is not part of the public interface.

The QDBusMetaType class allows you to register class types for marshalling and demarshalling over D-Bus. D-Bus supports a very limited set of primitive types, but allows one to extend the type system by creating compound types, such as arrays (lists) and structs. In order to use them with QtDBus, those types must be registered.

See QtDBus type system for more information on the type system and how to register additional types.

See also
QtDBus type system, qDBusRegisterMetaType(), QMetaType, QVariant, QDBusArgument

Definition at line 56 of file qdbusmetatype.h.

Typedefs

◆ DemarshallFunction

QDBusMetaType::DemarshallFunction
Warning
This function is not part of the public interface.

Definition at line 60 of file qdbusmetatype.h.

◆ MarshallFunction

QDBusMetaType::MarshallFunction
Warning
This function is not part of the public interface.

Definition at line 59 of file qdbusmetatype.h.

Functions

◆ demarshall()

bool QDBusMetaType::demarshall ( const QDBusArgument arg,
int  id,
void *  data 
)
static

Executes the demarshalling of type id (whose data will be placed in data) from the D-Bus marshalling argument arg.

Warning
This function is not part of the public interface. Returns true if the demarshalling succeeded, or false if an error occurred.

Definition at line 287 of file qdbusmetatype.cpp.

Referenced by copyArgument(), QDBusConnectionPrivate::deliverCall(), QDBusAbstractInterfacePrivate::property(), qDBusReplyFill(), and writeProperty().

288 {
290 
292  {
293  QReadLocker locker(customTypesLock());
295  if (id >= ct->size())
296  return false; // non-existent
297 
298  const QDBusCustomTypeInfo &info = (*ct).at(id);
299  if (!info.demarshall) {
300  df = 0; // make gcc happy
301  return false;
302  } else
303  df = info.demarshall;
304  }
305 
306  QDBusArgument copy = arg;
307  df(copy, data);
308  return true;
309 }
const QStringList & customTypes
static mach_timebase_info_data_t info
void(* DemarshallFunction)(const QDBusArgument &, void *)
Definition: qdbusmetatype.h:60
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
QDBusMetaType::DemarshallFunction demarshall
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static const char * data(const QByteArray &arr)
static void init()
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ marshall()

bool QDBusMetaType::marshall ( QDBusArgument arg,
int  id,
const void *  data 
)
static

Executes the marshalling of type id (whose data is contained in data) to the D-Bus marshalling argument arg.

Warning
This function is not part of the public interface. Returns true if the marshalling succeeded, or false if an error occurred.

Definition at line 255 of file qdbusmetatype.cpp.

Referenced by QDBusMarshaller::appendRegisteredType(), and QDBusArgumentPrivate::createSignature().

256 {
258 
259  MarshallFunction mf;
260  {
261  QReadLocker locker(customTypesLock());
263  if (id >= ct->size())
264  return false; // non-existent
265 
266  const QDBusCustomTypeInfo &info = (*ct).at(id);
267  if (!info.marshall) {
268  mf = 0; // make gcc happy
269  return false;
270  } else
271  mf = info.marshall;
272  }
273 
274  mf(arg, data);
275  return true;
276 }
const QStringList & customTypes
static mach_timebase_info_data_t info
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static const char * data(const QByteArray &arr)
static void init()
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
void(* MarshallFunction)(QDBusArgument &, const void *)
Definition: qdbusmetatype.h:59
QDBusMetaType::MarshallFunction marshall
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ registerMarshallOperators()

void QDBusMetaType::registerMarshallOperators ( int  id,
MarshallFunction  mf,
DemarshallFunction  df 
)
static

Registers the marshalling and demarshalling functions for meta type id.

Warning
This function is not part of the public interface.

Definition at line 230 of file qdbusmetatype.cpp.

232 {
233  QByteArray var;
235  if (id < 0 || !mf || !df || !ct)
236  return; // error!
237 
238  QWriteLocker locker(customTypesLock());
239  if (id >= ct->size())
240  ct->resize(id + 1);
241  QDBusCustomTypeInfo &info = (*ct)[id];
242  info.marshall = mf;
243  info.demarshall = df;
244 }
const QStringList & customTypes
static mach_timebase_info_data_t info
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDBusMetaType::DemarshallFunction demarshall
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QDBusMetaType::MarshallFunction marshall
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ signatureToType()

int QDBusMetaType::signatureToType ( const char *  signature)
static
Warning
This function is not part of the public interface.

Returns the Qt meta type id for the given D-Bus signature for exactly one full type, given by signature.

Note: this function only handles the basic D-Bus types.

See also
QDBusUtil::isValidSingleSignature(), typeToSignature(), QVariant::type(), QVariant::userType()

Definition at line 323 of file qdbusmetatype.cpp.

Referenced by QDBusArgumentPrivate::createSignature(), QDBusMetaObjectGenerator::findType(), and generateInterfaceXml().

324 {
325  if (!signature)
326  return QVariant::Invalid;
327 
329  switch (signature[0])
330  {
331  case DBUS_TYPE_BOOLEAN:
332  return QVariant::Bool;
333 
334  case DBUS_TYPE_BYTE:
335  return QMetaType::UChar;
336 
337  case DBUS_TYPE_INT16:
338  return QMetaType::Short;
339 
340  case DBUS_TYPE_UINT16:
341  return QMetaType::UShort;
342 
343  case DBUS_TYPE_INT32:
344  return QVariant::Int;
345 
346  case DBUS_TYPE_UINT32:
347  return QVariant::UInt;
348 
349  case DBUS_TYPE_INT64:
350  return QVariant::LongLong;
351 
352  case DBUS_TYPE_UINT64:
353  return QVariant::ULongLong;
354 
355  case DBUS_TYPE_DOUBLE:
356  return QVariant::Double;
357 
358  case DBUS_TYPE_STRING:
359  return QVariant::String;
360 
361  case DBUS_TYPE_OBJECT_PATH:
363 
364  case DBUS_TYPE_SIGNATURE:
366 
367  case DBUS_TYPE_UNIX_FD:
369 
370  case DBUS_TYPE_VARIANT:
372 
373  case DBUS_TYPE_ARRAY: // special case
374  switch (signature[1]) {
375  case DBUS_TYPE_BYTE:
376  return QVariant::ByteArray;
377 
378  case DBUS_TYPE_STRING:
379  return QVariant::StringList;
380 
381  case DBUS_TYPE_VARIANT:
382  return QVariant::List;
383 
384  case DBUS_TYPE_OBJECT_PATH:
385  return qMetaTypeId<QList<QDBusObjectPath> >();
386 
387  case DBUS_TYPE_SIGNATURE:
388  return qMetaTypeId<QList<QDBusSignature> >();
389 
390  }
391  // fall through
392  default:
393  return QVariant::Invalid;
394  }
395 }
static int variant
#define DBUS_TYPE_UNIX_FD
static int objectpath
static void init()
static int unixfd
static int signature

◆ typeToSignature()

const char * QDBusMetaType::typeToSignature ( int  type)
static

Returns the D-Bus signature equivalent to the supplied meta type id type.

Warning
This function is not part of the public interface.

More types can be registered with the qDBusRegisterMetaType() function.

See also
QDBusUtil::isValidSingleSignature(), signatureToType(), QVariant::type(), QVariant::userType()

Definition at line 411 of file qdbusmetatype.cpp.

Referenced by QDBusMarshaller::append(), QDBusMarshaller::appendVariantInternal(), QDBusMarshaller::beginArray(), QDBusMarshaller::beginMap(), copyArgument(), findSlot(), QDBusMetaObjectGenerator::findType(), generateInterfaceXml(), QDBusMessagePrivate::makeLocal(), QDBusConnectionPrivate::prepareHook(), QDBusAbstractInterfacePrivate::property(), qDBusParametersForMethod(), qDBusReplyFill(), readAllProperties(), and QDBusPendingCallPrivate::setMetaTypes().

412 {
413  // check if it's a static type
414  switch (type)
415  {
416  case QMetaType::UChar:
417  return DBUS_TYPE_BYTE_AS_STRING;
418 
419  case QVariant::Bool:
420  return DBUS_TYPE_BOOLEAN_AS_STRING;
421 
422  case QMetaType::Short:
423  return DBUS_TYPE_INT16_AS_STRING;
424 
425  case QMetaType::UShort:
426  return DBUS_TYPE_UINT16_AS_STRING;
427 
428  case QVariant::Int:
429  return DBUS_TYPE_INT32_AS_STRING;
430 
431  case QVariant::UInt:
432  return DBUS_TYPE_UINT32_AS_STRING;
433 
434  case QVariant::LongLong:
435  return DBUS_TYPE_INT64_AS_STRING;
436 
437  case QVariant::ULongLong:
438  return DBUS_TYPE_UINT64_AS_STRING;
439 
440  case QVariant::Double:
441  return DBUS_TYPE_DOUBLE_AS_STRING;
442 
443  case QVariant::String:
444  return DBUS_TYPE_STRING_AS_STRING;
445 
447  return DBUS_TYPE_ARRAY_AS_STRING
448  DBUS_TYPE_STRING_AS_STRING; // as
449 
450  case QVariant::ByteArray:
451  return DBUS_TYPE_ARRAY_AS_STRING
452  DBUS_TYPE_BYTE_AS_STRING; // ay
453  }
454 
457  return DBUS_TYPE_VARIANT_AS_STRING;
458  else if (type == QDBusMetaTypeId::objectpath)
459  return DBUS_TYPE_OBJECT_PATH_AS_STRING;
460  else if (type == QDBusMetaTypeId::signature)
461  return DBUS_TYPE_SIGNATURE_AS_STRING;
462  else if (type == QDBusMetaTypeId::unixfd)
464 
465  // try the database
467  {
468  QReadLocker locker(customTypesLock());
469  if (type >= ct->size())
470  return 0; // type not registered with us
471 
472  const QDBusCustomTypeInfo &info = (*ct).at(type);
473 
474  if (!info.signature.isNull())
475  return info.signature;
476 
477  if (!info.marshall)
478  return 0; // type not registered with us
479  }
480 
481  // call to user code to construct the signature type
483  {
484  // createSignature will never return a null QByteArray
485  // if there was an error, it'll return ""
487 
488  // re-acquire lock
489  QWriteLocker locker(customTypesLock());
490  info = &(*ct)[type];
491  info->signature = signature;
492  }
493  return info->signature;
494 }
const QStringList & customTypes
int type
Definition: qmetatype.cpp:239
static mach_timebase_info_data_t info
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static int variant
static int objectpath
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static void init()
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
static int unixfd
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
#define DBUS_TYPE_UNIX_FD_AS_STRING
if(void) toggleToolbarShown
QDBusMetaType::MarshallFunction marshall
static int signature
static QByteArray createSignature(int id)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

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