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

#include <qdbusargument_p.h>

Inheritance diagram for QDBusArgumentPrivate:
QDBusDemarshaller QDBusMarshaller

Public Types

enum  Direction { Marshalling, Demarshalling }
 

Public Functions

QDBusDemarshallerdemarshaller ()
 
QDBusMarshallermarshaller ()
 
 QDBusArgumentPrivate (int flags=0)
 
 ~QDBusArgumentPrivate ()
 

Static Public Functions

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)
 

Public Variables

int capabilities
 
enum QDBusArgumentPrivate::Direction direction
 
DBusMessage * message
 
QAtomicInt ref
 

Detailed Description

Definition at line 71 of file qdbusargument_p.h.

Enumerations

◆ Direction

Enumerator
Marshalling 
Demarshalling 

Definition at line 99 of file qdbusargument_p.h.

Constructors and Destructors

◆ QDBusArgumentPrivate()

QDBusArgumentPrivate::QDBusArgumentPrivate ( int  flags = 0)
inline

Definition at line 74 of file qdbusargument_p.h.

75  : message(0), ref(1), capabilities(flags)
76  { }
DBusMessage * message

◆ ~QDBusArgumentPrivate()

QDBusArgumentPrivate::~QDBusArgumentPrivate ( )

Definition at line 63 of file qdbusargument.cpp.

Referenced by QDBusArgumentPrivate().

64 {
65  if (message)
66  q_dbus_message_unref(message);
67 }
DBusMessage * message

Functions

◆ checkRead()

bool QDBusArgumentPrivate::checkRead ( QDBusArgumentPrivate d)
static

Definition at line 136 of file qdbusargument.cpp.

Referenced by QDBusArgument::asVariant(), QDBusArgument::atEnd(), checkReadAndDetach(), and QDBusArgumentPrivate().

137 {
138  if (!d)
139  return false;
140  if (d->direction == Demarshalling)
141  return true;
142 
143 #ifdef QT_DEBUG
144  qFatal("QDBusArgument: read from a write-only object");
145 #else
146  qWarning("QDBusArgument: read from a write-only object");
147 #endif
148 
149  return false;
150 }
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT void qFatal(const char *,...)
enum QDBusArgumentPrivate::Direction direction

◆ checkReadAndDetach()

bool QDBusArgumentPrivate::checkReadAndDetach ( QDBusArgumentPrivate *&  d)
static

Definition at line 152 of file qdbusargument.cpp.

Referenced by QDBusArgument::beginArray(), QDBusArgument::beginMap(), QDBusArgument::beginMapEntry(), QDBusArgument::beginStructure(), QDBusArgument::endArray(), QDBusArgument::endMap(), QDBusArgument::endMapEntry(), QDBusArgument::endStructure(), QDBusArgument::operator>>(), and QDBusArgumentPrivate().

153 {
154  if (!checkRead(d))
155  return false; // don't bother
156 
157  if (d->ref == 1)
158  return true; // no need to detach
159 
161  dd->message = q_dbus_message_ref(d->message);
162  dd->iterator = static_cast<QDBusDemarshaller*>(d)->iterator;
163 
164  if (!d->ref.deref())
165  delete d;
166  d = dd;
167  return true;
168 }
DBusMessage * message
static QDBusArgumentPrivate * d(QDBusArgument &q)
bool deref()
Atomically decrements the value of this QAtomicInt.
static bool checkRead(QDBusArgumentPrivate *d)
DBusMessageIter iterator

◆ checkWrite()

bool QDBusArgumentPrivate::checkWrite ( QDBusArgumentPrivate *&  d)
static

Definition at line 108 of file qdbusargument.cpp.

Referenced by QDBusArgument::appendVariant(), QDBusArgument::beginArray(), QDBusArgument::beginMap(), QDBusArgument::beginMapEntry(), QDBusArgument::beginStructure(), QDBusArgument::endArray(), QDBusArgument::endMap(), QDBusArgument::endMapEntry(), QDBusArgument::endStructure(), QDBusArgument::operator<<(), and QDBusArgumentPrivate().

