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;
void **scanResults = NULL;
int *deviceCounts = NULL;
int i = 0;
int i;
int baseDeviceIndex;
PA_LOGAPI_ENTER( "Pa_UpdateAvailableDeviceList" );
if( !PA_IS_INITIALISED_ )
@ -790,15 +791,10 @@ 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_ )
result = hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] );
if( result != paNoError )
{
/* If failure, rollback the scan changes back to original state */
/* On error, dispose scan results already obtained, then return. */
int j = 0;
for( j = 0 ; j < i ; ++j )
{
@ -809,13 +805,17 @@ PaError Pa_RefreshDeviceList( void )
PA_DEBUG(( "Performing rollback for device list scan for host api %d.\n",i));
hostApi->DisposeDeviceInfos( hostApi, scanResults[ j ], deviceCounts[ j ] );
}
}
else
{
int baseDeviceIndex = 0;
deviceCount_ = 0;
/* Otherwise, commit the scan changes to each back-end */
goto done;
}
}
/* -------------- 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 )
{
PaUtilHostApiRepresentation *hostApi = hostApis_[i];
@ -851,7 +851,6 @@ PaError Pa_RefreshDeviceList( void )
baseDeviceIndex += hostApi->info.deviceCount;
deviceCount_ += hostApi->info.deviceCount;
}
}
done: