obex/obexprotocol/obex/test/tobex/btutils.cpp
changeset 54 4dc88a4ac6f4
parent 52 866b4af7ffbe
child 57 f6055a57ae18
equal deleted inserted replaced
52:866b4af7ffbe 54:4dc88a4ac6f4
     1 // Copyright (c) 2005-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 <es_sock.h>
       
    17 #include <ir_sock.h>
       
    18 #include <bautils.h>
       
    19 #include <usbman.h>
       
    20 #include <d32usbc.h>
       
    21 #include "btutils.h" 
       
    22 #include "btextnotifiers.h"
       
    23 
       
    24 #define EPOCIDENT _L8("EPOC32 ER5")
       
    25 
       
    26 
       
    27 CRFCOMMServiceFinder* CRFCOMMServiceFinder::NewL(	const TUUID& aServiceClass,
       
    28 							const TBTDevAddr& aDevAddr,
       
    29 							MRFCOMMServiceSeeker& aSeeker)
       
    30 	{
       
    31 	CRFCOMMServiceFinder* self= new (ELeave) CRFCOMMServiceFinder(aSeeker);
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL(aDevAddr, aServiceClass);
       
    34 	CleanupStack::Pop();
       
    35 	return (self);
       
    36 	}
       
    37 
       
    38 
       
    39 CRFCOMMServiceFinder::~CRFCOMMServiceFinder()
       
    40 	{
       
    41 	delete iPattern;
       
    42 	delete iAgent;
       
    43 	}
       
    44 
       
    45 	
       
    46 CRFCOMMServiceFinder::CRFCOMMServiceFinder(MRFCOMMServiceSeeker& aSeeker)
       
    47 : iSeeker(aSeeker)
       
    48 	{
       
    49 
       
    50 	}
       
    51 
       
    52 void CRFCOMMServiceFinder::ConstructL(const TBTDevAddr& aDevAddr, const TUUID& aServiceClass)
       
    53 	{
       
    54 	iPattern=CSdpSearchPattern::NewL();
       
    55 	iPattern->AddL(aServiceClass);
       
    56 	iAgent=CSdpAgent::NewL(*this, aDevAddr);
       
    57 	iAgent->SetRecordFilterL(*iPattern);
       
    58 	}
       
    59 
       
    60 void CRFCOMMServiceFinder::FindPortL()
       
    61 	{
       
    62 	iSearchState = ENoUuidFound;	
       
    63 	iProfileVersion = -1;	// version is unit16 in the spec - so this is an invalid version	
       
    64 							// that will never be returned from a query	
       
    65 	iPort=0xFF;	// 0xFF will never be returned from a query, 	
       
    66 				// because RFCOMM server channels only go up to 30.
       
    67 	iAgent->NextRecordRequestL();
       
    68 	}
       
    69 
       
    70 void CRFCOMMServiceFinder::NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt /*aTotalRecordsCount*/) 
       
    71 	{
       
    72 	if (aError == KErrNone)
       
    73 		{
       
    74 		//We have the record, kick off the attribute request
       
    75 		TRAP(aError,AttributeRequestL(aHandle)); 
       
    76 		}
       
    77 
       
    78 	if (aError != KErrNone)
       
    79 		{
       
    80 		iSeeker.SearchResult(aError, 0, 0);
       
    81 		}
       
    82 	}
       
    83 
       
    84 void CRFCOMMServiceFinder::AttributeRequestL(TSdpServRecordHandle aHandle) 	
       
    85 	{	
       
    86 	CSdpAttrIdMatchList* attrList = CSdpAttrIdMatchList::NewL();	
       
    87 	CleanupStack::PushL(attrList);	
       
    88 	attrList->AddL(TAttrRange(KSdpAttrIdProtocolDescriptorList)); 	
       
    89 	attrList->AddL(TAttrRange(KSdpAttrIdBluetoothProfileDescriptorList)); 	
       
    90 
       
    91 	iAgent->AttributeRequestL(this, aHandle, *attrList); 	
       
    92 
       
    93 	CleanupStack::PopAndDestroy(attrList);	
       
    94 	}
       
    95 
       
    96 MSdpElementBuilder* CRFCOMMServiceFinder::BuildUintL(const TDesC8& aUint)
       
    97 	{
       
    98 	switch (iSearchState)	
       
    99 		{	
       
   100 	// Extract port number	
       
   101 	case EFoundRfcommUuid:	
       
   102 		iPort = SdpUtil::GetUint(aUint);
       
   103 		break;	
       
   104 
       
   105 	// Extract version number	
       
   106 	case EFoundProfileUuid:	
       
   107 		iProfileVersion = SdpUtil::GetUint(aUint);
       
   108 		break;	
       
   109 		}	
       
   110 
       
   111 	// Reset search state
       
   112 	iSearchState = ENoUuidFound;
       
   113 	return this;
       
   114 	}
       
   115  
       
   116 MSdpElementBuilder* CRFCOMMServiceFinder::BuildUUIDL(const TUUID& aUUID)
       
   117 	{
       
   118 	if ((aUUID == TUUID(3)) && (iPort == 0xFF)) 	
       
   119 		{	
       
   120 		// Found RFCOMM so need to get the port	
       
   121 		iSearchState = EFoundRfcommUuid;	
       
   122 		}	
       
   123 	if ((aUUID == iPattern->At(0)) && (iProfileVersion == -1))  	
       
   124 		{	
       
   125 		// Found Profile so need to get the version	
       
   126 		iSearchState = EFoundProfileUuid;	
       
   127 		}
       
   128 
       
   129 	return this;				
       
   130 	}
       
   131 
       
   132 //The search can be concluded by calling back when AttributeRequestComplete gets called;
       
   133 void CRFCOMMServiceFinder::AttributeRequestComplete(TSdpServRecordHandle /*aHandle*/, TInt aError)
       
   134 	{
       
   135 	// Check if the RFCOMM port was found, send a suitable error code if not	
       
   136 	if ((aError == KErrNone) && (iPort == 0xFF))	
       
   137 		{	
       
   138 		aError = KErrNotFound;	
       
   139 		}	
       
   140 
       
   141 	iSeeker.SearchResult(aError, iPort, iProfileVersion);
       
   142 	}
       
   143 
       
   144 
       
   145 
       
   146