bluetoothengine/bthid/bthidserver/inc/genericactive.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2008 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 v5.0
       
    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 v5.0
       
    52      * @param aActive the Active Object to which the request is assigned to.
       
    53      */
       
    54     virtual void CancelRequest(CGenericActive& aActive) = 0;
       
    55 
       
    56     /**
       
    57      * Callback to notify that an error has occurred in RunL.
       
    58      *
       
    59      * @since S60 v5.0
       
    60      * @param ?arg1 ?description
       
    61      */
       
    62     virtual void HandleError(TInt aId, TInt aError) = 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     static CGenericActive* NewL(MGenericActiveObserver& aObserver,
       
    82             CActive::TPriority aPriority, TInt aRequestId);
       
    83 
       
    84     virtual ~CGenericActive();
       
    85 
       
    86 public:
       
    87 
       
    88     /**
       
    89      * Calls SetActive().
       
    90      *
       
    91      * @since S60 v3.1
       
    92      */
       
    93     virtual void GoActive();
       
    94 
       
    95     /**
       
    96      * Gets the identifier of the request that this active object is serving.
       
    97      *
       
    98      * @since S60 v3.1
       
    99      * @return the request identifier
       
   100      */
       
   101     TInt RequestId() const;
       
   102 
       
   103     /**
       
   104      * Gets the identifier of the request that this active object is serving.
       
   105      *
       
   106      * @since S60 v3.1
       
   107      * @param the request identifier
       
   108      */
       
   109     void SetRequestId(TInt aRequestId);
       
   110 
       
   111     TRequestStatus& RequestStatus();
       
   112 
       
   113 protected:
       
   114 
       
   115     /**
       
   116      * From CActive. 
       
   117      * cancels the outstanding request.
       
   118      *
       
   119      * @since S60 v3.1
       
   120      */
       
   121     virtual void DoCancel();
       
   122 
       
   123     /**
       
   124      * From CActive. 
       
   125      * Handles the request completion event.
       
   126      *
       
   127      * @since S60 v3.1
       
   128      */
       
   129     virtual void RunL();
       
   130 
       
   131     /**
       
   132      * From CActive. 
       
   133      * Handles the leave from RunL().
       
   134      *
       
   135      * @since S60 v3.1
       
   136      * @param aError the leave code in RunL()
       
   137      * @return the error code to Active Scheduler
       
   138      */
       
   139     virtual TInt RunError(TInt aError);
       
   140 
       
   141 protected:
       
   142 
       
   143     CGenericActive(MGenericActiveObserver& aObserver,
       
   144             CActive::TPriority aPriority, TInt aRequestId);
       
   145 
       
   146 private:
       
   147 
       
   148     /**
       
   149      * The observer which is interested in the request handling events.
       
   150      * Not own.
       
   151      */
       
   152     MGenericActiveObserver& iObserver;
       
   153 
       
   154     /**
       
   155      * The request identifier assigned to this active object.
       
   156      */
       
   157     TInt iRequestId;
       
   158 
       
   159     };
       
   160 
       
   161 #endif  // C_GENERICACTIVE_H