os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/callback.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/callback.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,102 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __CALLBACK_H__
    1.20 +#define __CALLBACK_H__
    1.21 +
    1.22 +/**
    1.23 +@file
    1.24 +@internalTechnology
    1.25 +*/
    1.26 +
    1.27 +#include <e32cmn.h>
    1.28 +
    1.29 +/** enum to identify why callback is invoked. */
    1.30 +enum TCallBackId
    1.31 +	{
    1.32 +	ECallBackId_None = 0,
    1.33 +	ECallBackId_ImplUpgrade,
    1.34 +	ECallBackId_SwiEvent,
    1.35 +	ECallBackId_BurEvent
    1.36 +	};
    1.37 +
    1.38 +/** enum to generalize start and end of SWI or BUR */
    1.39 +enum TCallBackState
    1.40 +	{
    1.41 +	ECallBackState_EventEnd,
    1.42 +	ECallBackState_EventStart
    1.43 +	};
    1.44 +
    1.45 +/**
    1.46 +This description is cloned from TCallBack in e32std.h. The only difference
    1.47 +between TCallBack and TCallBackWithArg is that the callback of the
    1.48 +latter takes 3 arguments.
    1.49 +TCallBackWithArg encapsulates a general call-back function.
    1.50 +The class encapsulates:
    1.51 +1. a pointer to a function which takes 3 arguments, TAny*, TInt, and TAny*
    1.52 +   and returns a TInt.
    1.53 +2. a pointer which is passed to the function every time it is called.
    1.54 +   The pointer can point to any object. This pointer is required in the constructor
    1.55 +   but can be NULL if not used.
    1.56 +3. The TInt and the other TAny* arguments are passed in when invoking the callback
    1.57 +   function.
    1.58 +Do not let the names of the 3 callback arguments dictate their uses. Feel free
    1.59 +to store anything you want or ignore anyone that is not needed.
    1.60 +
    1.61 +The callback function can be a static function of a class,
    1.62 +e.g. static TInt X::Foo(TAny*, TInt, TAny*) or
    1.63 +it can be a function which is not a member of any class, e.g.
    1.64 +TInt Foo(TAny *, TInt, TAny*).
    1.65 +*/
    1.66 +class TCallBackWithArg
    1.67 +	{
    1.68 +public:
    1.69 +	// default constructor
    1.70 +	inline TCallBackWithArg();
    1.71 +
    1.72 +	// Real constructor requires the callback function and a pointer.
    1.73 +	inline TCallBackWithArg(TInt (*aFunction)(TAny* aObj, TInt aEvent, TAny* aData), TAny* aObj);
    1.74 +
    1.75 +	inline TInt CallBack(TInt aEvent = ECallBackId_None,
    1.76 +						 TAny* aData = NULL) const;
    1.77 +public:
    1.78 +	/** A pointer to the callback function. */
    1.79 +	TInt (*iFunction)(TAny* aObj, TInt aEvent, TAny* aData);
    1.80 +	
    1.81 +	/** the first argument in the callback function. */
    1.82 +	TAny* iObj;
    1.83 +	};
    1.84 +
    1.85 +//
    1.86 +// Implementation of TCallBackWithArg
    1.87 +//
    1.88 +
    1.89 +/** Default contructor sets the callback function
    1.90 +to NULL. This way a not yet initialized callback object will just
    1.91 +do nothing. */
    1.92 +inline TCallBackWithArg::TCallBackWithArg()
    1.93 +	: iFunction(NULL), iObj(NULL)
    1.94 +	{ }
    1.95 +
    1.96 +inline TCallBackWithArg::TCallBackWithArg(TInt (*aFunction)(TAny*, TInt, TAny*), TAny* aObj)
    1.97 +	: iFunction(aFunction), iObj(aObj)
    1.98 +	{ }
    1.99 +
   1.100 +inline TInt TCallBackWithArg::CallBack(TInt aEvent, TAny* aData) const
   1.101 +	{ 
   1.102 +	return (iFunction ? (*iFunction)(iObj, aEvent, aData) : 0);
   1.103 +	}
   1.104 +
   1.105 +#endif