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_ )
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: