Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 06:39, 30 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

WISE Discover Device

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: ebra (17 Jun 2008)
Last edited: hamishwillee (30 May 2013)

Maemo Platform

int search_servers(wise_connection_manager* manager)
{
inquiry_info *inquiry=NULL;
int max_rsp,num_rsp,device_id,socket,len,flags,index;
 
/* Get local device ID */
device_id = hci_get_route(NULL);
if ( device_id < 0 ) return WISE_CONNECTION_ERROR;
 
/* Open socket */
socket = hci_open_dev( device_id );
if ( socket < 0 ) return WISE_CONNECTION_ERROR;
 
len = 8;
max_rsp = 255;
 
/* Flush existing Bluetooth devices */
flags = IREQ_CACHE_FLUSH;
 
/* Search Bluetooth devices */
inquiry = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
if ( inquiry==NULL ) return WISE_CONNECTION_ERROR;
num_rsp = hci_inquiry(device_id,len,max_rsp,NULL,&inquiry,flags);
 
for ( index=0; index < num_rsp; index++ )
{
wise_device* device = malloc(sizeof(wise_device));
if ( device!=NULL )
{
ba2str(&(inquiry+index)->bdaddr,device->BT_address);
if ( search_service(manager,device,logger)!=WISE_OK ) free(device);
else add_server(manager,device);
}
}
free(inquiry);
close(socket);
return WISE_OK;
}

S60 Platform

struct TDeviceData
{
THostName iDeviceName;
TBTDevAddr iDeviceAddr;
TUint iDeviceServicePort;
};
 
typedef RPointerArray<TDeviceData> TDeviceDataList;
TDeviceDataList iFoundDevices;
void CWISEConnectionManager::SearchServersL()
{
RHostResolver resolver;
TInquirySockAddr addr;
TNameEntry entry;
 
// reset search arrays
iFoundDevices.ResetAndDestroy();
 
// load protocol for discovery
TProtocolDesc pdesc;
User::LeaveIfError(iSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc));
 
// initialize host resolver
User::LeaveIfError(resolver.Open(iSocketServ, pdesc.iAddrFamily, pdesc.iProtocol));
 
// start device discovery by invoking remote address lookup
addr.SetIAC(KGIAC);
addr.SetAction(KHostResInquiry|KHostResName|KHostResIgnoreCache);
TInt error = resolver.GetByAddress(addr, entry);
while ( error==KErrNone )
{
TDeviceData *devData = new (ELeave) TDeviceData();
devData->iDeviceName = entry().iName;
devData->iDeviceAddr =
static_cast<TBTSockAddr>(entry().iAddr).BTAddr();
 
devData->iDeviceServicePort = 0;
iFoundDevices.Append(devData);
error = resolver.Next(entry);
}
resolver.Close();
}

Links

This page was last modified on 30 May 2013, at 06:39.
64 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×