Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:05, 2 May 2008.

CS000936 - Discovering Bluetooth devices

From Forum Nokia Wiki


ID CS000936 Creation date May 2, 2008
Platform S60 3rd Edition, MR Tested on devices Nokia N95
Category Symbian C++ Subcategory Bluetooth


Keywords (APIs, classes, methods, functions): RHostResolver, RSocketServ, TInquirySockAddr, RHostResolver::GetByAddress(), RSocketServ::FindProtocol()

Overview

RHostResolver provides an interface to host name resolution services, such as DNS, that may be provided by certain protocol modules.

The interface provides functions to access the following facilities:

  • Obtaining names from addresses
  • Obtaining addresses from names
  • Getting and setting local host name

Before using any service, a connection to a socket server session must be established.

Each function is available in both synchronous and asynchronous versions.

The following codes show how to search Bluetooth devices with RHostResolver.

MMP file

The following capabilities and libraries are required:

CAPABILITY    LocalServices
LIBRARY       esock.lib
LIBRARY       bluetooth.lib

Header file

#include <es_sock.h>
#include <bt_sock.h>
 
RSocketServ         iSocketServ;
RHostResolver       iResolver;
TInquirySockAddr    iAddr;

Source file

CMyDeviceDiscoverer must be an active object (derived from CActive).

_LIT(KBTLinkManagerTxt,"BTLinkManager");
 
 
void CMyDeviceDiscoverer::ConstructL()
    {
    ...
    // Get socket server session
    User::LeaveIfError(iSocketServ.Connect());
    ...
    }
 
void CMyDeviceDiscoverer::DiscoverDevicesL()
    {
    if (!IsActive())
        {
        // Load protocol for discovery
        TProtocolDesc pdesc;
        User::LeaveIfError(
            iSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc));
 
        // Initialize host resolver
        iResolver.Close();
        User::LeaveIfError(
            iResolver.Open(iSocketServ, pdesc.iAddrFamily, pdesc.iProtocol));
        
        // Start device discovery by invoking remote address lookup
        iAddr.SetIAC( KGIAC );
        iAddr.SetAction(KHostResInquiry|KHostResName|KHostResIgnoreCache);
        iResolver.GetByAddress(iAddr, iEntry, iStatus);
        SetActive();
        }
    else
        {
        User::Leave(KErrNotReady);
        }
    }
 
void CMyDeviceDiscoverer::RunL()
    {
    // RHostResolver.GetByAddress() has completed, process results
 
    if ( iStatus!=KErrNone )
        {
        // All devices find
        }
    else 
        {
        // New device data entry
 
        // Device name
        iEntry().iName;
 
        // Device address
        static_cast<TBTSockAddr>(iEntry().iAddr).BTAddr();
        
        // Get next discovered device
        iResolver.Next(iEntry, iStatus);
        SetActive();
        }
    }
 
void CMyDeviceDiscoverer::DoCancel()
    {
    iResolver.Cancel();
    }
 
CMyDeviceDiscoverer::~CMyDeviceDiscoverer()
    { 
    Cancel();
    iResolver.Close();
    }

Postconditions

CMyDeviceDiscoverer finds existing Bluetooth devices.

See also

CS000937 - Discovering Bluetooth services

CS000938 - Advertising Bluetooth services

CS000939 - Establishing a Bluetooth connection

KIS000330 - RHostResolver and redundant display of access point selection dialog

Example application

This code snippet has been used in the S60 Platform: Bluetooth Point-to-multipoint Example application.

 
Powered by MediaWiki