C H A P T E R 2
Working with Nodes
} // PrintNodeName
Finding a Node
The sample code in Listing
The FindNodes routine calls dsBuildFromPath to build a data list for the pathname and calls dsDataBufferAllocate to allocate a data buffer in which to store the result of calling dsFindDirNodes. The routine then calls dsFindDirNodes to find the node whose name matches the specified pathname.
Then the FindNodes routine calls dsDataListAllocate to allocate a data list and provides that data list as a parameter when it calls dsGetDirNodeName. The dsGetDirNodeName function copies the node name from the data buffer filled in by dsFindDirNodes to the data list. Then the FindNodes routine calls its PrintNodeName routine to print the node name that was found. The PrintNodeName routine is described in the section Listing
When the PrintNodeName routine returns, the FindNodes routine cleans up by calling dsDataListDeallocate and free() to deallocate the data list.
Listing
void main ( )
{
long dirStatus = eDSNoErr;
dirStatus = dsOpenDirService( &gDirRef ); if ( dirStatus == eDSNoErr )
{
FindNodes("/NetInfo/root");
}
if ( gDirRef != NULL )
{
dirStatus = dsCloseDirService( gDirRef );
}
}
void FindNodes ( char* inNodePath ){ bool done = false;
long dirStatus = eDSNoErr; unsigned long index = 0; unsigned long bufferCount = 0; tDataBufferPtr dataBuffer = NULL; tDataListPtr nodeName = NULL; tContextData context = NULL;
nodeName = dsBuildFromPath( gDirRef, inNodePath, "/"); if ( nodeName != NULL )
{
//Allocate a 32k buffer.
dataBuffer = dsDataBufferAllocate( gDirRef, 32 * 1024 ); if ( dataBuffer != NULL )
{
while ( (dirStatus == eDSNoErr) && (done == false) )
{
Finding a Node | 27 |