refs #507, changed setup reader and simplied global setup and setup reader

* a single base URL (shared), derived URLs by appended path
* simplified dir structure shared with sub directories
* renamed functions
* automatically synchronize setup with DB when initialized
* trigger download info loading when setup is completed
* allow to automatically read after setup data have been synchronized
* read DB data when setup has been loaded
* allow to reload from threaded reader
* improved handling (log messages, skip reading) when data are not available
This commit is contained in:
Klaus Basan
2015-11-13 03:03:03 +01:00
committed by Mathew Sutcliffe
parent 4d4d6fcdc9
commit d131cd2d33
25 changed files with 527 additions and 267 deletions

View File

@@ -8,6 +8,7 @@
*/
#include "globalsetup.h"
#include "blackmisc/project.h"
#include "blackmisc/math/mathutils.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <QStringList>
@@ -22,35 +23,35 @@ namespace BlackCore
{
CGlobalSetup::CGlobalSetup() :
ITimestampBased(0),
m_dbRootDirectory("http://ubuntu12/swiftdatastore/public"),
m_dbHttpPort(80),
m_dbHttpsPort(443),
m_vatsimBookings("http://vatbook.euroutepro.com/xml2.php"),
m_vatsimMetars("http://metar.vatsim.net/metar.php"),
m_vatsimDataFile(QStringList({ "http://info.vroute.net/vatsim-data.txt" })),
m_bootstrap(QStringList({ "https://vatsim-germany.org:50443/mapping/public/bootstrap", "http://ubuntu12/public/bootstrap"})),
m_swiftDbDataFiles(QStringList({})),
m_dbRootDirectoryUrl("http://ubuntu12/swiftdatastore/public"),
m_vatsimBookingsUrl("http://vatbook.euroutepro.com/xml2.php"),
m_vatsimMetarsUrl("http://metar.vatsim.net/metar.php"),
m_vatsimDataFileUrls(QStringList({ "http://info.vroute.net/vatsim-data.txt" })),
m_sharedUrls(CProject::swiftTeamDefaultServers()),
m_newsUrls(QStringList({ "http://swift-project.org/" })),
m_fsdTestServers({ CServer("swift", "swift Testserver", "vatsim-germany.org", 6809, CUser("1234567", "swift Test User", "", "123456"), true) })
{ }
CUrl CGlobalSetup::dbIcaoReader() const
CUrl CGlobalSetup::dbIcaoReaderUrl() const
{
return dbRootDirectory();
return dbRootDirectoryUrl();
}
CUrl CGlobalSetup::dbModelReader() const
CUrl CGlobalSetup::dbModelReaderUrl() const
{
return dbRootDirectory();
return dbRootDirectoryUrl();
}
CUrl CGlobalSetup::dbHomePage() const
CUrl CGlobalSetup::dbHomePageUrl() const
{
return dbRootDirectory().withAppendedPath("/page/index.php");
return dbRootDirectoryUrl().withAppendedPath("/page/index.php");
}
CUrl CGlobalSetup::dbLoginService() const
CUrl CGlobalSetup::dbLoginServiceUrl() const
{
return dbRootDirectory().
return dbRootDirectoryUrl().
withAppendedPath("/service/jsonauthenticate.php").
withSwitchedScheme("https", m_dbHttpsPort);
}
@@ -68,14 +69,38 @@ namespace BlackCore
m_dbDebugFlag = debug;
}
bool CGlobalSetup::hasSameType(CGlobalSetup &otherSetup) const
bool CGlobalSetup::hasSameType(const CGlobalSetup &otherSetup) const
{
return this->isDevelopment() == otherSetup.isDevelopment();
}
CUrl CGlobalSetup::vatsimMetars() const
CUrl CGlobalSetup::vatsimMetarsUrl() const
{
return this->m_vatsimMetars.withAppendedQuery("id=all");
return this->m_vatsimMetarsUrl.withAppendedQuery("id=all");
}
CUrlList CGlobalSetup::bootstrapUrls() const
{
CUrlList urls(m_sharedUrls);
return urls.appendPath(isDevelopment() ?
CGlobalSetup::versionString() + "/development/bootstrap/bootstrap.json" :
CGlobalSetup::versionString() + "/productive/bootstrap/bootstrap.json");
}
CUrlList CGlobalSetup::downloadInfoUrls() const
{
CUrlList urls(m_sharedUrls);
return urls.appendPath(isDevelopment() ?
CGlobalSetup::versionString() + "/development/download/download.json" :
CGlobalSetup::versionString() + "/productive/download/download.json");
}
CUrlList CGlobalSetup::swiftDbDataFileLocationUrls() const
{
CUrlList urls(m_sharedUrls);
return urls.appendPath(isDevelopment() ?
CGlobalSetup::versionString() + "/development/dbdata/" :
CGlobalSetup::versionString() + "/productive/dbdata/");
}
QString CGlobalSetup::convertToQString(bool i18n) const
@@ -91,39 +116,48 @@ namespace BlackCore
s.append("For development: ");
s.append(boolToYesNo(isDevelopment()));
s.append(separator);
s.append("DB root directory: ");
s.append(dbRootDirectory().convertToQString(i18n));
s.append(separator);
s.append("ICAO DB reader: ");
s.append(dbIcaoReader().convertToQString(i18n));
s.append(separator);
s.append("Model DB reader: ");
s.append(dbModelReader().convertToQString(i18n));
s.append(separator);
s.append("DB home page: ");
s.append(dbHomePage().convertToQString(i18n));
s.append(separator);
s.append("DB login service: ");
s.append(dbLoginService().convertToQString(i18n));
s.append(separator);
s.append("VATSIM bookings: ");
s.append(vatsimBookings().convertToQString(i18n));
s.append(separator);
s.append("VATSIM METARs: ");
s.append(vatsimMetars().convertToQString(i18n));
s.append(separator);
s.append("VATSIM data file: ");
s.append(vatsimDataFile().convertToQString(i18n));
s.append("Download URLs: ");
s.append(downloadInfoUrls().toQString(i18n));
s.append(separator);
s.append("Bootstrap URLs: ");
s.append(bootstrapUrls().convertToQString(i18n));
s.append(bootstrapUrls().toQString(i18n));
s.append(separator);
s.append("News URLs: ");
s.append(swiftLatestNewsUrls().toQString(i18n));
s.append(separator);
s.append("DB root directory: ");
s.append(dbRootDirectoryUrl().toQString(i18n));
s.append(separator);
s.append("ICAO DB reader: ");
s.append(dbIcaoReaderUrl().toQString(i18n));
s.append(separator);
s.append("Model DB reader: ");
s.append(dbModelReaderUrl().toQString(i18n));
s.append(separator);
s.append("DB home page: ");
s.append(dbHomePageUrl().toQString(i18n));
s.append(separator);
s.append("DB login service: ");
s.append(dbLoginServiceUrl().toQString(i18n));
s.append(separator);
s.append("swift DB datafile locations: ");
s.append(swiftDbDataFileLocations().convertToQString(i18n));
s.append(swiftDbDataFileLocationUrls().toQString(i18n));
s.append(separator);
s.append("VATSIM bookings: ");
s.append(vatsimBookingsUrl().toQString(i18n));
s.append(separator);
s.append("VATSIM METARs: ");
s.append(vatsimMetarsUrl().toQString(i18n));
s.append(separator);
s.append("VATSIM data file: ");
s.append(vatsimDataFileUrls().toQString(i18n));
s.append(separator);
s.append("FSD test servers: ");
s.append(fsdTestServers().convertToQString(i18n));
s.append(fsdTestServers().toQString(i18n));
return s;
}
@@ -136,23 +170,27 @@ namespace BlackCore
switch (i)
{
case IndexDbRootDirectory:
return CVariant::fromValue(this->m_dbRootDirectory);
return CVariant::fromValue(this->m_dbRootDirectoryUrl);
case IndexDbHttpPort:
return CVariant::fromValue(this->m_dbHttpPort);
case IndexDbHttpsPort:
return CVariant::fromValue(this->m_dbHttpsPort);
case IndexDbLoginService:
return CVariant::fromValue(this->dbLoginService());
return CVariant::fromValue(this->dbLoginServiceUrl());
case IndexVatsimData:
return CVariant::fromValue(this->m_vatsimDataFile);
return CVariant::fromValue(this->m_vatsimDataFileUrls);
case IndexVatsimBookings:
return CVariant::fromValue(this->m_vatsimDataFile);
return CVariant::fromValue(this->m_vatsimDataFileUrls);
case IndexVatsimMetars:
return CVariant::fromValue(this->m_vatsimMetars);
return CVariant::fromValue(this->m_vatsimMetarsUrl);
case IndexDownload:
return CVariant::fromValue(this->downloadInfoUrls());
case IndexBootstrap:
return CVariant::fromValue(this->m_bootstrap);
return CVariant::fromValue(this->bootstrapUrls());
case IndexSwiftDbFiles:
return CVariant::fromValue(this->m_swiftDbDataFiles);
return CVariant::fromValue(this->swiftDbDataFileLocationUrls());
case IndexShared:
return CVariant::fromValue(this->m_sharedUrls);
default:
return CValueObject::propertyByIndex(index);
}
@@ -171,7 +209,7 @@ namespace BlackCore
switch (i)
{
case IndexDbRootDirectory:
this->m_dbRootDirectory.setPropertyByIndex(variant, index.copyFrontRemoved());
this->m_dbRootDirectoryUrl.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexDbHttpPort:
this->m_dbHttpPort = variant.toInt();
@@ -182,19 +220,16 @@ namespace BlackCore
case IndexDbLoginService:
break;
case IndexVatsimData:
this->m_vatsimDataFile = variant.value<CUrlList>();
this->m_vatsimDataFileUrls = variant.value<CUrlList>();
break;
case IndexVatsimBookings:
this->m_vatsimBookings.setPropertyByIndex(variant, index.copyFrontRemoved());
this->m_vatsimBookingsUrl.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexVatsimMetars:
this->m_vatsimMetars.setPropertyByIndex(variant, index.copyFrontRemoved());
this->m_vatsimMetarsUrl.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexBootstrap:
this->m_bootstrap = variant.value<CUrlList>();
break;
case IndexSwiftDbFiles:
this->m_swiftDbDataFiles = variant.value<CUrlList>();
case IndexShared:
this->m_sharedUrls = variant.value<CUrlList>();
break;
default:
CValueObject::setPropertyByIndex(variant, index);
@@ -204,7 +239,7 @@ namespace BlackCore
const QString &CGlobalSetup::versionString()
{
static const QString v("0.6");
static const QString v("0.6.1");
return v;
}
} // ns

