summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-09-13 08:03:45 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-09-13 08:03:45 (GMT)
commit139cffbfe1598b32ffe658968694d163dc53e3dd (patch)
tree494fc37f23644b856061416d1c44610c69e726af
parent3c99094f117a60ad39aa626af2af8fe6eb5d054f (diff)
downloadQt-139cffbfe1598b32ffe658968694d163dc53e3dd.zip
Qt-139cffbfe1598b32ffe658968694d163dc53e3dd.tar.gz
Qt-139cffbfe1598b32ffe658968694d163dc53e3dd.tar.bz2
Improve upon the previous commit and allow more cases to activate.
Use the Introspect call's return value to determine whether the service exists or not. That way, a call to a non-existing service may activate it.
-rw-r--r--tools/qdbus/qdbus/qdbus.cpp66
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);
}