mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 21:20:31 -05:00 
			
		
		
		
	Merge pull request #1998 from mxi-box/buddy_bugfix
Fix not remove source buddy
This commit is contained in:
		
						commit
						480241fa8e
					
				@ -29,6 +29,7 @@
 | 
			
		||||
#include "util/simpleserializer.h"
 | 
			
		||||
 | 
			
		||||
#include "deviceapi.h"
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
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<DeviceAPI*>::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<DeviceAPI*>::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();
 | 
			
		||||
 | 
			
		||||
@ -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; }
 | 
			
		||||
 | 
			
		||||
@ -481,27 +481,14 @@ void MainWindow::sampleSourceCreate(
 | 
			
		||||
    for (; it != m_deviceUIs.end(); ++it)
 | 
			
		||||
    {
 | 
			
		||||
        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()))
 | 
			
		||||
            {
 | 
			
		||||
                    (*it)->m_deviceAPI->addSourceBuddy(deviceUISet->m_deviceAPI);
 | 
			
		||||
                (*it)->m_deviceAPI->addBuddy(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++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (nbOfBuddies == 0) {
 | 
			
		||||
@ -712,27 +699,14 @@ void MainWindow::sampleSinkCreate(
 | 
			
		||||
    for (; it != m_deviceUIs.end(); ++it)
 | 
			
		||||
    {
 | 
			
		||||
        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()))
 | 
			
		||||
            {
 | 
			
		||||
                    (*it)->m_deviceAPI->addSinkBuddy(deviceAPI);
 | 
			
		||||
                (*it)->m_deviceAPI->addBuddy(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++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (nbOfBuddies == 0) {
 | 
			
		||||
 | 
			
		||||
@ -500,27 +500,14 @@ void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
 | 
			
		||||
        for (; it != m_mainCore->m_deviceSets.end(); ++it)
 | 
			
		||||
        {
 | 
			
		||||
            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()))
 | 
			
		||||
                {
 | 
			
		||||
                        (*it)->m_deviceAPI->addSourceBuddy(deviceSet->m_deviceAPI);
 | 
			
		||||
                    (*it)->m_deviceAPI->addBuddy(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++;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (nbOfBuddies == 0) {
 | 
			
		||||
@ -586,27 +573,14 @@ void MainServer::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex)
 | 
			
		||||
        for (; it != m_mainCore->m_deviceSets.end(); ++it)
 | 
			
		||||
        {
 | 
			
		||||
            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()))
 | 
			
		||||
                {
 | 
			
		||||
                        (*it)->m_deviceAPI->addSinkBuddy(deviceSet->m_deviceAPI);
 | 
			
		||||
                    (*it)->m_deviceAPI->addBuddy(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++;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (nbOfBuddies == 0) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user