From cba40a8ca45532c261a7674ee80f1904a4520ae1 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 14 Oct 2015 02:00:14 +0200 Subject: [PATCH] refs #478, setup class containing the fundamental URLs and locations Removed the old class CGlobalNetworkSettings --- src/blackcore/blackcore.h | 5 + src/blackcore/blackcore.pro | 10 +- src/blackcore/blackcorefreefunctions.cpp | 3 + src/blackcore/data/globalsetup.cpp | 141 ++++++++++++++++++ src/blackcore/data/globalsetup.h | 130 ++++++++++++++++ .../settings/global_network_settings.cpp | 31 ---- .../settings/global_network_settings.h | 45 ------ .../settings/global_reader_settings.cpp | 35 ----- .../settings/global_reader_settings.h | 79 ---------- 9 files changed, 285 insertions(+), 194 deletions(-) create mode 100644 src/blackcore/data/globalsetup.cpp create mode 100644 src/blackcore/data/globalsetup.h delete mode 100644 src/blackcore/settings/global_network_settings.cpp delete mode 100644 src/blackcore/settings/global_network_settings.h delete mode 100644 src/blackcore/settings/global_reader_settings.cpp delete mode 100644 src/blackcore/settings/global_reader_settings.h diff --git a/src/blackcore/blackcore.h b/src/blackcore/blackcore.h index 407b5237e..bf14b0629 100644 --- a/src/blackcore/blackcore.h +++ b/src/blackcore/blackcore.h @@ -13,6 +13,11 @@ * Core settings traits. */ +/*! + * \namespace BlackCore::Data + * Core data traits (aka cached values) and classes. + */ + /*! * \namespace BlackCore::Settings::Network * Network settings traits. diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 3531e6043..b62e37631 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -22,11 +22,13 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += LOG_IN_FILE BUILD_BLACKCORE_LIB -HEADERS += *.h -HEADERS += $$PWD/settings/*.h +HEADERS += *.h \ + $$PWD/settings/*.h \ + $$PWD/data/*.h -SOURCES += *.cpp -SOURCES += $$PWD/settings/*.cpp +SOURCES += *.cpp \ +# $$PWD/settings/*.cpp \ + $$PWD/data/*.cpp LIBS *= -lvatlib2 diff --git a/src/blackcore/blackcorefreefunctions.cpp b/src/blackcore/blackcorefreefunctions.cpp index 670adb90b..d0c7e83bb 100644 --- a/src/blackcore/blackcorefreefunctions.cpp +++ b/src/blackcore/blackcorefreefunctions.cpp @@ -5,6 +5,7 @@ #include "blackcorefreefunctions.h" #include "blackcore/webreaderflags.h" +#include "blackcore/data/globalsetup.h" #include "voice_channel.h" #include "network.h" @@ -23,6 +24,8 @@ namespace BlackCore qRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); + + BlackCore::Data::CGlobalSetup::registerMetadata(); } bool isCurrentThreadObjectThread(QObject *toBeTested) diff --git a/src/blackcore/data/globalsetup.cpp b/src/blackcore/data/globalsetup.cpp new file mode 100644 index 000000000..fb08ad53f --- /dev/null +++ b/src/blackcore/data/globalsetup.cpp @@ -0,0 +1,141 @@ +/* Copyright (C) 2015 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "globalsetup.h" +#include "blackmisc/math/mathutils.h" +#include + +using namespace BlackMisc; +using namespace BlackMisc::Math; +using namespace BlackMisc::Network; + +namespace BlackCore +{ + namespace Data + { + CGlobalSetup::CGlobalSetup() : + ITimestampBased(0), + m_dbIcaoReader("http://ubuntu12/vatrep/public"), + m_dbModelReader("http://ubuntu12/vatrep/public"), + 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_fsdTestServers({ CServer("swift", "swift Testserver", "vatsim-germany.org", 6809, CUser("1234567", "swift Test User", "", "123456"), true) }) + { } + + CUrl CGlobalSetup::vatsimMetars() const + { + return this->m_vatsimMetars.withAppendedQuery("id=all"); + } + + QString CGlobalSetup::convertToQString(bool i18n) const + { + return convertToQString(", ", i18n); + } + + QString CGlobalSetup::convertToQString(const QString &separator, bool i18n) const + { + QString s("timestamp: "); + s.append(this->getFormattedUtcTimestampYmdhms()); + 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("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(separator); + s.append("Bootstrap URLs: "); + s.append(bootstrapUrls().convertToQString(i18n)); + s.append(separator); + s.append("swift DB datafile locations: "); + s.append(swiftDbDataFileLocations().convertToQString(i18n)); + s.append(separator); + s.append("FSD test servers: "); + s.append(fsdTestServers().convertToQString(i18n)); + return s; + } + + CVariant CGlobalSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbIcaoReader: + return CVariant::fromValue(this->m_dbIcaoReader); + case IndexDbModelReader: + return CVariant::fromValue(this->m_dbModelReader); + case IndexVatsimData: + return CVariant::fromValue(this->m_vatsimDataFile); + case IndexVatsimBookings: + return CVariant::fromValue(this->m_vatsimDataFile); + case IndexVatsimMetars: + return CVariant::fromValue(this->m_vatsimMetars); + case IndexBootstrap: + return CVariant::fromValue(this->m_bootstrap); + case IndexSwiftDbFiles: + return CVariant::fromValue(this->m_swiftDbDataFiles); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CGlobalSetup::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + if (ITimestampBased::canHandleIndex(index)) + { + ITimestampBased::setPropertyByIndex(variant, index); + return; + } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbIcaoReader: + this->m_dbIcaoReader.setPropertyByIndex(variant, index.copyFrontRemoved()); + break; + case IndexDbModelReader: + this->m_dbModelReader.setPropertyByIndex(variant, index.copyFrontRemoved()); + break; + case IndexVatsimData: + this->m_vatsimDataFile = variant.value(); + break; + case IndexVatsimBookings: + this->m_vatsimBookings.setPropertyByIndex(variant, index.copyFrontRemoved()); + break; + case IndexVatsimMetars: + this->m_vatsimMetars.setPropertyByIndex(variant, index.copyFrontRemoved()); + break; + case IndexBootstrap: + this->m_bootstrap = variant.value(); + break; + case IndexSwiftDbFiles: + this->m_swiftDbDataFiles = variant.value(); + break; + default: + CValueObject::setPropertyByIndex(variant, index); + break; + } + } + } // ns +} // ns diff --git a/src/blackcore/data/globalsetup.h b/src/blackcore/data/globalsetup.h new file mode 100644 index 000000000..208a80e99 --- /dev/null +++ b/src/blackcore/data/globalsetup.h @@ -0,0 +1,130 @@ +/* Copyright (C) 2015 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_DATA_GLOBALSETUP_H +#define BLACKCORE_DATA_GLOBALSETUP_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/datacache.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/network/urllist.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/variant.h" +#include + +namespace BlackCore +{ + namespace Data + { + //! Settings for readers + class BLACKCORE_EXPORT CGlobalSetup : + public BlackMisc::CValueObject, + public BlackMisc::ITimestampBased + { + public: + //! Properties by index + enum ColumnIndex + { + IndexDbIcaoReader = BlackMisc::CPropertyIndex::GlobalIndexCGlobalSetup, + IndexDbModelReader, + IndexVatsimBookings, + IndexVatsimMetars, + IndexVatsimData, + IndexSwiftDbFiles, + IndexBootstrap + }; + + //! Default constructor + CGlobalSetup(); + + //! Destructor. + ~CGlobalSetup() {} + + //! ICAO Reader location + const BlackMisc::Network::CUrl &dbIcaoReader() const { return m_dbIcaoReader; } + + //! Model Reader protocol + const BlackMisc::Network::CUrl &dbModelReader() const { return m_dbModelReader; } + + //! URL to read VATSIM bookings + const BlackMisc::Network::CUrl &vatsimBookings() const { return m_vatsimBookings; } + + //! VATSIM METAR URL + BlackMisc::Network::CUrl vatsimMetars() const; + + //! VATSIM data file URLs + const BlackMisc::Network::CUrlList &vatsimDataFile() const { return m_vatsimDataFile; } + + //! Bootstrap URLs (where the data for the setup itself can be downloaded) + const BlackMisc::Network::CUrlList &bootstrapUrls() const { return m_bootstrap; } + + //! Alternative locations of swift DB data files + const BlackMisc::Network::CUrlList &swiftDbDataFileLocations() const { return m_swiftDbDataFiles; } + + //! FSD test servers + const BlackMisc::Network::CServerList &fsdTestServers() const { return m_fsdTestServers; } + + //! \copydoc CValueObject::convertToQString + QString convertToQString(bool i18n = false) const; + + //! To string + QString convertToQString(const QString &separator, bool i18n = false) const; + + //! \copydoc CValueObject::propertyByIndex + BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc CValueObject::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index); + + private: + BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup) + + BlackMisc::Network::CUrl m_dbIcaoReader; //!< direct DB ICAO reader + BlackMisc::Network::CUrl m_dbModelReader; //!< direct DB model reader + 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 + }; + + //! Trait for for global setup data + struct GlobalSetup : public BlackCore::CDataTrait + { + //! Key in data cache + static const char *key() { return "readers/global/bootstrap"; } + + //! Default value + static const CGlobalSetup &defaultValue() + { + static const CGlobalSetup urls; + return urls; + } + }; + + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup) +BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup, ( + attr(o.m_timestampMSecsSinceEpoch), + attr(o.m_dbIcaoReader), + attr(o.m_dbModelReader), + attr(o.m_vatsimBookings), + attr(o.m_vatsimMetars), + attr(o.m_vatsimDataFile), + attr(o.m_bootstrap), + attr(o.m_swiftDbDataFiles), + attr(o.m_fsdTestServers) + )) + +#endif // guard diff --git a/src/blackcore/settings/global_network_settings.cpp b/src/blackcore/settings/global_network_settings.cpp deleted file mode 100644 index ea5fab6de..000000000 --- a/src/blackcore/settings/global_network_settings.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2015 - * swift project community / contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "global_network_settings.h" -#include "blackmisc/network/user.h" - -using namespace BlackMisc::Network; - -namespace BlackCore -{ - namespace Settings - { - - CGlobalNetworkSettings::CGlobalNetworkSettings() : - m_fsdSwiftServer("swift", "swift Testserver", "vatsim-germany.org", 6809, - CUser("1234567", "swift Test User", "", "123456"), true) - { } - - const CGlobalNetworkSettings &CGlobalNetworkSettings::instance() - { - static const CGlobalNetworkSettings rs; - return rs; - } - } // ns -} // ns diff --git a/src/blackcore/settings/global_network_settings.h b/src/blackcore/settings/global_network_settings.h deleted file mode 100644 index 98df80e81..000000000 --- a/src/blackcore/settings/global_network_settings.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2015 - * swift project community / contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#ifndef BLACKCORE_SETTINGS_GLOBAL_NETWORKSETTINGS_H -#define BLACKCORE_SETTINGS_GLOBAL_NETWORKSETTINGS_H - -#include "blackmisc/network/server.h" -#include "blackcore/blackcoreexport.h" -#include -#include - -namespace BlackCore -{ - namespace Settings - { - //! Settings for readers - class BLACKCORE_EXPORT CGlobalNetworkSettings : public QObject - { - Q_OBJECT - - public: - //! FSD Server - const BlackMisc::Network::CServer &swiftFsdTestServer() const { return m_fsdSwiftServer; } - - //! Singleton - static const CGlobalNetworkSettings &instance(); - - private: - //! Default constructor - CGlobalNetworkSettings(); - - //! Destructor. - ~CGlobalNetworkSettings() {} - - BlackMisc::Network::CServer m_fsdSwiftServer; - }; - } // ns -} // ns -#endif // guard diff --git a/src/blackcore/settings/global_reader_settings.cpp b/src/blackcore/settings/global_reader_settings.cpp deleted file mode 100644 index d4686de3e..000000000 --- a/src/blackcore/settings/global_reader_settings.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2015 - * swift project community / contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "global_reader_settings.h" - -namespace BlackCore -{ - namespace Settings - { - CGlobalReaderSettings::CGlobalReaderSettings() : - m_protocolIcaoReader("http"), m_serverIcaoReader("ubuntu12"), m_baseUrlIcaoReader("vatrep/public"), - m_protocolModelReader("http"), m_serverModelReader("ubuntu12"), m_baseUrlModelReader("vatrep/public"), - m_bookingsUrl("http://vatbook.euroutepro.com/xml2.php"), - m_metarUrl("http://metar.vatsim.net/metar.php"), - m_vatsimDataFileUrls({ "http://info.vroute.net/vatsim-data.txt" }) - { } - - QString CGlobalReaderSettings::urlVatsimMetars() const - { - return m_metarUrl + "?id=all"; - } - - const CGlobalReaderSettings &CGlobalReaderSettings::instance() - { - static const CGlobalReaderSettings rs; - return rs; - } - } // ns -} // ns diff --git a/src/blackcore/settings/global_reader_settings.h b/src/blackcore/settings/global_reader_settings.h deleted file mode 100644 index a0244beb4..000000000 --- a/src/blackcore/settings/global_reader_settings.h +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2015 - * swift project community / contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#ifndef BLACKCORE_SETTINGS_GLOBAL_READERSETTINGS_H -#define BLACKCORE_SETTINGS_GLOBAL_READERSETTINGS_H - -#include "blackcore/blackcoreexport.h" -#include -#include - -namespace BlackCore -{ - namespace Settings - { - //! Settings for readers - class BLACKCORE_EXPORT CGlobalReaderSettings : public QObject - { - Q_OBJECT - - public: - //! ICAO Reader protocol - const QString &protocolIcaoReader() const { return m_protocolIcaoReader; } - - //! ICAO Reader server - const QString &serverIcaoReader() const { return m_serverIcaoReader; } - - //! ICAO Reader base URL - const QString &baseUrlIcaoReader() const { return m_baseUrlIcaoReader; } - - //! Model Reader protocol - const QString &protocolModelReader() const { return m_protocolModelReader; } - - //! Model Reader server - const QString &serverModelReader() const { return m_serverModelReader; } - - //! Model Reader server - const QString &baseUrlModelReader() const { return m_baseUrlModelReader; } - - //! URL to read VATSIM bookings - const QString &bookingsUrl() const { return m_bookingsUrl; } - - //! VATSIM data file URLs - const QStringList &vatsimDataFileUrls() const { return m_vatsimDataFileUrls; } - - //! VATSIM METAR URL - const QString &baseUrlVatsimMetars() const { return m_metarUrl; } - - //! VATSIM METAR URL (with query string) - QString urlVatsimMetars() const; - - //! Singleton - static const CGlobalReaderSettings &instance(); - - private: - //! Default constructor - CGlobalReaderSettings(); - - //! Destructor. - ~CGlobalReaderSettings() {} - - QString m_protocolIcaoReader; - QString m_serverIcaoReader; - QString m_baseUrlIcaoReader; - QString m_protocolModelReader; - QString m_serverModelReader; - QString m_baseUrlModelReader; - QString m_bookingsUrl; - QString m_metarUrl; - QStringList m_vatsimDataFileUrls; - }; - } -} -#endif // guard