|
1 /* |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class for instantiating Generic WLAN Plugins |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <wlanpluginclient.h> |
|
20 #include "wlangenericplugin.h" |
|
21 #include "am_debug.h" |
|
22 |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // CGenericWlanPlugin::CGenericWlanPlugin |
|
26 // |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CGenericWlanPlugin::CGenericWlanPlugin() |
|
30 { |
|
31 DEBUG("CGenericWlanPlugin::CGenericWlanPlugin"); |
|
32 iPluginArray.Reset(); |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CGenericWlanPlugin::~CGenericWlanPlugin |
|
37 // |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CGenericWlanPlugin::~CGenericWlanPlugin() |
|
41 { |
|
42 DEBUG("CGenericWlanPlugin::~CGenericWlanPlugin"); |
|
43 StopPlugins(); |
|
44 iPluginArray.Close(); |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CGenericWlanPlugin::StopPlugins |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CGenericWlanPlugin::StopPlugins() |
|
53 { |
|
54 DEBUG("CGenericWlanPlugin::StopPlugins"); |
|
55 for (TInt i = 0; i < iPluginArray.Count(); ++i) |
|
56 { |
|
57 if ( iPluginArray[i].iActiveScheduler ) |
|
58 { |
|
59 DEBUG3("CGenericWlanPlugin::StopPlugins - iPluginArray[%d] = UID: 0x%08X, ActiveScheduler 0x%08X", |
|
60 i, |
|
61 iPluginArray[i].iUid, |
|
62 iPluginArray[i].iActiveScheduler ); |
|
63 iPluginArray[i].iActiveScheduler->Halt( KErrNone ); |
|
64 } |
|
65 } |
|
66 iPluginArray.Reset(); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CGenericWlanPlugin::StartPlugins |
|
71 // |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CGenericWlanPlugin::StartPlugins() |
|
75 { |
|
76 DEBUG("CGenericWlanPlugin::StartPlugins"); |
|
77 |
|
78 // List implementations |
|
79 RImplInfoPtrArray implInfoArray; |
|
80 |
|
81 TRAPD( listImplementationsError, CGenericWlanPluginClient::ListImplementationsL( implInfoArray ) ); |
|
82 if ( listImplementationsError ) |
|
83 { |
|
84 DEBUG1("CGenericWlanPlugin::StartPlugins - CGenericWlanPluginClient::ListImplementationsL() failed with error %i", listImplementationsError ); |
|
85 implInfoArray.ResetAndDestroy(); |
|
86 return; |
|
87 } |
|
88 |
|
89 // Get number of implementations |
|
90 const TInt pluginCount( implInfoArray.Count() ); |
|
91 |
|
92 // Loop implementation info and create instances |
|
93 for (TInt i = 0; i < pluginCount; i++) |
|
94 { |
|
95 // Get next implementation info |
|
96 CImplementationInformation* info = static_cast<CImplementationInformation*>(implInfoArray[i] ); |
|
97 |
|
98 #ifdef _DEBUG |
|
99 // Trace information about plugin |
|
100 DEBUG1( "CGenericWlanPlugin::StartPlugins - Generic WLAN Plugin # %i", i ); |
|
101 DEBUG1( "CGenericWlanPlugin::StartPlugins - ImplementationUid 0x%08X", info->ImplementationUid().iUid ); |
|
102 TBuf8<KPrintLineLength> buf8; |
|
103 buf8.Copy( info->DisplayName() ); |
|
104 DEBUG1S("CGenericWlanPlugin::StartPlugins - DisplayName ", buf8.Length(), buf8.Ptr() ); |
|
105 DEBUG1( "CGenericWlanPlugin::StartPlugins - Version %i", info->Version() ); |
|
106 DEBUG1S("CGenericWlanPlugin::StartPlugins - DataType ", info->DataType().Length(), info->DataType().Ptr() ); |
|
107 DEBUG1S("CGenericWlanPlugin::StartPlugins - OpaqueData ", info->OpaqueData().Length(), info->OpaqueData().Ptr() ); |
|
108 DEBUG1( "CGenericWlanPlugin::StartPlugins - RomOnly %i", info->RomOnly() ); |
|
109 DEBUG1( "CGenericWlanPlugin::StartPlugins - RomBased %i", info->RomBased() ); |
|
110 DEBUG1( "CGenericWlanPlugin::StartPlugins - VendorId 0x%08X", info->VendorId().iId ); |
|
111 #endif |
|
112 CGenericWlanPlugin::TPluginArrayEntry entry; |
|
113 entry.iUid = info->ImplementationUid(); |
|
114 // Active scheduler will be updated when thread is started and Active Scheduler is created. |
|
115 entry.iActiveScheduler = NULL; |
|
116 iPluginArray.Append( entry ); |
|
117 |
|
118 RThread thread; |
|
119 TInt err = thread.Create( info->DisplayName(), GenericWlanPluginThreadMain, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, |
|
120 reinterpret_cast<TAny*>( &iPluginArray[ iPluginArray.Count()-1 ] ) /*EOwnerProcess / EOwnerThread*/ ); |
|
121 if (err != KErrNone) |
|
122 { |
|
123 DEBUG1("CGenericWlanPlugin::StartPlugins - thread.Create() failed with error %i", err ); |
|
124 implInfoArray.ResetAndDestroy(); |
|
125 return; |
|
126 } |
|
127 else |
|
128 { |
|
129 thread.Resume(); |
|
130 } |
|
131 thread.Close(); |
|
132 } |
|
133 |
|
134 // Reset and destroy implementations infos |
|
135 implInfoArray.ResetAndDestroy(); |
|
136 |
|
137 DEBUG1("CGenericWlanPlugin::StartPlugins - Started plugin count %i", pluginCount ); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CGenericWlanPlugin::GenericWlanPluginThreadMain |
|
142 // |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CGenericWlanPlugin::GenericWlanPluginThreadMain( TAny* aPluginArrayEntryPtr ) |
|
146 { |
|
147 DEBUG("CGenericWlanPlugin::GenericWlanPluginThreadMain()"); |
|
148 |
|
149 // Create cleanup stack |
|
150 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
151 if ( !cleanup ) |
|
152 { |
|
153 DEBUG("CGenericWlanPlugin::GenericWlanPluginThreadMain() - CTrapCleanup::New() failed. Stopping thread."); |
|
154 User::Exit( KErrNoMemory ); |
|
155 } |
|
156 |
|
157 __UHEAP_MARK; |
|
158 |
|
159 TRAPD(createError, LoadGenericWlanPluginL( reinterpret_cast<TPluginArrayEntry *>( aPluginArrayEntryPtr ) ) ); |
|
160 if ( createError ) |
|
161 { |
|
162 return createError; |
|
163 } |
|
164 |
|
165 __UHEAP_MARKEND; |
|
166 |
|
167 delete cleanup; |
|
168 return KErrNone; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CGenericWlanPlugin::LoadGenericWlanPluginL |
|
173 // |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CGenericWlanPlugin::LoadGenericWlanPluginL( TPluginArrayEntry * aPluginArrayEntryPtr ) |
|
177 { |
|
178 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
|
179 CleanupStack::PushL(scheduler); |
|
180 CActiveScheduler::Install(scheduler); |
|
181 |
|
182 aPluginArrayEntryPtr->iActiveScheduler = scheduler; |
|
183 |
|
184 // Initialize WLAN plugin |
|
185 CGenericWlanPluginClient* wlanPluginClient( NULL ); |
|
186 DEBUG1( "Instantiating CGenericWlanPluginClient(UID 0x%08X)", aPluginArrayEntryPtr->iUid ); |
|
187 TRAPD( ret, wlanPluginClient = CGenericWlanPluginClient::NewL( aPluginArrayEntryPtr->iUid ) ); |
|
188 // Create new instance of the plugin |
|
189 if( ret == KErrNone ) |
|
190 { |
|
191 DEBUG1("CGenericWlanPlugin::LoadGenericWlanPluginL() - wlanPluginClient instance 0x%08X", wlanPluginClient); |
|
192 /* |
|
193 * This thread will run in CActiveScheduler::Start() until CActiveScheduler is stopped. |
|
194 */ |
|
195 DEBUG("CGenericWlanPlugin::LoadGenericWlanPluginL() - Starting CActiveScheduler"); |
|
196 CActiveScheduler::Start(); |
|
197 |
|
198 DEBUG("CGenericWlanPlugin::LoadGenericWlanPluginL() - deleting wlanPluginClient"); |
|
199 delete wlanPluginClient; |
|
200 } |
|
201 else |
|
202 { |
|
203 DEBUG1( "CGenericWlanPlugin::LoadGenericWlanPluginL - CGenericWlanPluginClient::NewL leaved with %d, let's ignore it.", ret ); |
|
204 } |
|
205 |
|
206 // Delete active scheduler |
|
207 CleanupStack::PopAndDestroy(scheduler); |
|
208 |
|
209 DEBUG("CGenericWlanPlugin::LoadGenericWlanPluginL() - exit"); |
|
210 User::Exit( KErrNone ); |
|
211 } |