Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to inquire about remote devices

Each Bluetooth device has a 48-bit unique address built into its hardware. A basic inquiry for devices in range returns zero or more of these addresses.

As well as an address, a Bluetooth device has a text name suitable for display to users. If you want to display a list of available devices to the user, you will also need to obtain these names.

The address and the name inquiries can occur simultaneously, if the underlying hardware supports this. Otherwise, the address inquiry must finish before the name request can be issued over the air.

Address and name inquiries are performed through the generic EPOC sockets class RHostResolver. A specialist Bluetooth sockets address class, TInquirySockAddr, which encapsulates Bluetooth address, Inquiry Access Code, and service and device classes, is provided for use with such inquiries.


Getting the addresses of remote devices

To inquire for the addresses of remote devices, take the following steps:

  1. Connect to the Sockets Server (RSocketServ), and then select the protocol to be used using RSocketServ::FindProtocol(). Address and name queries are supplied by the stack's BTLinkManager protocol layer, so select this.

  2. Create and initialise an RHostResolver object.

  3. Set the TInquirySockAddr parameter for the inquiry: for address inquiries, the KHostResInquiry flag must be set through TInquirySockAddr::SetAction().

    The query can then be started with RHostResolver::GetByAddress().

  4. When GetByAddress() completes, it fills in a TNameEntry object with the address and class of the first device found (or is undefined if no device was found).

  5. To get all the devices discovered, call RHostResolver::Next() repeatedly until KErrHostResNoMoreResults is returned.

Example

The following example shows how to start a remote device address inquiry.

// 1. Connect to the socket server
RSocketServ socketServ;
socketServ.Connect();
TProtocolDesc pInfo;
_LIT(KL2Cap, "BTLinkManager");
User::LeaveIfError(socketServ.FindProtocol(KL2Cap,pInfo));

// 2. Create and initialise an RHostResolver
RHostResolver hr;
User::LeaveIfError(hr.Open(socketServ,pInfo.iAddrFamily,pInfo.iProtocol));

// 3. Set up a discovery query and start it
TInquirySockAddr addr;
TNameEntry name;
addr.SetIAC(KGIAC);
addr.SetAction(KHostResInquiry);
TRequestStatus status;
hr.GetByAddress(addr, entry, status);
User::WaitForRequest(status);

// 4. Process the information returned in entry
...

Notes

[Top]


Getting the name of a remote device

The name of a remote device can be queried for by taking the same steps as for an address query, but setting the action flag of a TInquirySockAddr to KHostResName. The name is returned in the iName member accessed through the TNameEntry.

Example

// Now do name inquiry
addr.SetAction(KHostResName);
hr.GetByAddress(addr, entry, stat);
User::WaitForRequest(stat);
TPtrC deviceName;
if (stat == KErrNone)
     deviceName.Set(entry().iName);

Notes