QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg) { Q_ASSERT(msg.arguments().count() == 3); Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(), "QDBusConnection: internal threading error", "function called for an object that is in another thread!!"); QString interface_name = msg.arguments().at(0).toString(); QByteArray property_name = msg.arguments().at(1).toString().toUtf8(); QVariant value = qvariant_cast<QDBusVariant>(msg.arguments().at(2)).variant(); QDBusAdaptorConnector *connector; if (node.flags & QDBusConnection::ExportAdaptors && (connector = qDBusFindAdaptorConnector(node.obj))) { // find the class that implements interface_name or try until we've found the property // in case of an empty interface if (interface_name.isEmpty()) { for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(), end = connector->adaptors.constEnd(); it != end; ++it) { int status = writeProperty(it->adaptor, property_name, value); if (status == PropertyNotFound) continue; return propertyWriteReply(msg, interface_name, property_name, status); } } else { QDBusAdaptorConnector::AdaptorMap::ConstIterator it; it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), interface_name); if (it != connector->adaptors.end() && interface_name == QLatin1String(it->interface)) { return propertyWriteReply(msg, interface_name, property_name, writeProperty(it->adaptor, property_name, value)); } } } if (node.flags & (QDBusConnection::ExportScriptableProperties | QDBusConnection::ExportNonScriptableProperties)) { // try the object itself bool interfaceFound = true; if (!interface_name.isEmpty()) interfaceFound = qDBusInterfaceInObject(node.obj, interface_name); if (interfaceFound) { return propertyWriteReply(msg, interface_name, property_name, writeProperty(node.obj, property_name, value, node.flags)); } } // the property was not found if (!interface_name.isEmpty()) return interfaceNotFoundError(msg, interface_name); return propertyWriteReply(msg, interface_name, property_name, PropertyNotFound); }
QDBusAdaptorConnector *qDBusCreateAdaptorConnector(QObject *obj) { QDBusAdaptorConnector *connector = qDBusFindAdaptorConnector(obj); if (connector) return connector; return new QDBusAdaptorConnector(obj); }
QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg) { Q_ASSERT(msg.arguments().count() == 1); Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(), "QDBusConnection: internal threading error", "function called for an object that is in another thread!!"); QString interface_name = msg.arguments().at(0).toString(); bool interfaceFound = false; QVariantMap result; QDBusAdaptorConnector *connector; if (node.flags & QDBusConnection::ExportAdaptors && (connector = qDBusFindAdaptorConnector(node.obj))) { if (interface_name.isEmpty()) { // iterate over all interfaces for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(), end = connector->adaptors.constEnd(); it != end; ++it) { result += readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties); } } else { // find the class that implements interface_name QDBusAdaptorConnector::AdaptorMap::ConstIterator it; it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), interface_name); if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) { interfaceFound = true; result = readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties); } } } if (node.flags & QDBusConnection::ExportAllProperties && (!interfaceFound || interface_name.isEmpty())) { // try the object itself result += readAllProperties(node.obj, node.flags); interfaceFound = true; } if (!interfaceFound && !interface_name.isEmpty()) { // the interface was not found return interfaceNotFoundError(msg, interface_name); } return msg.createReply(QVariant::fromValue(result)); }
QDBusAdaptorConnector *qDBusFindAdaptorConnector(QDBusAbstractAdaptor *adaptor) { return qDBusFindAdaptorConnector(adaptor->parent()); }
QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node, const QDBusMessage &msg) { Q_ASSERT(msg.arguments().count() == 2); Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(), "QDBusConnection: internal threading error", "function called for an object that is in another thread!!"); QString interface_name = msg.arguments().at(0).toString(); QByteArray property_name = msg.arguments().at(1).toString().toUtf8(); QDBusAdaptorConnector *connector; QVariant value; bool interfaceFound = false; if (node.flags & QDBusConnection::ExportAdaptors && (connector = qDBusFindAdaptorConnector(node.obj))) { // find the class that implements interface_name or try until we've found the property // in case of an empty interface if (interface_name.isEmpty()) { for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(), end = connector->adaptors.constEnd(); it != end; ++it) { const QMetaObject *mo = it->adaptor->metaObject(); int pidx = mo->indexOfProperty(property_name); if (pidx != -1) { value = mo->property(pidx).read(it->adaptor); break; } } } else { QDBusAdaptorConnector::AdaptorMap::ConstIterator it; it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), interface_name); if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) { interfaceFound = true; value = it->adaptor->property(property_name); } } } if (!interfaceFound && !value.isValid() && node.flags & (QDBusConnection::ExportAllProperties | QDBusConnection::ExportNonScriptableProperties)) { // try the object itself if (!interface_name.isEmpty()) interfaceFound = qDBusInterfaceInObject(node.obj, interface_name); if (interfaceFound) { int pidx = node.obj->metaObject()->indexOfProperty(property_name); if (pidx != -1) { QMetaProperty mp = node.obj->metaObject()->property(pidx); if ((mp.isScriptable() && (node.flags & QDBusConnection::ExportScriptableProperties)) || (!mp.isScriptable() && (node.flags & QDBusConnection::ExportNonScriptableProperties))) value = mp.read(node.obj); } } } if (!value.isValid()) { // the property was not found if (!interfaceFound) return interfaceNotFoundError(msg, interface_name); return propertyNotFoundError(msg, interface_name, property_name); } return msg.createReply(QVariant::fromValue(QDBusVariant(value))); }
QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node, const QString &path) { // object may be null QString xml_data(QLatin1String(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE)); xml_data += QLatin1String("<node>\n"); if (node.obj) { Q_ASSERT_X(QThread::currentThread() == node.obj->thread(), "QDBusConnection: internal threading error", "function called for an object that is in another thread!!"); if (node.flags & (QDBusConnection::ExportScriptableContents | QDBusConnection::ExportNonScriptableContents)) { // create XML for the object itself const QMetaObject *mo = node.obj->metaObject(); for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass()) xml_data += qDBusGenerateMetaObjectXml(QString(), mo, mo->superClass(), node.flags); } // does this object have adaptors? QDBusAdaptorConnector *connector; if (node.flags & QDBusConnection::ExportAdaptors && (connector = qDBusFindAdaptorConnector(node.obj))) { // trasverse every adaptor in this object QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(); QDBusAdaptorConnector::AdaptorMap::ConstIterator end = connector->adaptors.constEnd(); for ( ; it != end; ++it) { // add the interface: QString ifaceXml = QDBusAbstractAdaptorPrivate::retrieveIntrospectionXml(it->adaptor); if (ifaceXml.isEmpty()) { // add the interface's contents: ifaceXml += qDBusGenerateMetaObjectXml(QString::fromLatin1(it->interface), it->adaptor->metaObject(), &QDBusAbstractAdaptor::staticMetaObject, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportNonScriptableContents); QDBusAbstractAdaptorPrivate::saveIntrospectionXml(it->adaptor, ifaceXml); } xml_data += ifaceXml; } } // is it a virtual node that handles introspection itself? if (node.flags & QDBusConnectionPrivate::VirtualObject) { xml_data += node.treeNode->introspect(path); } xml_data += QLatin1String( propertiesInterfaceXml ); } xml_data += QLatin1String( introspectableInterfaceXml ); xml_data += QLatin1String( peerInterfaceXml ); if (node.flags & QDBusConnection::ExportChildObjects) { xml_data += generateSubObjectXml(node.obj); } else { // generate from the object tree QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = node.children.constBegin(); QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end = node.children.constEnd(); for ( ; it != end; ++it) if (it->obj || !it->children.isEmpty()) xml_data += QString::fromLatin1(" <node name=\"%1\"/>\n") .arg(it->name); } xml_data += QLatin1String("</node>\n"); return xml_data; }