|
1 /* |
|
2 * Copyright (c) 2006-2007 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 "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: CCCHRequestStorage implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cchlogger.h" |
|
21 #include "cchserverbase.h" |
|
22 #include "cchrequeststorage.h" |
|
23 #include "cchconnmonhandler.h" |
|
24 #include "cchservicehandler.h" |
|
25 #include "cchsubsession.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // None |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // None |
|
32 |
|
33 // CONSTANTS |
|
34 // None |
|
35 |
|
36 // MACROS |
|
37 // None |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 // None |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 // None |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 // None |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 // None |
|
50 |
|
51 // ============================= LOCAL FUNCTIONS ============================= |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // IdentityRequestRelation |
|
55 // Compare two request storage entries. |
|
56 // (other items were commented in a header). |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 TBool IdentityRequestRelation( |
|
60 const TCCHStorageEntry& aFirst, |
|
61 const TCCHStorageEntry& aSecond ) |
|
62 { |
|
63 TBool result( EFalse ); |
|
64 |
|
65 result = ( aFirst.iRequest == aSecond.iRequest && |
|
66 aFirst.iSubsession == aSecond.iSubsession ); |
|
67 |
|
68 return result; |
|
69 } |
|
70 |
|
71 // ============================ MEMBER FUNCTIONS ============================= |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CCCHRequestStorage::CCCHRequestStorage |
|
75 // C++ default constructor can NOT contain any code, that might leave. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CCCHRequestStorage::CCCHRequestStorage( CCCHServerBase& aServer ) : |
|
79 iServer( aServer ) |
|
80 { |
|
81 // No implementation required |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CCCHRequestStorage::NewL |
|
86 // Two-phased constructor. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CCCHRequestStorage* CCCHRequestStorage::NewL( CCCHServerBase& aServer ) |
|
90 { |
|
91 CCCHRequestStorage* self = CCCHRequestStorage::NewLC( aServer ); |
|
92 CleanupStack::Pop( self ); |
|
93 return self; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CCCHRequestStorage::NewLC |
|
98 // Two-phased constructor. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CCCHRequestStorage* CCCHRequestStorage::NewLC( CCCHServerBase& aServer ) |
|
102 { |
|
103 CCCHRequestStorage* self = new (ELeave)CCCHRequestStorage( aServer ); |
|
104 CleanupStack::PushL( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // Destructor |
|
109 CCCHRequestStorage::~CCCHRequestStorage() |
|
110 { |
|
111 iRequests.Close(); |
|
112 iSubsessions.Close(); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CCCHRequestStorage::AddRequestL |
|
117 // Add new request into storage. |
|
118 // (other items were commented in a header). |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CCCHRequestStorage::AddRequestL( TCCHCommands aRequest, |
|
122 const RMessage2& aMessage, |
|
123 const CCCHSubsession* aSubsession ) |
|
124 { |
|
125 CCHLOGSTRING( "CCCHRequestStorage::AddRequestL: IN" ); |
|
126 CCHLOGSTRING3 |
|
127 ("CCCHRequestStorage::AddRequestL: Request = %d, Session = 0x%x", |
|
128 aRequest, aSubsession ); |
|
129 |
|
130 // Create new request entry |
|
131 TCCHStorageEntry* entry = new (ELeave) TCCHStorageEntry; |
|
132 CleanupStack::PushL( entry ); |
|
133 |
|
134 // Set entry data |
|
135 entry->iRequest = aRequest; |
|
136 entry->iMessage = new (ELeave) RMessage2( aMessage ); |
|
137 CleanupStack::PushL( entry->iMessage ); |
|
138 entry->iSubsession = aSubsession; |
|
139 |
|
140 // Check that subsession has not already made the request |
|
141 if ( KErrNotFound == |
|
142 iRequests.Find( *entry, IdentityRequestRelation ) ) |
|
143 { |
|
144 iRequests.AppendL( *entry ); |
|
145 |
|
146 switch ( aRequest ) |
|
147 { |
|
148 case ECCHEnableService: |
|
149 { |
|
150 TBool connectivityCheck( EFalse ); |
|
151 TServiceSelection serviceSelection( aMessage.Int0(), |
|
152 static_cast<TCCHSubserviceType>( aMessage.Int1() ) ); |
|
153 connectivityCheck = |
|
154 aMessage.Int2(); |
|
155 |
|
156 TInt err = iServer.ServiceHandler().EnableService( |
|
157 serviceSelection, connectivityCheck ); |
|
158 |
|
159 CompleteRequest( ECCHEnableService, aSubsession, err ); |
|
160 } |
|
161 break; |
|
162 case ECCHDisableService: |
|
163 { |
|
164 TServiceSelection serviceSelection( aMessage.Int0(), |
|
165 static_cast<TCCHSubserviceType>( aMessage.Int1() ) ); |
|
166 |
|
167 TInt err = iServer.ServiceHandler().DisableService( |
|
168 serviceSelection ); |
|
169 |
|
170 CompleteRequest( ECCHDisableService, aSubsession, err ); |
|
171 } |
|
172 break; |
|
173 case ECCHSetConnectionInfo: |
|
174 { |
|
175 TServiceConnectionInfo serviceConnInfo; |
|
176 |
|
177 TPckgBuf<TServiceConnectionInfo> serviceConnInfoPckg; |
|
178 aMessage.ReadL( 0, serviceConnInfoPckg ); |
|
179 |
|
180 serviceConnInfo.iServiceSelection.iServiceId = serviceConnInfoPckg().iServiceSelection.iServiceId; |
|
181 serviceConnInfo.iServiceSelection.iType = serviceConnInfoPckg().iServiceSelection.iType; |
|
182 serviceConnInfo.iServiceSelection.iParameter = serviceConnInfoPckg().iServiceSelection.iParameter; |
|
183 |
|
184 serviceConnInfo.iSNAPId = serviceConnInfoPckg().iSNAPId; |
|
185 serviceConnInfo.iIapId = serviceConnInfoPckg().iIapId; |
|
186 serviceConnInfo.iReserved = serviceConnInfoPckg().iReserved; |
|
187 |
|
188 if( serviceConnInfo.iServiceSelection.iParameter == ECchUsername ) |
|
189 { |
|
190 serviceConnInfo.iUsername = serviceConnInfoPckg().iUsername; |
|
191 serviceConnInfo.iUsername.ZeroTerminate(); |
|
192 } |
|
193 if( serviceConnInfo.iServiceSelection.iParameter == ECchPassword ) |
|
194 { |
|
195 /* : verify password will be zeroed correctly */ |
|
196 serviceConnInfo.iPassword = serviceConnInfoPckg().iPassword; |
|
197 serviceConnInfo.iPassword.ZeroTerminate(); |
|
198 } |
|
199 |
|
200 TInt err = iServer.ServiceHandler().SetConnectionInfo( |
|
201 serviceConnInfo ); |
|
202 |
|
203 CompleteRequest( ECCHSetConnectionInfo, aSubsession, err ); |
|
204 } |
|
205 break; |
|
206 case ECCHGetConnectionInfo: |
|
207 { |
|
208 TServiceConnectionInfo serviceConnInfo; |
|
209 |
|
210 TPckgBuf<TServiceConnectionInfo> serviceConnInfoPckg; |
|
211 aMessage.ReadL( 0, serviceConnInfoPckg ); |
|
212 |
|
213 serviceConnInfo.iServiceSelection.iServiceId = serviceConnInfoPckg().iServiceSelection.iServiceId; |
|
214 serviceConnInfo.iServiceSelection.iType = serviceConnInfoPckg().iServiceSelection.iType; |
|
215 serviceConnInfo.iServiceSelection.iParameter = serviceConnInfoPckg().iServiceSelection.iParameter; |
|
216 |
|
217 TInt err = iServer.ServiceHandler().GetConnectionInfo( |
|
218 serviceConnInfo ); |
|
219 |
|
220 CompleteRequestL( ECCHGetConnectionInfo, aSubsession, |
|
221 &serviceConnInfo, err ); |
|
222 } |
|
223 break; |
|
224 |
|
225 case ECCHGetServices: |
|
226 { |
|
227 TInt scanAllowed( KErrNone ); |
|
228 |
|
229 // if service id is greater than or equals zero then |
|
230 // this is Quick service discovery request. Network scan is |
|
231 // not performed. |
|
232 scanAllowed = aMessage.Int0(); |
|
233 |
|
234 if ( KErrNotFound == scanAllowed ) |
|
235 { |
|
236 ScanNetworks(); |
|
237 |
|
238 iServer.ServiceHandler().UpdateL( ETrue ); |
|
239 } |
|
240 |
|
241 |
|
242 TRAPD( err, |
|
243 iServer.ServiceHandler().GetServicesL( aMessage ) ); |
|
244 |
|
245 CompleteRequest( ECCHGetServices, aSubsession, err ); |
|
246 } |
|
247 break; |
|
248 default: |
|
249 break; |
|
250 } |
|
251 } |
|
252 else |
|
253 { |
|
254 // Notify request is already active |
|
255 CCHLOGSTRING |
|
256 ( "CCCHRequestStorage::AddRequestL: Request already active!" ); |
|
257 iServer.PanicClient( aMessage, KErrAlreadyExists ); |
|
258 } |
|
259 CleanupStack::Pop( entry->iMessage ); |
|
260 CleanupStack::PopAndDestroy( entry ); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CCCHRequestStorage::CompleteRequest |
|
265 // Complete request and remove it from storage. |
|
266 // (other items were commented in a header). |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 TInt CCCHRequestStorage::CompleteRequest( TCCHCommands aRequest, |
|
270 const CCCHSubsession* aSubsession, |
|
271 TInt aError ) |
|
272 { |
|
273 CCHLOGSTRING2 |
|
274 ( "CCCHRequestStorage::CompleteRequest: error: %d", aError ); |
|
275 |
|
276 TInt error( KErrNone ); |
|
277 TCCHStorageEntry entry; |
|
278 entry.iRequest = aRequest; |
|
279 entry.iSubsession = aSubsession; |
|
280 |
|
281 error = iRequests.Find( entry, IdentityRequestRelation ); |
|
282 if ( KErrNotFound != error ) |
|
283 { |
|
284 iRequests[ error ].iMessage->Complete( aError ); |
|
285 DeleteRequest( error ); |
|
286 |
|
287 // If no error -> return KErrNone |
|
288 error = KErrNone; |
|
289 } |
|
290 CCHLOGSTRING( "CCCHRequestStorage::CompleteRequest: OUT" ); |
|
291 return error; |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // CCCHRequestStorage::CompleteRequestL |
|
296 // Complete request and remove it from storage. |
|
297 // (other items were commented in a header). |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 TInt CCCHRequestStorage::CompleteRequestL( TCCHCommands aRequest, |
|
301 const CCCHSubsession* aSubsession, |
|
302 TAny* aParams, |
|
303 TInt aError ) |
|
304 { |
|
305 CCHLOGSTRING2 |
|
306 ( "CCCHRequestStorage::CompleteRequestL: error: %d", aError ); |
|
307 |
|
308 TInt error( KErrNone ); |
|
309 TCCHStorageEntry entry; |
|
310 entry.iRequest = aRequest; |
|
311 entry.iSubsession = aSubsession; |
|
312 |
|
313 error = iRequests.Find( entry, IdentityRequestRelation ); |
|
314 if ( KErrNotFound != error ) |
|
315 { |
|
316 if ( ECCHGetConnectionInfo == entry.iRequest ) |
|
317 { |
|
318 TPckgBuf<TServiceConnectionInfo> conInfo; |
|
319 iRequests[ error ].iMessage->ReadL( 0, conInfo ); |
|
320 conInfo().iServiceSelection.iServiceId = |
|
321 static_cast<TServiceConnectionInfo*>( aParams )->iServiceSelection.iServiceId; |
|
322 conInfo().iServiceSelection.iType = |
|
323 static_cast<TServiceConnectionInfo*>( aParams )->iServiceSelection.iType; |
|
324 conInfo().iSNAPId = |
|
325 static_cast<TServiceConnectionInfo*>( aParams )->iSNAPId; |
|
326 conInfo().iIapId = |
|
327 static_cast<TServiceConnectionInfo*>( aParams )->iIapId; |
|
328 conInfo().iSNAPLocked = |
|
329 static_cast<TServiceConnectionInfo*>( aParams )->iSNAPLocked; |
|
330 conInfo().iPasswordSet = |
|
331 static_cast<TServiceConnectionInfo*>( aParams )->iPasswordSet; |
|
332 conInfo().iUsername = static_cast<TServiceConnectionInfo*>( aParams )->iUsername; |
|
333 conInfo().iReserved = |
|
334 static_cast<TServiceConnectionInfo*>( aParams )->iReserved; |
|
335 |
|
336 iRequests[ error ].iMessage->WriteL( 0, conInfo ); |
|
337 } |
|
338 |
|
339 iRequests[ error ].iMessage->Complete( aError ); |
|
340 DeleteRequest( error ); |
|
341 |
|
342 // If no error -> return KErrNone |
|
343 error = KErrNone; |
|
344 } |
|
345 CCHLOGSTRING( "CCCHRequestStorage::CompleteRequestL: OUT" ); |
|
346 return error; |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CCCHRequestStorage::RemoveRequestsBySession |
|
351 // Remove all requests by session id. (Does not complete request) |
|
352 // (other items were commented in a header). |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 TInt CCCHRequestStorage::RemoveRequestsBySession( |
|
356 const CCCHSubsession* aSubSession ) |
|
357 { |
|
358 CCHLOGSTRING( "CCCHRequestStorage::RemoveRequestsBySession: IN" ); |
|
359 |
|
360 TInt error( KErrNotFound ); |
|
361 |
|
362 for ( TInt i( iRequests.Count() - 1 ); i >= 0; i-- ) |
|
363 { |
|
364 if ( iRequests[ i ].iSubsession == aSubSession ) |
|
365 { |
|
366 DeleteRequest( i ); |
|
367 error = KErrNone; |
|
368 } |
|
369 } |
|
370 CCHLOGSTRING( "CCCHRequestStorage::RemoveRequestsBySession: OUT" ); |
|
371 return error; |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CCCHRequestStorage::NotifySubserviceStatusChangeL |
|
376 // (other items were commented in a header). |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CCCHRequestStorage::NotifyServiceStatesChange( |
|
380 TServiceStatus aNewStatus ) |
|
381 { |
|
382 CCHLOGSTRING( "CCCHRequestStorage::NotifyServiceStatesChange: IN" ); |
|
383 //deliver the status event to all subsessions |
|
384 for ( TInt i = 0; i < iSubsessions.Count(); i++ ) |
|
385 { |
|
386 iSubsessions[ i ]->ServiceEventOccured( aNewStatus ); |
|
387 } |
|
388 |
|
389 CCHLOGSTRING( "CCCHRequestStorage::NotifyServiceStatesChange: OUT" ); |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CCCHRequestStorage::DeleteRequest |
|
394 // Delete message object |
|
395 // Delete entry from array |
|
396 // (other items were commented in a header). |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 void CCCHRequestStorage::DeleteRequest( TInt aIndex ) |
|
400 { |
|
401 CCHLOGSTRING( "CCCHRequestStorage::DeleteRequest: IN" ); |
|
402 CCHLOGSTRING2("CCCHRequestStorage::DeleteRequest: Index = %d", aIndex ); |
|
403 |
|
404 if ( iRequests.Count() > aIndex ) |
|
405 { |
|
406 delete iRequests[ aIndex ].iMessage; |
|
407 iRequests[ aIndex ].iMessage = NULL; |
|
408 |
|
409 // Remove entry from storage |
|
410 iRequests.Remove( aIndex ); |
|
411 } |
|
412 |
|
413 CCHLOGSTRING( "CCCHRequestStorage::DeleteRequest: OUT" ); |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------------------------- |
|
417 // CCCHRequestStorage::ScanNetworks |
|
418 // (other items were commented in a header). |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CCCHRequestStorage::ScanNetworks() |
|
422 { |
|
423 // ETrue indicates wlan network scan |
|
424 iServer.ConnMonHandler().ScanNetworks( ETrue ); |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CCCHRequestStorage::AddSession |
|
429 // (other items were commented in a header). |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CCCHRequestStorage::AddSession( |
|
433 CCCHSubsession* aSubSession ) |
|
434 { |
|
435 CCHLOGSTRING( "CCCHRequestStorage::AddSession: IN" ); |
|
436 |
|
437 if( KErrNotFound == iSubsessions.Find( aSubSession ) ) |
|
438 { |
|
439 iSubsessions.Append( aSubSession ); |
|
440 } |
|
441 |
|
442 CCHLOGSTRING( "CCCHRequestStorage::AddSession: OUT" ); |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------------------------- |
|
446 // CCCHRequestStorage::RemoveSession |
|
447 // (other items were commented in a header). |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 TInt CCCHRequestStorage::RemoveSession( |
|
451 const CCCHSubsession* aSubSession ) |
|
452 { |
|
453 CCHLOGSTRING( "CCCHRequestStorage::RemoveSession: IN" ); |
|
454 |
|
455 TInt error( KErrNotFound ); |
|
456 |
|
457 for ( TInt i = 0; i < iSubsessions.Count(); i++ ) |
|
458 { |
|
459 if ( iSubsessions[ i ] == aSubSession ) |
|
460 { |
|
461 iSubsessions.Remove( i ); |
|
462 error = KErrNone; |
|
463 break; |
|
464 } |
|
465 } |
|
466 CCHLOGSTRING( "CCCHRequestStorage::RemoveSession: OUT" ); |
|
467 return error; |
|
468 } |
|
469 |
|
470 // ========================== OTHER EXPORTED FUNCTIONS ======================= |
|
471 |
|
472 // End of File |