Access Point: 3 Searching For an Access Point

Up: GEOS SDK TechDocs| Up | Prev: 2 Letting The User Choose | Next: 4 Locking and Unlocking

Perhaps instead of allowing the user to choose an access point, the program should use a known access point. The following code example shows how a program might search for an access point, given its type and name.

Code Display 23-1 Searching for an Access Point

@start  TemplateStringsResource, data;
    @chunk  TCHAR TargetName[] = "Stuckeys Sales Server";
@end    TemplateStringsResource;
@method TemplateProcessClass, MSG_TP_SEND {
    MemHandle     aBlock;
    ChunkHandle   theList;  /* Chunk Array of entry IDs of access points */
    word          theID = ACCESS_POINT_INVALID_ID ;
    aBlock = MemAllocLMem( LMEM_TYPE_GENERAL, 0 );
    MemLock( aBlock );
    theList = AccessPointGetEntries( aBlock , 0, APT_INTERNET );
    ChunkArrayEnumHandles( aBlock, theList, &theID, FunkyCallback);
    MemUnlock( aBlock );
    MemFree(aBlock);
    if (theID == ACCESS_POINT_INVALID_ID ) {
      /* didn't find the access point--deal with it */
    } else {
      /* found the access point--use it */
    }
}
Boolean _pascal FunkyCallback( void *el, void *retVal ) {
    char nomen[128];
    int  nomenSize;
    int  cmpResult;
    char *accessPointName;
    AccessPointGetStringPropertyBuffer( *((word *)el), APSP_NAME, 
                                           nomen, &nomenSize );
    MemLock( OptrToHandle(@TargetName) );
    cmpResult = LocalCmpStrings( LMemDeref( @TargetName ) , nomen, 0);
    MemUnlock( OptrToHandle(@TargetName) );
    if (cmpResult) return(FALSE); 					/* if they don't match, return FALSE so 
					   we can keep searching. */	

    *(word *)retVal = *(word *)el;					/* We found a match. grab its ID */
    return(TRUE);				 	/* ...and we can stop searching now. */
}

The AccessPointGetEntries() routine returns a chunk array containing a list of access point IDs.

We then use the ChunkArrayEnumHandles() routine to call a callback routine to examine each ID in turn. There are many other ways we could have cycled through these entries--see the documentation of chunk arrays in the Local Memory chapter to find out which is best for your purpose.

Given an access point's ID number, we find out the name associated with that ID by calling AccessPointGetStringPropertyBuffer() . To specify that we're interested in the name, we pass APSP_NAME; we could also have passed some other AccessPointStandardProperty value, or even a pointer to a string to search for the value of some custom property.

While the application is using the selected access point, it can "lock" the access point to prevent the access point's parameters from being modified while it's in use. (See Locking and Unlocking.)


Up: GEOS SDK TechDocs| Up | Prev: 2 Letting The User Choose | Next: 4 Locking and Unlocking