68 #include <aputils.h> |
67 #include <aputils.h> |
69 #endif |
68 #endif |
70 |
69 |
71 QTM_BEGIN_NAMESPACE |
70 QTM_BEGIN_NAMESPACE |
72 |
71 |
73 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
|
74 static const int KValueThatWillBeAddedToSNAPId = 1000; |
|
75 #endif |
|
76 static const int KUserChoiceIAPId = 0; |
72 static const int KUserChoiceIAPId = 0; |
77 |
73 |
78 QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() |
74 QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() |
79 : QObject(0), CActive(CActive::EPriorityIdle), capFlags(0), |
75 : QObject(0), CActive(CActive::EPriorityHigh), capFlags(0), |
80 iFirstUpdate(true), iInitOk(true), iIgnoringUpdates(false), |
76 iFirstUpdate(true), iInitOk(true), iUpdatePending(false), |
81 iTimeToWait(0), iIgnoreEventLoop(0) |
77 iTimeToWait(0) |
82 { |
78 { |
83 CActiveScheduler::Add(this); |
79 CActiveScheduler::Add(this); |
84 |
80 |
85 // Seed the randomgenerator |
81 // Seed the randomgenerator |
86 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()) + QCoreApplication::applicationPid()); |
82 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()) + QCoreApplication::applicationPid()); |
87 iIgnoreEventLoop = new QEventLoop(this); |
|
88 |
83 |
89 registerPlatformCapabilities(); |
84 registerPlatformCapabilities(); |
90 TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); |
85 TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); |
91 if (error != KErrNone) { |
86 if (error != KErrNone) { |
92 iInitOk = false; |
87 iInitOk = false; |
93 return; |
88 return; |
94 } |
89 } |
95 |
90 |
96 TRAP_IGNORE(iConnectionMonitor.ConnectL()); |
91 TRAP_IGNORE(iConnectionMonitor.ConnectL()); |
|
92 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
|
93 TRAP_IGNORE(iConnectionMonitor.SetUintAttribute(EBearerIdAll, 0, KBearerGroupThreshold, 1)); |
|
94 #endif |
97 TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); |
95 TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); |
98 |
96 |
99 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
97 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
100 TRAP(error, iCmManager.OpenL()); |
98 TRAP(error, iCmManager.OpenL()); |
101 if (error != KErrNone) { |
99 if (error != KErrNone) { |
217 iCmManager.ConnectionMethodL(connectionMethods); |
233 iCmManager.ConnectionMethodL(connectionMethods); |
218 for(int i = 0; i < connectionMethods.Count(); i++) { |
234 for(int i = 0; i < connectionMethods.Count(); i++) { |
219 RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); |
235 RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); |
220 CleanupClosePushL(connectionMethod); |
236 CleanupClosePushL(connectionMethod); |
221 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
237 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
222 QString ident = QString::number(qHash(iapId)); |
238 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId)); |
223 if (accessPointConfigurations.contains(ident)) { |
239 if (accessPointConfigurations.contains(ident)) { |
224 knownConfigs.removeOne(ident); |
240 knownConfigs.removeOne(ident); |
225 } else { |
241 } else { |
226 QNetworkConfigurationPrivate* cpPriv = NULL; |
242 QNetworkConfigurationPrivate* cpPriv = NULL; |
227 TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); |
243 TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); |
245 iCmManager.AllDestinationsL(destinations); |
265 iCmManager.AllDestinationsL(destinations); |
246 for(int i = 0; i < destinations.Count(); i++) { |
266 for(int i = 0; i < destinations.Count(); i++) { |
247 RCmDestination destination; |
267 RCmDestination destination; |
248 destination = iCmManager.DestinationL(destinations[i]); |
268 destination = iCmManager.DestinationL(destinations[i]); |
249 CleanupClosePushL(destination); |
269 CleanupClosePushL(destination); |
250 QString ident = QString::number(qHash(destination.Id()+KValueThatWillBeAddedToSNAPId)); //TODO: Check if it's ok to add 1000 SNAP Id to prevent SNAP ids overlapping IAP ids |
270 QString ident = QT_BEARERMGMT_CONFIGURATION_SNAP_PREFIX+QString::number(qHash(destination.Id())); |
251 if (snapConfigurations.contains(ident)) { |
271 if (snapConfigurations.contains(ident)) { |
252 knownSnapConfigs.removeOne(ident); |
272 knownSnapConfigs.removeOne(ident); |
253 } else { |
273 } else { |
254 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
274 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
255 CleanupStack::PushL(cpPriv); |
|
256 |
275 |
257 HBufC *pName = destination.NameLC(); |
276 HBufC *pName = destination.NameLC(); |
258 cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); |
277 QT_TRYCATCH_LEAVING(cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length())); |
259 CleanupStack::PopAndDestroy(pName); |
278 CleanupStack::PopAndDestroy(pName); |
260 pName = NULL; |
279 pName = NULL; |
261 |
280 |
262 cpPriv->isValid = true; |
281 cpPriv->isValid = true; |
263 cpPriv->id = ident; |
282 cpPriv->id = ident; |
272 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); |
291 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); |
273 snapConfigurations.insert(ident, ptr); |
292 snapConfigurations.insert(ident, ptr); |
274 if (!iFirstUpdate) { |
293 if (!iFirstUpdate) { |
275 QNetworkConfiguration item; |
294 QNetworkConfiguration item; |
276 item.d = ptr; |
295 item.d = ptr; |
277 emit configurationAdded(item); |
296 QT_TRYCATCH_LEAVING(emit configurationAdded(item)); |
278 } |
297 } |
279 |
|
280 CleanupStack::Pop(cpPriv); |
|
281 } |
298 } |
282 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> privSNAP = snapConfigurations.value(ident); |
299 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> privSNAP = snapConfigurations.value(ident); |
283 |
300 |
284 for (int j=0; j < destination.ConnectionMethodCount(); j++) { |
301 for (int j=0; j < destination.ConnectionMethodCount(); j++) { |
285 RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); |
302 RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); |
286 CleanupClosePushL(connectionMethod); |
303 CleanupClosePushL(connectionMethod); |
287 |
304 |
288 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
305 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
289 QString iface = QString::number(qHash(iapId)); |
306 QString iface = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId)); |
290 // Check that IAP can be found from accessPointConfigurations list |
307 // Check that IAP can be found from accessPointConfigurations list |
291 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
308 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
292 if (priv.data() == 0) { |
309 if (priv.data() == 0) { |
293 QNetworkConfigurationPrivate* cpPriv = NULL; |
310 QNetworkConfigurationPrivate* cpPriv = NULL; |
294 TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); |
311 TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); |
338 // Loop through all IAPs |
355 // Loop through all IAPs |
339 TUint32 apId = 0; |
356 TUint32 apId = 0; |
340 TInt retVal = pDbTView->GotoFirstRecord(); |
357 TInt retVal = pDbTView->GotoFirstRecord(); |
341 while (retVal == KErrNone) { |
358 while (retVal == KErrNone) { |
342 pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); |
359 pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); |
343 QString ident = QString::number(qHash(apId)); |
360 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId)); |
344 if (accessPointConfigurations.contains(ident)) { |
361 if (accessPointConfigurations.contains(ident)) { |
345 knownConfigs.removeOne(ident); |
362 knownConfigs.removeOne(ident); |
346 } else { |
363 } else { |
347 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
364 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
348 if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { |
365 if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { |
349 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); |
366 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); |
350 accessPointConfigurations.insert(ident, ptr); |
367 accessPointConfigurations.insert(ident, ptr); |
351 if (!iFirstUpdate) { |
368 if (!iFirstUpdate) { |
352 QNetworkConfiguration item; |
369 QNetworkConfiguration item; |
353 item.d = ptr; |
370 item.d = ptr; |
354 emit configurationAdded(item); |
371 QT_TRYCATCH_LEAVING(emit configurationAdded(item)); |
355 } |
372 } |
356 } else { |
373 } else { |
357 delete cpPriv; |
374 delete cpPriv; |
358 } |
375 } |
359 } |
376 } |
360 retVal = pDbTView->GotoNextRecord(); |
377 retVal = pDbTView->GotoNextRecord(); |
361 } |
378 } |
362 CleanupStack::PopAndDestroy(pDbTView); |
379 CleanupStack::PopAndDestroy(pDbTView); |
363 #endif |
380 #endif |
364 updateActiveAccessPoints(); |
381 QT_TRYCATCH_LEAVING(updateActiveAccessPoints()); |
365 |
382 |
366 foreach (const QString &oldIface, knownConfigs) { |
383 foreach (const QString &oldIface, knownConfigs) { |
367 //remove non existing IAP |
384 //remove non existing IAP |
368 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(oldIface); |
385 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(oldIface); |
369 priv->isValid = false; |
386 priv->isValid = false; |
370 if (!iFirstUpdate) { |
387 if (!iFirstUpdate) { |
371 QNetworkConfiguration item; |
388 QNetworkConfiguration item; |
372 item.d = priv; |
389 item.d = priv; |
373 emit configurationRemoved(item); |
390 QT_TRYCATCH_LEAVING(emit configurationRemoved(item)); |
374 } |
391 } |
375 // Remove non existing IAP from SNAPs |
392 // Remove non existing IAP from SNAPs |
376 foreach (const QString &iface, snapConfigurations.keys()) { |
393 foreach (const QString &iface, snapConfigurations.keys()) { |
377 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv2 = snapConfigurations.value(iface); |
394 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv2 = snapConfigurations.value(iface); |
378 // => Check if one of the IAPs of the SNAP is active |
395 // => Check if one of the IAPs of the SNAP is active |
389 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = snapConfigurations.take(oldIface); |
406 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = snapConfigurations.take(oldIface); |
390 priv->isValid = false; |
407 priv->isValid = false; |
391 if (!iFirstUpdate) { |
408 if (!iFirstUpdate) { |
392 QNetworkConfiguration item; |
409 QNetworkConfiguration item; |
393 item.d = priv; |
410 item.d = priv; |
394 emit configurationRemoved(item); |
411 QT_TRYCATCH_LEAVING(emit configurationRemoved(item)); |
395 } |
412 } |
396 } |
413 } |
397 } |
414 } |
398 |
415 |
399 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
416 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
400 QNetworkConfigurationPrivate* QNetworkConfigurationManagerPrivate::configFromConnectionMethodL( |
417 QNetworkConfigurationPrivate* QNetworkConfigurationManagerPrivate::configFromConnectionMethodL( |
401 RCmConnectionMethod& connectionMethod) |
418 RCmConnectionMethod& connectionMethod) |
402 { |
419 { |
403 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
420 QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); |
404 CleanupStack::PushL(cpPriv); |
|
405 |
|
406 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
421 TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); |
407 QString ident = QString::number(qHash(iapId)); |
422 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iapId)); |
408 |
423 |
409 HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); |
424 HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); |
410 CleanupStack::PushL(pName); |
425 CleanupStack::PushL(pName); |
411 cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); |
426 QT_TRYCATCH_LEAVING(cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length())); |
412 CleanupStack::PopAndDestroy(pName); |
427 CleanupStack::PopAndDestroy(pName); |
413 pName = NULL; |
428 pName = NULL; |
414 |
429 |
415 TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); |
430 TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); |
416 switch (bearerId) { |
431 switch (bearerId) { |
505 if (name.Compare(_L("Easy WLAN")) == 0) { |
518 if (name.Compare(_L("Easy WLAN")) == 0) { |
506 // "Easy WLAN" won't be accepted to the Configurations list |
519 // "Easy WLAN" won't be accepted to the Configurations list |
507 User::Leave(KErrNotFound); |
520 User::Leave(KErrNotFound); |
508 } |
521 } |
509 |
522 |
510 QString ident = QString::number(qHash(aApId)); |
523 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(aApId)); |
511 |
524 |
512 apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()); |
525 QT_TRYCATCH_LEAVING(apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length())); |
513 apNetworkConfiguration->isValid = true; |
526 apNetworkConfiguration->isValid = true; |
514 apNetworkConfiguration->id = ident; |
527 apNetworkConfiguration->id = ident; |
515 apNetworkConfiguration->numericId = aApId; |
528 apNetworkConfiguration->numericId = aApId; |
516 apNetworkConfiguration->connectionId = 0; |
529 apNetworkConfiguration->connectionId = 0; |
517 apNetworkConfiguration->state = (QNetworkConfiguration::Defined); |
530 apNetworkConfiguration->state = (QNetworkConfiguration::Defined); |
572 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
585 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
573 // Check Default Connection (SNAP or IAP) |
586 // Check Default Connection (SNAP or IAP) |
574 TCmDefConnValue defaultConnectionValue; |
587 TCmDefConnValue defaultConnectionValue; |
575 iCmManager.ReadDefConnL(defaultConnectionValue); |
588 iCmManager.ReadDefConnL(defaultConnectionValue); |
576 if (defaultConnectionValue.iType == ECmDefConnDestination) { |
589 if (defaultConnectionValue.iType == ECmDefConnDestination) { |
577 QString iface = QString::number(qHash(defaultConnectionValue.iId+KValueThatWillBeAddedToSNAPId)); |
590 QString iface = QT_BEARERMGMT_CONFIGURATION_SNAP_PREFIX+QString::number(qHash(defaultConnectionValue.iId)); |
578 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = snapConfigurations.value(iface); |
591 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = snapConfigurations.value(iface); |
579 if (priv.data() != 0) { |
592 if (priv.data() != 0) { |
580 item.d = priv; |
593 item.d = priv; |
581 } |
594 } |
582 } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { |
595 } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { |
583 QString iface = QString::number(qHash(defaultConnectionValue.iId)); |
596 QString iface = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(defaultConnectionValue.iId)); |
584 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
597 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
585 if (priv.data() != 0) { |
598 if (priv.data() != 0) { |
586 item.d = priv; |
599 item.d = priv; |
587 } |
600 } |
588 } |
601 } |
620 if (status.Int() == KErrNone) { |
633 if (status.Int() == KErrNone) { |
621 for (TUint i = 1; i <= connectionCount; i++) { |
634 for (TUint i = 1; i <= connectionCount; i++) { |
622 iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); |
635 iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); |
623 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
636 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
624 User::WaitForRequest(status); |
637 User::WaitForRequest(status); |
625 QString ident = QString::number(qHash(apId)); |
638 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId)); |
626 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
639 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
|
640 #ifdef OCC_FUNCTIONALITY_AVAILABLE |
|
641 if (!priv.data()) { |
|
642 // If IAP was not found, check if the update was about EasyWLAN |
|
643 priv = configurationFromEasyWlan(apId, connectionId); |
|
644 } |
|
645 #endif |
627 if (priv.data()) { |
646 if (priv.data()) { |
628 iConnectionMonitor.GetIntAttribute(connectionId, subConnectionCount, KConnectionStatus, connectionStatus, status); |
647 iConnectionMonitor.GetIntAttribute(connectionId, subConnectionCount, KConnectionStatus, connectionStatus, status); |
629 User::WaitForRequest(status); |
648 User::WaitForRequest(status); |
630 if (connectionStatus == KLinkLayerOpen) { |
649 if (connectionStatus == KLinkLayerOpen) { |
631 online = true; |
650 online = true; |
731 changeConfigurationStateTo(priv, QNetworkConfiguration::Defined); |
750 changeConfigurationStateTo(priv, QNetworkConfiguration::Defined); |
732 } |
751 } |
733 } |
752 } |
734 } |
753 } |
735 |
754 |
|
755 #ifdef SNAP_FUNCTIONALITY_AVAILABLE |
|
756 void QNetworkConfigurationManagerPrivate::updateMobileBearerToConfigs(TConnMonBearerInfo bearerInfo) |
|
757 { |
|
758 foreach (const QString &ii, accessPointConfigurations.keys()) { |
|
759 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> p = |
|
760 accessPointConfigurations.value(ii); |
|
761 if (p->bearer >= QNetworkConfigurationPrivate::Bearer2G && |
|
762 p->bearer <= QNetworkConfigurationPrivate::BearerHSPA) { |
|
763 switch (bearerInfo) { |
|
764 case EBearerInfoCSD: p->bearer = QNetworkConfigurationPrivate::Bearer2G; break; |
|
765 case EBearerInfoWCDMA: p->bearer = QNetworkConfigurationPrivate::BearerWCDMA; break; |
|
766 case EBearerInfoCDMA2000: p->bearer = QNetworkConfigurationPrivate::BearerCDMA2000; break; |
|
767 case EBearerInfoGPRS: p->bearer = QNetworkConfigurationPrivate::Bearer2G; break; |
|
768 case EBearerInfoHSCSD: p->bearer = QNetworkConfigurationPrivate::Bearer2G; break; |
|
769 case EBearerInfoEdgeGPRS: p->bearer = QNetworkConfigurationPrivate::Bearer2G; break; |
|
770 case EBearerInfoWcdmaCSD: p->bearer = QNetworkConfigurationPrivate::BearerWCDMA; break; |
|
771 case EBearerInfoHSDPA: p->bearer = QNetworkConfigurationPrivate::BearerHSPA; break; |
|
772 case EBearerInfoHSUPA: p->bearer = QNetworkConfigurationPrivate::BearerHSPA; break; |
|
773 case EBearerInfoHSxPA: p->bearer = QNetworkConfigurationPrivate::BearerHSPA; break; |
|
774 } |
|
775 } |
|
776 } |
|
777 } |
|
778 #endif |
|
779 |
736 bool QNetworkConfigurationManagerPrivate::changeConfigurationStateTo(QExplicitlySharedDataPointer<QNetworkConfigurationPrivate>& sharedData, |
780 bool QNetworkConfigurationManagerPrivate::changeConfigurationStateTo(QExplicitlySharedDataPointer<QNetworkConfigurationPrivate>& sharedData, |
737 QNetworkConfiguration::StateFlags newState) |
781 QNetworkConfiguration::StateFlags newState) |
738 { |
782 { |
739 if (newState != sharedData.data()->state) { |
783 if (newState != sharedData.data()->state) { |
740 sharedData.data()->state = newState; |
784 sharedData.data()->state = newState; |
815 } |
859 } |
816 } |
860 } |
817 |
861 |
818 void QNetworkConfigurationManagerPrivate::RunL() |
862 void QNetworkConfigurationManagerPrivate::RunL() |
819 { |
863 { |
820 if (iIgnoringUpdates) { |
|
821 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
|
822 qDebug("QNCM CommsDB event handling postponed (postpone-timer running because IAPs/SNAPs were updated very recently)."); |
|
823 #endif |
|
824 return; |
|
825 } |
|
826 if (iStatus != KErrCancel) { |
864 if (iStatus != KErrCancel) { |
|
865 // By default, start relistening notifications. Stop only if interesting event occured. |
|
866 iWaitingCommsDatabaseNotifications = true; |
827 RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); |
867 RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); |
828 |
|
829 switch (event) { |
868 switch (event) { |
830 case RDbNotifier::EUnlock: /** All read locks have been removed. */ |
|
831 case RDbNotifier::ECommit: /** A transaction has been committed. */ |
869 case RDbNotifier::ECommit: /** A transaction has been committed. */ |
832 case RDbNotifier::ERollback: /** A transaction has been rolled back */ |
|
833 case RDbNotifier::ERecover: /** The database has been recovered */ |
870 case RDbNotifier::ERecover: /** The database has been recovered */ |
834 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
871 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
835 qDebug("QNCM CommsDB event (of type RDbNotifier::TEvent) received: %d", iStatus.Int()); |
872 qDebug("QNCM CommsDB event (of type RDbNotifier::TEvent) received: %d", iStatus.Int()); |
836 #endif |
873 #endif |
837 iIgnoringUpdates = true; |
874 // Mark that there is update pending. No need to ask more events, |
838 // Other events than ECommit get lower priority. In practice with those events, |
875 // as we know we will be updating anyway when the timer expires. |
839 // we delay_before_updating methods, whereas |
876 if (!iUpdatePending) { |
840 // with ECommit we _update_before_delaying the reaction to next event. |
877 iUpdatePending = true; |
841 // Few important notes: 1) listening to only ECommit does not seem to be adequate, |
878 iWaitingCommsDatabaseNotifications = false; |
842 // but updates will be missed. Hence other events are reacted upon too. |
879 // Update after random time, so that many processes won't |
843 // 2) RDbNotifier records the most significant event, and that will be returned once |
880 // start updating simultaneously |
844 // we issue new RequestNotification, and hence updates will not be missed even |
881 updateConfigurationsAfterRandomTime(); |
845 // when we are 'not reacting to them' for few seconds. |
882 } |
846 if (event == RDbNotifier::ECommit) { |
883 break; |
847 TRAPD(error, updateConfigurationsL()); |
|
848 if (error == KErrNone) { |
|
849 updateStatesToSnaps(); |
|
850 } |
|
851 waitRandomTime(); |
|
852 } else { |
|
853 waitRandomTime(); |
|
854 TRAPD(error, updateConfigurationsL()); |
|
855 if (error == KErrNone) { |
|
856 updateStatesToSnaps(); |
|
857 } |
|
858 } |
|
859 iIgnoringUpdates = false; // Wait time done, allow updating again |
|
860 iWaitingCommsDatabaseNotifications = true; |
|
861 break; |
|
862 default: |
884 default: |
863 // Do nothing |
885 // Do nothing |
864 break; |
886 break; |
865 } |
887 } |
866 } |
888 } |
894 TUint subConnectionCount = 0; |
930 TUint subConnectionCount = 0; |
895 TUint apId; |
931 TUint apId; |
896 TRequestStatus status; |
932 TRequestStatus status; |
897 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
933 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
898 User::WaitForRequest(status); |
934 User::WaitForRequest(status); |
899 QString ident = QString::number(qHash(apId)); |
935 |
|
936 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId)); |
900 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
937 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
|
938 #ifdef OCC_FUNCTIONALITY_AVAILABLE |
|
939 if (!priv.data()) { |
|
940 // Check if status was regarding EasyWLAN |
|
941 priv = configurationFromEasyWlan(apId, connectionId); |
|
942 } |
|
943 #endif |
901 if (priv.data()) { |
944 if (priv.data()) { |
902 priv.data()->connectionId = connectionId; |
945 priv.data()->connectionId = connectionId; |
903 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Connecting); |
946 QT_TRYCATCH_LEAVING(emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Connecting)); |
904 } |
947 } |
905 } else if (connectionStatus == KLinkLayerOpen) { |
948 } else if (connectionStatus == KLinkLayerOpen) { |
906 // Connection has been successfully opened |
949 // Connection has been successfully opened |
907 TUint connectionId = realEvent->ConnectionId(); |
950 TUint connectionId = realEvent->ConnectionId(); |
908 TUint subConnectionCount = 0; |
951 TUint subConnectionCount = 0; |
909 TUint apId; |
952 TUint apId; |
910 TRequestStatus status; |
953 TRequestStatus status; |
911 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
954 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
912 User::WaitForRequest(status); |
955 User::WaitForRequest(status); |
913 QString ident = QString::number(qHash(apId)); |
956 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId)); |
914 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
957 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
|
958 #ifdef OCC_FUNCTIONALITY_AVAILABLE |
|
959 if (!priv.data()) { |
|
960 // Check for EasyWLAN |
|
961 priv = configurationFromEasyWlan(apId, connectionId); |
|
962 } |
|
963 #endif |
915 if (priv.data()) { |
964 if (priv.data()) { |
916 priv.data()->connectionId = connectionId; |
965 priv.data()->connectionId = connectionId; |
917 // Configuration is Active |
966 // Configuration is Active |
918 if (changeConfigurationStateTo(priv, QNetworkConfiguration::Active)) { |
967 QT_TRYCATCH_LEAVING( |
919 updateStatesToSnaps(); |
968 if (changeConfigurationStateTo(priv, QNetworkConfiguration::Active)) { |
920 } |
969 updateStatesToSnaps(); |
921 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Connected); |
970 } |
922 if (!iOnline) { |
971 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Connected); |
923 iOnline = true; |
972 if (!iOnline) { |
924 emit this->onlineStateChanged(iOnline); |
973 iOnline = true; |
925 } |
974 emit this->onlineStateChanged(iOnline); |
|
975 } |
|
976 ); |
926 } |
977 } |
927 } else if (connectionStatus == KConfigDaemonStartingDeregistration) { |
978 } else if (connectionStatus == KConfigDaemonStartingDeregistration) { |
928 TUint connectionId = realEvent->ConnectionId(); |
979 TUint connectionId = realEvent->ConnectionId(); |
929 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = dataByConnectionId(connectionId); |
980 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = dataByConnectionId(connectionId); |
930 if (priv.data()) { |
981 if (priv.data()) { |
931 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Closing); |
982 QT_TRYCATCH_LEAVING(emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Closing)); |
932 } |
983 } |
933 } else if (connectionStatus == KLinkLayerClosed || |
984 } else if (connectionStatus == KLinkLayerClosed || |
934 connectionStatus == KConnectionClosed) { |
985 connectionStatus == KConnectionClosed) { |
935 // Connection has been closed. Which of the above events is reported, depends on the Symbian |
986 // Connection has been closed. Which of the above events is reported, depends on the Symbian |
936 // platform. |
987 // platform. |
937 TUint connectionId = realEvent->ConnectionId(); |
988 TUint connectionId = realEvent->ConnectionId(); |
938 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = dataByConnectionId(connectionId); |
989 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = dataByConnectionId(connectionId); |
939 if (priv.data()) { |
990 if (priv.data()) { |
940 // Configuration is either Defined or Discovered |
991 // Configuration is either Defined or Discovered |
941 if (changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered)) { |
992 QT_TRYCATCH_LEAVING( |
942 updateStatesToSnaps(); |
993 if (changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered)) { |
943 } |
994 updateStatesToSnaps(); |
944 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Disconnected); |
995 } |
|
996 emit this->configurationStateChanged(priv.data()->numericId, connectionId, QNetworkSession::Disconnected); |
|
997 ); |
945 } |
998 } |
946 |
999 |
947 bool online = false; |
1000 bool online = false; |
948 foreach (const QString &iface, accessPointConfigurations.keys()) { |
1001 foreach (const QString &iface, accessPointConfigurations.keys()) { |
949 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
1002 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
965 CConnMonIapAvailabilityChange* realEvent; |
1018 CConnMonIapAvailabilityChange* realEvent; |
966 realEvent = (CConnMonIapAvailabilityChange*) &aEvent; |
1019 realEvent = (CConnMonIapAvailabilityChange*) &aEvent; |
967 TConnMonIapInfo iaps = realEvent->IapAvailability(); |
1020 TConnMonIapInfo iaps = realEvent->IapAvailability(); |
968 QList<QString> unDiscoveredConfigs = accessPointConfigurations.keys(); |
1021 QList<QString> unDiscoveredConfigs = accessPointConfigurations.keys(); |
969 for ( TUint i = 0; i < iaps.Count(); i++ ) { |
1022 for ( TUint i = 0; i < iaps.Count(); i++ ) { |
970 QString ident = QString::number(qHash(iaps.iIap[i].iIapId)); |
1023 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(iaps.iIap[i].iIapId)); |
971 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
1024 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
972 if (priv.data()) { |
1025 if (priv.data()) { |
973 // Configuration is either Discovered or Active |
1026 // Configuration is either Discovered or Active |
974 changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); |
1027 QT_TRYCATCH_LEAVING(changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered)); |
975 unDiscoveredConfigs.removeOne(ident); |
1028 unDiscoveredConfigs.removeOne(ident); |
976 } |
1029 } |
977 } |
1030 } |
978 foreach (const QString &iface, unDiscoveredConfigs) { |
1031 foreach (const QString &iface, unDiscoveredConfigs) { |
979 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
1032 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(iface); |
980 if (priv.data()) { |
1033 if (priv.data()) { |
981 // Configuration is Defined |
1034 // Configuration is Defined |
982 changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); |
1035 QT_TRYCATCH_LEAVING(changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined)); |
983 } |
1036 } |
984 } |
1037 } |
985 } |
1038 } |
986 break; |
1039 break; |
987 |
1040 |
994 TUint apId; |
1047 TUint apId; |
995 TUint connectionId = realEvent->ConnectionId(); |
1048 TUint connectionId = realEvent->ConnectionId(); |
996 TRequestStatus status; |
1049 TRequestStatus status; |
997 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
1050 iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); |
998 User::WaitForRequest(status); |
1051 User::WaitForRequest(status); |
999 QString ident = QString::number(qHash(apId)); |
1052 QString ident = QT_BEARERMGMT_CONFIGURATION_IAP_PREFIX+QString::number(qHash(apId)); |
1000 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
1053 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.value(ident); |
|
1054 #ifdef OCC_FUNCTIONALITY_AVAILABLE |
|
1055 if (!priv.data()) { |
|
1056 // If IAP was not found, check if the update was about EasyWLAN |
|
1057 priv = configurationFromEasyWlan(apId, connectionId); |
|
1058 } |
|
1059 #endif |
1001 if (priv.data()) { |
1060 if (priv.data()) { |
1002 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
1061 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
1003 qDebug() << "QNCM updating connection monitor ID : from, to, whose: " << priv.data()->connectionId << connectionId << priv->name; |
1062 qDebug() << "QNCM updating connection monitor ID : from, to, whose: " << priv.data()->connectionId << connectionId << priv->name; |
1004 #endif |
1063 #endif |
1005 priv.data()->connectionId = connectionId; |
1064 priv.data()->connectionId = connectionId; |
1009 default: |
1068 default: |
1010 // For unrecognized events |
1069 // For unrecognized events |
1011 break; |
1070 break; |
1012 } |
1071 } |
1013 } |
1072 } |
|
1073 |
|
1074 #ifdef OCC_FUNCTIONALITY_AVAILABLE |
|
1075 // Tries to derive configuration from EasyWLAN. |
|
1076 // First checks if the interface brought up was EasyWLAN, then derives the real SSID, |
|
1077 // and looks up configuration based on that one. |
|
1078 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> QNetworkConfigurationManagerPrivate::configurationFromEasyWlan(TUint32 apId, TUint connectionId) |
|
1079 { |
|
1080 if (apId == iCmManager.EasyWlanIdL()) { |
|
1081 TRequestStatus status; |
|
1082 TBuf<50> easyWlanNetworkName; |
|
1083 iConnectionMonitor.GetStringAttribute( connectionId, 0, KNetworkName, |
|
1084 easyWlanNetworkName, status ); |
|
1085 User::WaitForRequest(status); |
|
1086 if (status.Int() == KErrNone) { |
|
1087 QString realSSID = QString::fromUtf16(easyWlanNetworkName.Ptr(), easyWlanNetworkName.Length()); |
|
1088 |
|
1089 // Browser through all items and check their name for match |
|
1090 QNetworkConfiguration item; |
|
1091 QHash<QString, QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> >::const_iterator i = |
|
1092 accessPointConfigurations.constBegin(); |
|
1093 while (i != accessPointConfigurations.constEnd()) { |
|
1094 QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = i.value(); |
|
1095 if (priv.data()->name == realSSID) { |
|
1096 #ifdef QT_BEARERMGMT_SYMBIAN_DEBUG |
|
1097 qDebug() << "QNCM EasyWlan uses real SSID: " << realSSID; |
|
1098 #endif |
|
1099 return priv; |
|
1100 } |
|
1101 ++i; |
|
1102 } |
|
1103 } |
|
1104 } |
|
1105 return QExplicitlySharedDataPointer<QNetworkConfigurationPrivate>(); |
|
1106 } |
|
1107 #endif |
1014 |
1108 |
1015 // Sessions may use this function to report configuration state changes, |
1109 // Sessions may use this function to report configuration state changes, |
1016 // because on some Symbian platforms (especially Symbian^3) all state changes are not |
1110 // because on some Symbian platforms (especially Symbian^3) all state changes are not |
1017 // reported by the RConnectionMonitor, in particular in relation to stop() call, |
1111 // reported by the RConnectionMonitor, in particular in relation to stop() call, |
1018 // whereas they _are_ reported on RConnection progress notifier used by sessions --> centralize |
1112 // whereas they _are_ reported on RConnection progress notifier used by sessions --> centralize |