telephonyprotocols/rawipnif/src/Sender.cpp
changeset 0 3553901f7fa8
child 16 fe8b59ab9fa0
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2002-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 // Implements the active object that controls the Write() requests. 
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "Sender.h"
       
    23 #include "Constants.h"
       
    24 #include <es_ini.h>
       
    25 
       
    26 
       
    27 CSender::CSender(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
       
    28 /**
       
    29  * Constructor. Performs standard active object initialisation.
       
    30  *
       
    31  * @param aObserver Reference to the observer of this state machine
       
    32  */
       
    33 	: CActive(EPriorityStandard), 
       
    34 	  iObserver(aObserver),
       
    35 	  iTheLogger(aTheLogger),
       
    36 	  iMaxPacketSise(aMaxPacketSise)
       
    37 	{
       
    38 	CActiveScheduler::Add(this);
       
    39 	}
       
    40 
       
    41 CSender* CSender::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
       
    42 /**
       
    43  * Two-phase constructor. Creates a new CBcaIoController object, performs 
       
    44  * second-phase construction, then returns it.
       
    45  *
       
    46  * @param aObserver The observer, to which events will be reported
       
    47  * @param aTheLogger The logging object
       
    48  * @return A newly constructed CBcaIoController object
       
    49  */
       
    50 	{
       
    51 	CSender* self = new (ELeave) CSender(aObserver, aTheLogger, aMaxPacketSise);
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	CleanupStack::Pop(self);
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 void CSender::ConstructL()
       
    59 /**
       
    60  * Second-phase constructor. Creates all the state objects it owns.
       
    61  */
       
    62 	{
       
    63 	_LOG_L1C1(_L8("CSender::ConstructL"));
       
    64 	iSendBuffer.CreateL(iMaxPacketSise);
       
    65 	}
       
    66 
       
    67 CSender::~CSender()
       
    68 /**
       
    69  * Destructor.
       
    70  */
       
    71 	{
       
    72 	iSendBuffer.Close();
       
    73 	Cancel();
       
    74 	}
       
    75 
       
    76 void CSender::RunL()
       
    77 /**
       
    78  * This method checks if any error occured in the write operation.  
       
    79  */
       
    80 	{
       
    81 	_LOG_L1C2(_L8("CSender::RunL [iStatus=%d]"), iStatus.Int());
       
    82 
       
    83 	if (iStatus!=KErrNone)
       
    84 		{
       
    85 		if(iStatus == KErrNoMemory)
       
    86 			{
       
    87 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNoMemory"));
       
    88 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
       
    89 			// Write operation failed!! Nif will ignore this packet.
       
    90 			iObserver.SendComplete();
       
    91 			}
       
    92 		else if (iStatus == KErrNotReady)
       
    93 			{
       
    94 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNotReady"));
       
    95 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
       
    96 			// Write operation failed!! Nif will ignore this packet.
       
    97 			iObserver.SendComplete();
       
    98 			}
       
    99 		else
       
   100 			{
       
   101 			_LOG_L2C1(_L8("ERROR! CSender: Write failed!!!!"));
       
   102 			// Nif will shut down
       
   103 			iObserver.Stop(iStatus.Int());
       
   104 			}
       
   105 		return;
       
   106 		}
       
   107 
       
   108 	else
       
   109 		{
       
   110 		// The Ip packet was sent successfuly
       
   111 		_LOG_L1C1(_L8("***** CSender: Packet Sent."));
       
   112 		iObserver.SendComplete();
       
   113 		}
       
   114 	}
       
   115 
       
   116 void CSender::DoCancel()
       
   117 /**
       
   118  *	Cancel active request
       
   119  */
       
   120 	{
       
   121 	_LOG_L1C1(_L8("CSender::DoCancel"));
       
   122 
       
   123 	(iObserver.Bca())->CancelWrite(); 
       
   124 	}
       
   125 
       
   126 void CSender::Send(RMBufChain& aPdu)
       
   127 /**
       
   128  * Copies the specified RMBufChain into a descriptor and sends it.
       
   129  *
       
   130  * @param aPdu The IP packet to be sent.
       
   131  * @return KStopSending, or KErrArgument if the packet is too large.
       
   132  */
       
   133 	{
       
   134 	_LOG_L1C1(_L8("CSender::Send"));
       
   135 
       
   136 	// Copy the IP portion of the RMBufChain to the buffer.
       
   137 	iSendBuffer.SetMax();
       
   138 	aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
       
   139 
       
   140 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
       
   141 	iObserver.AddHeader(iSendBuffer);
       
   142 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
       
   143 
       
   144 	aPdu.Free();
       
   145 
       
   146 	SendBuffer(iSendBuffer);
       
   147 	}
       
   148 
       
   149 void CSender::SendBuffer(const TDesC8& aBuffer)
       
   150 /**
       
   151  * Sends an IP packet, contained in the specified descriptor
       
   152  *
       
   153  * @param aBuffer The IP packet to send.
       
   154  * @return Always KStopSending.
       
   155  */
       
   156 	{
       
   157 	_LOG_L1C1(_L8("CSender::SendBuffer"));
       
   158 
       
   159 	// Finally, send the packet to BCA
       
   160 	(iObserver.Bca())->Write(iStatus, aBuffer);
       
   161 	SetActive();
       
   162 	}