Qt 4.8
Enumerations | Functions | Variables
qdbusinternalfilters.cpp File Reference
#include "qdbusconnection_p.h"
#include "qdbus_symbols_p.h"
#include <QtCore/qcoreapplication.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qthread.h>
#include "qdbusabstractadaptor.h"
#include "qdbusabstractadaptor_p.h"
#include "qdbusconnection.h"
#include "qdbusextratypes.h"
#include "qdbusmessage.h"
#include "qdbusmetatype.h"
#include "qdbusmetatype_p.h"
#include "qdbusmessage_p.h"
#include "qdbusutil_p.h"
#include "qdbusvirtualobject.h"

Go to the source code of this file.

Enumerations

enum  PropertyWriteResult { PropertyWriteSuccess = 0, PropertyNotFound, PropertyTypeMismatch, PropertyWriteFailed }
 

Functions

static QString generateSubObjectXml (QObject *object)
 
static QDBusMessage interfaceNotFoundError (const QDBusMessage &msg, const QString &interface_name)
 
static QVariantMapoperator+= (QVariantMap &lhs, const QVariantMap &rhs)
 
static QDBusMessage propertyNotFoundError (const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name)
 
static QDBusMessage propertyWriteReply (const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name, int status)
 
QString qDBusGenerateMetaObjectXml (QString interface, const QMetaObject *mo, const QMetaObject *base, int flags)
 
QString qDBusIntrospectObject (const QDBusConnectionPrivate::ObjectTreeNode &node, const QString &path)
 
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)
 
static QVariantMap readAllProperties (QObject *object, int flags)
 
static int writeProperty (QObject *obj, const QByteArray &property_name, QVariant value, int propFlags=QDBusConnection::ExportAllProperties)
 

Variables

static const char introspectableInterfaceXml []
 
static const char peerInterfaceXml []
 
static const char propertiesInterfaceXml []
 

Enumeration Type Documentation

◆ PropertyWriteResult

Enumerator
PropertyWriteSuccess 
PropertyNotFound 
PropertyTypeMismatch 
PropertyWriteFailed 

Definition at line 285 of file qdbusinternalfilters.cpp.

Function Documentation

◆ generateSubObjectXml()

static QString generateSubObjectXml ( QObject object)
static

Definition at line 103 of file qdbusinternalfilters.cpp.

Referenced by qDBusIntrospectObject().

104 {
105  QString retval;
106  const QObjectList &objs = object->children();
109  for ( ; it != end; ++it) {
110  QString name = (*it)->objectName();
111  if (!name.isEmpty() && QDBusUtil::isValidPartOfObjectPath(name))
112  retval += QString::fromLatin1(" <node name=\"%1\"/>\n")
113  .arg(name);
114  }
115  return retval;
116 }
#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
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
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
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
bool isValidPartOfObjectPath(const QString &part)
Definition: qdbusutil.cpp:338
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

◆ interfaceNotFoundError()

static QDBusMessage interfaceNotFoundError ( const QDBusMessage msg,
const QString interface_name 
)
inlinestatic

Definition at line 198 of file qdbusinternalfilters.cpp.

Referenced by qDBusPropertyGet(), qDBusPropertyGetAll(), and qDBusPropertySet().

199 {
201  QString::fromLatin1("Interface %1 was not found in object %2")
202  .arg(interface_name)
203  .arg(msg.path()));
204 }
QDBusMessage createErrorReply(const QString name, const QString &msg) const
Constructs a new DBus message representing an error reply message, with the given name and msg...
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
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

◆ operator+=()

static QVariantMap& operator+= ( QVariantMap lhs,
const QVariantMap rhs 
)
static

Definition at line 423 of file qdbusinternalfilters.cpp.

424 {
426  end = rhs.constEnd();
427  for ( ; it != end; ++it)
428  lhs.insert(it.key(), it.value());
429  return lhs;
430 }
#define it(className, varName)
const_iterator ConstIterator
Qt-style synonym for QMap::const_iterator.
Definition: qmap.h:389
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
static const KeyPair *const end

◆ propertyNotFoundError()

static QDBusMessage propertyNotFoundError ( const QDBusMessage msg,
const QString interface_name,
const QByteArray property_name 
)
inlinestatic

Definition at line 207 of file qdbusinternalfilters.cpp.

