Qt 4.8
Classes | Functions
qdbusconnection_p.h File Reference
#include <qdbuserror.h>
#include <qdbusconnection.h>
#include <QtCore/qatomic.h>
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include <QtCore/qobject.h>
#include <QtCore/qpointer.h>
#include <QtCore/qreadwritelock.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qvector.h>
#include "qdbus_symbols_p.h"
#include <qdbusmessage.h>

Go to the source code of this file.

Classes

class  QDBusConnectionPrivate
 
struct  QDBusConnectionPrivate::ObjectTreeNode
 
struct  QDBusConnectionPrivate::SignalHook
 
struct  QDBusConnectionPrivate::WatchedServiceData
 
struct  QDBusConnectionPrivate::Watcher
 
class  QDBusErrorInternal
 

Functions

bool qDBusCheckAsyncTag (const char *tag)
 
QString qDBusInterfaceFromMetaObject (const QMetaObject *mo)
 
bool qDBusInterfaceInObject (QObject *obj, const QString &interface_name)
 
QString qDBusIntrospectObject (const QDBusConnectionPrivate::ObjectTreeNode &node, const QString &path)
 
int qDBusNameToTypeId (const char *name)
 
int qDBusParametersForMethod (const QMetaMethod &mm, QList< int > &metaTypes)
 
QDBusMessage qDBusPropertyGet (const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
 
QDBusMessage qDBusPropertyGetAll (const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
 
QDBusMessage qDBusPropertySet (const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg)
 

Function Documentation

◆ qDBusCheckAsyncTag()

bool qDBusCheckAsyncTag ( const char *  tag)

Definition at line 57 of file qdbusmisc.cpp.

Referenced by findSlot(), and generateInterfaceXml().

58 {
59  static const char noReplyTag[] = "Q_NOREPLY";
60  if (!tag || !*tag)
61  return false;
62 
63  const char *p = strstr(tag, noReplyTag);
64  if (p != NULL &&
65  (p == tag || *(p-1) == ' ') &&
66  (p[sizeof noReplyTag - 1] == '\0' || p[sizeof noReplyTag - 1] == ' '))
67  return true;
68 
69  return false;
70 }

◆ qDBusInterfaceFromMetaObject()

QString qDBusInterfaceFromMetaObject ( const QMetaObject mo)

Definition at line 80 of file qdbusmisc.cpp.

Referenced by qDBusGenerateMetaObjectXml(), and qDBusInterfaceInObject().

81 {
82  QString interface;
83 
85  if (idx >= mo->classInfoOffset()) {
86  interface = QLatin1String(mo->classInfo(idx).value());
87  } else {
88  interface = QLatin1String(mo->className());
89  interface.replace(QLatin1String("::"), QLatin1String("."));
90 
91  if (interface.startsWith(QLatin1String("QDBus"))) {
92  interface.prepend(QLatin1String("org.qtproject.QtDBus."));
93  } else if (interface.startsWith(QLatin1Char('Q')) &&
94  interface.length() >= 2 && interface.at(1).isUpper()) {
95  // assume it's Qt
96  interface.prepend(QLatin1String("org.qtproject.Qt."));
97  } else if (!QCoreApplication::instance()||
98  QCoreApplication::instance()->applicationName().isEmpty()) {
99  interface.prepend(QLatin1String("local."));
100  } else {
101  interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
102  QStringList domainName =
105  if (domainName.isEmpty())
106  interface.prepend(QLatin1String("local."));
107  else
108  for (int i = 0; i < domainName.count(); ++i)
109  interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
110  }
111  }
112 
113  return interface;
114 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString organizationDomain
the Internet domain of the organization that wrote this application
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * className
Definition: qwizard.cpp:137
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static bool isEmpty(const char *str)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define QCLASSINFO_DBUS_INTERFACE
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool isUpper() const
Returns true if the character is an uppercase letter, i.
Definition: qchar.h:273
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
int classInfoOffset() const
Returns the class information offset for this class; i.e.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qDBusInterfaceInObject()

bool qDBusInterfaceInObject ( QObject obj,
const QString interface_name 
)

Definition at line 116 of file qdbusmisc.cpp.

Referenced by QDBusConnectionPrivate::activateObject(), qDBusPropertyGet(), and qDBusPropertySet().

117 {
118  const QMetaObject *mo = obj->metaObject();
119  for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
120  if (interface_name == qDBusInterfaceFromMetaObject(mo))
121  return true;
122  return false;
123 }
QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
Definition: qdbusmisc.cpp:80
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qDBusIntrospectObject()

QString qDBusIntrospectObject ( const QDBusConnectionPrivate::ObjectTreeNode node,
const QString path 
)

Definition at line 120 of file qdbusinternalfilters.cpp.

Referenced by QDBusConnectionPrivate::activateInternalFilters().

121 {
122  // object may be null
123 
124  QString xml_data(QLatin1String(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE));
125  xml_data += QLatin1String("<node>\n");
126 
127  if (node.obj) {
129  "QDBusConnection: internal threading error",
130  "function called for an object that is in another thread!!");
131 
134  // create XML for the object itself
135  const QMetaObject *mo = node.obj->metaObject();
136  for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
137  xml_data += qDBusGenerateMetaObjectXml(QString(), mo, mo->superClass(),
138  node.flags);
139  }
140 
141  // does this object have adaptors?
142  QDBusAdaptorConnector *connector;
144  (connector = qDBusFindAdaptorConnector(node.obj))) {
145 
146  // trasverse every adaptor in this object
149  for ( ; it != end; ++it) {
150  // add the interface:
152  if (ifaceXml.isEmpty()) {
153  // add the interface's contents:
154  ifaceXml += qDBusGenerateMetaObjectXml(QString::fromLatin1(it->interface),
155  it->adaptor->metaObject(),
159 
161  }
162 
163  xml_data += ifaceXml;
164  }
165  }
166 
167  // is it a virtual node that handles introspection itself?
169  xml_data += node.treeNode->introspect(path);
170  }
171 
172  xml_data += QLatin1String( propertiesInterfaceXml );
173  }
174 
176  xml_data += QLatin1String( peerInterfaceXml );
177 
179  xml_data += generateSubObjectXml(node.obj);
180  } else {
181  // generate from the object tree
183  node.children.constBegin();
185  node.children.constEnd();
186  for ( ; it != end; ++it)
187  if (it->obj || !it->children.isEmpty())
188  xml_data += QString::fromLatin1(" <node name=\"%1\"/>\n")
189  .arg(it->name);
190  }
191 
192  xml_data += QLatin1String("</node>\n");
193  return xml_data;
194 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QDBusAdaptorConnector * qDBusFindAdaptorConnector(QObject *obj)
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo, const QMetaObject *base, int flags)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char peerInterfaceXml[]
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual QString introspect(const QString &path) const =0
This function needs to handle the introspection of the virtual object.
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString generateSubObjectXml(QObject *object)
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
static void saveIntrospectionXml(QDBusAbstractAdaptor *adaptor, const QString &xml)
static const char introspectableInterfaceXml[]
static const char propertiesInterfaceXml[]
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
static const KeyPair *const end
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
static QString retrieveIntrospectionXml(QDBusAbstractAdaptor *adaptor)

