Listing 2-14 – Apple Network Setup User Manual

Page 46

Advertising
background image

C H A P T E R 2

Using Network Setup

46

Working with Sets

Listing 2-14

Finding 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) {

Advertising