static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name, int status) { switch (status) { case PropertyNotFound: return propertyNotFoundError(msg, interface_name, property_name); case PropertyTypeMismatch: return msg.createErrorReply(QDBusError::InvalidArgs, QString::fromLatin1("Invalid arguments for writing to property %1%2%3") .arg(interface_name, QString::fromLatin1(interface_name.isEmpty() ? "" : "."), QString::fromLatin1(property_name))); case PropertyReadOnly: return msg.createErrorReply(QDBusError::PropertyReadOnly, QString::fromLatin1("Property %1%2%3 is read-only") .arg(interface_name, QString::fromLatin1(interface_name.isEmpty() ? "" : "."), QString::fromLatin1(property_name))); case PropertyWriteFailed: return msg.createErrorReply(QDBusError::InternalError, QString::fromLatin1("Internal error")); case PropertyWriteSuccess: return msg.createReply(); } Q_ASSERT_X(false, "", "Should not be reached"); return QDBusMessage(); }
static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name, int status) { switch (status) { case PropertyNotFound: return propertyNotFoundError(msg, interface_name, property_name); case PropertyTypeMismatch: return msg.createErrorReply(QDBusError::InvalidArgs, QString::fromLatin1("Invalid arguments for writing to property %1%2%3") .arg(interface_name, QString::fromLatin1(interface_name.isEmpty() ? "" : "."), QString::fromLatin1(property_name))); case PropertyWriteFailed: return msg.createErrorReply(QDBusError::InternalError, QString::fromLatin1("Internal error")); case PropertyWriteSuccess: return msg.createReply(); } Q_UNREACHABLE(); }
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))); }