C H A P T E R 2

Using Network Setup

The MyFindActiveSet routine in Listing 2-13 implements the first two steps. It starts by getting a list of all of the set entities by calling the MyGetEntitiesList routine (Listing 2-5). Then MyFindActiveSet iterates through all of the set entities, reading the kOTCfgSetsStructPref preference of each set entity. That preference maps to the CfgSetsStruct structure, which contains an fFlags member. One bit of the fFlags member, kOTCfgSetsFlagActiveMask, indicates whether this set entity is the active set entity. If it is, the routine breaks out of the loop and returns the set’s entity reference to the caller.

Listing 2-13Finding the active set entity

static OSStatus MyFindActiveSet(CfgDatabaseRef dbRef, CfgAreaID area, CfgEntityRef *activeSet)

{

OSStatus err;

CfgEntityRef **entityRefs;

ItemCount entityCount;

ItemCount entityIndex;

Boolean found;

CfgSetsStruct thisStruct;

assert(dbRef != nil);

 

assert(area

!= kInvalidCfgAreaID);

 

entityRefs

= (CfgEntityRef **) NewHandle(0);

 

err = MemError();

 

if (err ==

noErr) {

 

err = MyGetEntitiesList(dbRef, area,

 

 

kOTCfgClassSetOfSettings, kOTCfgTypeSetOfSettings,

 

entityRefs, nil);

 

}

 

 

if (err ==

noErr) {

 

HLock(

(Handle) entityRefs );

assert(MemError() ==

noErr);

entityCount = GetHandleSize( (Handle) entityRefs ) / sizeof(CfgEntityRef); found = false;

for (entityIndex = 0; entityIndex < entityCount; entityIndex++) { err = MyReadFixedSizePref(dbRef, &(*entityRefs)[entityIndex],

44Working with Sets

Page 44
Image 44
Apple Network Setup manual Listing 2-13Finding the active set entity