Ref T210, moved "guess" into CApplicationInfo

* core unit test, set correct type
* guess application type now in CApplicationInfo
This commit is contained in:
Klaus Basan
2017-12-19 21:02:38 +01:00
parent cb751306f8
commit 8b74acb3a9
5 changed files with 27 additions and 20 deletions

View File

@@ -102,7 +102,8 @@ namespace BlackCore
CApplication::CApplication(const QString &applicationName, CApplicationInfo::Application application, bool init) : CApplication::CApplication(const QString &applicationName, CApplicationInfo::Application application, bool init) :
m_accessManager(new QNetworkAccessManager(this)), m_accessManager(new QNetworkAccessManager(this)),
m_application(application), m_cookieManager( {}, this), m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty()) m_applicationInfo(application, QCoreApplication::applicationDirPath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess()),
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");
@@ -266,21 +267,7 @@ namespace BlackCore
m_singleApplication = singleApplication; m_singleApplication = singleApplication;
} }
CApplicationInfo::Application CApplication::getSwiftApplication() const
{
if (m_application != CApplicationInfo::Unknown) { return 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 CApplicationInfo::PilotClientCore; }
if (a.contains("launcher")) { return CApplicationInfo::Laucher; }
if (a.contains("gui")) { return CApplicationInfo::PilotClientGui; }
if (a.contains("test")) { return CApplicationInfo::UnitTest; }
if (a.contains("sample")) { return CApplicationInfo::Sample; }
if (a.contains("data") || a.contains("mapping")) { return CApplicationInfo::MappingTool; }
return CApplicationInfo::Unknown;
}
QString CApplication::getExecutableForApplication(CApplicationInfo::Application application) const QString CApplication::getExecutableForApplication(CApplicationInfo::Application application) const
{ {

View File

@@ -136,7 +136,7 @@ namespace BlackCore
void setSingleApplication(bool singleApplication); void setSingleApplication(bool singleApplication);
//! swift application running //! swift application running
BlackMisc::CApplicationInfo::Application getSwiftApplication() const; BlackMisc::CApplicationInfo::Application getSwiftApplication() const { return m_applicationInfo.application(); }
//! Executable names for the given applications //! Executable names for the given applications
QString getExecutableForApplication(BlackMisc::CApplicationInfo::Application application) const; QString getExecutableForApplication(BlackMisc::CApplicationInfo::Application application) const;
@@ -590,7 +590,7 @@ namespace BlackCore
std::function<QNetworkReply *(QNetworkAccessManager &, const QNetworkRequest &)> requestOrPostMethod); std::function<QNetworkReply *(QNetworkAccessManager &, const QNetworkRequest &)> requestOrPostMethod);
QNetworkAccessManager *m_accessManager = nullptr; //!< single network access manager QNetworkAccessManager *m_accessManager = nullptr; //!< single network access manager
BlackMisc::CApplicationInfo::Application m_application = BlackMisc::CApplicationInfo::Unknown; //!< Application if specified BlackMisc::CApplicationInfo m_applicationInfo; //!< Application if specified
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services

View File

@@ -17,10 +17,15 @@ namespace BlackMisc
CApplicationInfo::CApplicationInfo(Application app, const QString &exePath, const QString &version, const CProcessInfo &process) : CApplicationInfo::CApplicationInfo(Application app, const QString &exePath, const QString &version, const CProcessInfo &process) :
m_app(app), m_app(app),
m_exePath(exePath), m_exePath(exePath.isEmpty() ? QCoreApplication::applicationDirPath() : exePath),
m_version(version), m_version(version),
m_process(process) m_process(process)
{} {
if (app == CApplicationInfo::Unknown)
{
m_app = guessApplication();
}
}
bool CApplicationInfo::isSampleOrUnitTest() const bool CApplicationInfo::isSampleOrUnitTest() const
{ {
@@ -62,4 +67,16 @@ namespace BlackMisc
static const QString s("swift core"); static const QString s("swift core");
return s; return s;
} }
CApplicationInfo::Application CApplicationInfo::guessApplication()
{
const QString a(QCoreApplication::instance()->applicationName().toLower());
if (a.contains("test")) { return CApplicationInfo::UnitTest; } // names like testcore
if (a.contains("sample")) { return CApplicationInfo::Sample; }
if (a.contains("core")) { return CApplicationInfo::PilotClientCore; }
if (a.contains("launcher")) { return CApplicationInfo::Laucher; }
if (a.contains("gui")) { return CApplicationInfo::PilotClientGui; }
if (a.contains("data") || a.contains("mapping")) { return CApplicationInfo::MappingTool; }
return CApplicationInfo::Unknown;
}
} }

View File

@@ -93,6 +93,8 @@ namespace BlackMisc
QString m_version; QString m_version;
CProcessInfo m_process; CProcessInfo m_process;
static Application guessApplication();
BLACK_METACLASS( BLACK_METACLASS(
CApplicationInfo, CApplicationInfo,
BLACK_METAMEMBER(app), BLACK_METAMEMBER(app),

View File

@@ -19,6 +19,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
using namespace BlackMisc;
using namespace BlackCore; using namespace BlackCore;
using namespace BlackCoreTest; using namespace BlackCoreTest;
@@ -27,7 +28,7 @@ int main(int argc, char *argv[])
{ {
QCoreApplication qa(argc, argv); QCoreApplication qa(argc, argv);
Q_UNUSED(qa); Q_UNUSED(qa);
CApplication a; CApplication a(CApplicationInfo::UnitTest);
a.addVatlibOptions(); a.addVatlibOptions();
const bool setup = a.parseAndSynchronizeSetup(); const bool setup = a.parseAndSynchronizeSetup();
if (!setup) { qWarning() << "No setup loaded"; } if (!setup) { qWarning() << "No setup loaded"; }