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

#include <qdbusmessage_p.h>

Public Functions

 QDBusMessagePrivate ()
 
 ~QDBusMessagePrivate ()
 

Static Public Functions

static QDBusMessage fromDBusMessage (DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
 Constructs a QDBusMessage by parsing the given DBusMessage object. More...
 
static bool isLocal (const QDBusMessage &msg)
 
static QDBusMessage makeLocal (const QDBusConnectionPrivate &conn, const QDBusMessage &asSent)
 
static QDBusMessage makeLocalReply (const QDBusConnectionPrivate &conn, const QDBusMessage &asSent)
 
static void setParametersValidated (QDBusMessage &msg, bool enable)
 
static DBusMessage * toDBusMessage (const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
 Constructs a DBusMessage object from message. More...
 

Public Variables

QList< QVariantarguments
 
uint autoStartService: 1
 
uint delayedReply: 1
 
QString interface
 
uint localMessage: 1
 
QDBusMessagelocalReply
 
QString message
 
DBusMessage * msg
 
QString name
 
uint parametersValidated: 1
 
QString path
 
QAtomicInt ref
 
DBusMessage * reply
 
QString service
 
QString signature
 
int timeout
 
int type
 

Detailed Description

Definition at line 69 of file qdbusmessage_p.h.

Constructors and Destructors

◆ QDBusMessagePrivate()

QDBusMessagePrivate::QDBusMessagePrivate ( )

Definition at line 65 of file qdbusmessage.cpp.

Referenced by QDBusMessage::QDBusMessage().

66  : msg(0), reply(0), type(DBUS_MESSAGE_TYPE_INVALID),
67  timeout(-1), localReply(0), ref(1), delayedReply(false), localMessage(false),
69 {
70 }
DBusMessage * reply
DBusMessage * msg
QDBusMessage * localReply

◆ ~QDBusMessagePrivate()

QDBusMessagePrivate::~QDBusMessagePrivate ( )

Definition at line 72 of file qdbusmessage.cpp.

73 {
74  if (msg)
75  q_dbus_message_unref(msg);
76  if (reply)
77  q_dbus_message_unref(reply);
78  delete localReply;
79 }
DBusMessage * reply
DBusMessage * msg
QDBusMessage * localReply

Functions

◆ fromDBusMessage()

QDBusMessage QDBusMessagePrivate::fromDBusMessage ( DBusMessage *  dmsg,
QDBusConnection::ConnectionCapabilities  capabilities 
)
static

Constructs a QDBusMessage by parsing the given DBusMessage object.

Warning
This function is not part of the public interface.

Definition at line 235 of file qdbusmessage.cpp.

Referenced by makeLocal(), QDBusConnectionPrivate::processFinishedCall(), qDBusSignalFilter(), QDBusConnectionPrivate::sendWithReply(), and setParametersValidated().

236 {
238  if (!dmsg)
239  return message;
240 
241  message.d_ptr->type = q_dbus_message_get_type(dmsg);
242  message.d_ptr->path = QString::fromUtf8(q_dbus_message_get_path(dmsg));
243  message.d_ptr->interface = QString::fromUtf8(q_dbus_message_get_interface(dmsg));
244  message.d_ptr->name = message.d_ptr->type == DBUS_MESSAGE_TYPE_ERROR ?
245  QString::fromUtf8(q_dbus_message_get_error_name(dmsg)) :
246  QString::fromUtf8(q_dbus_message_get_member(dmsg));
247  message.d_ptr->service = QString::fromUtf8(q_dbus_message_get_sender(dmsg));
248  message.d_ptr->signature = QString::fromUtf8(q_dbus_message_get_signature(dmsg));
249  message.d_ptr->msg = q_dbus_message_ref(dmsg);
250 
251  QDBusDemarshaller demarshaller(capabilities);
252  demarshaller.message = q_dbus_message_ref(dmsg);
253  if (q_dbus_message_iter_init(demarshaller.message, &demarshaller.iterator))
254  while (!demarshaller.atEnd())
255  message << demarshaller.toVariantInternal();
256  return message;
257 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDBusMessagePrivate * d_ptr
Definition: qdbusmessage.h:119
DBusMessage * msg
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
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59

◆ isLocal()

bool QDBusMessagePrivate::isLocal ( const QDBusMessage msg)
static

Definition at line 259 of file qdbusmessage.cpp.

Referenced by QDBusConnectionPrivate::handleObjectCall(), QDBusConnectionPrivate::send(), and setParametersValidated().

260 {
261  return message.d_ptr->localMessage;
262 }

◆ makeLocal()

QDBusMessage QDBusMessagePrivate::makeLocal ( const QDBusConnectionPrivate conn,
const QDBusMessage asSent 
)
static

Definition at line 264 of file qdbusmessage.cpp.

Referenced by makeLocalReply(), QDBusConnectionPrivate::sendWithReplyLocal(), and setParametersValidated().

266 {
267  // simulate the message being sent to the bus and then received back
268  // the only field that the bus sets when delivering the message
269  // (as opposed to the message as we send it), is the sender
270  // so we simply set the sender to our unique name
271 
272  // determine if we are carrying any complex types
273  QString computedSignature;
276  for ( ; it != end; ++it) {
277  int id = it->userType();
278  const char *signature = QDBusMetaType::typeToSignature(id);
279  if ((id != QVariant::StringList && id != QVariant::ByteArray &&
280  qstrlen(signature) != 1) || id == qMetaTypeId<QDBusVariant>()) {
281  // yes, we are
282  // we must marshall and demarshall again so as to create QDBusArgument
283  // entries for the complex types
285  DBusMessage *message = toDBusMessage(asSent, conn.capabilities, &error);
286  if (!message) {
287  // failed to marshall, so it's a call error
288  return QDBusMessage::createError(error);
289  }
290 
291  q_dbus_message_set_sender(message, conn.baseService.toUtf8());
292 
293  QDBusMessage retval = fromDBusMessage(message, conn.capabilities);
294  retval.d_ptr->localMessage = true;
295  q_dbus_message_unref(message);
296  if (retval.d_ptr->service.isEmpty())
297  retval.d_ptr->service = conn.baseService;
298  return retval;
299  } else {
300  computedSignature += QLatin1String(signature);
301  }
302  }
303 
304  // no complex types seen
305  // optimize by using the variant list itself
306  QDBusMessage retval;
307  QDBusMessagePrivate *d = retval.d_ptr;
308  d->arguments = asSent.d_ptr->arguments;
309  d->path = asSent.d_ptr->path;
310  d->interface = asSent.d_ptr->interface;
311  d->name = asSent.d_ptr->name;
312  d->message = asSent.d_ptr->message;
313  d->type = asSent.d_ptr->type;
314 
315  d->service = conn.baseService;
316  d->signature = computedSignature;
317  d->localMessage = true;
318  return retval;
319 }
double d
Definition: qnumeric_p.h:62
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
#define it(className, varName)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define error(msg)
QList< QVariant > arguments
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDBusMessage fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
Constructs a QDBusMessage by parsing the given DBusMessage object.
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
QDBusMessagePrivate * d_ptr
Definition: qdbusmessage.h:119
static DBusMessage * toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities, QDBusError *error)
Constructs a DBusMessage object from message.
QDBusConnection::ConnectionCapabilities capabilities
uint qstrlen(const char *str)
Definition: qbytearray.h:79
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
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

◆ makeLocalReply()

QDBusMessage QDBusMessagePrivate::makeLocalReply ( const QDBusConnectionPrivate conn,
const QDBusMessage asSent 
)
static

Definition at line 321 of file qdbusmessage.cpp.

Referenced by QDBusConnectionPrivate::sendWithReplyLocal(), and setParametersValidated().

323 {
324  // simulate the reply (return or error) message being sent to the bus and
325  // then received back.
326  if (callMsg.d_ptr->localReply)
327  return makeLocal(conn, *callMsg.d_ptr->localReply);
328  return QDBusMessage(); // failed
329 }
static QDBusMessage makeLocal(const QDBusConnectionPrivate &conn, const QDBusMessage &asSent)
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320

◆ setParametersValidated()

static void QDBusMessagePrivate::setParametersValidated ( QDBusMessage msg,
bool  enable 
)
inlinestatic

◆ toDBusMessage()

DBusMessage * QDBusMessagePrivate::toDBusMessage ( const QDBusMessage message,
QDBusConnection::ConnectionCapabilities  capabilities,
QDBusError error 
)
static

Constructs a DBusMessage object from message.

Warning
This function is not part of the public interface. The returned value must be de-referenced with q_dbus_message_unref. The capabilities flags indicates which capabilities to use.

The error object is set to indicate the error if anything went wrong with the marshalling. Usually, this error message will be placed in the reply, as if the call failed. The error pointer must not be null.

Definition at line 111 of file qdbusmessage.cpp.

Referenced by makeLocal(), QDBusConnectionPrivate::relaySignal(), QDBusConnectionPrivate::send(), QDBusConnectionPrivate::sendWithReply(), QDBusConnectionPrivate::sendWithReplyAsync(), and setParametersValidated().

113 {
114  if (!qdbus_loadLibDBus()) {
115  *error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library"));
116  return 0;
117  }
118 
119  DBusMessage *msg = 0;
120  const QDBusMessagePrivate *d_ptr = message.d_ptr;
121 
122  switch (d_ptr->type) {
123  case DBUS_MESSAGE_TYPE_INVALID:
124  //qDebug() << "QDBusMessagePrivate::toDBusMessage" << "message is invalid";
125  break;
126  case DBUS_MESSAGE_TYPE_METHOD_CALL:
127  // only service and interface can be empty -> path and name must not be empty
128  if (!d_ptr->parametersValidated) {
130  return 0;
132  return 0;
134  return 0;
135  if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method"))
136  return 0;
137  }
138 
139  msg = q_dbus_message_new_method_call(data(d_ptr->service.toUtf8()), d_ptr->path.toUtf8(),
140  data(d_ptr->interface.toUtf8()), d_ptr->name.toUtf8());
141  q_dbus_message_set_auto_start( msg, d_ptr->autoStartService );
142  break;
143  case DBUS_MESSAGE_TYPE_METHOD_RETURN:
144  msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
145  if (!d_ptr->localMessage) {
146  q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply));
147  q_dbus_message_set_reply_serial(msg, q_dbus_message_get_serial(d_ptr->reply));
148  }
149  break;
150  case DBUS_MESSAGE_TYPE_ERROR:
151  // error name can't be empty
152  if (!d_ptr->parametersValidated
154  return 0;
155 
156  msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
157  q_dbus_message_set_error_name(msg, d_ptr->name.toUtf8());
158  if (!d_ptr->localMessage) {
159  q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply));
160  q_dbus_message_set_reply_serial(msg, q_dbus_message_get_serial(d_ptr->reply));
161  }
162  break;
163  case DBUS_MESSAGE_TYPE_SIGNAL:
164  // nothing can be empty here
165  if (!d_ptr->parametersValidated) {
167  return 0;
169  return 0;
170  if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method"))
171  return 0;
172  }
173 
174  msg = q_dbus_message_new_signal(d_ptr->path.toUtf8(), d_ptr->interface.toUtf8(),
175  d_ptr->name.toUtf8());
176  break;
177  default:
178  Q_ASSERT(false);
179  break;
180  }
181 
182  // if we got here, the parameters validated
183  // and since the message parameters cannot be changed once the message is created
184  // we can record this fact
185  d_ptr->parametersValidated = true;
186 
187  QDBusMarshaller marshaller(capabilities);
190  q_dbus_message_iter_init_append(msg, &marshaller.iterator);
191  if (!d_ptr->message.isEmpty())
192  // prepend the error message
193  marshaller.append(d_ptr->message);
194  for ( ; it != cend; ++it)
195  marshaller.appendVariantInternal(*it);
196 
197  // check if everything is ok
198  if (marshaller.ok)
199  return msg;
200 
201  // not ok;
202  q_dbus_message_unref(msg);
203  *error = QDBusError(QDBusError::Failed, QLatin1String("Marshalling failed: ") + marshaller.errorString);
204  return 0;
205 }
bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType=0)
Definition: qdbusutil_p.h:135
#define it(className, varName)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QList< QVariant > arguments
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DBusMessage * reply
bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:111
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusMessagePrivate * d_ptr
Definition: qdbusmessage.h:119
DBusMessage * msg
static const char * data(const QByteArray &arr)
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:123
bool qdbus_loadLibDBus()
bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:149
bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
Definition: qdbusutil_p.h:99
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

