telephonyprotocols/rawipnif/src/Receiver.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
    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 "ReceiverTraces.h"
       
    26 #endif
       
    27 
       
    28 #include "Receiver.h"
    22 #include "Receiver.h"
    29 #include "Constants.h"
    23 #include "Constants.h"
    30 #include <es_ini.h>
    24 #include <es_ini.h>
    31 
    25 
    32 const TUint KBufferIncreaseStep=500;
    26 const TUint KBufferIncreaseStep=500;
    33 const TUint K64k=65535;
    27 const TUint K64k=65535;
    34 
    28 
    35 CReceiver::CReceiver(CBcaIoController& aObserver, TUint aMaxPacketSize)
    29 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize)
    36 /**
    30 /**
    37  * Constructor. Performs standard active object initialisation.
    31  * Constructor. Performs standard active object initialisation.
    38  *
    32  *
    39  * @param aObserver Reference to the observer of this state machine
    33  * @param aObserver Reference to the observer of this state machine
       
    34  * @param aTheLogger The logging object
    40  */
    35  */
    41 	: CActive(EPriorityHigh), 
    36 	: CActive(EPriorityHigh), 
    42 	  iObserver(aObserver), 
    37 	  iObserver(aObserver), 
       
    38 	  iTheLogger(aTheLogger),
    43 	  iMaxPacketSize(aMaxPacketSize)
    39 	  iMaxPacketSize(aMaxPacketSize)
    44 	{	
    40 	{	
    45 	CActiveScheduler::Add(this);
    41 	CActiveScheduler::Add(this);
    46 	}
    42 	}
    47 
    43 
    48 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, TUint aMaxPacketSize)
    44 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize)
    49 /**
    45 /**
    50  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    46  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    51  * second-phase construction, then returns it.
    47  * second-phase construction, then returns it.
    52  *
    48  *
    53  * @param aObserver The observer, to which events will be reported
    49  * @param aObserver The observer, to which events will be reported
       
    50  * @param aTheLogger The logging object
    54  * @return A newly constructed CBcaIoController object
    51  * @return A newly constructed CBcaIoController object
    55  */
    52  */
    56 	{
    53 	{
    57 	CReceiver* self = new (ELeave) CReceiver(aObserver, aMaxPacketSize);
    54 	CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSize);
    58 	CleanupStack::PushL(self);
    55 	CleanupStack::PushL(self);
    59 	self->ConstructL();
    56 	self->ConstructL();
    60 	CleanupStack::Pop(self);
    57 	CleanupStack::Pop(self);
    61 	return self;
    58 	return self;
    62 	}
    59 	}
    64 void CReceiver::ConstructL()
    61 void CReceiver::ConstructL()
    65 /**
    62 /**
    66  * Second-phase constructor. Creates all the state objects it owns.
    63  * Second-phase constructor. Creates all the state objects it owns.
    67  */
    64  */
    68 	{
    65 	{
    69 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_CONSTRUCTL_1, "CReceiver::ConstructL");
    66 	_LOG_L1C1(_L8("CReceiver::ConstructL"));
    70 	iData.CreateL(iMaxPacketSize);
    67 	iData.CreateL(iMaxPacketSize);
    71 	}
    68 	}
    72 
    69 
    73 CReceiver::~CReceiver()
    70 CReceiver::~CReceiver()
    74 /**
    71 /**
    86 /**
    83 /**
    87  *  Method called when read request completes. This will only be once the BCA has a full IP 
    84  *  Method called when read request completes. This will only be once the BCA has a full IP 
    88  *  packet in its buffer.
    85  *  packet in its buffer.
    89  */
    86  */
    90 	{
    87 	{
    91 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_1, "CReceiver::RunL [iStatus=%d]", iStatus.Int());
    88 	_LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int());
    92 
    89 
    93 	if (iStatus != KErrNone)
    90 	if (iStatus != KErrNone)
    94 		{
    91 		{
    95 		if (iStatus == KErrNoMemory)
    92 		if (iStatus == KErrNoMemory)
    96 			{
    93 			{
    97 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_2, "WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer.");
    94 			_LOG_L2C1(
    98 				// Read operation failed!! Nif will re-issue the read request. Increase buffer.			
    95 				_L8("WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer."));
       
    96 			// Read operation failed!! Nif will re-issue the read request. Increase buffer.			
    99 			if ((iMaxPacketSize + KBufferIncreaseStep) > K64k)
    97 			if ((iMaxPacketSize + KBufferIncreaseStep) > K64k)
   100 			    {
    98 			    {
   101 			    // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. 
    99 			    // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. 
   102                 iObserver.Stop(KErrNoMemory);
   100                 iObserver.Stop(KErrNoMemory);
   103 			    }
   101 			    }
   116                     }
   114                     }
   117 			    }
   115 			    }
   118 			}
   116 			}
   119 		else 
   117 		else 
   120 			{
   118 			{
   121 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_3, "WARNING! CReceiver: Read failed");
   119 			_LOG_L2C1(_L8("WARNING! CReceiver: Read failed"));
   122 			iObserver.Stop(iStatus.Int());
   120 			iObserver.Stop(iStatus.Int());
   123 			}
   121 			}
   124 		return;
   122 		return;
   125 		}
   123 		}
   126 	else
   124 	else
   127 	    {
   125 	    {
   128         OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_4, "CReceiver: Data Packet Received");
   126         _LOG_L1C1(_L8("CReceiver: Data Packet Received"));
   129     
   127     
   130         iRMBufPacket.CreateL(iData);
   128         iRMBufPacket.CreateL(iData);
   131         
   129         
   132         // Immediately execute new read request.
   130         // Immediately execute new read request.
   133         (iObserver.Bca())->Read(iStatus, iData);
   131         (iObserver.Bca())->Read(iStatus, iData);
   134     
   132     
   135         SetActive();
   133         SetActive();
   136         
   134         
   137         iRMBufPacket.Pack();
   135         iRMBufPacket.Pack();
   138         
   136     
   139 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   137 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   140         TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket);
   138         TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket);
   141 #else
   139 #else
   142         TUint16 protocolCode = 0;
   140         TUint16 protocolCode = 0;
   143 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   141 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   148 	    }
   146 	    }
   149 	}
   147 	}
   150 
   148 
   151 TInt CReceiver::RunError(TInt aError)
   149 TInt CReceiver::RunError(TInt aError)
   152     {
   150     {
   153     OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNERROR_1, "WARNING! CReceiver::RunError Read failed");
   151     _LOG_L2C1(_L8("WARNING! CReceiver::RunError Read failed"));
   154     iObserver.Stop(aError); 
   152     iObserver.Stop(aError); 
   155     return KErrNone;  
   153     return KErrNone;  
   156     }
   154     }
   157 
   155 
   158 void CReceiver::DoCancel()
   156 void CReceiver::DoCancel()
   159 /**
   157 /**
   160  *	Cancel active request
   158  *	Cancel active request
   161  */
   159  */
   162 	{
   160 	{
   163 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_DOCANCEL_1, "CReceiver::DoCancel");
   161 	_LOG_L1C1(_L8("CReceiver::DoCancel"));
   164 
   162 
   165 	(iObserver.Bca())->CancelRead(); 
   163 	(iObserver.Bca())->CancelRead(); 
   166 	}
   164 	}
   167 
   165 
   168 void CReceiver::StartListening()
   166 void CReceiver::StartListening()
   169 /**
   167 /**
   170  *  This method issues a Read request. This is the API used to receive 
   168  *  This method issues a Read request. This is the API used to receive 
   171  *  packets from BCA.  
   169  *  packets from BCA.  
   172  */
   170  */
   173 	{
   171 	{
   174 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_STARTLISTENING_1, "CReceiver::StartListening");
   172 	_LOG_L1C1(_L8("CReceiver::StartListening"));
   175 
   173 
   176 	// The BCA will complete this read once it has a full IP packet in its buffer.
   174 	// The BCA will complete this read once it has a full IP packet in its buffer.
   177 	(iObserver.Bca())->Read(iStatus, iData);
   175 	(iObserver.Bca())->Read(iStatus, iData);
   178 
   176 
   179 	SetActive();
   177 	SetActive();