swift
swiftguistdapplication.cpp
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 
5 
6 #include <QtGlobal>
7 
8 #include "core/application.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 
18  : CGuiApplication(CApplicationInfo::swiftPilotClientGui(), CApplicationInfo::PilotClientGui, CIcons::swift1024())
19 {
20  this->addParserOption(m_cmdFacadeMode);
21  this->addDBusAddressOption();
22  this->addNetworkOptions();
23  this->addAudioOptions();
24 }
25 
27 {
28  Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Not yet parsed cmd line arguments");
29 
30  QString dBusAddress(this->getCmdDBusAddressValue());
31  const QString coreModeStr =
32  this->isParserOptionSet(m_cmdFacadeMode) ? this->getParserValue(m_cmdFacadeMode) : QString();
33  CoreModes::CoreMode coreMode = CoreModes::stringToCoreMode(coreModeStr);
34 
35  // Valid combination?
36  if (!coreModeStr.isEmpty())
37  {
38  if (coreMode == CoreModes::Standalone && !dBusAddress.isEmpty())
39  {
40  const CStatusMessage m =
41  CStatusMessage(this, CLogCategories::validation()).error(u"Inconsistent pair DBus: '%1' and core: '%2'")
42  << dBusAddress << coreModeStr;
43  return CStatusMessageList(m);
44  }
45  }
46 
47  // Implicit configuration
48  CStatusMessageList msgs;
49  if (!dBusAddress.isEmpty() && coreModeStr.isEmpty())
50  {
51  coreMode = CoreModes::Distributed; // default
52  const CStatusMessage m =
53  CStatusMessage(this, CLogCategories::validation()).info(u"No DBus address, setting core mode: '%1'")
54  << CoreModes::coreModeToString(coreMode);
55  msgs.push_back(m);
56  }
57  else if (dBusAddress.isEmpty() && coreMode == CoreModes::Distributed)
58  {
59  dBusAddress = CDBusServer::sessionBusAddress(); // a possible default
60  const CStatusMessage m =
61  CStatusMessage(this, CLogCategories::validation()).info(u"Setting DBus address to '%1'") << dBusAddress;
62  msgs.push_back(m);
63  }
64 
65  CCoreFacadeConfig runtimeConfig = coreModeToCoreFacadeConfig(coreMode, dBusAddress);
66  const CStatusMessageList contextMsgs = this->initContextsAndStartCoreFacade(runtimeConfig);
67  msgs.push_back(contextMsgs);
68  return contextMsgs;
69 }
70 
72 {
73  // Parse core relevant arguments
74  const QString dBusAddress(this->getCmdDBusAddressValue());
75  if (!dBusAddress.isEmpty())
76  {
77  // check if reachable
78  if (!CDBusServer::isDBusAvailable(dBusAddress))
79  {
80  this->cmdLineErrorMessage("DBus error", "DBus server at '" + dBusAddress + "' can not be reached");
81  return false;
82  }
83  }
84  return CGuiApplication::parsingHookIn();
85 }
86 
88 {
89  return qobject_cast<CSwiftGuiStdApplication *>(CApplication::instance());
90 }
91 
92 CCoreFacadeConfig CSwiftGuiStdApplication::coreModeToCoreFacadeConfig(CoreModes::CoreMode coreMode,
93  const QString &dBusAddress)
94 {
95  switch (coreMode)
96  {
97  case CoreModes::Distributed: return CCoreFacadeConfig(CCoreFacadeConfig::Remote, dBusAddress);
98  case CoreModes::Standalone: return CCoreFacadeConfig(CCoreFacadeConfig::Local, dBusAddress); break;
99  default:
100  Q_ASSERT_X(false, Q_FUNC_INFO, "Not handled core mode");
101  return CCoreFacadeConfig(CCoreFacadeConfig::NotUsed, dBusAddress);
102  }
103 }
Specialized GUI application for swift pilot client.
CSwiftGuiStdApplication * instance()
Single instance.
virtual bool parsingHookIn()
Parsing of special CMD args.
virtual swift::misc::CStatusMessageList startHookIn()
Start facade by cmd arguments.
QString getParserValue(const QString &option) const
Delegates to QCommandLineParser::value.
void addAudioOptions()
Add the audio options.
void addNetworkOptions()
Add the network options.
bool m_parsed
Parsing accomplished?
Definition: application.h:576
bool isParserOptionSet(const QString &option) const
Delegates to QCommandLineParser::isSet.
QString getCmdDBusAddressValue() const
DBus address from CMD line, otherwise "".
void addDBusAddressOption()
CMD line argument for DBus address.
swift::misc::CStatusMessageList initContextsAndStartCoreFacade(const CCoreFacadeConfig &coreConfig)
Init the contexts part and start core facade.
bool addParserOption(const QCommandLineOption &option)
Configuration object for the contexts.
void cmdLineErrorMessage(const QString &text, const QString &informativeText) const
print messages generated during parsing / cmd handling
Description of a swift application.
Standard icons.
Definition: icons.h:25
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
Free functions in swift::misc.
CoreMode
Core runs how and where?
Definition: coremodeenums.h:18