mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 13:55:36 +08:00
refs #649, enum to specify which swift application is running
(remark: used to check which caches will be used)
This commit is contained in:
@@ -61,14 +61,14 @@ using namespace BlackMisc::Simulation;
|
|||||||
using namespace BlackMisc::Weather;
|
using namespace BlackMisc::Weather;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
using namespace BlackCore::Data;
|
using namespace BlackCore::Data;
|
||||||
|
using namespace BlackCore::Db;
|
||||||
|
|
||||||
BlackCore::CApplication *sApp = nullptr; // set by constructor
|
BlackCore::CApplication *sApp = nullptr; // set by constructor
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
CApplication::CApplication(
|
CApplication::CApplication(const QString &applicationName, SwiftApplication application, bool init) :
|
||||||
const QString &applicationName, bool init) :
|
m_cookieManager( {}, this), m_applicationName(applicationName), m_application(application), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
||||||
m_cookieManager( {}, this), m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!sApp, Q_FUNC_INFO, "already initialized");
|
Q_ASSERT_X(!sApp, Q_FUNC_INFO, "already initialized");
|
||||||
Q_ASSERT_X(QCoreApplication::instance(), Q_FUNC_INFO, "no application object");
|
Q_ASSERT_X(QCoreApplication::instance(), Q_FUNC_INFO, "no application object");
|
||||||
@@ -139,6 +139,20 @@ namespace BlackCore
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CApplication::SwiftApplication CApplication::getSwiftApplication() const
|
||||||
|
{
|
||||||
|
if (this->m_application != Unknown) { return this->m_application; }
|
||||||
|
|
||||||
|
// if not set, guess
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, "Missing application");
|
||||||
|
const QString a(QCoreApplication::instance()->applicationName().toLower());
|
||||||
|
if (a.contains("core")) { return PilotClientCore; }
|
||||||
|
if (a.contains("launcher")) { return Laucher; }
|
||||||
|
if (a.contains("gui")) { return PilotClientGui; }
|
||||||
|
if (a.contains("core")) { return PilotClientCore; }
|
||||||
|
return Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
CGlobalSetup CApplication::getGlobalSetup() const
|
CGlobalSetup CApplication::getGlobalSetup() const
|
||||||
{
|
{
|
||||||
const CSetupReader *r = this->m_setupReader.data();
|
const CSetupReader *r = this->m_setupReader.data();
|
||||||
@@ -349,6 +363,7 @@ namespace BlackCore
|
|||||||
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
||||||
QNetworkRequest r(request); // no QObject
|
QNetworkRequest r(request); // no QObject
|
||||||
CNetworkUtils::ignoreSslVerification(r);
|
CNetworkUtils::ignoreSslVerification(r);
|
||||||
|
CNetworkUtils::setSwiftUserAgent(r);
|
||||||
QNetworkReply *reply = this->m_accessManager.get(r);
|
QNetworkReply *reply = this->m_accessManager.get(r);
|
||||||
if (callback)
|
if (callback)
|
||||||
{
|
{
|
||||||
@@ -371,6 +386,7 @@ namespace BlackCore
|
|||||||
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
||||||
QNetworkRequest r(request);
|
QNetworkRequest r(request);
|
||||||
CNetworkUtils::ignoreSslVerification(r);
|
CNetworkUtils::ignoreSslVerification(r);
|
||||||
|
CNetworkUtils::setSwiftUserAgent(r);
|
||||||
QNetworkReply *reply = this->m_accessManager.post(r, data);
|
QNetworkReply *reply = this->m_accessManager.post(r, data);
|
||||||
if (callback)
|
if (callback)
|
||||||
{
|
{
|
||||||
@@ -393,6 +409,7 @@ namespace BlackCore
|
|||||||
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
Q_ASSERT_X(QThread::currentThread() == m_accessManager.thread(), Q_FUNC_INFO, "Network manager thread mismatch");
|
||||||
QNetworkRequest r(request);
|
QNetworkRequest r(request);
|
||||||
CNetworkUtils::ignoreSslVerification(r);
|
CNetworkUtils::ignoreSslVerification(r);
|
||||||
|
CNetworkUtils::setSwiftUserAgent(r);
|
||||||
QNetworkReply *reply = this->m_accessManager.post(r, multiPart);
|
QNetworkReply *reply = this->m_accessManager.post(r, multiPart);
|
||||||
if (callback)
|
if (callback)
|
||||||
{
|
{
|
||||||
@@ -454,13 +471,13 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (!this->m_useWebData)
|
if (!this->m_useWebData)
|
||||||
{
|
{
|
||||||
bool s = this->useWebDataServices(CWebReaderFlags::AllReaders, CWebReaderFlags::FromCache);
|
bool s = this->useWebDataServices(CWebReaderFlags::AllReaders, CDatabaseReaderConfigList::forPilotClient());
|
||||||
if (!s) { return false; }
|
if (!s) { return false; }
|
||||||
}
|
}
|
||||||
return this->startCoreFacade(); // will do nothing if setup is not yet loaded
|
return this->startCoreFacade(); // will do nothing if setup is not yet loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReader, CWebReaderFlags::DbReaderHint hint)
|
bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReader, const CDatabaseReaderConfigList &dbReaderConfig)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(this->m_webDataServices.isNull(), Q_FUNC_INFO, "Services already started");
|
Q_ASSERT_X(this->m_webDataServices.isNull(), Q_FUNC_INFO, "Services already started");
|
||||||
BLACK_VERIFY_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "No SSL");
|
BLACK_VERIFY_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "No SSL");
|
||||||
@@ -471,7 +488,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->m_webReader = webReader;
|
this->m_webReader = webReader;
|
||||||
this->m_dbReaderHint = hint;
|
this->m_dbReaderConfig = dbReaderConfig;
|
||||||
this->m_useWebData = true;
|
this->m_useWebData = true;
|
||||||
return this->startWebDataServices();
|
return this->startWebDataServices();
|
||||||
}
|
}
|
||||||
@@ -505,7 +522,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
CLogMessage(this).info("Will start web data services now");
|
CLogMessage(this).info("Will start web data services now");
|
||||||
this->m_webDataServices.reset(
|
this->m_webDataServices.reset(
|
||||||
new CWebDataServices(this->m_webReader, this->m_dbReaderHint, {}, this)
|
new CWebDataServices(this->m_webReader, this->m_dbReaderConfig, {}, this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -899,5 +916,4 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
return CUrlList();
|
return CUrlList();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "blackcore/corefacadeconfig.h"
|
#include "blackcore/corefacadeconfig.h"
|
||||||
#include "blackcore/data/globalsetup.h"
|
#include "blackcore/data/globalsetup.h"
|
||||||
#include "blackcore/data/updateinfo.h"
|
#include "blackcore/data/updateinfo.h"
|
||||||
|
#include "blackcore/db/databasereaderconfig.h"
|
||||||
#include "blackcore/webreaderflags.h"
|
#include "blackcore/webreaderflags.h"
|
||||||
#include "blackmisc/network/url.h"
|
#include "blackmisc/network/url.h"
|
||||||
#include "blackmisc/network/urllist.h"
|
#include "blackmisc/network/urllist.h"
|
||||||
@@ -78,6 +79,16 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//! Shich swift application is running?
|
||||||
|
enum SwiftApplication
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
Laucher,
|
||||||
|
PilotClientCore,
|
||||||
|
PilotClientGui,
|
||||||
|
MappingTool
|
||||||
|
};
|
||||||
|
|
||||||
//! Similar to \sa QCoreApplication::instance() returns the single instance
|
//! Similar to \sa QCoreApplication::instance() returns the single instance
|
||||||
static CApplication *instance();
|
static CApplication *instance();
|
||||||
|
|
||||||
@@ -85,7 +96,7 @@ namespace BlackCore
|
|||||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CApplication(const QString &applicationName = executable(), bool init = true);
|
CApplication(const QString &applicationName = executable(), SwiftApplication application = Unknown, bool init = true);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CApplication();
|
virtual ~CApplication();
|
||||||
@@ -96,6 +107,9 @@ namespace BlackCore
|
|||||||
//! Version, name beta and dev info
|
//! Version, name beta and dev info
|
||||||
const QString &getApplicationNameVersionBetaDev() const;
|
const QString &getApplicationNameVersionBetaDev() const;
|
||||||
|
|
||||||
|
//! swift application running
|
||||||
|
SwiftApplication getSwiftApplication() const;
|
||||||
|
|
||||||
//! Global setup
|
//! Global setup
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
BlackCore::Data::CGlobalSetup getGlobalSetup() const;
|
BlackCore::Data::CGlobalSetup getGlobalSetup() const;
|
||||||
@@ -220,7 +234,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Init web data services and start them
|
//! Init web data services and start them
|
||||||
//! \sa webDataServicesStarted
|
//! \sa webDataServicesStarted
|
||||||
bool useWebDataServices(const CWebReaderFlags::WebReader webReader, CWebReaderFlags::DbReaderHint hint);
|
bool useWebDataServices(const CWebReaderFlags::WebReader webReader, const BlackCore::Db::CDatabaseReaderConfigList &dbReaderConfig);
|
||||||
|
|
||||||
//! Get the facade
|
//! Get the facade
|
||||||
CCoreFacade *getCoreFacade() { return m_coreFacade.data(); }
|
CCoreFacade *getCoreFacade() { return m_coreFacade.data(); }
|
||||||
@@ -377,10 +391,11 @@ namespace BlackCore
|
|||||||
QNetworkAccessManager m_accessManager { this }; //!< single network access manager
|
QNetworkAccessManager m_accessManager { this }; //!< single network access manager
|
||||||
CCookieManager m_cookieManager; //!< single cookie manager for our access manager
|
CCookieManager m_cookieManager; //!< single cookie manager for our access manager
|
||||||
QString m_applicationName; //!< application name
|
QString m_applicationName; //!< application name
|
||||||
|
SwiftApplication m_application = Unknown; //!< Application if specified
|
||||||
QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe
|
QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe
|
||||||
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
||||||
CWebReaderFlags::WebReader m_webReader; //!< Readers used
|
CWebReaderFlags::WebReader m_webReader; //!< Readers used
|
||||||
CWebReaderFlags::DbReaderHint m_dbReaderHint; //!< Load or used caching?
|
BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< Load or used caching?
|
||||||
std::atomic<bool> m_shutdown { false }; //!< is being shutdown?
|
std::atomic<bool> m_shutdown { false }; //!< is being shutdown?
|
||||||
bool m_useContexts = false; //!< use contexts
|
bool m_useContexts = false; //!< use contexts
|
||||||
bool m_useWebData = false; //!< use web data
|
bool m_useWebData = false; //!< use web data
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ namespace BlackGui
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGuiApplication::CGuiApplication(const QString &applicationName, const QPixmap &icon) :
|
CGuiApplication::CGuiApplication(const QString &applicationName, SwiftApplication application, const QPixmap &icon) :
|
||||||
CApplication(applicationName, false)
|
CApplication(applicationName, application, false)
|
||||||
{
|
{
|
||||||
if (!sGui)
|
if (!sGui)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace BlackGui
|
|||||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CGuiApplication(const QString &applicationName = executable(), const QPixmap &icon = BlackMisc::CIcons::swift64());
|
CGuiApplication(const QString &applicationName = executable(), SwiftApplication application = Unknown, const QPixmap &icon = BlackMisc::CIcons::swift64());
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CGuiApplication();
|
virtual ~CGuiApplication();
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
|
|||||||
//! [CSwiftGuiStdApplication]
|
//! [CSwiftGuiStdApplication]
|
||||||
CGuiApplication::highDpiScreenSupport();
|
CGuiApplication::highDpiScreenSupport();
|
||||||
QApplication qa(argc, argv);
|
QApplication qa(argc, argv);
|
||||||
CGuiApplication a("swift core", CIcons::swiftNova24());
|
CGuiApplication a("swift core", CGuiApplication::PilotClientCore, CIcons::swiftNova24());
|
||||||
a.addWindowStateOption();
|
a.addWindowStateOption();
|
||||||
a.addDBusAddressOption();
|
a.addDBusAddressOption();
|
||||||
a.addVatlibOptions();
|
a.addVatlibOptions();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
|
using namespace BlackCore::Db;
|
||||||
using namespace BlackGui;
|
using namespace BlackGui;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -25,8 +26,8 @@ int main(int argc, char *argv[])
|
|||||||
CGuiApplication::highDpiScreenSupport();
|
CGuiApplication::highDpiScreenSupport();
|
||||||
QApplication qa(argc, argv);
|
QApplication qa(argc, argv);
|
||||||
Q_UNUSED(qa);
|
Q_UNUSED(qa);
|
||||||
CGuiApplication a("swift mapping tool", CIcons::swiftDatabase48());
|
CGuiApplication a("swift mapping tool", CGuiApplication::MappingTool, CIcons::swiftDatabase48());
|
||||||
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, BlackCore::CWebReaderFlags::FromDb);
|
a.useWebDataServices(BlackCore::CWebReaderFlags::AllSwiftDbReaders, CDatabaseReaderConfigList::forMappingTool());
|
||||||
if (!a.start()) { return EXIT_FAILURE; }
|
if (!a.start()) { return EXIT_FAILURE; }
|
||||||
CSwiftData w;
|
CSwiftData w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ using namespace BlackMisc;
|
|||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
|
|
||||||
CSwiftGuiStdApplication::CSwiftGuiStdApplication() :
|
CSwiftGuiStdApplication::CSwiftGuiStdApplication() :
|
||||||
CGuiApplication("swift pilot client GUI", CIcons::swift1024())
|
CGuiApplication("swift pilot client GUI", CGuiApplication::PilotClientGui, CIcons::swift1024())
|
||||||
{
|
{
|
||||||
this->addParserOption(this->m_cmdFacadeMode);
|
this->addParserOption(this->m_cmdFacadeMode);
|
||||||
this->addWindowModeOption();
|
this->addWindowModeOption();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
|||||||
//! [CSwiftGuiStdApplication]
|
//! [CSwiftGuiStdApplication]
|
||||||
CGuiApplication::highDpiScreenSupport();
|
CGuiApplication::highDpiScreenSupport();
|
||||||
QApplication qa(argc, argv);
|
QApplication qa(argc, argv);
|
||||||
CGuiApplication a("swift launcher", CIcons::swift1024());
|
CGuiApplication a("swift launcher", CGuiApplication::Laucher, CIcons::swift1024());
|
||||||
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup."), "installer"});
|
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup."), "installer"});
|
||||||
a.parse();
|
a.parse();
|
||||||
//! [CSwiftGuiStdApplication]
|
//! [CSwiftGuiStdApplication]
|
||||||
|
|||||||
Reference in New Issue
Block a user