summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/model/pulsemodel.cpp28
-rw-r--r--src/model/pulsemodel.h2
2 files changed, 13 insertions, 17 deletions
diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp
index 03ed42d..5b1d240 100644
--- a/src/model/pulsemodel.cpp
+++ b/src/model/pulsemodel.cpp
@@ -187,8 +187,6 @@ bool PulseModel::open()
void PulseModel::close()
{
- TQPtrList<PulseDevice> *allLists[4] = { &m_sinks, &m_sources, &m_sinkInputs, &m_sourceOutputs };
-
bool alreadyDead = false;
if ( m_context ) {
pa_context_state_t state = pa_context_get_state( m_context );
@@ -196,9 +194,7 @@ void PulseModel::close()
state == PA_CONTEXT_TERMINATED );
}
- for ( int i = 0; i < 4; i++ )
- for ( TQPtrListIterator<PulseDevice> it(*allLists[i]); *it; ++it )
- (*it)->detach( alreadyDead );
+ forEachDevice( [alreadyDead](PulseDevice *dev) { dev->detach( alreadyDead ); } );
if ( m_context ) {
if ( !alreadyDead ) {
@@ -480,23 +476,13 @@ void PulseModel::customEvent( TQCustomEvent *e )
if ( e->type() == PA_DIED_EVENT ) {
if ( !m_mainloop ) return; // already handling a previous die event
// Notify UI that all devices are gone, then tear down and retry.
- TQPtrList<PulseDevice> *allLists[4] = { &m_sinks, &m_sources, &m_sinkInputs, &m_sourceOutputs };
- for ( int i = 0; i < 4; i++ ) {
- TQPtrListIterator<PulseDevice> it( *allLists[i] );
- while ( *it ) {
- PulseDevice *dev = *it;
- ++it;
- emit deviceRemoved( dev );
- }
- }
+ forEachDevice( [this](PulseDevice *dev) { emit deviceRemoved( dev ); } );
// Zero out default-device pointers in connected UI before devices are deleted.
emit defaultOutputChanged( 0 );
emit defaultInputChanged( 0 );
// Sever all remaining signal connections on every device so that
// close() can delete them safely regardless of cross-device wiring.
- for ( int i = 0; i < 4; i++ )
- for ( TQPtrListIterator<PulseDevice> it( *allLists[i] ); *it; ++it )
- disconnect( *it, 0, 0, 0 );
+ forEachDevice( [this](PulseDevice *dev) { disconnect( dev, 0, 0, 0 ); } );
m_sinksByName.clear();
m_sourcesByName.clear();
m_sourceOutputToSource.clear();
@@ -713,6 +699,14 @@ AudioDevice *PulseModel::defaultInput() const
return 0;
}
+void PulseModel::forEachDevice( std::function<void(PulseDevice*)> fn )
+{
+ TQPtrList<PulseDevice> *lists[] = { &m_sinks, &m_sources, &m_sinkInputs, &m_sourceOutputs };
+ for ( int i = 0; i < 4; ++i )
+ for ( TQPtrListIterator<PulseDevice> it(*lists[i]); *it; ++it )
+ fn( *it );
+}
+
PulseDevice *PulseModel::findDevice( TQPtrList<PulseDevice> &list, uint32_t paIndex )
{
for ( TQPtrListIterator<PulseDevice> it(list); *it; ++it )
diff --git a/src/model/pulsemodel.h b/src/model/pulsemodel.h
index d0e93b4..d799a83 100644
--- a/src/model/pulsemodel.h
+++ b/src/model/pulsemodel.h
@@ -4,6 +4,7 @@
#include <tqptrlist.h>
#include <tqmap.h>
#include <tqvaluelist.h>
+#include <functional>
#include <pulse/pulseaudio.h>
@@ -144,6 +145,7 @@ private:
TQMap<uint32_t, TQString> m_sourceActivePort;
TQMap<uint32_t, TQValueList<PulseDevicePort>> m_sourcePorts;
+ void forEachDevice( std::function<void(PulseDevice*)> fn );
PulseDevice *findDevice( TQPtrList<PulseDevice> &list, uint32_t paIndex );
PulseCardInfo *findCard( uint32_t index );
};