9#include <QCoreApplication>
13#include <QHttpMultiPart>
14#include <QNetworkReply>
15#include <QNetworkRequest>
17#include <QRegularExpression>
19#include <QStandardPaths>
20#include <QStringBuilder>
23#include <QTemporaryDir>
26#include <QWriteLocker>
58using namespace swift::config;
60using namespace swift::misc::db;
61using namespace swift::misc::network;
62using namespace swift::misc::aviation;
63using namespace swift::misc::simulation;
64using namespace swift::misc::weather;
66using namespace swift::core::context;
67using namespace swift::core::vatsim;
74static const QString &swiftDataRoot()
91 Q_ASSERT_X(!sApp, Q_FUNC_INFO,
"already initialized");
132 this->tagApplicationDataDirectory();
161 m_inputManager->createDevices();
167 CLogMessage(cat).
debug(u
"Worker named '%1' still exists after application destroyed")
168 << worker->objectName();
213 Q_ASSERT_X(
instance(), Q_FUNC_INFO,
"missing application");
292 if (!m_gitHubPackagesReader)
296 return m_gitHubPackagesReader->getUpdateInfo();
305 if (!m_gitHubPackagesReader)
309 m_gitHubPackagesReader->readUpdateInfo();
326 Q_ASSERT_X(
m_parsed, Q_FUNC_INFO,
"Call this function after parsing");
344 if (!sApp || sApp->isShuttingDown())
348 this->simulateCrash();
352 Q_ASSERT_X(m_setupReader && m_setupReader->isSetupAvailable(), Q_FUNC_INFO,
"Setup not available");
362 msgs.
push_back(this->initLocalSettings());
391 return m_setupReader->isSetupAvailable();
396 return (this->
getGlobalSetup().isSwiftVersionMinimumMappingVersion());
405 return !m_webDataServices.isNull();
413 Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO,
414 "Missing web data services, use hasWebDataServices to test if existing");
415 return m_webDataServices.data();
450 bool CApplication::initIsRunningInDeveloperEnvironment()
const
471 if (m_localSettingsLoaded)
475 m_localSettingsLoaded =
true;
520 return tempDir.
path();
541 str += (separator % u
"Supporting contexts");
551 return this->
getFromNetwork(url, callback, progress, maxRedirects);
570 return this->
getFromNetwork(request, callback, progress, maxRedirects);
584 return this->httpRequestImpl(request, logId, callback, progress, maxRedirects,
595 return this->httpRequestImpl(request, logId, callback, progress, maxRedirects,
605 return this->httpRequestImpl(request, logId, callback,
NoRedirects,
621 return httpRequestImpl(request, logId, callback,
NoRedirects,
632 nr = qam.
post(request, multiPart);
646 return httpRequestImpl(
677 << url.
getFullUrl() << nwReply->errorString();
685 u
"Saving file '%1' downloaded from '%2' failed")
690 if (!sApp || sApp->isShuttingDown())
698 ProgressSlot progressSlot(
this, [=](
int, qint64, qint64,
const QUrl &) {
702 QNetworkReply *reply = this->getFromNetwork(url, callbackSlot, progressSlot, maxRedirects);
729 for (
const QString &arg : args)
773 if (sApp && sApp->isShuttingDown())
785 Q_ASSERT_X(
m_parsed, Q_FUNC_INFO,
"Call this function after parsing");
787 m_coreFacadeConfig = coreConfig;
796 if (!m_webDataServices)
810 Q_ASSERT_X(
m_parsed, Q_FUNC_INFO,
"Call this function after parsing");
825 Q_ASSERT_X(m_webDataServices.isNull(), Q_FUNC_INFO,
"Services already started");
848 Q_ASSERT_X(
m_parsed, Q_FUNC_INFO,
"Call this function after parsing");
850 if (!m_setupReader || !m_setupReader->isSetupAvailable())
855 Q_ASSERT_X(m_coreFacade.isNull(), Q_FUNC_INFO,
"Cannot alter facade");
856 Q_ASSERT_X(m_setupReader, Q_FUNC_INFO,
"No facade without setup possible");
857 Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO,
"Need running web data services");
860 m_coreFacade.reset(
new CCoreFacade(m_coreFacadeConfig));
868 Q_ASSERT_X(
m_parsed, Q_FUNC_INFO,
"Call this function after parsing");
870 if (!m_setupReader || !m_setupReader->isSetupAvailable())
875 Q_ASSERT_X(m_setupReader, Q_FUNC_INFO,
"No web data services without setup possible");
877 if (!m_webDataServices)
880 m_webDataServices.reset(
new CWebDataServices(webReader, dbReaderConfig,
this));
881 Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO,
"Missing web services");
893 void CApplication::initLogging()
906 void CApplication::initParser()
909 m_parser.setApplicationDescription(m_applicationName);
910 m_cmdHelp = m_parser.addHelpOption();
911 m_cmdVersion = m_parser.addVersionOption();
912 m_allOptions.append(m_cmdHelp);
913 m_allOptions.append(m_cmdVersion);
918 this->addParserOption(m_cmdDevelopment);
923 this->addParserOption(m_cmdSkipSingleApp);
926 m_cmdClearCache = QCommandLineOption({
"ccache",
"clearcache" },
928 this->addParserOption(m_cmdClearCache);
931 m_cmdTestCrashpad = QCommandLineOption(
933 this->addParserOption(m_cmdTestCrashpad);
972 CLogMessage(
this).
info(u
"Graceful shutdown of CApplication, released devices");
973 m_inputManager->releaseDevices();
977 if (
m_parsed && m_saveSettingsOnShutdown)
989 CLogMessage(
this).
info(u
"Graceful shutdown of CApplication, shutdown of contexts");
992 m_coreFacade->gracefulShutdown();
993 m_coreFacade.reset();
996 if (m_webDataServices)
998 CLogMessage(
this).
info(u
"Graceful shutdown of CApplication, shutdown of web services");
1000 m_webDataServices->gracefulShutdown();
1001 m_webDataServices.reset();
1004 if (m_gitHubPackagesReader)
1006 m_gitHubPackagesReader.reset();
1011 m_setupReader.reset();
1014 CLogMessage(
this).
info(u
"Graceful shutdown of CApplication, shutdown of logger");
1015 m_fileLogger->close();
1033 void CApplication::initNetwork()
1035 if (!m_accessManager)
1041 m_cookieManager->setParent(m_accessManager);
1042 m_accessManager->setCookieJar(m_cookieManager);
1045 Q_ASSERT_X(m_accessManager, Q_FUNC_INFO,
"Need QAM");
1075 return m_parser.addOptions(options);
1081 {
"dbus",
"dbusaddress" },
1110 return m_parser.value(option).trimmed();
1115 if (!this->startupCheck())
return false;
1116 if (!this->parseCommandLineArguments())
return false;
1117 if (!this->loadSetupAndHandleErrors())
return false;
1121 bool CApplication::parseCommandLineArguments()
1130 if (!m_parser.parse(args))
1132 this->cmdLineErrorMessage(
"Parser error:", m_parser.errorText());
1136 if (m_alreadyRunning && !this->skipSingleApplicationCheck())
1138 this->cmdLineErrorMessage(
"Program must only run once",
1139 "You cannot run two or more instances side-by-side.");
1144 if (m_parser.isSet(m_cmdHelp))
1147 this->cmdLineHelpMessage();
1150 if (m_parser.isSet(m_cmdVersion))
1153 this->cmdLineVersionMessage();
1158 m_devFlag = this->initIsRunningInDeveloperEnvironment();
1161 if (!this->parsingHookIn())
1171 bool CApplication::startupCheck()
const
1174 if (!verifyErrors.
isEmpty() && !m_applicationInfo.isUnitTest())
1176 cmdLineErrorMessage(
"Missing runtime directories/files:", verifyErrors.
join(
", "));
1182 bool CApplication::loadSetupAndHandleErrors()
1184 const CStatusMessageList msgs = loadSetup();
1188 displaySetupLoadFailure(msgs);
1201 fputs(qPrintable(text + informativeText), stderr);
1223 return this->
getCoreFacade()->getCContextSimulator()->simulator();
1239 void CApplication::cmdLineHelpMessage()
1241 m_parser.showHelp();
1245 void CApplication::cmdLineVersionMessage()
1247 m_parser.showVersion();
1270 toBeRemoved.
append(
"--installer");
1287 joinedArguments.
append(newArgumentsChecked);
1288 return joinedArguments;
1303 if (m_coreFacade.isNull())
1307 if (!m_coreFacade->getIContextApplication())
1311 return (!m_coreFacade->getIContextApplication()->isEmptyObject());
1338 return m_coreFacade->getCContextAudioBase();
1392 return m_coreFacade->getCContextAudioBase();
1445 Q_ASSERT_X(m_parsed, Q_FUNC_INFO,
"Not yet parsed");
1456 if (m_webDataServices)
1458 const CUrl url(m_webDataServices->getVatsimMetarUrl());
1466 return m_setupReader->getSetup().getVatsimMetarsUrl();
1477 if (m_webDataServices)
1479 const CUrl url(m_webDataServices->getVatsimDataFileUrl());
1487 return m_setupReader->getSetup().getVatsimDataFileUrl();
1499 return m_setupReader->getSetup().getVatsimServerFileUrl();
1509 return m_setupReader->getSetup().getVatsimFsdHttpUrl();
1512 void CApplication::onCrashDumpUploadEnabledChanged()
1515 this->enableCrashDumpUpload(enabled);
1526#ifdef SWIFT_USE_CRASHPAD
1533 void CApplication::httpRequestImplInQAMThread(
const QNetworkRequest &request,
int logId,
1534 const CallbackSlot &callback,
const ProgressSlot &progress,
1535 int maxRedirects, NetworkRequestOrPostFunction getPostOrDeleteRequest)
1538 if (this->isShuttingDown())
1544 if (!sApp || sApp->isShuttingDown())
1549 "Wrong thread, must be QAM thread");
1550 this->httpRequestImpl(request, logId, callback, progress, maxRedirects, getPostOrDeleteRequest);
1554 QNetworkReply *CApplication::httpRequestImpl(
const QNetworkRequest &request,
int logId,
1556 NetworkRequestOrPostFunction requestOrPostMethod)
1558 ProgressSlot progress;
1559 return this->httpRequestImpl(request, logId, callback, progress, maxRedirects, requestOrPostMethod);
1562 QNetworkReply *CApplication::httpRequestImpl(
const QNetworkRequest &request,
int logId,
1563 const CallbackSlot &callback,
const ProgressSlot &progress,
1564 int maxRedirects, NetworkRequestOrPostFunction getPostOrDeleteRequest)
1566 if (this->isShuttingDown())
1571 QWriteLocker locker(&m_accessManagerLock);
1572 Q_ASSERT_X(m_accessManager->thread() == qApp->thread(), Q_FUNC_INFO,
1573 "Network manager supposed to be in main thread");
1576 this->httpRequestImplInQAMThread(request, logId, callback, progress, maxRedirects, getPostOrDeleteRequest);
1581 QNetworkRequest copiedRequest =
1584 QNetworkReply *reply = getPostOrDeleteRequest(*m_accessManager, copiedRequest);
1587 const QUrl url(reply->
url());
1588 QString urlStr = url.toString();
1593 [=](qint64 current, qint64 max) { progress(logId, current, max, url); });
1598 Q_ASSERT_X(callback.object(), Q_FUNC_INFO,
"Need callback object (to determine thread)");
1607 const bool isRedirect = CNetworkUtils::isHttpStatusRedirect(reply);
1608 if (isRedirect && maxRedirects > 0)
1610 const QUrl redirectUrl = CNetworkUtils::getHttpRedirectUrl(reply);
1611 if (!redirectUrl.isEmpty())
1613 QNetworkRequest redirectRequest(redirectUrl);
1614 const int redirectsLeft = maxRedirects - 1;
1615 CLogMessage(sApp).info(u
"Redirecting '%1' to '%2'") << urlStr << redirectUrl.toString();
1616 this->httpRequestImplInQAMThread(redirectRequest, logId, callback, progress, redirectsLeft,
1617 getPostOrDeleteRequest);
1629 void CApplication::tagApplicationDataDirectory()
1633 if (!dir.exists() || !dir.isReadable())
1637 const QString aiStr(this->getApplicationInfo().toJsonString());
static const QString & getVersionString()
Version as QVersionNumber.
static constexpr bool isReleaseBuild()
Release build?
static constexpr bool isRunningOnUnixPlatform()
Running on Unix (Linux or Mac OS X) platform.
static constexpr bool isRunningOnMacOSPlatform()
Running on MacOS platform?
static bool isLocalDeveloperDebugBuild()
Local build for developers.
static constexpr bool isRunningOnWindowsNtPlatform()
Running on Windows NT platform?
static constexpr bool isRunningOnLinuxPlatform()
Running on Linux platform?
static const QString & compiledWithInfo()
Info string about compilation.
static const QString & getVersionStringPlatform()
Version as QVersionNumber plus platform info.
swift::misc::CStatusMessageList startCoreFacadeWithoutContexts()
Starts the core facade without any contexts.
static void argumentsWithoutOption(const QCommandLineOption &option, QStringList &args)
Arguments without that given option.
void aboutToShutdown()
About to shutdown.
QStringList argumentsJoined(const QStringList &newArguments={}, const QStringList &removeArguments={}) const
Current parameters replaced by new arguments without the cmd line argument.
const QString & versionStringDetailed() const
String with beta, dev. and version.
swift::misc::CSlot< void(QNetworkReply *)> CallbackSlot
The network reply callback when request is completed.
swift::misc::shared_state::CDataLinkDBus * getDataLinkDBus()
Transport mechanism for sharing state between applications.
swift::misc::CStatusMessageList startCoreFacade()
Start the core facade.
const context::IContextAudio * getIContextAudio() const
Direct access to contexts if a CCoreFacade has been initialized.
QString getParserValue(const QString &option) const
Delegates to QCommandLineParser::value.
~CApplication()
Destructor.
void addAudioOptions()
Add the audio options.
bool addParserOptions(const QList< QCommandLineOption > &options)
QNetworkReply * getFromNetwork(const swift::misc::network::CUrl &url, const CallbackSlot &callback, int maxRedirects=DefaultMaxRedirects)
Request to get network reply.
QNetworkReply * downloadFromNetwork(const swift::misc::network::CUrl &url, const QString &saveAsFileName, const swift::misc::CSlot< void(const swift::misc::CStatusMessage &)> &callback, int maxRedirects=DefaultMaxRedirects)
Download file from network and store it as passed.
bool hasSetupReader() const
Setup reader?
swift::misc::network::CUrl getVatsimServerFileUrl() const
Get URL to file which contains the list of VATSIM servers.
virtual void displaySetupLoadFailure(swift::misc::CStatusMessageList msgs)
Display the failures caused by loading the setup file.
const context::IContextOwnAircraft * getIContextOwnAircraft() const
Direct access to contexts if a CCoreFacade has been initialized.
std::atomic_bool m_shutdown
Is being shutdown?
QPointer< ISimulator > getISimulator() const
The simulator plugin, if available.
void restartApplication(const QStringList &newArguments={}, const QStringList &removeArguments={})
Stop and restart application.
bool hasSimulator() const
Simulator object available?
bool m_parsed
Parsing accomplished?
swift::misc::network::CUrl getVatsimMetarUrl() const
Consolidated version of METAR URLs, either from CGlobalSetup or CVatsimSetup.
bool isParserOptionSet(const QString &option) const
Delegates to QCommandLineParser::isSet.
static const QString & executable()
executable name
swift::misc::CStatusMessageList startWebDataServices(CWebReaderFlags::WebReader webReader, const db::CDatabaseReaderConfigList &dbReaderConfig)
Start the web data services.
data::CGlobalSetup getGlobalSetup() const
Global setup.
static constexpr int NoLogRequestId
network request without logging
bool isDeveloperFlagSet() const
Running with dev.flag?
swift::misc::db::CDistribution getOwnDistribution() const
Own distribution.
bool m_alreadyRunning
Application already running.
const char * swiftVersionChar()
swift info string
std::atomic_bool m_incognito
Incognito mode?
QCommandLineOption m_cmdClearCache
Clear cache.
const swift::misc::CApplicationInfo & getApplicationInfo() const
swift application running
const context::IContextApplication * getIContextApplication() const
Direct access to contexts if a CCoreFacade has been initialized.
QCommandLineOption m_cmdDBusAddress
DBus address.
virtual void onStartUpCompleted()
Startup completed.
swift::misc::CStatusMessageList initAndStartWebDataServices(CWebReaderFlags::WebReader webReader, const db::CDatabaseReaderConfigList &dbReaderConfig)
Init web data services and start them.
static bool unregisterAsRunning()
Unregister from running.
bool parseCommandLineArgsAndLoadSetup()
Combined function that does a startup check, parses the command line arguments and loads the setup.
QString getCmdDBusAddressValue() const
DBus address from CMD line, otherwise "".
bool skipSingleApplicationCheck() const
Skip the single application check.
QCommandLineParser m_parser
cmd parser
bool isIncognito() const
Is incognito mode?
static void processEventsFor(int milliseconds)
Process all events for some time.
bool hasUnsavedSettings() const
Unsaved settings.
QNetworkReply * postToNetwork(const QNetworkRequest &request, int logId, const QByteArray &data, const CallbackSlot &callback)
Post to network.
virtual void onCoreFacadeStarted()
Called when facade/contexts have been started.
const QString & swiftVersionString() const
swift info string
void coreFacadeStarted()
Facade started.
QList< QCommandLineOption > m_allOptions
All registered options.
void setIncognito(bool incognito)
Set incognito mode.
static QString getTemporaryDirectory()
Directory for temporary files.
void addDBusAddressOption()
CMD line argument for DBus address.
bool hasWebDataServices() const
Web data services available?
static const QStringList & getLogCategories()
Own log categories.
virtual void cmdLineErrorMessage(const QString &text, const QString &informativeText) const
Display error message.
void init(bool withMetadata)
Init class, allows to init from swift::gui::CGuiApplication as well (pseudo virtual).
swift::misc::network::CUrl getVatsimFsdHttpUrl() const
Get VATSIM FSD HTTP URL.
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
swift::misc::CStatusMessageList initContextsAndStartCoreFacade(const CCoreFacadeConfig &coreConfig)
Init the contexts part and start core facade.
void updateInfoAvailable(bool success)
Update info available (cache, web load).
swift::misc::CStatusMessage saveSettingsByKey(const QStringList &keys)
Save all settings.
CApplication(swift::misc::CApplicationInfo::Application application, bool init=true)
Constructor.
static void exit(int retcode=EXIT_SUCCESS)
Exit application, perform graceful shutdown and exit.
void deleteAllCookies()
Delete all cookies from cookie manager.
bool addParserOption(const QCommandLineOption &option)
bool isDBusContext() const
DBus application? (not Local).
QString getInfoString(const QString &separator) const
Comprehensive info.
bool isShuttingDown() const
Is application shutting down?
QNetworkReply * deleteResourceFromNetwork(const QNetworkRequest &request, int logId, const CallbackSlot &callback, int maxRedirects=DefaultMaxRedirects)
Request to delete a network resource from network, supporting swift::misc::network::CUrlLog.
static constexpr int NoRedirects
network request not allowing redirects
QCommandLineOption m_cmdDevelopment
Development flag.
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isSet(const QCommandLineOption &option) const
Flag set or explicitly set to true.
std::atomic_bool m_shutdownInProgress
shutdown in progress?
static swift::misc::CApplicationInfoList getRunningApplications()
Information about all running apps (including this one only if exec() has already been called).
QStringList getUnsavedSettingsKeys() const
All unsaved settings.
const QString & getApplicationNameVersionDetailed() const
Version, name beta and dev info.
void toggleIncognito()
Toggle incognito mode.
virtual swift::misc::CStatusMessageList startHookIn()
Can be used to start special services.
CSetupReader * getSetupReader() const
Access to setup reader.
static bool isApplicationRunning(swift::misc::CApplicationInfo::Application application)
Is application running?
CCoreFacade * getCoreFacade()
Get the facade.
bool m_started
Started with success?
swift::misc::db::CUpdateInfo getUpdateInfo() const
Update info.
swift::misc::network::CUrl getVatsimDataFileUrl() const
Consolidated version of data file URL, either from CGlobalSetup or CVatsimSetup.
QCommandLineOption m_cmdSkipSingleApp
Skip test for single application.
bool isSetupAvailable() const
Setup already synchronized.
static QStringList clearCaches()
Clear the caches.
void webDataServicesStarted(bool success)
Web data services started.
virtual bool start()
Start services, if not yet parsed call CApplication::parse.
const context::CContextAudioBase * getCContextAudioBase() const
Direct access to contexts if a CCoreFacade has been initialized.
bool supportsContexts(bool ignoreShutdownTest=false) const
Supports contexts.
static int indexOfCommandLineOption(const QCommandLineOption &option, const QStringList &args=CApplication::arguments())
Is the command line option represented in the given arguments?
void reloadUpdateInfo()
Reload update info.
swift::misc::CSlot< void(int, qint64, qint64, const QUrl &)> ProgressSlot
The progress slot.
CWebDataServices * getWebDataServices() const
Get the web data services.
int exec()
Finishes initialization and executes the event loop.
const QString & getApplicationNameAndVersion() const
Application name and version.
bool isLocalContext() const
Local application? (not DBus).
virtual void gracefulShutdown()
Graceful shutdown.
void enableCrashDumpUpload(bool enable)
Enable crash upload.
static QStringList arguments()
Similar to QCoreApplication::arguments.
void saveSettingsOnShutdown(bool saveSettings)
Save settings on shutdown.
QCommandLineOption m_cmdTestCrashpad
Test a crasphpad upload.
static void registerMetadata()
Register metadata.
bool isAlreadyRunning() const
True if this swift application is already running (including different versions).
virtual bool hasMinimumMappingVersion() const
Minimum mapping version check.
bool isSupportingCrashpad() const
Has crashpad support?
void startUpCompleted(bool success)
Startup has been completed Will be triggered shortly before starting the event loop.
QNetworkReply * headerFromNetwork(const swift::misc::network::CUrl &url, const CallbackSlot &callback, int maxRedirects=NoRedirects)
Request to get network repy using HTTP's HEADER method.
static CApplication * instance()
Similar to.
static bool registerAsRunning()
Register as running.
Threadsafe version of QNetworkCookieJar.
Configuration object for the contexts.
@ NotUsed
during shutdown or not used at all
@ Remote
context runs in a different process.
The class providing facades (the contexts) for all DBus relevant operations.
Read available updates from GitHub Packages REST API.
void updateInfoAvailable(bool available)
Updates have been received from GitHub Packages.
Read the central URLs / locations of our data, setup and versions.
data::CGlobalSetup getSetup() const
Current setup (reader URLs, DB location, crash server).
Encapsulates reading data from web sources.
Audio context base class.
static const QList< QCommandLineOption > & getCmdLineOptions()
Cmd.line arguments.
Application context interface.
virtual misc::CStatusMessage saveSettingsByKey(const QStringList &keys)=0
Save core settings to disk.
virtual QStringList getUnsavedSettingsKeys() const =0
Get keys of all unsaved settings currently in core settings cache.
const IContextSimulator * getIContextSimulator() const
Context for simulator.
IContextNetwork * getIContextNetwork()
Context for network.
const IContextApplication * getIContextApplication() const
Context for application.
IContextAudio * getIContextAudio()
Context for network.
IContextOwnAircraft * getIContextOwnAircraft()
Context for own aircraft.
Global settings for readers, debug flags, etc.
Value object encapsulating a list of reader configs.
static CDatabaseReaderConfigList forPilotClient()
Init for pilot client.
Description of a swift application.
Application getApplication() const
Get application.
static const QString & fileName()
File name of the application info file.
Application
Enumeration of application roles.
const CProcessInfo & getProcessInfo() const
Get process info.
List of swift application descriptions.
bool containsApplication(CApplicationInfo::Application application) const
List containing entry for CApplicationInfo::Application ?
QString toJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Indented) const
Convenience function JSON as string.
CStatusMessage convertFromJsonNoThrow(const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
Call convertFromJson, catch any CJsonException that is thrown and return it as CStatusMessage.
static CCrashHandler * instance()
Get singleton instance.
void setUploadsEnabled(bool enable)
Enable/disable automatic uploading.
void simulateAssert()
Simulate an ASSERT.
void simulateCrash()
Simulate a crash.
static QString normalizeAddress(const QString &address)
Turn something like 127.0.0.1:45000 into "tcp:host=127.0.0.1,port=45000".
static CDataCache * instance()
Return the singleton instance.
Class to write log messages to file.
void writeStatusMessageToFile(const swift::misc::CStatusMessage &statusMessage)
Write single status message to file.
static QString readLockedFileToString(const QString &fileNameAndPath)
Read file into string, with a lock so two applications can't access at the same time.
static bool writeStringToFile(const QString &content, const QString &fileNameAndPath)
Write string to text file.
static bool writeByteArrayToFile(const QByteArray &data, const QString &fileNameAndPath)
Write byte array to file.
static bool writeStringToLockedFile(const QString &content, const QString &fileNameAndPath)
Write string to file, with a lock so two applications can't access at the same time.
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
CIdentifiable(const QString &objectName)
Use literal based object name.
A sequence of log categories.
void localMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a message is logged in this process.
static CLogHandler * instance()
Return pointer to the CLogHandler singleton.
void remoteMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a log message is relayed from a different process.
void install(bool skipIfAlreadyInstalled=false)
Tell the CLogHandler to install itself with qInstallMessageHandler.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Value class for matching log messages based on their categories.
Derived & debug()
Set the severity to debug.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
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.
bool exists() const
True if this object identifies a process that exists.
bool containsBy(Predicate p) const
Return true if there is an element for which a given predicate returns true.
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
int removeIf(Predicate p)
Remove elements for which a given predicate returns true.
void push_back(const T &value)
Appends an element at the end of the sequence.
int remove(const T &object)
Remove all elements equal to the given object, if it is contained.
bool isEmpty() const
Synonym for empty.
CStatusMessage loadFromStore()
Load settings from disk.
void enableLocalSave()
Connects signal CValueCache::valuesSaveRequested to a private slot that saves the values....
static CSettingsCache * instance()
Return the singleton instance.
CStatusMessage saveToStore(const QString &keyPrefix={})
Save settings to disk.
Callable wrapper for a member function with function signature F.
Streamable status message, e.g.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
bool isFailure() const
Operation considered unsuccessful.
static constexpr auto SeverityDebug
Status severities.
Status messages, e.g. from Core -> GUI.
bool isFailure() const
Any message is marked as failure.
bool hasErrorMessages() const
Error messages.
bool isSuccess() const
All messages are marked as success.
static const QString & normalizedApplicationDataDirectory()
swift application data directory for one specific installation (a version)
static QStringList verifyRuntimeDirectoriesAndFiles()
Check if the (most important) runtime directories are available.
static bool isInThisThread(const QObject *toBeTested)
Is the current thread the object's thread?
void clearAllValues(const QString &keyPrefix={})
Clear all values from the cache.
QStringList getAllUnsavedKeys(const QString &keyPrefix={}) const
Return keys of all values which have been changed but not saved.
Base class for CWorker and CContinuousWorker.
static const QSet< CWorkerBase * > & allWorkers()
All workers currently existing.
Distributions for channel.
static const CDistribution & localDeveloperBuild()
Pseudo distribution for local builds.
Update info, i.e. artifacts and distributions.
CDistribution anticipateOwnDistribution() const
Own distribution.
QString toQString(bool i18n=false) const
Cast as QString.
static QNetworkRequest getSwiftNetworkRequest(const QUrl &url, RequestType type=Get, const QString &userAgentDetails={})
Our tweaked network request with swift header.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
bool isEmpty() const
Empty.
QNetworkRequest toNetworkRequest() const
To request.
QString getFullUrl(bool withQuery=true) const
Qualified name.
static const char * propertyNameId()
Property name used for request.
A transport mechanism using signals and slots distributed by DBus.
Core data traits (aka cached values) and classes.
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
void registerMetadata()
Register all relevant metadata in swift::core.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
SWIFT_MISC_EXPORT void setMockCacheRootDirectory(const QString &path)
Overwrite the default root directory for cache and settings, for testing purposes.
void registerMetadata()
Register all relevant metadata in Misc.
QString applicationName()
Get application name.
const char * constData() const const
QStringList names() const const
QString valueName() const const
QString applicationFilePath()
void setApplicationName(const QString &application)
void setApplicationVersion(const QString &version)
void exit(int returnCode)
QCoreApplication * instance()
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
qint64 currentMSecsSinceEpoch()
bool exists() const const
int exec(QEventLoop::ProcessEventsFlags flags)
void append(QList< T > &&value)
QList< T >::const_reference at(qsizetype i) const const
bool isEmpty() const const
void removeAt(qsizetype i)
qsizetype size() const const
bool startsWith(QList< T >::parameter_type value) const const
QNetworkReply * deleteResource(const QNetworkRequest &request)
QNetworkReply * get(const QNetworkRequest &request)
QNetworkReply * head(const QNetworkRequest &request)
QNetworkReply * post(const QNetworkRequest &request, QHttpMultiPart *multiPart)
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
QNetworkReply::NetworkError error() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
bool moveToThread(QThread *targetThread)
void setObjectName(QAnyStringView name)
void setParent(QObject *parent)
bool setProperty(const char *name, QVariant &&value)
QThread * thread() const const
bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid)
QString writableLocation(QStandardPaths::StandardLocation type)
bool isEmpty() const const
QString mid(qsizetype position, qsizetype n) &&
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QStringList filter(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
qsizetype removeDuplicates()
QString buildCpuArchitecture()
bool isValid() const const
QString path() const const
QFuture< QtFuture::ArgsType< Signal > > connect(Sender *sender, Signal signal)
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.