telephonyprotocols/rawipnif/src/Sender.cpp
changeset 44 8b72faa1200f
parent 23 6b1d113cdff3
equal deleted inserted replaced
39:2473f5e227f9 44:8b72faa1200f
    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 /**
    73  * Destructor.
    76  * Destructor.
    74  */
    77  */
    75 	{
    78     {
    76 	iSendBuffer.Close();
    79     Cancel();
    77 	Cancel();
    80     // iSendBuffer is a shared bit of memory between raw ip and bca
    78 	}
    81     // you cannot delete it while bca might be using it otherwise
       
    82     // bad things may happen.
       
    83     iSendBuffer.Close();
       
    84     }
    79 
    85 
    80 void CSender::RunL()
    86 void CSender::RunL()
    81 /**
    87 /**
    82  * This method checks if any error occured in the write operation.  
    88  * This method checks if any error occured in the write operation.  
    83  */
    89  */
    84 	{
    90 	{
    85 	_LOG_L1C2(_L8("CSender::RunL [iStatus=%d]"), iStatus.Int());
    91 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_1, "CSender::RunL [iStatus=%d]", iStatus.Int());
    86 
    92 
    87 	if (iStatus!=KErrNone)
    93 	if (iStatus!=KErrNone)
    88 		{
    94 		{
    89 		if(iStatus == KErrNoMemory)
    95 		if(iStatus == KErrNoMemory)
    90 			{
    96 			{
    91 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNoMemory"));
    97 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_2, "WARNING! CSender: Write failed with KErrNoMemory");
    92 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
    98 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_3, "WARNING! CSender: Ignoring packet!!!!");
    93 			// Write operation failed!! Nif will ignore this packet.
    99 			// Write operation failed!! Nif will ignore this packet.
    94 			iObserver.SendComplete();
   100 			iObserver.SendComplete();
    95 			}
   101 			}
    96 		else if (iStatus == KErrNotReady)
   102 		else if (iStatus == KErrNotReady)
    97 			{
   103 			{
    98 			_LOG_L2C1(_L8("WARNING! CSender: Write failed with KErrNotReady"));
   104 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_4, "WARNING! CSender: Write failed with KErrNotReady");
    99 			_LOG_L2C1(_L8("WARNING! CSender: Ignoring packet!!!!"));
   105 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_5, "WARNING! CSender: Ignoring packet!!!!");
   100 			// Write operation failed!! Nif will ignore this packet.
   106 			// Write operation failed!! Nif will ignore this packet.
   101 			iObserver.SendComplete();
   107 			iObserver.SendComplete();
   102 			}
   108 			}
   103 		else
   109 		else
   104 			{
   110 			{
   105 			_LOG_L2C1(_L8("ERROR! CSender: Write failed!!!!"));
   111 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_6, "ERROR! CSender: Write failed!!!!");
   106 			// Nif will shut down
   112 			// Nif will shut down
   107 			iObserver.Stop(iStatus.Int());
   113 			iObserver.Stop(iStatus.Int());
   108 			}
   114 			}
   109 		return;
   115 		return;
   110 		}
   116 		}
   111 
   117 
   112 	else
   118 	else
   113 		{
   119 		{
   114 		// The Ip packet was sent successfuly
   120 		// The Ip packet was sent successfuly
   115 		_LOG_L1C1(_L8("***** CSender: Packet Sent."));
   121 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_RUNL_7, "***** CSender: Packet Sent.");
   116 		iObserver.SendComplete();
   122 		iObserver.SendComplete();
   117 		}
   123 		}
   118 	}
   124 	}
   119 
   125 
   120 void CSender::DoCancel()
   126 void CSender::DoCancel()
   121 /**
   127 /**
   122  *	Cancel active request
   128  *	Cancel active request
   123  */
   129  */
   124 	{
   130 	{
   125 	_LOG_L1C1(_L8("CSender::DoCancel"));
   131 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_DOCANCEL_1, "CSender::DoCancel");
   126 
   132 
   127 	(iObserver.Bca())->CancelWrite(); 
   133 	(iObserver.Bca())->CancelWrite(); 
   128 	}
   134 	}
   129 
   135 
   130 void CSender::Send(RMBufChain& aPdu)
   136 void CSender::Send(RMBufChain& aPdu)
   133  *
   139  *
   134  * @param aPdu The IP packet to be sent.
   140  * @param aPdu The IP packet to be sent.
   135  * @return KStopSending, or KErrArgument if the packet is too large.
   141  * @return KStopSending, or KErrArgument if the packet is too large.
   136  */
   142  */
   137 	{
   143 	{
   138 	_LOG_L1C1(_L8("CSender::Send"));
   144 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CSENDER_SEND_1, "CSender::Send");
   139 
   145 
   140 	// Copy the IP portion of the RMBufChain to the buffer.
   146 	// Copy the IP portion of the RMBufChain to the buffer.
   141 	iSendBuffer.SetMax();
   147 	iSendBuffer.SetMax();
   142 	aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
   148 	aPdu.CopyOut(iSendBuffer, aPdu.First()->Length());
   143 
   149 
   146 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   152 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   147 
   153 
   148 	aPdu.Free();
   154 	aPdu.Free();
   149 
   155 
   150 	(iObserver.Bca())->Write(iStatus, iSendBuffer);
   156 	(iObserver.Bca())->Write(iStatus, iSendBuffer);
   151 	
       
   152 	SetActive();
   157 	SetActive();
   153 	}
   158 	}
   154