Every device driver typically needs to retrieve information about the device from the Name Registry. The example in Listing 10-13 retrieves the value of a single property for a specified name entry in the Name Registry.
Listing 10-13 Retrieving the value of a property
#include <NameRegistry.h>
OSStatus
JoePro_LookupProperty(
const RegCStrPathName *name,
const RegPropertyName *prop,
RegPropertyValue *val,
RegPropertyValueSize *siz
)
{
OSErr err = noErr;
RegEntryID entry;
err = JoePro_FindEntry(name, &entry);
if (err == noErr) {
err = JoePro_GetProperty(&entry, prop, val, siz);
RegistryEntryIDDispose(&entry);
}
return err;
}
OSStatus JoePro_FindEntry(
const RegCStrPathName *name,
RegEntryID *entry
)
{
return RegistryCStrEntryLookup(
NULL /* start root */, name, entry);
}
OSStatus JoePro_GetProperty(
RegEntryID *entry,
RegPropertyName *prop,
RegPropertyValue *val,
RegPropertyValueSize *siz
)
{
OSErr err = noErr;
/*
* Figure out how big a buffer we need for the value
*/
err = RegistryPropertyGetSize(entry, prop, siz);
if (err == noErr) {
*val = (RegPropertyValue) malloc(*siz);
assert(*val != NULL);
err = RegistryPropertyGet(entry, prop, val, siz);
if (err != noErr) {
free(*val);
*val = NULL;
}
}
return err;
}