Commit 18ba161f authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Fully replaced KDED for autostart + dbus activation, so we work outside KDE

parent 15745b24
......@@ -33,7 +33,7 @@ add_subdirectory(kio)
add_subdirectory(icon)
add_subdirectory(interfaces)
add_subdirectory(kded)
add_subdirectory(daemon)
add_subdirectory(plugins)
add_subdirectory(plasmoid)
add_subdirectory(cli)
......
project(kdeconnectd)
include_directories(${CMAKE_SOURCE_DIR})
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-daemon")
add_executable(kdeconnectd kdeconnectd.cpp)
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons KF5::ConfigWidgets)
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
configure_file(org.kde.kdeconnect.service.in ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
install(TARGETS kdeconnectd DESTINATION ${LIBEXEC_INSTALL_DIR})
......@@ -18,43 +18,60 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_KDED_H
#define KDECONNECT_KDED_H
#include <sys/socket.h>
#include <unistd.h>
#include <signal.h>
#include <unistd.h>
#include <KDEDModule>
#include <QProcess>
#include <QSocketNotifier>
#include <QApplication>
#include <QLoggingCategory>
#include <KDBusService>
class Kded
: public KDEDModule
#include "core/daemon.h"
#include "../kdeconnect-version.h"
static int sigtermfd[2];
const static char deadbeef = 1;
struct sigaction action;
void sighandler(int signum)
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kded.kdeconnect")
if( signum == SIGTERM || signum == SIGINT)
{
ssize_t unused = ::write(sigtermfd[0], &deadbeef, sizeof(deadbeef));
Q_UNUSED(unused);
}
}
public:
Kded(QObject *parent, const QList<QVariant>&);
~Kded();
void initializeTermHandlers(QCoreApplication* app, Daemon* daemon)
{
::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermfd);
QSocketNotifier* snTerm = new QSocketNotifier(sigtermfd[1], QSocketNotifier::Read, app);
QObject::connect(snTerm, SIGNAL(activated(int)), daemon, SLOT(deleteLater()));
public Q_SLOTS:
action.sa_handler = sighandler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
Q_SCRIPTABLE void start();
Q_SCRIPTABLE void stop();
Q_SCRIPTABLE void restart();
sigaction(SIGTERM, &action, NULL);
sigaction(SIGINT, &action, NULL);
}
Q_SIGNALS:
Q_SCRIPTABLE void started();
Q_SCRIPTABLE void stopped();
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
app.setApplicationName("kdeconnectd");
app.setApplicationVersion(QLatin1String(KDECONNECT_VERSION_STRING));
app.setOrganizationDomain("kde.org");
app.setQuitOnLastWindowClosed(false);
private Q_SLOTS:
void onError(QProcess::ProcessError);
void onFinished(int, QProcess::ExitStatus);
void daemonStarted();
void checkIfDaemonTerminated();
KDBusService dbusService(KDBusService::Unique);
private:
QProcess* m_daemon;
};
Daemon* daemon = new Daemon(0);
QObject::connect(daemon, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()));
initializeTermHandlers(&app, daemon);
Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_KDED)
#endif
return app.exec();
}
project(KDEConnectInterfaces)
include_directories(${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
......
......@@ -18,11 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dbusinterfaces.h"
QString activatedService() {
static const QString service = "org.kde.kdeconnect";
QDBusConnection::sessionBus().interface()->startService(service);
return service;
}
DaemonDbusInterface::DaemonDbusInterface(QObject* parent)
: OrgKdeKdeconnectDaemonInterface("org.kde.kdeconnect", "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDaemonInterface(activatedService(), "/modules/kdeconnect", QDBusConnection::sessionBus(), parent)
{
}
......@@ -33,7 +38,7 @@ DaemonDbusInterface::~DaemonDbusInterface()
}
DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent)
: OrgKdeKdeconnectDeviceInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDeviceInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
{
}
......@@ -44,7 +49,7 @@ DeviceDbusInterface::~DeviceDbusInterface()
}
DeviceBatteryDbusInterface::DeviceBatteryDbusInterface(const QString& id, QObject* parent)
: OrgKdeKdeconnectDeviceBatteryInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDeviceBatteryInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
{
}
......@@ -55,7 +60,7 @@ DeviceBatteryDbusInterface::~DeviceBatteryDbusInterface()
}
DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString& id, QObject* parent)
: OrgKdeKdeconnectDeviceNotificationsInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDeviceNotificationsInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
{
}
......@@ -66,7 +71,7 @@ DeviceNotificationsDbusInterface::~DeviceNotificationsDbusInterface()
}
NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent)
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDeviceNotificationsNotificationInterface(activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent)
{
}
......@@ -77,7 +82,7 @@ NotificationDbusInterface::~NotificationDbusInterface()
}
SftpDbusInterface::SftpDbusInterface(const QString& id, QObject* parent)
: OrgKdeKdeconnectDeviceSftpInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent)
: OrgKdeKdeconnectDeviceSftpInterface(activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent)
{
}
......
......@@ -88,6 +88,4 @@ public:
virtual ~SftpDbusInterface();
};
#endif // DEVICEINTERFACE_H
#endif
include_directories(${CMAKE_SOURCE_DIR})
add_definitions(-DTRANSLATION_DOMAIN="kdeconnect-kded")
configure_file(config-kded.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kded.h)
add_executable(kdeconnectd kdeconnectd.cpp)
target_link_libraries(kdeconnectd kdeconnectcore KF5::DBusAddons KF5::ConfigWidgets)
set(NEW_DAEMON_STARTUP_DESC "WIP: Start kdeconnectd without kded")
option(WITH_AUTOSTART NEW_DAEMON_STARTUP_DESC Off)
add_feature_info(WITH_AUTOSTART WITH_AUTOSTART NEW_DAEMON_STARTUP_DESC)
if (NOT WITH_AUTOSTART)
add_library(kded_kdeconnect MODULE kded.cpp)
target_link_libraries(kded_kdeconnect KF5::Service KF5::DBusAddons)
install(TARGETS kded_kdeconnect DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kdeconnect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
else()
configure_file(kdeconnectd.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectd.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
endif()
install(TARGETS kdeconnectd DESTINATION ${LIBEXEC_INSTALL_DIR})
configure_file(org.kde.kdeconnect.service.in
${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kdeconnect.service
DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
#define KDECONNECTD_BIN "${CMAKE_INSTALL_PREFIX}/${LIBEXEC_INSTALL_DIR}/kdeconnectd"
/**
* Copyright 2014 Yuri Samoilenko <kinnalru@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kded.h"
#include <QTimer>
#include <QDebug>
#include <KPluginFactory>
#include "config-kded.h"
K_PLUGIN_FACTORY(KdeConnectFactory, registerPlugin<Kded>();)
Q_LOGGING_CATEGORY(KDECONNECT_KDED, "kdeconnect.kded")
Kded::Kded(QObject *parent, const QList<QVariant>&)
: KDEDModule(parent)
, m_daemon(0)
{
QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
qDebug(KDECONNECT_KDED) << "kded_kdeconnect started";
}
Kded::~Kded()
{
stop();
qDebug(KDECONNECT_KDED) << "kded_kdeconnect stopped";
}
void Kded::start()
{
if (m_daemon) {
return;
}
const QString daemon = QStringLiteral(KDECONNECTD_BIN);
qDebug(KDECONNECT_KDED) << "Starting daemon " << daemon;
m_daemon = new QProcess(this);
connect(m_daemon, SIGNAL(started()), SLOT(daemonStarted()));
connect(m_daemon, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
connect(m_daemon, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus)));
connect(m_daemon, SIGNAL(finished(int,QProcess::ExitStatus)), m_daemon, SLOT(deleteLater()));
m_daemon->setProgram(daemon);
m_daemon->closeReadChannel(QProcess::StandardOutput);
m_daemon->start();
}
void Kded::stop()
{
if (!m_daemon) {
return;
}
m_daemon->terminate();
m_daemon->setProperty("terminate", true);
QTimer::singleShot(10000, this, SLOT(checkIfDaemonTerminated()));
}
void Kded::restart()
{
stop();
return start();
}
void Kded::onError(QProcess::ProcessError errorCode)
{
qCWarning(KDECONNECT_KDED) << "Process error code=" << errorCode;
}
void Kded::daemonStarted()
{
qDebug(KDECONNECT_KDED) << "Daemon successfuly started";
Q_EMIT started();
}
void Kded::onFinished(int exitCode, QProcess::ExitStatus status)
{
if (status == QProcess::CrashExit) {
qCWarning(KDECONNECT_KDED) << "Process crashed with code=" << exitCode;
qCWarning(KDECONNECT_KDED) << m_daemon->readAllStandardError();
qCWarning(KDECONNECT_KDED) << "Restarting in 5 sec...";
QTimer::singleShot(5000, this, SLOT(start()));
} else {
qCWarning(KDECONNECT_KDED) << "Process finished with code=" << exitCode;
}
Q_EMIT stopped();
m_daemon = 0;
}
void Kded::checkIfDaemonTerminated()
{
if (!m_daemon || !m_daemon->property("terminate").isValid()) {
return;
}
m_daemon->kill();
qCWarning(KDECONNECT_KDED) << "Daemon killed";
}
#include "kded.moc"
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