C H A P T E R 2

Using Network Setup

Listing 2-14Finding the active entity of a given class and type

static OSStatus MyFindFirstActiveEntity(CfgDatabaseRef dbRef, CfgAreaID area,

OSType entityClass,

OSType entityType,

CfgEntityRef *activeEntity)

{

OSStatus err;

CfgEntityRef activeSet;

CfgSetsVector **entitiesInSet;

ItemCount entityIndex;

Boolean found;

CfgEntityInfo thisEntityInfo;

entitiesInSet = (CfgSetsVector **) NewHandle(0); err = MemError();

if (err == noErr) {

err = MyFindActiveSet(dbRef, area, &activeSet);

}

if (err == noErr) {

err = MyReadVariableSizePref(dbRef, &activeSet, kOTCfgSetsVectorPref, (Handle ) entitiesInSet);

}

if (err == noErr) {

HLock( (Handle) entitiesInSet );

found = false;

for (entityIndex = 0; entityIndex < (**entitiesInSet).fCount; entityIndex++) {

thisEntityInfo = (**entitiesInSet).fElements[entityIndex].fEntityInfo; found = ( thisEntityInfo.fClass == entityClass && thisEntityInfo.fType ==

entityType );

if (found) { break;

}

}

if ( ! found ) {

err = kCfgErrEntityNotFound;

}

}

if (err == noErr) {

46Working with Sets

Page 46
Image 46
Apple Network Setup manual Working with Sets