sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #ifndef __CALLBACK_H__
sl@0: #define __CALLBACK_H__
sl@0: 
sl@0: /**
sl@0: @file
sl@0: @internalTechnology
sl@0: */
sl@0: 
sl@0: #include <e32cmn.h>
sl@0: 
sl@0: /** enum to identify why callback is invoked. */
sl@0: enum TCallBackId
sl@0: 	{
sl@0: 	ECallBackId_None = 0,
sl@0: 	ECallBackId_ImplUpgrade,
sl@0: 	ECallBackId_SwiEvent,
sl@0: 	ECallBackId_BurEvent
sl@0: 	};
sl@0: 
sl@0: /** enum to generalize start and end of SWI or BUR */
sl@0: enum TCallBackState
sl@0: 	{
sl@0: 	ECallBackState_EventEnd,
sl@0: 	ECallBackState_EventStart
sl@0: 	};
sl@0: 
sl@0: /**
sl@0: This description is cloned from TCallBack in e32std.h. The only difference
sl@0: between TCallBack and TCallBackWithArg is that the callback of the
sl@0: latter takes 3 arguments.
sl@0: TCallBackWithArg encapsulates a general call-back function.
sl@0: The class encapsulates:
sl@0: 1. a pointer to a function which takes 3 arguments, TAny*, TInt, and TAny*
sl@0:    and returns a TInt.
sl@0: 2. a pointer which is passed to the function every time it is called.
sl@0:    The pointer can point to any object. This pointer is required in the constructor
sl@0:    but can be NULL if not used.
sl@0: 3. The TInt and the other TAny* arguments are passed in when invoking the callback
sl@0:    function.
sl@0: Do not let the names of the 3 callback arguments dictate their uses. Feel free
sl@0: to store anything you want or ignore anyone that is not needed.
sl@0: 
sl@0: The callback function can be a static function of a class,
sl@0: e.g. static TInt X::Foo(TAny*, TInt, TAny*) or
sl@0: it can be a function which is not a member of any class, e.g.
sl@0: TInt Foo(TAny *, TInt, TAny*).
sl@0: */
sl@0: class TCallBackWithArg
sl@0: 	{
sl@0: public:
sl@0: 	// default constructor
sl@0: 	inline TCallBackWithArg();
sl@0: 
sl@0: 	// Real constructor requires the callback function and a pointer.
sl@0: 	inline TCallBackWithArg(TInt (*aFunction)(TAny* aObj, TInt aEvent, TAny* aData), TAny* aObj);
sl@0: 
sl@0: 	inline TInt CallBack(TInt aEvent = ECallBackId_None,
sl@0: 						 TAny* aData = NULL) const;
sl@0: public:
sl@0: 	/** A pointer to the callback function. */
sl@0: 	TInt (*iFunction)(TAny* aObj, TInt aEvent, TAny* aData);
sl@0: 	
sl@0: 	/** the first argument in the callback function. */
sl@0: 	TAny* iObj;
sl@0: 	};
sl@0: 
sl@0: //
sl@0: // Implementation of TCallBackWithArg
sl@0: //
sl@0: 
sl@0: /** Default contructor sets the callback function
sl@0: to NULL. This way a not yet initialized callback object will just
sl@0: do nothing. */
sl@0: inline TCallBackWithArg::TCallBackWithArg()
sl@0: 	: iFunction(NULL), iObj(NULL)
sl@0: 	{ }
sl@0: 
sl@0: inline TCallBackWithArg::TCallBackWithArg(TInt (*aFunction)(TAny*, TInt, TAny*), TAny* aObj)
sl@0: 	: iFunction(aFunction), iObj(aObj)
sl@0: 	{ }
sl@0: 
sl@0: inline TInt TCallBackWithArg::CallBack(TInt aEvent, TAny* aData) const
sl@0: 	{ 
sl@0: 	return (iFunction ? (*iFunction)(iObj, aEvent, aData) : 0);
sl@0: 	}
sl@0: 
sl@0: #endif