◆ qDBusNameToTypeId()

int qDBusNameToTypeId ( const char *  name)

Definition at line 72 of file qdbusmisc.cpp.

Referenced by findSlot(), generateInterfaceXml(), qDBusParametersForMethod(), readAllProperties(), and writeProperty().

73 {
74  int id = static_cast<int>( QVariant::nameToType(name) );
75  if (id == QVariant::UserType)
76  id = QMetaType::type(name);
77  return id;
78 }
const char * name
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
static Type nameToType(const char *name)
Converts the string representation of the storage type given in name, to its enum representation...
Definition: qvariant.cpp:2026

◆ qDBusParametersForMethod()

int qDBusParametersForMethod ( const QMetaMethod mm,
QList< int > &  metaTypes 
)

Definition at line 137 of file qdbusmisc.cpp.

Referenced by QDBusConnectionPrivate::findSlot(), findSlot(), generateInterfaceXml(), and QDBusAdaptorConnector::relay().

138 {
140 
141  QList<QByteArray> parameterTypes = mm.parameterTypes();
142  metaTypes.clear();
143 
144  metaTypes.append(0); // return type
145  int inputCount = 0;
146  bool seenMessage = false;
148  QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
149  for ( ; it != end; ++it) {
150  const QByteArray &type = *it;
151  if (type.endsWith('*')) {
152  //qWarning("Could not parse the method '%s'", mm.signature());
153  // pointer?
154  return -1;
155  }
156 
157  if (type.endsWith('&')) {
158  QByteArray basictype = type;
159  basictype.truncate(type.length() - 1);
160 
161  int id = qDBusNameToTypeId(basictype);
162  if (id == 0) {
163  //qWarning("Could not parse the method '%s'", mm.signature());
164  // invalid type in method parameter list
165  return -1;
166  } else if (QDBusMetaType::typeToSignature(id) == 0)
167  return -1;
168 
169  metaTypes.append( id );
170  seenMessage = true; // it cannot appear anymore anyways
171  continue;
172  }
173 
174  if (seenMessage) { // && !type.endsWith('&')
175  //qWarning("Could not parse the method '%s'", mm.signature());
176  // non-output parameters after message or after output params
177  return -1; // not allowed
178  }
179 
180  int id = qDBusNameToTypeId(type);
181  if (id == 0) {
182  //qWarning("Could not parse the method '%s'", mm.signature());
183  // invalid type in method parameter list
184  return -1;
185  }
186 
187  if (id == QDBusMetaTypeId::message)
188  seenMessage = true;
189  else if (QDBusMetaType::typeToSignature(id) == 0)
190  return -1;
191 
192  metaTypes.append(id);
193  ++inputCount;
194  }
195 
196  return inputCount;
197 }
int type
Definition: qmetatype.cpp:239
void truncate(int pos)
Truncates the byte array at index position pos.
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static int message
static void init()
void clear()
Removes all items from the list.
Definition: qlist.h:764
int length() const
Same as size().
Definition: qbytearray.h:356
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
static const KeyPair *const end
int qDBusNameToTypeId(const char *name)
Definition: qdbusmisc.cpp:72
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
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

