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