telephonyprotocols/rawipnif/version1/src/Receiver.cpp
changeset 64 b34bb05ac869
parent 56 ab72d5c1d770
equal deleted inserted replaced
56:ab72d5c1d770 64:b34bb05ac869
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements the active object that controls the Read() requests.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "Receiver.h"
       
    23 #include "Constants.h"
       
    24 
       
    25 
       
    26 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger)
       
    27 /**
       
    28  * Constructor. Performs standard active object initialisation.
       
    29  *
       
    30  * @param aObserver Reference to the observer of this state machine
       
    31  * @param aTheLogger The logging object
       
    32  */
       
    33 	: CActive(EPriorityNormal), 
       
    34 	  iObserver(aObserver), 
       
    35 	  iTheLogger(aTheLogger)
       
    36 	{
       
    37 	CActiveScheduler::Add(this);
       
    38 	}
       
    39 
       
    40 CReceiver::~CReceiver()
       
    41 /**
       
    42  * Destructor.
       
    43  */
       
    44 	{
       
    45 	Cancel();
       
    46 	}
       
    47 
       
    48 void CReceiver::RunL()
       
    49 /**
       
    50  *  Method called when read request completes. This will only be once the BCA has a full IP 
       
    51  *  packet in its buffer.
       
    52  */
       
    53 	{
       
    54 	_LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int());
       
    55 
       
    56 	if (iStatus!=KErrNone)
       
    57 		{
       
    58 		if(iStatus == KErrNoMemory)
       
    59 			{
       
    60 			_LOG_L2C1(
       
    61 				_L8("WARNING! CReceiver: Read failed with KErrNoMemory"));
       
    62 			// Read operation failed!! Nif will re-issue the read request.
       
    63 			StartListening();
       
    64 			}
       
    65 		else 
       
    66 			{
       
    67 			_LOG_L2C1(_L8("WARNING! CReceiver: Read failed"));
       
    68 			iObserver.Stop(iStatus.Int());
       
    69 			}
       
    70 		return;
       
    71 		}
       
    72 
       
    73 	_LOG_L1C1(_L8("CReceiver: Data Packet Received"));
       
    74 
       
    75 	// Process Ip packet
       
    76 	iObserver.Process(iData);
       
    77 
       
    78 	// The packet received was processed. NIF can start listening
       
    79 	// for another one.
       
    80 	StartListening();
       
    81 
       
    82 	}
       
    83 
       
    84 void CReceiver::DoCancel()
       
    85 /**
       
    86  *	Cancel active request
       
    87  */
       
    88 	{
       
    89 	_LOG_L1C1(_L8("CReceiver::DoCancel"));
       
    90 
       
    91 	(iObserver.Bca())->CancelRead(); 
       
    92 	}
       
    93 
       
    94 void CReceiver::StartListening()
       
    95 /**
       
    96  *  This method issues a Read request. This is the API used to receive 
       
    97  *  packets from BCA.  
       
    98  */
       
    99 	{
       
   100 	_LOG_L1C1(_L8("CReceiver::StartListening"));
       
   101 
       
   102 	// The BCA will complete this read once it has a full IP packet in its buffer.
       
   103 	(iObserver.Bca())->Read(iStatus, iData);
       
   104 
       
   105 	SetActive();
       
   106 	}