src/plugins/bearer/symbian/symbianengine.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the plugins of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef SYMBIANENGINE_H
       
    43 #define SYMBIANENGINE_H
       
    44 
       
    45 #include <QtCore/qstringlist.h>
       
    46 #include <QtNetwork/private/qbearerengine_p.h>
       
    47 #include <QtNetwork/qnetworkconfigmanager.h>
       
    48 
       
    49 #include <QHash>
       
    50 #include <rconnmon.h>
       
    51 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
       
    52     #include <cmmanager.h>
       
    53 #endif
       
    54 
       
    55 // Uncomment and compile QtBearer to gain detailed state tracing
       
    56 // #define QT_BEARERMGMT_SYMBIAN_DEBUG
       
    57 
       
    58 class CCommsDatabase;
       
    59 class QEventLoop;
       
    60 
       
    61 QT_BEGIN_NAMESPACE
       
    62 class QTimer;
       
    63 QT_END_NAMESPACE
       
    64 
       
    65 QT_BEGIN_NAMESPACE
       
    66 
       
    67 class QNetworkSessionPrivate;
       
    68 class AccessPointsAvailabilityScanner;
       
    69 
       
    70 class SymbianNetworkConfigurationPrivate : public QNetworkConfigurationPrivate
       
    71 {
       
    72 public:
       
    73     enum Bearer {
       
    74         BearerEthernet,
       
    75         BearerWLAN,
       
    76         Bearer2G,
       
    77         BearerCDMA2000,
       
    78         BearerWCDMA,
       
    79         BearerHSPA,
       
    80         BearerBluetooth,
       
    81         BearerWiMAX,
       
    82         BearerUnknown = -1
       
    83     };
       
    84 
       
    85     SymbianNetworkConfigurationPrivate();
       
    86     ~SymbianNetworkConfigurationPrivate();
       
    87 
       
    88     QString bearerName() const;
       
    89 
       
    90     QNetworkConfigurationPrivatePointer serviceNetworkPtr;
       
    91 
       
    92     QString mappingName;
       
    93 
       
    94     Bearer bearer;
       
    95 
       
    96     // So called IAP id from the platform. Remains constant as long as the
       
    97     // platform is aware of the configuration ie. it is stored in the databases
       
    98     // --> does not depend on whether connections are currently open or not.
       
    99     // In practice is the same for the lifetime of the QNetworkConfiguration.
       
   100     TUint32 numericId;
       
   101     // So called connection id, or connection monitor ID. A dynamic ID assigned
       
   102     // by RConnectionMonitor whenever a new connection is opened. ConnectionID and
       
   103     // numericId/IAP id have 1-to-1 mapping during the lifetime of the connection at
       
   104     // connection monitor. Notably however it changes whenever a new connection to
       
   105     // a given IAP is created. In a sense it is constant during the time the
       
   106     // configuration remains between states Discovered..Active..Discovered, do not
       
   107     // however relay on this.
       
   108     TUint connectionId;
       
   109 };
       
   110 
       
   111 inline SymbianNetworkConfigurationPrivate *toSymbianConfig(QNetworkConfigurationPrivatePointer ptr)
       
   112 {
       
   113     return static_cast<SymbianNetworkConfigurationPrivate *>(ptr.data());
       
   114 }
       
   115 
       
   116 class SymbianEngine : public QBearerEngine, public CActive,
       
   117                       public MConnectionMonitorObserver
       
   118 {
       
   119     Q_OBJECT
       
   120 
       
   121 public:
       
   122     SymbianEngine(QObject *parent = 0);
       
   123     virtual ~SymbianEngine();
       
   124 
       
   125     bool hasIdentifier(const QString &id);
       
   126 
       
   127     Q_INVOKABLE void initialize();
       
   128     Q_INVOKABLE void requestUpdate();
       
   129 
       
   130     QNetworkConfigurationManager::Capabilities capabilities() const;
       
   131 
       
   132     QNetworkSessionPrivate *createSessionBackend();
       
   133 
       
   134     QNetworkConfigurationPrivatePointer defaultConfiguration();
       
   135 
       
   136     QStringList accessPointConfigurationIdentifiers();
       
   137 
       
   138 Q_SIGNALS:
       
   139     void onlineStateChanged(bool isOnline);
       
   140     
       
   141     void configurationStateChanged(TUint32 accessPointId, TUint32 connMonId,
       
   142                                    QNetworkSession::State newState);
       
   143     
       
   144 public Q_SLOTS:
       
   145     void updateConfigurations();
       
   146 
       
   147 private:
       
   148     void updateStatesToSnaps();
       
   149     bool changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr,
       
   150                                     QNetworkConfiguration::StateFlags newState);
       
   151     bool changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr,
       
   152                                          QNetworkConfiguration::StateFlags newState);
       
   153     bool changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr,
       
   154                                          QNetworkConfiguration::StateFlags newState);
       
   155 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
       
   156     SymbianNetworkConfigurationPrivate *configFromConnectionMethodL(RCmConnectionMethod& connectionMethod);
       
   157 #else
       
   158     bool readNetworkConfigurationValuesFromCommsDb(
       
   159             TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration);
       
   160     void readNetworkConfigurationValuesFromCommsDbL(
       
   161             TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration);
       
   162 #endif    
       
   163     
       
   164     void updateConfigurationsL();
       
   165     void updateActiveAccessPoints();
       
   166     void updateAvailableAccessPoints();
       
   167     void accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo);
       
   168     void startCommsDatabaseNotifications();
       
   169     void stopCommsDatabaseNotifications();
       
   170     void waitRandomTime();
       
   171 
       
   172     QNetworkConfigurationPrivatePointer defaultConfigurationL();
       
   173     TBool GetS60PlatformVersion(TUint& aMajor, TUint& aMinor) const;
       
   174     void startMonitoringIAPData(TUint32 aIapId);
       
   175     QNetworkConfigurationPrivatePointer dataByConnectionId(TUint aConnectionId);
       
   176 
       
   177 protected:
       
   178     // From CActive
       
   179     void RunL();
       
   180     void DoCancel();
       
   181     
       
   182 private:
       
   183     // MConnectionMonitorObserver
       
   184     void EventL(const CConnMonEventBase& aEvent);
       
   185     // For QNetworkSessionPrivate to indicate about state changes
       
   186     void configurationStateChangeReport(TUint32 accessPointId,
       
   187                                    QNetworkSession::State newState);
       
   188 
       
   189 private: // Data
       
   190     bool               iFirstUpdate; 
       
   191     CCommsDatabase*    ipCommsDB;
       
   192     RConnectionMonitor iConnectionMonitor;
       
   193 
       
   194     TBool              iWaitingCommsDatabaseNotifications;
       
   195     TBool              iOnline;
       
   196     TBool              iInitOk;
       
   197     TBool              iUpdateGoingOn;
       
   198     TBool              iIgnoringUpdates;
       
   199     TUint              iTimeToWait;
       
   200     QEventLoop*        iIgnoreEventLoop;
       
   201 
       
   202     AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner;
       
   203     
       
   204     friend class QNetworkSessionPrivate;
       
   205     friend class AccessPointsAvailabilityScanner;
       
   206     friend class QNetworkSessionPrivateImpl;
       
   207 
       
   208 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
       
   209     RCmManager iCmManager;
       
   210 #endif
       
   211 };
       
   212 
       
   213 class AccessPointsAvailabilityScanner : public CActive
       
   214 {
       
   215 public:
       
   216     AccessPointsAvailabilityScanner(SymbianEngine& owner,
       
   217                                    RConnectionMonitor& connectionMonitor); 
       
   218     ~AccessPointsAvailabilityScanner();
       
   219 
       
   220     void StartScanning();
       
   221     
       
   222 protected: // From CActive
       
   223     void RunL();
       
   224     void DoCancel();
       
   225 
       
   226 private: // Data
       
   227     SymbianEngine& iOwner;
       
   228     RConnectionMonitor& iConnectionMonitor;
       
   229     TConnMonIapInfoBuf iIapBuf;
       
   230 };
       
   231 
       
   232 QT_END_NAMESPACE
       
   233 
       
   234 #endif