mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +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
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
|
||||
Reference in New Issue
Block a user