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