Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0bb66df6 authored by David Edmundson's avatar David Edmundson

Move kactivitymanagerd to libexec and remove manual daemon management

Summary:
Since it was made DBus activatable having any other code to start/stop
the daemon doesn't really make any sense. For that reason I've
moved it to libexec.

Also the original code can be more efficient. It creates a whole qapp
instance, checks if we're registered then forks itself to spawn a new
version of the app that then registers otherwise quits.

KDBusService already does all this in a simpler faster non-racey way.

Test Plan:
Installed
Still got kactivitymanagerd

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D15870
parent e24b9ac7
......@@ -35,7 +35,6 @@ cxx_check_feature ("c++11" "initializer-lists" "N2672" HAVE_CXX11_INITIALIZER_L
# Starting the actual project definition
# Config file
set (KAMD_FULL_BIN_DIR "${KDE_INSTALL_FULL_BINDIR}")
set (KAMD_PLUGIN_VERSION 1)
set (KAMD_PLUGIN_DIR "kactivitymanagerd/${KAMD_PLUGIN_VERSION}")
set (KAMD_FULL_PLUGIN_DIR "${KDE_INSTALL_FULL_PLUGINDIR}/${KAMD_PLUGIN_DIR}/")
......
......@@ -4,8 +4,6 @@
#cmakedefine KAMD_PLUGIN_DIR "@KAMD_PLUGIN_DIR@"
#cmakedefine KAMD_FULL_PLUGIN_DIR "@KAMD_FULL_PLUGIN_DIR@"
#cmakedefine KAMD_FULL_BIN_DIR "@KAMD_FULL_BIN_DIR@"
#cmakedefine01 HAVE_CXX11_AUTO
#cmakedefine01 HAVE_CXX11_NULLPTR
#cmakedefine01 HAVE_CXX11_LAMBDA
......
[D-BUS Service]
Name=org.kde.ActivityManager
Exec=@KAMD_FULL_BIN_DIR@/kactivitymanagerd
Exec=${KDE_INSTALL_FULL_LIBEXECDIR}/kactivitymanagerd
......@@ -290,31 +290,6 @@ QString Application::serviceVersion() const
return KACTIVITIES_VERSION_STRING;
}
// Leaving object oriented world :)
namespace {
template <typename Return>
Return callOnRunningService(const QString &method)
{
static QDBusInterface remote(KAMD_DBUS_SERVICE, QStringLiteral("/ActivityManager"),
QStringLiteral("org.kde.ActivityManager.Application"));
QDBusReply<Return> reply = remote.call(method);
return (Return)reply;
}
QString runningServiceVersion()
{
return callOnRunningService<QString>(QStringLiteral("serviceVersion"));
}
bool isServiceRunning()
{
return QDBusConnection::sessionBus().interface()->isServiceRegistered(
KAMD_DBUS_SERVICE);
}
}
int main(int argc, char **argv)
{
// Disable session management for this process
......@@ -325,102 +300,11 @@ int main(int argc, char **argv)
Application application(argc, argv);
application.setApplicationName(QStringLiteral("ActivityManager"));
application.setOrganizationDomain(QStringLiteral("kde.org"));
KDBusService service(KDBusService::Unique);
// KAboutData about("kactivitymanagerd", nullptr, ki18n("KDE Activity Manager"), "3.0",
// ki18n("KDE Activity Management Service"),
// KAboutData::License_GPL,
// ki18n("(c) 2010, 2011, 2012 Ivan Cukic"), KLocalizedString(),
// "http://www.kde.org/");
// KCmdLineArgs::init(argc, argv, &about);
const auto arguments = application.arguments();
if (arguments.size() == 0) {
QCoreApplication::exit(EXIT_FAILURE);
} else if (arguments.size() != 1 && (arguments.size() != 2 || arguments[1] == QLatin1String("--help"))) {
QTextStream(stdout)
<< "start\tStarts the service\n"
<< "stop\tStops the server\n"
<< "status\tPrints basic server information\n"
<< "start-daemon\tStarts the service without forking (use with caution)\n"
<< "--help\tThis help message\n";
QCoreApplication::exit(EXIT_SUCCESS);
} else if (arguments.size() == 1 || arguments[1] == QLatin1String("start")) {
// Checking whether the service is already running
if (isServiceRunning()) {
QTextStream(stdout) << "Already running\n";
QCoreApplication::exit(EXIT_SUCCESS);
}
// Creating the watcher, but not on the wall
QDBusServiceWatcher watcher(KAMD_DBUS_SERVICE,
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration);
application.init();
QObject::connect(&watcher, &QDBusServiceWatcher::serviceRegistered,
[] (const QString &service) {
QTextStream(stdout)
<< "Service started, version: " << runningServiceVersion()
<< "\n";
QCoreApplication::exit(EXIT_SUCCESS);
});
// Starting the dameon
QProcess::startDetached(
QLatin1String(KAMD_FULL_BIN_DIR "/kactivitymanagerd"),
QStringList{QStringLiteral("start-daemon")}
);
return application.exec();
} else if (arguments[1] == QLatin1String("stop")) {
if (!isServiceRunning()) {
QTextStream(stdout) << "Service not running\n";
QCoreApplication::exit(EXIT_SUCCESS);
}
callOnRunningService<void>(QStringLiteral("quit"));
QTextStream(stdout) << "Service stopped\n";
return EXIT_SUCCESS;
} else if (arguments[1] == QLatin1String("status")) {
// Checking whether the service is already running
if (isServiceRunning()) {
QTextStream(stdout) << "The service is running, version: "
<< runningServiceVersion() << "\n";
} else {
QTextStream(stdout) << "The service is not running\n";
}
return EXIT_SUCCESS;
} else if (arguments[1] == QLatin1String("start-daemon")) {
// Really starting the activity manager
KDBusService service(KDBusService::Unique);
application.init();
return application.exec();
} else {
QTextStream(stdout) << "Unrecognized command: " << arguments[1] << '\n';
return EXIT_FAILURE;
}
return application.exec();
}
QStringList Application::loadedPlugins() const
......
......@@ -81,7 +81,12 @@ install (FILES
)
install (TARGETS
kactivitymanagerd kactivitymanagerd_plugin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
kactivitymanagerd
DESTINATION ${KDE_INSTALL_LIBEXECDIR}
)
install (TARGETS
kactivitymanagerd_plugin ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
)
install (FILES
......
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