2016-10-17 22:03:51 +00:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
2017-09-03 17:55:00 +00:00
# include <plugin/plugininstanceui.h>
2016-10-17 22:03:51 +00:00
# include "device/devicesinkapi.h"
2016-12-29 11:41:10 +00:00
# include "device/devicesourceapi.h"
2016-10-17 22:03:51 +00:00
# include "plugin/pluginapi.h"
# include "plugin/plugininterface.h"
# include "gui/glspectrum.h"
# include "gui/channelwindow.h"
# include "mainwindow.h"
# include "settings/preset.h"
DeviceSinkAPI : : DeviceSinkAPI ( MainWindow * mainWindow ,
int deviceTabIndex ,
DSPDeviceSinkEngine * deviceSinkEngine ,
GLSpectrum * glSpectrum ,
ChannelWindow * channelWindow ) :
m_mainWindow ( mainWindow ) ,
m_deviceTabIndex ( deviceTabIndex ) ,
m_deviceSinkEngine ( deviceSinkEngine ) ,
m_spectrum ( glSpectrum ) ,
m_channelWindow ( channelWindow ) ,
m_sampleSinkSequence ( 0 ) ,
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI ( 0 ) ,
2017-07-03 06:59:48 +00:00
m_buddySharedPtr ( 0 ) ,
m_isBuddyLeader ( false )
2016-10-17 22:03:51 +00:00
{
}
DeviceSinkAPI : : ~ DeviceSinkAPI ( )
{
}
2016-10-24 16:06:44 +00:00
void DeviceSinkAPI : : addSpectrumSink ( BasebandSampleSink * spectrumSink )
2016-10-17 22:03:51 +00:00
{
2016-10-24 16:06:44 +00:00
m_deviceSinkEngine - > addSpectrumSink ( spectrumSink ) ;
2016-10-17 22:03:51 +00:00
}
2016-10-24 16:06:44 +00:00
void DeviceSinkAPI : : removeSpectrumSink ( BasebandSampleSink * spectrumSink )
2016-10-17 22:03:51 +00:00
{
2016-10-24 16:06:44 +00:00
m_deviceSinkEngine - > removeSpectrumSink ( spectrumSink ) ;
2016-10-17 22:03:51 +00:00
}
void DeviceSinkAPI : : addSource ( BasebandSampleSource * source )
{
m_deviceSinkEngine - > addSource ( source ) ;
}
void DeviceSinkAPI : : removeSource ( BasebandSampleSource * source )
{
m_deviceSinkEngine - > removeSource ( source ) ;
}
void DeviceSinkAPI : : addThreadedSource ( ThreadedBasebandSampleSource * source )
{
m_deviceSinkEngine - > addThreadedSource ( source ) ;
}
void DeviceSinkAPI : : removeThreadedSource ( ThreadedBasebandSampleSource * source )
{
m_deviceSinkEngine - > removeThreadedSource ( source ) ;
}
2016-12-26 14:26:25 +00:00
uint32_t DeviceSinkAPI : : getNumberOfSources ( )
{
return m_deviceSinkEngine - > getNumberOfSources ( ) ;
}
2016-10-17 22:03:51 +00:00
void DeviceSinkAPI : : setSink ( DeviceSampleSink * sink )
{
m_deviceSinkEngine - > setSink ( sink ) ;
}
bool DeviceSinkAPI : : initGeneration ( )
{
return m_deviceSinkEngine - > initGeneration ( ) ;
}
bool DeviceSinkAPI : : startGeneration ( )
{
return m_deviceSinkEngine - > startGeneration ( ) ;
}
void DeviceSinkAPI : : stopGeneration ( )
{
m_deviceSinkEngine - > stopGeneration ( ) ;
}
DSPDeviceSinkEngine : : State DeviceSinkAPI : : state ( ) const
{
return m_deviceSinkEngine - > state ( ) ;
}
QString DeviceSinkAPI : : errorMessage ( )
{
return m_deviceSinkEngine - > errorMessage ( ) ;
}
uint DeviceSinkAPI : : getDeviceUID ( ) const
{
return m_deviceSinkEngine - > getUID ( ) ;
}
MessageQueue * DeviceSinkAPI : : getDeviceInputMessageQueue ( )
{
return m_deviceSinkEngine - > getInputMessageQueue ( ) ;
}
MessageQueue * DeviceSinkAPI : : getDeviceOutputMessageQueue ( )
{
return m_deviceSinkEngine - > getOutputMessageQueue ( ) ;
}
GLSpectrum * DeviceSinkAPI : : getSpectrum ( )
{
return m_spectrum ;
}
void DeviceSinkAPI : : addChannelMarker ( ChannelMarker * channelMarker )
{
m_spectrum - > addChannelMarker ( channelMarker ) ;
}
ChannelWindow * DeviceSinkAPI : : getChannelWindow ( )
{
return m_channelWindow ;
}
void DeviceSinkAPI : : addRollupWidget ( QWidget * widget )
{
m_channelWindow - > addRollupWidget ( widget ) ;
}
void DeviceSinkAPI : : setOutputGUI ( QWidget * outputGUI , const QString & sinkDisplayName )
{
m_mainWindow - > setDeviceGUI ( m_deviceTabIndex , outputGUI , sinkDisplayName , false ) ;
}
2016-12-29 11:41:10 +00:00
void DeviceSinkAPI : : setHardwareId ( const QString & id )
{
m_hardwareId = id ;
}
2016-10-17 22:03:51 +00:00
void DeviceSinkAPI : : setSampleSinkId ( const QString & id )
{
m_sampleSinkId = id ;
}
void DeviceSinkAPI : : setSampleSinkSerial ( const QString & serial )
{
m_sampleSinkSerial = serial ;
}
void DeviceSinkAPI : : setSampleSinkSequence ( int sequence )
{
m_sampleSinkSequence = sequence ;
m_deviceSinkEngine - > setSinkSequence ( sequence ) ;
}
2017-09-03 18:24:17 +00:00
void DeviceSinkAPI : : setSampleSinkPluginInstanceUI ( PluginInstanceUI * gui )
2016-10-17 22:03:51 +00:00
{
2017-09-03 18:24:17 +00:00
if ( m_sampleSinkPluginInstanceUI ! = 0 )
2016-10-17 22:03:51 +00:00
{
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI - > destroy ( ) ;
2016-10-17 22:03:51 +00:00
m_sampleSinkId . clear ( ) ;
}
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI = gui ;
2016-10-17 22:03:51 +00:00
}
2017-09-03 17:55:00 +00:00
void DeviceSinkAPI : : registerChannelInstance ( const QString & channelName , PluginInstanceUI * pluginGUI )
2016-10-17 22:03:51 +00:00
{
m_channelInstanceRegistrations . append ( ChannelInstanceRegistration ( channelName , pluginGUI ) ) ;
renameChannelInstances ( ) ;
}
2017-09-03 17:55:00 +00:00
void DeviceSinkAPI : : removeChannelInstance ( PluginInstanceUI * pluginGUI )
2016-10-17 22:03:51 +00:00
{
for ( ChannelInstanceRegistrations : : iterator it = m_channelInstanceRegistrations . begin ( ) ; it ! = m_channelInstanceRegistrations . end ( ) ; + + it )
{
if ( it - > m_gui = = pluginGUI )
{
m_channelInstanceRegistrations . erase ( it ) ;
break ;
}
}
renameChannelInstances ( ) ;
}
void DeviceSinkAPI : : renameChannelInstances ( )
{
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
m_channelInstanceRegistrations [ i ] . m_gui - > setName ( QString ( " %1:%2 " ) . arg ( m_channelInstanceRegistrations [ i ] . m_channelName ) . arg ( i ) ) ;
}
}
void DeviceSinkAPI : : freeAll ( )
{
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
qDebug ( " DeviceSinkAPI::freeAll: destroying channel [%s] " , qPrintable ( m_channelInstanceRegistrations [ i ] . m_channelName ) ) ;
m_channelInstanceRegistrations [ i ] . m_gui - > destroy ( ) ;
}
2017-09-03 18:24:17 +00:00
if ( m_sampleSinkPluginInstanceUI ! = 0 )
2016-10-17 22:03:51 +00:00
{
qDebug ( " DeviceSinkAPI::freeAll: destroying m_sampleSourcePluginGUI " ) ;
m_deviceSinkEngine - > setSink ( 0 ) ;
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI - > destroy ( ) ;
m_sampleSinkPluginInstanceUI = 0 ;
2016-10-17 22:03:51 +00:00
m_sampleSinkId . clear ( ) ;
}
}
void DeviceSinkAPI : : loadSinkSettings ( const Preset * preset )
{
2016-10-18 22:07:42 +00:00
if ( preset - > isSourcePreset ( ) )
2016-10-17 22:03:51 +00:00
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadSinkSettings: Preset [%s | %s] is not a sink preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2016-10-18 22:07:42 +00:00
}
else
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadSinkSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2016-10-17 22:03:51 +00:00
2017-09-03 18:24:17 +00:00
if ( m_sampleSinkPluginInstanceUI ! = 0 )
2016-10-17 22:03:51 +00:00
{
2016-10-18 22:07:42 +00:00
const QByteArray * sourceConfig = preset - > findBestDeviceConfig ( m_sampleSinkId , m_sampleSinkSerial , m_sampleSinkSequence ) ;
2016-10-17 22:03:51 +00:00
2016-10-18 22:07:42 +00:00
if ( sourceConfig ! = 0 )
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadSinkSettings: deserializing sink: %s " , qPrintable ( m_sampleSinkId ) ) ;
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI - > deserialize ( * sourceConfig ) ;
2016-10-18 22:07:42 +00:00
}
qint64 centerFrequency = preset - > getCenterFrequency ( ) ;
2017-09-03 18:24:17 +00:00
m_sampleSinkPluginInstanceUI - > setCenterFrequency ( centerFrequency ) ;
2016-10-18 22:07:42 +00:00
}
2016-10-17 22:03:51 +00:00
}
}
void DeviceSinkAPI : : saveSinkSettings ( Preset * preset )
{
2016-10-18 22:07:42 +00:00
if ( preset - > isSourcePreset ( ) )
2016-10-17 22:03:51 +00:00
{
2016-10-18 22:07:42 +00:00
qDebug ( " DeviceSinkAPI::saveSinkSettings: not a sink preset " ) ;
}
else
{
2017-09-03 18:24:17 +00:00
if ( m_sampleSinkPluginInstanceUI ! = NULL )
2016-10-18 22:07:42 +00:00
{
2017-09-03 18:24:17 +00:00
qDebug ( " DeviceSinkAPI::saveSourceSettings: %s saved " , qPrintable ( m_sampleSinkPluginInstanceUI - > getName ( ) ) ) ;
preset - > addOrUpdateDeviceConfig ( m_sampleSinkId , m_sampleSinkSerial , m_sampleSinkSequence , m_sampleSinkPluginInstanceUI - > serialize ( ) ) ;
preset - > setCenterFrequency ( m_sampleSinkPluginInstanceUI - > getCenterFrequency ( ) ) ;
2016-10-18 22:07:42 +00:00
}
2016-10-22 08:10:17 +00:00
else
{
qDebug ( " DeviceSinkAPI::saveSinkSettings: no sink " ) ;
}
2016-10-17 22:03:51 +00:00
}
}
void DeviceSinkAPI : : loadChannelSettings ( const Preset * preset , PluginAPI * pluginAPI )
{
2016-10-18 22:07:42 +00:00
if ( preset - > isSourcePreset ( ) )
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: Loading preset [%s | %s] not a sink preset " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2016-10-18 22:07:42 +00:00
}
else
2016-10-17 22:03:51 +00:00
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: Loading preset [%s | %s] " , qPrintable ( preset - > getGroup ( ) ) , qPrintable ( preset - > getDescription ( ) ) ) ;
2016-10-17 22:03:51 +00:00
2016-10-18 22:07:42 +00:00
// Available channel plugins
2016-10-22 10:07:28 +00:00
PluginAPI : : ChannelRegistrations * channelRegistrations = pluginAPI - > getTxChannelRegistrations ( ) ;
2016-10-17 22:03:51 +00:00
2016-10-18 22:07:42 +00:00
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations ;
m_channelInstanceRegistrations . clear ( ) ;
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: %d channel(s) in preset " , preset - > getChannelCount ( ) ) ;
2016-10-18 22:07:42 +00:00
for ( int i = 0 ; i < preset - > getChannelCount ( ) ; i + + )
2016-10-17 22:03:51 +00:00
{
2016-10-18 22:07:42 +00:00
const Preset : : ChannelConfig & channelConfig = preset - > getChannelConfig ( i ) ;
ChannelInstanceRegistration reg ;
2016-10-17 22:03:51 +00:00
2016-10-18 22:07:42 +00:00
// if we have one instance available already, use it
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2016-10-17 22:03:51 +00:00
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: channels compare [%s] vs [%s] " , qPrintable ( openChannels [ i ] . m_channelName ) , qPrintable ( channelConfig . m_channel ) ) ;
2016-10-18 22:07:42 +00:00
if ( openChannels [ i ] . m_channelName = = channelConfig . m_channel )
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: channel [%s] found " , qPrintable ( openChannels [ i ] . m_channelName ) ) ;
2016-10-18 22:07:42 +00:00
reg = openChannels . takeAt ( i ) ;
m_channelInstanceRegistrations . append ( reg ) ;
break ;
}
2016-10-17 22:03:51 +00:00
}
2016-10-18 22:07:42 +00:00
// if we haven't one already, create one
2016-10-17 22:03:51 +00:00
2016-10-22 10:07:28 +00:00
if ( reg . m_gui = = 0 )
2016-10-17 22:03:51 +00:00
{
2016-10-18 22:07:42 +00:00
for ( int i = 0 ; i < channelRegistrations - > count ( ) ; i + + )
2016-10-17 22:03:51 +00:00
{
2016-10-18 22:07:42 +00:00
if ( ( * channelRegistrations ) [ i ] . m_channelName = = channelConfig . m_channel )
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: creating new channel [%s] " , qPrintable ( channelConfig . m_channel ) ) ;
2016-10-18 22:07:42 +00:00
reg = ChannelInstanceRegistration ( channelConfig . m_channel , ( * channelRegistrations ) [ i ] . m_plugin - > createTxChannel ( channelConfig . m_channel , this ) ) ;
break ;
}
2016-10-17 22:03:51 +00:00
}
}
2016-10-18 22:07:42 +00:00
2016-10-22 10:07:28 +00:00
if ( reg . m_gui ! = 0 )
2016-10-18 22:07:42 +00:00
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: deserializing channel [%s] " , qPrintable ( channelConfig . m_channel ) ) ;
2016-10-18 22:07:42 +00:00
reg . m_gui - > deserialize ( channelConfig . m_config ) ;
}
2016-10-17 22:03:51 +00:00
}
2016-10-18 22:07:42 +00:00
// everything, that is still "available" is not needed anymore
for ( int i = 0 ; i < openChannels . count ( ) ; i + + )
2016-10-17 22:03:51 +00:00
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::loadChannelSettings: destroying spare channel [%s] " , qPrintable ( openChannels [ i ] . m_channelName ) ) ;
2016-10-18 22:07:42 +00:00
openChannels [ i ] . m_gui - > destroy ( ) ;
2016-10-17 22:03:51 +00:00
}
2016-10-18 22:07:42 +00:00
renameChannelInstances ( ) ;
2016-10-17 22:03:51 +00:00
}
}
void DeviceSinkAPI : : saveChannelSettings ( Preset * preset )
{
2016-10-18 22:07:42 +00:00
if ( preset - > isSourcePreset ( ) )
{
qDebug ( " DeviceSinkAPI::saveChannelSettings: not a sink preset " ) ;
}
else
{
qSort ( m_channelInstanceRegistrations . begin ( ) , m_channelInstanceRegistrations . end ( ) ) ; // sort by increasing delta frequency and type
2016-10-17 22:03:51 +00:00
2016-10-18 22:07:42 +00:00
for ( int i = 0 ; i < m_channelInstanceRegistrations . count ( ) ; i + + )
{
2016-10-22 08:10:17 +00:00
qDebug ( " DeviceSinkAPI::saveChannelSettings: channel [%s] saved " , qPrintable ( m_channelInstanceRegistrations [ i ] . m_channelName ) ) ;
2016-10-18 22:07:42 +00:00
preset - > addChannel ( m_channelInstanceRegistrations [ i ] . m_channelName , m_channelInstanceRegistrations [ i ] . m_gui - > serialize ( ) ) ;
}
2016-10-17 22:03:51 +00:00
}
}
// sort by increasing delta frequency and type (i.e. name)
bool DeviceSinkAPI : : ChannelInstanceRegistration : : operator < ( const ChannelInstanceRegistration & other ) const
{
if ( m_gui & & other . m_gui )
{
if ( m_gui - > getCenterFrequency ( ) = = other . m_gui - > getCenterFrequency ( ) )
{
return m_gui - > getName ( ) < other . m_gui - > getName ( ) ;
}
else
{
return m_gui - > getCenterFrequency ( ) < other . m_gui - > getCenterFrequency ( ) ;
}
}
else
{
return false ;
}
}
2016-12-29 11:41:10 +00:00
void DeviceSinkAPI : : addSourceBuddy ( DeviceSourceAPI * buddy )
{
std : : vector < DeviceSourceAPI * > : : iterator it = m_sourceBuddies . begin ( ) ;
m_sourceBuddies . push_back ( buddy ) ;
2017-01-02 22:30:50 +00:00
buddy - > m_sinkBuddies . push_back ( this ) ;
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::addSourceBuddy: added buddy %s(%s) to the list [%lx] <-> [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSourceSerial ( ) ) ,
( uint64_t ) buddy ,
( uint64_t ) this ) ;
2016-12-29 11:41:10 +00:00
}
void DeviceSinkAPI : : addSinkBuddy ( DeviceSinkAPI * buddy )
{
std : : vector < DeviceSinkAPI * > : : iterator it = m_sinkBuddies . begin ( ) ;
m_sinkBuddies . push_back ( buddy ) ;
2017-01-02 22:30:50 +00:00
buddy - > m_sinkBuddies . push_back ( this ) ;
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::addSinkBuddy: added buddy %s(%s) to the list [%lx] <-> [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSinkSerial ( ) ) ,
( uint64_t ) buddy ,
( uint64_t ) this ) ;
2016-12-29 11:41:10 +00:00
}
void DeviceSinkAPI : : removeSourceBuddy ( DeviceSourceAPI * buddy )
{
std : : vector < DeviceSourceAPI * > : : iterator it = m_sourceBuddies . begin ( ) ;
for ( ; it ! = m_sourceBuddies . end ( ) ; + + it )
{
2016-12-29 18:26:45 +00:00
if ( * it = = buddy )
2016-12-29 11:41:10 +00:00
{
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::removeSourceBuddy: buddy %s(%s) [%lx] removed from the list of [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSourceSerial ( ) ) ,
( uint64_t ) ( * it ) ,
( uint64_t ) this ) ;
m_sourceBuddies . erase ( it ) ;
2016-12-29 11:41:10 +00:00
return ;
}
}
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::removeSourceBuddy: buddy %s(%s) [%lx] not found in the list of [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSourceSerial ( ) ) ,
( uint64_t ) buddy ,
( uint64_t ) this ) ;
2016-12-29 11:41:10 +00:00
}
void DeviceSinkAPI : : removeSinkBuddy ( DeviceSinkAPI * buddy )
{
std : : vector < DeviceSinkAPI * > : : iterator it = m_sinkBuddies . begin ( ) ;
for ( ; it ! = m_sinkBuddies . end ( ) ; + + it )
{
2016-12-29 18:26:45 +00:00
if ( * it = = buddy )
2016-12-29 11:41:10 +00:00
{
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::removeSinkBuddy: buddy %s(%s) [%lx] removed from the list of [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSinkSerial ( ) ) ,
( uint64_t ) ( * it ) ,
( uint64_t ) this ) ;
m_sinkBuddies . erase ( it ) ;
2016-12-29 11:41:10 +00:00
return ;
}
}
2016-12-29 18:26:45 +00:00
qDebug ( " DeviceSinkAPI::removeSinkBuddy: buddy %s(%s) [%lx] not found in the list of [%lx] " ,
2016-12-29 11:41:10 +00:00
qPrintable ( buddy - > getHardwareId ( ) ) ,
2016-12-29 18:26:45 +00:00
qPrintable ( buddy - > getSampleSinkSerial ( ) ) ,
( uint64_t ) buddy ,
( uint64_t ) this ) ;
2016-12-29 11:41:10 +00:00
}
2016-12-29 18:26:45 +00:00
void DeviceSinkAPI : : clearBuddiesLists ( )
2016-12-29 11:41:10 +00:00
{
std : : vector < DeviceSourceAPI * > : : iterator itSource = m_sourceBuddies . begin ( ) ;
std : : vector < DeviceSinkAPI * > : : iterator itSink = m_sinkBuddies . begin ( ) ;
2017-07-03 06:59:48 +00:00
bool leaderElected = false ;
2016-12-29 11:41:10 +00:00
for ( ; itSource ! = m_sourceBuddies . end ( ) ; + + itSource )
{
2017-07-03 06:59:48 +00:00
if ( isBuddyLeader ( ) & & ! leaderElected )
{
( * itSource ) - > setBuddyLeader ( true ) ;
leaderElected = true ;
}
2016-12-29 11:41:10 +00:00
( * itSource ) - > removeSinkBuddy ( this ) ;
}
2016-12-29 18:26:45 +00:00
m_sourceBuddies . clear ( ) ;
2016-12-29 11:41:10 +00:00
for ( ; itSink ! = m_sinkBuddies . end ( ) ; + + itSink )
{
2017-07-03 06:59:48 +00:00
if ( isBuddyLeader ( ) & & ! leaderElected )
{
( * itSink ) - > setBuddyLeader ( true ) ;
leaderElected = true ;
}
2016-12-29 11:41:10 +00:00
( * itSink ) - > removeSinkBuddy ( this ) ;
}
2016-12-29 18:26:45 +00:00
m_sinkBuddies . clear ( ) ;
2016-12-29 11:41:10 +00:00
}
2016-10-17 22:03:51 +00:00