void listObjects(const QString &service, const QString &path) { QDBusInterfacePtr iface(*connection, service, path.isEmpty() ? "/" : path, "org.freedesktop.DBus.Introspectable"); if (!iface->isValid()) { QDBusError err(iface->lastError()); fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", qPrintable(path.isEmpty() ? "/" : path), qPrintable(service), qPrintable(err.name()), qPrintable(err.message())); exit(1); } QDBusReply<QString> xml = iface->call("Introspect"); if (xml.isError()) return; // silently QDomDocument doc; doc.setContent(xml); QDomElement node = doc.documentElement(); QDomElement child = node.firstChildElement(); while (!child.isNull()) { if (child.tagName() == QLatin1String("node")) { QString sub = path + '/' + child.attribute("name"); printf("%s\n", qPrintable(sub)); listObjects(service, sub); } child = child.nextSiblingElement(); } }
void listAllInterfaces(const QString &service, const QString &path) { QDBusInterfacePtr iface(*connection, service, path, "org.freedesktop.DBus.Introspectable"); if (!iface->isValid()) { QDBusError err(iface->lastError()); fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", qPrintable(path), qPrintable(service), qPrintable(err.name()), qPrintable(err.message())); exit(1); } QDBusReply<QString> xml = iface->call("Introspect"); if (xml.isError()) return; // silently QDomDocument doc; doc.setContent(xml); QDomElement node = doc.documentElement(); QDomElement child = node.firstChildElement(); while (!child.isNull()) { if (child.tagName() == QLatin1String("interface")) { QString ifaceName = child.attribute("name"); if (QDBusUtil::isValidInterfaceName(ifaceName)) listInterface(service, path, ifaceName); else { qWarning("Invalid D-BUS interface name '%s' found while parsing introspection", qPrintable(ifaceName)); } } child = child.nextSiblingElement(); } }