obex/obexprotocol/obextransport/src/obexactivewriter.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 1997-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/obexactivewriter.h>
       
    17 #include <obex/internal/obexpacket.h>
       
    18 #include <es_sock.h>
       
    19 #include <obex/transport/mobextransportnotify.h>
       
    20 #include "ObexTransportUtil.h"
       
    21 #include "logger.h"
       
    22 
       
    23 #ifdef __FLOG_ACTIVE
       
    24 _LIT8(KLogComponent, "OBEXCT");
       
    25 #endif
       
    26 
       
    27 EXPORT_C CObexActiveWriter* CObexActiveWriter::NewL(MObexTransportNotify& aOwner, RSocket& aSocket, TObexConnectionInfo& aInfo)
       
    28 	{
       
    29 	CObexActiveWriter* self = new(ELeave) CObexActiveWriter(aOwner, aSocket, aInfo);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->BaseConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CObexActiveWriter::CObexActiveWriter (MObexTransportNotify& aOwner, RSocket& aSocket, TObexConnectionInfo& aInfo)
       
    37  :	CObexWriterBase (EPriorityHigh, aOwner, aInfo),
       
    38 	iInfo ( aInfo ),
       
    39 	iSocket(aSocket)
       
    40 	{
       
    41 	LOG_LINE
       
    42 	LOG_FUNC
       
    43 	}
       
    44 
       
    45 EXPORT_C CObexActiveWriter::~CObexActiveWriter ()
       
    46 	{
       
    47 	LOG_LINE
       
    48 	LOG_FUNC
       
    49 
       
    50 	Cancel ();
       
    51 	}
       
    52 
       
    53 /**
       
    54 Start transfer.
       
    55 Calls into CObexActiveRW, which eventaully queues a write which is limited by 
       
    56 the smaller of iInfo's max send size and aPacket's data limit
       
    57 
       
    58 @param aPacket The Obex packet to write
       
    59 */
       
    60 void CObexActiveWriter::StartTransfer (CObexPacket& aPacket)
       
    61 	{
       
    62 	LOG_FUNC
       
    63 
       
    64 	// Find out how much we can write to the remote end per transfer
       
    65 	iTransportWriteLimit = Min(iInfo.iMaxSendSize, aPacket.DataLimit());
       
    66 	LOG1(_L8("\tiTransportWriteLimit = %d"), iTransportWriteLimit);
       
    67 	CObexWriterBase::StartTransfer(aPacket);
       
    68 	}
       
    69 	
       
    70 
       
    71 // Called to actually transfer some data out from iLocation 
       
    72 void CObexActiveWriter::DoTransfer ()
       
    73 	{
       
    74 	LOG_FUNC
       
    75 
       
    76 	// Send the biggest chunk we can over the transport
       
    77 	if (iPacketBased && (iLocation.MaxLength () > iTransportWriteLimit))
       
    78 		{
       
    79 		iLocation.SetLength (iTransportWriteLimit);
       
    80 		}
       
    81 	else
       
    82 		{
       
    83 		iLocation.SetMax ();
       
    84 		}
       
    85 
       
    86 	iSocket.Write (iLocation, iStatus);
       
    87 	SetActive ();
       
    88 	}
       
    89 
       
    90 void CObexActiveWriter::DoCancel ()
       
    91 	{
       
    92 	LOG_FUNC
       
    93 
       
    94 	iSocket.CancelSend ();
       
    95 	}