C H A P T E R 2

Using Network Setup

err2 = OTCfgClosePrefs(accessID); if (err == noErr) {

err = err2;

}

}

return err;

}

Note

The sample shown in Listing 2-11, which opens and closes the entity for each preference written, is implemented in an inefficient manner for the sake of clarity. If you are writing multiple preferences, it is more efficient to open the entity, write your preferences by calling OTCfgSetPrefs multiple times, and close the entity when you’re done.

Iterating the Preferences in an Entity

Network Setup provides functions for iterating all of the preferences in an entity. You will rarely need to do this, but the code in Listing 2-12 gives an example. The code first calls OTCfgGetPrefsTOCCount (TOC stands for “Table of Contents”) to get a count of the number of preferences in the entity and then calls OTCfgGetPrefsTOC to get an array of CfgPrefsHeader structures. Each structure represents a preference in the entity, with fields for the preference’s type and size.

Listing 2-12Printing an entity’s table of contents

static void PrintPrefsTOC(CfgDatabaseRef dbRef, const CfgEntityRef *entity)

{

OSStatus err;

OSStatus err2;

CfgEntityAccessID accessID;

ItemCount prefsTOCCount;

ItemCount prefsTOCIndex;

CfgPrefsHeader *prefsTOC;

OSType prefType;

ByteCount prefSize;

40Reading and Writing Preferences

Page 40
Image 40
Apple Network Setup manual Iterating the Preferences in an Entity, Listing 2-12Printing an entity’s table of contents