mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 19:35:32 +08:00
refs #217, Project class providing information for compile configuration
* changed .pro / .pri as required * Used info from project class in network_vatlib * Checks / info in GUI/core (e.g. console) * const * versions of systemNameAndVersion / simulators, as mentioned in https://dev.vatsim-germany.org/issues/217#note-4
This commit is contained in:
@@ -77,7 +77,7 @@ namespace BlackCore
|
||||
virtual void unloadSimulatorPlugin () = 0;
|
||||
|
||||
//! Simulator avialable?
|
||||
bool isSimulatorAvailable() const { return !getSimulatorInfo().isUnspecified(); }
|
||||
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorInfo().isUnspecified(); }
|
||||
|
||||
protected:
|
||||
//! \brief Constructor
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "network_vatlib.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
@@ -11,10 +12,6 @@
|
||||
static_assert(! std::is_abstract<BlackCore::CNetworkVatlib>::value, "Must implement all pure virtuals");
|
||||
|
||||
//TODO just placeholders to allow this to compile
|
||||
#define CLIENT_NAME_VERSION "BlackBox 0.3"
|
||||
#define CLIENT_VERSION_MAJOR 0
|
||||
#define CLIENT_VERSION_MINOR 3
|
||||
#define CLIENT_SIMULATOR_NAME "None"
|
||||
#define CLIENT_PUBLIC_ID 0
|
||||
#define CLIENT_PRIVATE_KEY ""
|
||||
|
||||
@@ -25,6 +22,8 @@ namespace BlackCore
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc;
|
||||
|
||||
|
||||
void exceptionDispatcher(const char *caller);
|
||||
|
||||
@@ -66,8 +65,8 @@ namespace BlackCore
|
||||
capabilities += "=1";
|
||||
}
|
||||
|
||||
m_net->CreateNetworkSession(CLIENT_NAME_VERSION, CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR,
|
||||
CLIENT_SIMULATOR_NAME, CLIENT_PUBLIC_ID, CLIENT_PRIVATE_KEY, toFSD(capabilities));
|
||||
m_net->CreateNetworkSession(CProject::systemNameAndVersionChar(), CProject::versionMajor(), CProject::versionMinor(),
|
||||
CProject::simulatorsChar(), CLIENT_PUBLIC_ID, CLIENT_PRIVATE_KEY, toFSD(capabilities));
|
||||
|
||||
m_net->InstallOnConnectionStatusChangedEvent(onConnectionStatusChanged, this);
|
||||
m_net->InstallOnTextMessageReceivedEvent(onTextMessageReceived, this);
|
||||
@@ -264,7 +263,7 @@ namespace BlackCore
|
||||
m_bytesVec.push_back(creator->toFSD(*i));
|
||||
}
|
||||
}
|
||||
const char **operator ()()
|
||||
const char **operator()()
|
||||
{
|
||||
Q_ASSERT(m_cstrVec.isEmpty());
|
||||
for (auto i = m_bytesVec.begin(); i != m_bytesVec.end(); ++i)
|
||||
@@ -330,7 +329,7 @@ namespace BlackCore
|
||||
net = netPtr.data();
|
||||
}
|
||||
|
||||
auto urlsPtr = QSharedPointer<const char *const>(net->GetVatsimStatusUrls(), [=](const char *const *p){ net->GetVatsimStatusUrls_Free(p); });
|
||||
auto urlsPtr = QSharedPointer<const char *const>(net->GetVatsimStatusUrls(), [ = ](const char *const * p) { net->GetVatsimStatusUrls_Free(p); });
|
||||
auto urls = urlsPtr.data();
|
||||
while (*urls)
|
||||
{
|
||||
@@ -354,10 +353,10 @@ namespace BlackCore
|
||||
net = netPtr.data();
|
||||
}
|
||||
|
||||
auto namesPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerNames(), [=](const char *const *p){ net->GetVatsimFSDServerNames_Free(p); });
|
||||
auto ipsPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerIps(), [=](const char *const *p){ net->GetVatsimFSDServerIps_Free(p); });
|
||||
auto locationsPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerLocations(), [=](const char *const *p){ net->GetVatsimFSDServerLocations_Free(p); });
|
||||
auto acceptsPtr = QSharedPointer<const bool>(net->GetVatsimFSDServerAcceptingConnections(), [=](const bool *p){ net->GetVatsimFSDServerAcceptingConnections_Free(p); });
|
||||
auto namesPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerNames(), [ = ](const char *const * p) { net->GetVatsimFSDServerNames_Free(p); });
|
||||
auto ipsPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerIps(), [ = ](const char *const * p) { net->GetVatsimFSDServerIps_Free(p); });
|
||||
auto locationsPtr = QSharedPointer<const char *const>(net->GetVatsimFSDServerLocations(), [ = ](const char *const * p) { net->GetVatsimFSDServerLocations_Free(p); });
|
||||
auto acceptsPtr = QSharedPointer<const bool>(net->GetVatsimFSDServerAcceptingConnections(), [ = ](const bool * p) { net->GetVatsimFSDServerAcceptingConnections_Free(p); });
|
||||
auto names = namesPtr.data();
|
||||
auto ips = ipsPtr.data();
|
||||
auto locations = locationsPtr.data();
|
||||
@@ -759,8 +758,8 @@ namespace BlackCore
|
||||
void CNetworkVatlib::onConnectionStatusChanged(Cvatlib_Network *, Cvatlib_Network::connStatus, Cvatlib_Network::connStatus newStatus, void *cbvar)
|
||||
{
|
||||
if (newStatus == Cvatlib_Network::connStatus_Error ||
|
||||
newStatus == Cvatlib_Network::connStatus_ConnectionFailed ||
|
||||
newStatus == Cvatlib_Network::connStatus_ConnectionLost)
|
||||
newStatus == Cvatlib_Network::connStatus_ConnectionFailed ||
|
||||
newStatus == Cvatlib_Network::connStatus_ConnectionLost)
|
||||
{
|
||||
cbvar_cast(cbvar)->changeConnectionStatus(newStatus, cbvar_cast(cbvar)->getSocketError());
|
||||
}
|
||||
|
||||
141
src/blackmisc/project.cpp
Normal file
141
src/blackmisc/project.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "project.h"
|
||||
#include <QStringList>
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
|
||||
#define BLACK_VERSION_STR_X(v) #v
|
||||
#define BLACK_VERSION_STR(v) BLACK_VERSION_STR_X(v)
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
bool CProject::isCompiledWithBlackCore()
|
||||
{
|
||||
#ifdef WITH_BLACKCORE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithBlackSound()
|
||||
{
|
||||
#ifdef WITH_BLACKSOUND
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFsxSupport()
|
||||
{
|
||||
#ifdef WITH_FSX
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithXPlaneSupport()
|
||||
{
|
||||
#ifdef WITH_XPLANE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFlightSimulatorSupport()
|
||||
{
|
||||
return isCompiledWithFsxSupport() || isCompiledWithXPlaneSupport();
|
||||
}
|
||||
|
||||
bool BlackMisc::CProject::isCompiledWithGui()
|
||||
{
|
||||
#ifdef WITH_BLACKGUI
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
const QString &CProject::compiledInfo()
|
||||
{
|
||||
static QString info;
|
||||
if (info.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithBlackCore()) sl << "BlackCore";
|
||||
if (isCompiledWithBlackSound()) sl << "BlackSound";
|
||||
if (isCompiledWithGui()) sl << "BlackGui";
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
info = sl.join(", ");
|
||||
if (info.isEmpty()) info = "<none>";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
const QString &CProject::simulators()
|
||||
{
|
||||
static QString sims;
|
||||
if (sims.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
sims = sl.join(", ");
|
||||
if (sims.isEmpty()) sims = "<none>";
|
||||
}
|
||||
return sims;
|
||||
}
|
||||
|
||||
const char *CProject::simulatorsChar()
|
||||
{
|
||||
static const QByteArray a(simulators().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
const QString &CProject::version()
|
||||
{
|
||||
#ifdef BLACK_VERSION
|
||||
const static QString v(BLACK_VERSION_STR(BLACK_VERSION));
|
||||
#else
|
||||
const static QString v("?");
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
const QString &CProject::systemNameAndVersion()
|
||||
{
|
||||
static QString s = QString("BlackBox %1").arg(version());
|
||||
return s;
|
||||
}
|
||||
|
||||
const char *CProject::systemNameAndVersionChar()
|
||||
{
|
||||
static const QByteArray a(systemNameAndVersion().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
int CProject::versionMajor()
|
||||
{
|
||||
return getMajorMinor(0);
|
||||
}
|
||||
|
||||
int CProject::versionMinor()
|
||||
{
|
||||
return getMajorMinor(1);
|
||||
}
|
||||
|
||||
int CProject::getMajorMinor(int index)
|
||||
{
|
||||
QString v = version();
|
||||
if (v.isEmpty() || !v.contains(".")) return -1;
|
||||
bool ok;
|
||||
int vi = v.split(".")[index].toInt(&ok);
|
||||
return ok ? vi : -1;
|
||||
}
|
||||
}
|
||||
|
||||
#undef BLACK_VERSION_STR
|
||||
#undef BLACK_VERSION_STR_X
|
||||
66
src/blackmisc/project.h
Normal file
66
src/blackmisc/project.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef BLACKMISC_CPROJECT_H
|
||||
#define BLACKMISC_CPROJECT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Metadata about the project
|
||||
*/
|
||||
class CProject
|
||||
{
|
||||
public:
|
||||
//! with BlackCore?
|
||||
static bool isCompiledWithBlackCore();
|
||||
|
||||
//! with BlackSound?
|
||||
static bool isCompiledWithBlackSound();
|
||||
|
||||
//! with FSX support?
|
||||
static bool isCompiledWithFsxSupport();
|
||||
|
||||
//! with XPlane support?
|
||||
static bool isCompiledWithXPlaneSupport();
|
||||
|
||||
//! with any simulator libraries
|
||||
static bool isCompiledWithFlightSimulatorSupport();
|
||||
|
||||
//! with GUI?
|
||||
static bool isCompiledWithGui();
|
||||
|
||||
//! Compiled with as info string
|
||||
static const QString &compiledInfo();
|
||||
|
||||
//! Simulator String info
|
||||
static const QString &simulators();
|
||||
|
||||
//! Simulator String info
|
||||
static const char *simulatorsChar();
|
||||
|
||||
//! Version info
|
||||
static const QString &version();
|
||||
|
||||
//! System's name and version
|
||||
static const QString &systemNameAndVersion();
|
||||
|
||||
//! System's name and version
|
||||
static const char *systemNameAndVersionChar();
|
||||
|
||||
//! Version major
|
||||
static int versionMajor();
|
||||
|
||||
//! Version minor
|
||||
static int versionMinor();
|
||||
|
||||
private:
|
||||
//! Constructor
|
||||
CProject() {}
|
||||
|
||||
//! Split version
|
||||
static int getMajorMinor(int index);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user