telephonyprotocols/rawipnif/src/Receiver.cpp
branchRCL_3
changeset 8 3f227a47ad75
parent 7 fe8b59ab9fa0
child 10 4284d6390a82
equal deleted inserted replaced
7:fe8b59ab9fa0 8:3f227a47ad75
    21 
    21 
    22 #include "Receiver.h"
    22 #include "Receiver.h"
    23 #include "Constants.h"
    23 #include "Constants.h"
    24 #include <es_ini.h>
    24 #include <es_ini.h>
    25 
    25 
    26 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
    26 const TUint KBufferIncreaseStep=500;
       
    27 const TUint K64k=65535;
       
    28 
       
    29 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize)
    27 /**
    30 /**
    28  * Constructor. Performs standard active object initialisation.
    31  * Constructor. Performs standard active object initialisation.
    29  *
    32  *
    30  * @param aObserver Reference to the observer of this state machine
    33  * @param aObserver Reference to the observer of this state machine
    31  * @param aTheLogger The logging object
    34  * @param aTheLogger The logging object
    32  */
    35  */
    33 	: CActive(EPriorityHigh), 
    36 	: CActive(EPriorityHigh), 
    34 	  iObserver(aObserver), 
    37 	  iObserver(aObserver), 
    35 	  iTheLogger(aTheLogger),
    38 	  iTheLogger(aTheLogger),
    36 	  iMaxPacketSise(aMaxPacketSise)
    39 	  iMaxPacketSize(aMaxPacketSize)
    37 	{	
    40 	{	
    38 	CActiveScheduler::Add(this);
    41 	CActiveScheduler::Add(this);
    39 	}
    42 	}
    40 
    43 
    41 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise)
    44 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize)
    42 /**
    45 /**
    43  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    46  * Two-phase constructor. Creates a new CBcaIoController object, performs 
    44  * second-phase construction, then returns it.
    47  * second-phase construction, then returns it.
    45  *
    48  *
    46  * @param aObserver The observer, to which events will be reported
    49  * @param aObserver The observer, to which events will be reported
    47  * @param aTheLogger The logging object
    50  * @param aTheLogger The logging object
    48  * @return A newly constructed CBcaIoController object
    51  * @return A newly constructed CBcaIoController object
    49  */
    52  */
    50 	{
    53 	{
    51 	CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSise);
    54 	CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSize);
    52 	CleanupStack::PushL(self);
    55 	CleanupStack::PushL(self);
    53 	self->ConstructL();
    56 	self->ConstructL();
    54 	CleanupStack::Pop(self);
    57 	CleanupStack::Pop(self);
    55 	return self;
    58 	return self;
    56 	}
    59 	}
    59 /**
    62 /**
    60  * Second-phase constructor. Creates all the state objects it owns.
    63  * Second-phase constructor. Creates all the state objects it owns.
    61  */
    64  */
    62 	{
    65 	{
    63 	_LOG_L1C1(_L8("CReceiver::ConstructL"));
    66 	_LOG_L1C1(_L8("CReceiver::ConstructL"));
    64 	iData.CreateL(iMaxPacketSise);
    67 	iData.CreateL(iMaxPacketSize);
    65 	}
    68 	}
    66 
    69 
    67 CReceiver::~CReceiver()
    70 CReceiver::~CReceiver()
    68 /**
    71 /**
    69  * Destructor.
    72  * Destructor.
    84 	if (iStatus != KErrNone)
    87 	if (iStatus != KErrNone)
    85 		{
    88 		{
    86 		if (iStatus == KErrNoMemory)
    89 		if (iStatus == KErrNoMemory)
    87 			{
    90 			{
    88 			_LOG_L2C1(
    91 			_LOG_L2C1(
    89 				_L8("WARNING! CReceiver: Read failed with KErrNoMemory"));
    92 				_L8("WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer."));
    90 			// Read operation failed!! Nif will re-issue the read request.
    93 			// Read operation failed!! Nif will re-issue the read request. Increase buffer.			
    91 		    (iObserver.Bca())->Read(iStatus, iData);
    94 			if ((iMaxPacketSize + KBufferIncreaseStep) > K64k)
    92 
    95 			    {
    93 		    SetActive();
    96 			    // 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);
       
    98 			    }
       
    99 			else
       
   100 			    {
       
   101                 iMaxPacketSize += KBufferIncreaseStep;
       
   102                 TInt err = iData.ReAlloc(iMaxPacketSize);
       
   103                 if (KErrNoMemory == err)
       
   104                     {                
       
   105                     iObserver.Stop(KErrNoMemory);
       
   106                     }
       
   107                 else
       
   108                     {
       
   109                     (iObserver.Bca())->Read(iStatus, iData);    
       
   110                     SetActive();
       
   111                     }
       
   112 			    }
    94 			}
   113 			}
    95 		else 
   114 		else 
    96 			{
   115 			{
    97 			_LOG_L2C1(_L8("WARNING! CReceiver: Read failed"));
   116 			_LOG_L2C1(_L8("WARNING! CReceiver: Read failed"));
    98 			iObserver.Stop(iStatus.Int());
   117 			iObserver.Stop(iStatus.Int());