diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 5722c99a5..567f27410 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -66,6 +66,9 @@ namespace BlackCore ActionStops }; + //! Log message category + static QString getMessageCategory() { return "swift.context.application"; } + //! Service name static const QString &InterfaceName() { diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index 15a7adc29..537a07437 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -7,6 +7,7 @@ #include "context_runtime.h" #include "input_manager.h" #include "blackmisc/settingutilities.h" +#include "blackmisc/logmessage.h" #include #include @@ -50,7 +51,7 @@ namespace BlackCore */ void CContextApplication::notifyAboutComponentChange(uint component, uint action) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { QString::number(component), QString::number(action) }); + CLogMessage().debug(this) << Q_FUNC_INFO << QString::number(component) << QString::number(action); this->componentChanged(component, action); } @@ -59,7 +60,7 @@ namespace BlackCore */ bool CContextApplication::writeToFile(const QString &fileName, const QString &content) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { fileName, content.left(25) }); + CLogMessage().debug(this) << Q_FUNC_INFO << fileName << content.left(25); if (fileName.isEmpty()) return false; QFile file(fileName); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) @@ -76,7 +77,7 @@ namespace BlackCore */ QString CContextApplication::readFromFile(const QString &fileName) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, fileName); + CLogMessage().debug(this) << Q_FUNC_INFO << fileName; QFile file(fileName); QString content; if (fileName.isEmpty()) return content; diff --git a/src/blackcore/context_audio.h b/src/blackcore/context_audio.h index 8b9ada420..7acacbb78 100644 --- a/src/blackcore/context_audio.h +++ b/src/blackcore/context_audio.h @@ -43,6 +43,9 @@ namespace BlackCore IContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} public: + //! Log message category + static QString getMessageCategory() { return "swift.context.audio"; } + //! \brief Interface name static const QString &InterfaceName() { diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 662a2a3a0..90fb5d215 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -13,6 +13,7 @@ #include "blackmisc/notificationsounds.h" #include "blackmisc/voiceroomlist.h" #include "blackmisc/hotkeyfunction.h" +#include "blackmisc/logmessage.h" #include @@ -76,7 +77,7 @@ namespace BlackCore CVoiceRoomList CContextAudio::getComVoiceRoomsWithAudioStatus() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return getComVoiceRooms(); } @@ -86,7 +87,7 @@ namespace BlackCore CVoiceRoom CContextAudio::getCom1VoiceRoom(bool withAudioStatus) const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, withAudioStatus); + CLogMessage().debug(this) << Q_FUNC_INFO << withAudioStatus; // We always have the audio status due to shared status return m_channelCom1->getVoiceRoom(); } @@ -97,7 +98,7 @@ namespace BlackCore CVoiceRoom CContextAudio::getCom2VoiceRoom(bool withAudioStatus) const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, withAudioStatus); + CLogMessage().debug(this) << Q_FUNC_INFO << withAudioStatus; // We always have the audio status due to shared status return m_channelCom2->getVoiceRoom(); } @@ -108,7 +109,7 @@ namespace BlackCore CVoiceRoomList CContextAudio::getComVoiceRooms() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; CVoiceRoomList voiceRoomList; voiceRoomList.push_back(m_channelCom1->getVoiceRoom()); voiceRoomList.push_back(m_channelCom2->getVoiceRoom()); @@ -121,7 +122,7 @@ namespace BlackCore void CContextAudio::leaveAllVoiceRooms() { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; m_channelCom1->leaveVoiceRoom(); m_channelCom2->leaveVoiceRoom(); } @@ -132,7 +133,7 @@ namespace BlackCore CAudioDeviceList CContextAudio::getAudioDevices() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_voice->audioDevices(); } @@ -142,7 +143,7 @@ namespace BlackCore CAudioDeviceList CContextAudio::getCurrentAudioDevices() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; CAudioDeviceList devices; devices.push_back(this->m_voice->getCurrentInputDevice()); devices.push_back(this->m_voice->getCurrentOutputDevice()); @@ -156,7 +157,7 @@ namespace BlackCore { Q_ASSERT(this->m_voice); Q_ASSERT(audioDevice.getType() != CAudioDevice::Unknown); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, audioDevice.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << audioDevice; if (audioDevice.getType() == CAudioDevice::InputDevice) { this->m_voice->setInputDevice(audioDevice); @@ -173,7 +174,7 @@ namespace BlackCore void CContextAudio::setVolumes(const CComSystem &com1, const CComSystem &com2) { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { com1.toQString(), com2.toQString() }); + CLogMessage().debug(this) << Q_FUNC_INFO << com1 << com2; // volumes qint32 vol1 = com1.getVolumeOutput(); @@ -192,7 +193,7 @@ namespace BlackCore bool CContextAudio::isMuted() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return m_channelCom1->isMuted() && m_channelCom2->isMuted(); } @@ -203,7 +204,7 @@ namespace BlackCore { Q_ASSERT(this->m_voice); Q_ASSERT(newRooms.size() == 2); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, newRooms.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << newRooms; CVoiceRoomList currentRooms = getComVoiceRooms(); CVoiceRoom currentRoom1 = currentRooms[0]; @@ -244,7 +245,7 @@ namespace BlackCore CCallsignList CContextAudio::getCom1RoomCallsigns() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return m_channelCom1->getVoiceRoomCallsigns(); } @@ -254,7 +255,7 @@ namespace BlackCore CCallsignList CContextAudio::getCom2RoomCallsigns() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return m_channelCom2->getVoiceRoomCallsigns(); } @@ -266,7 +267,7 @@ namespace BlackCore Q_ASSERT(this->m_voice); Q_ASSERT(this->getRuntime()); if (!this->getRuntime()->getIContextNetwork()) return Network::CUserList(); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->getIContextNetwork()->getUsersForCallsigns(this->getCom1RoomCallsigns()); } @@ -278,7 +279,7 @@ namespace BlackCore Q_ASSERT(this->m_voice); Q_ASSERT(this->getRuntime()); if (!this->getRuntime()->getIContextNetwork()) return Network::CUserList(); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->getIContextNetwork()->getUsersForCallsigns(this->getCom2RoomCallsigns()); } @@ -288,7 +289,7 @@ namespace BlackCore void CContextAudio::playSelcalTone(const CSelcal &selcal) const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, selcal.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << selcal; CAudioDevice outputDevice = m_voice->getCurrentOutputDevice(); BlackSound::CSoundGenerator::playSelcal(90, selcal, outputDevice); } @@ -299,7 +300,7 @@ namespace BlackCore void CContextAudio::playNotification(uint notification, bool considerSettings) const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, QString::number(notification)); + CLogMessage().debug(this) << Q_FUNC_INFO << notification; auto notificationSound = static_cast(notification); if (considerSettings) @@ -326,7 +327,7 @@ namespace BlackCore void CContextAudio::runMicrophoneTest() { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; this->m_voice->runMicrophoneTest(); } @@ -336,7 +337,7 @@ namespace BlackCore void CContextAudio::runSquelchTest() { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; this->m_voice->runSquelchTest(); } @@ -346,7 +347,7 @@ namespace BlackCore QString CContextAudio::getMicrophoneTestResult() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_voice->micTestResultAsString(); } @@ -356,7 +357,7 @@ namespace BlackCore double CContextAudio::getSquelchValue() const { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return static_cast(this->m_voice->inputSquelch()); } @@ -366,7 +367,7 @@ namespace BlackCore void CContextAudio::enableAudioLoopback(bool enable) { Q_ASSERT(this->m_voice); - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; m_voice->enableAudioLoopback(enable); } diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index 8cbf10d9f..342af39aa 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -43,6 +43,9 @@ namespace BlackCore Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) public: + //! Log message category + static QString getMessageCategory() { return "swift.context.network"; } + //! DBus interface name static const QString &InterfaceName() { @@ -144,13 +147,13 @@ namespace BlackCore * \return messages gererated during connecting * \see INetwork::LoginMode */ - virtual BlackMisc::CStatusMessageList connectToNetwork(uint loginMode) = 0; + virtual BlackMisc::CStatusMessage connectToNetwork(uint loginMode) = 0; /*! * Disconnect from network * \return messages generated during disconnecting */ - virtual BlackMisc::CStatusMessageList disconnectFromNetwork() = 0; + virtual BlackMisc::CStatusMessage disconnectFromNetwork() = 0; //! Network connected? virtual bool isConnected() const = 0; diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index 84d6e9f36..5aecb1f9f 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -19,6 +19,7 @@ #include "blackmisc/networkutils.h" #include "blackmisc/avatcstationlist.h" +#include "blackmisc/logmessage.h" #include #include @@ -104,32 +105,31 @@ namespace BlackCore /* * Connect to network */ - CStatusMessageList CContextNetwork::connectToNetwork(uint loginMode) + CStatusMessage CContextNetwork::connectToNetwork(uint loginMode) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); - CStatusMessageList msgs; - QString msg; + CLogMessage().debug(this) << Q_FUNC_INFO; CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer(); + QString msg; if (!currentServer.getUser().isValid()) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid user credentials")); + return CLogMessage().error(this, "Invalid user credentials"); } else if (!this->ownAircraft().getIcaoInfo().hasAircraftAndAirlineDesignator()) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Invalid ICAO data for own aircraft")); + return CLogMessage().error(this, "Invalid ICAO data for own aircraft"); } else if (!CNetworkUtils::canConnect(currentServer, msg, 2000)) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, msg)); + return CLogMessage().error(this, msg); } else if (this->m_network->isConnected()) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already connected")); + return CLogMessage().error(this, "Already connected"); } else if (this->isPendingConnection()) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Pending connection, please wait")); + return CLogMessage().error(this, "Pending connection, please wait"); } else { @@ -143,36 +143,31 @@ namespace BlackCore this->m_network->presetIcaoCodes(ownAircraft.getIcaoInfo()); this->m_network->setOwnAircraft(ownAircraft); this->m_network->initiateConnection(); - msg = "Connection pending "; - msg.append(" ").append(currentServer.getAddress()).append(" ").append(QString::number(currentServer.getPort())); - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, msg)); + return CLogMessage().info(this, "Connection pending %1 %2") << currentServer.getAddress() << currentServer.getPort(); } - return msgs; } /* * Disconnect from network */ - CStatusMessageList CContextNetwork::disconnectFromNetwork() + CStatusMessage CContextNetwork::disconnectFromNetwork() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); - CStatusMessageList msgs; + CLogMessage().debug(this) << Q_FUNC_INFO; if (this->m_network->isConnected()) { this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect this->m_network->terminateConnection(); this->m_airspace->clear(); - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, "Connection terminating")); + return CLogMessage().info(this, "Connection terminating"); } else if (this->isPendingConnection()) { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Pending connection, please wait")); + return CLogMessage().warning(this, "Pending connection, please wait"); } else { - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityWarning, "Already disconnected")); + return CLogMessage().warning(this, "Already disconnected"); } - return msgs; } /* @@ -180,7 +175,7 @@ namespace BlackCore */ bool CContextNetwork::isConnected() const { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_network->isConnected(); } @@ -198,7 +193,7 @@ namespace BlackCore */ void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, textMessages.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << textMessages; this->m_network->sendTextMessages(textMessages); } @@ -207,14 +202,14 @@ namespace BlackCore */ void CContextNetwork::sendFlightPlan(const CFlightPlan &flightPlan) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, flightPlan.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << flightPlan; this->m_network->sendFlightPlan(flightPlan); this->m_network->sendFlightPlanQuery(this->ownAircraft().getCallsign()); } CFlightPlan CContextNetwork::loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_airspace->loadFlightPlanFromNetwork(callsign); } @@ -269,8 +264,8 @@ namespace BlackCore */ void CContextNetwork::ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to, const QString &message) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { QString::number(from), QString::number(to) }); - INetwork::ConnectionStatus fromOld = this->m_currentStatus; + CLogMessage().debug(this) << Q_FUNC_INFO << from << to; + auto fromOld = this->m_currentStatus; this->m_currentStatus = to; if (fromOld == INetwork::Disconnecting) @@ -280,26 +275,20 @@ namespace BlackCore from = INetwork::Disconnecting; } - CStatusMessageList msgs; // send 1st position if (to == INetwork::Connected) { - QString m("Connected, own aircraft "); - m.append(this->ownAircraft().toQString(true)); - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m)); + CLogMessage().info(this, "Connected, own aircraft %1") << this->ownAircraft().toQString(); } // send as message - QString m("Connection status changed from %1 to %2"); - m = m.arg(INetwork::connectionStatusToString(from), INetwork::connectionStatusToString(to)); - if (!message.isEmpty()) m.append(" ").append(message); - msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, - to == INetwork::DisconnectedError ? CStatusMessage::SeverityError : CStatusMessage::SeverityInfo, m)); - // FIXME (MS) conditional increases the number of scenarios which must be considered and continuously tested - // This is more a guard than a real conditional, e.g. when system shuts down - if (this->getIContextApplication()) + if (to == INetwork::DisconnectedError) { - this->getIContextApplication()->sendStatusMessages(msgs); + CLogMessage().error(this, "Connection status changed from %1 to %2 %3") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to) << message; + } + else + { + CLogMessage().info(this, "Connection status changed from %1 to %2 %3") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to) << message; } // send as own signal @@ -311,11 +300,8 @@ namespace BlackCore */ void CContextNetwork::ps_dataFileRead() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); - if (this->getIContextApplication()) - { - this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage("Read VATSIM data file", CStatusMessage::TypeTrafficNetwork)); - } + CLogMessage().debug(this) << Q_FUNC_INFO; + CLogMessage().info(this, "Read VATSIM data file"); } /* @@ -323,7 +309,7 @@ namespace BlackCore */ void CContextNetwork::ps_fsdTextMessageReceived(const CTextMessageList &messages) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, messages.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << messages; this->textMessagesReceived(messages); // relay } @@ -355,8 +341,7 @@ namespace BlackCore */ void CContextNetwork::ps_receivedBookings(const CAtcStationList &) { - // TODO (MS) no test for if (this->getIContextApplication()) here? - this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage("Read bookings from network", CStatusMessage::TypeTrafficNetwork)); + CLogMessage().info(this, "Read bookings from network"); } /* @@ -395,7 +380,7 @@ namespace BlackCore */ BlackMisc::Aviation::CInformationMessage CContextNetwork::getMetar(const BlackMisc::Aviation::CAirportIcao &airportIcaoCode) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, airportIcaoCode.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << airportIcaoCode; return m_airspace->getMetar(airportIcaoCode); } diff --git a/src/blackcore/context_network_impl.h b/src/blackcore/context_network_impl.h index 9fdc2f203..c85f90e66 100644 --- a/src/blackcore/context_network_impl.h +++ b/src/blackcore/context_network_impl.h @@ -22,6 +22,7 @@ #include "blackmisc/setnetwork.h" #include "blackmisc/nwclientlist.h" #include "blackmisc/digestsignal.h" +#include "blackmisc/logmessage.h" #include @@ -55,29 +56,29 @@ namespace BlackCore //! \copydoc IContextNetwork::getAtcStationsOnline() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + BlackMisc::CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_airspace->getAtcStationsOnline(); } //! \copydoc IContextNetwork::getAtcStationsBooked() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + BlackMisc::CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_airspace->getAtcStationsBooked(); } //! \copydoc IContextNetwork::getAircraftsInRange() virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + BlackMisc::CLogMessage().debug(this) << Q_FUNC_INFO; return this->m_airspace->getAircraftInRange(); } //! \copydoc IContextNetwork::connectToNetwork() - virtual BlackMisc::CStatusMessageList connectToNetwork(uint mode) override; + virtual BlackMisc::CStatusMessage connectToNetwork(uint mode) override; //! \copydoc IContextNetwork::disconnectFromNetwork() - virtual BlackMisc::CStatusMessageList disconnectFromNetwork() override; + virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; //! \copydoc IContextNetwork::isConnected() virtual bool isConnected() const override; diff --git a/src/blackcore/context_network_proxy.cpp b/src/blackcore/context_network_proxy.cpp index 0dac982d9..0610f7d79 100644 --- a/src/blackcore/context_network_proxy.cpp +++ b/src/blackcore/context_network_proxy.cpp @@ -131,14 +131,14 @@ namespace BlackCore this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number); } - BlackMisc::CStatusMessageList CContextNetworkProxy::connectToNetwork(uint loginMode) + BlackMisc::CStatusMessage CContextNetworkProxy::connectToNetwork(uint loginMode) { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork"), loginMode); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork"), loginMode); } - BlackMisc::CStatusMessageList CContextNetworkProxy::disconnectFromNetwork() + BlackMisc::CStatusMessage CContextNetworkProxy::disconnectFromNetwork() { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); + return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); } bool CContextNetworkProxy::isConnected() const diff --git a/src/blackcore/context_network_proxy.h b/src/blackcore/context_network_proxy.h index b9de794c3..c13c5b148 100644 --- a/src/blackcore/context_network_proxy.h +++ b/src/blackcore/context_network_proxy.h @@ -60,10 +60,10 @@ namespace BlackCore virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override; //! \copydoc IContextNetwork::connectToNetwork() - virtual BlackMisc::CStatusMessageList connectToNetwork(uint mode) override; + virtual BlackMisc::CStatusMessage connectToNetwork(uint mode) override; //! \copydoc IContextNetwork::disconnectFromNetwork() - virtual BlackMisc::CStatusMessageList disconnectFromNetwork() override; + virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; //! \copydoc IContextNetwork::isConnected() virtual bool isConnected() const override; diff --git a/src/blackcore/context_ownaircraft.h b/src/blackcore/context_ownaircraft.h index 371bdaa72..6bec21228 100644 --- a/src/blackcore/context_ownaircraft.h +++ b/src/blackcore/context_ownaircraft.h @@ -34,6 +34,9 @@ namespace BlackCore Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) public: + //! Log message category + static QString getMessageCategory() { return "swift.context.ownaircraft"; } + //! DBus interface name static const QString &InterfaceName() { diff --git a/src/blackcore/context_ownaircraft_impl.cpp b/src/blackcore/context_ownaircraft_impl.cpp index 7dd4dc0bd..12fd10a9c 100644 --- a/src/blackcore/context_ownaircraft_impl.cpp +++ b/src/blackcore/context_ownaircraft_impl.cpp @@ -8,6 +8,7 @@ #include "context_audio.h" #include "context_runtime.h" #include "context_settings.h" +#include "blackmisc/logmessage.h" using namespace BlackMisc; using namespace BlackMisc::PhysicalQuantities; @@ -70,7 +71,7 @@ namespace BlackCore */ void CContextOwnAircraft::resolveVoiceRooms() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (this->m_voiceRoom1UrlOverride.isEmpty() && this->m_voiceRoom2UrlOverride.isEmpty() && !this->m_automaticVoiceRoomResolution) return; if (!this->getIContextNetwork()) return; // no chance to resolve rooms if (!this->getIContextAudio()) return; // no place to set rooms @@ -93,7 +94,7 @@ namespace BlackCore */ void CContextOwnAircraft::updateOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { ownAircraft().toQString(), originator }); + CLogMessage().debug(this) << Q_FUNC_INFO << ownAircraft() << originator; // trigger the correct signals bool changedCockpit = this->updateOwnCockpit(aircraft.getCom1System(), aircraft.getCom2System(), aircraft.getTransponder(), originator); @@ -120,7 +121,7 @@ namespace BlackCore */ bool CContextOwnAircraft::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude, const QString &originator) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { position.toQString(), altitude.toQString(), originator }); + CLogMessage().debug(this) << Q_FUNC_INFO << position << altitude << originator; bool changed = (this->m_ownAircraft.getPosition() != position); if (changed) this->m_ownAircraft.setPosition(position); @@ -143,7 +144,7 @@ namespace BlackCore */ bool CContextOwnAircraft::updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation, const QString &originator) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, situation.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << situation; bool changed = this->m_ownAircraft.getSituation() != situation; if (!changed) return changed; @@ -161,7 +162,7 @@ namespace BlackCore */ bool CContextOwnAircraft::updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { com1.toQString(), com2.toQString(), transponder.toQString() }); + CLogMessage().debug(this) << Q_FUNC_INFO << com1 << com2 << transponder; bool changed = this->m_ownAircraft.hasChangedCockpitData(com1, com2, transponder); if (changed) { @@ -183,7 +184,7 @@ namespace BlackCore void CContextOwnAircraft::setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { QString::number(outputVolumeCom1), QString::number(outputVolumeCom2) }); + CLogMessage().debug(this) << Q_FUNC_INFO << outputVolumeCom1 << outputVolumeCom2; CComSystem com1 = this->m_ownAircraft.getCom1System(); com1.setVolumeOutput(outputVolumeCom1); @@ -213,7 +214,7 @@ namespace BlackCore */ void CContextOwnAircraft::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { voiceRoom1Url, voiceRoom2Url }); + CLogMessage().debug(this) << Q_FUNC_INFO << voiceRoom1Url << voiceRoom2Url; this->m_voiceRoom1UrlOverride = voiceRoom1Url.trimmed(); this->m_voiceRoom2UrlOverride = voiceRoom2Url.trimmed(); @@ -225,7 +226,7 @@ namespace BlackCore */ void CContextOwnAircraft::enableAutomaticVoiceRoomResolution(bool enable) { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, enable); + CLogMessage().debug(this) << Q_FUNC_INFO << enable; this->m_automaticVoiceRoomResolution = enable; } @@ -234,7 +235,7 @@ namespace BlackCore */ CAircraft CContextOwnAircraft::getOwnAircraft() const { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, this->m_ownAircraft.toQString()); + CLogMessage().debug(this) << Q_FUNC_INFO << this->m_ownAircraft; return this->m_ownAircraft; } diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index db7964cea..c90a8f543 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -8,6 +8,7 @@ #include "blackmisc/statusmessagelist.h" #include "blackmisc/avaircraft.h" #include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/logmessage.h" #include "blackcore/context_runtime.h" #include @@ -442,8 +443,7 @@ namespace BlackCore connect(this->m_contextSettings, &IContextSettings::changedSettings, this->m_contextSimulator, &IContextSimulator::settingsChanged); if (!this->m_contextSimulator->loadSimulatorPluginFromSettings()) { - qWarning() << "No simulator plugin loaded"; - this->sendStatusMessage(CStatusMessage::getWarningMessage("No simulator plugin loaded", CStatusMessage::TypeSimulator)); + CLogMessage().warning(this, "No simulator plugin loaded"); } } } diff --git a/src/blackcore/context_runtime.h b/src/blackcore/context_runtime.h index 370a85ab3..46dc030cd 100644 --- a/src/blackcore/context_runtime.h +++ b/src/blackcore/context_runtime.h @@ -34,6 +34,8 @@ namespace BlackCore Q_OBJECT public: + //! Log message category + static QString getMessageCategory() { return "swift.runtime"; } //! Tags to identify the context when logging a slot enum LogContext { diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index d73905494..d033159b1 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -56,6 +56,8 @@ namespace BlackCore {} public: + //! Log message category + static QString getMessageCategory() { return "swift.context.settings"; } //! Service name static const QString &InterfaceName() diff --git a/src/blackcore/context_settings_impl.cpp b/src/blackcore/context_settings_impl.cpp index 489dff688..e2b416ca6 100644 --- a/src/blackcore/context_settings_impl.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -8,6 +8,7 @@ #include "blackmisc/settingutilities.h" #include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/logmessage.h" #include #include @@ -32,8 +33,7 @@ namespace BlackCore { if (!CSettingUtilities::initSettingsDirectory()) { - return CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, - QString("Cannot init directory: %1").arg(this->getSettingsDirectory())); + return CLogMessage().error(this, "Cannot init directory: %1") << this->getSettingsDirectory(); } bool ok = false; QFile jsonFile(this->getSettingsFileName()); @@ -94,13 +94,11 @@ namespace BlackCore if (ok) { - return CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityInfo, - QString("Read settings: %1").arg(this->getSettingsFileName())); + return CLogMessage().info(this, "Read settings: %1") << this->getSettingsFileName(); } else { - return CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, - QString("Problem reading settings: %1").arg(this->getSettingsFileName())); + return CLogMessage().error(this, "Problem reading settings: %1") << this->getSettingsFileName(); } } @@ -111,8 +109,7 @@ namespace BlackCore { if (!CSettingUtilities::initSettingsDirectory()) { - return CStatusMessage(CStatusMessage::TypeCore, CStatusMessage::SeverityError, - QString("Cannot init directory: %1").arg(this->getSettingsDirectory())); + return CLogMessage().error(this, "Cannot init directory: %1") << this->getSettingsDirectory(); } QFile jsonFile(this->getSettingsFileName()); bool ok = false; @@ -124,13 +121,11 @@ namespace BlackCore } if (ok) { - return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo, - QString("Written settings: %1").arg(this->getSettingsFileName())); + return CLogMessage().info(this, "Written settings: %1") << this->getSettingsFileName(); } else { - return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityError, - QString("Problem writing settings: %1").arg(this->getSettingsFileName())); + return CLogMessage().error(this, "Problem writing settings: %1") << this->getSettingsFileName(); } } @@ -147,9 +142,7 @@ namespace BlackCore if (write) return this->write(); else - return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo, - QString("Reset settings data, not written")); - + return CLogMessage().info(this, "Reset settings data, not written"); } QString CContextSettings::getSettingsAsJsonString() const @@ -244,7 +237,7 @@ namespace BlackCore bool changed = false; if (path.startsWith(IContextSettings::PathNetworkSettings())) { - msgs = this->m_settingsNetwork.value(nextLevelPath, command, value, changed); + msgs.push_back(this->m_settingsNetwork.value(nextLevelPath, command, value, changed)); if (changed) { msgs.push_back(this->write()); @@ -253,7 +246,7 @@ namespace BlackCore } else if (path.startsWith(IContextSettings::PathAudioSettings())) { - msgs = this->m_settingsAudio.value(nextLevelPath, command, value, changed); + msgs.push_back(this->m_settingsAudio.value(nextLevelPath, command, value, changed)); if (changed) { msgs.push_back(this->write()); @@ -262,7 +255,7 @@ namespace BlackCore } else if (path.startsWith(IContextSettings::PathSimulatorSettings())) { - msgs = this->m_settingsSimulator.value(nextLevelPath, command, value, changed); + msgs.push_back(this->m_settingsSimulator.value(nextLevelPath, command, value, changed)); if (changed) { msgs.push_back(this->write()); @@ -271,8 +264,7 @@ namespace BlackCore } else { - // wrong path - msgs = CSettingUtilities::wrongPathMessages(path); + msgs.push_back(CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong path: %1") << path); } return msgs; } diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 0efd2ed67..d9890565b 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -39,6 +39,9 @@ namespace BlackCore Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) public: + //! Log message category + static QString getMessageCategory() { return "swift.context.simulator"; } + //! Service name static const QString &InterfaceName() { diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index 82070409c..351fe6d7f 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -9,6 +9,7 @@ #include "context_application.h" #include "context_network_impl.h" #include "context_runtime.h" +#include "blackmisc/logmessage.h" #include #include @@ -52,42 +53,42 @@ namespace BlackCore bool CContextSimulator::isConnected() const { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator) return false; return m_simulator->isConnected(); } bool CContextSimulator::canConnect() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator) return false; return m_simulator->canConnect(); } bool CContextSimulator::connectTo() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator) return false; return m_simulator->connectTo(); } void CContextSimulator::asyncConnectTo() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator || m_canConnectResult.isRunning()) return; // already checking m_simulator->asyncConnectTo(); } bool CContextSimulator::disconnectFrom() { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator) return false; return m_simulator->disconnectFrom(); } BlackSim::CSimulatorInfo CContextSimulator::getSimulatorInfo() const { - this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO); + CLogMessage().debug(this) << Q_FUNC_INFO; if (!m_simulator) return BlackSim::CSimulatorInfo::UnspecifiedSim(); return m_simulator->getSimulatorInfo(); } @@ -137,7 +138,7 @@ namespace BlackCore // warning if we do not have any plugins if (m_simulatorFactories.isEmpty()) { - this->getRuntime()->sendStatusMessage(CStatusMessage::getErrorMessage("No simulator plugins", CStatusMessage::TypeSimulator)); + CLogMessage().error(this, "No simulator plugins"); return false; } @@ -149,9 +150,7 @@ namespace BlackCore // no plugin found if (iterator == m_simulatorFactories.end()) { - QString m = QString("Plugin not found: '%1'").arg(simulatorInfo.toQString(true)); - this->getRuntime()->sendStatusMessage(CStatusMessage::getErrorMessage(m, CStatusMessage::TypeSimulator)); - qCritical() << m; + CLogMessage().error(this, "Plugin not found: '%1'") << simulatorInfo.toQString(true); return false; } @@ -193,8 +192,7 @@ namespace BlackCore asyncConnectTo(); // info about what is going on - QString m = QString("Simulator plugin loaded: '%1'").arg(this->m_simulator->getSimulatorInfo().toQString(true)); - this->getRuntime()->sendStatusMessage(CStatusMessage::getInfoMessage(m, CStatusMessage::TypeSimulator)); + CLogMessage().info(this, "Simulator plugin loaded: '%1'") << this->m_simulator->getSimulatorInfo().toQString(true); return true; } @@ -349,13 +347,11 @@ namespace BlackCore { if (this->loadSimulatorPlugin(plugin)) { - QString m = QString("Plugin loaded: '%1'").arg(plugin.toQString(true)); - this->getRuntime()->sendStatusMessage(CStatusMessage::getInfoMessage(m, CStatusMessage::TypeSimulator)); + CLogMessage().info(this, "Plugin loaded: '%1'") << plugin.toQString(true); } else { - QString m = QString("Cannot load driver: '%1'").arg(plugin.toQString(true)); - this->getRuntime()->sendStatusMessage(CStatusMessage::getErrorMessage(m, CStatusMessage::TypeSimulator)); + CLogMessage().error(this, "Cannot load driver: '%1'") << plugin.toQString(true); } } @@ -377,9 +373,7 @@ namespace BlackCore m_pluginsDir = QDir(path); if (!m_pluginsDir.exists()) { - QString m = QString("No plugin directory: %1").arg(m_pluginsDir.currentPath()); - qWarning() << m; - this->getRuntime()->sendStatusMessage(CStatusMessage::getErrorMessage(m, CStatusMessage::TypeSimulator)); + CLogMessage().error(this, "No plugin directory: %1") << m_pluginsDir.currentPath(); return; } @@ -403,9 +397,7 @@ namespace BlackCore } else { - QString m = loader.errorString(); - this->getRuntime()->sendStatusMessage(CStatusMessage::getErrorMessage(m, CStatusMessage::TypeSimulator)); - qDebug() << m; + CLogMessage().error(this, loader.errorString()); qDebug() << "Also check if required dll/libs of plugin exists"; } } diff --git a/src/blackcore/network.h b/src/blackcore/network.h index 53924d8df..6a4cd25d1 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -65,6 +65,11 @@ namespace BlackCore */ virtual ~INetwork() {} + /*! + * Log message category. + */ + static QString getMessageCategory() { return "swift.trafficNetwork"; } + /*! * Flags for capabilities bitfield. */ diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index 1f960b31d..664efb12c 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -5,6 +5,7 @@ #include "network_vatlib.h" #include "blackmisc/project.h" +#include "blackmisc/logmessage.h" #include #include #include @@ -1083,42 +1084,34 @@ namespace BlackCore //TODO } - void CNetworkVatlib::onErrorReceived(Cvatlib_Network *, Cvatlib_Network::error type, const char *msgData, const char *data, void *cbvar) + void CNetworkVatlib::onErrorReceived(Cvatlib_Network *, Cvatlib_Network::error type, const char *msg, const char *data, void *cbvar) { - QString msg; - + auto *self = cbvar_cast(cbvar); switch (type) { - case Cvatlib_Network::error_CallsignTaken: msg = "The requested callsign is already taken"; goto terminate; - case Cvatlib_Network::error_CallsignInvalid: msg = "The requested callsign is not valid"; goto terminate; - case Cvatlib_Network::error_CIDPasswdInvalid: msg = "Wrong user ID or password"; goto terminate; - case Cvatlib_Network::error_ProtoVersion: msg = "This server does not support our protocol version"; goto terminate; - case Cvatlib_Network::error_LevelTooHigh: msg = "You are not authorized to use the requested pilot rating"; goto terminate; - case Cvatlib_Network::error_ServerFull: msg = "The server is full"; goto terminate; - case Cvatlib_Network::error_CIDSuspended: msg = "Your user account is suspended"; goto terminate; - case Cvatlib_Network::error_InvalidPosition: msg = "You are not authorized to use the requested pilot rating"; goto terminate; - case Cvatlib_Network::error_SoftwareNotAuthorized: msg = "This client software has not been authorized for use on this network"; goto terminate; + case Cvatlib_Network::error_CallsignTaken: CLogMessage().error(self, "The requested callsign is already taken"); emit self->terminate(); break; + case Cvatlib_Network::error_CallsignInvalid: CLogMessage().error(self, "The requested callsign is not valid"); emit self->terminate(); break; + case Cvatlib_Network::error_CIDPasswdInvalid: CLogMessage().error(self, "Wrong user ID or password"); emit self->terminate(); break; + case Cvatlib_Network::error_ProtoVersion: CLogMessage().error(self, "This server does not support our protocol version"); emit self->terminate(); break; + case Cvatlib_Network::error_LevelTooHigh: CLogMessage().error(self, "You are not authorized to use the requested pilot rating"); emit self->terminate(); break; + case Cvatlib_Network::error_ServerFull: CLogMessage().error(self, "The server is full"); emit self->terminate(); break; + case Cvatlib_Network::error_CIDSuspended: CLogMessage().error(self, "Your user account is suspended"); emit self->terminate(); break; + case Cvatlib_Network::error_InvalidPosition: CLogMessage().error(self, "You are not authorized to use the requested pilot rating"); emit self->terminate(); break; + case Cvatlib_Network::error_SoftwareNotAuthorized: CLogMessage().error(self, "This software is not authorized for use on this network"); emit self->terminate(); break; - case Cvatlib_Network::error_Ok: msg = "OK"; break; - case Cvatlib_Network::error_Syntax: msg = "Malformed packet: Syntax error: "; msg.append(cbvar_cast(cbvar)->fromFSD(data)); break; - case Cvatlib_Network::error_SourceInvalid: msg = "Server: source invalid "; msg.append(cbvar_cast(cbvar)->fromFSD(data)); break; - case Cvatlib_Network::error_CallsignNotExists: msg = "Shim lib: "; msg.append(cbvar_cast(cbvar)->fromFSD(msgData)).append(" (").append(cbvar_cast(cbvar)->fromFSD(data)).append(")"); break; - case Cvatlib_Network::error_NoFP: msg = "Server: no flight plan"; break; - case Cvatlib_Network::error_NoWeather: msg = "Server: requested weather profile does not exist"; break; + case Cvatlib_Network::error_Ok: CLogMessage().info(self, "OK"); break; + case Cvatlib_Network::error_Syntax: CLogMessage().info(self, "Malformed packet: Syntax error: %1") << self->fromFSD(data); break; + case Cvatlib_Network::error_SourceInvalid: CLogMessage().info(self, "Server: source invalid %1") << self->fromFSD(data); break; + case Cvatlib_Network::error_CallsignNotExists: CLogMessage().info(self, "Shim lib: %1 (%2)") << self->fromFSD(msg) << self->fromFSD(data); break; + case Cvatlib_Network::error_NoFP: CLogMessage().info(self, "Server: no flight plan"); break; + case Cvatlib_Network::error_NoWeather: CLogMessage().info(self, "Server: requested weather profile does not exist"); break; // we have no idea what these mean case Cvatlib_Network::error_Registered: - case Cvatlib_Network::error_InvalidControl: msg = "Server: "; msg.append(cbvar_cast(cbvar)->fromFSD(msgData)); break; + case Cvatlib_Network::error_InvalidControl: CLogMessage().info(self, "Server: ") << self->fromFSD(msg); break; - default: qFatal("VATSIM shim library: %s (error %d)", qPrintable(msg), type); goto terminate; + default: qFatal("VATSIM shim library: %s (error %d)", msg, type); emit self->terminate(); } - - emit cbvar_cast(cbvar)->statusMessage(BlackMisc::CStatusMessage(BlackMisc::CStatusMessage::TypeTrafficNetwork, BlackMisc::CStatusMessage::SeverityInfo, msg)); - return; - - terminate: - emit cbvar_cast(cbvar)->statusMessage(BlackMisc::CStatusMessage(BlackMisc::CStatusMessage::TypeTrafficNetwork, BlackMisc::CStatusMessage::SeverityError, msg)); - emit cbvar_cast(cbvar)->terminate(); // private, will be handled during the next pass of the Qt event loop } void CNetworkVatlib::onWindDataReceived(Cvatlib_Network *, Cvatlib_Network::WindLayer /** layers **/[4], void * /** cbvar **/) diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 9049714ba..1aa0f6c28 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -25,6 +25,8 @@ namespace BlackCore Q_ENUMS(Status) public: + //! Log message category + static QString getMessageCategory() { return "swift.simulator"; } //! ISimulator connection enum Status diff --git a/src/blackcore/voice.h b/src/blackcore/voice.h index 03c3f54ca..503ae0eaa 100644 --- a/src/blackcore/voice.h +++ b/src/blackcore/voice.h @@ -50,6 +50,8 @@ namespace BlackCore IVoice(QObject *parent = nullptr); public: + //! Log message category + static QString getMessageCategory() { return "swift.voice"; } //! Virtual destructor. virtual ~IVoice() {} diff --git a/src/blackcore/voice_channel.h b/src/blackcore/voice_channel.h index dd8cc918b..1f5179a72 100644 --- a/src/blackcore/voice_channel.h +++ b/src/blackcore/voice_channel.h @@ -27,6 +27,8 @@ namespace BlackCore Q_OBJECT public: + //! Log message category + static QString getMessageCategory() { return "swift.voice.channel"; } //! Com status enum ConnectionStatus diff --git a/src/blackcore/voice_channel_vatlib.cpp b/src/blackcore/voice_channel_vatlib.cpp index dd72e72da..a44121ca4 100644 --- a/src/blackcore/voice_channel_vatlib.cpp +++ b/src/blackcore/voice_channel_vatlib.cpp @@ -9,6 +9,7 @@ #include "voice_channel_vatlib.h" #include "voice_channel_vatlib_p.h" +#include "blackmisc/logmessage.h" #include @@ -139,27 +140,22 @@ namespace BlackCore catch (const NetworkNotConnectedException &e) { // this could be caused by a race condition during normal operation, so not an error - msg.append("NetworkNotConnectedException").append(" ").append(e.what()); - emit q->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qDebug() << "NetworkNotConnectedException caught in " << caller << "\n" << e.what(); + CLogMessage().debug(q) << "NetworkNotConnectedException" << e.what() << "in" << caller; } catch (const VatlibException &e) { - msg.append("VatlibException").append(" ").append(e.what()); - emit q->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("VatlibException caught in %s\n%s", caller, e.what()); + CLogMessage().error(q, "VatlibException %1 in %2") << e.what() << caller; + Q_ASSERT(false); } catch (const std::exception &e) { - msg.append("std::exception").append(" ").append(e.what()); - emit q->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("std::exception caught in %s\n%s", caller, e.what()); + CLogMessage().error(q, "std::exception %1 in %2") << e.what() << caller; + Q_ASSERT(false); } catch (...) { - msg.append("unknown exception"); - emit q->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("Unknown exception caught in %s", caller); + CLogMessage().error(q, "Unknown exception in %1") << caller; + Q_ASSERT(false); } } diff --git a/src/blackcore/voice_vatlib.cpp b/src/blackcore/voice_vatlib.cpp index c6126facf..b81f460c6 100644 --- a/src/blackcore/voice_vatlib.cpp +++ b/src/blackcore/voice_vatlib.cpp @@ -5,6 +5,7 @@ #include "voice_vatlib.h" #include "voice_channel_vatlib.h" +#include "blackmisc/logmessage.h" #include #include @@ -429,27 +430,22 @@ namespace BlackCore catch (const NetworkNotConnectedException &e) { // this could be caused by a race condition during normal operation, so not an error - msg.append("NetworkNotConnectedException").append(" ").append(e.what()); - emit this->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qDebug() << "NetworkNotConnectedException caught in " << caller << "\n" << e.what(); + CLogMessage().debug(this) << "NetworkNotConnectedException" << e.what() << "in" << caller; } catch (const VatlibException &e) { - msg.append("VatlibException").append(" ").append(e.what()); - emit this->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("VatlibException caught in %s\n%s", caller, e.what()); + CLogMessage().error(this, "VatlibException %1 in %2") << e.what() << caller; + Q_ASSERT(false); } catch (const std::exception &e) { - msg.append("std::exception").append(" ").append(e.what()); - emit this->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("std::exception caught in %s\n%s", caller, e.what()); + CLogMessage().error(this, "std::exception %1 in %2") << e.what() << caller; + Q_ASSERT(false); } catch (...) { - msg.append("unknown exception"); - emit this->statusMessage(CStatusMessage::getErrorMessage(msg, CStatusMessage::TypeAudio)); - qFatal("Unknown exception caught in %s", caller); + CLogMessage().error(this, "Unknown exception in %1") << caller; + Q_ASSERT(false); } }