|
1 // Copyright (c) 2005-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 @released |
|
20 */ |
|
21 |
|
22 #include <elements/interfacetable.h> |
|
23 |
|
24 |
|
25 #ifdef _DEBUG |
|
26 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
27 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
28 _LIT(KSpecAssert_ElemNetIntfIntrf, "ElemNetIntfIntrf"); |
|
29 #endif |
|
30 |
|
31 using namespace NetInterfaces; |
|
32 _LIT(KNetInterfacesPanic, "NetInterfaces"); |
|
33 enum TNetInterfacesPanic |
|
34 { |
|
35 EInterfaceNotFound = 0, |
|
36 }; |
|
37 |
|
38 EXPORT_C TAny* TInterfaceControl::FetchInterfaceL(TInt aInterfaceId) |
|
39 { |
|
40 TAny* itf = DoFetchInterface(aInterfaceId); |
|
41 if(itf == NULL) |
|
42 { |
|
43 //Since we do not have control over 3rd party code we only check |
|
44 //and mask this error as KErrNotSupported rather than panic ESockSvr |
|
45 //(we panic in UDEB, please see DoFetchInterface); |
|
46 User::Leave(KErrInterfaceNotSupported); |
|
47 } |
|
48 |
|
49 return itf; |
|
50 } |
|
51 |
|
52 EXPORT_C TAny* TInterfaceControl::FetchInterface(TInt aInterfaceId) |
|
53 { |
|
54 TAny* itf = DoFetchInterface(aInterfaceId); |
|
55 if(itf == NULL) |
|
56 { |
|
57 // This is fatal. Either an TInterfaceControl was returned for a |
|
58 // particular interface id and the TInterfaceControl was inconsistent, |
|
59 // or a bad interface id was passed into FetchInterface. |
|
60 User::Panic(KNetInterfacesPanic, EInterfaceNotFound); |
|
61 } |
|
62 |
|
63 return itf; |
|
64 } |
|
65 |
|
66 TAny* TInterfaceControl::DoFetchInterface(TInt aInterfaceId) |
|
67 { |
|
68 const TFIEntry* head = iHead; |
|
69 |
|
70 // Find the interface implementer |
|
71 while((head != NULL) && (head->iIfId != aInterfaceId)) |
|
72 { |
|
73 head = head->iNextFn(); |
|
74 } |
|
75 |
|
76 // If not found, aInterfaceId is not valid, leave with KErrArgument |
|
77 TAny* iface = NULL; |
|
78 if(head != NULL) |
|
79 { |
|
80 // Ask the implementer for the interface reference (pointer) |
|
81 iface = head->iFetchFnL(this); |
|
82 //The returned pointer cannot be NULL because it has been returned from a leaving function. |
|
83 //This may be the case in one scenario, where the API extension implementer (TInterfaceControl |
|
84 //derived object) has returned NULL from ReturnInterfacePtrL() which is a bug. |
|
85 __ASSERT_DEBUG(iface,User::Panic(KNetInterfacesPanic, EInterfaceNotFound)); |
|
86 } |
|
87 |
|
88 return iface; |
|
89 } |
|
90 |
|
91 |
|
92 EXPORT_C TInterfaceIter::TInterfaceIter(const TInterfaceControl& aItfControl) |
|
93 : iItfControl(aItfControl), |
|
94 iCurrent(aItfControl.iHead) |
|
95 { |
|
96 } |
|
97 |
|
98 EXPORT_C TAny* TInterfaceIter::operator[](TInt aInd) |
|
99 { |
|
100 //aInd>0 not yet supported! |
|
101 __ASSERT_ALWAYS(aInd==0, User::Panic(KNetInterfacesPanic, EInterfaceNotFound)); |
|
102 const TInterfaceControl::TFIEntry* fetcher = iItfControl.iHead; |
|
103 return fetcher? fetcher->iFetchFnL(const_cast<TInterfaceControl*>(&iItfControl)) : NULL; |
|
104 } |
|
105 |
|
106 EXPORT_C TAny* TInterfaceIter::Next() |
|
107 { |
|
108 // Initialise current to head or grab next interface in list |
|
109 if (iCurrent == NULL) |
|
110 return NULL; |
|
111 |
|
112 iCurrent = iCurrent->iNextFn(); |
|
113 return iCurrent? iCurrent->iFetchFnL(const_cast<TInterfaceControl*>(&iItfControl)) : NULL; |
|
114 } |
|
115 |
|
116 EXPORT_C TBool AApiExtBase::SupportsExtInterface(TInt aInterfaceId) const |
|
117 { |
|
118 TRAPD(ret,const_cast<AApiExtBase*>(this)->FetchExtInterfaceL(aInterfaceId)); |
|
119 return ret == KErrNone; |
|
120 } |
|
121 |
|
122 EXPORT_C TInterfaceControl* AApiExtBase::FetchExtInterfaceControlL(TInt aInterfaceId) |
|
123 { |
|
124 return DoFetchInterfaceControlL(aInterfaceId); |
|
125 } |
|
126 |
|
127 EXPORT_C TAny* AApiExtBase::FetchExtInterfaceL(TInt aInterfaceId) |
|
128 { |
|
129 TInterfaceControl* tic = FetchExtInterfaceControlL(aInterfaceId); |
|
130 __ASSERT_DEBUG(tic, User::Panic(KSpecAssert_ElemNetIntfIntrf, 1)); |
|
131 return tic->FetchInterfaceL(aInterfaceId); |
|
132 } |
|
133 |
|
134 EXPORT_C TAny* AApiExtBase::FetchExtInterface(TInt aInterfaceId) |
|
135 { |
|
136 TInterfaceControl* tic = NULL; |
|
137 TRAP_IGNORE(tic = FetchExtInterfaceControlL(aInterfaceId)); |
|
138 return tic? tic->FetchInterface(aInterfaceId) : NULL; |
|
139 } |
|
140 |
|
141 EXPORT_C TInterfaceControl* AApiExtBase::DoFetchInterfaceControlL(TInt aInterfaceId) |
|
142 { |
|
143 (void)aInterfaceId; |
|
144 User::Leave(KErrInterfaceNotSupported); |
|
145 return NULL; |
|
146 } |
|
147 |
|
148 |