Qt 4.8
qnetworksession_impl.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QNETWORKSESSION_IMPL_H
43 #define QNETWORKSESSION_IMPL_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 
56 #include <QtNetwork/private/qnetworksession_p.h>
57 #include <QtNetwork/qnetworkconfigmanager.h>
58 
59 #include <QtCore/qdatetime.h>
60 #include <QtCore/qtimer.h>
61 #include <QtCore/quuid.h>
62 
63 #include <QtDBus/qdbusconnection.h>
64 #include <QtDBus/qdbusinterface.h>
65 #include <QtDBus/qdbusmessage.h>
66 #include <QtDBus/qdbusmetatype.h>
67 
68 #include <icd/dbus_api.h>
69 
70 #ifndef QT_NO_BEARERMANAGEMENT
71 
73 
74 class QIcdEngine;
75 
77 {
84 };
85 
87 
89 {
90  Q_OBJECT
91 
92 public:
94  : engine(engine),
95  connectFlags(ICD_CONNECTION_FLAG_USER_EVENT),
96  currentState(QNetworkSession::Invalid),
97  m_asynchCallActive(false)
98  {
99  m_stopTimer.setSingleShot(true);
100  connect(&m_stopTimer, SIGNAL(timeout()), this, SLOT(finishStopBySendingClosedSignal()));
101 
105 
106  m_dbusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE,
107  ICD_DBUS_API_PATH,
108  ICD_DBUS_API_INTERFACE,
109  systemBus,
110  this);
111 
112  systemBus.connect(ICD_DBUS_API_INTERFACE,
113  ICD_DBUS_API_PATH,
114  ICD_DBUS_API_INTERFACE,
115  ICD_DBUS_API_CONNECT_SIG,
116  this,
117  SLOT(stateChange(const QDBusMessage&)));
118 
119  qDBusRegisterMetaType<ICd2DetailsDBusStruct>();
120  qDBusRegisterMetaType<ICd2DetailsList>();
121 
122  m_connectRequestTimer.setSingleShot(true);
123  connect(&m_connectRequestTimer, SIGNAL(timeout()), this, SLOT(connectTimeout()));
124  }
125 
127  {
128  cleanupSession();
129 
130  QDBusConnection::disconnectFromBus(m_dbusInterface->connection().name());
131  }
132 
133  //called by QNetworkSession constructor and ensures
134  //that the state is immediately updated (w/o actually opening
135  //a session). Also this function should take care of
136  //notification hooks to discover future state changes.
137  void syncStateWithInterface();
138 
139 #ifndef QT_NO_NETWORKINTERFACE
140  QNetworkInterface currentInterface() const;
141 #endif
142  QVariant sessionProperty(const QString& key) const;
143  void setSessionProperty(const QString& key, const QVariant& value);
144 
145  void open();
146  void close();
147  void stop();
148 
149  void migrate();
150  void accept();
151  void ignore();
152  void reject();
153 
154  QString errorString() const; //must return translated string
156 
157  quint64 bytesWritten() const;
158  quint64 bytesReceived() const;
159  quint64 activeTime() const;
160 
161 private:
162  void updateStateFromServiceNetwork();
163  void updateStateFromActiveConfig();
164 
165 private Q_SLOTS:
166  void do_open();
167  void networkConfigurationsChanged();
168  void iapStateChanged(const QString& iapid, uint icd_connection_state);
169  void updateProxies(QNetworkSession::State newState);
170  void finishStopBySendingClosedSignal();
171  void stateChange(const QDBusMessage& rep);
172  void connectTimeout();
173 
174 private:
177 
178  struct Statistics {
182  };
183 
184  // The config set on QNetworkSession.
186 
187  QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true);
188  void clearConfiguration(QNetworkConfiguration &config);
189 
190  bool opened;
191  icd_connection_flags connectFlags;
192 
194 
197  friend class IcdListener;
198  void updateState(QNetworkSession::State);
199  void updateIdentifier(const QString &newId);
200  Statistics getStatistics() const;
201  void cleanupSession(void);
202 
203  void updateProxyInformation();
204  void clearProxyInformation();
206 
208 
210 
213 };
214 
215 // Marshall the ICd2DetailsDBusStruct data into a D-Bus argument
217 
218 // Retrieve the ICd2DetailsDBusStruct data from the D-Bus argument
219 const QDBusArgument &operator>>(const QDBusArgument &argument, ICd2DetailsDBusStruct &icd2);
220 
223 
225 
226 #endif // QT_NO_BEARERMANAGEMENT
227 
228 #endif //QNETWORKSESSIONPRIVATE_H
229 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QNetworkConfiguration config
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QNetworkSession::State currentState
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
static QUuid createUuid()
On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and vers...
Definition: quuid.cpp:897
icd_connection_flags connectFlags
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QNetworkSession::SessionError lastError
#define SLOT(a)
Definition: qobjectdefs.h:226
QList< ICd2DetailsDBusStruct > ICd2DetailsList
static bool ignore(const char *test, const char *const *table)
Definition: qaxserver.cpp:660
State
This enum describes the connectivity state of the session.
The QDBusInterface class is a proxy for interfaces on remote objects.
The QNetworkConfigurationManager class manages the network configurations provided by the system...
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
QNetworkSessionPrivateImpl(QIcdEngine *engine)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QString toString(Register *reg, int type, bool *ok=0)
SessionError
This enum describes the session errors that can occur.
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static void disconnectFromBus(const QString &name)
Closes the bus connection of name name.
unsigned __int64 quint64
Definition: qglobal.h:943
QNetworkConfigurationManager manager
unsigned int uint
Definition: qglobal.h:996
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
Connects the signal specified by the service, path, interface and name parameters to the slot slot in...
const QDBusArgument & operator>>(const QDBusArgument &argument, ICd2DetailsDBusStruct &icd2)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QNetworkSession class provides control over the system&#39;s access points and enables session manage...
Q_DECLARE_METATYPE(ICd2DetailsDBusStruct)
The QDBusConnection class represents a connection to the D-Bus bus daemon.
int key
static QDBusConnection connectToBus(BusType type, const QString &name)
Opens a connection of type type to one of the known busses and associate with it the connection name ...
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
The QNetworkInterface class provides a listing of the host&#39;s IP addresses and network interfaces...
QDBusArgument & operator<<(QDBusArgument &argument, const ICd2DetailsDBusStruct &icd2)
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
int open(const char *, int,...)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62