I develope bluetooth application which will scan all neighbourhood bt device's and discover service attributes from those device's.
Steps are next: 1. Scan 1st device
2. Discover service atrributes from the 1 st
device
3. Scan next device
4. Discover service atrributes from the next
device
5. Scan.....
I use ListServicesL() method from the Discovery example to list service attributes. After ListServicesL() call I have a request which will wait until service attributes are listed before application will scan a new device.
My problem is that if I use request (WaitForRequest or SetActive)after ListServicesL() call, ListServicesL method will not list service attributes any more.
If I don't use request after ListServicesL, application will scan next device before service attributes are listed from the former device.
I have also edited little bit ListServicesL method so that it has now TRequestStatus& aObserverRequestStatus. Now it will chance aObserverRequestStatus if service listing is finished.
iAddr.SetIAC(KGIAC);
iAddr.SetAction(KHostResName|KHostResInquiry);
iHr.GetByAddress(iAddr, iRemoteDeviceName, iStatus);
User::WaitForRequest(iStatus);
iNotifier->Print(_L("Device's are scanned"));
if(iStatus.Int()==KErrNone)
{
iDevAddr = TBTSockAddr(iRemoteDeviceName ().iAddr).BTAddr();
deviceName.Set(iRemoteDeviceName().iName);
iNotifier->Print(deviceName);
PrintLine(_L("Retrieving services..."));
iDiscoverer->ListServicesL(iDevAddr,iStatus2);
User::WaitForRequest(iStatus2); /*or SetActive() if using active object. PROBLEM is here, this will block service listing*/
}
else
{
iNotifier->Print(_L("no bt device found!"));
}
if(iStatus.Int()==KErrNone)
{
while(iHr.Next(iRemoteDeviceName) != KErrHostResNoMoreResults)
{
iDevAddr = TBTSockAddr(iRemoteDeviceName().iAddr).BTAddr();
deviceName.Set(iRemoteDeviceName().iName);
iNotifier->Print(deviceName);
PrintLine(_L("Retrieving services..."));
iDiscoverer->ListServicesL(iDevAddr,iStatus2);
User::WaitForRequest(iStatus2); /*or SetActive() if using active object, PROBLE is here*/
}
iNotifier->Print(_L("no more bt device's found!"));
}
You can't have two Bluetooth requests like device inquiry and service discovery active at the same time. First discover *all* devices (until KErrEof == KErrHostResNoMoreResults) and keep a local copy of the found devices. Then go through the results and discover their services.