◆ qDBusPropertyGet()

QDBusMessage qDBusPropertyGet ( const QDBusConnectionPrivate::ObjectTreeNode node,
const QDBusMessage msg 
)

Definition at line 217 of file qdbusinternalfilters.cpp.

Referenced by QDBusConnectionPrivate::activateInternalFilters().

219 {
220  Q_ASSERT(msg.arguments().count() == 2);
221  Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
222  "QDBusConnection: internal threading error",
223  "function called for an object that is in another thread!!");
224 
225  QString interface_name = msg.arguments().at(0).toString();
226  QByteArray property_name = msg.arguments().at(1).toString().toUtf8();
227 
228  QDBusAdaptorConnector *connector;
229  QVariant value;
230  bool interfaceFound = false;
232  (connector = qDBusFindAdaptorConnector(node.obj))) {
233 
234  // find the class that implements interface_name or try until we've found the property
235  // in case of an empty interface
236  if (interface_name.isEmpty()) {
238  end = connector->adaptors.constEnd(); it != end; ++it) {
239  const QMetaObject *mo = it->adaptor->metaObject();
240  int pidx = mo->indexOfProperty(property_name);
241  if (pidx != -1) {
242  value = mo->property(pidx).read(it->adaptor);
243  break;
244  }
245  }
246  } else {
248  it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
249  interface_name);
250  if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
251  interfaceFound = true;
252  value = it->adaptor->property(property_name);
253  }
254  }
255  }
256 
257  if (!interfaceFound && !value.isValid()
260  // try the object itself
261  if (!interface_name.isEmpty())
262  interfaceFound = qDBusInterfaceInObject(node.obj, interface_name);
263 
264  if (interfaceFound) {
265  int pidx = node.obj->metaObject()->indexOfProperty(property_name);
266  if (pidx != -1) {
267  QMetaProperty mp = node.obj->metaObject()->property(pidx);
270  value = mp.read(node.obj);
271  }
272  }
273  }
274 
275  if (!value.isValid()) {
276  // the property was not found
277  if (!interfaceFound)
278  return interfaceNotFoundError(msg, interface_name);
279  return propertyNotFoundError(msg, interface_name, property_name);
280  }
281 
282  return msg.createReply(QVariant::fromValue(QDBusVariant(value)));
283 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
bool isScriptable(const QObject *obj=0) const
Returns true if the property is scriptable for the given object; otherwise returns false...
QDBusAdaptorConnector * qDBusFindAdaptorConnector(QObject *obj)
static QDBusMessage interfaceNotFoundError(const QDBusMessage &msg, const QString &interface_name)
#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
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
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
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
static QDBusMessage propertyNotFoundError(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QDBusMessage createReply(const QList< QVariant > &arguments=QList< QVariant >()) const
Constructs a new DBus message representing a reply, with the given arguments.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
Definition: qdbusmisc.cpp:116
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static const KeyPair *const end
The QDBusVariant class enables the programmer to identify the variant type provided by the D-Bus type...
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ qDBusPropertyGetAll()

QDBusMessage qDBusPropertyGetAll ( const QDBusConnectionPrivate::ObjectTreeNode node,
const QDBusMessage msg 
)

Definition at line 466 of file qdbusinternalfilters.cpp.

Referenced by QDBusConnectionPrivate::activateInternalFilters().

468 {
469  Q_ASSERT(msg.arguments().count() == 1);
470  Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
471  "QDBusConnection: internal threading error",
472  "function called for an object that is in another thread!!");
473 
474  QString interface_name = msg.arguments().at(0).toString();
475 
476  bool interfaceFound = false;
477  QVariantMap result;
478 
479  QDBusAdaptorConnector *connector;
481  (connector = qDBusFindAdaptorConnector(node.obj))) {
482 
483  if (interface_name.isEmpty()) {
484  // iterate over all interfaces
486  end = connector->adaptors.constEnd(); it != end; ++it) {
488  }
489  } else {
490  // find the class that implements interface_name
492  it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
493  interface_name);
494  if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
495  interfaceFound = true;
497  }
498  }
499  }
500 
502  (!interfaceFound || interface_name.isEmpty())) {
503  // try the object itself
504  result += readAllProperties(node.obj, node.flags);
505  interfaceFound = true;
506  }
507 
508  if (!interfaceFound && !interface_name.isEmpty()) {
509  // the interface was not found
510  return interfaceNotFoundError(msg, interface_name);
511  }
512 
513  return msg.createReply(QVariant::fromValue(result));
514 }
QDBusAdaptorConnector * qDBusFindAdaptorConnector(QObject *obj)
static QDBusMessage interfaceNotFoundError(const QDBusMessage &msg, const QString &interface_name)
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
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
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QDBusMessage createReply(const QList< QVariant > &arguments=QList< QVariant >()) const
Constructs a new DBus message representing a reply, with the given arguments.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
static const KeyPair *const end
static QVariantMap readAllProperties(QObject *object, int flags)

