refs #603, new CMD args, formerly passed by env.vars

* removed from CProject
* removed. env. vars menu items
* prepared for vatlib cmd. args
* prepared for eol (end of lifetime) timestamp (time bomb)
This commit is contained in:
Klaus Basan
2016-02-29 02:17:20 +01:00
committed by Mathew Sutcliffe
parent d7e5b5206c
commit f4cbfc2fa9
22 changed files with 264 additions and 240 deletions

View File

@@ -10,6 +10,7 @@
#include "application.h"
#include "blackcore/corefacade.h"
#include "blackcore/setupreader.h"
#include "blackcore/networkvatlib.h"
#include "blackcore/webdataservices.h"
#include "blackcore/contextapplication.h"
#include "blackcore/registermetadata.h"
@@ -22,6 +23,7 @@
#include "blackmisc/network/networkutils.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/verify.h"
#include "blackmisc/stringutils.h"
#include <QStandardPaths>
#include <QFile>
#include <QFileInfo>
@@ -93,9 +95,16 @@ namespace BlackCore
this->gracefulShutdown();
}
QString CApplication::getApplicationNameAndVersion() const
const QString &CApplication::getApplicationNameAndVersion() const
{
return QCoreApplication::instance()->applicationName() + " " + CProject::version();
static const QString s(QCoreApplication::instance()->applicationName() + " " + CProject::version());
return s;
}
const QString &CApplication::getApplicationNameVersionBetaDev() const
{
static const QString s(QCoreApplication::instance()->applicationName() + " " + this->versionStringDevBetaInfo());
return s;
}
Data::CGlobalSetup CApplication::getGlobalSetup() const
@@ -186,6 +195,76 @@ namespace BlackCore
return CThreadUtils::isCurrentThreadApplicationThread();
}
const QString &CApplication::versionStringDevBetaInfo() const
{
if (isRunningInDeveloperEnvironment() && CProject::isBetaTest())
{
static const QString s(CProject::version() + " [DEV, BETA]");
return s;
}
if (isRunningInDeveloperEnvironment())
{
static const QString s(CProject::version() + " [DEV]");
return s;
}
if (CProject::isBetaTest())
{
static const QString s(CProject::version() + " [BETA]");
return s;
}
return CProject::version();
}
const QString &CApplication::swiftVersionString() const
{
static const QString s(QString("swift %1").arg(versionStringDevBetaInfo()));
return s;
}
const char *CApplication::swiftVersionChar()
{
static const QByteArray a(swiftVersionString().toUtf8());
return a.constData();
}
bool CApplication::isRunningInDeveloperEnvironment() const
{
if (!CProject::canRunInDeveloperEnvironment()) { return false; }
if (!this->m_parser.value(this->m_cmdDevelopment).isEmpty())
{
// explicit value
const QString v(this->m_parser.value(this->m_cmdDevelopment));
return stringToBool(v);
}
else if (this->isSetupSyncronized())
{
// assume value from setup
return this->getGlobalSetup().isDevelopment();
}
return false;
}
QString CApplication::getEnvironmentInfoString(const QString &separator) const
{
QString env("Beta: ");
env.append(boolToYesNo(CProject::isBetaTest()));
env = env.append(" dev.env,: ").append(boolToYesNo(isRunningInDeveloperEnvironment()));
env = env.append(separator);
env.append("Windows: ").append(boolToYesNo(CProject::isRunningOnWindowsNtPlatform()));
return env;
}
QString CApplication::getInfoString(const QString &separator) const
{
QString str(CProject::version());
str = str.append(" ").append(CProject::isReleaseBuild() ? "Release build" : "Debug build");
str = str.append(separator);
str = str.append(getEnvironmentInfoString(separator));
str = str.append(separator);
str.append(CProject::compiledWithInfo(false));
return str;
}
QNetworkReply *CApplication::getFromNetwork(const CUrl &url, const CSlot<void(QNetworkReply *)> &callback)
{
if (this->m_shutdown) { return nullptr; }
@@ -296,14 +375,15 @@ namespace BlackCore
bool CApplication::useContexts(const CCoreFacadeConfig &coreConfig)
{
Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this after parsing");
Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing");
this->m_useContexts = true;
this->m_coreFacadeConfig = coreConfig;
if (!this->m_useWebData)
{
this->useWebDataServices(CWebReaderFlags::AllReaders, CWebReaderFlags::FromCache);
bool s = this->useWebDataServices(CWebReaderFlags::AllReaders, CWebReaderFlags::FromCache);
if (!s) { return false; }
}
return this->startCoreFacade(); // will do nothing if setup is not yet loaded
}
@@ -311,6 +391,13 @@ namespace BlackCore
bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReader, CWebReaderFlags::DbReaderHint hint)
{
Q_ASSERT_X(this->m_webDataServices.isNull(), Q_FUNC_INFO, "Services already started");
BLACK_VERIFY_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "No SSL");
if (!QSslSocket::supportsSsl())
{
this->cmdLineErrorMessage("No SSL supported, can`t be used");
return false;
}
this->m_webReader = webReader;
this->m_dbReaderHint = hint;
this->m_useWebData = true;
@@ -368,6 +455,16 @@ namespace BlackCore
this->m_parser.setApplicationDescription(m_applicationName);
this->m_cmdHelp = this->m_parser.addHelpOption();
this->m_cmdVersion = this->m_parser.addVersionOption();
this->m_cmdDevelopment = QCommandLineOption({ "dev", "developemnt" },
QCoreApplication::translate("application", "Dev.system feature?"),
"development");
this->addParserOption(this->m_cmdDevelopment);
this->m_cmdSharedDir = QCommandLineOption({ "shared", "shareddir" },
QCoreApplication::translate("application", "Local shred directory."),
"shared");
this->addParserOption(this->m_cmdSharedDir);
}
void CApplication::initEnvironment()
@@ -478,6 +575,11 @@ namespace BlackCore
return this->m_parser.addOption(option);
}
bool CApplication::addParserOptions(const QList<QCommandLineOption> &options)
{
return this->m_parser.addOptions(options);
}
void CApplication::addDBusAddressOption()
{
this->m_cmdDBusAddress = QCommandLineOption({ "dbus", "dbus-address", "dbusaddress" },
@@ -486,11 +588,16 @@ namespace BlackCore
this->addParserOption(this->m_cmdDBusAddress);
}
void CApplication::addVatlibOptions()
{
this->addParserOptions(CNetworkVatlib::getCmdLineOptions());
}
QString CApplication::getCmdDBusAddressValue() const
{
if (this->isParserOptionSet(this->m_cmdDBusAddress))
{
const QString v(this->getParserOptionValue(m_cmdDBusAddress));
const QString v(this->getParserValue(m_cmdDBusAddress));
const QString dBusAddress(CDBusServer:: normalizeAddress(v));
return dBusAddress;
}
@@ -500,6 +607,11 @@ namespace BlackCore
}
}
QString CApplication::getCmdSwiftPrivateSharedDir() const
{
return this->m_parser.value(this->m_cmdSharedDir);
}
bool CApplication::isParserOptionSet(const QString &option) const
{
return this->m_parser.isSet(option);
@@ -510,12 +622,12 @@ namespace BlackCore
return this->m_parser.isSet(option);
}
QString CApplication::getParserOptionValue(const QString &option) const
QString CApplication::getParserValue(const QString &option) const
{
return this->m_parser.value(option).trimmed();
}
QString CApplication::getParserOptionValue(const QCommandLineOption &option) const
QString CApplication::getParserValue(const QCommandLineOption &option) const
{
return this->m_parser.value(option).trimmed();
}
@@ -523,9 +635,14 @@ namespace BlackCore
bool CApplication::parse()
{
if (this->m_parsed) { return m_parsed; }
if (CProject::isLifetimeExpired())
{
this->cmdLineErrorMessage("Program exired " + CProject::getEol().toString());
return false;
}
// we call parse because we also want to display a GUI error message when applicable
QStringList args(QCoreApplication::instance()->arguments());
const QStringList args(QCoreApplication::instance()->arguments());
if (!this->m_parser.parse(args))
{
this->cmdLineErrorMessage(this->m_parser.errorText());

View File

@@ -48,6 +48,7 @@ namespace BlackCore
* - The core facade (aka core runtime) is now part of the application. It can be started via cmd line arguments.
* - Settings are loaded
* - Setup is loaded (load the so called bootsrap file) to find servers and other resources
* - An end of lifetime can be specified, aka time bombing
*
* \sa BlackGui::CGuiApplication for the GUI version of application
*/
@@ -69,7 +70,10 @@ namespace BlackCore
virtual ~CApplication();
//! Application name and version
QString getApplicationNameAndVersion() const;
const QString &getApplicationNameAndVersion() const;
//! Version, name beta and dev info
const QString &getApplicationNameVersionBetaDev() const;
//! Global setup
//! \threadsafe
@@ -93,6 +97,24 @@ namespace BlackCore
//! Currently running in application thread?
bool isApplicationThread() const;
//! String with beta, dev. and version
const QString &versionStringDevBetaInfo() const;
//! swift info string
const QString &swiftVersionString() const;
//! swift info string
const char *swiftVersionChar();
//! Running in dev.environment?
bool isRunningInDeveloperEnvironment() const;
//! Info string
QString getEnvironmentInfoString(const QString &separator) const;
//! To string
QString getInfoString(const QString &separator) const;
//! Run event loop
static int exec();
@@ -110,15 +132,24 @@ namespace BlackCore
//! \name parsing of command line options
//! @{
//! \copydoc QCommandLineParser::addOption(const QCommandLineOption &)
//! \copydoc QCommandLineParser::addOption
bool addParserOption(const QCommandLineOption &option);
//! \copydoc QCommandLineParser::addOptions
bool addParserOptions(const QList<QCommandLineOption> &options);
//! CMD line argument for DBus address
void addDBusAddressOption();
//! DBus address from CMD line, otherwise ""
QString getCmdDBusAddressValue() const;
//! Add the VATLIB options
void addVatlibOptions();
//! Private resource dir for developer's own resource files
QString getCmdSwiftPrivateSharedDir() const;
//! Delegates to QCommandLineParser::isSet
bool isParserOptionSet(const QString &option) const;
@@ -126,10 +157,10 @@ namespace BlackCore
bool isParserOptionSet(const QCommandLineOption &option) const;
//! Delegates to QCommandLineParser::value
QString getParserOptionValue(const QString &option) const;
QString getParserValue(const QString &option) const;
//! Delegates to QCommandLineParser::value
QString getParserOptionValue(const QCommandLineOption &option) const;
QString getParserValue(const QCommandLineOption &option) const;
//! Display parser error message
virtual void cmdLineErrorMessage(const QString &cmdLineErrorMessage) const;
@@ -258,6 +289,9 @@ namespace BlackCore
QCommandLineOption m_cmdHelp {"help"}; //!< help option
QCommandLineOption m_cmdVersion {"version"}; //!< version option
QCommandLineOption m_cmdDBusAddress {"empty"}; //!< DBus address
QCommandLineOption m_cmdDevelopment {"dev"}; //!< Dev flag
QCommandLineOption m_cmdSharedDir {"shared"}; //!< Dev flag
bool m_parsed = false; //!< Parsing accomplished?
bool m_started = false; //!< started with success?
bool m_startUpCompleted = false; //!< startup phase completed? Can mean startup failed

View File

@@ -23,7 +23,6 @@ namespace BlackCore
{
CGlobalSetup::CGlobalSetup() :
ITimestampBased(0),
m_development(CProject::isRunningInDeveloperEnvironment()),
m_dbRootDirectoryUrl("http://ubuntu12/swiftdatastore/public"),
m_vatsimBookingsUrl("http://vatbook.euroutepro.com/xml2.php"),
m_vatsimMetarsUrl("http://metar.vatsim.net/metar.php"),

View File

@@ -100,9 +100,9 @@ namespace BlackCore
bool CSetupReader::parseCmdLineArguments()
{
this->m_bootsrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl(
sApp->getParserOptionValue(this->m_cmdBootstrapUrl)
sApp->getParserValue(this->m_cmdBootstrapUrl)
);
this->m_bootstrapMode = stringToEnum(sApp->getParserOptionValue(this->m_cmdBootstrapMode));
this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode));
QUrl url(this->m_bootsrapUrlFileValue);
// check on local file
@@ -208,7 +208,7 @@ namespace BlackCore
if (!file.exists())
{
// relative name?
QString dir(CProject::getSwiftPrivateResourceDir());
QString dir(sApp->getCmdSwiftPrivateSharedDir());
if (dir.isEmpty()) { return false; }
// no version for local files, as those come withe the current code
@@ -228,11 +228,6 @@ namespace BlackCore
return true;
}
bool CSetupReader::isForDevelopment()
{
return CProject::useDevelopmentSetup();
}
void CSetupReader::ps_parseSetupFile(QNetworkReply *nwReplyPtr)
{
// wrap pointer, make sure any exit cleans up reply
@@ -343,7 +338,6 @@ namespace BlackCore
CUpdateInfo currentUpdateInfo(m_updateInfo.get()); // from cache
CUpdateInfo loadedUpdateInfo;
loadedUpdateInfo.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedUpdateInfo.setDevelopment(isForDevelopment()); // always update, regardless what persistent setting says
if (lastModified > 0 && lastModified > loadedUpdateInfo.getMSecsSinceEpoch()) { loadedUpdateInfo.setMSecsSinceEpoch(lastModified); }
bool sameVersionLoaded = (loadedUpdateInfo == currentUpdateInfo);
if (sameVersionLoaded)

View File

@@ -111,7 +111,7 @@ namespace BlackCore
CacheOnly
};
bool m_shutdown = false;
bool m_shutdown = false;
std::atomic<bool> m_setupSyncronized { false };
std::atomic<bool> m_updateInfoSyncronized { false };
QString m_localSetupFileValue;
@@ -140,9 +140,6 @@ namespace BlackCore
//! Convert string to mode
static BootsrapMode stringToEnum(const QString &s);
//! Read for development environment?
static bool isForDevelopment();
};
} // ns