Properties

◆ arguments

QList<QVariant> QDBusMessagePrivate::arguments

Definition at line 75 of file qdbusmessage_p.h.

Referenced by makeLocal(), QDBusMessage::setArguments(), and toDBusMessage().

◆ autoStartService

uint QDBusMessagePrivate::autoStartService

Definition at line 91 of file qdbusmessage_p.h.

Referenced by toDBusMessage().

◆ delayedReply

uint QDBusMessagePrivate::delayedReply
mutable

Definition at line 88 of file qdbusmessage_p.h.

◆ interface

QString QDBusMessagePrivate::interface

◆ localMessage

uint QDBusMessagePrivate::localMessage

◆ localReply

QDBusMessage* QDBusMessagePrivate::localReply
mutable

Definition at line 85 of file qdbusmessage_p.h.

Referenced by makeLocalReply(), and ~QDBusMessagePrivate().

◆ message

QString QDBusMessagePrivate::message

◆ msg

DBusMessage* QDBusMessagePrivate::msg

◆ name

QString QDBusMessagePrivate::name

◆ parametersValidated

uint QDBusMessagePrivate::parametersValidated
mutable

◆ path

QString QDBusMessagePrivate::path

◆ ref

QAtomicInt QDBusMessagePrivate::ref

Definition at line 86 of file qdbusmessage_p.h.

Referenced by QDBusMessage::QDBusMessage().

◆ reply

DBusMessage* QDBusMessagePrivate::reply

◆ service

QString QDBusMessagePrivate::service

◆ signature

QString QDBusMessagePrivate::signature

Definition at line 79 of file qdbusmessage_p.h.

Referenced by fromDBusMessage(), and makeLocal().

◆ timeout

int QDBusMessagePrivate::timeout

Definition at line 84 of file qdbusmessage_p.h.

◆ type

int QDBusMessagePrivate::type

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