commsfwsupport/commselements/NetInterfaces/inc/interfacetable_internal.h
changeset 0 dfb7c4ff071f
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 // interfacetable.h
       
    15 // THIS WHOLE FILE IS INTERNAL TECHNOLOGY - DO NOT ADD NON-INTERNAL ITEMS
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 
       
    24 #ifndef SYMBIAN_INTERFACETABLE_INTERNAL_H
       
    25 #define SYMBIAN_INTERFACETABLE_INTERNAL_H
       
    26 
       
    27 #include <e32std.h>
       
    28 
       
    29 const TInt KErrInterfaceNotSupported = -17204;	// Requested interface is not supported by this object
       
    30 
       
    31 namespace NetInterfaces
       
    32 {
       
    33 
       
    34 template<class TINTERFACE> struct TIfStaticFetcherFirstInHierarchy;
       
    35 class TInterfaceIter;
       
    36 
       
    37 class TInterfaceControl
       
    38 /**
       
    39 This class provides a base for an API extension implementer.
       
    40 It implements an interface towards the ESock server.
       
    41 
       
    42 */
       
    43 	{
       
    44 	friend class TIfStaticFetcherFirstInHierarchy<TInterfaceControl>;
       
    45 	friend class TInterfaceIter;
       
    46 
       
    47 public:
       
    48 	struct TFIEntry
       
    49 		{
       
    50 		typedef TAny* (*TStaticFetch)(TInterfaceControl*);
       
    51 		typedef const TFIEntry* (*TStaticNext)();
       
    52 		TInt iIfId;
       
    53 		TStaticFetch iFetchFnL;
       
    54 		TStaticNext iNextFn;
       
    55 		};
       
    56 
       
    57 public:
       
    58 	IMPORT_C TAny* FetchInterfaceL(TInt aInterfaceId);
       
    59 	IMPORT_C TAny* FetchInterface(TInt aInterfaceId);
       
    60 
       
    61 protected:
       
    62 	inline TInterfaceControl();
       
    63 
       
    64 private:
       
    65 	TAny* DoFetchInterface(TInt aInterfaceId);
       
    66 
       
    67 private:
       
    68 	const TFIEntry* iHead;
       
    69 	};
       
    70 
       
    71 TInterfaceControl::TInterfaceControl()
       
    72 :	iHead(NULL)
       
    73 	{
       
    74 	}
       
    75 
       
    76 /**
       
    77 	Simple iterator for all the interfaces available via a specified
       
    78 	TInterfaceControl.
       
    79 
       
    80 */
       
    81 class TInterfaceIter
       
    82 	{
       
    83 public:
       
    84 	IMPORT_C TInterfaceIter(const TInterfaceControl& aItfControl);
       
    85 
       
    86 	inline TInt ItfId() const
       
    87 		{
       
    88 		return iCurrent? iCurrent->iIfId : 0;
       
    89 		}
       
    90 
       
    91 	inline TAny* operator++(TInt /*aInd*/)	// postfix
       
    92 	    {
       
    93 	    return Next();
       
    94 		}
       
    95 
       
    96 	IMPORT_C TAny* operator[](TInt aInd);
       
    97 
       
    98 private:
       
    99 	IMPORT_C TAny* Next();
       
   100 
       
   101 private:
       
   102     const TInterfaceControl& iItfControl;
       
   103     const TInterfaceControl::TFIEntry* iCurrent;
       
   104 	};
       
   105 
       
   106 template <class TINTERFACE>
       
   107 class TIfStaticFetcherFirstInHierarchy
       
   108 /**
       
   109 This class provides a base for the templated hierarchy of
       
   110 interface fetchers.
       
   111 
       
   112 */
       
   113 	{
       
   114 public:
       
   115     inline static const TInterfaceControl::TFIEntry* IFEntry()
       
   116 		{
       
   117 		return NULL;
       
   118 		}
       
   119 
       
   120 protected:
       
   121 	inline explicit TIfStaticFetcherFirstInHierarchy(TInterfaceControl* aInterfaceControl, const TInterfaceControl::TFIEntry* aHead)
       
   122 		{
       
   123 		aInterfaceControl->iHead = aHead; //This class is a friend of TInterfaceControl so we can do this
       
   124 		}
       
   125 	};
       
   126 
       
   127 template <class TBASE, class TCLIENT, class TINTERFACE, class TLINK = TBASE>
       
   128 class TIfStaticFetcher : protected TBASE
       
   129 /**
       
   130 Helper templated class used to build a static const linked list of
       
   131 supported calls to ReturnInterfacePtrL().
       
   132 
       
   133 */
       
   134 	{
       
   135 public:
       
   136 	inline static const TInterfaceControl::TFIEntry* IFEntry()
       
   137 		{
       
   138 		return &iFIEntry;
       
   139 		}
       
   140 
       
   141 protected:
       
   142 	inline explicit TIfStaticFetcher(TInterfaceControl* aInterfaceControl, const TInterfaceControl::TFIEntry* aHead = NULL)
       
   143 	:	TBASE(aInterfaceControl,(aHead)?aHead:&iFIEntry)
       
   144 		{
       
   145 		}
       
   146 
       
   147 private:
       
   148 	inline static TAny* FetchL(TInterfaceControl* aInterfaceControl)
       
   149 		{
       
   150 		TINTERFACE* interface;
       
   151 		TCLIENT* cl = (TCLIENT*)aInterfaceControl;
       
   152 		cl->ReturnInterfacePtrL(interface);
       
   153 		return interface;
       
   154 		}
       
   155 	static const TInterfaceControl::TFIEntry iFIEntry;
       
   156 	};
       
   157 
       
   158 template <class TBASE, class TCLIENT, class TINTERFACE, class TLINK>
       
   159 const TInterfaceControl::TFIEntry TIfStaticFetcher<TBASE,TCLIENT,TINTERFACE,TLINK>::iFIEntry =
       
   160 	{
       
   161 	TINTERFACE::KInterfaceId,
       
   162 	&TIfStaticFetcher<TBASE,TCLIENT,TINTERFACE,TLINK>::FetchL,
       
   163 	&TLINK::IFEntry
       
   164 	};
       
   165 
       
   166 template <class TBASE, class TCLIENT, class TINTERFACE>
       
   167 class TIfStaticFetcherLinkBase : protected TBASE
       
   168 /**
       
   169 This template works like TIfStaticFetcher, but doesn't use a TLINK. This means that in the
       
   170 template name TLINK will not be expanded twice. The double expansion was causing linking problems
       
   171 with armlink. By using this class in ITFHIERARCHY_LINK_1, the final expansion will be shortened,
       
   172 and the linker bug will be avoided.
       
   173 This code is only here because of this bug.
       
   174 -IBK
       
   175 
       
   176 */
       
   177 	{
       
   178 public:
       
   179 	inline static const TInterfaceControl::TFIEntry* IFEntry()
       
   180 		{
       
   181 		return &iFIEntry;
       
   182 		}
       
   183 
       
   184 protected:
       
   185 	inline explicit TIfStaticFetcherLinkBase(TInterfaceControl* aInterfaceControl, const TInterfaceControl::TFIEntry* aHead = NULL)
       
   186 	:	TBASE(aInterfaceControl,(aHead)?aHead:&iFIEntry)
       
   187 		{
       
   188 		}
       
   189 
       
   190 private:
       
   191 	inline static TAny* FetchL(TInterfaceControl* aInterfaceControl)
       
   192 		{
       
   193 		TINTERFACE* interface;
       
   194 		TCLIENT* cl = (TCLIENT*)aInterfaceControl;
       
   195 		cl->ReturnInterfacePtrL(interface);
       
   196 		return interface;
       
   197 		}
       
   198 	static const TInterfaceControl::TFIEntry iFIEntry;
       
   199 	};
       
   200 
       
   201 template <class TBASE, class TCLIENT, class TINTERFACE>
       
   202 const TInterfaceControl::TFIEntry TIfStaticFetcherLinkBase<TBASE,TCLIENT,TINTERFACE>::iFIEntry =
       
   203 	{
       
   204 	TINTERFACE::KInterfaceId,
       
   205 	&TIfStaticFetcherLinkBase<TBASE,TCLIENT,TINTERFACE>::FetchL,
       
   206 	&TBASE::IFEntry
       
   207 	};
       
   208 
       
   209 
       
   210 
       
   211 class AApiExtBase
       
   212 /**
       
   213 */
       
   214 	{
       
   215 public:
       
   216 	IMPORT_C NetInterfaces::TInterfaceControl* FetchExtInterfaceControlL(TInt aInterfaceId);
       
   217 	IMPORT_C TAny* FetchExtInterfaceL(TInt aInterfaceId); //Never returns NULL
       
   218 	IMPORT_C TAny* FetchExtInterface(TInt aInterfaceId); //May return NULL
       
   219 	IMPORT_C TBool SupportsExtInterface(TInt aInterfaceId) const;
       
   220 	
       
   221 protected:
       
   222 	IMPORT_C virtual NetInterfaces::TInterfaceControl* DoFetchInterfaceControlL(TInt aInterfaceId);
       
   223 	};
       
   224 
       
   225 }	// namespace NetInterfaces
       
   226 
       
   227 #endif
       
   228 	//SYMBIAN_INTERFACETABLE_INTERNAL_H
       
   229 
       
   230 
       
   231