qtmobility/src/bearer/qnetworksession_s60_p.cpp
branchRCL_3
changeset 2 5822d84012fb
parent 0 cfcbf08528c4
child 5 453da2cfceef
equal deleted inserted replaced
0:cfcbf08528c4 2:5822d84012fb
    52 QTM_BEGIN_NAMESPACE
    52 QTM_BEGIN_NAMESPACE
    53 
    53 
    54 QNetworkSessionPrivate::QNetworkSessionPrivate()
    54 QNetworkSessionPrivate::QNetworkSessionPrivate()
    55     : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid),
    55     : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid),
    56       isOpen(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError),
    56       isOpen(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError),
    57       iALREnabled(0)
    57       iALREnabled(0), iConnectInBackground(false)
    58 {
    58 {
    59     CActiveScheduler::Add(this);
    59     CActiveScheduler::Add(this);
    60     
    60     
    61     // Try to load "Open C" dll dynamically and
       
    62     // try to attach to setdefaultif function dynamically.
       
    63     if (iOpenCLibrary.Load(_L("libc")) == KErrNone) {
       
    64         iDynamicSetdefaultif = (TOpenCSetdefaultifFunction)iOpenCLibrary.Lookup(564);
       
    65     }
       
    66 
       
    67     TRAP_IGNORE(iConnectionMonitor.ConnectL());
    61     TRAP_IGNORE(iConnectionMonitor.ConnectL());
    68 }
    62 }
    69 
    63 
    70 QNetworkSessionPrivate::~QNetworkSessionPrivate()
    64 QNetworkSessionPrivate::~QNetworkSessionPrivate()
    71 {
    65 {
    87     }
    81     }
    88 #endif
    82 #endif
    89 
    83 
    90     iConnection.Close();
    84     iConnection.Close();
    91     iSocketServ.Close();
    85     iSocketServ.Close();
    92     if (iDynamicSetdefaultif) {
    86     
    93         iDynamicSetdefaultif(0);
    87     // Close global 'Open C' RConnection
    94     }
    88     setdefaultif(0);
    95 
    89 
    96     iConnectionMonitor.CancelNotifications();
    90     iConnectionMonitor.CancelNotifications();
    97     iConnectionMonitor.Close();
    91     iConnectionMonitor.Close();
    98 
       
    99     iOpenCLibrary.Close();
       
   100 }
    92 }
   101 
    93 
   102 void QNetworkSessionPrivate::syncStateWithInterface()
    94 void QNetworkSessionPrivate::syncStateWithInterface()
   103 {
    95 {
   104     if (!publicConfig.d) {
    96     if (!publicConfig.d) {
   200     }
   192     }
   201     
   193     
   202     return activeInterface;
   194     return activeInterface;
   203 }
   195 }
   204 
   196 
   205 QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const
   197 QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const
   206 {
   198 {
       
   199     if (key == "ConnectInBackground") {
       
   200         return QVariant(iConnectInBackground);
       
   201     }
   207     return QVariant();
   202     return QVariant();
   208 }
   203 }
   209 
   204 
   210 void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/)
   205 void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVariant& value)
   211 {
   206 {
       
   207     // Valid value means adding property, invalid means removing it.
       
   208     if (key == "ConnectInBackground") {
       
   209         if (value.isValid()) {
       
   210             iConnectInBackground = value.toBool();
       
   211         } else {
       
   212             iConnectInBackground = EFalse;
       
   213         }
       
   214     }
   212 }
   215 }
   213 
   216 
   214 QString QNetworkSessionPrivate::errorString() const
   217 QString QNetworkSessionPrivate::errorString() const
   215 {
   218 {
   216     switch (iError) {
   219     switch (iError) {
   242 
   245 
   243     // Cancel notifications from RConnectionMonitor
   246     // Cancel notifications from RConnectionMonitor
   244     // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring
   247     // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring
   245     iConnectionMonitor.CancelNotifications();
   248     iConnectionMonitor.CancelNotifications();
   246 
   249 
   247     // Configuration must be at least in Discovered - state for connecting purposes.
   250     // Configuration may have been invalidated after session creation by platform
   248     if ((publicConfig.state() & QNetworkConfiguration::Discovered) !=
   251     // (e.g. configuration has been deleted).
   249                 QNetworkConfiguration::Discovered) {
   252     if (!publicConfig.isValid()) {
   250         newState(QNetworkSession::Invalid);
   253         newState(QNetworkSession::Invalid);
   251         iError = QNetworkSession::InvalidConfigurationError;
   254         iError = QNetworkSession::InvalidConfigurationError;
   252         emit q->error(iError);
   255         emit q->error(iError);
   253         syncStateWithInterface();
   256         syncStateWithInterface();
       
   257         return;
       
   258     }
       
   259     // If opening a (un)defined configuration, session emits error and enters
       
   260     // NotAvailable -state.
       
   261     if (publicConfig.state() == QNetworkConfiguration::Undefined ||
       
   262         publicConfig.state() == QNetworkConfiguration::Defined) {
       
   263         newState(QNetworkSession::NotAvailable);
       
   264         iError = QNetworkSession::InvalidConfigurationError;
       
   265         emit q->error(iError);
   254         return;
   266         return;
   255     }
   267     }
   256     
   268     
   257     TInt error = iSocketServ.Connect();
   269     TInt error = iSocketServ.Connect();
   258     if (error != KErrNone) {
   270     if (error != KErrNone) {
   299                         if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) {
   311                         if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) {
   300                             activeConfig = publicConfig;
   312                             activeConfig = publicConfig;
   301                             activeInterface = interface(activeConfig.d.data()->numericId);
   313                             activeInterface = interface(activeConfig.d.data()->numericId);
   302                             connected = ETrue;
   314                             connected = ETrue;
   303                             startTime = QDateTime::currentDateTime();
   315                             startTime = QDateTime::currentDateTime();
   304                             if (iDynamicSetdefaultif) {
   316                             // Use name of the IAP to open global 'Open C' RConnection
   305                                 // Use name of the IAP to set default IAP
   317                             QByteArray nameAsByteArray = publicConfig.name().toUtf8();
   306                                 QByteArray nameAsByteArray = publicConfig.name().toUtf8();
   318                             ifreq ifr;
   307                                 ifreq ifr;
   319                             memset(&ifr, 0, sizeof(struct ifreq));
   308                                 strcpy(ifr.ifr_name, nameAsByteArray.constData());
   320                             strcpy(ifr.ifr_name, nameAsByteArray.constData());
   309 
   321                             error = setdefaultif(&ifr);
   310                                 error = iDynamicSetdefaultif(&ifr);
       
   311                             }
       
   312                             isOpen = true;
   322                             isOpen = true;
   313                             // Make sure that state will be Connected
   323                             // Make sure that state will be Connected
   314                             newState(QNetworkSession::Connected);
   324                             newState(QNetworkSession::Connected);
   315                             emit quitPendingWaitsForOpened();
   325                             emit quitPendingWaitsForOpened();
   316                             break;
   326                             break;
   318                     }
   328                     }
   319                 }
   329                 }
   320             }
   330             }
   321         }
   331         }
   322         if (!connected) {
   332         if (!connected) {
       
   333 #ifdef OCC_FUNCTIONALITY_AVAILABLE
       
   334             // With One Click Connectivity (Symbian^3 onwards) it is possible
       
   335             // to connect silently, without any popups.
       
   336             TConnPrefList pref;
       
   337             TExtendedConnPref prefs;
       
   338             prefs.SetIapId(publicConfig.d.data()->numericId);
       
   339             if (iConnectInBackground) {
       
   340                 prefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnSilent );
       
   341             }
       
   342             pref.AppendL(&prefs);
       
   343 #else
   323             TCommDbConnPref pref;
   344             TCommDbConnPref pref;
   324             pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
   345             pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
   325             pref.SetIapId(publicConfig.d.data()->numericId);
   346             pref.SetIapId(publicConfig.d.data()->numericId);
       
   347 #endif
   326             iConnection.Start(pref, iStatus);
   348             iConnection.Start(pref, iStatus);
   327             if (!IsActive()) {
   349             if (!IsActive()) {
   328                 SetActive();
   350                 SetActive();
   329             }
   351             }
   330             newState(QNetworkSession::Connecting);
   352             newState(QNetworkSession::Connecting);
   331         }
   353         }
   332     } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
   354     } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) {
       
   355 #ifdef OCC_FUNCTIONALITY_AVAILABLE
       
   356         TConnPrefList snapPref;
       
   357         TExtendedConnPref prefs;
       
   358         prefs.SetSnapId(publicConfig.d.data()->numericId);
       
   359         if (iConnectInBackground) {
       
   360             prefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnSilent );
       
   361         }
       
   362         snapPref.AppendL(&prefs);
       
   363 #else
   333         TConnSnapPref snapPref(publicConfig.d.data()->numericId);
   364         TConnSnapPref snapPref(publicConfig.d.data()->numericId);
       
   365 #endif
   334         iConnection.Start(snapPref, iStatus);
   366         iConnection.Start(snapPref, iStatus);
   335         if (!IsActive()) {
   367         if (!IsActive()) {
   336             SetActive();
   368             SetActive();
   337         }
   369         }
   338         newState(QNetworkSession::Connecting);
   370         newState(QNetworkSession::Connecting);
   406         ipConnectionNotifier->StopNotifications();
   438         ipConnectionNotifier->StopNotifications();
   407     }
   439     }
   408     
   440     
   409     iConnection.Close();
   441     iConnection.Close();
   410     iSocketServ.Close();
   442     iSocketServ.Close();
   411     if (iDynamicSetdefaultif) {
   443     
   412         iDynamicSetdefaultif(0);
   444     // Close global 'Open C' RConnection
   413     }
   445     setdefaultif(0);
   414 
   446 
   415 #ifdef Q_CC_NOKIAX86
   447 #ifdef Q_CC_NOKIAX86
   416     if ((allowSignals && iapClientCount(activeIap) <= 0) ||
   448     if ((allowSignals && iapClientCount(activeIap) <= 0) ||
   417 #else
   449 #else
   418     if ((allowSignals && iapClientCount(activeIap) <= 1) ||
   450     if ((allowSignals && iapClientCount(activeIap) <= 1) ||
   430     }
   462     }
   431 }
   463 }
   432 
   464 
   433 void QNetworkSessionPrivate::stop()
   465 void QNetworkSessionPrivate::stop()
   434 {
   466 {
   435     if (!isOpen) {
   467     if (!isOpen &&
   436         return;
   468         publicConfig.isValid() &&
   437     }
   469         publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) {
   438     isOpen = false;
   470         // If the publicConfig is type of IAP, enumerate through connections at
   439     newState(QNetworkSession::Closing);
   471         // connection monitor. If publicConfig is active in that list, stop it.
   440     iConnection.Stop(RConnection::EStopAuthoritative);
   472         // Otherwise there is nothing to stop. Note: because this QNetworkSession is not open,
   441     isOpen = true;
   473         // activeConfig is not usable.
   442     close(false);
   474         TUint count;
   443     emit q->closed();
   475         TRequestStatus status;
       
   476         iConnectionMonitor.GetConnectionCount(count, status);
       
   477         User::WaitForRequest(status);
       
   478         if (status.Int() != KErrNone) {
       
   479             return;
       
   480         }
       
   481         TUint numSubConnections; // Not used but needed by GetConnectionInfo i/f
       
   482         TUint connectionId;
       
   483         for (TInt i = 1; i <= count; ++i) {
       
   484             // Get (connection monitor's assigned) connection ID
       
   485             TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections);            
       
   486             if (ret == KErrNone) {
       
   487                 // See if connection Id matches with our Id. If so, stop() it.
       
   488                 if (publicConfig.d.data()->connectionId == connectionId) {
       
   489                     ret = iConnectionMonitor.SetBoolAttribute(connectionId,
       
   490                                                               0, // subConnectionId don't care
       
   491                                                               KConnectionStop,
       
   492                                                               ETrue);
       
   493                 }
       
   494             }
       
   495         }
       
   496     } else if (isOpen) {
       
   497         // Since we are open, use RConnection to stop the interface
       
   498         isOpen = false;
       
   499         newState(QNetworkSession::Closing);
       
   500         iConnection.Stop(RConnection::EStopAuthoritative);
       
   501         isOpen = true;
       
   502         close(false);
       
   503         emit q->closed();
       
   504     }
   444 }
   505 }
   445 
   506 
   446 void QNetworkSessionPrivate::migrate()
   507 void QNetworkSessionPrivate::migrate()
   447 {
   508 {
   448 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   509 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
       
   510     // Close global 'Open C' RConnection
       
   511     setdefaultif(0);
       
   512     
       
   513     // Start migrating to new IAP
   449     iMobility->MigrateToPreferredCarrier();
   514     iMobility->MigrateToPreferredCarrier();
   450 #endif
   515 #endif
   451 }
   516 }
   452 
   517 
   453 void QNetworkSessionPrivate::ignore()
   518 void QNetworkSessionPrivate::ignore()
   464 
   529 
   465 void QNetworkSessionPrivate::accept()
   530 void QNetworkSessionPrivate::accept()
   466 {
   531 {
   467 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   532 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   468     iMobility->NewCarrierAccepted();
   533     iMobility->NewCarrierAccepted();
   469     if (iDynamicSetdefaultif) {
   534     
   470         // Use name of the IAP to set default IAP
   535     QNetworkConfiguration newActiveConfig = activeConfiguration(iNewRoamingIap);
   471         QByteArray nameAsByteArray = activeConfig.name().toUtf8();
   536 
   472         ifreq ifr;
   537     // Use name of the new IAP to open global 'Open C' RConnection
   473         strcpy(ifr.ifr_name, nameAsByteArray.constData());
   538     QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
   474 
   539     ifreq ifr;
   475         iDynamicSetdefaultif(&ifr);
   540     memset(&ifr, 0, sizeof(struct ifreq));
   476     }
   541     strcpy(ifr.ifr_name, nameAsByteArray.constData());
       
   542     setdefaultif(&ifr);
       
   543     
   477     newState(QNetworkSession::Connected, iNewRoamingIap);
   544     newState(QNetworkSession::Connected, iNewRoamingIap);
   478 #endif
   545 #endif
   479 }
   546 }
   480 
   547 
   481 void QNetworkSessionPrivate::reject()
   548 void QNetworkSessionPrivate::reject()
   482 {
   549 {
   483 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   550 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
   484     iMobility->NewCarrierRejected();
   551     iMobility->NewCarrierRejected();
       
   552 
   485     if (!iALRUpgradingConnection) {
   553     if (!iALRUpgradingConnection) {
   486         newState(QNetworkSession::Disconnected);
   554         newState(QNetworkSession::Disconnected);
   487     } else {
   555     } else {
       
   556         QNetworkConfiguration newActiveConfig = activeConfiguration(iOldRoamingIap);
       
   557 
       
   558         // Use name of the old IAP to open global 'Open C' RConnection
       
   559         QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
       
   560         ifreq ifr;
       
   561         memset(&ifr, 0, sizeof(struct ifreq));
       
   562         strcpy(ifr.ifr_name, nameAsByteArray.constData());
       
   563         setdefaultif(&ifr);
       
   564 
   488         newState(QNetworkSession::Connected, iOldRoamingIap);
   565         newState(QNetworkSession::Connected, iOldRoamingIap);
   489     }
   566     }
   490 #endif
   567 #endif
   491 }
   568 }
   492 
   569 
   746 void QNetworkSessionPrivate::RunL()
   823 void QNetworkSessionPrivate::RunL()
   747 {
   824 {
   748     TInt statusCode = iStatus.Int();
   825     TInt statusCode = iStatus.Int();
   749 
   826 
   750     switch (statusCode) {
   827     switch (statusCode) {
   751         case KErrNone: // Connection created succesfully
   828         case KErrNone: // Connection created successfully
   752             {
   829             {
   753             TInt error = KErrNone;
   830             TInt error = KErrNone;
   754             QNetworkConfiguration newActiveConfig = activeConfiguration();
   831             QNetworkConfiguration newActiveConfig = activeConfiguration();
   755             if (!newActiveConfig.isValid()) {
   832             if (!newActiveConfig.isValid()) {
   756                 error = KErrGeneral;
   833                 error = KErrGeneral;
   757             } else if (iDynamicSetdefaultif) {
   834             } else {
   758                 // Use name of the IAP to set default IAP
   835                 // Use name of the IAP to open global 'Open C' RConnection
       
   836                 ifreq ifr;
       
   837                 memset(&ifr, 0, sizeof(struct ifreq));
   759                 QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
   838                 QByteArray nameAsByteArray = newActiveConfig.name().toUtf8();
   760                 ifreq ifr;
       
   761                 strcpy(ifr.ifr_name, nameAsByteArray.constData());
   839                 strcpy(ifr.ifr_name, nameAsByteArray.constData());
   762 
   840                 error = setdefaultif(&ifr);
   763                 error = iDynamicSetdefaultif(&ifr);
       
   764             }
   841             }
   765             
   842             
   766             if (error != KErrNone) {
   843             if (error != KErrNone) {
   767                 isOpen = false;
   844                 isOpen = false;
   768                 iError = QNetworkSession::UnknownSessionError;
   845                 iError = QNetworkSession::UnknownSessionError;