Another kind of iteration call, RegistryEntrySearch, retrieves the next name entry in the Name Registry that has a specified matching property.
OSStatus RegistryEntrySearch(
RegEntryIter *cookie,
RegEntryIterationOp relationship,
RegEntryID *foundEntry,
Boolean *done,
const RegPropertyName *propertyName,
const void *propertyValue,
RegPropertyValueSize propertySize);
RegistryEntrySearch searches for a name entry with a property that matches certain criteria and returns the RegEntryID value that identifies that entry in foundEntry, or true in done if all matching name entries have been found.
RegistryEntrySearch returns only entries with properties that simultaneously match the values of propertyName, propertyValue, and propertySize. If the propertyValue pointer is null or propertySize is 0, then any property value is considered a match.
Listing 10-4 shows code that uses RegistryEntrySearch to count the number of SCSI interface devices for a given parent device.
Listing 10-4 Using RegistryEntrySearch
OSStatus
FindSCSIDevices(
constRegEntryID *parentEntry,
int *numberOfSCSIDevices
)
{
RegEntryIter cookie;
RegEntryID SCSIEntry;
RegEntryIterationOp iterOp;
Boolean done;
OSStatus err = noErr;
#define kSCSIDeviceType "scsi"
RegistryEntryIDInit(&SCSIEntry);
*numberOfSCSIDevices = 0;
err = RegistryEntryIterateCreate(&cookie);
if(err != noErr)
return err;
/*
* Reset iterator to point to the parent entry
*/
err=RegistryEntryIterateSet(&cookie, parentEntry);
if (err == noErr){
/*
* Search all descendants of the parent device.
*/
iterOp = kRegIterDescendants;
do {
err = RegistryEntrySearch(&cookie, iterOp, &SCSIEntry, &done,
"device_type", kSCSIDeviceType, sizeof(kSCSIDeviceType));
if (!done && err == noErr){
*numberOfSCSIDevices +=1;
RegistryEntryIDDispose(&SCSIEntry);
}
iterOp = kRegIterContinue;
} while (!done && err == noErr);
}
RegistryEntryIterateDispose(&cookie);
return err;
}