2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "ping-common.h"
|
|
|
|
|
2023-02-22 11:52:55 +00:00
|
|
|
#include <QObject>
|
2021-01-08 11:57:47 +00:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusError>
|
|
|
|
|
2023-02-22 11:52:55 +00:00
|
|
|
class Pong : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public slots:
|
|
|
|
QString ping(const QString &arg);
|
|
|
|
};
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QString Pong::ping(const QString &arg)
|
|
|
|
{
|
2023-02-22 11:41:05 +00:00
|
|
|
QMetaObject::invokeMethod(QCoreApplication::instance(), &QCoreApplication::quit);
|
2011-04-27 10:05:43 +00:00
|
|
|
return QString("ping(\"%1\") got called").arg(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
2023-02-22 11:41:05 +00:00
|
|
|
auto connection = QDBusConnection::sessionBus();
|
|
|
|
|
|
|
|
if (!connection.isConnected()) {
|
|
|
|
qWarning("Cannot connect to the D-Bus session bus.\n"
|
|
|
|
"To start it, run:\n"
|
|
|
|
"\teval `dbus-launch --auto-syntax`\n");
|
2011-04-27 10:05:43 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-22 11:41:05 +00:00
|
|
|
if (!connection.registerService(SERVICE_NAME)) {
|
|
|
|
qWarning("%s\n", qPrintable(connection.lastError().message()));
|
2011-04-27 10:05:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pong pong;
|
2023-02-22 11:41:05 +00:00
|
|
|
connection.registerObject("/", &pong, QDBusConnection::ExportAllSlots);
|
2013-03-14 23:42:15 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
app.exec();
|
|
|
|
return 0;
|
|
|
|
}
|
2023-02-22 11:52:55 +00:00
|
|
|
|
|
|
|
#include "pong.moc"
|