tsrc/public/basic/atextpluginapitest/inc/genericactive.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2007 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:  An Active Object offering its request status for any
       
    15 *                asynchronous request handling.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef C_GENERICACTIVE_H
       
    21 #define C_GENERICACTIVE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 
       
    26 class CGenericActive;
       
    27 
       
    28 /**
       
    29  * The observer of CGenericActive's request events
       
    30  *
       
    31  * This class defines the interface to handle request events from CGenericActive.
       
    32  *
       
    33  * @since S60 v3.1
       
    34  */
       
    35 class MGenericActiveObserver
       
    36     {
       
    37     
       
    38 public:
       
    39 
       
    40     /**
       
    41      * Called by CGenericActive::RunL() to handle the request completion event.
       
    42      *
       
    43      * @since S60 v3.1
       
    44      * @param aActive the Active Object to which the request is assigned to.
       
    45      */
       
    46     virtual void RequestCompletedL(CGenericActive& aActive) = 0;
       
    47     
       
    48     /**
       
    49      * alled by CGenericActive::RunL() to handle the cancellation of an outstanding request.
       
    50      *
       
    51      * @since S60 v3.1
       
    52      * @param aActive the Active Object to which the request is assigned to.
       
    53      */
       
    54     virtual void CancelRequest(CGenericActive& aActive) = 0;
       
    55     
       
    56     /**
       
    57      * alled by CGenericActive::RunError() to handle an exception.
       
    58      *
       
    59      * @since S60 v3.1
       
    60      * @param aErr the leave code of RunL()
       
    61      */
       
    62     virtual TInt HandleRunError(TInt aErr) = 0;
       
    63     };
       
    64 
       
    65 /**
       
    66  *
       
    67  * CGenericActive provides TRequestStatus for an async operation but it doesn't know the
       
    68  * detail of the request. CGenericActive could be used to implement timers, P&S subscribes 
       
    69  * that are "simple" enough operations. 
       
    70  *
       
    71  * @since S60 v3.1
       
    72  */
       
    73 class CGenericActive : public CActive
       
    74     {
       
    75     
       
    76 public:
       
    77 
       
    78     static CGenericActive* New(MGenericActiveObserver& aObserver, 
       
    79         CActive::TPriority aPriority, TInt aRequestId);
       
    80     
       
    81 
       
    82     static CGenericActive* NewL(MGenericActiveObserver& aObserver, 
       
    83         CActive::TPriority aPriority, TInt aRequestId);
       
    84 
       
    85     virtual ~CGenericActive();
       
    86 
       
    87 public:
       
    88 
       
    89     /**
       
    90      * Calls SetActive().
       
    91      *
       
    92      * @since S60 v3.1
       
    93      */
       
    94     virtual void GoActive();
       
    95 
       
    96     /**
       
    97      * Gets the identifier of the request that this active object is serving.
       
    98      *
       
    99      * @since S60 v3.1
       
   100      * @return the request identifier
       
   101      */
       
   102     TInt RequestId() const;
       
   103     
       
   104     /**
       
   105      * Gets the identifier of the request that this active object is serving.
       
   106      *
       
   107      * @since S60 v3.1
       
   108      * @param the request identifier
       
   109      */
       
   110     void SetRequestId(TInt aRequestId);
       
   111 
       
   112     TRequestStatus& RequestStatus();
       
   113 
       
   114 protected:
       
   115 
       
   116     /**
       
   117      * From CActive. 
       
   118      * cancels the outstanding request.
       
   119      *
       
   120      * @since S60 v3.1
       
   121      */
       
   122     virtual void DoCancel();
       
   123 
       
   124     /**
       
   125      * From CActive. 
       
   126      * Handles the request completion event.
       
   127      *
       
   128      * @since S60 v3.1
       
   129      */
       
   130     virtual void RunL();
       
   131 
       
   132     /**
       
   133      * From CActive. 
       
   134      * Handles the leave from RunL().
       
   135      *
       
   136      * @since S60 v3.1
       
   137      * @param aError the leave code in RunL()
       
   138      * @return the error code to Active Scheduler
       
   139      */
       
   140     virtual TInt RunError(TInt aError);
       
   141 
       
   142 protected:
       
   143 
       
   144     CGenericActive(MGenericActiveObserver& aObserver, 
       
   145         CActive::TPriority aPriority, TInt aRequestId);
       
   146 
       
   147 private:
       
   148 
       
   149     /**
       
   150      * The observer which is interested in the request handling events.
       
   151      * Not own.
       
   152      */
       
   153     MGenericActiveObserver& iObserver;
       
   154     
       
   155     /**
       
   156      * The request identifier assigned to this active object.
       
   157      */
       
   158     TInt iRequestId;
       
   159     
       
   160     };
       
   161 
       
   162 #endif  // C_GENERICACTIVE_H