diff --git a/client.pro b/client.pro index a6a28e996..2ba0b8bea 100644 --- a/client.pro +++ b/client.pro @@ -17,7 +17,7 @@ WITH_SAMPLES = ON equals(WITH_BLACKMISC, ON) { SUBDIRS += src/blackmisc - #SUBDIRS += src/blackmisc_cpp2xml + SUBDIRS += src/blackmisc_cpp2xml } equals(WITH_BLACKCORE, ON) { diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 8945cc7cb..8cff9d0b4 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -153,11 +153,11 @@ bool MainWindow::reloadOwnAircraft() */ void MainWindow::toggleNetworkConnection() { - CStatusMessages msgs; + CStatusMessageList msgs; if (!this->isContextNetworkAvailableCheck()) return; if (!this->m_contextNetwork->isConnected()) { - QString cs = this->ui->le_SettingsPlaneCallsign->text(); + QString cs = this->ui->le_SettingsAircraftCallsign->text(); if (cs.isEmpty()) { this->displayStatusMessage(CStatusMessage::getValidationError("missing callsign")); @@ -196,10 +196,10 @@ void MainWindow::displayStatusMessage(const CStatusMessage &message) /* * Display a status message */ -void MainWindow::displayStatusMessages(const CStatusMessages &messages) +void MainWindow::displayStatusMessages(const CStatusMessageList &messages) { if (messages.isEmpty()) return; - foreach(CStatusMessage msg, messages.getMessages()) + foreach(CStatusMessage msg, messages) { this->displayStatusMessage(msg); } @@ -211,37 +211,44 @@ void MainWindow::displayStatusMessages(const CStatusMessages &messages) void MainWindow::menuClicked() { QObject *sender = QObject::sender(); - CStatusMessages msgs; + CStatusMessageList msgs; + if (sender == this->ui->menu_TestLocationsEDRY) { - this->m_contextNetwork->updateOwnPosition( - CCoordinateGeodetic( - CLatitude::fromWgs84("N 049° 18' 17"), - CLongitude::fromWgs84("E 008° 27' 05"), - CLength(0, CLengthUnit::m())), - CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()) - ); + this->setTestPosition("N 049° 18' 17", "E 008° 27' 05", CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())); + } + else if (sender == this->ui->menu_TestLocationsEDNX) + { + this->setTestPosition("N 048° 14′ 22", "E 011° 33′ 41", CAltitude(486, CAltitude::MeanSeaLevel, CLengthUnit::m())); + } + else if (sender == this->ui->menu_TestLocationsEDDM) + { + this->setTestPosition("N 048° 21′ 14", "E 011° 47′ 10", CAltitude(448, CAltitude::MeanSeaLevel, CLengthUnit::m())); + } + else if (sender == this->ui->menu_TestLocationsEDDF) + { + this->setTestPosition("N 50° 2′ 0", "E 8° 34′ 14", CAltitude(100, CAltitude::MeanSeaLevel, CLengthUnit::m())); } else if (sender == this->ui->menu_ReloadSettings) { this->reloadSettings(); - msgs.append(CStatusMessage::getInfoMessage("Settings reloaded")); + msgs.push_back(CStatusMessage::getInfoMessage("Settings reloaded")); } if (!msgs.isEmpty()) this->displayStatusMessages(msgs); } /* - * Connection terminated - */ +* Connection terminated +*/ void MainWindow::connectionTerminated() { this->updateGuiStatusInformation(); } /* - * Connection status changed - */ +* Connection status changed +*/ void MainWindow::connectionStatusChanged(uint /** from **/, uint to) { // CContextNetwork::ConnectionStatus statusFrom = static_cast(from); diff --git a/samples/blackgui/mainwindow_cockpit.cpp b/samples/blackgui/mainwindow_cockpit.cpp index 041e910bd..264959159 100644 --- a/samples/blackgui/mainwindow_cockpit.cpp +++ b/samples/blackgui/mainwindow_cockpit.cpp @@ -20,6 +20,8 @@ using namespace BlackMisc::Math; void MainWindow::cockpitValuesChanged() { Q_ASSERT(this->m_timerCollectedCockpitUpdates); + + // this will call send cockpit updates with all changes made this->m_timerCollectedCockpitUpdates->stop(); this->m_timerCollectedCockpitUpdates->start(1000); // start this->m_timerCollectedCockpitUpdates->setSingleShot(true); @@ -83,6 +85,21 @@ void MainWindow::updateCockpitFromContext() default: break; } + +/* + * Reset transponder mode to Standby + */ +void MainWindow::resetTransponderModerToStandby() +{ + this->ui->cb_CockpitTransponderMode->setCurrentText("S"); +} + +/* + * Reset transponder mode to Standby + */ +void MainWindow::resetTransponderModerToCharly() +{ + this->ui->cb_CockpitTransponderMode->setCurrentText("C"); } /* @@ -94,6 +111,9 @@ void MainWindow::sendCockpitUpdates() CComSystem com1 = this->m_ownAircraft.getCom1System(); CComSystem com2 = this->m_ownAircraft.getCom2System(); + // + // Transponder + // QString transponderCode = QString::number(qRound(this->ui->ds_CockpitTransponder->value())); if (CTransponder::isValidTransponderCode(transponderCode)) { @@ -101,8 +121,8 @@ void MainWindow::sendCockpitUpdates() } else { - this->displayStatusMessage(CStatusMessage::getValidationError("Wrong transponder code")); - return; + this->displayStatusMessage(CStatusMessage::getValidationError("Wrong transponder code, reset")); + this->ui->ds_CockpitTransponder->setValue(transponder.getTransponderCode()); } QString tm = this->ui->cb_CockpitTransponderMode->currentText().toUpper(); @@ -111,13 +131,28 @@ void MainWindow::sendCockpitUpdates() else if (tm == "C") transponder.setTransponderMode(CTransponder::ModeC); else if (tm == "I") + { + // ident shall be sent for some time, then reset transponder.setTransponderMode(CTransponder::StateIdent); + if (this->m_ownAircraft.getTransponderMode() == CTransponder::ModeS) + QTimer::singleShot(5000, this, SLOT(resetTransponderModerToStandby())); + else + QTimer::singleShot(5000, this, SLOT(resetTransponderModerToCharly())); + } + // + // COM units + // com1.setFrequencyActiveMHz(this->ui->ds_CockpitCom1Active->value()); com1.setFrequencyStandbyMHz(this->ui->ds_CockpitCom1Standby->value()); com2.setFrequencyActiveMHz(this->ui->ds_CockpitCom2Active->value()); com2.setFrequencyStandbyMHz(this->ui->ds_CockpitCom2Standby->value()); + + // + // Send to context + // + bool changedCockpit = false; if (this->m_contextNetworkAvailable) { if (this->m_ownAircraft.getCom1System() != com1 || @@ -125,7 +160,8 @@ void MainWindow::sendCockpitUpdates() this->m_ownAircraft.getTransponder() != transponder) { this->m_contextNetwork->updateOwnCockpit(com1, com2, transponder); - this->reloadOwnAircraft(); + this->reloadOwnAircraft(); // also loads resolved voice rooms + changedCockpit = true; } } } diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 405be394c..15850f90e 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -17,7 +17,6 @@ using namespace BlackGui; void MainWindow::init(bool withDBus) { if (this->m_init) return; - this->m_init = true; this->m_withDBus = withDBus; // init models, the delete allows to re-init @@ -120,6 +119,7 @@ void MainWindow::init(bool withDBus) connect = this->connect(this->ui->sw_MainMiddle, SIGNAL(currentChanged(int)), this, SLOT(middlePanelChanged(int))); Q_ASSERT_X(connect, "init", "cannot connect middle panle changed"); + Q_UNUSED(connect); // start timers @@ -132,6 +132,10 @@ void MainWindow::init(bool withDBus) // start screen this->setMainPage(true); + + // do this as last statement, so it can be used as flag + // whether init has been completed + this->m_init = true; } /* @@ -140,8 +144,8 @@ void MainWindow::init(bool withDBus) void MainWindow::initialDataReads() { qint64 t = QDateTime::currentMSecsSinceEpoch(); - m_contextNetworkAvailable = (this->m_contextNetwork->usingLocalObjects() || (this->m_contextNetwork->ping(t) == t)); - if (!this->m_contextNetworkAvailable) + this->m_coreAvailable = (this->m_contextNetwork->usingLocalObjects() || (this->m_contextApplication->ping(t) == t)); + if (!this->m_coreAvailable) { this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, "No initial data read as network context is not available")); diff --git a/samples/blackgui/mainwindow_settings.cpp b/samples/blackgui/mainwindow_settings.cpp index eb3d6acfa..ffee45264 100644 --- a/samples/blackgui/mainwindow_settings.cpp +++ b/samples/blackgui/mainwindow_settings.cpp @@ -50,7 +50,7 @@ void MainWindow::alterTrafficServer() const QString path = CSettingUtilities::appendPaths(IContextSettings::PathNetworkSettings(), CSettingsNetwork::PathTrafficServer()); QObject *sender = QObject::sender(); - CStatusMessages msgs; + CStatusMessageList msgs; if (sender == this->ui->pb_SettingsTnCurrentServer) { msgs = this->m_contextSettings->value(path, CSettingsNetwork::CmdSetCurrentServer(), server.toQVariant()); @@ -85,7 +85,7 @@ void MainWindow::updateGuiSelectedServerTextboxes(const CServer &server) this->ui->le_SettingsTnCsDescription->setText(server.getDescription()); this->ui->le_SettingsTnCsAddress->setText(server.getAddress()); this->ui->le_SettingsTnCsPort->setText(QString::number(server.getPort())); - this->ui->le_SettingsTnCsRealname->setText(server.getUser().getRealname()); + this->ui->le_SettingsTnCsRealName->setText(server.getUser().getRealName()); this->ui->le_SettingsTnCsNetworkId->setText(server.getUser().getId()); this->ui->le_SettingsTnCsPassword->setText(server.getUser().getPassword()); } @@ -105,7 +105,7 @@ CServer MainWindow::selectedServerFromTextboxes() const if (!portOk) server.setPort(-1); CUser user; - user.setRealname(this->ui->le_SettingsTnCsRealname->text()); + user.setRealName(this->ui->le_SettingsTnCsRealName->text()); user.setId(this->ui->le_SettingsTnCsNetworkId->text()); user.setPassword(this->ui->le_SettingsTnCsPassword->text()); server.setUser(user); diff --git a/samples/blackgui/mainwindow_textmessages.cpp b/samples/blackgui/mainwindow_textmessages.cpp index 35e3825d0..63cf47f9b 100644 --- a/samples/blackgui/mainwindow_textmessages.cpp +++ b/samples/blackgui/mainwindow_textmessages.cpp @@ -168,8 +168,6 @@ void MainWindow::closeTextMessageTab() if (index >= 0) this->ui->tw_TextMessages->removeTab(index); } - - /* * Command entered */ @@ -185,7 +183,7 @@ void MainWindow::commandEntered() QString cmd = parts[0].startsWith('.') ? parts[0].toLower() : ""; if (cmd == ".m" || cmd == ".msg") { - if (!this->m_contextNetwork->isConnected()) + if (!this->m_contextNetworkAvailable || !this->m_contextNetwork->isConnected()) { this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "network needs to be connected")); return; @@ -217,7 +215,7 @@ void MainWindow::commandEntered() this->ui->tw_TextMessages->setCurrentWidget(tab); } CTextMessage tm = this->getTextMessageStubForChannel(); - int index = cmdLine.indexOf(tm.getToCallsign().asString(), 0, Qt::CaseInsensitive); + int index = cmdLine.indexOf(tm.getToCallsign().getStringAsSet(), 0, Qt::CaseInsensitive); if (index < 0) { this->displayStatusMessage( diff --git a/samples/blackmisc/samplescontainer.cpp b/samples/blackmisc/samplescontainer.cpp index 928cad89a..b6060afc6 100644 --- a/samples/blackmisc/samplescontainer.cpp +++ b/samples/blackmisc/samplescontainer.cpp @@ -52,7 +52,7 @@ namespace BlackMiscTest qDebug() << "-- find by:"; qDebug() << atcListFind.toQString(); - CAtcStationList atcListSort = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealname); + CAtcStationList atcListSort = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealName); qDebug() << "-- sort by:"; qDebug() << atcListSort.toQString(); diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index 96fe88fce..5d0195f45 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -96,7 +96,7 @@ namespace BlackMiscTest atcList.push_back(station2); atcList.push_back(station3); atcList = atcList.findBy(&CAtcStation::getCallsign, "eddm_twr", &CAtcStation::getFrequency, CFrequency(118.7, CFrequencyUnit::MHz())); - atcList = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealname); + atcList = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealName); qDebug() << atcList; qDebug() << "-----------------------------------------------"; diff --git a/samples/cli_client/main.cpp b/samples/cli_client/main.cpp index 44cf0126a..170cad6d9 100644 --- a/samples/cli_client/main.cpp +++ b/samples/cli_client/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) BlackMisc::IContext::setInstance(ctx); BlackMisc::CDebug debug; ctx.setObject(debug); - BlackCore::NetworkVatlib net; + BlackCore::CNetworkVatlib net; ctx.setObject(net); Client client(ctx); diff --git a/samples/voiceclient/client.cpp b/samples/voiceclient/client.cpp index fec6cb9b3..b112da23b 100644 --- a/samples/voiceclient/client.cpp +++ b/samples/voiceclient/client.cpp @@ -30,7 +30,7 @@ Client::Client(QObject *parent) : m_commands["termconnect"] = std::bind(&Client::terminateConnectionCmd, this, _1); m_commands["inputdevices"] = std::bind(&Client::inputDevicesCmd, this, _1); m_commands["outputdevices"] = std::bind(&Client::outputDevicesCmd, this, _1); - m_commands["users"] = std::bind(&Client::listUsersCmd, this, _1); + m_commands["users"] = std::bind(&Client::listCallsignsCmd, this, _1); } @@ -103,7 +103,7 @@ void Client::setCallsignCmd(QTextStream &args) { QString callsign; args >> callsign; - m_voiceClient->setCallsign(BlackMisc::Aviation::CCallsign(callsign)); + m_voiceClient->setMyAircraftCallsign(BlackMisc::Aviation::CCallsign(callsign)); } void Client::initiateConnectionCmd(QTextStream &args) @@ -143,7 +143,10 @@ void Client::outputDevicesCmd(QTextStream & /** args **/) printLinePrefix(); } -void Client::listUsersCmd(QTextStream &args) +/* + * Input devices + */ +void Client::listCallsignsCmd(QTextStream &args) { Q_UNUSED(args) QSet users = m_voiceClient->roomUserList(BlackCore::IVoiceClient::COM1); diff --git a/samples/voiceclient/client.h b/samples/voiceclient/client.h index db9ad46d1..151cb5558 100644 --- a/samples/voiceclient/client.h +++ b/samples/voiceclient/client.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef CLIENT_H -#define CLIENT_H +#ifndef SAMPLE_VOICECLIENT +#define SAMPLE_VOICECLIENT #include "blackcore/voiceclient.h" @@ -15,8 +15,9 @@ class Client : public QObject { Q_OBJECT + public: - Client(QObject *parent = 0); + Client(QObject *parent = nullptr); signals: void quit(); @@ -35,7 +36,7 @@ private: //commands void terminateConnectionCmd(QTextStream &args); void inputDevicesCmd(QTextStream &args); void outputDevicesCmd(QTextStream &args); - void listUsersCmd(QTextStream &args); + void listCallsignsCmd(QTextStream &args); void printLinePrefix(); diff --git a/samples/voiceclient/main.cpp b/samples/voiceclient/main.cpp index 877d5f42d..3ac3c3a49 100644 --- a/samples/voiceclient/main.cpp +++ b/samples/voiceclient/main.cpp @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) Client client; LineReader reader; - QObject::connect(&reader, SIGNAL(command(const QString&)), &client, SLOT(command(const QString&))); + QObject::connect(&reader, SIGNAL(command(const QString &)), &client, SLOT(command(const QString &))); QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate())); QObject::connect(&client, SIGNAL(quit()), &app, SLOT(quit())); diff --git a/src/blackcore/blackcore.contextnetwork.xml b/src/blackcore/blackcore.contextnetwork.xml index 9da320a3f..2e9fd6071 100644 --- a/src/blackcore/blackcore.contextnetwork.xml +++ b/src/blackcore/blackcore.contextnetwork.xml @@ -18,44 +18,30 @@ - + - + - + - + - + - - - - - - - - - - - - - - @@ -67,15 +53,15 @@ - + - + - + diff --git a/src/blackcore/blackcore.contextsettings.xml b/src/blackcore/blackcore.contextsettings.xml index 38717488e..abba67243 100644 --- a/src/blackcore/blackcore.contextsettings.xml +++ b/src/blackcore/blackcore.contextsettings.xml @@ -7,13 +7,5 @@ - - - - - - - - diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index ed1f9d7ec..3d93d31ee 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -1,6 +1,7 @@ include (../../externals.pri) # GUI is required for the matrix classes +# Network for host info etc. QT += network dbus xml TARGET = blackcore @@ -20,11 +21,11 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { # Causes nmake to run qdbusxml2cpp to automatically generate the dbus adaptor and interface classes, # then automatically adds them to the sources to compile # !! Make sure the plugin is available as release build and known QT_PLUGIN_PATH -# QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h QDBUSXML2CPP_ADAPTOR_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h DBUS_ADAPTORS += blackcore.contextnetwork.xml DBUS_ADAPTORS += blackcore.contextsettings.xml +# QDBUSXML2CPP_INTERFACE_HEADER_FLAGS = -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h # DBUS_INTERFACES += blackcore.contextnetwork.xml DEFINES += LOG_IN_FILE @@ -37,4 +38,4 @@ else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../lib -OTHER_FILES += readme.txt blackcore.contextnetwork.xml blackcore.contextsettings.xml +OTHER_FILES += readme.txt *.xml diff --git a/src/blackcore/context_network.cpp b/src/blackcore/context_network.cpp index e00efd185..9b1093b57 100644 --- a/src/blackcore/context_network.cpp +++ b/src/blackcore/context_network.cpp @@ -21,14 +21,11 @@ namespace BlackCore * Init this context */ CContextNetwork::CContextNetwork(CCoreRuntime *parent) : - IContextNetwork(parent), - m_atcStationsOnline(), m_atcStationsBooked(), m_aircraftsInRange(), - m_network(nullptr), m_ownAircraft(), - m_metarCache() + IContextNetwork(parent), m_network(nullptr) { // 1. Init by "network driver" - this->m_network = new NetworkVatlib(this); + this->m_network = new CNetworkVatlib(this); // 2. Init own aircraft this->initOwnAircraft(); @@ -41,8 +38,9 @@ namespace BlackCore this->m_atcBookingTimer->start(15 * 1000); // 4. connect signals and slots - bool connect = this->connect(this->m_network, SIGNAL(connectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus)), - this, SLOT(psFsdConnectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus))); + bool connect; + connect = this->connect(this->m_network, SIGNAL(connectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus)), + this, SLOT(psFsdConnectionStatusChanged(Cvatlib_Network::connStatus, Cvatlib_Network::connStatus))); Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect connectionStatusChanged"); connect = this->connect(this->m_network, SIGNAL(terminate()), @@ -53,8 +51,8 @@ namespace BlackCore this, SLOT(psFsdAtcPositionUpdate(BlackMisc::Aviation::CCallsign, BlackMisc::PhysicalQuantities::CFrequency, BlackMisc::Geo::CCoordinateGeodetic, BlackMisc::PhysicalQuantities::CLength))); Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect atcPositionUpdate"); - connect = this->connect(this->m_network, SIGNAL(atisQueryReplyReceived(BlackMisc::Aviation::CCallsign, QString)), - this, SLOT(psFsdAtisQueryReceived(BlackMisc::Aviation::CCallsign, QString))); + connect = this->connect(this->m_network, SIGNAL(atisQueryReplyReceived(BlackMisc::Aviation::CCallsign, Cvatlib_Network::atisLineType, QString)), + this, SLOT(psFsdAtisQueryReceived(BlackMisc::Aviation::CCallsign, Cvatlib_Network::atisLineType, QString))); Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect atis"); connect = this->connect(this->m_network, SIGNAL(metarReceived(QString)), @@ -94,6 +92,8 @@ namespace BlackCore connect = this->connect(this->m_network, SIGNAL(statusMessage(BlackMisc::CStatusMessage)), this, SIGNAL(statusMessage(BlackMisc::CStatusMessage))); Q_ASSERT_X(connect, "CContextNetwork", "Cannot connect status message"); + Q_UNUSED(connect); // no warning in release mode + } /* @@ -102,8 +102,6 @@ namespace BlackCore CContextNetwork::~CContextNetwork() { if (this->isConnected()) this->disconnectFromNetwork(); - this->disconnect(this); - this->disconnect(this->m_network); } /* @@ -134,16 +132,15 @@ namespace BlackCore /* * Connect to network */ - CStatusMessages CContextNetwork::connectToNetwork() + CStatusMessageList CContextNetwork::connectToNetwork() { - qDebug() << Q_FUNC_INFO; - - CStatusMessages msgs; + // this->log(Q_FUNC_INFO); + CStatusMessageList msgs; CServer currentServer = this->getRuntime()->getIContextSettings()->getNetworkSettings().getCurrentNetworkServer(); if (!currentServer.getUser().isValid()) { - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials")); + msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials")); } //else if (!this->m_network->isDisconnected()) //{ @@ -157,7 +154,7 @@ namespace BlackCore this->m_network->initiateConnection(); QString msg = "Connection pending "; msg.append(" ").append(currentServer.getAddress()).append(" ").append(QString::number(currentServer.getPort())); - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, msg)); + msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, msg)); } return msgs; } @@ -165,14 +162,13 @@ namespace BlackCore /* * Disconnect from network */ - CStatusMessages CContextNetwork::disconnectFromNetwork() + CStatusMessageList CContextNetwork::disconnectFromNetwork() { - qDebug() << Q_FUNC_INFO; - - CStatusMessages msgs; + // this->log(Q_FUNC_INFO); + CStatusMessageList msgs; //if (this->m_network->isDisconnected()) //{ - // msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected")); + // msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected")); //} //else { @@ -181,7 +177,7 @@ namespace BlackCore this->m_atcStationsBooked.clear(); this->m_atcStationsOnline.clear(); this->m_metarCache.clear(); - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, "Connection terminating")); + msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, "Connection terminating")); } return msgs; } @@ -194,78 +190,33 @@ namespace BlackCore return false; } - /* - * Own's plane position update - */ - void CContextNetwork::sendOwnAircraftCheckedPositionUpdateToNetwork() const - { - // TODO: Would this logic go into network_vatlib? - // 1. Check not sending to many updates - // 2. Send as pull update to intermediate update - // 3. Same position, no update? - // ... - - // this->log(Q_FUNC_INFO, this->m_ownAircraft.toQString()); - // this->m_network->sendAircraftUpdate(this->m_ownAircraft); - } - /* * Own Aircraft */ - CStatusMessages CContextNetwork::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) + CStatusMessageList CContextNetwork::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) { - this->log(Q_FUNC_INFO, aircraft.toQString()); - CStatusMessages msgs; + // this->log(Q_FUNC_INFO, aircraft.toQString()); + CStatusMessageList msgs; //if (this->m_network->isDisconnected()) - //{ - // this->m_ownAircraft = aircraft; - //} + { + this->m_ownAircraft = aircraft; + } //else - { - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot set plane info, network already connected")); - } + //{ + // msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot set plane info, network already connected")); + //} return msgs; } - /* - * Own Aircraft details - */ - CStatusMessages CContextNetwork::sendOwnAircraftDetails() - { -#if 0 - CStatusMessages msgs; - if (this->m_network->isDisconnected() && false) - { - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot send plane info, network not connected")); - - } - else if (!this->m_ownAircraft.isValidForLogin()) - { - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot send plane info, own aircraft is invalid")); - } - else - { - // TODO: really sending plane info ?? - // NOPE: this->m_network->sendAircraftInfo(this->m_ownAircraft); - this->sendOwnAircraftCheckedPositionUpdateToNetwork(); - QString m("Aircraft send "); - m.append(this->m_ownAircraft.toQString(true)); - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m)); - } - return msgs; -#endif // 0 - return CStatusMessages(); - } - /* * Own position */ void CContextNetwork::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) { - if (position == this->m_ownAircraft.getPosition() && altitude == this->m_ownAircraft.getAltitude()) return; + // TODO: Do I really need own member? this->m_ownAircraft.setPosition(position); this->m_ownAircraft.setAltitude(altitude); - this->sendOwnAircraftCheckedPositionUpdateToNetwork(); + this->m_network->setOwnAircraftPosition(this->m_ownAircraft.getSituation()); } /* @@ -273,9 +224,9 @@ namespace BlackCore */ void CContextNetwork::updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) { - if (situation == this->m_ownAircraft.getSituation()) return; + // TODO: Do I really need own member? this->m_ownAircraft.setSituation(situation); - this->sendOwnAircraftCheckedPositionUpdateToNetwork(); + this->m_network->setOwnAircraftPosition(situation); } /* @@ -309,7 +260,7 @@ namespace BlackCore */ CAircraft CContextNetwork::getOwnAircraft() const { - this->log(Q_FUNC_INFO, this->m_ownAircraft.toQString()); + // this->log(Q_FUNC_INFO, this->m_ownAircraft.toQString()); return this->m_ownAircraft; } @@ -318,7 +269,7 @@ namespace BlackCore */ void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages) { - this->log(Q_FUNC_INFO, textMessages.toQString()); + // this->log(Q_FUNC_INFO, textMessages.toQString()); this->m_network->sendTextMessages(textMessages); } @@ -338,13 +289,15 @@ namespace BlackCore { ConnectionStatus fromCs = static_cast(from); ConnectionStatus toCs = static_cast(to); - CStatusMessages msgs; + CStatusMessageList msgs; // send 1st position if (toCs == CContextNetwork::ConnectionStatusConnected) { - msgs = this->sendOwnAircraftDetails(); + QString m("Connected, own aircraft "); + m.append(this->m_ownAircraft.toQString(true)); + msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m)); } // send as message @@ -352,10 +305,9 @@ namespace BlackCore m.append(this->connectionStatusToString(fromCs)). append(" "). append(this->connectionStatusToString(toCs)); - qDebug() << m; - msgs.append(CStatusMessage(CStatusMessage::TypeTrafficNetwork, + msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, toCs == ConnectionStatusError ? CStatusMessage::SeverityError : CStatusMessage::SeverityInfo, m)); - emit this->statusMessage(msgs.at(0)); + emit this->statusMessage(msgs[0]); // send as own signal emit this->connectionStatusChanged(fromCs, toCs); @@ -366,13 +318,13 @@ namespace BlackCore */ void CContextNetwork::psFsdNameQueryReplyReceived(const CCallsign &callsign, const QString &realname) { - this->log(Q_FUNC_INFO, callsign.toQString(), realname); + // this->log(Q_FUNC_INFO, callsign.toQString(), realname); if (realname.isEmpty()) return; - CValueMap vm(CAtcStation::IndexControllerRealname, realname); + CValueMap vm(CAtcStation::IndexControllerRealName, realname); this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); - vm = CValueMap(CAircraft::IndexPilotRealname, realname); + vm = CValueMap(CAircraft::IndexPilotRealName, realname); this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm); } @@ -390,8 +342,7 @@ namespace BlackCore */ void CContextNetwork::psVatlibExceptionMessage(const QString &message, bool fatal) { - CStatusMessage msg(CStatusMessage::TypeTrafficNetwork, - fatal ? CStatusMessage::SeverityError : CStatusMessage::SeverityWarning, message); + CStatusMessage msg(CStatusMessage::TypeTrafficNetwork, fatal ? CStatusMessage::SeverityError : CStatusMessage::SeverityWarning, message); emit this->statusMessage(msg); } diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index 2c9d3e82e..3f55ac66b 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -11,22 +11,17 @@ #include "blackcore/context_network_interface.h" #include "blackmisc/avallclasses.h" #include "blackmisc/statusmessage.h" -#include "blackmisc/statusmessages.h" -#include -#include -#include -#include -#include -#include +#include "blackmisc/statusmessagelist.h" + +class QNetworkAccessManager; +class QNetworkReply; #define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "blackcore.contextnetwork" namespace BlackCore { - class CCoreRuntime; - /*! * \brief Network context */ @@ -90,7 +85,7 @@ namespace BlackCore // needs to be crosschecked with the latest version of Qt virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const { - this->log(Q_FUNC_INFO); + // this->log(Q_FUNC_INFO); return m_atcStationsOnline; } @@ -101,7 +96,7 @@ namespace BlackCore // If I make this &getAtcStations XML is not generated correctly virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const { - this->log(Q_FUNC_INFO); + // this->log(Q_FUNC_INFO); return m_atcStationsBooked; } @@ -112,7 +107,7 @@ namespace BlackCore // If I make this &getAtcStations XML is not generated correctly virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const { - this->log(Q_FUNC_INFO); + // this->log(Q_FUNC_INFO); return m_aircraftsInRange; } @@ -120,13 +115,13 @@ namespace BlackCore * \brief Connect to Network * \return */ - virtual BlackMisc::CStatusMessages connectToNetwork(); + virtual BlackMisc::CStatusMessageList connectToNetwork(); /*! * \brief Disconnect from network * \return */ - virtual BlackMisc::CStatusMessages disconnectFromNetwork(); + virtual BlackMisc::CStatusMessageList disconnectFromNetwork(); /*! * \brief Network connected? @@ -139,7 +134,7 @@ namespace BlackCore * \param aircraft * \return */ - virtual BlackMisc::CStatusMessages setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft); + virtual BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft); /*! * \brief Update own position @@ -193,7 +188,8 @@ namespace BlackCore BlackMisc::Aviation::CAircraftList m_aircraftsInRange; BlackCore::INetwork *m_network; BlackMisc::Aviation::CAircraft m_ownAircraft; - QMap m_metarCache; + QMap m_metarCache /*!< Keep METARs for a while */; + QMap m_atisMessageBuilder; /*!< ATIS consists of several parts, complete ATIS needs to be concatenated */ // for reading XML QNetworkAccessManager *m_networkManager; @@ -230,18 +226,6 @@ namespace BlackCore return m_atcStationsBooked; } - /*! - * \brief Check position update before sending to network - */ - void sendOwnAircraftCheckedPositionUpdateToNetwork() const; - - /*! - * \brief Own aircraft details - * \param aircraft - * \return - */ - BlackMisc::CStatusMessages sendOwnAircraftDetails(); - /*! * \brief Init my very onw aircraft */ @@ -276,11 +260,12 @@ namespace BlackCore void psFsdAtcControllerDisconnected(const BlackMisc::Aviation::CCallsign &callsign); /*! - * \brief ATIS received + * \brief ATIS received (also relevant to get voice server) * \param callsign + * \param lineType * \param atisMessage */ - void psFsdAtisQueryReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &atisMessage); + void psFsdAtisQueryReceived(const BlackMisc::Aviation::CCallsign &callsign, Cvatlib_Network::atisLineType lineType, const QString &atisMessage); /*! * \brief METAR received diff --git a/src/blackcore/context_network_aircraft.cpp b/src/blackcore/context_network_aircraft.cpp index 02981f3fc..4dee0903f 100644 --- a/src/blackcore/context_network_aircraft.cpp +++ b/src/blackcore/context_network_aircraft.cpp @@ -21,7 +21,7 @@ namespace BlackCore */ void CContextNetwork::psFsdAircraftInfoReceived(const CCallsign &callsign, const CAircraftIcao &icaoData) { - this->log(Q_FUNC_INFO, callsign.toQString(), icaoData.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString(), icaoData.toQString()); CAircraftList aircraftsWithCallsign = this->m_aircraftsInRange.findByCallsign(callsign); if (aircraftsWithCallsign.isEmpty()) { @@ -30,7 +30,7 @@ namespace BlackCore aircraft.setCallsign(callsign); aircraft.setIcaoInfo(icaoData); aircraft.calculcateDistanceToPlane(this->m_ownAircraft.getPosition()); - this->m_aircraftsInRange.insert(aircraft); + this->m_aircraftsInRange.push_back(aircraft); emit this->m_network->sendFrequencyQuery(callsign); emit this->m_network->sendNameQuery(callsign); emit this->changedAircraftsInRange(); @@ -49,7 +49,7 @@ namespace BlackCore */ void CContextNetwork::psFsdAircraftPositionUpdate(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder) { - this->log(Q_FUNC_INFO, callsign.toQString(), situation.toQString(), transponder.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString(), situation.toQString(), transponder.toQString()); CAircraftList list = this->m_aircraftsInRange.findByCallsign(callsign); if (list.isEmpty()) { @@ -59,7 +59,7 @@ namespace BlackCore aircraft.setSituation(situation); aircraft.setTransponder(transponder); aircraft.calculcateDistanceToPlane(this->m_ownAircraft.getPosition()); - this->m_aircraftsInRange.insert(aircraft); + this->m_aircraftsInRange.push_back(aircraft); emit this->m_network->sendFrequencyQuery(callsign); emit this->m_network->sendNameQuery(callsign); emit this->m_network->requestAircraftInfo(callsign); @@ -68,9 +68,12 @@ namespace BlackCore else { // update + CLength distance = this->m_ownAircraft.calculcateDistanceToPlane(situation.getPosition()); + distance.switchUnit(CLengthUnit::NM()); CValueMap vm; vm.addValue(CAircraft::IndexTransponder, transponder); vm.addValue(CAircraft::IndexSituation, situation); + vm.addValue(CAircraft::IndexDistance, distance); this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm); emit this->changedAircraftsInRange(); } @@ -81,7 +84,7 @@ namespace BlackCore */ void CContextNetwork::psFsdPilotDisconnected(const CCallsign &callsign) { - this->log(Q_FUNC_INFO, callsign.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString()); this->m_aircraftsInRange.removeIf(&CAircraft::getCallsign, callsign); } @@ -90,7 +93,7 @@ namespace BlackCore */ void CContextNetwork::psFsdFrequencyReceived(const CCallsign &callsign, const CFrequency &frequency) { - this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString()); // update CValueMap vm(CAircraft::IndexFrequencyCom1, frequency.toQVariant()); diff --git a/src/blackcore/context_network_atc.cpp b/src/blackcore/context_network_atc.cpp index 2e4b0e210..9826bc841 100644 --- a/src/blackcore/context_network_atc.cpp +++ b/src/blackcore/context_network_atc.cpp @@ -84,7 +84,7 @@ namespace BlackCore */ void CContextNetwork::psFsdAtcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range) { - this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString(), position.toQString(), range.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString(), position.toQString(), range.toQString()); CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign); if (stationsWithCallsign.isEmpty()) { @@ -96,10 +96,12 @@ namespace BlackCore station.setPosition(position); station.setOnline(true); station.calculcateDistanceToPlane(this->m_ownAircraft.getPosition()); - this->m_atcStationsOnline.insert(station); + this->m_atisMessageBuilder[callsign.asString()] = ""; // reset ATIS builder + this->m_atcStationsOnline.push_back(station); emit this->changedAtcStationsOnline(); emit this->m_network->sendAtisQuery(callsign); // request ATIS emit this->m_network->sendNameQuery(callsign); + emit this->m_network->sendServerQuery(callsign); } else { @@ -118,7 +120,7 @@ namespace BlackCore */ void CContextNetwork::psFsdAtcControllerDisconnected(const CCallsign &callsign) { - this->log(Q_FUNC_INFO, callsign.toQString()); + // this->log(Q_FUNC_INFO, callsign.toQString()); this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign); emit this->changedAtcStationsOnline(); this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CValueMap(CAtcStation::IndexIsOnline, QVariant(false))); @@ -140,7 +142,7 @@ namespace BlackCore */ void CContextNetwork::psFsdMetarReceived(const QString &metarMessage) { - this->log(Q_FUNC_INFO, metarMessage); + // this->log(Q_FUNC_INFO, metarMessage); if (metarMessage.length() < 10) return; // invalid const QString icaoCode = metarMessage.left(4).toUpper(); const QString icaoCodeTower = icaoCode + "_TWR"; @@ -192,7 +194,7 @@ namespace BlackCore } else if (name == "name") { - user.setRealname(value); + user.setRealName(value); } else if (name == "cid") { @@ -221,7 +223,7 @@ namespace BlackCore // consolidate and append this->m_atcStationsOnline.mergeWithBooking(bookedStation); - stations.insert(bookedStation); + stations.push_back(bookedStation); } nwReply->close(); nwReply->deleteLater(); diff --git a/src/blackcore/context_network_interface.cpp b/src/blackcore/context_network_interface.cpp index 511ec222a..03bb26f08 100644 --- a/src/blackcore/context_network_interface.cpp +++ b/src/blackcore/context_network_interface.cpp @@ -95,17 +95,17 @@ namespace BlackCore /* * Relay to DBus */ - BlackMisc::CStatusMessages IContextNetwork::connectToNetwork() + BlackMisc::CStatusMessageList IContextNetwork::connectToNetwork() { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork")); } /* * Relay to DBus */ - BlackMisc::CStatusMessages IContextNetwork::disconnectFromNetwork() + BlackMisc::CStatusMessageList IContextNetwork::disconnectFromNetwork() { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); } /* @@ -113,17 +113,15 @@ namespace BlackCore */ bool IContextNetwork::isConnected() const { - qint64 token = QDateTime::currentMSecsSinceEpoch(); - if (this->ping(token) != token) return false; // Core cannot be reached return this->m_dBusInterface->callDBusRet(QLatin1Literal("isConnected")); } /* * Relay to DBus */ - BlackMisc::CStatusMessages IContextNetwork::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) + BlackMisc::CStatusMessageList IContextNetwork::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("setOwnAircraft"), aircraft); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("setOwnAircraft"), aircraft); } /* @@ -163,7 +161,7 @@ namespace BlackCore */ BlackMisc::Aviation::CInformationMessage IContextNetwork::getMetar(const QString &airportIcaoCode) { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("requestMetar"), airportIcaoCode); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getMetar"), airportIcaoCode); } /* diff --git a/src/blackcore/context_network_interface.h b/src/blackcore/context_network_interface.h index 893a3d6d8..618cb0b61 100644 --- a/src/blackcore/context_network_interface.h +++ b/src/blackcore/context_network_interface.h @@ -8,11 +8,12 @@ #include "blackmisc/avallclasses.h" #include "blackmisc/statusmessage.h" -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" #include "blackmisc/nwtextmessagelist.h" #include "blackmisc/genericdbusinterface.h" #include "blackcore/network_vatlib.h" #include +#include #include #define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "blackcore.contextnetwork" @@ -197,13 +198,13 @@ namespace BlackCore * \brief Connect to Network * \return */ - virtual BlackMisc::CStatusMessages connectToNetwork(); + virtual BlackMisc::CStatusMessageList connectToNetwork(); /*! * \brief Disconnect from network * \return */ - virtual BlackMisc::CStatusMessages disconnectFromNetwork(); + virtual BlackMisc::CStatusMessageList disconnectFromNetwork(); /*! * \brief Network connected? @@ -216,7 +217,7 @@ namespace BlackCore * \param aircraft * \return */ - virtual BlackMisc::CStatusMessages setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft); + virtual BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft); /*! * \brief Own position, be aware height is terrain height diff --git a/src/blackcore/context_network_textmessages.cpp b/src/blackcore/context_network_textmessages.cpp index 7b735565e..26d5967aa 100644 --- a/src/blackcore/context_network_textmessages.cpp +++ b/src/blackcore/context_network_textmessages.cpp @@ -20,7 +20,7 @@ namespace BlackCore void CContextNetwork::psFsdTextMessageReceived(const CTextMessageList &messages) { if (messages.isEmpty()) return; - this->log(Q_FUNC_INFO, messages.toQString()); + // this->log(Q_FUNC_INFO, messages.toQString()); this->textMessagesReceived(messages); // relay } diff --git a/src/blackcore/context_settings.cpp b/src/blackcore/context_settings.cpp index 78624390f..fa2fe0f97 100644 --- a/src/blackcore/context_settings.cpp +++ b/src/blackcore/context_settings.cpp @@ -43,12 +43,12 @@ namespace BlackCore /* * Pass value */ - BlackMisc::CStatusMessages CContextSettings::value(const QString &path, const QString &command, const QVariant &value) + BlackMisc::CStatusMessageList CContextSettings::value(const QString &path, const QString &command, const QVariant &value) { Q_ASSERT(path.length() > 3); Q_ASSERT(path.indexOf('/') >= 0); QString nextLevelPath = CSettingUtilities::removeLeadingPath(path); - BlackMisc::CStatusMessages msgs = CSettingUtilities::wrongPathMessages(path); + BlackMisc::CStatusMessageList msgs = CSettingUtilities::wrongPathMessages(path); bool changed = false; if (path.startsWith(IContextSettings::PathNetworkSettings())) { diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 9e74ef933..dd96158a2 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -9,7 +9,7 @@ #include "blackcore/dbus_server.h" #include "blackcore/context_settings_interface.h" #include "blackmisc/statusmessage.h" -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" #include #define BLACKCORE_CONTEXTSETTINGS_INTERFACENAME "blackcore.contextsettings" @@ -72,7 +72,7 @@ namespace BlackCore * \param value * \return */ - virtual BlackMisc::CStatusMessages value(const QString &path, const QString &command, const QVariant &value); + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value); private: BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; diff --git a/src/blackcore/context_settings_interface.cpp b/src/blackcore/context_settings_interface.cpp index 48f1d148b..e097efc46 100644 --- a/src/blackcore/context_settings_interface.cpp +++ b/src/blackcore/context_settings_interface.cpp @@ -24,7 +24,7 @@ namespace BlackCore } /* - * Workaround for unreliable signals + * Workaround for signals */ void IContextSettings::relaySignals(const QString &serviceName, QDBusConnection &connection) { @@ -43,16 +43,16 @@ namespace BlackCore /* * Relay to DBus */ - BlackMisc::CStatusMessages IContextSettings::value(const QString &path, const QString &command, const QVariant &value) + BlackMisc::CStatusMessageList IContextSettings::value(const QString &path, const QString &command, const QVariant &value) { int type = value.userType() - BlackMisc::firstBlackMetaType(); - return this->m_dBusInterface->callDBusRet(QLatin1Literal("value"), path, command, QDBusVariant(value), type); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("value"), path, command, QDBusVariant(value), type); } /* * DBus version of value */ - BlackMisc::CStatusMessages IContextSettings::value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType) + BlackMisc::CStatusMessageList IContextSettings::value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType) { QVariant qv = value.variant(); if (qv.canConvert()) diff --git a/src/blackcore/context_settings_interface.h b/src/blackcore/context_settings_interface.h index 30bab6af9..67269e153 100644 --- a/src/blackcore/context_settings_interface.h +++ b/src/blackcore/context_settings_interface.h @@ -6,7 +6,7 @@ #ifndef BLACKCORE_CONTEXTSETTINGS_INTERFACE_H #define BLACKCORE_CONTEXTSETTINGS_INTERFACE_H -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" #include "blackmisc/genericdbusinterface.h" #include "blackmisc/settingutilities.h" #include "blackmisc/setnetwork.h" @@ -24,7 +24,7 @@ namespace BlackCore { /*! - * \brief The IContextSettings class + * \brief The interface context settings */ class IContextSettings : public QObject { @@ -80,7 +80,7 @@ namespace BlackCore BlackMisc::CGenericDBusInterface *m_dBusInterface; /*! - * \brief Relay connection signals to local signals + * Relay connection signals to local signals * No idea why this has to be wired and is not done automatically * \param connection */ @@ -115,7 +115,7 @@ namespace BlackCore * \param value * \return */ - virtual BlackMisc::CStatusMessages value(const QString &path, const QString &command, const QVariant &value); + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value); /*! * Basically an unwanted signature as this is different from the "local" signature and @@ -129,7 +129,7 @@ namespace BlackCore * \param unifiedBlackMetaType * \return */ - virtual BlackMisc::CStatusMessages value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType); + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType); }; } diff --git a/src/blackcore/dbus_dummy.cpp b/src/blackcore/dbus_dummy.cpp deleted file mode 100644 index 754b8787e..000000000 --- a/src/blackcore/dbus_dummy.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// These two header files are not really needed here. But if they are not -// included "somewhere", they are not generated -> compiler error! -// Possible solution: Generate them once and put them in git. -#include "contextnetwork_adaptor.h" -#include "contextsettings_adaptor.h" diff --git a/src/blackcore/dbus_server.cpp b/src/blackcore/dbus_server.cpp index 5e1071419..2152513e1 100644 --- a/src/blackcore/dbus_server.cpp +++ b/src/blackcore/dbus_server.cpp @@ -8,6 +8,13 @@ #include "dbus_server.h" +// TODO: move from dbus_dummy.cpp +// These two header files are not really needed here. But if they are not +// included "somewhere", they are not generated -> compiler error! +// Possible solution: Generate them once and put them in git. +#include "contextnetwork_adaptor.h" +#include "contextsettings_adaptor.h" + namespace BlackCore { diff --git a/src/blackcore/network.h b/src/blackcore/network.h index 7a9d7a86d..5356622a4 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -15,8 +15,9 @@ #include "blackmisc/coordinategeodetic.h" #include "blackmisc/pqlength.h" #include "blackmisc/pqtime.h" +#include "blackmisc/nwserverlist.h" #include "blackmisc/nwtextmessagelist.h" -#include "blackmisc/nwserver.h" +#include "blackmisc/statusmessagelist.h" #include #include #include @@ -129,7 +130,7 @@ namespace BlackCore /*! * Dummy implementation of INetwork used for testing. */ - class NetworkDummy : public INetwork + class CNetworkDummy : public INetwork { public: //INetwork slots overrides virtual void setServer(const BlackMisc::Network::CServer &) {} diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index b5d8c19b9..7723f601a 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -8,8 +8,8 @@ #include #include -static_assert(! std::is_abstract::value, "Must implement all pure virtuals"); -static_assert(! std::is_abstract::value, "Must implement all pure virtuals"); +static_assert(! std::is_abstract::value, "Must implement all pure virtuals"); +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" @@ -29,7 +29,7 @@ namespace BlackCore void exceptionDispatcher(const char* caller); - NetworkVatlib::NetworkVatlib(QObject *parent) + CNetworkVatlib::CNetworkVatlib(QObject *parent) : INetwork(parent), m_net(Cvatlib_Network::Create()), m_status(Cvatlib_Network::connStatus_Idle), @@ -39,7 +39,7 @@ namespace BlackCore { connect(this, SIGNAL(terminate()), this, SLOT(terminateConnection()), Qt::QueuedConnection); - Q_ASSERT_X(m_fsdTextCodec, "NetworkVatlib", "Missing default wire text encoding"); + Q_ASSERT_X(m_fsdTextCodec, "CNetworkVatlib", "Missing default wire text encoding"); //TODO reinit m_fsdTextCodec from WireTextEncoding config setting if present QString capabilities; @@ -82,7 +82,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - NetworkVatlib::~NetworkVatlib() + CNetworkVatlib::~CNetworkVatlib() { try { @@ -99,7 +99,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::process() + void CNetworkVatlib::process() { try { @@ -111,7 +111,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::update() + void CNetworkVatlib::update() { try { @@ -140,17 +140,17 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - QByteArray NetworkVatlib::toFSD(QString qstr) const + QByteArray CNetworkVatlib::toFSD(QString qstr) const { return m_fsdTextCodec->fromUnicode(qstr); } - QByteArray NetworkVatlib::toFSD(const BlackMisc::Aviation::CCallsign &callsign) const + QByteArray CNetworkVatlib::toFSD(const BlackMisc::Aviation::CCallsign &callsign) const { return toFSD(callsign.getStringAsSet()); } - QString NetworkVatlib::fromFSD(const char *cstr) const + QString CNetworkVatlib::fromFSD(const char *cstr) const { return m_fsdTextCodec->toUnicode(cstr); } @@ -184,29 +184,29 @@ namespace BlackCore /********************************** INetwork slots ************************************/ /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ - void NetworkVatlib::setServer(const CServer &server) + void CNetworkVatlib::setServer(const CServer &server) { - Q_ASSERT_X(isDisconnected(), "NetworkVatlib", "Can't change server details while still connected"); + Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change server details while still connected"); this->m_server = server; } - void NetworkVatlib::setCallsign(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::setCallsign(const BlackMisc::Aviation::CCallsign &callsign) { - Q_ASSERT_X(isDisconnected(), "NetworkVatlib", "Can't change callsign while still connected"); + Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change callsign while still connected"); m_callsign = toFSD(callsign); } - void NetworkVatlib::setRealName(const QString &name) + void CNetworkVatlib::setRealName(const QString &name) { - Q_ASSERT_X(isDisconnected(), "NetworkVatlib", "Can't change name while still connected"); + Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change name while still connected"); m_realname = toFSD(name); } - void NetworkVatlib::initiateConnection() + void CNetworkVatlib::initiateConnection() { - Q_ASSERT_X(isDisconnected(), "NetworkVatlib", "Can't connect while still connected"); + Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't connect while still connected"); try { @@ -227,7 +227,7 @@ namespace BlackCore } } - void NetworkVatlib::terminateConnection() + void CNetworkVatlib::terminateConnection() { try { @@ -236,7 +236,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::setOwnAircraftPosition(const BlackMisc::Aviation::CAircraftSituation &aircraft) + void CNetworkVatlib::setOwnAircraftPosition(const BlackMisc::Aviation::CAircraftSituation &aircraft) { m_ownAircraft = aircraft; @@ -246,22 +246,22 @@ namespace BlackCore } } - void NetworkVatlib::setOwnAircraftTransponder(const BlackMisc::Aviation::CTransponder &xpdr) + void CNetworkVatlib::setOwnAircraftTransponder(const BlackMisc::Aviation::CTransponder &xpdr) { m_ownTransponder = xpdr; } - void NetworkVatlib::setOwnAircraftFrequency(const BlackMisc::PhysicalQuantities::CFrequency &freq) + void CNetworkVatlib::setOwnAircraftFrequency(const BlackMisc::PhysicalQuantities::CFrequency &freq) { m_ownFrequency = freq; } - void NetworkVatlib::setOwnAircraftIcao(const BlackMisc::Aviation::CAircraftIcao &icao) + void CNetworkVatlib::setOwnAircraftIcao(const BlackMisc::Aviation::CAircraftIcao &icao) { m_ownAircraftIcao = icao; } - void NetworkVatlib::sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) + void CNetworkVatlib::sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) { if (messages.isEmpty()) return; try @@ -287,7 +287,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendIpQuery() + void CNetworkVatlib::sendIpQuery() { try { @@ -296,7 +296,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -305,7 +305,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -314,7 +314,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendAtcQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendAtcQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -323,7 +323,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendAtisQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendAtisQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -332,7 +332,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendNameQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendNameQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -341,7 +341,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendCapabilitiesQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendCapabilitiesQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -350,7 +350,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -359,7 +359,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -368,7 +368,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::requestAircraftInfo(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::requestAircraftInfo(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -377,7 +377,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::sendAircraftInfo(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::sendAircraftInfo(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -406,7 +406,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::ping(const BlackMisc::Aviation::CCallsign &callsign) + void CNetworkVatlib::ping(const BlackMisc::Aviation::CCallsign &callsign) { try { @@ -415,7 +415,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::requestMetar(const QString &airportICAO) + void CNetworkVatlib::requestMetar(const QString &airportICAO) { try { @@ -424,7 +424,7 @@ namespace BlackCore catch (...) { exceptionDispatcher(Q_FUNC_INFO); } } - void NetworkVatlib::requestWeatherData(const QString &airportICAO) + void CNetworkVatlib::requestWeatherData(const QString &airportICAO) { try { @@ -437,12 +437,12 @@ namespace BlackCore /********************************** shimlib callbacks ************************************/ /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ - NetworkVatlib *cbvar_cast(void *cbvar) + CNetworkVatlib *cbvar_cast(void *cbvar) { - return static_cast(cbvar); + return static_cast(cbvar); } - void NetworkVatlib::onConnectionStatusChanged(Cvatlib_Network *, Cvatlib_Network::connStatus, Cvatlib_Network::connStatus newStatus, void *cbvar) + void CNetworkVatlib::onConnectionStatusChanged(Cvatlib_Network *, Cvatlib_Network::connStatus, Cvatlib_Network::connStatus newStatus, void *cbvar) { cbvar_cast(cbvar)->m_status = newStatus; switch (newStatus) @@ -455,13 +455,13 @@ namespace BlackCore } } - void NetworkVatlib::onTextMessageReceived(Cvatlib_Network *, const char *from, const char *to, const char *msg, void *cbvar) + void CNetworkVatlib::onTextMessageReceived(Cvatlib_Network *, const char *from, const char *to, const char *msg, void *cbvar) { BlackMisc::Network::CTextMessageList messages(cbvar_cast(cbvar)->fromFSD(msg), CCallsign(cbvar_cast(cbvar)->fromFSD(from)), CCallsign(cbvar_cast(cbvar)->fromFSD(to))); emit cbvar_cast(cbvar)->textMessagesReceived(messages); } - void NetworkVatlib::onRadioMessageReceived(Cvatlib_Network *, const char *from, INT numFreq, INT *freqList, const char *msg, void *cbvar) + void CNetworkVatlib::onRadioMessageReceived(Cvatlib_Network *, const char *from, INT numFreq, INT *freqList, const char *msg, void *cbvar) { QList frequencies; for (int i = 0; i < numFreq; ++i) @@ -472,17 +472,17 @@ namespace BlackCore emit cbvar_cast(cbvar)->textMessagesReceived(messages); } - void NetworkVatlib::onPilotDisconnected(Cvatlib_Network *, const char *callsign, void *cbvar) + void CNetworkVatlib::onPilotDisconnected(Cvatlib_Network *, const char *callsign, void *cbvar) { emit cbvar_cast(cbvar)->pilotDisconnected(cbvar_cast(cbvar)->fromFSD(callsign)); } - void NetworkVatlib::onControllerDisconnected(Cvatlib_Network *, const char *callsign, void *cbvar) + void CNetworkVatlib::onControllerDisconnected(Cvatlib_Network *, const char *callsign, void *cbvar) { emit cbvar_cast(cbvar)->atcDisconnected(cbvar_cast(cbvar)->fromFSD(callsign)); } - void NetworkVatlib::onPilotPositionUpdate(Cvatlib_Network *, const char *callsignChar , Cvatlib_Network::PilotPosUpdate pos, void *cbvar) + void CNetworkVatlib::onPilotPositionUpdate(Cvatlib_Network *, const char *callsignChar , Cvatlib_Network::PilotPosUpdate pos, void *cbvar) { const CCallsign callsign(callsignChar); const CAircraftSituation situation( @@ -516,12 +516,12 @@ namespace BlackCore emit cbvar_cast(cbvar)->aircraftPositionUpdate(callsign, situation, transponder); } - void NetworkVatlib::onInterimPilotPositionUpdate(Cvatlib_Network *, const char * /** callsign **/, Cvatlib_Network::PilotPosUpdate /** pos **/, void * /** cbvar **/) + void CNetworkVatlib::onInterimPilotPositionUpdate(Cvatlib_Network *, const char * /** callsign **/, Cvatlib_Network::PilotPosUpdate /** pos **/, void * /** cbvar **/) { //TODO } - void NetworkVatlib::onAtcPositionUpdate(Cvatlib_Network *, const char *callsign, Cvatlib_Network::ATCPosUpdate pos, void *cbvar) + void CNetworkVatlib::onAtcPositionUpdate(Cvatlib_Network *, const char *callsign, Cvatlib_Network::ATCPosUpdate pos, void *cbvar) { CFrequency freq(pos.frequency, CFrequencyUnit::kHz()); freq.switchUnit(CFrequencyUnit::MHz()); // we would not need to bother, but this makes it easier to identify @@ -529,22 +529,22 @@ namespace BlackCore CCoordinateGeodetic(pos.lat, pos.lon, 0), CLength(pos.visibleRange, CLengthUnit::NM())); } - void NetworkVatlib::onKicked(Cvatlib_Network *, const char *reason, void *cbvar) + void CNetworkVatlib::onKicked(Cvatlib_Network *, const char *reason, void *cbvar) { emit cbvar_cast(cbvar)->kicked(cbvar_cast(cbvar)->fromFSD(reason)); } - void NetworkVatlib::onPong(Cvatlib_Network *, const char *callsign, INT elapsedTime, void *cbvar) + void CNetworkVatlib::onPong(Cvatlib_Network *, const char *callsign, INT elapsedTime, void *cbvar) { emit cbvar_cast(cbvar)->pong(cbvar_cast(cbvar)->fromFSD(callsign), CTime(elapsedTime, CTimeUnit::s())); } - void NetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar) + void CNetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar) { emit cbvar_cast(cbvar)->metarReceived(cbvar_cast(cbvar)->fromFSD(data)); } - void NetworkVatlib::onInfoQueryRequestReceived(Cvatlib_Network *, const char *callsignString, Cvatlib_Network::infoQuery type, const char *, void *cbvar) + void CNetworkVatlib::onInfoQueryRequestReceived(Cvatlib_Network *, const char *callsignString, Cvatlib_Network::infoQuery type, const char *, void *cbvar) { auto timer = new QTimer(cbvar_cast(cbvar)); timer->setSingleShot(true); @@ -562,7 +562,7 @@ namespace BlackCore } } - void NetworkVatlib::onInfoQueryReplyReceived(Cvatlib_Network *, const char *callsign, Cvatlib_Network::infoQuery type, const char *data, const char *data2, void *cbvar) + void CNetworkVatlib::onInfoQueryReplyReceived(Cvatlib_Network *, const char *callsign, Cvatlib_Network::infoQuery type, const char *data, const char *data2, void *cbvar) { switch (type) { @@ -574,7 +574,7 @@ namespace BlackCore } } - void NetworkVatlib::onCapabilitiesReplyReceived(Cvatlib_Network *net, const char *callsign, const char **keysValues, void *cbvar) + void CNetworkVatlib::onCapabilitiesReplyReceived(Cvatlib_Network *net, const char *callsign, const char **keysValues, void *cbvar) { quint32 flags = 0; while (*keysValues) @@ -592,17 +592,17 @@ namespace BlackCore emit cbvar_cast(cbvar)->capabilitiesQueryReplyReceived(cbvar_cast(cbvar)->fromFSD(callsign), flags); } - void NetworkVatlib::onAtisReplyReceived(Cvatlib_Network *, const char *callsign, Cvatlib_Network::atisLineType, const char *data, void *cbvar) + void CNetworkVatlib::onAtisReplyReceived(Cvatlib_Network *, const char *callsign, Cvatlib_Network::atisLineType lineType, const char *data, void *cbvar) { emit cbvar_cast(cbvar)->atisQueryReplyReceived(cbvar_cast(cbvar)->fromFSD(callsign), cbvar_cast(cbvar)->fromFSD(data)); } - void NetworkVatlib::onTemperatureDataReceived(Cvatlib_Network *, Cvatlib_Network::TempLayer /** layers **/ [4], INT /** pressure **/, void * /** cbvar **/) + void CNetworkVatlib::onTemperatureDataReceived(Cvatlib_Network *, Cvatlib_Network::TempLayer /** layers **/ [4], INT /** pressure **/, void * /** cbvar **/) { //TODO } - void NetworkVatlib::onErrorReceived(Cvatlib_Network *, Cvatlib_Network::error type, const char *msg, const char *data, void *cbvar) + void CNetworkVatlib::onErrorReceived(Cvatlib_Network *, Cvatlib_Network::error type, const char *msg, const char *data, void *cbvar) { switch (type) { @@ -635,17 +635,17 @@ namespace BlackCore emit cbvar_cast(cbvar)->terminate(); } - void NetworkVatlib::onWindDataReceived(Cvatlib_Network *, Cvatlib_Network::WindLayer /** layers **/[4], void * /** cbvar **/) + void CNetworkVatlib::onWindDataReceived(Cvatlib_Network *, Cvatlib_Network::WindLayer /** layers **/[4], void * /** cbvar **/) { //TODO } - void NetworkVatlib::onCloudDataReceived(Cvatlib_Network *, Cvatlib_Network::CloudLayer /** layers **/ [2], Cvatlib_Network::StormLayer /** storm **/, float /** vis **/, void * /** cbvar **/) + void CNetworkVatlib::onCloudDataReceived(Cvatlib_Network *, Cvatlib_Network::CloudLayer /** layers **/ [2], Cvatlib_Network::StormLayer /** storm **/, float /** vis **/, void * /** cbvar **/) { //TODO } - void NetworkVatlib::onPilotInfoRequestReceived(Cvatlib_Network *, const char *callsignString, void *cbvar) + void CNetworkVatlib::onPilotInfoRequestReceived(Cvatlib_Network *, const char *callsignString, void *cbvar) { auto timer = new QTimer(cbvar_cast(cbvar)); timer->setSingleShot(true); @@ -655,7 +655,7 @@ namespace BlackCore connect(timer, &QTimer::timeout, [ = ]() { cbvar_cast(cbvar)->sendAircraftInfo(callsign); }); } - void NetworkVatlib::onPilotInfoReceived(Cvatlib_Network *net, const char *callsign, const char **keysValues, void *cbvar) + void CNetworkVatlib::onPilotInfoReceived(Cvatlib_Network *net, const char *callsign, const char **keysValues, void *cbvar) { BlackMisc::Aviation::CAircraftIcao icao; while (*keysValues) diff --git a/src/blackcore/network_vatlib.h b/src/blackcore/network_vatlib.h index 5e7101d72..6f60f00e1 100644 --- a/src/blackcore/network_vatlib.h +++ b/src/blackcore/network_vatlib.h @@ -21,13 +21,13 @@ namespace BlackCore { - class NetworkVatlib : public INetwork + class CNetworkVatlib : public INetwork { Q_OBJECT public: - NetworkVatlib(QObject *parent = nullptr); - virtual ~NetworkVatlib(); + CNetworkVatlib(QObject *parent = nullptr); + virtual ~CNetworkVatlib(); public: // INetwork slots overrides diff --git a/src/blackcore/readme.txt b/src/blackcore/readme.txt index 5b9adacb9..506dd3829 100644 --- a/src/blackcore/readme.txt +++ b/src/blackcore/readme.txt @@ -7,6 +7,8 @@ Starting: dbus-daemon.exe --session /// qdbuscpp2xml context_network.h -x blackmisc_cpp2xml.dll -o blackcore.contextnetwork.xml qdbuscpp2xml context_network_interface.h -x blackmisc_cpp2xml.dll -o blackcore.contextnetwork.xml qdbuscpp2xml context_settings_interface.h -x blackmisc_cpp2xml.dll -o blackcore.contextsettings.xml +qdbuscpp2xml context_application_interface.h -x blackmisc_cpp2xml.dll -o blackcore.contextapplication.xml +qdbuscpp2xml context_voice_interface.h -x blackmisc_cpp2xml.dll -o blackcore.contextvoice.xml Set search path for plugins: env.var. QT_PLUGIN_PATH @@ -15,13 +17,10 @@ Interface: qdbusxml2cpp -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h -p contextnetwork_interface.h: H:\Projects\Qt\VatsimClient\client\src\blackcore\blackcore.contextnetwork.xml qdbusxml2cpp -i contextnetwork_interface.h -p :contextnetwork_interface.cpp H:\Projects\Qt\VatsimClient\client\src\blackcore\blackcore.contextnetwork.xml -The : indicates generation of cpp file - -Adaptor: +Adaptor: The : indicates generation of cpp file qdbusxml2cpp -i blackmisc/blackmiscfreefunctions.h -i blackmisc/blackmiscallvalueclasses.h -a contextnetwork_adaptor.h blackcore.contextnetwork.xml qdbusxml2cpp -i context_adaptor.h -a :contextnetwork_adaptor.cpp blackcore.contextnetwork.xml - Manually: diff --git a/src/blackgui/aircraftlistmodel.cpp b/src/blackgui/aircraftlistmodel.cpp index ff9a1bcdf..95ddb3dfb 100644 --- a/src/blackgui/aircraftlistmodel.cpp +++ b/src/blackgui/aircraftlistmodel.cpp @@ -17,7 +17,7 @@ namespace BlackGui CAircraftListModel::CAircraftListModel(QObject *parent) : CListModelBase("ViewAircraftList", parent) { this->m_columns.addColumn(CAircraft::IndexCallsign, "callsign"); - this->m_columns.addColumn(CAircraft::IndexPilotRealname, "pilotrealname"); + this->m_columns.addColumn(CAircraft::IndexPilotRealName, "pilotrealname"); this->m_columns.addColumn(CAircraft::IndexDistance, "distance", Qt::AlignRight | Qt::AlignVCenter); this->m_columns.addColumn(CAircraft::IndexFrequencyCom1, "frequency", Qt::AlignRight | Qt::AlignVCenter); this->m_columns.addColumn(CAircraftIcao::IndexAsString, "model"); diff --git a/src/blackgui/atcstationlistmodel.cpp b/src/blackgui/atcstationlistmodel.cpp index 9d24cc793..894e13802 100644 --- a/src/blackgui/atcstationlistmodel.cpp +++ b/src/blackgui/atcstationlistmodel.cpp @@ -18,7 +18,7 @@ namespace BlackGui this->m_columns.addColumn(CAtcStation::IndexCallsignAsStringAsSet, "callsign"); this->m_columns.addColumn(CAtcStation::IndexDistance, "distance", Qt::AlignRight | Qt::AlignVCenter); this->m_columns.addColumn(CAtcStation::IndexFrequency, "frequency", Qt::AlignRight | Qt::AlignVCenter); - this->m_columns.addColumn(CAtcStation::IndexControllerRealname, "controllername"); + this->m_columns.addColumn(CAtcStation::IndexControllerRealName, "controllername"); this->m_columns.addColumn(CAtcStation::IndexIsOnline, "online"); this->m_columns.addColumn(CAtcStation::IndexBookedFrom, "bookedfrom"); this->m_columns.addColumn(CAtcStation::IndexBookedUntil, "bookeduntil"); diff --git a/src/blackgui/serverlistmodel.cpp b/src/blackgui/serverlistmodel.cpp index fe06b4b0e..e53fbaac4 100644 --- a/src/blackgui/serverlistmodel.cpp +++ b/src/blackgui/serverlistmodel.cpp @@ -22,7 +22,7 @@ namespace BlackGui this->m_columns.addColumn(CServer::IndexDescription, "description"); this->m_columns.addColumn(CServer::IndexAddress, "address"); this->m_columns.addColumn(CServer::IndexPort, "port"); - this->m_columns.addColumn(CServer::IndexUserRealname, "username"); + this->m_columns.addColumn(CServer::IndexUserRealName, "realname"); this->m_columns.addColumn(CServer::IndexUserId, "userid"); // force strings for translation in resource files @@ -30,7 +30,7 @@ namespace BlackGui (void)QT_TRANSLATE_NOOP("ViewServerList", "description"); (void)QT_TRANSLATE_NOOP("ViewServerList", "address"); (void)QT_TRANSLATE_NOOP("ViewServerList", "port"); - (void)QT_TRANSLATE_NOOP("ViewServerList", "username"); + (void)QT_TRANSLATE_NOOP("ViewServerList", "realname"); (void)QT_TRANSLATE_NOOP("ViewServerList", "userid"); } diff --git a/src/blackmisc/avaircraft.cpp b/src/blackmisc/avaircraft.cpp index 0069ab688..c22ba7609 100644 --- a/src/blackmisc/avaircraft.cpp +++ b/src/blackmisc/avaircraft.cpp @@ -156,8 +156,8 @@ namespace BlackMisc return QVariant(this->m_callsign.getStringAsSet()); case IndexPilotId: return QVariant::fromValue(this->m_pilot.getId()); - case IndexPilotRealname: - return QVariant::fromValue(this->m_pilot.getRealname()); + case IndexPilotRealName: + return QVariant::fromValue(this->m_pilot.getRealName()); case IndexDistance: return this->m_distanceToPlane.toQVariant(); case IndexCom1System: @@ -194,9 +194,9 @@ namespace BlackMisc { case IndexFrequencyCom1: if (!CComSystem::isValidCivilAviationFrequency(qv.value())) - { return ""; - } + else + return qv.value().valueRoundedWithUnit(3, i18n); break; case IndexDistance: { @@ -229,8 +229,11 @@ namespace BlackMisc case IndexCallsignAsString: this->m_callsign = CCallsign(variant.value()); break; - case IndexPilotRealname: - this->m_pilot.setRealname(variant.value()); + case IndexPilotRealName: + this->m_pilot.setRealName(variant.value()); + break; + case IndexDistance: + this->m_distanceToPlane = variant.value(); break; case IndexCom1System: this->setCom1System(variant.value()); diff --git a/src/blackmisc/avaircraft.h b/src/blackmisc/avaircraft.h index 00ee1652f..ec0de50e9 100644 --- a/src/blackmisc/avaircraft.h +++ b/src/blackmisc/avaircraft.h @@ -297,7 +297,7 @@ namespace BlackMisc IndexCallsignAsString, IndexCallsignAsStringAsSet, IndexPilotId, - IndexPilotRealname, + IndexPilotRealName, IndexDistance, IndexCom1System, IndexFrequencyCom1, diff --git a/src/blackmisc/avaircrafticao.h b/src/blackmisc/avaircrafticao.h index 4ae39dc22..7011fcc57 100644 --- a/src/blackmisc/avaircrafticao.h +++ b/src/blackmisc/avaircrafticao.h @@ -36,7 +36,8 @@ namespace BlackMisc * \param color */ CAircraftIcao(const QString &icao, const QString &type, const QString &airline, const QString &livery, const QString &color) - : m_designator(icao), m_type(type), m_airline(airline), m_livery(livery), m_color(color) {} + : m_designator(icao.trimmed().toUpper()), m_type(type.trimmed().toUpper()), m_airline(airline.trimmed().toUpper()), + m_livery(livery.trimmed().toUpper()), m_color(color.trimmed().toUpper()) {} /*! * \brief QVariant, required for DBus QVariant lists @@ -87,7 +88,7 @@ namespace BlackMisc * \brief Set airline * \param livery */ - void setLivery(const QString &livery) { this->m_livery = livery; } + void setLivery(const QString &livery) { this->m_livery = livery.trimmed().toUpper(); } /*! * \brief Livery? diff --git a/src/blackmisc/avaircraftlist.h b/src/blackmisc/avaircraftlist.h index b60467dbd..7b0b1f8af 100644 --- a/src/blackmisc/avaircraftlist.h +++ b/src/blackmisc/avaircraftlist.h @@ -22,13 +22,13 @@ namespace BlackMisc namespace Aviation { /*! - * Value object encapsulating a list of aircraft stations. + * Value object encapsulating a list of aircrafts. */ class CAircraftList : public CSequence { public: /*! - * \brief Empty constructor. + * \brief Default constructor. */ CAircraftList(); diff --git a/src/blackmisc/avaircraftsituation.h b/src/blackmisc/avaircraftsituation.h index a814b50c0..b27603fe1 100644 --- a/src/blackmisc/avaircraftsituation.h +++ b/src/blackmisc/avaircraftsituation.h @@ -15,7 +15,6 @@ #include "avheading.h" #include "pqspeed.h" #include "valueobject.h" -#include namespace BlackMisc { @@ -50,7 +49,6 @@ namespace BlackMisc : m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch), m_bank(bank), m_groundspeed(gs), m_timestamp(QDateTime::currentDateTimeUtc()) {} - /*! * \brief Properties by index */ diff --git a/src/blackmisc/avatcstation.cpp b/src/blackmisc/avatcstation.cpp index 2df39d957..863371f4e 100644 --- a/src/blackmisc/avatcstation.cpp +++ b/src/blackmisc/avatcstation.cpp @@ -317,8 +317,8 @@ namespace BlackMisc return QVariant(this->m_callsign.getStringAsSet()); case IndexController: return this->m_controller.toQVariant(); - case IndexControllerRealname: - return QVariant(this->getControllerRealname()); + case IndexControllerRealName: + return QVariant(this->getControllerRealName()); case IndexControllerId: return QVariant(this->getControllerId()); case IndexFrequency: @@ -374,8 +374,8 @@ namespace BlackMisc case IndexController: this->setController(variant.value()); break; - case IndexControllerRealname: - this->setControllerRealname(variant.value()); + case IndexControllerRealName: + this->setControllerRealName(variant.value()); break; case IndexControllerId: this->setControllerId(variant.value()); @@ -437,9 +437,9 @@ namespace BlackMisc { case IndexFrequency: if (!CComSystem::isValidCivilAviationFrequency(qv.value())) - { return ""; - } + else + return qv.value().valueRoundedWithUnit(3, i18n); break; case IndexDistance: { diff --git a/src/blackmisc/avatcstation.h b/src/blackmisc/avatcstation.h index 6d14abe8e..9ff74a1f1 100644 --- a/src/blackmisc/avatcstation.h +++ b/src/blackmisc/avatcstation.h @@ -41,7 +41,7 @@ namespace BlackMisc IndexCallsignAsString, IndexCallsignAsStringAsSet, IndexController, - IndexControllerRealname, + IndexControllerRealName, IndexControllerId, IndexFrequency, IndexPosition, @@ -165,7 +165,7 @@ namespace BlackMisc * Get controller name. * \return */ - QString getControllerRealname() const { return m_controller.getRealname(); } + QString getControllerRealName() const { return m_controller.getRealName(); } /*! * Get controller name. @@ -183,7 +183,7 @@ namespace BlackMisc * Set controller's name * \param controllerName */ - void setControllerRealname(const QString &controllerName) { this->m_controller.setRealname(controllerName); } + void setControllerRealName(const QString &controllerName) { this->m_controller.setRealName(controllerName); } /*! * Set controller's id @@ -195,7 +195,7 @@ namespace BlackMisc * \brief Has valid realname? * \return */ - bool hasValidRealname() const { return this->m_controller.hasValidRealname(); } + bool hasValidRealName() const { return this->m_controller.hasValidRealName(); } /*! * \brief Has valid id? @@ -354,7 +354,7 @@ namespace BlackMisc * \brief Set ATIS Message * \param atis */ - void setAtisMessage(const QString &atis) { this->m_atis.addMessage(atis); } + void setAtisMessage(const QString &atis) { this->m_atis.setMessage(atis); } /*! * \brief Get METAR @@ -372,7 +372,7 @@ namespace BlackMisc * \brief Set METAR Message * \param msg */ - void setMetarMessage(const QString &metar) { this->m_metar.addMessage(metar); } + void setMetarMessage(const QString &metar) { this->m_metar.setMessage(metar); } /*! * Set booked until diff --git a/src/blackmisc/avatcstationlist.cpp b/src/blackmisc/avatcstationlist.cpp index eede624a2..377292e96 100644 --- a/src/blackmisc/avatcstationlist.cpp +++ b/src/blackmisc/avatcstationlist.cpp @@ -69,70 +69,75 @@ namespace BlackMisc /* * Merge with booking */ - int CAtcStationList::mergeWithBooking(CAtcStation &booking) + int CAtcStationList::mergeWithBooking(CAtcStation &bookedAtcStation) { int c = 0; - booking.setOnline(false); // reset + bookedAtcStation.setOnline(false); // reset for (auto i = this->begin(); i != this->end(); ++i) { - CAtcStation currentOnline = *i; - if (currentOnline.getCallsign() != booking.getCallsign()) continue; + CAtcStation onlineAtcStation = *i; + if (onlineAtcStation.getCallsign() != bookedAtcStation.getCallsign()) continue; // from online to booking - booking.setOnline(true); - booking.setFrequency(currentOnline.getFrequency()); + bookedAtcStation.setOnline(true); + bookedAtcStation.setFrequency(onlineAtcStation.getFrequency()); + + // Logoff Zulu Time set? + // comes directly from the online controller and is most likely more accurate + if (!onlineAtcStation.getBookedUntilUtc().isNull()) + bookedAtcStation.setBookedUntilUtc(onlineAtcStation.getBookedUntilUtc()); // from booking to online - if (!currentOnline.isBookedNow() && booking.hasValidBookingTimes()) + if (!onlineAtcStation.isBookedNow() && bookedAtcStation.hasValidBookingTimes()) { - if (currentOnline.hasValidBookingTimes()) + if (onlineAtcStation.hasValidBookingTimes()) { - if (booking.isBookedNow()) + if (bookedAtcStation.isBookedNow()) { // can't get any better - currentOnline.setBookedFromUntil(booking); + onlineAtcStation.setBookedFromUntil(bookedAtcStation); } else { // we already have some booking dates - CTime timeDiffBooking = booking.bookedWhen(); - CTime timeDiffOnline = currentOnline.bookedWhen(); + CTime timeDiffBooking = bookedAtcStation.bookedWhen(); + CTime timeDiffOnline = onlineAtcStation.bookedWhen(); if (timeDiffBooking.isNegativeWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered()) { // both in past if (timeDiffBooking > timeDiffOnline) - currentOnline.setBookedFromUntil(booking); + onlineAtcStation.setBookedFromUntil(bookedAtcStation); } else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isPositiveWithEpsilonConsidered()) { // both in future if (timeDiffBooking < timeDiffOnline) - currentOnline.setBookedFromUntil(booking); + onlineAtcStation.setBookedFromUntil(bookedAtcStation); } else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered()) { // future booking is better than past booking - currentOnline.setBookedFromUntil(booking); + onlineAtcStation.setBookedFromUntil(bookedAtcStation); } } } else { // no booking info so far - currentOnline.setBookedFromUntil(booking); + onlineAtcStation.setBookedFromUntil(bookedAtcStation); } } // both ways - currentOnline.syncronizeControllerData(booking); - if (currentOnline.hasValidDistance()) - booking.setDistanceToPlane(currentOnline.getDistanceToPlane()); - else if (booking.hasValidDistance()) - currentOnline.setDistanceToPlane(booking.getDistanceToPlane()); + onlineAtcStation.syncronizeControllerData(bookedAtcStation); + if (onlineAtcStation.hasValidDistance()) + bookedAtcStation.setDistanceToPlane(onlineAtcStation.getDistanceToPlane()); + else if (bookedAtcStation.hasValidDistance()) + onlineAtcStation.setDistanceToPlane(bookedAtcStation.getDistanceToPlane()); // update - *i = currentOnline; + *i = onlineAtcStation; c++; } diff --git a/src/blackmisc/avatcstationlist.h b/src/blackmisc/avatcstationlist.h index e26ba7316..8685d1fb6 100644 --- a/src/blackmisc/avatcstationlist.h +++ b/src/blackmisc/avatcstationlist.h @@ -75,10 +75,10 @@ namespace BlackMisc /*! * \brief Merge with ATC station representing booking information - * \param booking + * \param bookedAtcStation * \return */ - int mergeWithBooking(CAtcStation &booking); + int mergeWithBooking(CAtcStation &bookedAtcStation); }; } //namespace diff --git a/src/blackmisc/avcallsign.h b/src/blackmisc/avcallsign.h index 2639e7f44..87a08f46c 100644 --- a/src/blackmisc/avcallsign.h +++ b/src/blackmisc/avcallsign.h @@ -61,13 +61,13 @@ namespace BlackMisc * Get callsign. * \return */ - const QString &asString() const { return m_callsign; } + const QString &asString() const { return this->m_callsign; } /*! * Get callsign. * \return */ - const QString &getStringAsSet() const { return m_callsignAsSet; } + const QString &getStringAsSet() const { return this->m_callsignAsSet; } /*! * \brief Get ICAO code, if this possible diff --git a/src/blackmisc/avinformationmessage.cpp b/src/blackmisc/avinformationmessage.cpp index cc9df1e80..26efcdfa5 100644 --- a/src/blackmisc/avinformationmessage.cpp +++ b/src/blackmisc/avinformationmessage.cpp @@ -54,41 +54,6 @@ namespace BlackMisc return !((*this) == other); } - /* - * Set / append ATIS message - */ - void CInformationMessage::addMessage(const QString &message) - { - const QString np = message.trimmed(); - if (np.isEmpty()) return; - - // detect the stupid z1, z2, z3 placeholders - // TODO: Anything better as this stupid code here? - const QString test = np.toLower().remove(QRegExp("[\\n\\t\\r]")); - if (test == "z") return; - if (test.startsWith("z") && test.length() == 2) return; - if (test.length() == 1) return; - - // set message - bool outdated = this->isOutdated(); - if (outdated) this->m_message.clear(); - if (!this->m_message.isEmpty()) this->m_message.append("\n"); - this->m_message.append(np); - this->m_receivedTimestamp = QDateTime::currentDateTimeUtc(); - } - - /* - * Outdated? New ATIS, or just a part - */ - bool CInformationMessage::isOutdated() const - { - // everything received within this timespan is considered to be the - // same ATIS values - // FSD sends messages as parts - qint64 diff = this->m_receivedTimestamp.msecsTo(QDateTime::currentDateTimeUtc()); - return (diff > 1000 * 10); // n seconds - } - /* * Register metadata */ diff --git a/src/blackmisc/avinformationmessage.h b/src/blackmisc/avinformationmessage.h index 0105eb034..3986601f8 100644 --- a/src/blackmisc/avinformationmessage.h +++ b/src/blackmisc/avinformationmessage.h @@ -87,18 +87,15 @@ namespace BlackMisc */ bool hasMessage() const { return !m_message.isEmpty(); } - /*! - * \brief Add message - * \remarks ATIS message come in as parts, this here features some logic, to either append or reset the message - * \param message - */ - void addMessage(const QString &message); - /*! * \brief Set message * \param message */ - void setMessage(const QString &message) { m_message = message; } + void setMessage(const QString &message) + { + this->m_receivedTimestamp = QDateTime::currentDateTimeUtc(); + this->m_message = message; + } /*! * \brief Type as string @@ -167,12 +164,6 @@ namespace BlackMisc InformationType m_type; QString m_message; QDateTime m_receivedTimestamp; - - /*! - * \brief Outdated timestamp? - * \return - */ - bool isOutdated() const; }; } // namespace } // namespace diff --git a/src/blackmisc/aviocomsystem.cpp b/src/blackmisc/aviocomsystem.cpp new file mode 100644 index 000000000..253c566a9 --- /dev/null +++ b/src/blackmisc/aviocomsystem.cpp @@ -0,0 +1,66 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/aviocomsystem.h" + +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMisc +{ + namespace Aviation + { + /* + * Valid values? + */ + bool CComSystem::validValues() const + { + if (this->isDefaultValue()) return true; // special case + return + (CComSystem::isValidCivilAviationFrequency(this->getFrequencyActive()) || + CComSystem::isValidMilitaryFrequency(this->getFrequencyActive())) && + (CComSystem::isValidCivilAviationFrequency(this->getFrequencyStandby()) || + CComSystem::isValidMilitaryFrequency(this->getFrequencyStandby())); + } + + /* + * Validate + */ + bool CComSystem::validate(bool strict) const + { + if (this->isDefaultValue()) return true; + bool valid = this->validValues(); + if (!strict) return valid; + Q_ASSERT_X(valid, "CComSystem::validate", "illegal values"); + if (!valid) throw std::range_error("Illegal values in CComSystem::validate"); + return true; + } + + void CComSystem::setFrequencyActiveMHz(double frequencyMHz) + { + CFrequency f(frequencyMHz, CFrequencyUnit::MHz()); + CComSystem::roundTo25KHz(f); + this->CModulator::setFrequencyActive(f); + this->validate(true); + } + + void CComSystem::setFrequencyStandbyMHz(double frequencyMHz) + { + CFrequency f(frequencyMHz, CFrequencyUnit::MHz()); + CComSystem::roundTo25KHz(f); + this->CModulator::setFrequencyStandby(f); + this->validate(true); + } + + /* + * Round to 25KHz + */ + void CComSystem::roundTo25KHz(PhysicalQuantities::CFrequency &frequency) + { + double f = frequency.valueRounded(CFrequencyUnit::kHz(), 0); + quint32 d = static_cast(f / 25.0); + frequency.setCurrentUnitValue(d * (25.0 / 1000.0)); + } + } // namespace +} diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 1b91cd0cd..f3271fc76 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -39,15 +39,7 @@ namespace BlackMisc * \brief Are the set values valid / in range? * \return */ - bool validValues() const - { - if (this->isDefaultValue()) return true; // special case - return - (CComSystem::isValidCivilAviationFrequency(this->getFrequencyActive()) || - CComSystem::isValidMilitaryFrequency(this->getFrequencyActive())) && - (CComSystem::isValidCivilAviationFrequency(this->getFrequencyStandby()) || - CComSystem::isValidMilitaryFrequency(this->getFrequencyStandby())); - } + bool validValues() const; /*! * \brief Validate values by assert and exception @@ -56,15 +48,7 @@ namespace BlackMisc * \remarks Cannot be virtual because used in constructor * \return */ - bool validate(bool strict = true) const - { - if (this->isDefaultValue()) return true; - bool valid = this->validValues(); - if (!strict) return valid; - Q_ASSERT_X(valid, "CComSystem::validate", "illegal values"); - if (!valid) throw std::range_error("Illegal values in CComSystem::validate"); - return true; - } + bool validate(bool strict = true) const; public: /*! @@ -113,21 +97,13 @@ namespace BlackMisc * \brief Set active frequency * \param frequencyMHz */ - void setFrequencyActiveMHz(double frequencyMHz) - { - this->CModulator::setFrequencyActiveMHz(frequencyMHz); - this->validate(true); - } + void setFrequencyActiveMHz(double frequencyMHz); /*! * \brief Set standby frequency * \param frequencyMHz */ - void setFrequencyStandbyMHz(double frequencyMHz) - { - this->CModulator::setFrequencyStandbyMHz(frequencyMHz); - this->validate(true); - } + void setFrequencyStandbyMHz(double frequencyMHz); /*! * \brief Set UNICOM frequency as active @@ -344,7 +320,7 @@ namespace BlackMisc * \param f * \return */ - static bool isValidCivilAviationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) + static bool isValidCivilAviationFrequency(const BlackMisc::PhysicalQuantities::CFrequency &f) { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3); return fr >= 118.0 && fr <= 136.975; @@ -355,11 +331,19 @@ namespace BlackMisc * \param f * \return */ - static bool isValidMilitaryFrequency(BlackMisc::PhysicalQuantities::CFrequency f) + static bool isValidMilitaryFrequency(const BlackMisc::PhysicalQuantities::CFrequency &f) { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3); return fr >= 220.0 && fr <= 399.95; } + + /*! + * \brief Round to 25KHz + * \param f + * \return + */ + static void roundTo25KHz(BlackMisc::PhysicalQuantities::CFrequency &frequency); + }; } // namespace diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index a3851e4fa..8228fb7ca 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -16,7 +16,6 @@ namespace BlackMisc { namespace Aviation { - /* * Toggle standby <-> active */ @@ -67,7 +66,7 @@ namespace BlackMisc } /* - * From DBuss + * From DBus */ template void CModulator::unmarshallFromDbus(const QDBusArgument &argument) { diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 9679c4a30..5b609124e 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -20,9 +20,7 @@ TRANSLATIONS += translations/blackmisc_i18n_de.ts \ translations/blackmisc_i18n_fr.ts \ translations/blackmisc_i18n_en.ts -HEADERS += *.h \ - vaudiodevice.h \ - voiceallclasses.h +HEADERS += *.h SOURCES += *.cpp DESTDIR = ../../lib OTHER_FILES += $$TRANSLATIONS readme.txt diff --git a/src/blackmisc/blackmiscallvalueclasses.h b/src/blackmisc/blackmiscallvalueclasses.h index 73c88e8a8..13498b830 100644 --- a/src/blackmisc/blackmiscallvalueclasses.h +++ b/src/blackmisc/blackmiscallvalueclasses.h @@ -12,7 +12,7 @@ #include "blackmisc/settingsallclasses.h" #include "blackmisc/valuemap.h" #include "blackmisc/networkallclasses.h" -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" #include "blackmisc/statusmessage.h" #include "blackmisc/voiceallclasses.h" diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 4a1b08e8f..8a86718df 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -11,7 +11,7 @@ #include "networkallclasses.h" #include "settingsallclasses.h" #include "valuemap.h" -#include "statusmessages.h" +#include "statusmessagelist.h" #include "voiceallclasses.h" /* @@ -82,6 +82,7 @@ void BlackMisc::Geo::registerMetadata() void BlackMisc::Network::registerMetadata() { CUser::registerMetadata(); + CUserList::registerMetadata(); CServer::registerMetadata(); CServerList::registerMetadata(); CTextMessage::registerMetadata(); @@ -115,6 +116,9 @@ void BlackMisc::registerMetadata() // !! firstBlackMetaType CValueMap::registerMetadata(); + CStatusMessage::registerMetadata(); + CStatusMessageList::registerMetadata(); + // sub namespaces PhysicalQuantities::registerMetadata(); Aviation::registerMetadata(); diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index aa96aec17..6c9efab22 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -5,6 +5,7 @@ #ifndef BLACKMISC_COORDINATEGEODETIC_H #define BLACKMISC_COORDINATEGEODETIC_H + #include "blackmisc/mathvector3dbase.h" #include "blackmisc/geolatitude.h" #include "blackmisc/geolongitude.h" diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index d95afa2bb..76efe48ff 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -8,6 +8,7 @@ #include "blackmisc/valueobject.h" #include "blackmisc/mathematics.h" +using namespace BlackMisc::Math; namespace BlackMisc { @@ -167,9 +168,10 @@ namespace BlackMisc bool operator ==(const CVector3DBase &other) const { if (this == &other) return true; - return this->m_i == other.m_i && - this->m_j == other.m_j && - this->m_k == other.m_k; + return + CMath::epsilonEqual(this->m_i, other.m_i, 1E-9) && + CMath::epsilonEqual(this->m_j, other.m_j, 1E-9) && + CMath::epsilonEqual(this->m_k, other.m_k, 1E-9); } /*! diff --git a/src/blackmisc/networkallclasses.h b/src/blackmisc/networkallclasses.h index 6ddaf5166..db92ae735 100644 --- a/src/blackmisc/networkallclasses.h +++ b/src/blackmisc/networkallclasses.h @@ -7,6 +7,7 @@ #define BLACKMISC_NETWORKALLCLASSES_H #include "blackmisc/nwuser.h" +#include "blackmisc/nwuserlist.h" #include "blackmisc/nwserverlist.h" #include "blackmisc/nwtextmessagelist.h" diff --git a/src/blackmisc/nwserver.cpp b/src/blackmisc/nwserver.cpp index 19935e52c..d2b4aa32c 100644 --- a/src/blackmisc/nwserver.cpp +++ b/src/blackmisc/nwserver.cpp @@ -97,8 +97,8 @@ namespace BlackMisc return QVariant::fromValue(this->m_port); case IndexUserId: return QVariant::fromValue(this->m_user.getId()); - case IndexUserRealname: - return QVariant::fromValue(this->m_user.getRealname()); + case IndexUserRealName: + return QVariant::fromValue(this->m_user.getRealName()); default: break; } @@ -142,8 +142,8 @@ namespace BlackMisc case IndexUserPassword: this->m_user.setPassword(variant.value()); break; - case IndexUserRealname: - this->m_user.setRealname(variant.value()); + case IndexUserRealName: + this->m_user.setRealName(variant.value()); break; default: Q_ASSERT_X(false, "CServer", "index unknown"); diff --git a/src/blackmisc/nwserver.h b/src/blackmisc/nwserver.h index c8abb8c13..7e95b3a2d 100644 --- a/src/blackmisc/nwserver.h +++ b/src/blackmisc/nwserver.h @@ -147,7 +147,7 @@ namespace BlackMisc IndexAddress, IndexPort, IndexUserId, - IndexUserRealname, + IndexUserRealName, IndexUserPassword }; diff --git a/src/blackmisc/nwuser.cpp b/src/blackmisc/nwuser.cpp index fe5eb2fae..43c82221c 100644 --- a/src/blackmisc/nwuser.cpp +++ b/src/blackmisc/nwuser.cpp @@ -59,10 +59,10 @@ namespace BlackMisc { if (otherUser == (*this)) return; - if (this->hasValidRealname()) - otherUser.setRealname(this->getRealname()); - else if (otherUser.hasValidRealname()) - this->setRealname(otherUser.getRealname()); + if (this->hasValidRealName()) + otherUser.setRealName(this->getRealName()); + else if (otherUser.hasValidRealName()) + this->setRealName(otherUser.getRealName()); if (this->hasValidId()) otherUser.setId(this->getId()); @@ -104,5 +104,53 @@ namespace BlackMisc qDBusRegisterMetaType(); } + /* + * Property by index + */ + QVariant CUser::propertyByIndex(int index) const + { + switch (index) + { + case IndexEmail: + return QVariant(this->m_email); + case IndexId: + return QVariant(this->m_id); + case IndexPassword: + return QVariant(this->m_password); + case IndexRealName: + return QVariant(this->m_realname); + default: + break; + } + + Q_ASSERT_X(false, "CUser", "index unknown"); + QString m = QString("no property, index ").append(QString::number(index)); + return QVariant::fromValue(m); + } + + /* + * Set property as index + */ + void CUser::propertyByIndex(const QVariant &variant, int index) + { + switch (index) + { + case IndexEmail: + this->setEmail(variant.value()); + break; + case IndexId: + this->setId(variant.value()); + break; + case IndexPassword: + this->setPassword(variant.value()); + break; + case IndexRealName: + this->setRealName(variant.value()); + break; + default: + Q_ASSERT_X(false, "CUser", "index unknown (setter)"); + break; + } + } } // namespace } // namespace diff --git a/src/blackmisc/nwuser.h b/src/blackmisc/nwuser.h index 7c6fbc625..20c5de54b 100644 --- a/src/blackmisc/nwuser.h +++ b/src/blackmisc/nwuser.h @@ -21,6 +21,18 @@ namespace BlackMisc class CUser : public BlackMisc::CValueObject { public: + + /*! + * \brief Properties by index + */ + enum ColumnIndex + { + IndexEmail, + IndexId, + IndexPassword, + IndexRealName + }; + /*! * Default constructor. */ @@ -46,13 +58,13 @@ namespace BlackMisc * Get full name. * \return */ - QString getRealname() const { return m_realname; } + QString getRealName() const { return m_realname; } /*! - * \brief setRealname + * \brief setRealName * \param realname */ - void setRealname(const QString &realname) { m_realname = realname.trimmed(); } + void setRealName(const QString &realname) { m_realname = realname.trimmed(); } /*! * Get password @@ -82,7 +94,7 @@ namespace BlackMisc * \brief Valid real name? * \return */ - bool hasValidRealname() const { return !this->m_realname.isEmpty(); } + bool hasValidRealName() const { return !this->m_realname.isEmpty(); } /*! * \brief Valid id? @@ -151,6 +163,20 @@ namespace BlackMisc */ void syncronizeData(CUser &otherUser); + /*! + * \brief Property by index + * \param index + * \return + */ + QVariant propertyByIndex(int index) const; + + /*! + * \brief Property by index + * \param variant + * \param index + */ + void propertyByIndex(const QVariant &variant, int index); + protected: /*! * \brief Rounded value as string diff --git a/src/blackmisc/nwuserlist.cpp b/src/blackmisc/nwuserlist.cpp new file mode 100644 index 000000000..a565329b1 --- /dev/null +++ b/src/blackmisc/nwuserlist.cpp @@ -0,0 +1,34 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nwuserlist.h" +#include "predicates.h" + +namespace BlackMisc +{ + namespace Network + { + /* + * Default constructor + */ + CUserList::CUserList() { } + + /* + * Construct from base class object + */ + CUserList::CUserList(const CSequence &other) : CSequence(other) + { } + + /* + * Register metadata + */ + void CUserList::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/nwuserlist.h b/src/blackmisc/nwuserlist.h new file mode 100644 index 000000000..4afdec165 --- /dev/null +++ b/src/blackmisc/nwuserlist.h @@ -0,0 +1,64 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/*! + \file +*/ + +#ifndef BLACKMISC_USERLIST_H +#define BLACKMISC_USERLIST_H + +#include "nwuser.h" +#include "sequence.h" +#include "collection.h" +#include +#include +#include + +namespace BlackMisc +{ + namespace Network + { + /*! + * Value object encapsulating a list of voice rooms. + */ + class CUserList : public CSequence + { + public: + /*! + * \brief Default constructor. + */ + CUserList(); + + /*! + * \brief Construct from a base class object. + * \param other + */ + CUserList(const CSequence &other); + + /*! + * \brief QVariant, required for DBus QVariant lists + * \return + */ + virtual QVariant asQVariant() const + { + return QVariant::fromValue(*this); + } + + /*! + * \brief Register metadata + */ + static void registerMetadata(); + + }; + + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Network::CUserList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index ac705533a..3cc9d1038 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -6,13 +6,15 @@ #ifndef BLACKMISC_PQUNITS_H #define BLACKMISC_PQUNITS_H +#pragma push_macro("min") +#undef min + #include "blackmisc/pqbase.h" #include #include #include #include - // // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations @@ -949,14 +951,15 @@ namespace BlackMisc return h; } + /*! * \brief Minute * \return */ static const CTimeUnit &min() { - static CTimeUnit min(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", LinearConverter(), 2); - return min; + static CTimeUnit minute(QT_TRANSLATE_NOOP("CMeasurementUnit", "minute"), "min", LinearConverter(), 2); + return minute; } /*! @@ -1128,4 +1131,5 @@ Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CSpeedUnit) Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CTimeUnit) Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CAccelerationUnit) +#pragma pop_macro("min") #endif // guard diff --git a/src/blackmisc/setnetwork.cpp b/src/blackmisc/setnetwork.cpp index 8e9df6f1a..92a19a11b 100644 --- a/src/blackmisc/setnetwork.cpp +++ b/src/blackmisc/setnetwork.cpp @@ -1,6 +1,6 @@ #include "setnetwork.h" #include "blackmisc/blackmiscfreefunctions.h" -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" #include "blackmisc/settingutilities.h" using namespace BlackMisc::Network; @@ -91,11 +91,11 @@ namespace BlackMisc /* * Value */ - BlackMisc::CStatusMessages CSettingsNetwork::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag) + BlackMisc::CStatusMessageList CSettingsNetwork::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag) { // TODO: This needs to be refactored to a smarter way to delegate commands changedFlag = false; - CStatusMessages msgs; + CStatusMessageList msgs; if (path == CSettingsNetwork::PathTrafficServer()) { const CServer server = value.value(); @@ -118,7 +118,7 @@ namespace BlackMisc changedFlag = this->m_trafficNetworkServers.contains(&CServer::getName, server.getName()); this->m_trafficNetworkServers.removeIf(&CServer::getName, server.getName()); } - msgs.append(CStatusMessage::getInfoMessage("set current server")); + msgs.push_back(CStatusMessage::getInfoMessage("set current server")); return msgs; } return CSettingUtilities::wrongPathMessages(path); diff --git a/src/blackmisc/setnetwork.h b/src/blackmisc/setnetwork.h index 1bd0bc4a2..b7af81f2e 100644 --- a/src/blackmisc/setnetwork.h +++ b/src/blackmisc/setnetwork.h @@ -12,7 +12,7 @@ #include "nwserverlist.h" #include "valueobject.h" -#include "statusmessages.h" +#include "statusmessagelist.h" #include "settingutilities.h" @@ -112,7 +112,7 @@ namespace BlackMisc * \param changedFlag * \return */ - virtual BlackMisc::CStatusMessages value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag); + virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag); /*! * \brief Value hash diff --git a/src/blackmisc/settingutilities.cpp b/src/blackmisc/settingutilities.cpp index 79d850ff2..054dcdb34 100644 --- a/src/blackmisc/settingutilities.cpp +++ b/src/blackmisc/settingutilities.cpp @@ -22,10 +22,10 @@ namespace BlackMisc /* * Wrong path name messages */ - CStatusMessages CSettingUtilities::wrongPathMessages(const QString &path) + CStatusMessageList CSettingUtilities::wrongPathMessages(const QString &path) { - BlackMisc::CStatusMessages rps; - rps.append(CSettingUtilities::wrongPathMessage(path)); + BlackMisc::CStatusMessageList rps; + rps.push_back(CSettingUtilities::wrongPathMessage(path)); return rps; } diff --git a/src/blackmisc/settingutilities.h b/src/blackmisc/settingutilities.h index 791e382e5..6bdceb5e6 100644 --- a/src/blackmisc/settingutilities.h +++ b/src/blackmisc/settingutilities.h @@ -1,7 +1,7 @@ #ifndef BLACKMISC_SETTINGUTILITIES_H #define BLACKMISC_SETTINGUTILITIES_H -#include "blackmisc/statusmessages.h" +#include "blackmisc/statusmessagelist.h" namespace BlackMisc { @@ -66,7 +66,7 @@ namespace BlackMisc * \param path * \return */ - static BlackMisc::CStatusMessages wrongPathMessages(const QString &path = ""); + static BlackMisc::CStatusMessageList wrongPathMessages(const QString &path = ""); /*! * \brief Remove leading path diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index ab83fa580..9160dae63 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -71,6 +71,25 @@ namespace BlackMisc return BlackMisc::calculateHash(hashs, "CStatusMessage"); } + /* + * Equal + */ + bool CStatusMessage::operator ==(const CStatusMessage &other) const + { + return this->m_severity == other.m_severity && + this->m_type == other.m_type && + this->m_timestamp == other.m_timestamp && + this->m_message == other.m_message; + } + + /* + * Equal + */ + bool CStatusMessage::operator !=(const CStatusMessage &other) const + { + return !(other == (*this)); + } + /* * To DBus */ diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 82bda8508..d7fced67b 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -95,6 +95,20 @@ namespace BlackMisc return QVariant::fromValue(*this); } + /*! + * \brief Equal operator == + * \param other + * @return + */ + bool operator ==(const CStatusMessage &other) const; + + /*! + * \brief Unequal operator == + * \param other + * @return + */ + bool operator !=(const CStatusMessage &other) const; + /*! * \brief Register metadata */ @@ -114,7 +128,6 @@ namespace BlackMisc */ static CStatusMessage getInfoMessage(const QString &message); - protected: /*! * \brief Marshall to DBus diff --git a/src/blackmisc/statusmessagelist.cpp b/src/blackmisc/statusmessagelist.cpp new file mode 100644 index 000000000..ae5bafcff --- /dev/null +++ b/src/blackmisc/statusmessagelist.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "statusmessagelist.h" +#include "statusmessage.h" + +namespace BlackMisc +{ + /* + * Messages by type + */ + CStatusMessageList CStatusMessageList::findByType(CStatusMessage::StatusType type) const + { + CStatusMessageList sm; + foreach(CStatusMessage message, *this) + { + if (message.getType() == type) + { + sm.push_back(message); + } + } + return sm; + } + + /* + * Messages by severity + */ + CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const + { + CStatusMessageList sm; + foreach(CStatusMessage message, *this) + { + if (message.getSeverity() == severity) + { + sm.push_back(message); + } + } + return sm; + } + + /* + * Metadata + */ + void CStatusMessageList::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } +} diff --git a/src/blackmisc/statusmessagelist.h b/src/blackmisc/statusmessagelist.h new file mode 100644 index 000000000..80c2c31f9 --- /dev/null +++ b/src/blackmisc/statusmessagelist.h @@ -0,0 +1,64 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISC_STATUSMESSAGELIST_H +#define BLACKMISC_STATUSMESSAGELIST_H + +#include "valueobject.h" +#include "sequence.h" +#include "collection.h" +#include "statusmessage.h" + +namespace BlackMisc +{ + + /*! + * \brief Status messages, e.g. from Core -> GUI + */ + class CStatusMessageList : public CSequence + { + public: + /*! + * \brief StatusMessage + */ + CStatusMessageList() {} + + /*! + * \brief Find by type + * \param type + * \return + */ + CStatusMessageList findByType(CStatusMessage::StatusType type) const; + + /*! + * \brief Find by type + * \param type + * \return + */ + CStatusMessageList findBySeverity(CStatusMessage::StatusSeverity severity) const; + + /*! + * \brief As QVariant + * \return + */ + virtual QVariant asQVariant() const + { + return QVariant::fromValue(*this); + } + + /*! + * \brief Register metadata of unit and quantity + */ + static void registerMetadata(); + + }; + +} + +Q_DECLARE_METATYPE(BlackMisc::CStatusMessageList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif // guard diff --git a/src/blackmisc/statusmessages.cpp b/src/blackmisc/statusmessages.cpp deleted file mode 100644 index ab87c2735..000000000 --- a/src/blackmisc/statusmessages.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "statusmessages.h" -#include "statusmessage.h" - -namespace BlackMisc -{ - /* - * Messages by type - */ - CStatusMessages CStatusMessages::findByType(CStatusMessage::StatusType type) const - { - CStatusMessages sm; - foreach(CStatusMessage message, this->m_messages) - { - if (message.getType() == type) - { - sm.m_messages.append(message); - } - } - return sm; - } - - /* - * Messages by severity - */ - CStatusMessages CStatusMessages::findBySeverity(CStatusMessage::StatusSeverity severity) const - { - CStatusMessages sm; - foreach(CStatusMessage message, this->m_messages) - { - if (message.getSeverity() == severity) - { - sm.m_messages.append(message); - } - } - return sm; - } - - /* - * Size - */ - int CStatusMessages::size() const - { - return this->m_messages.size(); - } - - /* - * Append - */ - void CStatusMessages::append(const CStatusMessage &message) - { - return this->m_messages.append(message); - } - - /* - * Metadata - */ - void CStatusMessages::registerMetadata() - { - qRegisterMetaType(); - qDBusRegisterMetaType(); - } - - /* - * To DBus - */ - void CStatusMessages::marshallToDbus(QDBusArgument &arg) const - { - arg << this->m_messages; - } - - /* - * From DBus - */ - void CStatusMessages::unmarshallFromDbus(const QDBusArgument &arg) - { - arg >> this->m_messages; - } - - /* - * To string - */ - QString CStatusMessages::convertToQString(bool i18n) const - { - QString s = "{"; - foreach(CStatusMessage message, this->m_messages) - { - if (s.length() > 1) s.append(", "); - s.append(message.toQString(i18n)); - } - s.append("}"); - return s; - } -} diff --git a/src/blackmisc/statusmessages.h b/src/blackmisc/statusmessages.h deleted file mode 100644 index f9c98e7e1..000000000 --- a/src/blackmisc/statusmessages.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef BLACKMISC_STATUSMESSAGES_H -#define BLACKMISC_STATUSMESSAGES_H - -#include "valueobject.h" -#include "statusmessage.h" - -namespace BlackMisc -{ - - /*! - * \brief Status messages, e.g. from Core -> GUI - */ - class CStatusMessages : public CValueObject - { - public: - - private: - QList m_messages; - - public: - /*! - * \brief StatusMessage - */ - CStatusMessages() {} - - /*! - * \brief Find by type - * \param type - * \return - */ - CStatusMessages findByType(CStatusMessage::StatusType type) const; - - /*! - * \brief Find by type - * \param type - * \return - */ - CStatusMessages findBySeverity(CStatusMessage::StatusSeverity severity) const; - - /*! - * \brief Size - * \return - */ - int size() const; - - /*! - * \brief Append - * \param message - */ - void append(const CStatusMessage &message); - - /*! - * \brief Is empty - * \return - */ - bool isEmpty() const - { - return this->m_messages.isEmpty(); - } - - /*! - * \brief Get messages - * \return - */ - const QList &getMessages() const - { - return this->m_messages; - } - - /*! - * \brief Message at - * \param index - * \return - */ - const CStatusMessage &at(int index) const - { - return this->m_messages.at(index); - } - - /*! - * \brief Value hash - * \return - */ - virtual uint getValueHash() const - { - return qHash(this); - } - - /*! - * \brief As QVariant - * \return - */ - virtual QVariant toQVariant() const - { - return QVariant::fromValue(*this); - } - - /*! - * \brief Register metadata of unit and quantity - */ - static void registerMetadata(); - - protected: - /*! - * \brief Marshall to DBus - * \param argument - */ - virtual void marshallToDbus(QDBusArgument &arg) const; - - /*! - * \brief Unmarshall from DBus - * \param argument - */ - virtual void unmarshallFromDbus(const QDBusArgument &arg); - - /*! - * \brief Convert to String - * \param i18n - * \return - */ - virtual QString convertToQString(bool i18n = false) const; - }; - -} - -Q_DECLARE_METATYPE(BlackMisc::CStatusMessages) - -#endif // guard diff --git a/src/blackmisc/valueobject.cpp b/src/blackmisc/valueobject.cpp index 665f86187..0376ac525 100644 --- a/src/blackmisc/valueobject.cpp +++ b/src/blackmisc/valueobject.cpp @@ -5,11 +5,6 @@ namespace BlackMisc { - /* - * Constructor - */ - CValueObject::CValueObject() {} - /* * Stringify */ diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index bfc3a8ec6..0e8b2be6d 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -244,7 +244,18 @@ namespace BlackMisc /*! * \brief Default constructor */ - CValueObject(); + CValueObject() {} + + /*! + * \brief Copy constructor + */ + CValueObject(const CValueObject &) {} + + /*! + * \brief Copy assignment operator = + * \return + */ + CValueObject &operator=(const CValueObject &) { return *this; } /*! * \brief String for streaming operators diff --git a/src/blackmisc/vaudiodevice.h b/src/blackmisc/vaudiodevice.h index ca184eecc..b0755c58a 100644 --- a/src/blackmisc/vaudiodevice.h +++ b/src/blackmisc/vaudiodevice.h @@ -15,16 +15,15 @@ #include #ifdef Q_OS_WIN -typedef short int16_t; +typedef short int16_t; #endif - namespace BlackMisc { namespace Voice { /*! - * \brief Value object encapsulating information of a audio device. + * Value object encapsulating information of a audio device. * If you want to safe this object, use the name instead of the index, since the index can change after * a restart. */ diff --git a/tests/blackcore/expect.h b/tests/blackcore/expect.h index 0f15c8e63..87e907484 100644 --- a/tests/blackcore/expect.h +++ b/tests/blackcore/expect.h @@ -48,8 +48,8 @@ public: //! Copying is only allowed when there are no connections stored. //! @{ - ConnectGuard(const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); } - ConnectGuard& operator= (const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); } + ConnectGuard(const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); } + ConnectGuard& operator= (const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); } //! @} private: diff --git a/tests/blackcore/testnetwork.h b/tests/blackcore/testnetwork.h index 7796ae1bd..39d10d4c2 100644 --- a/tests/blackcore/testnetwork.h +++ b/tests/blackcore/testnetwork.h @@ -38,7 +38,7 @@ namespace BlackCoreTest */ void networkTest(BlackCore::INetwork *); - BlackCore::NetworkVatlib m_networkVatlib; + BlackCore::CNetworkVatlib m_networkVatlib; }; } //namespace BlackCoreTest diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp index 8c5b5b21b..80de9070d 100644 --- a/tests/blackmisc/testgeo.cpp +++ b/tests/blackmisc/testgeo.cpp @@ -2,33 +2,35 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Math; + namespace BlackMiscTest { -/* - * Geo classes tests - */ -void CTestGeo::geoBasics() -{ - CLatitude lati(10, CAngleUnit::deg()); - QVERIFY2(lati * 2 == lati + lati, "Latitude addition should be equal"); - lati += CLatitude(20, CAngleUnit::deg()); - QVERIFY2(lati.valueRounded() == 30.0, "Latitude should be 30 degrees"); + /* + * Geo classes tests + */ + void CTestGeo::geoBasics() + { + CLatitude lati(10, CAngleUnit::deg()); + QVERIFY2(lati * 2 == lati + lati, "Latitude addition should be equal"); + lati += CLatitude(20, CAngleUnit::deg()); + QVERIFY2(lati.valueRounded() == 30.0, "Latitude should be 30 degrees"); - double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest - CCoordinateGeodetic startGeoVec(lat, lon, h); - CCoordinateEcef mediumEcefVec = CCoordinateTransformation::toEcef(startGeoVec); - CCoordinateGeodetic endGeoVec = CCoordinateTransformation::toGeodetic(mediumEcefVec); + double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest + CCoordinateGeodetic startGeoVec(lat, lon, h); + CCoordinateEcef mediumEcefVec = CCoordinateTransformation::toEcef(startGeoVec); + CCoordinateGeodetic endGeoVec = CCoordinateTransformation::toGeodetic(mediumEcefVec); - // this == contains some implicit rounding, since it is based on PQs - QVERIFY2(startGeoVec == endGeoVec, "Reconverted geo vector should be equal "); + // this == contains some implicit rounding, since it is based on PQs + QVERIFY2(startGeoVec == endGeoVec, "Reconverted geo vector should be equal "); - CCoordinateNed nedVec = CCoordinateTransformation::toNed(mediumEcefVec, startGeoVec); - CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec); + CCoordinateNed nedVec = CCoordinateTransformation::toNed(mediumEcefVec, startGeoVec); + CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec); - // check against rounded reconvert - QVERIFY2(mediumEcefVec.rounded() == ecefReconvert.rounded(), "Reconverted geo vector should be equal"); -} + // check against rounded reconvert + QVERIFY2(mediumEcefVec.rounded() == ecefReconvert.rounded(), "Reconverted geo vector should be equal"); + } } // namespace diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 3c285ab4e..d2e2b5ce2 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -69,8 +69,8 @@ namespace BlackMiscTest { CSpeed s1(100, CSpeedUnit::km_h()); CSpeed s2(1000, CSpeedUnit::ft_min()); - QVERIFY2(s1.valueRounded(CSpeedUnit::NM_h(), 0) == 54, qPrintable(QString("100km/h is not %1 NM/h").arg(s1.valueRounded(CSpeedUnit::NM_h(), 0)))); - QVERIFY2(s2.valueRounded(CSpeedUnit::m_s(), 1) == 5.1, qPrintable(QString("1000ft/min is not %1 m/s").arg(s2.valueRounded(CSpeedUnit::m_s(), 1)))); + QVERIFY2(CMath::epsilonEqual(s1.valueRounded(CSpeedUnit::NM_h(), 0), 54), qPrintable(QString("100km/h is not %1 NM/h").arg(s1.valueRounded(CSpeedUnit::NM_h(), 0)))); + QVERIFY2(CMath::epsilonEqual(s2.valueRounded(CSpeedUnit::m_s(), 1), 5.1), qPrintable(QString("1000ft/min is not %1 m/s").arg(s2.valueRounded(CSpeedUnit::m_s(), 1)))); } /* @@ -97,10 +97,10 @@ namespace BlackMiscTest CAngle a4(35.436, CAngleUnit::sexagesimalDegMin()); // 35.72666 CAngle a5(-60.3015, CAngleUnit::sexagesimalDeg()); // negative angles = west longitude or south latitude a2.switchUnit(CAngleUnit::deg()); - QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor()))); - QVERIFY2(a3.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); - QVERIFY2(a4.valueRounded(CAngleUnit::deg()) == 35.73, "Expecting 35.73"); - QVERIFY2(a5.valueRounded(CAngleUnit::deg(), 4) == -60.5042, "Expecting -60.5042"); + QVERIFY2(CMath::epsilonEqual(a1.piFactor(), 1.00), qPrintable(QString("Pi should be 1PI, not %1").arg(a1.piFactor()))); + QVERIFY2(CMath::epsilonEqual(a3.valueRounded(CAngleUnit::deg()), 35.73), "Expecting 35.73"); + QVERIFY2(CMath::epsilonEqual(a4.valueRounded(CAngleUnit::deg()), 35.73), "Expecting 35.73"); + QVERIFY2(CMath::epsilonEqual(a5.valueRounded(CAngleUnit::deg(), 4), -60.5042), "Expecting -60.5042"); } /* @@ -113,7 +113,7 @@ namespace BlackMiscTest w2.switchUnit(CMassUnit::tonne()); QVERIFY2(w2.value() == 1, "1tonne shall be 1000kg"); w2.switchUnit(CMassUnit::lb()); - QVERIFY2(w2.valueRounded(2) == 2204.62, "1tonne shall be 2204pounds"); + QVERIFY2(CMath::epsilonEqual(w2.valueRounded(2), 2204.62), "1tonne shall be 2204pounds"); QVERIFY2(w1 == w2, "Masses shall be equal"); } @@ -141,10 +141,10 @@ namespace BlackMiscTest CTemperature t2(1, CTemperatureUnit::F()); // 1F CTemperature t3(220.15, CTemperatureUnit::F()); CTemperature t4(10, CTemperatureUnit::F()); - QVERIFY2(t1.valueRounded(CTemperatureUnit::K()) == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.valueRounded(CTemperatureUnit::K())))); - QVERIFY2(t2.valueRounded(CTemperatureUnit::C()) == -17.22, qPrintable(QString("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C())))); - QVERIFY2(t3.valueRounded(CTemperatureUnit::C()) == 104.53, qPrintable(QString("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C())))); - QVERIFY2(t4.valueRounded(CTemperatureUnit::K()) == 260.93, qPrintable(QString("10F shall be 260.93K, not %1 K").arg(t4.valueRounded(CTemperatureUnit::K())))); + QVERIFY2(CMath::epsilonEqual(t1.valueRounded(CTemperatureUnit::K()), 273.15), qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.valueRounded(CTemperatureUnit::K())))); + QVERIFY2(CMath::epsilonEqual(t2.valueRounded(CTemperatureUnit::C()), -17.22), qPrintable(QString("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C())))); + QVERIFY2(CMath::epsilonEqual(t3.valueRounded(CTemperatureUnit::C()), 104.53), qPrintable(QString("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C())))); + QVERIFY2(CMath::epsilonEqual(t4.valueRounded(CTemperatureUnit::K()), 260.93), qPrintable(QString("10F shall be 260.93K, not %1 K").arg(t4.valueRounded(CTemperatureUnit::K())))); } /* @@ -174,7 +174,8 @@ namespace BlackMiscTest CAcceleration a2(a1); a1.switchUnit(CAccelerationUnit::ft_s2()); QVERIFY2(a1 == a2, "Accelerations should be similar"); - QVERIFY2(BlackMisc::Math::CMath::round(a2.value() * ftFactor, 6) == a1.valueRounded(6), + QVERIFY2(CMath::epsilonEqual(BlackMisc::Math::CMath::round(a2.value() * ftFactor, 6), + a1.valueRounded(6)), "Numerical values should be equal"); }