irda/irdastack/irtranp/COMMANDP.CPP
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1997-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 //
       
    15 
       
    16 #include "debug.h"
       
    17 #include <e32base.h>
       
    18 #include "COMMANDP.H"
       
    19 #include "ABSTRACT.H"
       
    20 #include "GLOBAL.H"
       
    21 
       
    22 CommandProcessor::CommandProcessor()
       
    23 	{
       
    24 	m_iCommands = 0;
       
    25 	m_iMaxCommands = 20;
       
    26 	for(TInt i=0;i<m_iMaxCommands;i++)
       
    27 		{
       
    28 		m_CommandQueue[i] = NULL;
       
    29 		}
       
    30 	}
       
    31 
       
    32 CommandProcessor::~CommandProcessor()
       
    33 	{
       
    34 	for(TInt i=0;i<m_iMaxCommands;i++)
       
    35 		{
       
    36 		//if(m_CommandQueue[i]!=NULL)
       
    37 		//	{
       
    38 			delete m_CommandQueue[i]; // Get rid of old commands!
       
    39 		//	}
       
    40 		}
       
    41 	}
       
    42 
       
    43 /*
       
    44 * Method description:	Called from SCEP with a new command to add into the outgoing queue
       
    45 *
       
    46 * Parameter:			a_oCommand - pointer to a command to send
       
    47 */
       
    48 
       
    49 void CommandProcessor::Add(AbstractCommand* a_oCommand)
       
    50 	{	
       
    51 	SCEPPRINT(_L("CommandProcessor: Add Command\n"));
       
    52 
       
    53 	m_CommandQueue[m_iCommands++] = a_oCommand;
       
    54 	if(m_iCommands >= m_iMaxCommands)
       
    55 		{
       
    56 		m_iCommands = 0; // yeah, sorry. We do leak old stuff for now.
       
    57 		}
       
    58 	}
       
    59 
       
    60 /*
       
    61 * Method description:	Called from SCEP when the application "pumps" the module for incoming/outgoing data processing
       
    62 *
       
    63 */
       
    64 
       
    65 void CommandProcessor::DoCommand()
       
    66 	{	
       
    67 	if(m_CommandQueue[0] != NULL)
       
    68 		{
       
    69 		SCEPPRINT(_L("CommandProcessor: DoCommand\n"));
       
    70 		m_CommandQueue[0]->DoIt(); // we always execute the first command in the queue!
       
    71 		
       
    72 		delete m_CommandQueue[0];
       
    73 		m_CommandQueue[0] = NULL; // well, it gets a new value below .. but anyway
       
    74 		ShiftQueue();
       
    75 		}
       
    76 	}
       
    77 
       
    78 	/*
       
    79 	* Method description:	Private method called to shift new commands to the beginning of the queue
       
    80 	*
       
    81 */
       
    82 
       
    83 void CommandProcessor::ShiftQueue()
       
    84 	{
       
    85 	for(TInt i=1;i<m_iCommands;i++)
       
    86 		{
       
    87 		m_CommandQueue[i-1] = m_CommandQueue[i];
       
    88 		}
       
    89 	m_CommandQueue[m_iCommands] = NULL; // obsolete pointer
       
    90 	m_iCommands--;
       
    91 	if(m_iCommands<0) // can this happen?
       
    92 		{
       
    93 		m_iCommands=0;
       
    94 		}
       
    95 	}