From aeafe51220f1a82072b1a7d25073cf600e15a6be Mon Sep 17 00:00:00 2001 From: mxi-box Date: Tue, 27 Feb 2024 07:13:09 +0800 Subject: [PATCH] Fix not remove source buddy --- sdrbase/device/deviceapi.cpp | 124 ++++++++--------------------------- sdrbase/device/deviceapi.h | 6 +- sdrgui/mainwindow.cpp | 42 +++--------- sdrsrv/mainserver.cpp | 42 +++--------- 4 files changed, 44 insertions(+), 170 deletions(-) diff --git a/sdrbase/device/deviceapi.cpp b/sdrbase/device/deviceapi.cpp index 203ef8663..65bd30529 100644 --- a/sdrbase/device/deviceapi.cpp +++ b/sdrbase/device/deviceapi.cpp @@ -29,6 +29,7 @@ #include "util/simpleserializer.h" #include "deviceapi.h" +#include DeviceAPI::DeviceAPI( StreamType streamType, @@ -738,28 +739,32 @@ void DeviceAPI::saveSamplingDeviceSettings(Preset* preset) } } -void DeviceAPI::addSourceBuddy(DeviceAPI* buddy) +void DeviceAPI::addBuddy(DeviceAPI* buddy) { - if (buddy->m_streamType != StreamSingleRx) + if (buddy->m_streamType == StreamSingleRx) { - qDebug("DeviceAPI::addSourceBuddy: buddy %s(%s) is not of single Rx type", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial())); + m_sourceBuddies.push_back(buddy); // this is a source + } + else if (buddy->m_streamType == StreamSingleTx) + { + m_sinkBuddies.push_back(buddy); // this is a sink + } + else + { + qDebug("DeviceAPI::addBuddy: not relevant if buddy is not a single Rx or Tx"); return; } - m_sourceBuddies.push_back(buddy); - if (m_streamType == StreamSingleRx) { buddy->m_sourceBuddies.push_back(this); // this is a source } else if (m_streamType == StreamSingleTx) { buddy->m_sinkBuddies.push_back(this); // this is a sink } else { - qDebug("DeviceAPI::addSourceBuddy: not relevant if this is not a single Rx or Tx"); + qDebug("DeviceAPI::addBuddy: not relevant if this is not a single Rx or Tx"); return; } - qDebug("DeviceAPI::addSourceBuddy: added buddy %s(%s) [%llu] <-> [%llu]", + qDebug("DeviceAPI::addBuddy: added buddy %s(%s) [%llu] <-> [%llu]", qPrintable(buddy->getHardwareId()), qPrintable(buddy->getSamplingDeviceSerial()), (quint64) buddy, @@ -767,98 +772,21 @@ void DeviceAPI::addSourceBuddy(DeviceAPI* buddy) } -void DeviceAPI::addSinkBuddy(DeviceAPI* buddy) +void DeviceAPI::removeBuddy(DeviceAPI* buddy) { - if (buddy->m_streamType != StreamSingleTx) - { - qDebug("DeviceAPI::addSinkBuddy: buddy %s(%s) is not of single Tx type", + switch(buddy->m_streamType) { + case StreamSingleRx: + m_sourceBuddies.erase(std::find(m_sourceBuddies.begin(), m_sourceBuddies.end(), buddy)); + break; + case StreamSingleTx: + m_sinkBuddies.erase(std::find(m_sinkBuddies.begin(), m_sinkBuddies.end(), buddy)); + break; + default: + qDebug("DeviceAPI::removeSourceBuddy: buddy %s(%s) is not of single Rx or Tx type", qPrintable(buddy->getHardwareId()), qPrintable(buddy->getSamplingDeviceSerial())); return; } - - m_sinkBuddies.push_back(buddy); - - if (m_streamType == StreamSingleRx) { - buddy->m_sourceBuddies.push_back(this); // this is a source - } else if (m_streamType == StreamSingleTx) { - buddy->m_sinkBuddies.push_back(this); // this is a sink - } else { - qDebug("DeviceAPI::addSinkBuddy: not relevant if this is not a single Rx or Tx"); - return; - } - - qDebug("DeviceAPI::addSinkBuddy: added buddy %s(%s) [%llu] <-> [%llu]", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial()), - (quint64) buddy, - (quint64) this); -} - -void DeviceAPI::removeSourceBuddy(DeviceAPI* buddy) -{ - if (buddy->m_streamType != StreamSingleRx) - { - qDebug("DeviceAPI::removeSourceBuddy: buddy %s(%s) is not of single Rx type", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial())); - return; - } - - std::vector::iterator it = m_sourceBuddies.begin(); - - for (;it != m_sourceBuddies.end(); ++it) - { - if (*it == buddy) - { - qDebug("DeviceAPI::removeSourceBuddy: buddy %s(%s) [%llu] removed from the list of [%llu]", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial()), - (quint64) (*it), - (quint64) this); - m_sourceBuddies.erase(it); - return; - } - } - - qDebug("DeviceAPI::removeSourceBuddy: buddy %s(%s) [%llu] not found in the list of [%llu]", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial()), - (quint64) buddy, - (quint64) this); -} - -void DeviceAPI::removeSinkBuddy(DeviceAPI* buddy) -{ - if (buddy->m_streamType != StreamSingleTx) - { - qDebug("DeviceAPI::removeSinkBuddy: buddy %s(%s) is not of single Tx type", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial())); - return; - } - - std::vector::iterator it = m_sinkBuddies.begin(); - - for (;it != m_sinkBuddies.end(); ++it) - { - if (*it == buddy) - { - qDebug("DeviceAPI::removeSinkBuddy: buddy %s(%s) [%llu] removed from the list of [%llu]", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial()), - (quint64) (*it), - (quint64) this); - m_sinkBuddies.erase(it); - return; - } - } - - qDebug("DeviceAPI::removeSourceBuddy: buddy %s(%s) [%llu] not found in the list of [%llu]", - qPrintable(buddy->getHardwareId()), - qPrintable(buddy->getSamplingDeviceSerial()), - (quint64) buddy, - (quint64) this); } void DeviceAPI::clearBuddiesLists() @@ -875,7 +803,7 @@ void DeviceAPI::clearBuddiesLists() leaderElected = true; } - (*itSource)->removeSinkBuddy(this); + (*itSource)->removeBuddy(this); } m_sourceBuddies.clear(); @@ -888,7 +816,7 @@ void DeviceAPI::clearBuddiesLists() leaderElected = true; } - (*itSink)->removeSinkBuddy(this); + (*itSink)->removeBuddy(this); } m_sinkBuddies.clear(); diff --git a/sdrbase/device/deviceapi.h b/sdrbase/device/deviceapi.h index 302b486ce..26d21eaaf 100644 --- a/sdrbase/device/deviceapi.h +++ b/sdrbase/device/deviceapi.h @@ -159,10 +159,8 @@ public: DSPDeviceSinkEngine *getDeviceSinkEngine() { return m_deviceSinkEngine; } DSPDeviceMIMOEngine *getDeviceMIMOEngine() { return m_deviceMIMOEngine; } - void addSourceBuddy(DeviceAPI* buddy); - void addSinkBuddy(DeviceAPI* buddy); - void removeSourceBuddy(DeviceAPI* buddy); - void removeSinkBuddy(DeviceAPI* buddy); + void addBuddy(DeviceAPI* buddy); + void removeBuddy(DeviceAPI* buddy); void clearBuddiesLists(); void *getBuddySharedPtr() const { return m_buddySharedPtr; } void setBuddySharedPtr(void *ptr) { m_buddySharedPtr = ptr; } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 75fdce20f..5eff075c6 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -482,24 +482,11 @@ void MainWindow::sampleSourceCreate( { if (*it != deviceUISet) // do not add to itself { - if ((*it)->m_deviceSourceEngine) // it is a source device + if ((deviceUISet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceUISet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceUISet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceUISet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSourceBuddy(deviceUISet->m_deviceAPI); - nbOfBuddies++; - } - } - - if ((*it)->m_deviceSinkEngine) // it is a sink device - { - if ((deviceUISet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceUISet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSourceBuddy(deviceUISet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceUISet->m_deviceAPI); + nbOfBuddies++; } } } @@ -713,24 +700,11 @@ void MainWindow::sampleSinkCreate( { if (*it != deviceUISet) // do not add to itself { - if ((*it)->m_deviceSourceEngine) // it is a source device + if ((deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSinkBuddy(deviceAPI); - nbOfBuddies++; - } - } - - if ((*it)->m_deviceSinkEngine) // it is a sink device - { - if ((deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSinkBuddy(deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceAPI); + nbOfBuddies++; } } } diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index 69d912e67..0e79081e1 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -501,24 +501,11 @@ void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex) { if (*it != deviceSet) // do not add to itself { - if ((*it)->m_deviceSourceEngine) // it is a source device + if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSourceBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } - } - - if ((*it)->m_deviceSinkEngine) // it is a sink device - { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSourceBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); + nbOfBuddies++; } } } @@ -587,24 +574,11 @@ void MainServer::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex) { if (*it != deviceSet) // do not add to itself { - if ((*it)->m_deviceSourceEngine) // it is a source device + if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && + (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSinkBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } - } - - if ((*it)->m_deviceSinkEngine) // it is a sink device - { - if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) && - (deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial())) - { - (*it)->m_deviceAPI->addSinkBuddy(deviceSet->m_deviceAPI); - nbOfBuddies++; - } + (*it)->m_deviceAPI->addBuddy(deviceSet->m_deviceAPI); + nbOfBuddies++; } } }