PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

Listing Devices

Expert software must be able to find various devices in the system. The example shown in Listing 10-15 contains two procedures. The first loops through name entries, invoking a callback function for each one. The second loops through the properties for a name entry, invoking a callback function for each property. It is up to the caller to determine what the callback functions will do, but they could (for example) display a graph of names and properties in a window or identify all name entries that match a complex set of search criteria.

Listing 10-15 Listing names and properties

#include <NameRegistry.h>

OSStatus JoePro_ListDevices(
    void (*callback) (
        RegCStrPathName         *name,
        RegEntryID              *entry
        )
    )   
{
    OSErr err = noErr;
    RegEntryIter cookie;
    Boolean done;

    /*
    * Entry iterators are created pointing to the root
    * with a RegEntryIterationOp of kRegIterDescendants.
    * So, we just need to continue.
    */
    RegEntryIterationOp op = kRegIterContinue;

    err = RegistryEntryIterateCreate(&cookie);
    if (err == noErr) do {
        RegEntryID entry;

        err = RegistryEntryIterate(&cookie, op, &entry, &done);
        if (!done) {
            RegCStrPathName     *name;
            RegPathNameSize     len;

            err = RegistryCStrEntryToPathSize(&entry, &len);
            if (err == noErr) {
                name = (RegCStrPathName*) malloc(len);

                assert(name != NULL);

                err = RegistryCStrEntryToPath(&entry, name, len);
                if (err == noErr) {
                    (*callback)(name, &entry);
                }
                free(name);
            }
            RegistryEntryIDDispose(&entry);
        }
    } while (!done);
    RegistryEntryIterateDispose(&cookie);
    return err;
}

OSStatus JoePro_ListProperties(
    const RegCStrPathName       *name,
    const RegEntryID            *entry,
    void    (*callback)(
            RegPropertyName*,
            RegPropertyValue,
            RegPropertyValueSize
            )
    )
{
    OSErr err = noErr;
    RegPropertyIter cookie;
    Boolean done;

    err = RegistryPropertyIterateCreate(entry, &cookie);
    if (err == noErr) do {
        RegPropertyNameBuf      property;

        err = RegistryPropertyIterate(&cookie, property, &done);
        if (!done) {
            RegPropertyValue        val;
            RegPropertyValueSize    siz;

            err = JoePro_GetProperty(entry, property, &val, &siz);
            if (err == noErr) {
                (*callback)(property, val, siz);
            }
        }
    } while (!done);
    RegistryPropertyIterateDispose(&cookie);
    return err;
}

© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)