bluetoothengine/headsetsimulator/profiles/hfpprofile/src/hfpsdp.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
equal deleted inserted replaced
59:02103bf20ee5 60:90dbfc0435e3
       
     1 /* 
       
     2  *
       
     3  * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of the License "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Original Contributors:
       
    11  * Comarch S.A. - original contribution.
       
    12  *
       
    13  * Contributors:
       
    14  *
       
    15  * Description:
       
    16  *
       
    17  */
       
    18 
       
    19 #include "hfpsdp.h"
       
    20 #include "debug.h"
       
    21 
       
    22 CHsHFPSDP* CHsHFPSDP::NewL()
       
    23     {
       
    24     CHsHFPSDP *self = CHsHFPSDP::NewLC();
       
    25     CleanupStack::Pop(self);
       
    26     return self;
       
    27     }
       
    28 
       
    29 CHsHFPSDP* CHsHFPSDP::NewLC()
       
    30     {
       
    31     CHsHFPSDP *self = new (ELeave) CHsHFPSDP();
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     return self;
       
    35     }
       
    36 
       
    37 CHsHFPSDP::CHsHFPSDP()
       
    38     {
       
    39     }
       
    40 
       
    41 CHsHFPSDP::~CHsHFPSDP()
       
    42     {
       
    43     TRACE_FUNC_ENTRY
       
    44     iSdpDatabase.Close();
       
    45     iSdp.Close();
       
    46     TRACE_FUNC_EXIT
       
    47     }
       
    48 
       
    49 void CHsHFPSDP::CreateSdpRecordL()
       
    50     {
       
    51     TRACE_FUNC_ENTRY
       
    52 
       
    53     if (iSdpRecordHandle)
       
    54         {
       
    55         User::Leave(KErrAlreadyExists);
       
    56         }
       
    57 
       
    58     // create service class id list
       
    59     CSdpAttrValueDES* serviceClassIdList = CSdpAttrValueDES::NewDESL(NULL);
       
    60     CleanupStack::PushL(serviceClassIdList);
       
    61 
       
    62     // add Hands-Free UID (0x111E) and Generic Audio UID (0x1203)
       
    63     serviceClassIdList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    64             TUUID(KHsHandsFreeUid))->EndListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    65             TUUID(KHsHfpGenericAudioUid))->EndListL()->EndListL();
       
    66 
       
    67     // register record in database
       
    68     iSdpDatabase.CreateServiceRecordL(*serviceClassIdList, iSdpRecordHandle);
       
    69     CleanupStack::PopAndDestroy(serviceClassIdList);
       
    70 
       
    71     CSdpAttrValueDES* protocolDescList = CSdpAttrValueDES::NewDESL(NULL);
       
    72     CleanupStack::PushL(protocolDescList);
       
    73 
       
    74     // add protocol descriptor list to inform clients about listening channel
       
    75     protocolDescList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    76             TUUID(KL2CAPUUID))->EndListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    77             TUUID(KRFCommUUID))->BuildUintL(TSdpIntBuf<TUint8> (iServicePort))->EndListL()->EndListL();
       
    78 
       
    79     // update record in database
       
    80     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
       
    81             KSdpAttrIdProtocolDescriptorList, *protocolDescList);
       
    82     CleanupStack::PopAndDestroy(protocolDescList);
       
    83 
       
    84     CSdpAttrValueDES* bluetoothProfileDescList = CSdpAttrValueDES::NewDESL(
       
    85             NULL);
       
    86     CleanupStack::PushL(bluetoothProfileDescList);
       
    87 
       
    88     // add info of bluetooth profile - headset profile (0x111E) version 1.5 (0x0105)
       
    89     bluetoothProfileDescList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    90             TUUID(KHsHandsFreeUid))->BuildUintL(TSdpIntBuf<TUint16> (
       
    91             KHsHfpProfileVersion))->EndListL()->EndListL();
       
    92 
       
    93     // update record in database
       
    94     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
       
    95             KSdpAttrIdBluetoothProfileDescriptorList,
       
    96             *bluetoothProfileDescList);
       
    97     CleanupStack::PopAndDestroy(bluetoothProfileDescList);
       
    98 
       
    99     // set service name and update record
       
   100     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
       
   101             KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
       
   102             KHsServiceNameHandsFree);
       
   103 
       
   104     // set supported features
       
   105     CSdpAttrValueUint* supportedFeatures = CSdpAttrValueUint::NewUintL(
       
   106             TSdpIntBuf<TUint16> (KHsSupportedFeaturesValue));
       
   107     CleanupStack::PushL(supportedFeatures);
       
   108     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KHsSupportedFeaturesUid,
       
   109             *supportedFeatures);
       
   110     CleanupStack::PopAndDestroy(supportedFeatures);
       
   111 
       
   112     // set availability to true
       
   113     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
       
   114             KSdpAttrIdServiceAvailability, 0xFF);
       
   115     iSdpDatabase.UpdateAttributeL(iSdpRecordHandle,
       
   116             KSdpAttrIdServiceRecordState, 1);
       
   117     TRACE_INFO( _L("HFP SDP registering OK") );
       
   118     TRACE_FUNC_EXIT
       
   119     }
       
   120 
       
   121 void CHsHFPSDP::DeleteSdpRecordL()
       
   122     {
       
   123     TRACE_FUNC_ENTRY
       
   124 
       
   125     if (iSdpRecordHandle)
       
   126         {
       
   127         iSdpDatabase.DeleteRecordL(iSdpRecordHandle);
       
   128         iSdpRecordHandle = 0;
       
   129         }
       
   130 
       
   131     TRACE_FUNC_EXIT
       
   132     }
       
   133 
       
   134 void CHsHFPSDP::ConstructL()
       
   135     {
       
   136     TRACE_FUNC_ENTRY
       
   137 
       
   138     User::LeaveIfError(iSdp.Connect());
       
   139 
       
   140     User::LeaveIfError(iSdpDatabase.Open(iSdp));
       
   141 
       
   142     TRACE_FUNC_EXIT
       
   143     }