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.

This commit is contained in:
Ross Bencina 2016-09-19 00:39:26 +10:00
commit 82bdb95a6d

View file

@ -758,7 +758,8 @@ PaError Pa_RefreshDeviceList( void )
PaError result = paNoError; PaError result = paNoError;
void **scanResults = NULL; void **scanResults = NULL;
int *deviceCounts = NULL; int *deviceCounts = NULL;
int i = 0; int i;
int baseDeviceIndex;
PA_LOGAPI_ENTER( "Pa_UpdateAvailableDeviceList" ); PA_LOGAPI_ENTER( "Pa_UpdateAvailableDeviceList" );
if( !PA_IS_INITIALISED_ ) if( !PA_IS_INITIALISED_ )
@ -790,67 +791,65 @@ PaError Pa_RefreshDeviceList( void )
continue; continue;
PA_DEBUG(( "Scanning new device list for host api %d.\n",i)); PA_DEBUG(( "Scanning new device list for host api %d.\n",i));
if( hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] ) != paNoError ) result = hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] );
break; if( result != paNoError )
}
/* Check the result of the scan operation */
if( i < hostApisCount_ )
{
/* If failure, rollback the scan changes back to original state */
int j = 0;
for( j = 0 ; j < i ; ++j )
{ {
PaUtilHostApiRepresentation *hostApi = hostApis_[j]; /* On error, dispose scan results already obtained, then return. */
if( hostApi->DisposeDeviceInfos == NULL ) int j = 0;
continue; 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)); PA_DEBUG(( "Performing rollback for device list scan for host api %d.\n",i));
hostApi->DisposeDeviceInfos( hostApi, scanResults[ j ], deviceCounts[ j ] ); hostApi->DisposeDeviceInfos( hostApi, scanResults[ j ], deviceCounts[ j ] );
}
goto done;
} }
} }
else
/* -------------- 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 )
{ {
int baseDeviceIndex = 0; PaUtilHostApiRepresentation *hostApi = hostApis_[i];
deviceCount_ = 0; if( hostApi->CommitDeviceInfos == NULL )
/* Otherwise, commit the scan changes to each back-end */
for( i = 0 ; i < hostApisCount_ ; ++i )
{ {
PaUtilHostApiRepresentation *hostApi = hostApis_[i]; /* Not yet implemented for this backend. Just
if( hostApi->CommitDeviceInfos == NULL ) assume that the baseDeviceIndex and the deviceCount_ are
{ incremented according to the values in the info */
/* 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;
}
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex;
if( hostApi->info.defaultInputDevice != paNoDevice )
hostApi->info.defaultInputDevice += baseDeviceIndex;
if( hostApi->info.defaultOutputDevice != paNoDevice )
hostApi->info.defaultOutputDevice += baseDeviceIndex;
baseDeviceIndex += hostApi->info.deviceCount; baseDeviceIndex += hostApi->info.deviceCount;
deviceCount_ += 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;
}
assert( hostApi->info.defaultInputDevice < hostApi->info.deviceCount );
assert( hostApi->info.defaultOutputDevice < hostApi->info.deviceCount );
hostApi->privatePaFrontInfo.baseDeviceIndex = baseDeviceIndex;
if( hostApi->info.defaultInputDevice != paNoDevice )
hostApi->info.defaultInputDevice += baseDeviceIndex;
if( hostApi->info.defaultOutputDevice != paNoDevice )
hostApi->info.defaultOutputDevice += baseDeviceIndex;
baseDeviceIndex += hostApi->info.deviceCount;
deviceCount_ += hostApi->info.deviceCount;
} }
done: done: