Starting as Controller

The controller is the device that sends commands to a target device.

Intended Audience:

This tutorial is designed for Symbian licensees and 3rd party application developers.

Using the Controller

The following tasks will be covered in this tutorial:

  • Starting a Connectionless controller

  • Starting a Connection-Oriented controller

  • Stopping a controller

Basic procedure

The high level steps to start a controller are:

  • Create the Controller interface

  • Open a controller session on the server. This will either be:

    • Connectionless

      This would be enough to create a connectionless controller.

    • Connection-oriented

      If you are starting a connection-oriented controller you will need to know the following:

      • Device address

      • Bearer

Note: Starting the Bluetooth stack and setting up the sockets, housekeeping tasks usually associated with Bluetooth components, are wrapped up and taken care of in the background by the Remote Control Framework.

Starting a connectionless controller

Create a controller interface by instantiating an interface selector using CRemConInterfaceSelector::NewL(), as shown here:

CRemConInterfaceSelector* iInterfaceSelector;
iInterfaceSelector = CRemConInterfaceSelector::NewL();

Create a core remote control API controller and add the interface selector created above as shown here:

CRemConCoreApiController* iCoreController;
iCoreController = CRemConCoreApiController::NewL(*iInterfaceSelector, *this);

Open the interface created above using CRemConInterfaceSelector::OpenControllerL().

iInterfaceSelector->OpenControllerL();

The Target Selector Plugin (TSP) discovers the bearer and device address of target devices as required.

Starting a Connection-Oriented controller

The first part of starting your Connection-Oriented controller is the same as that described above for starting a connectionless controller, but to go Connection-Oriented you will need to provide two additional pieces of information, the device address and the bearer.

The following code, which constructs a TUid, shows how to set information about the AVRCP bearer (it may be different for other bearers):

...
 TUid iBearerUid;
 RBuf8 iBearerData;
 iBearerUid = TUid::Uid(KAvrcpBearerUid);

To get the device address you can either use the SDP, a notifier, or the following:

GetDeviceAddressL()
    {
    // MTestManager iManager;
    iManager.MtmWrite(
    _L8( "Type device address and press enter\n0x" ) );
    // Read address in unicode as human readable
    TBuf<12> buf;
    iManager.MtmRead( buf );
    // Translate to machine readable
    TBTDevAddr btAddr;
    LEAVEIFERRORL( btAddr.SetReadable( buf ) );
    // Store as 8 bit machine readable
    iBearerData.Close();
    iBearerData.CreateL( btAddr.Des() );
    }
Note: The above uses test code. In a real application, you would need a UI instead of the console.

Now that you have the device address and bearer information you can start the Connection-Oriented controller by adding the bearer and Bluetooth device address information to the addr using the TRemConAddress::BearerUid() and TRemConAddress::Addr() functions as follows:

TRemConAddress addr;
addr.BearerUid() = iBearerUid;
addr.Addr() = iBearerData;
iInterfaceSelector->GoConnectionOrientedL( addr );

The CRemConInterfaceSelector::GoConnectionOrientedL() function makes the controller Connection-Oriented.

Switching to Connectionless

It is possible to switch a Connection-Oriented controller to connectionless if necessary. The CRemConInterfaceSelector::GoConnectionlessL() is used as shown here:

iInterfaceSelector->GoConnectionlessL();

Of course you can also switch back to a Connection-Oriented controller as needed.

Stopping a controller

To stop your controller use:

delete iInterfaceSelector;