pimprotocols/pbap/server/pbapsdp.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <btsdp.h>
       
    17 
       
    18 #include "pbapserver.h"
       
    19 #include "btaccesshostlog.h"
       
    20 
       
    21 // PBAP Profile Description UUID
       
    22 const TUint16 KPbapProfileUUID	= 0x1130;
       
    23 
       
    24 const TUint16 KPbapProfileVersion			= 0x0100;
       
    25 const TUint8 KPbapLocalPhonebookRepository 	= 0x01;
       
    26 
       
    27 const TSdpAttributeID KPbapSdpAttrIdSupportedRepositories = 0x0314;
       
    28 
       
    29 _LIT8(KPbapProviderName,	"Symbian OS");
       
    30 _LIT8(KPbapServiceName,		"Phonebook access PSE");
       
    31 
       
    32 
       
    33 
       
    34 void CPbapServer::RegisterWithSdpL(TUint aRfcommChannel)
       
    35 	{
       
    36 	LOG_FUNC
       
    37 	// must not call this function repeatedly without freeing record between calls
       
    38 	if(iSdpRecordHandle)
       
    39 		{
       
    40 		__ASSERT_DEBUG(EFalse, Panic(EPbapServerPanicSDPRecordExists));
       
    41 		User::Leave(KErrAlreadyExists);
       
    42 		}
       
    43 	if (iSdpRecordHandle)
       
    44 		{
       
    45 		return;
       
    46 		}
       
    47 		
       
    48 	// connect to SDP server and database
       
    49 	User::LeaveIfError(iSdpServer.Connect());
       
    50 	User::LeaveIfError(iSdpDatabase.Open(iSdpServer));
       
    51 	
       
    52 	// create the record
       
    53 	iSdpDatabase.CreateServiceRecordL(TUUID(KPbapPseUUID), iSdpRecordHandle);
       
    54 		
       
    55 	CSdpAttrValue* attrVal;
       
    56 	CSdpAttrValueDES* attrValDES;
       
    57 
       
    58 	// protocol Descriptor List
       
    59 	attrValDES = CSdpAttrValueDES::NewDESL(NULL);
       
    60 	CleanupStack::PushL(attrValDES);		
       
    61 	attrValDES
       
    62 		->StartListL()
       
    63 		->BuildDESL()
       
    64 			->StartListL()
       
    65 			->BuildUUIDL(TUUID(KL2CAPUUID))
       
    66 			->EndListL()
       
    67 		->BuildDESL()
       
    68 			->StartListL()
       
    69 			->BuildUUIDL(TUUID(KRFCommUUID))
       
    70 			->BuildUintL(TSdpIntBuf<TUint8>(aRfcommChannel)) // channel read from obex
       
    71 			->EndListL()
       
    72 		->BuildDESL()
       
    73 			->StartListL()
       
    74 			->BuildUUIDL(TUUID(KObexProtocolUUID))
       
    75 			->EndListL()	
       
    76 		->EndListL();
       
    77 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdProtocolDescriptorList, *attrValDES);
       
    78 	CleanupStack::PopAndDestroy(attrValDES);
       
    79 
       
    80 
       
    81 	// language
       
    82 	attrValDES = CSdpAttrValueDES::NewDESL(NULL);
       
    83 	CleanupStack::PushL(attrValDES);
       
    84 	attrValDES
       
    85 		->StartListL()
       
    86 		->BuildUintL(TSdpIntBuf<TUint16>(KLanguageEnglish))
       
    87 		->BuildUintL(TSdpIntBuf<TUint16>(KSdpAttrIdCharacterEncodingUTF8))
       
    88 		->BuildUintL(TSdpIntBuf<TUint16>(KSdpAttrIdBasePrimaryLanguage))
       
    89 		->EndListL();
       
    90 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdLanguageBaseAttributeIDList, *attrValDES);
       
    91 	CleanupStack::PopAndDestroy(attrValDES);
       
    92 
       
    93 
       
    94 	// BT Profile Description
       
    95 	attrValDES = CSdpAttrValueDES::NewDESL(NULL);
       
    96 	CleanupStack::PushL(attrValDES);
       
    97 	attrValDES
       
    98 		->StartListL()
       
    99 		->BuildDESL()
       
   100 			->StartListL()
       
   101 			->BuildUUIDL(TUUID(KPbapProfileUUID))
       
   102 			->BuildUintL(TSdpIntBuf<TUint16>(KPbapProfileVersion))
       
   103 			->EndListL()
       
   104 		->EndListL();
       
   105 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdBluetoothProfileDescriptorList, *attrValDES);
       
   106 	CleanupStack::PopAndDestroy(attrValDES);
       
   107 
       
   108 	// Browse Group List
       
   109 	attrValDES = CSdpAttrValueDES::NewDESL(NULL);
       
   110 	CleanupStack::PushL(attrValDES);
       
   111 	attrValDES
       
   112 		->StartListL()
       
   113 		->BuildUUIDL(TUUID(TUint16(KPublicBrowseGroupUUID))) // Public Browse Group
       
   114 		->EndListL();
       
   115 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdBrowseGroupList, *attrValDES);
       
   116 	CleanupStack::PopAndDestroy(attrValDES);
       
   117 
       
   118 	// provider name
       
   119 	attrVal = CSdpAttrValueString::NewStringL(KPbapProviderName);
       
   120 	CleanupStack::PushL(attrVal);
       
   121 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetProviderName, *attrVal);
       
   122 	CleanupStack::PopAndDestroy(attrVal);
       
   123 
       
   124 
       
   125 	// service name
       
   126 	attrVal = CSdpAttrValueString::NewStringL(KPbapServiceName);
       
   127 	CleanupStack::PushL(attrVal);
       
   128 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName, *attrVal);
       
   129 	CleanupStack::PopAndDestroy(attrVal);
       
   130 
       
   131 
       
   132 	// supported repositories (currently no support for SIM repositories)
       
   133 	TUint8 supportedRepositories = KPbapLocalPhonebookRepository;
       
   134 		
       
   135 	attrVal = CSdpAttrValueUint::NewUintL(TSdpIntBuf<TUint8>(supportedRepositories));
       
   136 	CleanupStack::PushL(attrVal);
       
   137 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KPbapSdpAttrIdSupportedRepositories, *attrVal);
       
   138 	CleanupStack::PopAndDestroy(attrVal);
       
   139 	// availablity
       
   140 	UpdateAvailability(EPbapAvailable);
       
   141 	}
       
   142 
       
   143 void CPbapServer::UpdateAvailability(TPbapAvailability aAvailability)
       
   144 	{
       
   145 	// Non-leaving version of UpdateAvailability, called in place of Leaving
       
   146 	// version, as the service availabilty is an optional part of PBAP and a
       
   147 	// failure to update the SDP does not affect the functionality of the
       
   148 	// profile as a whole
       
   149 	TRAP_IGNORE(DoUpdateAvailabilityL(aAvailability));
       
   150 	}
       
   151 
       
   152 void CPbapServer::DoUpdateAvailabilityL(TPbapAvailability aAvailability)
       
   153 	{
       
   154 	iSdpDatabase.DeleteAttribute(iSdpRecordHandle, KSdpAttrIdServiceAvailability);
       
   155 	CSdpAttrValue* attrVal = CSdpAttrValueUint::NewUintL(TSdpIntBuf<TUint8>(aAvailability));
       
   156 	CleanupStack::PushL(attrVal);
       
   157 	iSdpDatabase.UpdateAttributeL(iSdpRecordHandle, KSdpAttrIdServiceAvailability, *attrVal);
       
   158 	CleanupStack::PopAndDestroy(attrVal);
       
   159 	}
       
   160 
       
   161 void CPbapServer::ReleaseSdpRegistration()
       
   162 	{
       
   163 	LOG_FUNC
       
   164 	if(iSdpRecordHandle)
       
   165 		{
       
   166 		// delete the pbap sdp record
       
   167 		iSdpDatabase.DeleteRecord(iSdpRecordHandle);		
       
   168 		iSdpRecordHandle=0;
       
   169 		}
       
   170 	iSdpDatabase.Close();
       
   171 	iSdpServer.Close();	
       
   172 	}