bluetoothengine/headsetsimulator/profiles/hspprofile/src/hspsdp.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 "hspsdp.h"
       
    20 #include "debug.h"
       
    21 
       
    22 CHsHSPSDP* CHsHSPSDP::NewL()
       
    23     {
       
    24 
       
    25     CHsHSPSDP *self = CHsHSPSDP::NewLC();
       
    26     CleanupStack::Pop( self );
       
    27 
       
    28     return self;
       
    29     }
       
    30 
       
    31 CHsHSPSDP* CHsHSPSDP::NewLC()
       
    32     {
       
    33     CHsHSPSDP *self = new ( ELeave ) CHsHSPSDP;
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     return self;
       
    37     }
       
    38 
       
    39 CHsHSPSDP::CHsHSPSDP()
       
    40     {
       
    41     }
       
    42 
       
    43 CHsHSPSDP::~CHsHSPSDP()
       
    44     {
       
    45     iSdpDatabase.Close();
       
    46     iSdp.Close();
       
    47     }
       
    48 
       
    49 void CHsHSPSDP::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 Headset UID (0x1131) and Generic Audio UID (0x1203)
       
    63     serviceClassIdList->StartListL()->BuildDESL()->StartListL()
       
    64             ->BuildUUIDL( TUUID( KHsHeadsetUid ) )->EndListL()->BuildDESL()
       
    65             ->StartListL()->BuildUUIDL( TUUID( KHsGenericAudioUid ) )
       
    66             ->EndListL()->EndListL();
       
    67 
       
    68     // register record in database
       
    69     iSdpDatabase.CreateServiceRecordL( *serviceClassIdList, iSdpRecordHandle );
       
    70     CleanupStack::PopAndDestroy( serviceClassIdList );
       
    71 
       
    72     CSdpAttrValueDES* protocolDescList = CSdpAttrValueDES::NewDESL( NULL );
       
    73     CleanupStack::PushL( protocolDescList );
       
    74 
       
    75     // add protocol descriptor list to inform clients about listening channel
       
    76     protocolDescList->StartListL()->BuildDESL()->StartListL()->BuildUUIDL(
       
    77             TUUID( KL2CAPUUID ) )->EndListL()->BuildDESL()->StartListL()
       
    78             ->BuildUUIDL( TUUID( KRFCommUUID ) )->BuildUintL(
       
    79             TSdpIntBuf <TUint8> ( iServicePort ) )->EndListL()->EndListL();
       
    80 
       
    81     // update record in database
       
    82     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
    83             KSdpAttrIdProtocolDescriptorList, *protocolDescList );
       
    84     CleanupStack::PopAndDestroy( protocolDescList );
       
    85 
       
    86     CSdpAttrValueDES* bluetoothProfileDescList = CSdpAttrValueDES::NewDESL(
       
    87             NULL );
       
    88     CleanupStack::PushL( bluetoothProfileDescList );
       
    89 
       
    90     /**
       
    91      * add info of bluetooth profile - headset profile (0x1108) version 1.2 
       
    92      * (0x0102) 
       
    93      */ 
       
    94     bluetoothProfileDescList->StartListL()->BuildDESL()->StartListL()
       
    95             ->BuildUUIDL( TUUID( KHsHeadsetProfileUid ) )
       
    96             ->BuildUintL( TSdpIntBuf <TUint16> ( KHsHeadsetProfileVersion ) )
       
    97             ->EndListL()->EndListL();
       
    98 
       
    99     // update record in database
       
   100     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
   101             KSdpAttrIdBluetoothProfileDescriptorList, 
       
   102             *bluetoothProfileDescList );
       
   103     CleanupStack::PopAndDestroy( bluetoothProfileDescList );
       
   104 
       
   105     // set service name and update record
       
   106     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
   107             KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
       
   108             KHsServiceNameHeadset );
       
   109 
       
   110     // set remote audio volume control to false
       
   111     CSdpAttrValueBoolean* remoteAudioVolumeControl =
       
   112             CSdpAttrValueBoolean::NewBoolL( ETrue );
       
   113     CleanupStack::PushL( remoteAudioVolumeControl );
       
   114     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
   115             KHsRemoteAudioVolumeControl, *remoteAudioVolumeControl );
       
   116     CleanupStack::PopAndDestroy( remoteAudioVolumeControl );
       
   117 
       
   118     // set availability to true
       
   119     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
   120             KSdpAttrIdServiceAvailability, 0xFF );
       
   121     iSdpDatabase.UpdateAttributeL( iSdpRecordHandle,
       
   122             KSdpAttrIdServiceRecordState, 1 );
       
   123 
       
   124     TRACE_FUNC_EXIT
       
   125     }
       
   126 
       
   127 void CHsHSPSDP::DeleteSdpRecordL()
       
   128     {
       
   129     TRACE_FUNC_ENTRY
       
   130 
       
   131     if ( iSdpRecordHandle )
       
   132         {
       
   133         iSdpDatabase.DeleteRecordL( iSdpRecordHandle );
       
   134         iSdpRecordHandle = 0;
       
   135         }
       
   136 
       
   137     TRACE_FUNC_EXIT
       
   138     }
       
   139 
       
   140 void CHsHSPSDP::ConstructL()
       
   141     {
       
   142     TRACE_FUNC_ENTRY
       
   143 
       
   144     User::LeaveIfError( iSdp.Connect() );
       
   145     User::LeaveIfError( iSdpDatabase.Open( iSdp ) );
       
   146 
       
   147     TRACE_FUNC_EXIT
       
   148     }