Referenced by propertyWriteReply(), and qDBusPropertyGet().

208 {
210  QString::fromLatin1("Property %1%2%3 was not found in object %4")
211  .arg(interface_name,
212  QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
213  QString::fromLatin1(property_name),
214  msg.path()));
215 }
QDBusMessage createErrorReply(const QString name, const QString &msg) const
Constructs a new DBus message representing an error reply message, with the given name and msg...
QString path() const
Returns the path of the object that this message is being sent to (in the case of a method call) or b...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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

◆ propertyWriteReply()

static QDBusMessage propertyWriteReply ( const QDBusMessage msg,
const QString interface_name,
const QByteArray property_name,
int  status 
)
static

Definition at line 292 of file qdbusinternalfilters.cpp.

Referenced by qDBusPropertySet().

294 {
295  switch (status) {
296  case PropertyNotFound:
297  return propertyNotFoundError(msg, interface_name, property_name);
300  QString::fromLatin1("Invalid arguments for writing to property %1%2%3")
301  .arg(interface_name,
302  QString::fromLatin1(interface_name.isEmpty() ? "" : "."),
303  QString::fromLatin1(property_name)));
304  case PropertyWriteFailed:
306  QString::fromLatin1("Internal error"));
307 
309  return msg.createReply();
310  }
311  Q_ASSERT_X(false, "", "Should not be reached");
312  return QDBusMessage();
313 }
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
static QDBusMessage propertyNotFoundError(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name)
QDBusMessage createErrorReply(const QString name, const QString &msg) const
Constructs a new DBus message representing an error reply message, with the given name and msg...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusMessage createReply(const QList< QVariant > &arguments=QList< QVariant >()) const
Constructs a new DBus message representing a reply, with the given arguments.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
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
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59

◆ qDBusGenerateMetaObjectXml()

QString qDBusGenerateMetaObjectXml ( QString  interface,
const QMetaObject mo,
const QMetaObject base,
int  flags 
)

Definition at line 236 of file qdbusxmlgenerator.cpp.

Referenced by qDBusIntrospectObject().

238 {
239  if (interface.isEmpty())
240  // generate the interface name from the meta object
241  interface = qDBusInterfaceFromMetaObject(mo);
242 
243  QString xml;
245  if (idx >= mo->classInfoOffset())
246  return QString::fromUtf8(mo->classInfo(idx).value());
247  else
248  xml = generateInterfaceXml(mo, flags, base->methodCount(), base->propertyCount());
249 
250  if (xml.isEmpty())
251  return QString(); // don't add an empty interface
252  return QString::fromLatin1(" <interface name=\"%1\">\n%2 </interface>\n")
253  .arg(interface, xml);
254 }
#define QCLASSINFO_DBUS_INTROSPECTION
QMetaClassInfo classInfo(int index) const
Returns the meta-data for the item of class information with the given index.
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * value() const
Returns the value of this item.
QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
Definition: qdbusmisc.cpp:80
static QString generateInterfaceXml(const QMetaObject *mo, int flags, int methodOffset, int propOffset)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
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
int classInfoOffset() const
Returns the class information offset for this class; i.e.
int indexOfClassInfo(const char *name) const
Finds class information item name and returns its index; otherwise returns -1.
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...

◆ 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)

◆ 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

◆ readAllProperties()

static QVariantMap readAllProperties ( QObject object,
int  flags 
)
static

Definition at line 432 of file qdbusinternalfilters.cpp.

Referenced by qDBusPropertyGetAll().

433 {
434  QVariantMap result;
435  const QMetaObject *mo = object->metaObject();
436 
437  // QObject has properties, so don't start from 0
438  for (int i = QObject::staticMetaObject.propertyCount(); i < mo->propertyCount(); ++i) {
439  QMetaProperty mp = mo->property(i);
440 
441  // is it readable?
442  if (!mp.isReadable())
443  continue;
444 
445  // is it a registered property?
446  int typeId = qDBusNameToTypeId(mp.typeName());
447  if (!typeId)
448  continue;
449  const char *signature = QDBusMetaType::typeToSignature(typeId);
450  if (!signature)
451  continue;
452 
453  // is this property visible from the outside?
456  // yes, it's visible
457  QVariant value = mp.read(object);
458  if (value.isValid())
459  result.insert(QString::fromLatin1(mp.name()), value);
460  }
461  }
462 
463  return result;
464 }
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...
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
int qDBusNameToTypeId(const char *name)
Definition: qdbusmisc.cpp:72
const char * name() const
Returns this property&#39;s name.
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
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
bool isReadable() const
Returns true if this property is readable; otherwise returns false.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
const char * typeName() const
Returns the name of this property&#39;s type.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.

