From ee4d498733937ff6f06dfcd0b301b6c9e2d3ca28 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 13 Mar 2019 17:29:10 +0100 Subject: [PATCH] Ref T565, "canTalk" function in audio context --- src/blackcore/context/contextaudio.h | 3 ++ src/blackcore/context/contextaudioempty.h | 11 +++++-- src/blackcore/context/contextaudioimpl.cpp | 36 +++++++++++++++------ src/blackcore/context/contextaudioimpl.h | 1 + src/blackcore/context/contextaudioproxy.cpp | 5 +++ src/blackcore/context/contextaudioproxy.h | 1 + 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index f3de1e8b0..32d70b36c 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -112,6 +112,9 @@ namespace BlackCore //! Get voice rooms for COM1, COM2: virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const = 0; + //! Can talk in any voice room + virtual bool canTalk() const = 0; + //! Get voice rooms for COM1, COM2, but without latest audio status virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const = 0; diff --git a/src/blackcore/context/contextaudioempty.h b/src/blackcore/context/contextaudioempty.h index b3b021b99..49833d54d 100644 --- a/src/blackcore/context/contextaudioempty.h +++ b/src/blackcore/context/contextaudioempty.h @@ -32,20 +32,27 @@ namespace BlackCore CContextAudioEmpty(CCoreFacade *runtime) : IContextAudio(CCoreFacadeConfig::NotUsed, runtime) {} public slots: - //! \copydoc IContextAudio::getComVoiceRooms() + //! \copydoc IContextAudio::getComVoiceRooms virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override { logEmptyContextWarning(Q_FUNC_INFO); return BlackMisc::Audio::CVoiceRoomList(); } - //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() + //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override { logEmptyContextWarning(Q_FUNC_INFO); return BlackMisc::Audio::CVoiceRoomList(); } + //! \copydoc IContextAudio::canTalk + virtual bool canTalk() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + //! \copydoc IContextAudio::getVoiceRoom virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override { diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 0920caac9..fa9a3e27d 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -127,7 +127,7 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } CVoiceRoomList voiceRoomList; - QSharedPointer voiceChannelCom1 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com1); + QSharedPointer voiceChannelCom1 = m_voiceChannelMapping.value(CComSystem::Com1); if (voiceChannelCom1) { CVoiceRoom room = voiceChannelCom1->getVoiceRoom(); @@ -138,7 +138,7 @@ namespace BlackCore voiceRoomList.push_back(CVoiceRoom()); } - QSharedPointer voiceChannelCom2 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com2); + QSharedPointer voiceChannelCom2 = m_voiceChannelMapping.value(CComSystem::Com2); if (voiceChannelCom2) { CVoiceRoom room = voiceChannelCom2->getVoiceRoom(); @@ -152,6 +152,12 @@ namespace BlackCore return voiceRoomList; } + bool CContextAudio::canTalk() const + { + const CVoiceRoomList rooms = this->getComVoiceRoomsWithAudioStatus(); + return rooms.countCanTalkTo() > 0; + } + void CContextAudio::leaveAllVoiceRooms() { Q_ASSERT(m_voice); @@ -295,9 +301,9 @@ namespace BlackCore Q_ASSERT(getIContextOwnAircraft()); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << newRooms; } - CVoiceRoomList currentRooms = this->getComVoiceRooms(); - CVoiceRoom currentRoomCom1 = currentRooms[0]; - CVoiceRoom currentRoomCom2 = currentRooms[1]; + const CVoiceRoomList currentRooms = this->getComVoiceRooms(); + const CVoiceRoom currentRoomCom1 = currentRooms[0]; + const CVoiceRoom currentRoomCom2 = currentRooms[1]; CVoiceRoom newRoomCom1 = newRooms[0]; CVoiceRoom newRoomCom2 = newRooms[1]; const CCallsign ownCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); @@ -372,7 +378,7 @@ namespace BlackCore newVoiceChannel->setOwnAircraftCallsign(ownCallsign); newVoiceChannel->setUserId(id); bool inUse = m_voiceChannelMapping.values().contains(newVoiceChannel); - m_voiceChannelMapping.insert(BlackMisc::Aviation::CComSystem::Com2, newVoiceChannel); + m_voiceChannelMapping.insert(CComSystem::Com2, newVoiceChannel); // If the voice channel is not used by anybody else if (!inUse) @@ -392,7 +398,7 @@ namespace BlackCore Q_UNUSED(changed); } - CCallsignSet CContextAudio::getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const + CCallsignSet CContextAudio::getRoomCallsigns(CComSystem::ComUnit comUnitValue) const { Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } @@ -401,7 +407,7 @@ namespace BlackCore return voiceChannel ? voiceChannel->getVoiceRoomCallsigns() : CCallsignSet(); } - Network::CUserList CContextAudio::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const + Network::CUserList CContextAudio::getRoomUsers(CComSystem::ComUnit comUnit) const { Q_ASSERT(m_voice); Q_ASSERT(this->getRuntime()); @@ -434,8 +440,18 @@ namespace BlackCore Q_ASSERT(m_voice); if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; } - const bool play = !considerSettings || m_audioSettings.getThreadLocal().isNotificationFlagSet(notification); - if (play) { CSoundGenerator::playNotificationSound(90, notification); } + const CSettings settings = m_audioSettings.getThreadLocal(); + const bool play = !considerSettings || settings.isNotificationFlagSet(notification); + if (!play) { return; } + if (notification == CNotificationSounds::PTTClick && (considerSettings && settings.noAudioTransmission())) + { + if (!this->canTalk()) + { + // warning sound + notification = CNotificationSounds::NotificationNoAudioTransmission; + } + } + CSoundGenerator::playNotificationSound(90, notification); } void CContextAudio::initNotificationSounds() diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 7aa296e60..1b90fe4b8 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -77,6 +77,7 @@ namespace BlackCore //! @{ virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; + virtual bool canTalk() const override; virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &newRooms) override; virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; diff --git a/src/blackcore/context/contextaudioproxy.cpp b/src/blackcore/context/contextaudioproxy.cpp index 60e1ba1e5..b28ad463a 100644 --- a/src/blackcore/context/contextaudioproxy.cpp +++ b/src/blackcore/context/contextaudioproxy.cpp @@ -105,6 +105,11 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1String("getComVoiceRoomsWithAudioStatus")); } + bool CContextAudioProxy::canTalk() const + { + return this->m_dBusInterface->callDBusRet(QLatin1String("canTalk")); + } + CVoiceRoomList CContextAudioProxy::getComVoiceRooms() const { return this->m_dBusInterface->callDBusRet(QLatin1String("getComVoiceRooms")); diff --git a/src/blackcore/context/contextaudioproxy.h b/src/blackcore/context/contextaudioproxy.h index c82cc9f95..496b39dfe 100644 --- a/src/blackcore/context/contextaudioproxy.h +++ b/src/blackcore/context/contextaudioproxy.h @@ -65,6 +65,7 @@ namespace BlackCore //! @{ virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; + virtual bool canTalk() const override; virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) override; virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override;