obex/obexprotocol/obexbttransport/src/ObexActiveRfcommConnector.cpp
changeset 57 f6055a57ae18
parent 0 d0791faffa3f
equal deleted inserted replaced
54:4dc88a4ac6f4 57:f6055a57ae18
       
     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 <obex/transport/obexconnector.h>
       
    17 #include "ObexActiveRfcommConnector.h"
       
    18 #include "connectobserver.h"
       
    19 #include "logger.h"
       
    20 #include "obexbtfaults.h"
       
    21 
       
    22 #ifdef __FLOG_ACTIVE
       
    23 _LIT8(KLogComponent, "RFCOMM");
       
    24 #endif
       
    25 
       
    26 #ifdef _DEBUG
       
    27 _LIT(KPanicCat, "ActiveRfcommConn");
       
    28 #endif
       
    29 
       
    30 CObexActiveRfcommConnector::CObexActiveRfcommConnector(MConnectObserver& aParent,
       
    31 													   RSocketServ& aSocketServ,
       
    32 													   RSocket& aSocket,
       
    33 													   const TProtocolDesc& aProtocolDesc,
       
    34 													   const TBTSockAddr& aAddr)
       
    35  :	CActive(EPriorityStandard),
       
    36 	iParent(aParent),
       
    37 	iSocketServ(aSocketServ),
       
    38 	iSocket(aSocket),
       
    39 	iProtocolDesc(aProtocolDesc),
       
    40 	iAddr(aAddr)
       
    41 	{
       
    42 	LOG_FUNC
       
    43 	LOG(_L8("\taAddr:"));
       
    44 	LOGHEXDESC(aAddr);
       
    45 
       
    46 	CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 CObexActiveRfcommConnector::~CObexActiveRfcommConnector()
       
    50 	{
       
    51 	LOG_FUNC
       
    52 
       
    53 	Cancel();
       
    54 	}
       
    55 
       
    56 void CObexActiveRfcommConnector::RunL()
       
    57 	{
       
    58 	LOG_LINE
       
    59 	LOG_FUNC
       
    60 	LOG1(_L8("\tiStatus = %d"), iStatus.Int());
       
    61 
       
    62 	// This exists purely as a sanity-check on our internal state.
       
    63 	__ASSERT_DEBUG(iSocket.SubSessionHandle(), PANIC(KPanicCat, EActiveRfcommConnInternalError));
       
    64 
       
    65 	TObexConnectionInfo sockinfo;
       
    66 	if ( iStatus == KErrNone )
       
    67 		{
       
    68 		sockinfo.iSocketType = TObexConnectionInfo::ESocketStream;
       
    69 		
       
    70 		TPckgBuf<TUint> optBuf(65535); //If all else fails we should get a max 64K buffer
       
    71 		iSocket.GetOpt(KRFCOMMMaximumMTU, KSolBtRFCOMM, optBuf);
       
    72 
       
    73 		// Set socket buffer sizes based on negotiated MTU
       
    74 		iSocket.SetOpt(KSOSendBuf, KSOLSocket, optBuf);
       
    75 		iSocket.SetOpt(KSORecvBuf, KSOLSocket, optBuf);		
       
    76 		}
       
    77 	else
       
    78 		{
       
    79 		iSocket.Close();
       
    80 		}
       
    81 
       
    82 	iParent.ConnectComplete(iStatus.Int(), sockinfo);
       
    83 	}
       
    84 
       
    85 void CObexActiveRfcommConnector::DoCancel()
       
    86 	{
       
    87 	LOG_FUNC
       
    88 
       
    89 	// This exists purely as a sanity-check on our internal state.
       
    90 	__ASSERT_DEBUG(iSocket.SubSessionHandle(), PANIC(KPanicCat, EActiveRfcommConnInternalError));
       
    91 	iSocket.CancelConnect();
       
    92 	iSocket.Close();
       
    93 	}
       
    94 
       
    95 void CObexActiveRfcommConnector::ConnectL()
       
    96 	{
       
    97 	LOG_FUNC
       
    98 
       
    99 	__ASSERT_DEBUG(!iSocket.SubSessionHandle(), PANIC(KPanicCat, EActiveRfcommConnInternalError));
       
   100 	LEAVEIFERRORL(iSocket.Open(iSocketServ, 
       
   101 							   iProtocolDesc.iAddrFamily,
       
   102 							   iProtocolDesc.iSockType, 
       
   103 							   iProtocolDesc.iProtocol));
       
   104 
       
   105 	// iAddr is logically const, and needs constness casting away for this 
       
   106 	// API.
       
   107 	iSocket.Connect(const_cast<TBTSockAddr&>(iAddr), iStatus);
       
   108 	SetActive();
       
   109 	}