wvuing/wvuieng/EngSrc/CCABackgroundTask.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  This is encapsulation of a background task,
       
    15 *                part of CCARequestMapper
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CCABACKGROUNDTASK_H
       
    21 #define CCABACKGROUNDTASK_H
       
    22 
       
    23 // INCLUDES
       
    24 #include "MCABackgroundInterface.h"
       
    25 
       
    26 #include <e32base.h>
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 
       
    30 // CLASS DECLARATION
       
    31 class MCABackgroundCallback;
       
    32 
       
    33 /**
       
    34 *  Encapsulates a background task. This is a part of CCARequestMapper.
       
    35 *
       
    36 *
       
    37 *  @lib CAEngine.lib
       
    38 *  @since 1.2
       
    39 */
       
    40 class CCABackgroundTask : public CBase
       
    41     {
       
    42     public:  // Constructors and destructor
       
    43 
       
    44         /**
       
    45         * Static constructor.
       
    46         * @param aParent instance to call back with CIdle
       
    47         * @param aBackgroundTask background task to encapsulate
       
    48         * @param aTask id of the background task
       
    49         * @param aSubTasks number of iterations - greater than zero
       
    50         *	it leaves with KErrArgument if aSubTasks <= 0
       
    51         * @see MCABackgroundInterface::TCABackgroundTasks
       
    52         */
       
    53         static CCABackgroundTask* NewL(
       
    54             MCABackgroundCallback* aParent
       
    55             , MCABackgroundTask* aBackgroundTask
       
    56             , MCABackgroundInterface::TCABackgroundTasks aTask
       
    57             , TInt aSubTasks
       
    58         );
       
    59         /**
       
    60         * Static constructor.
       
    61         * @param aParent instance to call back with CIdle
       
    62         * @param aBackgroundTask background task to encapsulate
       
    63         * @param aTask id of the background task
       
    64         * @param aSubTasks number of iterations - greater than zero
       
    65         *	it leaves with KErrArgument if aSubTasks <= 0
       
    66         * @see MCABackgroundInterface::TCABackgroundTasks
       
    67         */
       
    68         static CCABackgroundTask* NewLC(
       
    69             MCABackgroundCallback* aParent
       
    70             , MCABackgroundTask* aBackgroundTask
       
    71             , MCABackgroundInterface::TCABackgroundTasks aTask
       
    72             , TInt aSubTasks
       
    73         );
       
    74         /**
       
    75         * Destructor.
       
    76         */
       
    77         virtual ~CCABackgroundTask();
       
    78 
       
    79     public: // New functions
       
    80 
       
    81         /**
       
    82         * Starts background execution ( CIdle ).
       
    83         */
       
    84         void Start();
       
    85 
       
    86         /**
       
    87         * Cancels background execution ( CIdle ).
       
    88         */
       
    89         void Cancel();
       
    90 
       
    91         /**
       
    92         * Identity relation for RArray Find(...)
       
    93         * @param aA for comparison
       
    94         * @param aB for comparison
       
    95         * @return ETrue if task ids are the same, EFalse otherwise
       
    96         */
       
    97         static TBool Identity( const CCABackgroundTask& aA
       
    98                                , const CCABackgroundTask& aB
       
    99                              );
       
   100         /**
       
   101         * @return the number of subtask/iteration left
       
   102         */
       
   103         TInt SubTasks();
       
   104 
       
   105         /**
       
   106         * @return the last execution state
       
   107         * @see MCABackgroundInterface::TCABackgroundStatus
       
   108         */
       
   109         MCABackgroundInterface::TCABackgroundStatus TaskState();
       
   110 
       
   111         /**
       
   112         * Sets State of this background task
       
   113         * @param aTaskState new state to set
       
   114         * @see MCABackgroundInterface::TCABackgroundStatus
       
   115         */
       
   116         void SetTaskState(
       
   117             MCABackgroundInterface::TCABackgroundStatus aTaskState );
       
   118 
       
   119         /**
       
   120         * Is more iteration left.
       
   121         * It detracts number of iterations by 1
       
   122         * @return ETrue if there is any after detraction( SubTasks() >0 ),
       
   123         */
       
   124         TBool More();
       
   125 
       
   126         /**
       
   127         * @return id of the background task
       
   128         * @see MCABackgroundInterface::TCABackgroundTasks
       
   129         */
       
   130         MCABackgroundInterface::TCABackgroundTasks TaskId();
       
   131 
       
   132         /**
       
   133         * @return pointer to the background task
       
   134         * no ownership transfer
       
   135         */
       
   136         MCABackgroundTask* BackgroundTask();
       
   137 
       
   138         /**
       
   139         * Executes background task.
       
   140         */
       
   141         void ExecuteTaskL();
       
   142 
       
   143         /**
       
   144         * @return ETrue if this task is active.
       
   145         */
       
   146         TBool Pending();
       
   147 
       
   148     private:
       
   149 
       
   150         /**
       
   151         * C++ default constructor.
       
   152         * @param aParent instance to call back with CIdle
       
   153         * @param aBackgroundTask background task to encapsulate
       
   154         * @param aTask id if the background task
       
   155         * @param aSubTasks number of iterations - greater than zero
       
   156         *	it leaves with KErrArgument if aSubTasks <= 0
       
   157         * @see MCABackgroundInterface::TCABackgroundTasks
       
   158         */
       
   159         CCABackgroundTask(
       
   160             MCABackgroundCallback* aParent
       
   161             , MCABackgroundTask* aBackgroundTask
       
   162             , MCABackgroundInterface::TCABackgroundTasks aTask
       
   163             , TInt aSubTasks
       
   164         );
       
   165 
       
   166         /**
       
   167         * By default Symbian 2nd phase constructor is private.
       
   168         */
       
   169         void ConstructL();
       
   170 
       
   171         /**
       
   172         * CIdle-kind of function for background task implementation
       
   173         * @param aInstance Instance of this class
       
   174         * @return Need for recall
       
   175         */
       
   176         static TInt BackgroundTask( TAny *aInstance );
       
   177 
       
   178         /**
       
   179         * Called by BackgroundTask().
       
   180         * Its calling instace given as aParent with aTask on construction.
       
   181         */
       
   182         TInt DoBackgroundTask();
       
   183 
       
   184     private:    // Data
       
   185         // Doesn't own
       
   186         MCABackgroundCallback* iParent;
       
   187         MCABackgroundTask* iBackgroundTask;
       
   188 
       
   189         //do own
       
   190         MCABackgroundInterface::TCABackgroundTasks iTask;
       
   191         TInt iSubTasks;
       
   192         MCABackgroundInterface::TCABackgroundStatus iTaskState;
       
   193         //Owns
       
   194         CIdle* iIdle;
       
   195 
       
   196 
       
   197     };
       
   198 
       
   199 #endif      // CCABACKGROUNDTASK_H
       
   200 
       
   201 // End of File