View File

@@ -41,7 +41,9 @@ namespace BlackCore
IndexVatsimMetars,
IndexVatsimData,
IndexSwiftDbFiles,
IndexBootstrap
IndexBootstrap,
IndexDownload,
IndexShared
};
//! Default constructor
@@ -50,50 +52,56 @@ namespace BlackCore
//! Destructor.
~CGlobalSetup() {}
//! Root directory of DB
const BlackMisc::Network::CUrl &dbRootDirectory() const { return m_dbRootDirectory; }
//! ICAO Reader location
BlackMisc::Network::CUrl dbIcaoReader() const;
//! Model Reader protocol
BlackMisc::Network::CUrl dbModelReader() const;
//! Http port
int dbHttpPort() const { return m_dbHttpPort; }
//! Https port
int dbHttpsPort() const { return m_dbHttpsPort; }
//! Home page url
BlackMisc::Network::CUrl dbHomePage() const;
//! Login service
BlackMisc::Network::CUrl dbLoginService() const;
//! Debug flag
bool dbDebugFlag() const;
//! Set debug flag
void setServerDebugFlag(bool debug);
//! URL to read VATSIM bookings
const BlackMisc::Network::CUrl &vatsimBookings() const { return m_vatsimBookings; }
//! Same type?
bool hasSameType(CGlobalSetup &otherSetup) const;
bool hasSameType(const CGlobalSetup &otherSetup) const;
//! Home page url
BlackMisc::Network::CUrl dbHomePageUrl() const;
//! Login service
BlackMisc::Network::CUrl dbLoginServiceUrl() const;
//! Root directory of DB
const BlackMisc::Network::CUrl &dbRootDirectoryUrl() const { return m_dbRootDirectoryUrl; }
//! ICAO Reader location
BlackMisc::Network::CUrl dbIcaoReaderUrl() const;
//! Model Reader protocol
BlackMisc::Network::CUrl dbModelReaderUrl() const;
//! URL to read VATSIM bookings
const BlackMisc::Network::CUrl &vatsimBookingsUrl() const { return m_vatsimBookingsUrl; }
//! VATSIM METAR URL
BlackMisc::Network::CUrl vatsimMetars() const;
BlackMisc::Network::CUrl vatsimMetarsUrl() const;
//! VATSIM data file URLs
const BlackMisc::Network::CUrlList &vatsimDataFile() const { return m_vatsimDataFile; }
const BlackMisc::Network::CUrlList &vatsimDataFileUrls() const { return m_vatsimDataFileUrls; }
//! Bootstrap URLs (where the data for the setup itself can be downloaded)
const BlackMisc::Network::CUrlList &bootstrapUrls() const { return m_bootstrap; }
BlackMisc::Network::CUrlList bootstrapUrls() const;
//! Version files and download locations
BlackMisc::Network::CUrlList downloadInfoUrls() const;
//! Alternative locations of swift DB data files
const BlackMisc::Network::CUrlList &swiftDbDataFileLocations() const { return m_swiftDbDataFiles; }
BlackMisc::Network::CUrlList swiftDbDataFileLocationUrls() const;
//! Locations of swift DB news
const BlackMisc::Network::CUrlList &swiftLatestNewsUrls() const { return m_newsUrls; }
//! FSD test servers
const BlackMisc::Network::CServerList &fsdTestServers() const { return m_fsdTestServers; }
@@ -122,19 +130,19 @@ namespace BlackCore
private:
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup)
BlackMisc::Network::CUrl m_dbRootDirectory; //!< Root directory
int m_dbHttpPort = 80; //!< port
int m_dbHttpsPort = 443; //!< SSL port
BlackMisc::Network::CUrl m_vatsimBookings; //!< ATC bookings
BlackMisc::Network::CUrl m_vatsimMetars; //!< METAR data
BlackMisc::Network::CUrlList m_vatsimDataFile; //!< Overall VATSIM data file
BlackMisc::Network::CUrlList m_bootstrap; //!< where we can obtain downloads of these data
BlackMisc::Network::CUrlList m_swiftDbDataFiles; //!< alternative locations of the DB files, if DB is not available
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers
bool m_development = false; //!< dev. version?
int m_dbHttpPort = 80; //!< port
int m_dbHttpsPort = 443; //!< SSL port
bool m_development = false; //!< dev. version?
BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB
BlackMisc::Network::CUrl m_vatsimBookingsUrl; //!< ATC bookings
BlackMisc::Network::CUrl m_vatsimMetarsUrl; //!< METAR data
BlackMisc::Network::CUrlList m_vatsimDataFileUrls; //!< Overall VATSIM data file
BlackMisc::Network::CUrlList m_sharedUrls; //!< where we can obtain shared info files such as bootstrap, ..
BlackMisc::Network::CUrlList m_newsUrls; //!< where we can obtain latest news
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers
// transient members, to be switched on/off via GUI or set from reader
bool m_dbDebugFlag = false; //!< can trigger DEBUG on the server, so you need to know hat you are doing
bool m_dbDebugFlag = false; //!< can trigger DEBUG on the server, so you need to know what you are doing
};
//! Trait for global setup data
@@ -157,14 +165,14 @@ namespace BlackCore
Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup)
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup, (
attr(o.m_timestampMSecsSinceEpoch),
attr(o.m_dbRootDirectory),
attr(o.m_dbRootDirectoryUrl),
attr(o.m_dbHttpPort),
attr(o.m_dbHttpsPort),
attr(o.m_vatsimBookings),
attr(o.m_vatsimMetars),
attr(o.m_vatsimDataFile),
attr(o.m_bootstrap),
attr(o.m_swiftDbDataFiles),
attr(o.m_vatsimBookingsUrl),
attr(o.m_vatsimMetarsUrl),
attr(o.m_vatsimDataFileUrls),
attr(o.m_sharedUrls),
attr(o.m_newsUrls),
attr(o.m_fsdTestServers),
attr(o.m_development),
attr(o.m_dbDebugFlag, flags < DisabledForJson > ())