Listing 2-5, Listing 2-5 shows the r – Apple Network Setup User Manual

Page 31

Advertising
background image

C H A P T E R 2

Using Network Setup

Working with Entities

31

Getting all entities. Set

entityClass

and

entityType

to the wildcard values

kCfgClassAnyEntity

and

kCfgTypeAnyEntity

, respectively.

The

entityRefs

and

entityInfos

parameters are handles containing an array of

elements of type

CfgEntityRef

and

CfgEntityInfo

, respectively. You must create

these handles before calling

MyGetEntitiesList

. You can set

entityInfos

to

NULL

if you’re not interested in the information returned in that handle. The

MyGetEntitiesList

routine resizes the handles appropriately to hold

information about each of the entities that it finds.

The

MyGetEntitiesList

routine calls two key Network Setup functions:

OTCfgGetEntitiesCount

to count the number of entities of the specified class and

type and

OTCfgGetEntitiesList

to get the actual entity information. The rest of

the

MyGetEntitiesList

routine is just memory management.

Listing 2-5

Finding all entities of a particular class and type

static OSStatus MyGetEntitiesList(CfgDatabaseRef dbRef,

CfgAreaID area,

OSType entityClass,

OSType entityType,

CfgEntityRef **entityRefs,

CfgEntityInfo **entityInfos)

{

OSStatus err;

ItemCount entityCount;

CfgEntityRef *paramRefs;

CfgEntityInfo *paramInfos;

SInt8 sRefs;

SInt8 sInfos;

assert(dbRef != nil);

assert(area != kInvalidCfgAreaID);

assert((entityRefs != nil) || (entityInfos != nil));

assert((entityRefs == nil) || (*entityRefs != nil));

assert((entityInfos == nil) || (*entityInfos != nil));

err = OTCfgGetEntitiesCount(dbRef, area, entityClass, entityType, &entityCount);

if ((err == noErr) && (entityRefs != nil)) {

Advertising