◆ writeProperty()

static int writeProperty ( QObject obj,
const QByteArray property_name,
QVariant  value,
int  propFlags = QDBusConnection::ExportAllProperties 
)
static

Definition at line 315 of file qdbusinternalfilters.cpp.

Referenced by qDBusPropertySet().

317 {
318  const QMetaObject *mo = obj->metaObject();
319  int pidx = mo->indexOfProperty(property_name);
320  if (pidx == -1) {
321  // this object has no property by that name
322  return PropertyNotFound;
323  }
324 
325  QMetaProperty mp = mo->property(pidx);
326 
327  // check if this property is exported
328  bool isScriptable = mp.isScriptable();
329  if (!(propFlags & QDBusConnection::ExportScriptableProperties) && isScriptable)
330  return PropertyNotFound;
331  if (!(propFlags & QDBusConnection::ExportNonScriptableProperties) && !isScriptable)
332  return PropertyNotFound;
333 
334  // we found our property
335  // do we have the right type?
336  int id = mp.type();
337  if (id == QVariant::UserType) {
338  // dynamic type
339  id = qDBusNameToTypeId(mp.typeName());
340  if (id == -1) {
341  // type not registered?
342  qWarning("QDBusConnection: Unable to handle unregistered datatype '%s' for property '%s::%s'",
343  mp.typeName(), mo->className(), property_name.constData());
344  return PropertyWriteFailed;
345  }
346  }
347 
348  if (id != 0xff && value.userType() == QDBusMetaTypeId::argument) {
349  // we have to demarshall before writing
350  void *null = 0;
351  QVariant other(id, null);
352  if (!QDBusMetaType::demarshall(qvariant_cast<QDBusArgument>(value), id, other.data())) {
353  qWarning("QDBusConnection: type `%s' (%d) is not registered with QtDBus. "
354  "Use qDBusRegisterMetaType to register it",
355  mp.typeName(), id);
356  return PropertyWriteFailed;
357  }
358 
359  value = other;
360  }
361 
362  // the property type here should match
363  return mp.write(obj, value) ? PropertyWriteSuccess : PropertyWriteFailed;
364 }
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...
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
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 ...
Q_CORE_EXPORT void qWarning(const char *,...)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int qDBusNameToTypeId(const char *name)
Definition: qdbusmisc.cpp:72
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
bool write(QObject *obj, const QVariant &value) const
Writes value as the property&#39;s value to the given object.
static int argument
const char * typeName() const
Returns the name of this property&#39;s 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.
QVariant::Type type() const
Returns this property&#39;s type.

Variable Documentation

◆ introspectableInterfaceXml

const char introspectableInterfaceXml[]
static
Initial value:
=
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
" <arg name=\"xml_data\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" </interface>\n"

Definition at line 69 of file qdbusinternalfilters.cpp.

Referenced by qDBusIntrospectObject().

◆ peerInterfaceXml

const char peerInterfaceXml[]
static
Initial value:
=
" <interface name=\"org.freedesktop.DBus.Peer\">\n"
" <method name=\"Ping\"/>\n"
" <method name=\"GetMachineId\">\n"
" <arg name=\"machine_uuid\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" </interface>\n"

Definition at line 95 of file qdbusinternalfilters.cpp.

Referenced by qDBusIntrospectObject().

◆ propertiesInterfaceXml

const char propertiesInterfaceXml[]
static
Initial value:
=
" <interface name=\"org.freedesktop.DBus.Properties\">\n"
" <method name=\"Get\">\n"
" <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"value\" type=\"v\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"Set\">\n"
" <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"value\" type=\"v\" direction=\"in\"/>\n"
" </method>\n"
" <method name=\"GetAll\">\n"
" <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n"
" <arg name=\"values\" type=\"a{sv}\" direction=\"out\"/>\n"
" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QVariantMap\"/>\n"
" </method>\n"
" </interface>\n"

Definition at line 76 of file qdbusinternalfilters.cpp.

Referenced by qDBusIntrospectObject().