1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the Qt Mobility Components. |
7 ** This file is part of the Qt Mobility Components. |
8 ** |
8 ** |
52 // |
52 // |
53 // We mean it. |
53 // We mean it. |
54 // |
54 // |
55 |
55 |
56 #include "qnetworksessionengine_p.h" |
56 #include "qnetworksessionengine_p.h" |
|
57 #include "qnetworkconfiguration.h" |
|
58 |
57 #include <QMap> |
59 #include <QMap> |
58 #include <QTimer> |
60 #include <QTimer> |
59 #include <SystemConfiguration/SystemConfiguration.h> |
61 #include <SystemConfiguration/SystemConfiguration.h> |
|
62 #include <QThread> |
|
63 #include <QMutex> |
60 |
64 |
61 QTM_BEGIN_NAMESPACE |
65 QTM_BEGIN_NAMESPACE |
62 |
66 |
63 class QNetworkConfigurationPrivate; |
67 class QNetworkConfigurationPrivate; |
|
68 class QScanThread; |
64 |
69 |
65 class QCoreWlanEngine : public QNetworkSessionEngine |
70 class QCoreWlanEngine : public QNetworkSessionEngine |
66 { |
71 { |
67 Q_OBJECT |
72 Q_OBJECT |
|
73 friend class QScanThread; |
68 |
74 |
69 public: |
75 public: |
70 QCoreWlanEngine(QObject *parent = 0); |
76 QCoreWlanEngine(QObject *parent = 0); |
71 ~QCoreWlanEngine(); |
77 ~QCoreWlanEngine(); |
72 |
78 |
80 void disconnectFromId(const QString &id); |
86 void disconnectFromId(const QString &id); |
81 |
87 |
82 void requestUpdate(); |
88 void requestUpdate(); |
83 |
89 |
84 static QCoreWlanEngine *instance(); |
90 static QCoreWlanEngine *instance(); |
85 static bool getAllScInterfaces(); |
91 QString interfaceName; |
86 |
92 |
87 private: |
93 private: |
88 bool isWifiReady(const QString &dev); |
94 bool isWifiReady(const QString &dev); |
89 QMap<uint, QString> configurationInterface; |
|
90 QTimer pollTimer; |
95 QTimer pollTimer; |
91 QList<QNetworkConfigurationPrivate *> scanForSsids(const QString &interfaceName); |
|
92 |
|
93 bool isKnownSsid(const QString &ssid); |
|
94 QList<QNetworkConfigurationPrivate *> foundConfigurations; |
96 QList<QNetworkConfigurationPrivate *> foundConfigurations; |
95 |
97 |
96 SCDynamicStoreRef storeSession; |
98 SCDynamicStoreRef storeSession; |
97 CFRunLoopSourceRef runloopSource; |
99 CFRunLoopSourceRef runloopSource; |
98 bool hasWifi; |
100 bool hasWifi; |
|
101 QScanThread *scanThread; |
|
102 QMutex mutex; |
|
103 static bool getAllScInterfaces(); |
|
104 |
|
105 private Q_SLOTS: |
|
106 void init(); |
99 |
107 |
100 protected: |
108 protected: |
101 QMap<QString, QMap<QString,QString> > userProfiles; |
109 void startNetworkChangeLoop(); |
|
110 }; |
102 |
111 |
103 void startNetworkChangeLoop(); |
112 class QScanThread : public QThread |
104 void getUserConfigurations(); |
113 { |
|
114 Q_OBJECT |
|
115 |
|
116 public: |
|
117 QScanThread(QObject *parent = 0); |
|
118 ~QScanThread(); |
|
119 |
|
120 void quit(); |
|
121 QList<QNetworkConfigurationPrivate *> getConfigurations(); |
|
122 QString interfaceName; |
|
123 QMap<QString, QString> configurationInterface; |
|
124 void getUserProfiles(); |
105 QString getNetworkNameFromSsid(const QString &ssid); |
125 QString getNetworkNameFromSsid(const QString &ssid); |
106 QString getSsidFromNetworkName(const QString &name); |
126 QString getSsidFromNetworkName(const QString &name); |
|
127 bool isKnownSsid(const QString &ssid); |
|
128 QMap<QString, QMap<QString,QString> > userProfiles; |
|
129 |
|
130 signals: |
|
131 void networksChanged(); |
|
132 |
|
133 protected: |
|
134 void run(); |
|
135 |
|
136 private: |
|
137 QList<QNetworkConfigurationPrivate *> fetchedConfigurations; |
|
138 QMutex mutex; |
|
139 QStringList foundNetwork(const QString &id, const QString &ssid, |
|
140 const QNetworkConfiguration::StateFlags state, |
|
141 const QString &interfaceName, |
|
142 const QNetworkConfiguration::Purpose purpose); |
|
143 |
107 }; |
144 }; |
|
145 |
108 |
146 |
109 QTM_END_NAMESPACE |
147 QTM_END_NAMESPACE |
110 |
148 |
111 #endif |
149 #endif |
112 |
150 |