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:
parent
c2175e14f1
commit
82bdb95a6d
1 changed files with 48 additions and 49 deletions
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
result = hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] );
|
||||
if( result != paNoError )
|
||||
{
|
||||
PaUtilHostApiRepresentation *hostApi = hostApis_[j];
|
||||
if( hostApi->DisposeDeviceInfos == NULL )
|
||||
continue;
|
||||
/* 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 ] );
|
||||
PA_DEBUG(( "Performing rollback for device list scan for host api %d.\n",i));
|
||||
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;
|
||||
deviceCount_ = 0;
|
||||
|
||||
/* Otherwise, commit the scan changes to each back-end */
|
||||
for( i = 0 ; i < hostApisCount_ ; ++i )
|
||||
PaUtilHostApiRepresentation *hostApi = hostApis_[i];
|
||||
if( hostApi->CommitDeviceInfos == NULL )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
deviceCount_ += hostApi->info.deviceCount;
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
|
|||
Loading…
Reference in a new issue