forked from linuxdeepin/ddm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaemonApp.cpp
More file actions
135 lines (106 loc) · 4.83 KB
/
DaemonApp.cpp
File metadata and controls
135 lines (106 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/***************************************************************************
* Copyright (C) 2025-2026 UnionTech Software Technology Co., Ltd.
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@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) any later version.
*
* 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, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
***************************************************************************/
#include "DaemonApp.h"
#include "Configuration.h"
#include "Constants.h"
#include "DisplayManager.h"
#include "PowerManager.h"
#include "SeatManager.h"
#include "SignalHandler.h"
#include "TreelandConnector.h"
#include "MessageHandler.h"
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDebug>
#include <QHostInfo>
#include <QTimer>
#include <iostream>
namespace DDM {
DaemonApp *DaemonApp::self = nullptr;
DaemonApp::DaemonApp(int &argc, char **argv) : QCoreApplication(argc, argv) {
// point instance to this
self = this;
qInstallMessageHandler(DDM::DaemonMessageHandler);
// log message
qDebug() << "Initializing...";
bool consoleKitServiceActivatable = false;
QDBusReply<QStringList> activatableNamesReply = QDBusConnection::systemBus().interface()->activatableServiceNames();
if (activatableNamesReply.isValid()) {
consoleKitServiceActivatable = activatableNamesReply.value().contains(QStringLiteral("org.freedesktop.ConsoleKit"));
}
// If ConsoleKit isn't started by the OS init system (FreeBSD, for instance),
// we start it ourselves during the ddm startup
if (consoleKitServiceActivatable) {
QDBusReply<bool> registeredReply = QDBusConnection::systemBus().interface()->isServiceRegistered(QStringLiteral("org.freedesktop.ConsoleKit"));
if (registeredReply.isValid() && registeredReply.value() == false) {
QDBusConnection::systemBus().interface()->startService(QStringLiteral("org.freedesktop.ConsoleKit"));
}
}
// create display manager
m_displayManager = new DisplayManager(this);
// create power manager
m_powerManager = new PowerManager(this);
// create seat manager
m_seatManager = new SeatManager(this);
// connect with display manager
connect(m_seatManager, &SeatManager::seatCreated, m_displayManager, &DisplayManager::AddSeat);
connect(m_seatManager, &SeatManager::seatRemoved, m_displayManager, &DisplayManager::RemoveSeat);
// create signal handler
m_signalHandler = new SignalHandler(this);
// quit when SIGINT, SIGTERM received
connect(m_signalHandler, &SignalHandler::sigintReceived, this, &DaemonApp::quit);
connect(m_signalHandler, &SignalHandler::sigtermReceived, this, &DaemonApp::quit);
m_treelandConnector = new TreelandConnector();
// log message
qDebug() << "Starting...";
m_seatManager->initialize();
}
QString DaemonApp::hostName() const {
return QHostInfo::localHostName();
}
int DaemonApp::newSessionId() {
return m_lastSessionId++;
}
void DaemonApp::backToNormal() {
QDBusInterface interface("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", QDBusConnection::systemBus());
qDebug() << interface.call("ReenableUnitFiles", QStringList() << "lightdm.service", false, true);
}
}
int main(int argc, char **argv) {
QStringList arguments;
for (int i = 0; i < argc; i++)
arguments << QString::fromLocal8Bit(argv[i]);
if (arguments.contains(QStringLiteral("--help")) || arguments.contains(QStringLiteral("-h"))) {
std::cout << "Usage: ddm [options]\n"
<< "Options: \n"
<< " --example-config Print the complete current configuration to stdout" << std::endl;
return EXIT_FAILURE;
}
// spit a complete config file on stdout and quit on demand
if (arguments.contains(QStringLiteral("--example-config"))) {
DDM::mainConfig.wipe();
QTextStream(stdout) << DDM::mainConfig.toConfigFull();
return EXIT_SUCCESS;
}
// create application
DDM::DaemonApp app(argc, argv);
// run application
return app.exec();
}