phonebookui/Phonebook/Engine/inc/CPbkIdleProcessRunner.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *      Executes a MPbkBackgroundProcess in an idle loop.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __CPBKIDLEPROCESSRUNNER_H__
       
    21 #define __CPBKIDLEPROCESSRUNNER_H__
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class MPbkBackgroundProcess;
       
    28 class MPbkProcessObserver;
       
    29 
       
    30 // CLASS DECLARATION
       
    31 
       
    32 /**
       
    33  * Executes a MPbkBackgroundProcess in an idle loop.
       
    34  */
       
    35 NONSHARABLE_CLASS(CPbkIdleProcessRunner) :
       
    36         public CBase
       
    37     {
       
    38     public: // Constructors and destructor
       
    39         /**
       
    40          * Creates a new instance of this class.
       
    41 		 * @param aPriority desired priority of the active object
       
    42          */
       
    43         static CPbkIdleProcessRunner* NewL(TInt aPriority);
       
    44 
       
    45         /**
       
    46          * Destructor.
       
    47          */
       
    48         ~CPbkIdleProcessRunner();
       
    49 
       
    50     public: // Interface
       
    51         /**
       
    52          * Executes aProcess asynchronously in an idle loop.
       
    53          *
       
    54          * @param aProcess  process to execute.
       
    55          * @param aObserver process observer.
       
    56          */
       
    57         void Execute
       
    58             (MPbkBackgroundProcess& aProcess, MPbkProcessObserver* aObserver);
       
    59 
       
    60         /**
       
    61          * Executes aProcess in an idle loop. This function returns when the 
       
    62          * process completes or is interrupted.
       
    63          *
       
    64          * @param aProcess  process to execute.
       
    65          * @exception any error when executing the process.
       
    66          */
       
    67         void SynchronousExecuteL
       
    68             (MPbkBackgroundProcess& aProcess);
       
    69 
       
    70         /**
       
    71          * Cancels current execution.
       
    72          */
       
    73         void Cancel();
       
    74 
       
    75     private:  // Implementation
       
    76         CPbkIdleProcessRunner(TInt aPriority);
       
    77 
       
    78         class CRunner : public CActive
       
    79             {
       
    80             public:  // Interface
       
    81                 CRunner(TInt aPriority);
       
    82                 ~CRunner();
       
    83                 void Start
       
    84                     (MPbkBackgroundProcess& aProcess, 
       
    85                     MPbkProcessObserver* aObserver);
       
    86                 void RunSyncL(MPbkBackgroundProcess& aProcess);
       
    87                 void Stop();
       
    88 
       
    89             private:  // from CActive
       
    90                 void DoCancel();
       
    91                 void RunL();
       
    92                 TInt RunError(TInt aError);
       
    93 
       
    94             private:  // Implementation
       
    95                 void ProcessFinished();
       
    96                 void ProcessCanceled();
       
    97                 void Finalize(MPbkBackgroundProcess* aProcess);
       
    98                 void IssueRequest();
       
    99 
       
   100             private:  // Data
       
   101                 MPbkBackgroundProcess* iProcess;
       
   102                 MPbkProcessObserver* iObserver;
       
   103                 TInt* iProcessError;
       
   104                 CActiveSchedulerWait iActiveWait;
       
   105             };
       
   106 
       
   107     private:  // Data
       
   108 		/// Own: the active object
       
   109         CRunner iRunner;
       
   110     };
       
   111 
       
   112 
       
   113 #endif // __CPBKIDLEPROCESSRUNNER_H__
       
   114 
       
   115 // End of File