summaryrefslogtreecommitdiff
path: root/tests/test-dbus-ping/test-dbus-ping.cpp
blob: ff496e61c361918096cad710e96806ed9672579c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>

#include <QtCore/QCoreApplication>
#include <QtDBus/QtDBus>

#define SERVICE_NAME            "com.nokia.dbusqeventloop.test"

int main(int argc, char **argv)
{
	QCoreApplication app(argc, argv);

	if( !QDBusConnection::systemBus().isConnected() )
	{
		fprintf(stderr, "Cannot connect to the D-Bus system bus.\n"
			"To start it, run:\n"
			"\teval `dbus-launch --auto-syntax`\n");
		return 1;
	}

	QDBusInterface iface(SERVICE_NAME, "/", "", QDBusConnection::systemBus());
	if( iface.isValid() )
	{
		QDBusReply<QString> reply = iface.call("ping", argc > 1 ? argv[1] : "");
		if( reply.isValid() )
		{
			printf("Reply was: %s\n", qPrintable(reply.value()));
			return 0;
		}

		fprintf(stderr, "Call failed: %s\n", qPrintable(reply.error().message()));
		return 2;
	}

	fprintf(stderr, "%s\n", qPrintable(QDBusConnection::systemBus().lastError().message()));
	return 3;
}