Registering Services

Services must be registered in the SDP database before they can be found by an SDP Agent query.

How to register a service in the database

After connecting to the SDP database, a service record can be created. You do this by supplying the UUID for the service class of the record. As the service class may be a single UUID or a list of UUIDs in the form of a DES, there are two overloaded functions.

The steps to register a service are as follows:

  1. Create a blank service record object, TSdpServRecordHandle.

  2. If the service class attribute should be a single UUID, create and set a TUUID object. If the attribute should be a list of UUIDs, create a attribute list object, CSdpAttrValueDES or CSdpAttrValueDEA, and call MSdpElementBuilder::BuildUUIDL() repeatedly to add UUIDs to the list.

  3. Call RSdpDatabase::CreateServiceRecordL() on an open subsession. On return, the record handle object holds a handle to the service record.

Registering a single service class

The following example creates a service record with a single service class.

  1. Create blank record handle

    // Assumes sdpSession is an open session to the database
    TSdpServRecordHandle recordHandle = 0;
  2. Create the service class UUIDs

    TUUID uuid(0x20000);
  3. Enter record into the database

    sdpSubSession.CreateServiceRecordL(uuid, recordHandle);

Registering a service class list

The following example creates a service record with a list of service classes.

  1. Create a blank record handle

    TSdpServRecordHandle recordHandle = 0;
  2. Create a list of service class UUIDs

    CSdpAttrValueDES* UUIDlist = CSdpAttrValueDES::NewDESL(NULL);
    CleanupStack::PushL(UUIDlist);
    UUIDlist
        ->StartListL()
            ->BuildUUIDL(TUUID(TUint32(0x20002000)))
            ->BuildUUIDL(TUUID(TUint32(0x11112222), TUint32(0x33334444), 
                                  TUint32(0x55556666), TUint32(0x77778888)))
            ->BuildUUIDL(TUUID(TUint32(0x40000)))
        ->EndListL();
    
  3. Enter record into the database

    sdpSubSession.CreateServiceRecordL(*UUIDlist, recordHandle);
    CleanupStack::PopL(); // UUIDlist

Note

The examples shows UUIDs of varying length. Both 16- and 32-bit integers may be used, which are assumed to be offsets from the Bluetooth base UUID.

Where next?

The complete set of Service Discovery Database tutorials are shown below:

  1. Connecting to the service discovery database

  2. Handling SDP attributes

  3. Registering Services - This document

  4. Setting service record attributes

  5. SDP Service records and attributes

Also refer to the Bluetooth Service Discovery Database overview and the Bluetooth SDP Overview for additional background information.