diff options
Diffstat (limited to 'tests/test-dbus-pong/test-dbus-pong.cpp')
-rw-r--r-- | tests/test-dbus-pong/test-dbus-pong.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/tests/test-dbus-pong/test-dbus-pong.cpp b/tests/test-dbus-pong/test-dbus-pong.cpp index 701abb1..c936cc4 100644 --- a/tests/test-dbus-pong/test-dbus-pong.cpp +++ b/tests/test-dbus-pong/test-dbus-pong.cpp @@ -31,17 +31,50 @@ unsigned int Pong::timeout() int main(int argc, char **argv) { + bool useSessionBus = false; + QCoreApplication app(argc, argv); + if( app.arguments().count() > 1 ) + { + if( app.arguments().at(1) == "--session" ) + { + useSessionBus = true; + } + } + + QDBusConnection* myBus; + if( useSessionBus ) + { + myBus = new QDBusConnection(QDBusConnection::systemBus().sessionBus()); + qDebug("Using session bus ..."); + } + else + { + myBus = new QDBusConnection(QDBusConnection::systemBus().systemBus()); + qDebug("Using system bus ..."); + } // Check system bus connection - if( !QDBusConnection::systemBus().isConnected() ) + if( !myBus->isConnected() ) { - qDebug("Cannot connect to the D-Bus system bus."); + // Cleanup!! + delete myBus; + myBus = NULL; + + if( useSessionBus ) + { + qDebug("Cannot connect to the D-Bus session bus."); + } + else + { + qDebug("Cannot connect to the D-Bus system bus."); + } + return 1; } // Create listener service - if( !QDBusConnection::systemBus().registerService("com.nokia.dbusqeventloop.test") ) + if( !myBus->registerService("com.nokia.dbusqeventloop.test") ) { qDebug("%s", qPrintable(QDBusConnection::systemBus().lastError().message())); exit(2); @@ -49,10 +82,14 @@ int main(int argc, char **argv) Pong pong; // Register all slots as dbus methods - QDBusConnection::systemBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots); + myBus->registerObject("/", &pong, QDBusConnection::ExportAllSlots); // Let's go! app.exec(); + // Cleanup!! + delete myBus; + myBus = NULL; + return 0; } |