bluetoothengine/headsetsimulator/profiles/hfpprofile/src/hfpsdp.cpp
author michal.sulewski
Wed, 15 Sep 2010 15:59:44 +0200
branchheadsetsimulator
changeset 60 90dbfc0435e3
permissions -rw-r--r--
source code commit

/* 
 *
 * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Original Contributors:
 * Comarch S.A. - original contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

#include "hfpsdp.h"
#include "debug.h"

CHsHFPSDP* CHsHFPSDP::NewL()
    {
    CHsHFPSDP *self = CHsHFPSDP::NewLC();
    CleanupStack::Pop(self);
    return self;
    }

CHsHFPSDP* CHsHFPSDP::NewLC()
    {
    CHsHFPSDP *self = new (ELeave) CHsHFPSDP();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

CHsHFPSDP::CHsHFPSDP()
    {
    }

CHsHFPSDP::~CHsHFPSDP()
    {
    TRACE_FUNC_ENTRY
    iSdpDatabase.Close();
    iSdp.Close();
    TRACE_FUNC_EXIT
    }

void CHsHFPSDP::CreateSdpRecordL()
    {
    TRACE_FUNC_ENTRY

    if (iSdpRecordHandle)
        {
        User::Leave(KErrAlreadyExists);
        }

    // create service class id list
    CSdpAttrValueDES* serviceClassIdList = CSdpAttrValueDES::NewDESL(NULL);
    CleanupStack::PushL(serviceClassIdList);

    // add Hands-Free UID (0x111E) and Generic Audio UID (0x1203)
    serviceClassIdList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
            TUUID(KHsHandsFreeUid))->EndListL()->BuildDESL()->StartListL()->BuildUUIDL(
            TUUID(KHsHfpGenericAudioUid))->EndListL()->EndListL();

    // register record in database
    iSdpDatabase.CreateServiceRecordL(*serviceClassIdList, iSdpRecordHandle);
    CleanupStack::PopAndDestroy(serviceClassIdList);

    CSdpAttrValueDES* protocolDescList = CSdpAttrValueDES::NewDESL(NULL);
    CleanupStack::PushL(protocolDescList);

    // add protocol descriptor list to inform clients about listening channel
    protocolDescList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
            TUUID(KL2CAPUUID))->EndListL()->BuildDESL()->StartListL()->BuildUUIDL(
            TUUID(KRFCommUUID))->BuildUintL(TSdpIntBuf<TUint8> (iServicePort))->EndListL()->EndListL();

    // update record in database
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
            KSdpAttrIdProtocolDescriptorList, *protocolDescList);
    CleanupStack::PopAndDestroy(protocolDescList);

    CSdpAttrValueDES* bluetoothProfileDescList = CSdpAttrValueDES::NewDESL(
            NULL);
    CleanupStack::PushL(bluetoothProfileDescList);

    // add info of bluetooth profile - headset profile (0x111E) version 1.5 (0x0105)
    bluetoothProfileDescList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
            TUUID(KHsHandsFreeUid))->BuildUintL(TSdpIntBuf<TUint16> (
            KHsHfpProfileVersion))->EndListL()->EndListL();

    // update record in database
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
            KSdpAttrIdBluetoothProfileDescriptorList,
            *bluetoothProfileDescList);
    CleanupStack::PopAndDestroy(bluetoothProfileDescList);

    // set service name and update record
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
            KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
            KHsServiceNameHandsFree);

    // set supported features
    CSdpAttrValueUint* supportedFeatures = CSdpAttrValueUint::NewUintL(
            TSdpIntBuf<TUint16> (KHsSupportedFeaturesValue));
    CleanupStack::PushL(supportedFeatures);
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KHsSupportedFeaturesUid,
            *supportedFeatures);
    CleanupStack::PopAndDestroy(supportedFeatures);

    // set availability to true
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
            KSdpAttrIdServiceAvailability, 0xFF);
    iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
            KSdpAttrIdServiceRecordState, 1);
    TRACE_INFO( _L("HFP SDP registering OK") );
    TRACE_FUNC_EXIT
    }

void CHsHFPSDP::DeleteSdpRecordL()
    {
    TRACE_FUNC_ENTRY

    if (iSdpRecordHandle)
        {
        iSdpDatabase.DeleteRecordL(iSdpRecordHandle);
        iSdpRecordHandle = 0;
        }

    TRACE_FUNC_EXIT
    }

void CHsHFPSDP::ConstructL()
    {
    TRACE_FUNC_ENTRY

    User::LeaveIfError(iSdp.Connect());

    User::LeaveIfError(iSdpDatabase.Open(iSdp));

    TRACE_FUNC_EXIT
    }