mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
refs #478, setup class containing the fundamental URLs and locations
Removed the old class CGlobalNetworkSettings
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a725ce2181
commit
cba40a8ca4
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<BlackCore::CWebReaderFlags::WebReader>();
|
||||
qDBusRegisterMetaType<BlackCore::CLogSubscriptionHash>();
|
||||
qDBusRegisterMetaType<BlackCore::CLogSubscriptionPair>();
|
||||
|
||||
BlackCore::Data::CGlobalSetup::registerMetadata();
|
||||
}
|
||||
|
||||
bool isCurrentThreadObjectThread(QObject *toBeTested)
|
||||
|
||||
141
src/blackcore/data/globalsetup.cpp
Normal file
141
src/blackcore/data/globalsetup.cpp
Normal file
@@ -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 <QStringList>
|
||||
|
||||
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<ColumnIndex>();
|
||||
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<CGlobalSetup>(); return; }
|
||||
if (ITimestampBased::canHandleIndex(index))
|
||||
{
|
||||
ITimestampBased::setPropertyByIndex(variant, index);
|
||||
return;
|
||||
}
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
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<CUrlList>();
|
||||
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<CUrlList>();
|
||||
break;
|
||||
case IndexSwiftDbFiles:
|
||||
this->m_swiftDbDataFiles = variant.value<CUrlList>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
130
src/blackcore/data/globalsetup.h
Normal file
130
src/blackcore/data/globalsetup.h
Normal file
@@ -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 <QStringList>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
//! Settings for readers
|
||||
class BLACKCORE_EXPORT CGlobalSetup :
|
||||
public BlackMisc::CValueObject<CGlobalSetup>,
|
||||
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<CGlobalSetup>
|
||||
{
|
||||
//! 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
|
||||
@@ -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
|
||||
@@ -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 <QStringList>
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
@@ -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
|
||||
@@ -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 <QStringList>
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user