◆ qDBusPropertySet()

QDBusMessage qDBusPropertySet ( const QDBusConnectionPrivate::ObjectTreeNode node,
const QDBusMessage msg 
)

Definition at line 366 of file qdbusinternalfilters.cpp.

Referenced by QDBusConnectionPrivate::activateInternalFilters().

368 {
369  Q_ASSERT(msg.arguments().count() == 3);
370  Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
371  "QDBusConnection: internal threading error",
372  "function called for an object that is in another thread!!");
373 
374  QString interface_name = msg.arguments().at(0).toString();
375  QByteArray property_name = msg.arguments().at(1).toString().toUtf8();
376  QVariant value = qvariant_cast<QDBusVariant>(msg.arguments().at(2)).variant();
377 
378  QDBusAdaptorConnector *connector;
380  (connector = qDBusFindAdaptorConnector(node.obj))) {
381 
382  // find the class that implements interface_name or try until we've found the property
383  // in case of an empty interface
384  if (interface_name.isEmpty()) {
386  end = connector->adaptors.constEnd(); it != end; ++it) {
387  int status = writeProperty(it->adaptor, property_name, value);
388  if (status == PropertyNotFound)
389  continue;
390  return propertyWriteReply(msg, interface_name, property_name, status);
391  }
392  } else {
394  it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
395  interface_name);
396  if (it != connector->adaptors.end() && interface_name == QLatin1String(it->interface)) {
397  return propertyWriteReply(msg, interface_name, property_name,
398  writeProperty(it->adaptor, property_name, value));
399  }
400  }
401  }
402 
405  // try the object itself
406  bool interfaceFound = true;
407  if (!interface_name.isEmpty())
408  interfaceFound = qDBusInterfaceInObject(node.obj, interface_name);
409 
410  if (interfaceFound) {
411  return propertyWriteReply(msg, interface_name, property_name,
412  writeProperty(node.obj, property_name, value, node.flags));
413  }
414  }
415 
416  // the property was not found
417  if (!interface_name.isEmpty())
418  return interfaceNotFoundError(msg, interface_name);
419  return propertyWriteReply(msg, interface_name, property_name, PropertyNotFound);
420 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name, int status)
QDBusAdaptorConnector * qDBusFindAdaptorConnector(QObject *obj)
static QDBusMessage interfaceNotFoundError(const QDBusMessage &msg, const QString &interface_name)
#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
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
Definition: qdbusmisc.cpp:116
static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant value, int propFlags=QDBusConnection::ExportAllProperties)
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
const char * variant
static const KeyPair *const end
The QDBusVariant class enables the programmer to identify the variant type provided by the D-Bus type...
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571