mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Implemented buddy leader logic
This commit is contained in:
parent
bceafe6f2c
commit
8da0464a54
@ -36,7 +36,8 @@ DeviceSinkAPI::DeviceSinkAPI(MainWindow *mainWindow,
|
||||
m_channelWindow(channelWindow),
|
||||
m_sampleSinkSequence(0),
|
||||
m_sampleSinkPluginGUI(0),
|
||||
m_buddySharedPtr(0)
|
||||
m_buddySharedPtr(0),
|
||||
m_isBuddyLeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -464,9 +465,16 @@ void DeviceSinkAPI::clearBuddiesLists()
|
||||
{
|
||||
std::vector<DeviceSourceAPI*>::iterator itSource = m_sourceBuddies.begin();
|
||||
std::vector<DeviceSinkAPI*>::iterator itSink = m_sinkBuddies.begin();
|
||||
bool leaderElected = false;
|
||||
|
||||
for (;itSource != m_sourceBuddies.end(); ++itSource)
|
||||
{
|
||||
if (isBuddyLeader() && !leaderElected)
|
||||
{
|
||||
(*itSource)->setBuddyLeader(true);
|
||||
leaderElected = true;
|
||||
}
|
||||
|
||||
(*itSource)->removeSinkBuddy(this);
|
||||
}
|
||||
|
||||
@ -474,6 +482,12 @@ void DeviceSinkAPI::clearBuddiesLists()
|
||||
|
||||
for (;itSink != m_sinkBuddies.end(); ++itSink)
|
||||
{
|
||||
if (isBuddyLeader() && !leaderElected)
|
||||
{
|
||||
(*itSink)->setBuddyLeader(true);
|
||||
leaderElected = true;
|
||||
}
|
||||
|
||||
(*itSink)->removeSinkBuddy(this);
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
void clearBuddiesLists();
|
||||
void *getBuddySharedPtr() const { return m_buddySharedPtr; }
|
||||
void setBuddySharedPtr(void *ptr) { m_buddySharedPtr = ptr; }
|
||||
bool isBuddyLeader() const { return m_isBuddyLeader; }
|
||||
void setBuddyLeader(bool isBuddyLeader) { m_isBuddyLeader = isBuddyLeader; }
|
||||
|
||||
protected:
|
||||
struct ChannelInstanceRegistration
|
||||
@ -146,6 +148,7 @@ protected:
|
||||
std::vector<DeviceSourceAPI*> m_sourceBuddies; //!< Device source APIs referencing the same physical device
|
||||
std::vector<DeviceSinkAPI*> m_sinkBuddies; //!< Device sink APIs referencing the same physical device
|
||||
void *m_buddySharedPtr;
|
||||
bool m_isBuddyLeader;
|
||||
|
||||
friend class MainWindow;
|
||||
friend class DeviceSourceAPI;
|
||||
|
@ -36,7 +36,8 @@ DeviceSourceAPI::DeviceSourceAPI(MainWindow *mainWindow,
|
||||
m_channelWindow(channelWindow),
|
||||
m_sampleSourceSequence(0),
|
||||
m_sampleSourcePluginGUI(0),
|
||||
m_buddySharedPtr(0)
|
||||
m_buddySharedPtr(0),
|
||||
m_isBuddyLeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -461,9 +462,16 @@ void DeviceSourceAPI::clearBuddiesLists()
|
||||
{
|
||||
std::vector<DeviceSourceAPI*>::iterator itSource = m_sourceBuddies.begin();
|
||||
std::vector<DeviceSinkAPI*>::iterator itSink = m_sinkBuddies.begin();
|
||||
bool leaderElected = false;
|
||||
|
||||
for (;itSource != m_sourceBuddies.end(); ++itSource)
|
||||
{
|
||||
if (isBuddyLeader() && !leaderElected)
|
||||
{
|
||||
(*itSource)->setBuddyLeader(true);
|
||||
leaderElected = true;
|
||||
}
|
||||
|
||||
(*itSource)->removeSourceBuddy(this);
|
||||
}
|
||||
|
||||
@ -471,6 +479,12 @@ void DeviceSourceAPI::clearBuddiesLists()
|
||||
|
||||
for (;itSink != m_sinkBuddies.end(); ++itSink)
|
||||
{
|
||||
if (isBuddyLeader() && !leaderElected)
|
||||
{
|
||||
(*itSink)->setBuddyLeader(true);
|
||||
leaderElected = true;
|
||||
}
|
||||
|
||||
(*itSink)->removeSourceBuddy(this);
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,8 @@ public:
|
||||
void clearBuddiesLists();
|
||||
void *getBuddySharedPtr() const { return m_buddySharedPtr; }
|
||||
void setBuddySharedPtr(void *ptr) { m_buddySharedPtr = ptr; }
|
||||
bool isBuddyLeader() const { return m_isBuddyLeader; }
|
||||
void setBuddyLeader(bool isBuddyLeader) { m_isBuddyLeader = isBuddyLeader; }
|
||||
|
||||
protected:
|
||||
struct ChannelInstanceRegistration
|
||||
@ -147,6 +149,7 @@ protected:
|
||||
std::vector<DeviceSourceAPI*> m_sourceBuddies; //!< Device source APIs referencing the same physical device
|
||||
std::vector<DeviceSinkAPI*> m_sinkBuddies; //!< Device sink APIs referencing the same physical device
|
||||
void *m_buddySharedPtr;
|
||||
bool m_isBuddyLeader;
|
||||
|
||||
friend class MainWindow;
|
||||
friend class DeviceSinkAPI;
|
||||
|
@ -804,6 +804,8 @@ void MainWindow::on_sampleSource_confirmClicked(bool checked __attribute__((unus
|
||||
|
||||
// add to buddies list
|
||||
std::vector<DeviceUISet*>::iterator it = m_deviceUIs.begin();
|
||||
int nbOfBuddies = 0;
|
||||
|
||||
for (; it != m_deviceUIs.end(); ++it)
|
||||
{
|
||||
if (*it != deviceUI) // do not add to itself
|
||||
@ -814,6 +816,7 @@ void MainWindow::on_sampleSource_confirmClicked(bool checked __attribute__((unus
|
||||
(deviceUI->m_deviceSourceAPI->getSampleSourceSerial() == (*it)->m_deviceSourceAPI->getSampleSourceSerial()))
|
||||
{
|
||||
(*it)->m_deviceSourceAPI->addSourceBuddy(deviceUI->m_deviceSourceAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -823,11 +826,16 @@ void MainWindow::on_sampleSource_confirmClicked(bool checked __attribute__((unus
|
||||
(deviceUI->m_deviceSourceAPI->getSampleSourceSerial() == (*it)->m_deviceSinkAPI->getSampleSinkSerial()))
|
||||
{
|
||||
(*it)->m_deviceSinkAPI->addSourceBuddy(deviceUI->m_deviceSourceAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nbOfBuddies == 0) {
|
||||
deviceUI->m_deviceSourceAPI->setBuddyLeader(true);
|
||||
}
|
||||
|
||||
// constructs new GUI and input object
|
||||
QWidget *gui;
|
||||
PluginManager::SamplingDevice *sampleSourceDevice = (PluginManager::SamplingDevice *) devicePtr;
|
||||
@ -866,6 +874,8 @@ void MainWindow::on_sampleSink_confirmClicked(bool checked __attribute__((unused
|
||||
|
||||
// add to buddies list
|
||||
std::vector<DeviceUISet*>::iterator it = m_deviceUIs.begin();
|
||||
int nbOfBuddies = 0;
|
||||
|
||||
for (; it != m_deviceUIs.end(); ++it)
|
||||
{
|
||||
if (*it != deviceUI) // do not add to itself
|
||||
@ -876,6 +886,7 @@ void MainWindow::on_sampleSink_confirmClicked(bool checked __attribute__((unused
|
||||
(deviceUI->m_deviceSinkAPI->getSampleSinkSerial() == (*it)->m_deviceSourceAPI->getSampleSourceSerial()))
|
||||
{
|
||||
(*it)->m_deviceSourceAPI->addSinkBuddy(deviceUI->m_deviceSinkAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -885,11 +896,16 @@ void MainWindow::on_sampleSink_confirmClicked(bool checked __attribute__((unused
|
||||
(deviceUI->m_deviceSinkAPI->getSampleSinkSerial() == (*it)->m_deviceSinkAPI->getSampleSinkSerial()))
|
||||
{
|
||||
(*it)->m_deviceSinkAPI->addSinkBuddy(deviceUI->m_deviceSinkAPI);
|
||||
nbOfBuddies++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nbOfBuddies == 0) {
|
||||
deviceUI->m_deviceSinkAPI->setBuddyLeader(true);
|
||||
}
|
||||
|
||||
// constructs new GUI and output object
|
||||
QWidget *gui;
|
||||
PluginManager::SamplingDevice *sampleSinkDevice = (PluginManager::SamplingDevice *) devicePtr;
|
||||
|
Loading…
Reference in New Issue
Block a user