diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qdbus/qdbus/qdbus.cpp | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/tools/qdbus/qdbus/qdbus.cpp b/tools/qdbus/qdbus/qdbus.cpp index dd29d9f..2441240 100644 --- a/tools/qdbus/qdbus/qdbus.cpp +++ b/tools/qdbus/qdbus/qdbus.cpp @@ -108,19 +108,28 @@ static void printArg(const QVariant &v) static void listObjects(const QString &service, const QString &path) { - QDBusInterface iface(service, path.isEmpty() ? QLatin1String("/") : path, - QLatin1String("org.freedesktop.DBus.Introspectable"), connection); - if (!iface.isValid()) { - QDBusError err(iface.lastError()); - fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", - qPrintable(path.isEmpty() ? QString(QLatin1String("/")) : path), qPrintable(service), - qPrintable(err.name()), qPrintable(err.message())); - exit(1); + // make a low-level call, to avoid introspecting the Introspectable interface + QDBusMessage call = QDBusMessage::createMethodCall(service, path.isEmpty() ? QLatin1String("/") : path, + QLatin1String("org.freedesktop.DBus.Introspectable"), + QLatin1String("Introspect")); + QDBusReply<QString> xml = connection.call(call); + + if (path.isEmpty()) { + // top-level + if (xml.isValid()) { + printf("/\n"); + } else { + QDBusError err = xml.error(); + if (err.type() == QDBusError::ServiceUnknown) + fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); + else + printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); + exit(2); + } + } else if (!xml.isValid()) { + // this is not the first object, just fail silently + return; } - QDBusReply<QString> xml = iface.call(QLatin1String("Introspect")); - - if (!xml.isValid()) - return; // silently QDomDocument doc; doc.setContent(xml); @@ -192,18 +201,20 @@ static void listInterface(const QString &service, const QString &path, const QSt static void listAllInterfaces(const QString &service, const QString &path) { - QDBusInterface iface(service, path, QLatin1String("org.freedesktop.DBus.Introspectable"), connection); - 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); + // make a low-level call, to avoid introspecting the Introspectable interface + QDBusMessage call = QDBusMessage::createMethodCall(service, path.isEmpty() ? QLatin1String("/") : path, + QLatin1String("org.freedesktop.DBus.Introspectable"), + QLatin1String("Introspect")); + QDBusReply<QString> xml = connection.call(call); + + if (!xml.isValid()) { + QDBusError err = xml.error(); + if (err.type() == QDBusError::ServiceUnknown) + fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); + else + printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); + exit(2); } - QDBusReply<QString> xml = iface.call(QLatin1String("Introspect")); - - if (!xml.isValid()) - return; // silently QDomDocument doc; doc.setContent(xml); @@ -439,11 +450,6 @@ int main(int argc, char **argv) } if (args.isEmpty()) { - if (!bus->isServiceRegistered(service)) { - fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); - exit(1); - } - printf("/\n"); listObjects(service, QString()); exit(0); } @@ -454,10 +460,6 @@ int main(int argc, char **argv) exit(1); } if (args.isEmpty()) { - if (!bus->isServiceRegistered(service)) { - fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); - exit(1); - } listAllInterfaces(service, path); exit(0); } |