qtmobility/src/bearer/qnetworksession_maemo_p.h
branchRCL_3
changeset 10 cd2778e5acfe
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
       
     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 Qt Mobility Components.
       
     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 QNETWORKSESSIONPRIVATE_H
       
    43 #define QNETWORKSESSIONPRIVATE_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists for the convenience
       
    50 // of the QLibrary class.  This header file may change from
       
    51 // version to version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 #include "qnetworkconfigmanager_maemo_p.h"
       
    56 #include "qnetworksession.h"
       
    57 
       
    58 #include <qnetworksession.h>
       
    59 #include <QNetworkInterface>
       
    60 #include <QDateTime>
       
    61 #include <QTimer>
       
    62 
       
    63 #include <icd/dbus_api.h>
       
    64 
       
    65 QTM_BEGIN_NAMESPACE
       
    66 
       
    67 struct ICd2DetailsDBusStruct
       
    68 {
       
    69     QString serviceType;
       
    70     uint serviceAttributes;
       
    71     QString setviceId;
       
    72     QString networkType;
       
    73     uint networkAttributes;
       
    74     QByteArray networkId;
       
    75 };
       
    76 
       
    77 typedef QList<ICd2DetailsDBusStruct> ICd2DetailsList;
       
    78 
       
    79 class QNetworkSessionPrivate : public QObject
       
    80 {
       
    81     Q_OBJECT
       
    82 public:
       
    83     QNetworkSessionPrivate() : 
       
    84         isOpen(false),
       
    85         connectFlags(ICD_CONNECTION_FLAG_USER_EVENT),
       
    86         currentState(QNetworkSession::Invalid),
       
    87         m_asynchCallActive(false)
       
    88     {
       
    89         m_stopTimer.setSingleShot(true);
       
    90         connect(&m_stopTimer, SIGNAL(timeout()), this, SLOT(finishStopBySendingClosedSignal()));
       
    91 
       
    92         QDBusConnection systemBus = QDBusConnection::systemBus();
       
    93 
       
    94         m_dbusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE,
       
    95                                          ICD_DBUS_API_PATH,
       
    96                                          ICD_DBUS_API_INTERFACE,
       
    97                                          systemBus,
       
    98                                          this);
       
    99 
       
   100         systemBus.connect(ICD_DBUS_API_INTERFACE,
       
   101                         ICD_DBUS_API_PATH,
       
   102                         ICD_DBUS_API_INTERFACE,
       
   103                         ICD_DBUS_API_CONNECT_SIG,
       
   104                         this,
       
   105                         SLOT(stateChange(const QDBusMessage&)));
       
   106 
       
   107         qDBusRegisterMetaType<ICd2DetailsDBusStruct>();
       
   108         qDBusRegisterMetaType<ICd2DetailsList>();
       
   109 
       
   110         m_connectRequestTimer.setSingleShot(true);
       
   111         connect(&m_connectRequestTimer, SIGNAL(timeout()), this, SLOT(connectTimeout()));
       
   112     }
       
   113 
       
   114     ~QNetworkSessionPrivate()
       
   115     {
       
   116 	cleanupSession();
       
   117     }
       
   118 
       
   119     //called by QNetworkSession constructor and ensures
       
   120     //that the state is immediately updated (w/o actually opening
       
   121     //a session). Also this function should take care of 
       
   122     //notification hooks to discover future state changes.
       
   123     void syncStateWithInterface();
       
   124 
       
   125     QNetworkInterface currentInterface() const;
       
   126     QVariant sessionProperty(const QString& key) const;
       
   127     void setSessionProperty(const QString& key, const QVariant& value);
       
   128 
       
   129     void open();
       
   130     void close();
       
   131     void stop();
       
   132     void migrate();
       
   133     void accept();
       
   134     void ignore();
       
   135     void reject();
       
   136 
       
   137     QString errorString() const; //must return translated string
       
   138     QNetworkSession::SessionError error() const;
       
   139 
       
   140     quint64 bytesWritten() const;
       
   141     quint64 bytesReceived() const;
       
   142     quint64 activeTime() const;
       
   143 
       
   144 private:
       
   145     void updateStateFromServiceNetwork();
       
   146     void updateStateFromActiveConfig();
       
   147 
       
   148 Q_SIGNALS:
       
   149     //releases any pending waitForOpened() calls
       
   150     void quitPendingWaitsForOpened();
       
   151 
       
   152 private Q_SLOTS:
       
   153     void do_open();
       
   154     void networkConfigurationsChanged();
       
   155     void iapStateChanged(const QString& iapid, uint icd_connection_state);
       
   156     void updateProxies(QNetworkSession::State newState);
       
   157     void finishStopBySendingClosedSignal();
       
   158     void stateChange(const QDBusMessage& rep);
       
   159     void connectTimeout();
       
   160 
       
   161 private:
       
   162     QNetworkConfigurationManager manager;
       
   163 
       
   164     struct Statistics {
       
   165         quint64 txData;
       
   166         quint64 rxData;
       
   167         quint64 activeTime;
       
   168     };
       
   169 
       
   170     // The config set on QNetworkSession.
       
   171     QNetworkConfiguration publicConfig;
       
   172     QNetworkConfiguration config;
       
   173 
       
   174     // If publicConfig is a ServiceNetwork this is a copy of publicConfig.
       
   175     // If publicConfig is an UserChoice that is resolved to a ServiceNetwork this is the actual
       
   176     // ServiceNetwork configuration.
       
   177     QNetworkConfiguration serviceConfig;
       
   178 
       
   179     // This is the actual active configuration currently in use by the session.
       
   180     // Either a copy of publicConfig or one of serviceConfig.children().
       
   181     QNetworkConfiguration activeConfig;
       
   182 
       
   183     QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true);
       
   184     void clearConfiguration(QNetworkConfiguration &config);
       
   185 
       
   186     QNetworkSession::State state;
       
   187     bool isOpen;
       
   188     bool opened;
       
   189     icd_connection_flags connectFlags;
       
   190 
       
   191     QNetworkSession::SessionError lastError;
       
   192 
       
   193     QNetworkSession* q;
       
   194     friend class QNetworkSession;
       
   195 
       
   196     QDateTime startTime;
       
   197     QString currentNetworkInterface;
       
   198     friend class IcdListener;
       
   199     void updateState(QNetworkSession::State);
       
   200     void updateIdentifier(const QString &newId);
       
   201     Statistics getStatistics() const;
       
   202     void cleanupSession(void);
       
   203 
       
   204     void updateProxyInformation();
       
   205     void clearProxyInformation();
       
   206     QNetworkSession::State currentState;
       
   207 
       
   208     QDBusInterface *m_dbusInterface;
       
   209 
       
   210     QTimer m_stopTimer;
       
   211 
       
   212     bool m_asynchCallActive;
       
   213     QTimer m_connectRequestTimer;
       
   214 };
       
   215 
       
   216 QTM_END_NAMESPACE
       
   217 
       
   218 // Marshall the ICd2DetailsDBusStruct data into a D-Bus argument
       
   219 QDBusArgument &operator<<(QDBusArgument &argument, const QtMobility::ICd2DetailsDBusStruct &icd2);
       
   220 
       
   221 // Retrieve the ICd2DetailsDBusStruct data from the D-Bus argument
       
   222 const QDBusArgument &operator>>(const QDBusArgument &argument, QtMobility::ICd2DetailsDBusStruct &icd2);
       
   223 
       
   224 Q_DECLARE_METATYPE(QtMobility::ICd2DetailsDBusStruct);
       
   225 Q_DECLARE_METATYPE(QtMobility::ICd2DetailsList);
       
   226 
       
   227 #endif //QNETWORKSESSIONPRIVATE_H
       
   228