From 82bdb95a6d03e169ab007b6187fb9a6abf055250 Mon Sep 17 00:00:00 2001 From: Ross Bencina Date: Mon, 19 Sep 2016 00:39:26 +1000 Subject: [PATCH] hotplug: Clean up structure of Pa_RefreshDeviceList(). Fix to report error result for failed host api ScanDeviceInfos(). Previously it would return paNoError if it failed. --- src/common/pa_front.c | 97 +++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/src/common/pa_front.c b/src/common/pa_front.c index 5c2eecb..fd2c95a 100644 --- a/src/common/pa_front.c +++ b/src/common/pa_front.c @@ -758,7 +758,8 @@ PaError Pa_RefreshDeviceList( void ) PaError result = paNoError; void **scanResults = NULL; int *deviceCounts = NULL; - int i = 0; + int i; + int baseDeviceIndex; PA_LOGAPI_ENTER( "Pa_UpdateAvailableDeviceList" ); if( !PA_IS_INITIALISED_ ) @@ -790,67 +791,65 @@ PaError Pa_RefreshDeviceList( void ) continue; PA_DEBUG(( "Scanning new device list for host api %d.\n",i)); - if( hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] ) != paNoError ) - break; + result = hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] ); + if( result != paNoError ) + { + /* On error, dispose scan results already obtained, then return. */ + int j = 0; + for( j = 0 ; j < i ; ++j ) + { + PaUtilHostApiRepresentation *hostApi = hostApis_[j]; + if( hostApi->DisposeDeviceInfos == NULL ) + continue; + + PA_DEBUG(( "Performing rollback for device list scan for host api %d.\n",i)); + hostApi->DisposeDeviceInfos( hostApi, scanResults[ j ], deviceCounts[ j ] ); + } + goto done; + } } - /* Check the result of the scan operation */ - if( i < hostApisCount_ ) + /* -------------- Can't fail from here on -------------- */ + + /* Phase 2: Commit the scan changes to each back-end */ + + baseDeviceIndex = 0; + deviceCount_ = 0; + for( i = 0 ; i < hostApisCount_ ; ++i ) { - /* If failure, rollback the scan changes back to original state */ - int j = 0; - for( j = 0 ; j < i ; ++j ) + PaUtilHostApiRepresentation *hostApi = hostApis_[i]; + if( hostApi->CommitDeviceInfos == NULL ) { - PaUtilHostApiRepresentation *hostApi = hostApis_[j]; - if( hostApi->DisposeDeviceInfos == NULL ) - continue; - - PA_DEBUG(( "Performing rollback for device list scan for host api %d.\n",i)); - hostApi->DisposeDeviceInfos( hostApi, scanResults[ j ], deviceCounts[ j ] ); + /* Not yet implemented for this backend. Just + assume that the baseDeviceIndex and the deviceCount_ are + incremented according to the values in the info */ + baseDeviceIndex += hostApi->info.deviceCount; + deviceCount_ += hostApi->info.deviceCount; + continue; } - } - else - { - int baseDeviceIndex = 0; - deviceCount_ = 0; - /* Otherwise, commit the scan changes to each back-end */ - for( i = 0 ; i < hostApisCount_ ; ++i ) + PA_DEBUG(( "Committing device list scan for host api %d.\n",i)); + if( hostApi->CommitDeviceInfos( hostApi, i, scanResults[ i ], deviceCounts[ i ] ) != paNoError ) { - PaUtilHostApiRepresentation *hostApi = hostApis_[i]; - if( hostApi->CommitDeviceInfos == NULL ) - { - /* Not yet implemented for this backend. Just - assume that the baseDeviceIndex and the deviceCount_ are - incremented according to the values in the info */ - baseDeviceIndex += hostApi->info.deviceCount; - deviceCount_ += hostApi->info.deviceCount; - continue; - } - - PA_DEBUG(( "Committing device list scan for host api %d.\n",i)); - if( hostApi->CommitDeviceInfos( hostApi, i, scanResults[ i ], deviceCounts[ i ] ) != paNoError ) - { - PA_DEBUG(( "Committing failed (shouldn't happen) %d.\n",i)); - result = paInternalError; - goto done; - } + PA_DEBUG(( "Committing failed (shouldn't happen) %d.\n",i)); + result = paInternalError; + goto done; + } - assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount ); - assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount ); + assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount ); + assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount ); - hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex; + hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex; - if( hostApi->info.defaultInputDevice != paNoDevice ) - hostApi->info.defaultInputDevice += baseDeviceIndex; + if( hostApi->info.defaultInputDevice != paNoDevice ) + hostApi->info.defaultInputDevice += baseDeviceIndex; - if( hostApi->info.defaultOutputDevice != paNoDevice ) - hostApi->info.defaultOutputDevice += baseDeviceIndex; + if( hostApi->info.defaultOutputDevice != paNoDevice ) + hostApi->info.defaultOutputDevice += baseDeviceIndex; - baseDeviceIndex += hostApi->info.deviceCount; - deviceCount_ += hostApi->info.deviceCount; - } + baseDeviceIndex += hostApi->info.deviceCount; + deviceCount_ += hostApi->info.deviceCount; } done: -- 2.43.0