diff --git a/client.pro b/client.pro index ef7d67223..a6bbf8d56 100644 --- a/client.pro +++ b/client.pro @@ -3,9 +3,7 @@ include (config.pri) TEMPLATE = subdirs CONFIG += ordered -contains(BLACK_CONFIG, BlackMisc) { - SUBDIRS += src/blackmisc -} +SUBDIRS += src/blackmisc contains(BLACK_CONFIG, BlackSound) { SUBDIRS += src/blacksound diff --git a/config.pri b/config.pri index b5581523b..36abc3f21 100644 --- a/config.pri +++ b/config.pri @@ -8,7 +8,8 @@ BLACK_VER_MAJ = 0 BLACK_VER_MIN = 4 BLACK_VER_PAT = 0 -BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VERSION} +BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_PAT} +DEFINES += BLACK_VERSION=$$BLACK_VERSION ########################### # Install paths @@ -19,7 +20,6 @@ BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VERSION} # Build configuration ########################### -BLACK_CONFIG += BlackMisc BLACK_CONFIG += BlackCore BLACK_CONFIG += BlackGui BLACK_CONFIG += BlackSound @@ -29,3 +29,14 @@ BLACK_CONFIG += Unittests #BLACK_CONFIG += FSX #BLACK_CONFIG += XPlane #BLACK_CONFIG += Doxygen + +################################ +# Defines, for compile time code +################################ + +contains(BLACK_CONFIG, BlackSound) { DEFINES += WITH_BLACKSOUND } +contains(BLACK_CONFIG, BlackSim) { DEFINES += WITH_BLACKSIM } +contains(BLACK_CONFIG, BlackCore) { DEFINES += WITH_BLACKCORE } +contains(BLACK_CONFIG, BlackGui) { DEFINES += WITH_BLACKGUI } +contains(BLACK_CONFIG, FSX) { DEFINES += WITH_FSX } +contains(BLACK_CONFIG, XPlane) { DEFINES += WITH_XPLANE } diff --git a/samples/blackcore/main.cpp b/samples/blackcore/main.cpp index 00f8de7ed..b9340cdab 100644 --- a/samples/blackcore/main.cpp +++ b/samples/blackcore/main.cpp @@ -10,6 +10,7 @@ #include "blackcore/context_application_impl.h" #include "blackmisc/networkutils.h" #include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/project.h" #include #include #include @@ -29,6 +30,10 @@ int main(int argc, char *argv[]) QApplication::setWindowIcon(icon); QTextStream cin(stdin); + qDebug() << BlackMisc::CProject::version(); + qDebug() << BlackMisc::CProject::compiledInfo(); + qDebug(); + qDebug() << "1 + la/ra .. session DBus server (default)"; qDebug() << "2 + la/ra .. system DBus server"; qDebug() << "3 + la/ra .. P2P DBus server"; diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index d66fa3288..9bb2b83cb 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -33,6 +33,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) // with frameless window, we shift menu and statusbar into central widget // http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5 + this->setWindowTitle(CProject::systemNameAndVersion()); if (this->m_windowMode == GuiModes::WindowFrameless) { @@ -151,6 +152,10 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) // We don't receive signals from the past. So ask for it simulate an initial signal simulatorConnectionChanged(this->getIContextSimulator()->isConnected()); + // info + this->ui->te_StatusPageConsole->appendPlainText(CProject::systemNameAndVersion()); + this->ui->te_StatusPageConsole->appendPlainText(CProject::compiledInfo()); + // do this as last statement, so it can be used as flag // whether init has been completed this->m_init = true; diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 1c2855f1d..08460bf24 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -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 diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index 324190445..b0a3cbab7 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -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 #include #include @@ -11,10 +12,6 @@ static_assert(! std::is_abstract::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(net->GetVatsimStatusUrls(), [=](const char *const *p){ net->GetVatsimStatusUrls_Free(p); }); + auto urlsPtr = QSharedPointer(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(net->GetVatsimFSDServerNames(), [=](const char *const *p){ net->GetVatsimFSDServerNames_Free(p); }); - auto ipsPtr = QSharedPointer(net->GetVatsimFSDServerIps(), [=](const char *const *p){ net->GetVatsimFSDServerIps_Free(p); }); - auto locationsPtr = QSharedPointer(net->GetVatsimFSDServerLocations(), [=](const char *const *p){ net->GetVatsimFSDServerLocations_Free(p); }); - auto acceptsPtr = QSharedPointer(net->GetVatsimFSDServerAcceptingConnections(), [=](const bool *p){ net->GetVatsimFSDServerAcceptingConnections_Free(p); }); + auto namesPtr = QSharedPointer(net->GetVatsimFSDServerNames(), [ = ](const char *const * p) { net->GetVatsimFSDServerNames_Free(p); }); + auto ipsPtr = QSharedPointer(net->GetVatsimFSDServerIps(), [ = ](const char *const * p) { net->GetVatsimFSDServerIps_Free(p); }); + auto locationsPtr = QSharedPointer(net->GetVatsimFSDServerLocations(), [ = ](const char *const * p) { net->GetVatsimFSDServerLocations_Free(p); }); + auto acceptsPtr = QSharedPointer(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()); } diff --git a/src/blackmisc/project.cpp b/src/blackmisc/project.cpp new file mode 100644 index 000000000..26dcb7307 --- /dev/null +++ b/src/blackmisc/project.cpp @@ -0,0 +1,141 @@ +#include "project.h" +#include +#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 = ""; + } + 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 = ""; + } + 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 diff --git a/src/blackmisc/project.h b/src/blackmisc/project.h new file mode 100644 index 000000000..9f608b5e4 --- /dev/null +++ b/src/blackmisc/project.h @@ -0,0 +1,66 @@ +#ifndef BLACKMISC_CPROJECT_H +#define BLACKMISC_CPROJECT_H + +#include + +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