telephonyprotocols/rawipnif/src/Receiver.cpp
changeset 44 8b72faa1200f
parent 23 6b1d113cdff3
child 73 70d75957b98f
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 "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 /**
    72  * Destructor.
    75  * Destructor.
    73  */
    76  */
    74 	{
    77     {
    75 	iData.Close();
    78     Cancel();
    76 	Cancel();
    79     // iData is a shared bit of memory between raw ip and bca
    77 	}
    80     // you cannot delete it while bca might be using it otherwise
       
    81     // bad things may happen.
       
    82     iData.Close();
       
    83     }
    78 
    84 
    79 void CReceiver::RunL()
    85 void CReceiver::RunL()
    80 /**
    86 /**
    81  *  Method called when read request completes. This will only be once the BCA has a full IP 
    87  *  Method called when read request completes. This will only be once the BCA has a full IP 
    82  *  packet in its buffer.
    88  *  packet in its buffer.
    83  */
    89  */
    84 	{
    90 	{
    85 	_LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int());
    91 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_1, "CReceiver::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(
    97 			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."));
    98 				// 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)
    99 			if ((iMaxPacketSize + KBufferIncreaseStep) > K64k)
    95 			    {
   100 			    {
    96 			    // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. 
   101 			    // 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);
   102                 iObserver.Stop(KErrNoMemory);
    98 			    }
   103 			    }
   111                     }
   116                     }
   112 			    }
   117 			    }
   113 			}
   118 			}
   114 		else 
   119 		else 
   115 			{
   120 			{
   116 			_LOG_L2C1(_L8("WARNING! CReceiver: Read failed"));
   121 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_3, "WARNING! CReceiver: Read failed");
   117 			iObserver.Stop(iStatus.Int());
   122 			iObserver.Stop(iStatus.Int());
   118 			}
   123 			}
   119 		return;
   124 		return;
   120 		}
   125 		}
   121 	else
   126 	else
   122 	    {
   127 	    {
   123         _LOG_L1C1(_L8("CReceiver: Data Packet Received"));
   128         OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_4, "CReceiver: Data Packet Received");
   124     
   129     
   125         iRMBufPacket.CreateL(iData);
   130         iRMBufPacket.CreateL(iData);
   126         
   131         
   127         // Immediately execute new read request.
   132         // Immediately execute new read request.
   128         (iObserver.Bca())->Read(iStatus, iData);
   133         (iObserver.Bca())->Read(iStatus, iData);
   129     
   134     
   130         SetActive();
   135         SetActive();
   131         
   136         
   132         iRMBufPacket.Pack();
   137         iRMBufPacket.Pack();
   133     
   138         
   134 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   139 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   135         TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket);
   140         TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket);
   136 #else
   141 #else
   137         TUint16 protocolCode = 0;
   142         TUint16 protocolCode = 0;
   138 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   143 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
   141         iObserver.GetObserver().Process(iRMBufPacket, protocolCode);
   146         iObserver.GetObserver().Process(iRMBufPacket, protocolCode);
   142         iRMBufPacket.Free();
   147         iRMBufPacket.Free();
   143 	    }
   148 	    }
   144 	}
   149 	}
   145 
   150 
       
   151 TInt CReceiver::RunError(TInt aError)
       
   152     {
       
   153     OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNERROR_1, "WARNING! CReceiver::RunError Read failed");
       
   154     iObserver.Stop(aError); 
       
   155     return KErrNone;  
       
   156     }
       
   157 
   146 void CReceiver::DoCancel()
   158 void CReceiver::DoCancel()
   147 /**
   159 /**
   148  *	Cancel active request
   160  *	Cancel active request
   149  */
   161  */
   150 	{
   162 	{
   151 	_LOG_L1C1(_L8("CReceiver::DoCancel"));
   163 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_DOCANCEL_1, "CReceiver::DoCancel");
   152 
   164 
   153 	(iObserver.Bca())->CancelRead(); 
   165 	(iObserver.Bca())->CancelRead(); 
   154 	}
   166 	}
   155 
   167 
   156 void CReceiver::StartListening()
   168 void CReceiver::StartListening()
   157 /**
   169 /**
   158  *  This method issues a Read request. This is the API used to receive 
   170  *  This method issues a Read request. This is the API used to receive 
   159  *  packets from BCA.  
   171  *  packets from BCA.  
   160  */
   172  */
   161 	{
   173 	{
   162 	_LOG_L1C1(_L8("CReceiver::StartListening"));
   174 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_STARTLISTENING_1, "CReceiver::StartListening");
   163 
   175 
   164 	// The BCA will complete this read once it has a full IP packet in its buffer.
   176 	// The BCA will complete this read once it has a full IP packet in its buffer.
   165 	(iObserver.Bca())->Read(iStatus, iData);
   177 	(iObserver.Bca())->Read(iStatus, iData);
   166 
   178 
   167 	SetActive();
   179 	SetActive();