commsfwsupport/commselements/factories/inc/factorynotify.h
changeset 0 dfb7c4ff071f
child 24 00c6709d25aa
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-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 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #ifndef SYMBIAN_FACTORYNOTIFY_H
       
    22 #define SYMBIAN_FACTORYNOTIFY_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <s32std.h>
       
    26 #include <elements/factory.h>
       
    27 
       
    28 namespace Factories
       
    29 {
       
    30 
       
    31 typedef void (*TInterfaceStateChangeFn)( TAny*, TDesC8& aInfo );
       
    32 typedef TInt (*TFactoryNotifyFn)( TAny*, AFactoryObject& aObject, CFactoryBase& aFactory );
       
    33 typedef void (*TAnyFn)(TAny*);
       
    34 
       
    35 //could be as a const static table part of the class
       
    36 class IFactoryNotify
       
    37 /**
       
    38  @internalComponent
       
    39  */
       
    40 	{
       
    41 public:
       
    42 	TBool operator==(const IFactoryNotify& aRhs) const
       
    43 		{
       
    44 		return (iThis == aRhs.iThis && iInterfaceVTable == aRhs.iInterfaceVTable);
       
    45 		}
       
    46 
       
    47 	IFactoryNotify( TAny* aThis, TAnyFn const& aInterfaceVTable ) :
       
    48 		iThis( aThis ),
       
    49 		iInterfaceVTable( &aInterfaceVTable )
       
    50 		{
       
    51 		}
       
    52 
       
    53 	void InterfaceStateChange(TDesC8& aInfo)
       
    54 		{
       
    55 		if ( Check(1) )
       
    56 			{
       
    57 			((TInterfaceStateChangeFn)(iInterfaceVTable[1]))(iThis,aInfo);
       
    58 			}
       
    59 		}
       
    60 	void NotifyDeletion(AFactoryObject& aObject, CFactoryBase& aFactory)
       
    61 		{
       
    62 		if ( Check(2) )
       
    63 			{
       
    64 			((TFactoryNotifyFn)(iInterfaceVTable[2]))(iThis, aObject, aFactory);
       
    65 			}
       
    66 		}
       
    67 	TInt NotifyCreation(AFactoryObject& aObject, CFactoryBase& aFactory)
       
    68 		{
       
    69 		return ( Check(3) ) ?
       
    70 			((TFactoryNotifyFn)(iInterfaceVTable[3]))(iThis, aObject, aFactory) :
       
    71 			KErrNone;
       
    72 		}
       
    73 
       
    74 protected:
       
    75 	TBool Check( TInt nFn )
       
    76 		{
       
    77 		return (TInt)iInterfaceVTable[0] >= nFn && iInterfaceVTable[nFn];
       
    78 		}
       
    79 
       
    80 protected:
       
    81 	TAny* iThis;
       
    82 	TAnyFn const* iInterfaceVTable;
       
    83 	};
       
    84 
       
    85 template <class TCLIENT>
       
    86 class TFactoryNotify
       
    87 /**
       
    88  @internalComponent
       
    89  */
       
    90 	{
       
    91 public:
       
    92 	static void Notification(TAny* aThis, TDesC8& aInfo);
       
    93 	static void NotifyDeletion(TAny* aThis, AFactoryObject& aObject, CFactoryBase& aFactory);
       
    94 	static TInt NotifyCreation(TAny* aThis, AFactoryObject& aObject, CFactoryBase& aFactory);
       
    95 
       
    96 	};
       
    97 
       
    98 template <class TCLIENT>
       
    99 void TFactoryNotify<TCLIENT>::Notification(TAny* aThis, TDesC8& aInfo)
       
   100 	{
       
   101 	TCLIENT* me = (TCLIENT*)aThis;
       
   102 	me->InterfaceStateChangeNotification(aInfo);
       
   103 	}
       
   104 
       
   105 template <class TCLIENT>
       
   106 void TFactoryNotify<TCLIENT>::NotifyDeletion(TAny* aThis, AFactoryObject& aObject, CFactoryBase& aFactory)
       
   107 	{
       
   108 	TCLIENT* me = (TCLIENT*)aThis;
       
   109 	me->NotifyDeletion(aObject, aFactory);
       
   110 	}
       
   111 
       
   112 template <class TCLIENT>
       
   113 TInt TFactoryNotify<TCLIENT>::NotifyCreation(TAny* aThis, AFactoryObject& aObject, CFactoryBase& aFactory)
       
   114 	{
       
   115 	TCLIENT* me = (TCLIENT*)aThis;
       
   116 	return me->NotifyCreation(aObject, aFactory);
       
   117 	}
       
   118 
       
   119 } //namespace Factories
       
   120 
       
   121 #endif // SYMBIAN_FACTORYNOTIFY_H
       
   122