Commit 348e452a authored by David Redondo's avatar David Redondo 🏎

Provide a --replace command line option

Useful when developing
parent 88e1ad8a
......@@ -8,7 +8,7 @@ set_source_files_properties("ksysguard_iface.xml"
qt5_add_dbus_adaptor(SOURCES "ksysguard_iface.xml" ksysguarddaemon.h KSysGuardDaemon)
add_library(ksystemstats_core STATIC ${SOURCES})
target_link_libraries(ksystemstats_core PUBLIC Qt5::Core Qt5::DBus KF5::CoreAddons KSysGuard::StatsBackend )
target_link_libraries(ksystemstats_core PUBLIC Qt5::Core Qt5::DBus KF5::CoreAddons KF5::DBusAddons KSysGuard::StatsBackend )
add_executable(ksystemstats main.cpp)
target_link_libraries(ksystemstats ksystemstats_core)
......
......@@ -72,7 +72,7 @@ public:
protected:
void loadProviders() override;
private Q_SLOTS:
void init();
void initTestCase();
void findById();
void update();
void subscription();
......@@ -98,9 +98,11 @@ void KStatsTest::loadProviders()
registerProvider(m_testPlugin);
}
void KStatsTest::init()
void KStatsTest::initTestCase()
{
KSysGuardDaemon::init();
QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAdaptors);
loadProviders();
}
void KStatsTest::findById()
......@@ -150,7 +152,7 @@ void KStatsTest::changes()
void KStatsTest::dbusApi()
{
OrgKdeKSysGuardDaemonInterface iface("org.kde.ksystemstats",
OrgKdeKSysGuardDaemonInterface iface(QDBusConnection::sessionBus().baseService(),
"/",
QDBusConnection::sessionBus(),
this);
......
/*
Copyright (c) 2019 David Edmundson <davidedmundson@kde.org>
Copyright (c) 2020 David Redondo <kde@david-redondo.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -32,6 +33,7 @@
#include "SensorContainer.h"
#include "SensorProperty.h"
#include <KDBusService>
#include <KPluginLoader>
#include <KPluginMetaData>
#include <KPluginFactory>
......@@ -67,14 +69,16 @@ KSysGuardDaemon::~KSysGuardDaemon()
}
}
void KSysGuardDaemon::init()
void KSysGuardDaemon::init(ReplaceIfRunning replaceIfRunning)
{
loadProviders();
QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAdaptors);
if (!QDBusConnection::sessionBus().registerService("org.kde.ksystemstats")) {
qCritical() << "Unable to register DBus service org.kde.ksystemstats. Maybe it is already running?";
exit(1);
KDBusService::StartupOptions options = KDBusService::Unique;
if (replaceIfRunning == ReplaceIfRunning::Replace) {
options |= KDBusService::Replace;
}
auto service = new KDBusService(options , this);
service->setExitValue(1);
QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAdaptors);
}
void KSysGuardDaemon::loadProviders()
......
......@@ -35,11 +35,15 @@ class QDBusServiceWatcher;
class KSysGuardDaemon : public QObject, public QDBusContext
{
Q_OBJECT
public:
enum class ReplaceIfRunning {
Replace,
DoNotReplace
};
KSysGuardDaemon();
~KSysGuardDaemon();
void init();
void init(ReplaceIfRunning replaceIfRunning);
SensorProperty *findSensor(const QString &path) const;
public Q_SLOTS:
......
/*
Copyright (c) 2019 David Edmundson <davidedmundson@kde.org>
Copyright (c) 2020 David Redondo <kde@david-redondo.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -18,6 +19,7 @@
*/
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QDebug>
#include "ksysguarddaemon.h"
......@@ -26,7 +28,13 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
app.setQuitLockEnabled(false) ;
app.setOrganizationDomain(QStringLiteral("kde.org"));
QCommandLineParser parser;
parser.addOption(QCommandLineOption(QStringLiteral("replace"), QStringLiteral("Replace the running instance")));
parser.process(app);
KSysGuardDaemon d;
d.init();
d.init(parser.isSet(QStringLiteral("replace")) ? KSysGuardDaemon::ReplaceIfRunning::Replace : KSysGuardDaemon::ReplaceIfRunning::DoNotReplace);
app.exec();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment