|
| 1 | +// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 |
| 3 | + |
| 4 | +#include "swiftdataapplication.h" |
| 5 | + |
| 6 | +#include <QtGlobal> |
| 7 | + |
| 8 | +#include "core/application.h" |
| 9 | +#include "core/corefacadeconfig.h" |
| 10 | +#include "core/coremodeenums.h" |
| 11 | +#include "misc/dbusserver.h" |
| 12 | +#include "misc/icons.h" |
| 13 | + |
| 14 | +using namespace swift::misc; |
| 15 | +using namespace swift::core; |
| 16 | + |
| 17 | +CSwiftDataApplication::CSwiftDataApplication() |
| 18 | + : CGuiApplication(CApplicationInfo::swiftMappingTool(), CApplicationInfo::MappingTool, CIcons::swiftDatabase48()) |
| 19 | +//: CGuiApplication(CApplicationInfo::swiftPilotClientGui(), CApplicationInfo::PilotClientGui, CIcons::swift1024()) |
| 20 | + |
| 21 | +{ |
| 22 | + this->addParserOption(m_cmdFacadeMode); |
| 23 | + this->addDBusAddressOption(); |
| 24 | + this->addNetworkOptions(); |
| 25 | + this->addAudioOptions(); |
| 26 | +} |
| 27 | + |
| 28 | +CStatusMessageList CSwiftDataApplication::startHookIn() |
| 29 | +{ |
| 30 | + Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Not yet parsed cmd line arguments"); |
| 31 | + |
| 32 | + QString dBusAddress(this->getCmdDBusAddressValue()); |
| 33 | + const QString coreModeStr = |
| 34 | + this->isParserOptionSet(m_cmdFacadeMode) ? this->getParserValue(m_cmdFacadeMode) : QString(); |
| 35 | + CoreModes::CoreMode coreMode = CoreModes::stringToCoreMode(coreModeStr); |
| 36 | + |
| 37 | + // Valid combination? |
| 38 | + if (!coreModeStr.isEmpty()) |
| 39 | + { |
| 40 | + if (coreMode == CoreModes::Standalone && !dBusAddress.isEmpty()) |
| 41 | + { |
| 42 | + const CStatusMessage m = |
| 43 | + CStatusMessage(this, CLogCategories::validation()).error(u"Inconsistent pair DBus: '%1' and core: '%2'") |
| 44 | + << dBusAddress << coreModeStr; |
| 45 | + return CStatusMessageList(m); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + // Implicit configuration |
| 50 | + CStatusMessageList msgs; |
| 51 | + if (!dBusAddress.isEmpty() && coreModeStr.isEmpty()) |
| 52 | + { |
| 53 | + coreMode = CoreModes::Distributed; // default |
| 54 | + const CStatusMessage m = |
| 55 | + CStatusMessage(this, CLogCategories::validation()).info(u"No DBus address, setting core mode: '%1'") |
| 56 | + << CoreModes::coreModeToString(coreMode); |
| 57 | + msgs.push_back(m); |
| 58 | + } |
| 59 | + else if (dBusAddress.isEmpty() && coreMode == CoreModes::Distributed) |
| 60 | + { |
| 61 | + dBusAddress = CDBusServer::sessionBusAddress(); // a possible default |
| 62 | + const CStatusMessage m = |
| 63 | + CStatusMessage(this, CLogCategories::validation()).info(u"Setting DBus address to '%1'") << dBusAddress; |
| 64 | + msgs.push_back(m); |
| 65 | + } |
| 66 | + |
| 67 | + CCoreFacadeConfig runtimeConfig = coreModeToCoreFacadeConfig(coreMode, dBusAddress); |
| 68 | + const CStatusMessageList contextMsgs = this->initContextsAndStartCoreFacade(runtimeConfig); |
| 69 | + //const CStatusMessageList contextMsgs = { CStatusMessage(this, CLogCategories::validation()).info(u"TEST") }; |
| 70 | + msgs.push_back(contextMsgs); |
| 71 | + return contextMsgs; |
| 72 | +} |
| 73 | + |
| 74 | +bool CSwiftDataApplication::parsingHookIn() |
| 75 | +{ |
| 76 | + // Parse core relevant arguments |
| 77 | + const QString dBusAddress(this->getCmdDBusAddressValue()); |
| 78 | + if (!dBusAddress.isEmpty()) |
| 79 | + { |
| 80 | + // check if reachable |
| 81 | + if (!CDBusServer::isDBusAvailable(dBusAddress)) |
| 82 | + { |
| 83 | + this->cmdLineErrorMessage("DBus error", "DBus server at '" + dBusAddress + "' can not be reached"); |
| 84 | + return false; |
| 85 | + } |
| 86 | + } |
| 87 | + return CGuiApplication::parsingHookIn(); |
| 88 | +} |
| 89 | + |
| 90 | +CSwiftDataApplication *CSwiftDataApplication::instance() |
| 91 | +{ |
| 92 | + return qobject_cast<CSwiftDataApplication *>(CApplication::instance()); |
| 93 | +} |
| 94 | + |
| 95 | +CCoreFacadeConfig CSwiftDataApplication::coreModeToCoreFacadeConfig(CoreModes::CoreMode coreMode, |
| 96 | + const QString &dBusAddress) |
| 97 | +{ |
| 98 | + switch (coreMode) |
| 99 | + { |
| 100 | + case CoreModes::Distributed: return CCoreFacadeConfig(CCoreFacadeConfig::Remote, dBusAddress); |
| 101 | + case CoreModes::Standalone: return CCoreFacadeConfig(CCoreFacadeConfig::Local, dBusAddress); break; |
| 102 | + default: |
| 103 | + Q_ASSERT_X(false, Q_FUNC_INFO, "Not handled core mode"); |
| 104 | + return CCoreFacadeConfig(CCoreFacadeConfig::NotUsed, dBusAddress); |
| 105 | + } |
| 106 | +} |
0 commit comments