MyFindFirstActiveEntity reference to the caller.
Working with Sets

C H A P T E R 2

Using Network Setup

kOTCfgSetsStructPref, &thisStruct, sizeof(thisStruct));

if ((err == noErr) && ((thisStruct.fFlags & kOTCfgSetsFlagActiveMask) !=

0)) {

found = true; break;

}

if (err != noErr) {

break;

}

}

if ( ! found ) {

err = kCfgErrEntityNotFound;

}

}

if (err == noErr) {

*activeSet = (*entityRefs)[entityIndex];

}

 

if (entityRefs != nil) {

 

DisposeHandle( (Handle) entityRefs );

assert(MemError() ==

noErr);

 

}

 

return err;

 

}

 

The remaining two steps for finding the set entity of a particular class and type are implemented by the MyFindFirstActiveEntity routine, shown in Listing

2-14. It calls MyFindActiveSet (Listing 2-13) to find the entity reference of the active set entity. The MyFindFirstActiveEntity routine then reads the kOTCfgSetsVectorPref preference out of the active set entity. This preference is a count field followed by an unbounded array of CfgSetsElement structures, each of which represents an entity in the set. Because of its variable size, MyFindFirstActiveEntity reads the preference by calling MyReadVariableSizePref (Listing 2-10). Once it has the array of information about entities contained in the set, MyFindFirstActiveEntity iterates over that array looking for the first element whose class and type matches the required class and type specified by the caller. When it finds the correct entity in the set,

breaks out of the loop and returns the found entity

45

Page 45
Image 45
Apple Network Setup manual NoErr Return err