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
|
|
|
|
2021-01-08 11:57:47 +00:00
|
|
|
#include "ping-common.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2021-01-08 11:57:47 +00:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusReply>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2023-02-22 11:41:05 +00:00
|
|
|
#include <iostream>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
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
|
|
|
QDBusInterface iface(SERVICE_NAME, "/");
|
2011-04-27 10:05:43 +00:00
|
|
|
if (iface.isValid()) {
|
|
|
|
QDBusReply<QString> reply = iface.call("ping", argc > 1 ? argv[1] : "");
|
|
|
|
if (reply.isValid()) {
|
2023-02-22 11:41:05 +00:00
|
|
|
std::cout << "Reply was: " << qPrintable(reply.value()) << std::endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-22 11:41:05 +00:00
|
|
|
qWarning("Call failed: %s\n", qPrintable(reply.error().message()));
|
2011-04-27 10:05:43 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-22 11:41:05 +00:00
|
|
|
qWarning("%s\n", qPrintable(connection.lastError().message()));
|
2011-04-27 10:05:43 +00:00
|
|
|
return 1;
|
|
|
|
}
|