diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index b37efa118..fb6403631 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -183,6 +183,7 @@ namespace BlackCore connect(m_voiceClient, &CAfvClient::startedAudio, this, &CContextAudioBase::startedAudio, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::stoppedAudio, this, &CContextAudioBase::stoppedAudio, Qt::QueuedConnection); connect(m_voiceClient, &CAfvClient::ptt, this, &CContextAudioBase::ptt, Qt::QueuedConnection); + connect(m_voiceClient, &CAfvClient::connectionStatusChanged, this, &CContextAudioBase::onAfvConnectionStatusChanged, Qt::QueuedConnection); const CAudioDeviceInfoList devices = CAudioDeviceInfoList::allDevices(); if (devices != m_activeLocalDevices) @@ -261,8 +262,16 @@ namespace BlackCore const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser(); const QString client = "swift " % BlackConfig::CBuildConfig::getShortVersionString(); - m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString(), client); - + CCallsign cs = connectedUser.getCallsign(); + this->unRegisterAudioCallsign(cs, this->identifier()); // un-register "myself" + if (this->hasRegisteredAudioCallsign(cs)) // anybody else using that callsign + { + //! \todo KB 2019-11 would need a better algorithm to really find a cs + cs = CCallsign(cs.asString() + "2"); + } + CLogMessage(this).info(u"About to connect to voice as '%1' '%2'") << connectedUser.getId() << cs; + m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), cs.asString(), client); + this->registerAudioCallsign(cs, this->identifier()); // login can still fail, but we "block" this callsign return true; } @@ -552,6 +561,24 @@ namespace BlackCore m_voiceClient->disconnectFrom(); } } + + void CContextAudioBase::onAfvConnectionStatusChanged(int status) + { + if (!m_voiceClient) { return; } + + const CCallsign cs = m_voiceClient->getCallsign(); + const CAfvClient::ConnectionStatus s = static_cast(status); + + switch (s) + { + case CAfvClient::Connected: + this->registerAudioCallsign(cs, this->identifier()); + break; + case CAfvClient::Disconnected: + this->unRegisterAudioCallsign(cs, this->identifier()); + break; + } + } } // ns } // ns diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index c8092bd08..202d3369c 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -100,6 +100,18 @@ namespace BlackCore //! Remove all devices for identifer (i.e. "a machine") virtual void unRegisterDevicesFor(const BlackMisc::CIdentifier &identifier) = 0; + //! Register an audio callsign (used with AFV) + //! \remarks normally called with login + virtual void registerAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) = 0; + + //! Un-register an audio callsign (used with AFV) + //! \remarks normally called with logoff + virtual void unRegisterAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) = 0; + + //! Un-register an audio callsign (used with AFV) + //! \remarks normally called with logoff + virtual bool hasRegisteredAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + // ------------- DBus --------------- protected: @@ -304,6 +316,9 @@ namespace BlackCore //! Network connection status void xCtxNetworkConnectionStatusChanged(const BlackMisc::Network::CConnectionStatus &from, const BlackMisc::Network::CConnectionStatus &to); + //! AFV client connection status changed + void onAfvConnectionStatusChanged(int status); + CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionComActive }; CActionBind m_actionPttCom1 { BlackMisc::Input::pttCom1HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionCom1 }; CActionBind m_actionPttCom2 { BlackMisc::Input::pttCom2HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionCom2 }; diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 288f530cc..87db49a8e 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -16,6 +16,7 @@ using namespace BlackMisc; using namespace BlackMisc::Audio; +using namespace BlackMisc::Aviation; using namespace BlackCore::Afv::Clients; namespace BlackCore @@ -53,6 +54,26 @@ namespace BlackCore m_registeredDevices.unRegisterDevices(identifier); } + void CContextAudio::registerAudioCallsign(const CCallsign &callsign, const CIdentifier &identifier) + { + m_registeredCallsigns.insert(identifier, callsign); + } + + void CContextAudio::unRegisterAudioCallsign(const CCallsign &callsign, const CIdentifier &identifier) + { + m_registeredCallsigns.remove(identifier); + Q_UNUSED(callsign) + } + + bool CContextAudio::hasRegisteredAudioCallsign(const CCallsign &callsign) const + { + for (const CCallsign &cs : m_registeredCallsigns.values()) + { + if (callsign == cs) { return true; } + } + return false; + } + CAudioDeviceInfoList CContextAudio::getRegisteredDevices() const { return m_registeredDevices; diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 6861b8b3f..2874158e6 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -17,6 +17,7 @@ #include "blackmisc/network/userlist.h" #include +#include #include #include #include @@ -45,9 +46,12 @@ namespace BlackCore //! \publicsection //! @{ virtual BlackMisc::Audio::CAudioDeviceInfoList getRegisteredDevices() const override; - virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override; + virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override; virtual void unRegisterDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override; virtual void unRegisterDevicesFor(const BlackMisc::CIdentifier &identifier) override; + virtual void registerAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) override; + virtual void unRegisterAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) override; + virtual bool hasRegisteredAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; //! @} protected: @@ -59,6 +63,7 @@ namespace BlackCore private: BlackMisc::Audio::CAudioDeviceInfoList m_registeredDevices; + QMap m_registeredCallsigns; }; } // namespace } // namespace diff --git a/src/blackcore/context/contextaudioproxy.cpp b/src/blackcore/context/contextaudioproxy.cpp index ce6aba180..c5af48d45 100644 --- a/src/blackcore/context/contextaudioproxy.cpp +++ b/src/blackcore/context/contextaudioproxy.cpp @@ -61,6 +61,21 @@ namespace BlackCore m_dBusInterface->callDBus(QLatin1String("unRegisterDevicesFor"), identifier); } + void CContextAudioProxy::registerAudioCallsign(const CCallsign &callsign, const CIdentifier &identifier) + { + m_dBusInterface->callDBus(QLatin1String("registerAudioCallsign"), callsign, identifier); + } + + void CContextAudioProxy::unRegisterAudioCallsign(const CCallsign &callsign, const CIdentifier &identifier) + { + m_dBusInterface->callDBus(QLatin1String("unRegisterAudioCallsign"), callsign, identifier); + } + + bool CContextAudioProxy::hasRegisteredAudioCallsign(const CCallsign &callsign) const + { + return m_dBusInterface->callDBusRet(QLatin1String("hasRegisteredAudioCallsign"), callsign); + } + CAudioDeviceInfoList CContextAudioProxy::getRegisteredDevices() const { return m_dBusInterface->callDBusRet(QLatin1String("getRegisteredDevices")); diff --git a/src/blackcore/context/contextaudioproxy.h b/src/blackcore/context/contextaudioproxy.h index 53c32942f..a94333bd7 100644 --- a/src/blackcore/context/contextaudioproxy.h +++ b/src/blackcore/context/contextaudioproxy.h @@ -66,6 +66,9 @@ namespace BlackCore virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override; virtual void unRegisterDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override; virtual void unRegisterDevicesFor(const BlackMisc::CIdentifier &identifier) override; + virtual void registerAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) override; + virtual void unRegisterAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CIdentifier &identifier) override; + virtual bool hasRegisteredAudioCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; //! @} private: