summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2006-04-29 12:49:21 +0000
committerThiago Macieira <thiago@kde.org>2006-04-29 12:49:21 +0000
commit3ad7ee6334a8b69794e64386657976a4df094c57 (patch)
treee1bead28446f8d58b9d6688a6df54d53dc70e55e
parent7cabddaa4237b7e0ce1c6b9781d115b9831e77f2 (diff)
* qt/examples/dbus.cpp: Enhance error messages and use
QDBusInterfacePtr.
-rw-r--r--ChangeLog5
-rw-r--r--qt/examples/dbus.cpp63
2 files changed, 46 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index c29fb746..889a6e36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com>
+ * qt/examples/dbus.cpp: Enhance error messages and use
+ QDBusInterfacePtr.
+
+2006-04-29 Thiago Macieira <thiago.macieira@trolltech.com>
+
* qt/qdbusinterface.h: Rename QDBusRef to QDBusInterfacePtr
and disable the copy operators. (r533772, r534746)
diff --git a/qt/examples/dbus.cpp b/qt/examples/dbus.cpp
index 0227c477..32fcc3fa 100644
--- a/qt/examples/dbus.cpp
+++ b/qt/examples/dbus.cpp
@@ -33,8 +33,15 @@ QDBusConnection *connection;
void listObjects(const QString &service, const QString &path)
{
- QDBusInterface *iface = connection->findInterface(service, path.isEmpty() ? "/" : path,
- "org.freedesktop.DBus.Introspectable");
+ 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())
@@ -52,13 +59,18 @@ void listObjects(const QString &service, const QString &path)
}
child = child.nextSiblingElement();
}
-
- delete iface;
}
void listInterface(const QString &service, const QString &path, const QString &interface)
{
- QDBusInterface *iface = connection->findInterface(service, path, interface);
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
+ qPrintable(interface), qPrintable(path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
+ exit(1);
+ }
const QMetaObject *mo = iface->metaObject();
// properties
@@ -101,13 +113,18 @@ void listInterface(const QString &service, const QString &path, const QString &i
}
printf(")\n");
}
- delete iface;
}
void listAllInterfaces(const QString &service, const QString &path)
{
- QDBusInterface *iface = connection->findInterface(service, path,
- "org.freedesktop.DBus.Introspectable");
+ 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())
@@ -123,8 +140,6 @@ void listAllInterfaces(const QString &service, const QString &path)
}
child = child.nextSiblingElement();
}
-
- delete iface;
}
QStringList readList(int &argc, const char *const *&argv)
@@ -142,12 +157,12 @@ QStringList readList(int &argc, const char *const *&argv)
void placeCall(const QString &service, const QString &path, const QString &interface,
const QString &member, int argc, const char *const *argv)
{
- QDBusInterface *iface;
- iface = connection->findInterface(service, path, interface);
-
- if (!iface) {
- fprintf(stderr, "Interface '%s' not available in object %s at %s\n",
- qPrintable(interface), qPrintable(path), qPrintable(service));
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
+ qPrintable(interface), qPrintable(path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
exit(1);
}
@@ -155,7 +170,7 @@ void placeCall(const QString &service, const QString &path, const QString &inter
QByteArray match = member.toLatin1();
match += '(';
- int midx;
+ int midx = -1;
for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
QByteArray signature = mm.signature();
@@ -172,7 +187,7 @@ void placeCall(const QString &service, const QString &path, const QString &inter
exit(1);
}
- QMetaMethod mm = iface->metaObject()->method(midx);
+ QMetaMethod mm = mo->method(midx);
QList<QByteArray> types = mm.parameterTypes();
QVariantList params;
@@ -221,12 +236,16 @@ void placeCall(const QString &service, const QString &path, const QString &inter
}
foreach (QVariant v, reply) {
- if (v.userType() == qMetaTypeId<QVariant>())
- v = qvariant_cast<QVariant>(v);
- printf("%s\n", qPrintable(v.toString()));
+ if (v.userType() == QVariant::StringList) {
+ foreach (QString s, v.toStringList())
+ printf("%s\n", qPrintable(s));
+ } else {
+ if (v.userType() == qMetaTypeId<QVariant>())
+ v = qvariant_cast<QVariant>(v);
+ printf("%s\n", qPrintable(v.toString()));
+ }
}
- delete iface;
exit(0);
}