systemswstubs/startupadaptationstub/src/CommandProcessingEngine.cpp
changeset 46 e1758cbb96ac
parent 0 0ce1b5ce9557
equal deleted inserted replaced
43:e71858845f73 46:e1758cbb96ac
       
     1 /*
       
     2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CCommandProcessingEngine class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CommandProcessingEngine.h"
       
    22 #include "CommandProcessingObserver.h"
       
    23 #include "StartupAdaptationStubDebug.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CCommandProcessingEngine::NewL
       
    29 // Two-phased constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CCommandProcessingEngine* CCommandProcessingEngine::NewL(
       
    33     MCommandProcessingObserver& aObserver )
       
    34     {
       
    35     CCommandProcessingEngine* self =
       
    36         new( ELeave ) CCommandProcessingEngine( aObserver );
       
    37 
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41 
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // Destructor
       
    47 CCommandProcessingEngine::~CCommandProcessingEngine()
       
    48     {
       
    49     Cancel();
       
    50     iTimer.Close();
       
    51     iCommands.Close();
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCommandProcessingEngine::ExecuteCommandL
       
    57 //
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CCommandProcessingEngine::ExecuteCommandL(
       
    61     const TInt aCommandId,
       
    62     const TInt aDuration )
       
    63     {
       
    64     RDEBUG_2( _L( "CCommandProcessingEngine::ExecuteCommandL( %d, %d )." ), aCommandId, aDuration );
       
    65 
       
    66     TCommandInfo info;
       
    67     info.iCommandId = aCommandId;
       
    68     info.iDuration = aDuration;
       
    69     iCommands.AppendL( info );
       
    70 
       
    71     if ( !IsActive() ) // If already active, this happens at the end of RunL.
       
    72     {
       
    73         ActivateWithTimeout( aDuration );
       
    74     }
       
    75 
       
    76     RDEBUG( _L( "CCommandProcessingEngine::ExecuteCommandL finished." ) );
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCommandProcessingEngine::RunL
       
    82 //
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CCommandProcessingEngine::RunL()
       
    86     {
       
    87     RDEBUG( _L( "CCommandProcessingEngine::RunL." ) );
       
    88     RDEBUG_1( _L( "Command count: %d." ), iCommands.Count() );
       
    89 
       
    90     __ASSERT_ALWAYS( iCommands.Count() > 0, User::Invariant() );
       
    91 
       
    92     const TInt& cmd = iCommands[0].iCommandId;
       
    93     RDEBUG_1( _L( "Processed command( %d )." ), cmd );
       
    94 
       
    95     iObserver.CommandProcessedL( cmd );
       
    96 
       
    97     iCommands.Remove( 0 );
       
    98 
       
    99     if ( iCommands.Count() > 0 ) // Check if there are more
       
   100         {                        // commands waiting to be processed.
       
   101         ActivateWithTimeout( iCommands[0].iDuration );
       
   102         }
       
   103 
       
   104     RDEBUG( _L( "CCommandProcessingEngine::RunL finished." ) );
       
   105     }
       
   106 
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCommandProcessingEngine::RunError
       
   110 //
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TInt CCommandProcessingEngine::RunError( TInt aError )
       
   114     {
       
   115     RDEBUG_1( _L( "CCommandProcessingEngine::RunError( %d )." ), aError );
       
   116     aError = aError; //To prevent compiler warning.
       
   117     RDEBUG( _L( "CCommandProcessingEngine::RunError finished." ) );
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CCommandProcessingEngine::DoCancel
       
   124 //
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CCommandProcessingEngine::DoCancel()
       
   128     {
       
   129     RDEBUG( _L( "CCommandProcessingEngine::DoCancel." ) );
       
   130 
       
   131     iTimer.Cancel();
       
   132 
       
   133     RDEBUG( _L( "CCommandProcessingEngine::DoCancel finished." ) );
       
   134     }
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CCommandProcessingEngine::CCommandProcessingEngine
       
   139 // C++ default constructor can NOT contain any code, that
       
   140 // might leave.
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 CCommandProcessingEngine::CCommandProcessingEngine(
       
   144     MCommandProcessingObserver& aObserver )
       
   145   : CActive( EPriorityStandard ), iObserver( aObserver )
       
   146     {
       
   147     CActiveScheduler::Add( this );
       
   148     }
       
   149 
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CCommandProcessingEngine::ConstructL
       
   153 // Symbian 2nd phase constructor can leave.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CCommandProcessingEngine::ConstructL()
       
   157     {
       
   158     User::LeaveIfError( iTimer.CreateLocal() );
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CCommandProcessingEngine::ActivateWithTimeout
       
   164 //
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CCommandProcessingEngine::ActivateWithTimeout( const TInt aDuration )
       
   168     {
       
   169     RDEBUG( _L( "CCommandProcessingEngine::ActivateWithTimeout." ) );
       
   170 
       
   171     iTimer.After( iStatus, 1000 * aDuration );
       
   172     SetActive();
       
   173 
       
   174     RDEBUG( _L( "CCommandProcessingEngine::ActivateWithTimeout finished." ) );
       
   175     }
       
   176 
       
   177 
       
   178 //  End of File