| 1 | // SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-only |
| 4 | |
| 5 | #include "LogManager.h" |
| 6 | |
| 7 | #include "util/utils.h" |
| 8 | #include "bootmakerservice.h" |
| 9 | |
| 10 | #include <QDebug> |
| 11 | #include <QCoreApplication> |
| 12 | #include <QDBusConnection> |
| 13 | #include <QDBusError> |
| 14 | |
| 15 | const QString BootMakerServiceName = "com.deepin.bootmaker"; |
| 16 | const QString BootMakerPath = "/com/deepin/bootmaker"; |
| 17 | |
| 18 | int main(int argc, char *argv[]) |
| 19 | { |
| 20 | QString PATH = qgetenv("PATH"); |
| 21 | |
| 22 | if (PATH.isEmpty()) { |
| 23 | PATH = "/usr/bin"; |
| 24 | } |
| 25 | |
| 26 | PATH += ":/usr/sbin"; |
| 27 | PATH += ":/sbin"; |
| 28 | qputenv("PATH", PATH.toLatin1()); |
| 29 | |
| 30 | QString strDebug = qgetenv("QT_LOGGING_RULES"); |
| 31 | |
| 32 | if (strDebug.isEmpty()) { |
| 33 | strDebug = "*.debug=false"; |
| 34 | } |
| 35 | |
| 36 | qputenv("QT_LOGGING_RULES", strDebug.toLatin1()); |
| 37 | QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); |
| 38 | Utils::initResource(); |
| 39 | |
| 40 | QCoreApplication a(argc, argv); |
| 41 | a.setOrganizationName("deepin"); |
| 42 | a.setApplicationName("deepin-boot-maker-service"); |
| 43 | BootMakerService service; |
| 44 | |
| 45 | const QString m_format = "%{time}{yyyyMMdd.HH:mm:ss.zzz}[%{type:1}][%{function:-35} %{line:-4} %{threadid} ] %{message}\n"; |
| 46 | DBMLogManager::setSystemLog(true); |
| 47 | DBMLogManager::setLogFormat(m_format); |
| 48 | DBMLogManager::registerFileAppender(); |
| 49 | DBMLogManager::registerConsoleAppender(); |
| 50 | |
| 51 | qDebug() << "write log to" << DBMLogManager::getlogFilePath(); |
| 52 | qDebug() << PATH; |
| 53 | |
| 54 | auto systemBus = QDBusConnection::systemBus(); |
| 55 | if (!systemBus.registerService(BootMakerServiceName)) { |
| 56 | qCritical() << "registerService failed:" << systemBus.lastError(); |
| 57 | exit(0x0001); |
| 58 | } |
| 59 | |
| 60 | if (!systemBus.registerObject(BootMakerPath, |
| 61 | &service, |
| 62 | QDBusConnection::ExportAllSlots | |
| 63 | QDBusConnection::ExportAllSignals)) { |
| 64 | qCritical() << "registerObject failed:" << systemBus.lastError(); |
| 65 | exit(0x0002); |
| 66 | } |
| 67 | |
| 68 | return a.exec(); |
| 69 | } |