Thursday, January 22, 2015

HOW TO SEARCH DEVICE THROUGH BLUETOOTH



coecntrl.h
es_sock.h
btdevice.h
bt_sock.h
btsdp.h
bttypes.h


struct TDeviceData
{
 THostName iDeviceName;
 TBTDevAddr iDeviceAddr;
 TUint iDeviceServicePort;
};


// Literals
_LIT(KBTLinkManagerTxt,"BTLinkManager");

TInquirySockAddr iAddr; //bluetooth.lib
TNameEntry iEntry;
TRequestStatus iStatus;
RSocketServ aSocketServ; //esock.lib
TProtocolDesc pdesc;
RHostResolver aResolver;

User::LeaveIfError(aSocketServ.Connect());
User::LeaveIfError(aSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc));
User::LeaveIfError(aResolver.Open(aSocketServ, pdesc.iAddrFamily, pdesc.iProtocol));

iAddr.SetIAC( KGIAC );
iAddr.SetAction(KHostResInquiryKHostResNameKHostResIgnoreCache);
aResolver.GetByAddress(iAddr, iEntry, iStatus);
User::WaitForRequest(iStatus);
if(iStatus==KErrNone)
{
 TDeviceData *devData = new (ELeave) TDeviceData();
 devData->iDeviceName = iEntry().iName;
 devData->iDeviceAddr =
 static_cast(iEntry().iAddr).BTAddr();
}

0 comments:

Post a Comment