2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-02-07 17:03:26 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2025 Symless Ltd.
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2025-02-06 18:13:54 +00:00
|
|
|
#include <QObject>
|
2025-03-05 15:40:23 +00:00
|
|
|
#include <QThread>
|
2025-02-06 11:22:47 +00:00
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
class Event;
|
2025-02-06 12:03:51 +00:00
|
|
|
class IEventQueue;
|
2014-11-11 13:51:47 +00:00
|
|
|
class FileLogOutputter;
|
2025-02-06 11:22:47 +00:00
|
|
|
class QLocalServer;
|
2025-02-06 18:13:54 +00:00
|
|
|
class QCoreApplication;
|
2025-02-06 11:22:47 +00:00
|
|
|
|
2025-02-06 12:03:51 +00:00
|
|
|
namespace deskflow::core::ipc {
|
|
|
|
|
class DaemonIpcServer;
|
2025-02-06 11:22:47 +00:00
|
|
|
}
|
2012-07-03 14:15:05 +00:00
|
|
|
|
2026-02-28 03:47:09 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2014-11-11 14:50:09 +00:00
|
|
|
class MSWindowsWatchdog;
|
2013-10-15 10:04:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-07-18 07:04:39 +00:00
|
|
|
extern const char *const kLogFilename;
|
|
|
|
|
|
2025-02-06 18:13:54 +00:00
|
|
|
class DaemonApp : public QObject
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-02-06 18:13:54 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-03-05 15:40:23 +00:00
|
|
|
explicit DaemonApp(IEventQueue &events);
|
|
|
|
|
~DaemonApp() override;
|
2025-02-10 12:58:23 +00:00
|
|
|
|
2025-03-05 15:40:23 +00:00
|
|
|
void run(QThread &daemonThread);
|
|
|
|
|
void setForeground();
|
|
|
|
|
void initLogging();
|
|
|
|
|
void connectIpcServer(const deskflow::core::ipc::DaemonIpcServer *ipcServer) const;
|
2025-02-07 12:50:25 +00:00
|
|
|
|
2025-03-14 21:18:54 +00:00
|
|
|
static QString logFilename();
|
2025-02-07 12:50:25 +00:00
|
|
|
|
2025-03-05 15:40:23 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
void daemonize();
|
2025-02-07 17:03:26 +00:00
|
|
|
void handleError(const char *message);
|
2025-03-05 15:40:23 +00:00
|
|
|
int mainLoop();
|
|
|
|
|
int daemonLoop();
|
|
|
|
|
void saveLogLevel(const QString &logLevel) const;
|
|
|
|
|
void setElevate(bool elevate);
|
|
|
|
|
void setCommand(const QString &command);
|
|
|
|
|
void applyWatchdogCommand() const;
|
|
|
|
|
void clearWatchdogCommand();
|
|
|
|
|
void clearSettings() const;
|
2025-02-06 13:31:18 +00:00
|
|
|
|
2025-03-05 16:56:49 +00:00
|
|
|
static void showConsole();
|
|
|
|
|
|
2026-02-28 03:47:09 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2025-03-05 15:40:23 +00:00
|
|
|
std::unique_ptr<MSWindowsWatchdog> m_pWatchdog;
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
2012-07-03 14:15:05 +00:00
|
|
|
|
2025-03-05 15:40:23 +00:00
|
|
|
IEventQueue &m_events;
|
|
|
|
|
FileLogOutputter *m_pFileLogOutputter = nullptr;
|
2025-02-06 13:31:18 +00:00
|
|
|
deskflow::core::ipc::DaemonIpcServer *m_ipcServer = nullptr;
|
|
|
|
|
std::string m_command = "";
|
2025-02-07 17:03:26 +00:00
|
|
|
bool m_elevate = false;
|
2025-02-06 18:13:54 +00:00
|
|
|
bool m_foreground = false;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|