43 /** |
45 /** |
44 * Index of the first item in an array. |
46 * Index of the first item in an array. |
45 */ |
47 */ |
46 const TInt KFirstItemIndex = 0; |
48 const TInt KFirstItemIndex = 0; |
47 |
49 |
|
50 MWlanBgScanAwsComms* CWlanBgScanAwsCommsFactory::InstanceL( CWlanBgScan& aBgScan ) |
|
51 { |
|
52 DEBUG( "CWlanBgScanAwsCommsFactory::Instance()" ); |
|
53 return CWlanBgScanAwsComms::NewL( aBgScan ); |
|
54 } |
|
55 |
48 // ======== MEMBER FUNCTIONS ======== |
56 // ======== MEMBER FUNCTIONS ======== |
49 |
57 |
50 // --------------------------------------------------------------------------- |
58 // --------------------------------------------------------------------------- |
51 // CWlanBgScanAwsComms::CWlanBgScanAwsComms |
59 // CWlanBgScanAwsComms::CWlanBgScanAwsComms |
52 // --------------------------------------------------------------------------- |
60 // --------------------------------------------------------------------------- |
53 // |
61 // |
54 CWlanBgScanAwsComms::CWlanBgScanAwsComms( CWlanBgScan& aBgScan ) : |
62 CWlanBgScanAwsComms::CWlanBgScanAwsComms( CWlanBgScan& aBgScan ) : |
55 CActive( CActive::EPriorityStandard ), |
63 CActive( CActive::EPriorityStandard ), |
56 iBgScan( aBgScan ), |
64 iBgScan( aBgScan ), |
57 iAws( NULL ), |
65 iAws( NULL ), |
58 iAwsImplInfo( NULL ), |
66 iAwsImplUid( 0 ), |
59 iCommandHandler( NULL ), |
67 iCommandHandler( NULL ), |
60 iAwsVersion( 0 ), |
68 iAwsVersion( 0 ), |
61 iPendingCommand( EAwsCommandMax ), |
69 iPendingCommand( EAwsCommandMax ), |
62 iAwsOk( EFalse ) |
70 iAwsOk( EFalse ) |
63 { |
71 { |
64 DEBUG( "CWlanBgScanAwsComms::CWlanBgScanAwsComms()" ); |
72 DEBUG( "CWlanBgScanAwsComms::CWlanBgScanAwsComms()" ); |
65 } |
73 } |
66 |
74 |
67 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
68 // CWlanBgScanAwsComms::ConstructL |
76 // CWlanBgScanAwsComms::~CWlanBgScanAwsComms() |
69 // --------------------------------------------------------------------------- |
77 // --------------------------------------------------------------------------- |
70 // |
78 // |
71 void CWlanBgScanAwsComms::ConstructL() |
79 CWlanBgScanAwsComms::~CWlanBgScanAwsComms() |
72 { |
80 { |
73 DEBUG( "CWlanBgScanAwsComms::ConstructL()" ); |
81 DEBUG( "CWlanBgScanAwsComms::~CWlanBgScanAwsComms()" ); |
74 |
82 |
75 // create handler for incoming messages from AWS |
83 delete iAws; |
76 iCommandHandler = CWlanBgScanCommand::NewL( *this ); |
84 iAws = NULL; |
77 |
85 |
78 CActiveScheduler::Add( this ); |
86 delete iCommandHandler; |
79 |
87 iCommandHandler = NULL; |
80 // leaves if no AWS present in system |
88 |
81 StartAwsThreadL(); |
89 iAwsMsgQueue.Close(); |
82 |
90 Cancel(); |
83 DEBUG( "CWlanBgScanAwsComms::ConstructL() - done" ); |
91 iWlanEngineThread.Close(); |
|
92 //iStartupLock.Close(); |
84 } |
93 } |
85 |
94 |
86 // --------------------------------------------------------------------------- |
95 // --------------------------------------------------------------------------- |
87 // CWlanBgScanAwsComms::NewL |
96 // CWlanBgScanAwsComms::NewL |
88 // --------------------------------------------------------------------------- |
97 // --------------------------------------------------------------------------- |
96 CleanupStack::Pop( self ); |
105 CleanupStack::Pop( self ); |
97 return self; |
106 return self; |
98 } |
107 } |
99 |
108 |
100 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
101 // CWlanBgScanAwsComms::~CWlanBgScanAwsComms() |
110 // CWlanBgScanAwsComms::ConstructL |
102 // --------------------------------------------------------------------------- |
111 // --------------------------------------------------------------------------- |
103 // |
112 // |
104 CWlanBgScanAwsComms::~CWlanBgScanAwsComms() |
113 void CWlanBgScanAwsComms::ConstructL() |
105 { |
114 { |
106 DEBUG( "CWlanBgScanAwsComms::~CWlanBgScanAwsComms()" ); |
115 DEBUG( "CWlanBgScanAwsComms::ConstructL()" ); |
107 |
116 |
108 delete iAws; |
117 // Get handle to current (WLAN Engine) thread so that |
109 iAws = NULL; |
118 // the handle can be later used for completing the |
110 |
119 // request status from AWS thread. |
111 delete iAwsImplInfo; |
120 TThreadId id = RThread().Id(); |
112 iAwsImplInfo = NULL; |
121 TInt err = iWlanEngineThread.Open( id ); |
113 |
122 if( err != KErrNone ) |
114 delete iCommandHandler; |
123 { |
115 iCommandHandler = NULL; |
124 DEBUG( "CWlanBgScanAwsComms::ConstructL() - Opening own thread handle failed" ); |
116 |
125 User::Leave( KErrBadHandle ); |
117 iAwsMsgQueue.Close(); |
126 } |
118 Cancel(); |
127 |
|
128 // create handler for incoming messages from AWS |
|
129 iCommandHandler = CWlanBgScanCommand::NewL( *this ); |
|
130 |
|
131 CActiveScheduler::Add( this ); |
|
132 |
|
133 DEBUG( "CWlanBgScanAwsComms::ConstructL() - Starting AWS thread" ); |
|
134 |
|
135 // leaves if no AWS present in system |
|
136 StartAwsThreadL(); |
|
137 |
|
138 DEBUG( "CWlanBgScanAwsComms::ConstructL() - done" ); |
119 } |
139 } |
120 |
140 |
121 // --------------------------------------------------------------------------- |
141 // --------------------------------------------------------------------------- |
122 // CWlanBgScanAwsComms::CleanupEComArray |
142 // CWlanBgScanAwsComms::CleanupEComArray |
123 // --------------------------------------------------------------------------- |
143 // --------------------------------------------------------------------------- |
152 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - no AWS implementation found" ); |
174 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - no AWS implementation found" ); |
153 User::Leave( KErrNotFound ); |
175 User::Leave( KErrNotFound ); |
154 } |
176 } |
155 |
177 |
156 // first found AWS implementation will be taken into use |
178 // first found AWS implementation will be taken into use |
157 iAwsImplInfo = static_cast<CImplementationInformation*>( awsImplArray[KFirstItemIndex] ); |
179 CImplementationInformation* awsImplInfo = static_cast<CImplementationInformation*>( awsImplArray[KFirstItemIndex] ); |
158 awsImplArray.Remove( KFirstItemIndex ); |
180 iAwsImplUid = awsImplInfo->ImplementationUid().iUid; |
159 |
181 |
160 CleanupStack::PopAndDestroy( &awsImplArray ); //this causes a call to CleanupEComArray |
182 DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - trying to instantiate AWS implementation:" ); |
161 |
183 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - ImplementationUid: 0x%08X", awsImplInfo->ImplementationUid().iUid ); |
|
184 #ifdef _DEBUG |
|
185 TBuf8<KPrintLineLength> buf8; |
|
186 buf8.Copy( awsImplInfo->DisplayName() ); |
|
187 #endif |
|
188 DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - DisplayName: ", buf8.Length(), buf8.Ptr() ); |
|
189 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - Version: %i", awsImplInfo->Version() ); |
|
190 DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - DataType: ", awsImplInfo->DataType().Length(), awsImplInfo->DataType().Ptr() ); |
|
191 DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - OpaqueData: ", awsImplInfo->OpaqueData().Length(), awsImplInfo->OpaqueData().Ptr() ); |
|
192 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomOnly: %i", awsImplInfo->RomOnly() ); |
|
193 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomBased: %i", awsImplInfo->RomBased() ); |
|
194 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - VendorId: 0x%08X", awsImplInfo->VendorId().iId ); |
|
195 |
|
196 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting request status to pending" ); |
|
197 iStatus = KRequestPending; |
|
198 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting pending command to EAwsStartupCompleted" ); |
|
199 iPendingCommand = EAwsStartupCompleted; |
|
200 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting ao active" ); |
|
201 SetActive(); |
|
202 |
162 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - creating AWS thread" ); |
203 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - creating AWS thread" ); |
163 RThread thread; |
204 RThread thread; |
164 TInt err = thread.Create( iAwsImplInfo->DisplayName(), |
205 TInt err = thread.Create( awsImplInfo->DisplayName(), |
165 AwsThreadEntryPoint, |
206 AwsThreadEntryPoint, |
166 KDefaultStackSize, |
207 KDefaultStackSize, |
167 KMinHeapSize, |
208 KMinHeapSize, |
168 KMaxHeapSize, |
209 KMaxHeapSize, |
169 reinterpret_cast<TAny*>( this ) ); |
210 reinterpret_cast<TAny*>( this ) ); |
|
211 |
|
212 CleanupStack::PopAndDestroy( &awsImplArray ); //this causes a call to CleanupEComArray |
|
213 |
170 if( err != KErrNone) |
214 if( err != KErrNone) |
171 { |
215 { |
172 DEBUG1( "CWlanBgScanAwsComms::StartAwsThreadL() - error: thread creation failed with error %i", err ); |
216 DEBUG1( "CWlanBgScanAwsComms::StartAwsThreadL() - error: thread creation failed with error %i", err ); |
173 delete iAwsImplInfo; |
|
174 iAwsImplInfo = NULL; |
|
175 User::Leave( err ); |
217 User::Leave( err ); |
176 } |
218 } |
177 |
219 |
178 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - Resuming AWS thread" ); |
220 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - resuming AWS thread" ); |
179 thread.Resume(); |
221 thread.Resume(); |
180 thread.Close(); |
222 thread.Close(); |
181 |
223 |
182 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - done" ); |
224 DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - done" ); |
183 } |
225 } |
202 User::Exit( KErrNoMemory ); |
244 User::Exit( KErrNoMemory ); |
203 } |
245 } |
204 |
246 |
205 __UHEAP_MARK; |
247 __UHEAP_MARK; |
206 |
248 |
207 TRAPD( err, self->InstantiateAwsPluginL() ); |
249 TRAPD( err, self->InstantiateAndRunAwsPluginL() ); |
208 if ( err != KErrNone ) |
250 if ( err != KErrNone ) |
209 { |
251 { |
210 DEBUG1("CWlanBgScanAwsComms::AwsThreadEntryPoint() - AWS instantiation leaved with code %i", err); |
252 DEBUG1( "CWlanBgScanAwsComms::AwsThreadEntryPoint() - error: AWS instantiation leaved, completing request to WLAN Engine thread with code %i", err ); |
211 } |
253 TRequestStatus *status = &self->iStatus; |
212 |
254 self->iWlanEngineThread.RequestComplete( status, err ); |
|
255 } |
|
256 |
213 __UHEAP_MARKEND; |
257 __UHEAP_MARKEND; |
214 |
258 |
215 delete cleanup; |
259 delete cleanup; |
216 cleanup = NULL; |
260 cleanup = NULL; |
|
261 DEBUG( "CWlanBgScanAwsComms::AwsThreadEntryPoint() - AWS thread exiting" ); |
217 return KErrNone; |
262 return KErrNone; |
218 } |
263 } |
219 |
264 |
220 // ----------------------------------------------------------------------------- |
265 // ----------------------------------------------------------------------------- |
221 // CWlanBgScanAwsComms::InstantiateAwsPluginL |
266 // CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL |
222 // |
267 // |
223 // This method is executing in the context of the AWS thread. |
268 // This method is executing in the context of the AWS thread. |
224 // ----------------------------------------------------------------------------- |
269 // ----------------------------------------------------------------------------- |
225 // |
270 // |
226 void CWlanBgScanAwsComms::InstantiateAwsPluginL() |
271 void CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() |
227 { |
272 { |
228 DEBUG("CWlanBgScanAwsComms::InstantiateAwsPluginL()"); |
273 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL()" ); |
229 |
|
230 ASSERT( iAwsImplInfo ); |
|
231 |
274 |
232 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
275 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
233 CleanupStack::PushL( scheduler ); |
276 CleanupStack::PushL( scheduler ); |
234 CActiveScheduler::Install( scheduler ); |
277 CActiveScheduler::Install( scheduler ); |
235 |
278 |
236 DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - trying to instantiate AWS implementation:" ); |
279 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - active scheduler installed" ); |
237 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - ImplementationUid: 0x%08X", iAwsImplInfo->ImplementationUid().iUid ); |
|
238 #ifdef _DEBUG |
|
239 TBuf8<KPrintLineLength> buf8; |
|
240 buf8.Copy( iAwsImplInfo->DisplayName() ); |
|
241 #endif |
|
242 DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - DisplayName: ", buf8.Length(), buf8.Ptr() ); |
|
243 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - Version: %i", iAwsImplInfo->Version() ); |
|
244 DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - DataType: ", iAwsImplInfo->DataType().Length(), iAwsImplInfo->DataType().Ptr() ); |
|
245 DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - OpaqueData: ", iAwsImplInfo->OpaqueData().Length(), iAwsImplInfo->OpaqueData().Ptr() ); |
|
246 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomOnly: %i", iAwsImplInfo->RomOnly() ); |
|
247 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomBased: %i", iAwsImplInfo->RomBased() ); |
|
248 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - VendorId: 0x%08X", iAwsImplInfo->VendorId().iId ); |
|
249 |
|
250 CAwsEngineBase::TAwsEngineConstructionParameters params = { this, KBgScanVersion, iAwsVersion }; |
280 CAwsEngineBase::TAwsEngineConstructionParameters params = { this, KBgScanVersion, iAwsVersion }; |
251 iAws = CAwsEngineBase::NewL( iAwsImplInfo->ImplementationUid().iUid, ¶ms ); |
281 |
252 |
282 TRequestStatus *status = &iStatus; |
253 DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - AWS instantiated OK, iAwsVersion %u", iAwsVersion ); |
283 |
254 iAwsOk = ETrue; |
284 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - calling CAwsEngineBase::NewL()" ); |
255 |
285 iAws = CAwsEngineBase::NewL( iAwsImplUid, ¶ms ); // iAws deallocated in destructor |
256 __e32_memory_barrier(); |
286 |
257 DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - data members synchronized" ); |
287 DEBUG1( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - AWS version %u instantiated", iAwsVersion ); |
258 |
288 |
259 DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - starting active scheduler - AWS is now in control of this thread" ); |
289 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - completing request to WLAN Engine thread" ); |
|
290 iWlanEngineThread.RequestComplete( status, KErrNone ); |
|
291 |
|
292 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - starting active scheduler - AWS is now in control of this thread" ); |
260 CActiveScheduler::Start(); |
293 CActiveScheduler::Start(); |
261 |
294 |
262 // Thread execution will stay in CActiveScheduler::Start() until active scheduler is stopped |
295 // Thread execution will stay in CActiveScheduler::Start() until active scheduler is stopped |
263 DEBUG("CWlanBgScanAwsComms::InstantiateAwsPluginL() - active scheduler stopped" ); |
296 DEBUG("CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - active scheduler stopped" ); |
264 |
297 |
265 // clean up |
298 // clean up |
266 delete iAws; |
|
267 iAws = NULL; |
|
268 CleanupStack::PopAndDestroy( scheduler ); |
299 CleanupStack::PopAndDestroy( scheduler ); |
269 |
300 |
270 DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - exiting..." ); |
301 DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - done" ); |
271 User::Exit( KErrNone ); |
|
272 } |
302 } |
273 |
303 |
274 // --------------------------------------------------------------------------- |
304 // --------------------------------------------------------------------------- |
275 // From class MAwsBgScanProvider. |
305 // From class MAwsBgScanProvider. |
276 // CWlanBgScanAwsComms::SetInterval |
306 // CWlanBgScanAwsComms::SetInterval |
371 DEBUG( "CWlanBgScanAwsComms::SendAwsCommand() - done" ); |
405 DEBUG( "CWlanBgScanAwsComms::SendAwsCommand() - done" ); |
372 } |
406 } |
373 |
407 |
374 // --------------------------------------------------------------------------- |
408 // --------------------------------------------------------------------------- |
375 // CWlanBgScanAwsComms::RunL |
409 // CWlanBgScanAwsComms::RunL |
|
410 // |
|
411 // This method is executing in the context of the WLAN Engine thread. |
376 // --------------------------------------------------------------------------- |
412 // --------------------------------------------------------------------------- |
377 // |
413 // |
378 void CWlanBgScanAwsComms::RunL() |
414 void CWlanBgScanAwsComms::RunL() |
379 { |
415 { |
380 DEBUG2( "CWlanBgScanAwsComms::RunL() - command: %u, completion status: %d", iPendingCommand, iStatus.Int() ); |
416 DEBUG2( "CWlanBgScanAwsComms::RunL() - command: %u, completion status: %d", iPendingCommand, iStatus.Int() ); |
|
417 |
|
418 switch ( iPendingCommand ) |
|
419 { |
|
420 case EAwsStartupCompleted: |
|
421 { |
|
422 DEBUG( "CWlanBgScanAwsComms::RunL() - AWS startup has been completed" ); |
|
423 iBgScan.AwsStartupComplete( iStatus.Int() ); |
|
424 break; |
|
425 } |
|
426 default: |
|
427 { |
|
428 DEBUG( "CWlanBgScanAwsComms::RunL() - AWS command has been completed" ); |
|
429 iBgScan.AwsCommandComplete( iPendingCommand, iStatus.Int() ); |
|
430 break; |
|
431 } |
|
432 } |
381 |
433 |
382 TAwsMessage cmd = { EAwsCommandMax, NULL }; |
434 TAwsMessage cmd = { EAwsCommandMax, NULL }; |
383 |
435 |
384 // if there are more commands, send the next one |
436 // if there are more commands, send the next one |
385 if( iAwsMsgQueue.Count() ) |
437 if( iAwsMsgQueue.Count() ) |