lowlevellibsandfws/pluginfw/Framework/frame/callback.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CALLBACK_H__
       
    17 #define __CALLBACK_H__
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalTechnology
       
    22 */
       
    23 
       
    24 #include <e32cmn.h>
       
    25 
       
    26 /** enum to identify why callback is invoked. */
       
    27 enum TCallBackId
       
    28 	{
       
    29 	ECallBackId_None = 0,
       
    30 	ECallBackId_ImplUpgrade,
       
    31 	ECallBackId_SwiEvent,
       
    32 	ECallBackId_BurEvent
       
    33 	};
       
    34 
       
    35 /** enum to generalize start and end of SWI or BUR */
       
    36 enum TCallBackState
       
    37 	{
       
    38 	ECallBackState_EventEnd,
       
    39 	ECallBackState_EventStart
       
    40 	};
       
    41 
       
    42 /**
       
    43 This description is cloned from TCallBack in e32std.h. The only difference
       
    44 between TCallBack and TCallBackWithArg is that the callback of the
       
    45 latter takes 3 arguments.
       
    46 TCallBackWithArg encapsulates a general call-back function.
       
    47 The class encapsulates:
       
    48 1. a pointer to a function which takes 3 arguments, TAny*, TInt, and TAny*
       
    49    and returns a TInt.
       
    50 2. a pointer which is passed to the function every time it is called.
       
    51    The pointer can point to any object. This pointer is required in the constructor
       
    52    but can be NULL if not used.
       
    53 3. The TInt and the other TAny* arguments are passed in when invoking the callback
       
    54    function.
       
    55 Do not let the names of the 3 callback arguments dictate their uses. Feel free
       
    56 to store anything you want or ignore anyone that is not needed.
       
    57 
       
    58 The callback function can be a static function of a class,
       
    59 e.g. static TInt X::Foo(TAny*, TInt, TAny*) or
       
    60 it can be a function which is not a member of any class, e.g.
       
    61 TInt Foo(TAny *, TInt, TAny*).
       
    62 */
       
    63 class TCallBackWithArg
       
    64 	{
       
    65 public:
       
    66 	// default constructor
       
    67 	inline TCallBackWithArg();
       
    68 
       
    69 	// Real constructor requires the callback function and a pointer.
       
    70 	inline TCallBackWithArg(TInt (*aFunction)(TAny* aObj, TInt aEvent, TAny* aData), TAny* aObj);
       
    71 
       
    72 	inline TInt CallBack(TInt aEvent = ECallBackId_None,
       
    73 						 TAny* aData = NULL) const;
       
    74 public:
       
    75 	/** A pointer to the callback function. */
       
    76 	TInt (*iFunction)(TAny* aObj, TInt aEvent, TAny* aData);
       
    77 	
       
    78 	/** the first argument in the callback function. */
       
    79 	TAny* iObj;
       
    80 	};
       
    81 
       
    82 //
       
    83 // Implementation of TCallBackWithArg
       
    84 //
       
    85 
       
    86 /** Default contructor sets the callback function
       
    87 to NULL. This way a not yet initialized callback object will just
       
    88 do nothing. */
       
    89 inline TCallBackWithArg::TCallBackWithArg()
       
    90 	: iFunction(NULL), iObj(NULL)
       
    91 	{ }
       
    92 
       
    93 inline TCallBackWithArg::TCallBackWithArg(TInt (*aFunction)(TAny*, TInt, TAny*), TAny* aObj)
       
    94 	: iFunction(aFunction), iObj(aObj)
       
    95 	{ }
       
    96 
       
    97 inline TInt TCallBackWithArg::CallBack(TInt aEvent, TAny* aData) const
       
    98 	{ 
       
    99 	return (iFunction ? (*iFunction)(iObj, aEvent, aData) : 0);
       
   100 	}
       
   101 
       
   102 #endif