stif/ConsoleUI/inc/CallBack.h
changeset 0 a03f92240627
child 30 86a2e675b80a
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 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 file contains the header file of the CCallBack 
       
    15 * class.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef CALLBACK_H
       
    20 #define CALLBACK_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 // CONSTANTS
       
    26 // None
       
    27 
       
    28 // MACROS
       
    29 // None
       
    30 
       
    31 // DATA TYPES
       
    32 // None
       
    33 
       
    34 // FUNCTION PROTOTYPES
       
    35 // None
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 // None
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 // DESCRIPTION
       
    43 // Simple class for callbacks.
       
    44 
       
    45 class CCallBack 
       
    46     :public CAsyncCallBack
       
    47     {
       
    48     public: // Enumerations
       
    49 
       
    50     private: // Enumerations
       
    51 
       
    52     public:  // Constructors and destructor
       
    53         /**
       
    54         * C++ constructor.
       
    55         */
       
    56         CCallBack( TInt aPriority ):CAsyncCallBack( aPriority ) {}
       
    57 
       
    58         /**
       
    59         * C++ constructor.
       
    60         */
       
    61         CCallBack( TCallBack& aCallBack, TInt aPriority ):
       
    62             CAsyncCallBack( aCallBack, aPriority ) {}
       
    63     
       
    64     public: // New functions
       
    65         /**
       
    66         * Return reference to TRequestStatus member.
       
    67         */
       
    68         TRequestStatus& Status(){ return iStatus; }
       
    69 
       
    70         /**
       
    71         * Set CCallBack active.
       
    72         */
       
    73         void SetActive()
       
    74             { 
       
    75             iStatus = KRequestPending; 
       
    76             CActive::SetActive(); 
       
    77             };
       
    78     
       
    79     public: // Functions from base classes
       
    80    
       
    81         /**
       
    82         *
       
    83         */
       
    84         void RunL(){ iCallBack.CallBack(); }
       
    85 
       
    86     protected:  // New functions
       
    87         
       
    88     protected:  // Functions from base classes
       
    89         
       
    90     private:
       
    91 
       
    92 	public:     // Data
       
    93     
       
    94 	protected:  // Data
       
    95 
       
    96     private:    // Data
       
    97 
       
    98     public:     // Friend classes
       
    99 
       
   100     protected:  // Friend classes
       
   101 
       
   102     private:    // Friend classes
       
   103 
       
   104     };
       
   105 
       
   106 
       
   107 template <class T>
       
   108 class CActiveCallback 
       
   109         :public CActive
       
   110     {
       
   111     public: // Enumerations
       
   112 
       
   113         /**
       
   114         * Callback function type definitions
       
   115         */
       
   116        typedef void (T::* TestFunction)();    
       
   117 
       
   118     private: // Enumerations
       
   119 
       
   120     public:  // Constructors and destructor
       
   121         /**
       
   122         * C++ constructor.
       
   123         */
       
   124         CActiveCallback ( T* aClass, TestFunction aFunction ) : CActive (EPriorityStandard)
       
   125             {
       
   126             iMethod = aFunction;
       
   127             iClass = aClass;
       
   128             iCompleted = EFalse;
       
   129             }
       
   130     
       
   131     public: // New functions
       
   132         /**
       
   133         * Return reference to TRequestStatus member.
       
   134         */
       
   135         TRequestStatus& Status(){ return iStatus; }
       
   136 
       
   137         /**
       
   138         * Set active object to active and return reference to TRequestStatus member
       
   139         */
       
   140         TRequestStatus& Activate()
       
   141             {        
       
   142             iCompleted = EFalse;
       
   143             SetActive();
       
   144             return iStatus;
       
   145             }
       
   146 
       
   147         /**
       
   148         * Is callback completed?
       
   149         */
       
   150         TBool isCompleted()
       
   151             {
       
   152             return iCompleted;
       
   153             }
       
   154     
       
   155     public: // Functions from base classes
       
   156    
       
   157         /**
       
   158         * Call the callback
       
   159         */
       
   160         void RunL()
       
   161             {
       
   162             iCompleted = ETrue;
       
   163             if ( iMethod != NULL )
       
   164                 {
       
   165                 (iClass->*iMethod) ();
       
   166                 }        
       
   167             }
       
   168 
       
   169         /**
       
   170         * Just forward errors to framework
       
   171         */
       
   172         TInt RunError ( TInt aError )
       
   173             {
       
   174             return aError;
       
   175             }
       
   176 
       
   177         /**
       
   178         * Cancel is not supported.
       
   179         */
       
   180         void DoCancel ()
       
   181             {  
       
   182             }
       
   183 
       
   184     protected:  // New functions
       
   185         
       
   186     protected:  // Functions from base classes
       
   187         
       
   188     private:
       
   189 
       
   190 
       
   191 
       
   192 	public:     // Data
       
   193     
       
   194 	protected:  // Data
       
   195 
       
   196     private:    // Data
       
   197         TestFunction iMethod;           // Pointer to method to be called
       
   198         T* iClass;                      // Pointer to calls to be called
       
   199         TBool iCompleted;               // Is callback completed?
       
   200 
       
   201     public:     // Friend classes
       
   202 
       
   203     protected:  // Friend classes
       
   204 
       
   205     private:    // Friend classes
       
   206 
       
   207     };
       
   208 
       
   209 #endif      // CALLBACK_H  
       
   210             
       
   211 // End of File