telephonyprotocols/rawipnif/src/Sender.cpp
changeset 42 3adadc800673
parent 23 6b1d113cdff3
child 49 f50f4094acd7
equal deleted inserted replaced
31:8ab6687fb94c 42:3adadc800673
    17 
    17 
    18 /**
    18 /**
    19  @file
    19  @file
    20 */
    20 */
    21 
    21 
       
    22 
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "SenderTraces.h"
       
    26 #endif
       
    27 
    22 #include "Sender.h"
    28 #include "Sender.h"
    23 #include "Constants.h"
    29 #include "Constants.h"
    24 #include <es_ini.h>
    30 #include <es_ini.h>
    25 
    31 
    26 
    32 
    27 CSender::CSender(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
    33 CSender::CSender(CBcaIoController& aObserver, TInt aMaxPacketSise)
    28 /**
    34 /**
    29  * Constructor. Performs standard active object initialisation.
    35  * Constructor. Performs standard active object initialisation.
    30  *
       
    31  * @param aObserver Reference to the observer of this state machine
    36  * @param aObserver Reference to the observer of this state machine
    32  */
    37  */
    33 	: CActive(EPriorityUserInput), 
    38 	: CActive(EPriorityUserInput), 
    34 	  iObserver(aObserver),
    39 	  iObserver(aObserver),
    35 	  iTheLogger(aTheLogger),
       
    36 	  iMaxPacketSize(aMaxPacketSise)
    40 	  iMaxPacketSize(aMaxPacketSise)
    37 	{
    41 	{
    38     // EPriorityUserInput is higher than the default priority but lower than
    42     // EPriorityUserInput is higher than the default priority but lower than
    39     // EPriorityHigh which is used on Receiving (DL having priority), however,
    43     // EPriorityHigh which is used on Receiving (DL having priority), however,
    40     // we want this to be handled in an expedited manner compared to other
    44     // we want this to be handled in an expedited manner compared to other
    41     // active objects in the thread.
    45     // active objects in the thread.
    42 	CActiveScheduler::Add(this);
    46 	CActiveScheduler::Add(this);
    43 	}
    47 	}
    44 
    48 
    45 CSender* CSender::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
    49 CSender* CSender::NewL(CBcaIoController& aObserver, TInt aMaxPacketSise)
    46 /**
    50 /**
    47  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    51  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    48  * second-phase construction, then returns it.
    52  * second-phase construction, then returns it.
    49  *
    53  *
    50  * @param aObserver The observer, to which events will be reported
    54  * @param aObserver The observer, to which events will be reported
    51  * @param aTheLogger The logging object
       
    52  * @return A newly constructed CBcaIoController object
    55  * @return A newly constructed CBcaIoController object
    53  */
    56  */
    54 	{
    57 	{
    55 	CSender* self = new (ELeave) CSender(aObserver, aTheLogger, aMaxPacketSise);
    58 	CSender* self = new (ELeave) CSender(aObserver, aMaxPacketSise);
    56 	CleanupStack::PushL(self);
    59 	CleanupStack::PushL(self);
    57 	self->ConstructL();
    60 	self->ConstructL();
    58 	CleanupStack::Pop(self);
    61 	CleanupStack::Pop(self);
    59 	return self;
    62 	return self;
    60 	}
    63 	}
    62 void CSender::ConstructL()
    65 void CSender::ConstructL()
    63 /**
    66 /**
    64  * Second-phase constructor. Creates all the state objects it owns.
    67  * Second-phase constructor. Creates all the state objects it owns.
    65  */
    68  */
    66 	{
    69 	{
    67 	_LOG_L1C1(_L8("CSender::ConstructL"));
    70 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_CONSTRUCTL_1, "CSender::ConstructL");
    68 	iSendBuffer.CreateL(iMaxPacketSize);
    71 	iSendBuffer.CreateL(iMaxPacketSize);
    69 	}
    72 	}
    70 
    73 
    71 CSender::~CSender()
    74 CSender::~CSender()
    72 /**
    75 /**
    80 void CSender::RunL()
    83 void CSender::RunL()
    81 /**
    84 /**
    82  * This method checks if any error occured in the write operation.  
    85  * This method checks if any error occured in the write operation.  
    83  */
    86  */
    84 	{
    87 	{
    85 	_LOG_L1C2(_L8("CSender::RunL [iStatus=%d]"), iStatus.Int());
    88 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_1, "CSender::RunL [iStatus=%d]", iStatus.Int());
    86 
    89 
    87 	if (iStatus!=KErrNone)
    90 	if (iStatus!=KErrNone)
    88 		{
    91 		{
    89 		if(iStatus == KErrNoMemory)
    92 		if(iStatus == KErrNoMemory)
    90 			{
    93 			{
    91 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNoMemory"));
    94 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_2, "WARNING! CSender: Write failed with KErrNoMemory");
    92 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
    95 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_3, "WARNING! CSender: Ignoring packet!!!!");
    93 			// Write operation failed!! Nif will ignore this packet.
    96 			// Write operation failed!! Nif will ignore this packet.
    94 			iObserver.SendComplete();
    97 			iObserver.SendComplete();
    95 			}
    98 			}
    96 		else if (iStatus == KErrNotReady)
    99 		else if (iStatus == KErrNotReady)
    97 			{
   100 			{
    98 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNotReady"));
   101 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_4, "WARNING! CSender: Write failed with KErrNotReady");
    99 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
   102 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_5, "WARNING! CSender: Ignoring packet!!!!");
   100 			// Write operation failed!! Nif will ignore this packet.
   103 			// Write operation failed!! Nif will ignore this packet.
   101 			iObserver.SendComplete();
   104 			iObserver.SendComplete();
   102 			}
   105 			}
   103 		else
   106 		else
   104 			{
   107 			{
   105 			_LOG_L2C1(_L8("ERROR! CSender: Write failed!!!!"));
   108 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_6, "ERROR! CSender: Write failed!!!!");
   106 			// Nif will shut down
   109 			// Nif will shut down
   107 			iObserver.Stop(iStatus.Int());
   110 			iObserver.Stop(iStatus.Int());
   108 			}
   111 			}
   109 		return;
   112 		return;
   110 		}
   113 		}
   111 
   114 
   112 	else
   115 	else
   113 		{
   116 		{
   114 		// The Ip packet was sent successfuly
   117 		// The Ip packet was sent successfuly
   115 		_LOG_L1C1(_L8("***** CSender: Packet Sent."));
   118 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_7, "***** CSender: Packet Sent.");
   116 		iObserver.SendComplete();
   119 		iObserver.SendComplete();
   117 		}
   120 		}
   118 	}
   121 	}
   119 
   122 
   120 void CSender::DoCancel()
   123 void CSender::DoCancel()
   121 /**
   124 /**
   122  *	Cancel active request
   125  *	Cancel active request
   123  */
   126  */
   124 	{
   127 	{
   125 	_LOG_L1C1(_L8("CSender::DoCancel"));
   128 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_DOCANCEL_1, "CSender::DoCancel");
   126 
   129 
   127 	(iObserver.Bca())->CancelWrite(); 
   130 	(iObserver.Bca())->CancelWrite(); 
   128 	}
   131 	}
   129 
   132 
   130 void CSender::Send(RMBufChain& aPdu)
   133 void CSender::Send(RMBufChain& aPdu)
   133  *
   136  *
   134  * @param aPdu The IP packet to be sent.
   137  * @param aPdu The IP packet to be sent.
   135  * @return KStopSending, or KErrArgument if the packet is too large.
   138  * @return KStopSending, or KErrArgument if the packet is too large.
   136  */
   139  */
   137 	{
   140 	{
   138 	_LOG_L1C1(_L8("CSender::Send"));
   141 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_SEND_1, "CSender::Send");
   139 
   142 
   140 	// Copy the IP portion of the RMBufChain to the buffer.
   143 	// Copy the IP portion of the RMBufChain to the buffer.
   141 	iSendBuffer.SetMax();
   144 	iSendBuffer.SetMax();
   142 	aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
   145 	aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
   143 
   146 
   146 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   149 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   147 
   150 
   148 	aPdu.Free();
   151 	aPdu.Free();
   149 
   152 
   150 	(iObserver.Bca())->Write(iStatus, iSendBuffer);
   153 	(iObserver.Bca())->Write(iStatus, iSendBuffer);
   151 	
       
   152 	SetActive();
   154 	SetActive();
   153 	}
   155 	}
   154