bthci/hci2implementations/hctls/usb_original/hctl/src/hctlusboriginalaclout.cpp
changeset 27 83036355c0f3
equal deleted inserted replaced
4:28479eeba3fb 27:83036355c0f3
       
     1 // Copyright (c) 2007-2010 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 /** 
       
    17 @file
       
    18 @internalComponent
       
    19 */
       
    20 
       
    21 #include "hctlusboriginalaclout.h"
       
    22 
       
    23 #include <bluetooth/hci/hctlchannelobserver.h>
       
    24 #include <bluetooth/hci/hciframe.h>
       
    25 
       
    26 #include <bluetooth/logger.h>
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_HCTL_USB_ORIGINAL);
       
    30 #endif
       
    31 
       
    32 CHCTLUsbOriginalAclOut::CHCTLUsbOriginalAclOut(RUsbInterface& aInterface)
       
    33 	: CActive(EPriorityStandard)
       
    34 	, iInterface(aInterface)
       
    35 	, iTransfer(CHctlAclDataFrame::KHCTLMaxACLDataSize)
       
    36 	{
       
    37 	LOG_FUNC
       
    38 	CActiveScheduler::Add(this);
       
    39 	}
       
    40 
       
    41 void CHCTLUsbOriginalAclOut::ConstructL()
       
    42 	{
       
    43 	LOG_FUNC
       
    44 	LEAVEIFERRORL(iInterface.RegisterTransferDescriptor(iTransfer));
       
    45 	LEAVEIFERRORL(iInterface.OpenPipeForEndpoint(iPipe, KEndpointNumber, EFalse));
       
    46 	}
       
    47 
       
    48 CHCTLUsbOriginalAclOut::~CHCTLUsbOriginalAclOut()
       
    49 	{
       
    50 	LOG_FUNC
       
    51 	Cancel();
       
    52 	iPipe.Close();
       
    53 	iTransfer.Close();
       
    54 	}
       
    55 
       
    56 CHCTLUsbOriginalAclOut* CHCTLUsbOriginalAclOut::NewL(RUsbInterface& aInterface)
       
    57 	{
       
    58 	LOG_STATIC_FUNC
       
    59 	CHCTLUsbOriginalAclOut* self = new(ELeave) CHCTLUsbOriginalAclOut(aInterface);
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL();
       
    62 	CleanupStack::Pop(self);
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 TInt CHCTLUsbOriginalAclOut::Write(const TDesC8& aData)
       
    67 	{
       
    68 	LOG_FUNC
       
    69 	TInt rerr = KErrNone;
       
    70 	//Check whether we finished with the previous write
       
    71 	if(!IsActive())
       
    72 		{
       
    73 		// Currently we only support sending one transfer at a time, so close off the channel after a write
       
    74 		iChannelObserver->MhcoChannelClosed(KHCITransportACLDataChannel);
       
    75 		
       
    76 		iTransfer.WritableBuffer() = aData;
       
    77 		iTransfer.SaveData(aData.Length());
       
    78 		
       
    79 		SetActive();
       
    80 		iPipe.Transfer(iTransfer, iStatus);
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		LOG(_L8("ERROR: Sender is already active!!\r\n"));
       
    85 		rerr = KErrInUse;
       
    86 		}
       
    87 
       
    88 	return rerr;
       
    89 	}
       
    90 
       
    91 void CHCTLUsbOriginalAclOut::SetChannelObserver(MHCTLChannelObserver& aObserver)
       
    92 	{
       
    93 	LOG_FUNC
       
    94 	iChannelObserver = &aObserver;
       
    95 	}
       
    96 
       
    97 void CHCTLUsbOriginalAclOut::RunL()
       
    98 	{
       
    99 	LOG_FUNC
       
   100 	LOG1(_L8("\tiStatus = %d"), iStatus.Int());
       
   101 	iChannelObserver->MhcoChannelOpen(KHCITransportACLDataChannel);
       
   102 	}
       
   103 
       
   104 void CHCTLUsbOriginalAclOut::DoCancel()
       
   105 	{
       
   106 	LOG_FUNC
       
   107 	iPipe.CancelAllTransfers();
       
   108 	}