109 {
110  if (!d)
111  return false;
112  if (d->direction == Marshalling) {
113  if (!d->marshaller()->ok)
114  return false;
115 
116  if (d->message && d->ref != 1) {
118  dd->message = q_dbus_message_copy(d->message);
119  q_dbus_message_iter_init_append(dd->message, &dd->iterator);
120 
121  if (!d->ref.deref())
122  delete d;
123  d = dd;
124  }
125  return true;
126  }
127 
128 #ifdef QT_DEBUG
129  qFatal("QDBusArgument: write from a read-only object");
130 #else
131  qWarning("QDBusArgument: write from a read-only object");
132 #endif
133  return false;
134 }
DBusMessage * message
DBusMessageIter iterator
QDBusMarshaller * marshaller()
bool deref()
Atomically decrements the value of this QAtomicInt.
Q_CORE_EXPORT void qWarning(const char *,...)
Q_CORE_EXPORT void qFatal(const char *,...)
enum QDBusArgumentPrivate::Direction direction

◆ create()

static QDBusArgument QDBusArgumentPrivate::create ( QDBusArgumentPrivate d)
inlinestatic

Definition at line 87 of file qdbusargument_p.h.

Referenced by QDBusMarshaller::appendRegisteredType(), and QDBusDemarshaller::duplicate().

88  {
89  QDBusArgument q(d);
90  return q;
91  }
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69

◆ createSignature()

QByteArray QDBusArgumentPrivate::createSignature ( int  id)
static

Definition at line 69 of file qdbusargument.cpp.

Referenced by QDBusArgumentPrivate(), and QDBusMetaType::typeToSignature().

70 {
71  if (!qdbus_loadLibDBus())
72  return "";
73 
74  QByteArray signature;
76  marshaller->ba = &signature;
77 
78  // run it
79  void *null = 0;
80  QVariant v(id, null);
81  QDBusArgument arg(marshaller);
82  QDBusMetaType::marshall(arg, v.userType(), v.constData());
83  arg.d = 0;
84 
85  // delete it
86  bool ok = marshaller->ok;
87  delete marshaller;
88 
89  if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) {
90  qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' "
91  "(Did you forget to call beginStructure() ?)",
93  signature.isEmpty() ? "<empty>" : signature.constData());
94  return "";
95  } else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
96  (signature.at(0) == DBUS_TYPE_ARRAY && (signature.at(1) == DBUS_TYPE_BYTE ||
97  signature.at(1) == DBUS_TYPE_STRING))) {
98  qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) "
99  "(Did you forget to call beginStructure() ?)",
101  signature.constData(),
103  return "";
104  }
105  return signature;
106 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static int signatureToType(const char *signature)
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
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
QDBusMarshaller * marshaller()
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 isValidSingleSignature(const QString &signature)
Returns true if signature is a valid D-Bus type signature for exactly one full type.
Definition: qdbusutil.cpp:593
QByteArray * ba
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
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
bool qdbus_loadLibDBus()
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
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...
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413

◆ d()

static QDBusArgumentPrivate* QDBusArgumentPrivate::d ( QDBusArgument q)
inlinestatic

◆ demarshaller()

QDBusDemarshaller * QDBusArgumentPrivate::demarshaller ( )
inline

◆ marshaller()

QDBusMarshaller * QDBusArgumentPrivate::marshaller ( )
inline

Properties

◆ capabilities

int QDBusArgumentPrivate::capabilities

◆ direction

enum QDBusArgumentPrivate::Direction QDBusArgumentPrivate::direction

◆ message

DBusMessage* QDBusArgumentPrivate::message

◆ ref

QAtomicInt QDBusArgumentPrivate::ref

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