Qt 4.8
qnetworksession_impl.cpp
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 #include "qnetworksession_impl.h"
43 #include "qicdengine.h"
44 
45 #include <QHash>
46 
47 #include <maemo_icd.h>
48 #include <iapconf.h>
49 #include <proxyconf.h>
50 
51 #include <ifaddrs.h>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
54 
55 #ifndef QT_NO_BEARERMANAGEMENT
56 
58 
60  const ICd2DetailsDBusStruct &icd2)
61 {
62  argument.beginStructure();
63 
64  argument << icd2.serviceType;
65  argument << icd2.serviceAttributes;
66  argument << icd2.setviceId;
67  argument << icd2.networkType;
68  argument << icd2.networkAttributes;
69  argument << icd2.networkId;
70 
71  argument.endStructure();
72 
73  return argument;
74 }
75 
76 const QDBusArgument &operator>>(const QDBusArgument &argument,
78 {
79  argument.beginStructure();
80 
81  argument >> icd2.serviceType;
82  argument >> icd2.serviceAttributes;
83  argument >> icd2.setviceId;
84  argument >> icd2.networkType;
85  argument >> icd2.networkAttributes;
86  argument >> icd2.networkId;
87 
88  argument.endStructure();
89 
90  return argument;
91 }
92 
93 const QDBusArgument &operator>>(const QDBusArgument &argument,
94  ICd2DetailsList &detailsList)
95 {
96  argument.beginArray();
97  detailsList.clear();
98 
99  while (!argument.atEnd()) {
100  ICd2DetailsDBusStruct element;
101  argument >> element;
102  detailsList.append(element);
103  }
104 
105  argument.endArray();
106  return argument;
107 }
108 
110  const ICd2DetailsList &detailsList)
111 {
112  argument.beginArray(qMetaTypeId<ICd2DetailsDBusStruct>());
113 
114  for (int i = 0; i < detailsList.count(); ++i)
115  argument << detailsList[i];
116 
117  argument.endArray();
118 
119  return argument;
120 }
121 
123 
125 
126 void QNetworkSessionPrivateImpl::iapStateChanged(const QString& iapid, uint icd_connection_state)
127 {
128 
130  (activeConfig.identifier() == iapid)) ||
131  (publicConfig.identifier() == iapid)) {
132  switch (icd_connection_state) {
133  case ICD_STATE_CONNECTING:
135  break;
136  case ICD_STATE_CONNECTED:
138  break;
139  case ICD_STATE_DISCONNECTING:
141  break;
142  case ICD_STATE_DISCONNECTED:
144  break;
145  default:
146  break;
147  }
148  }
150  updateIdentifier(iapid);
151  }
152 }
153 
155 {
158 }
159 
160 
162 {
163  if (newState != state) {
164  if (newState == QNetworkSession::Disconnected) {
165  if (isOpen) {
166  // The Session was aborted by the user or system
169  emit closed();
170  }
171  if (m_stopTimer.isActive()) {
172  // Session was closed by calling stop()
173  m_stopTimer.stop();
174  }
175  isOpen = false;
176  opened = false;
180  IcdNetworkConfigurationPrivate *icdConfig =
182 
183  icdConfig->mutex.lock();
185  icdConfig->mutex.unlock();
186 
187  // Reset the state of the default configuration to Discovered
189  icdConfig->mutex.lock();
191  icdConfig->mutex.unlock();
192  } else {
193  if (!activeConfig.isValid()) {
194  // Active configuration (IAP) was removed from system
195  // => Connection was disconnected and configuration became
196  // invalid
197  // => Also Session state must be changed to invalid
198  newState = QNetworkSession::Invalid;
199  }
200  }
201  } else if (newState == QNetworkSession::Connected) {
202  if (opened) {
203  isOpen = true;
204  }
206  IcdNetworkConfigurationPrivate *icdConfig =
208 
209  icdConfig->mutex.lock();
212  icdConfig->mutex.unlock();
213  }
214 
215  IcdNetworkConfigurationPrivate *icdConfig =
217 
218  icdConfig->mutex.lock();
220  icdConfig->mutex.unlock();
221  }
222 
223  if (newState != state) {
224  state = newState;
225  emit stateChanged(newState);
226  }
227  }
228 }
229 
230 
232 {
234  IcdNetworkConfigurationPrivate *icdConfig =
236 
237  icdConfig->mutex.lock();
238  icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME;
239  icdConfig->id = newId;
240  icdConfig->mutex.unlock();
241  } else {
242  IcdNetworkConfigurationPrivate *icdConfig =
244 
245  icdConfig->mutex.lock();
246  icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME;
247  if (icdConfig->id != newId)
248  icdConfig->id = newId;
249  icdConfig->mutex.unlock();
250  }
251 }
252 
253 
255 {
256  /* This could be also implemented by using the Maemo::Icd::statistics()
257  * that gets the statistics data for a specific IAP. Change if
258  * necessary.
259  */
260  Maemo::Icd icd;
261  QList<Maemo::IcdStatisticsResult> stats_results;
262  Statistics stats = { 0, 0, 0};
263 
264  if (!icd.statistics(stats_results))
265  return stats;
266 
267  foreach (const Maemo::IcdStatisticsResult &res, stats_results) {
268  if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) {
269  /* network_id is the IAP UUID */
271  stats.txData = res.bytes_sent;
272  stats.rxData = res.bytes_received;
273  stats.activeTime = res.time_active;
274  }
275  } else {
276  /* We probably will never get to this branch */
277  IcdNetworkConfigurationPrivate *icdConfig =
279 
280  icdConfig->mutex.lock();
281  if (res.params.network_id == icdConfig->network_id) {
282  stats.txData = res.bytes_sent;
283  stats.rxData = res.bytes_received;
284  stats.activeTime = res.time_active;
285  }
286  icdConfig->mutex.unlock();
287  }
288  }
289 
290  return stats;
291 }
292 
293 
295 {
296  return getStatistics().txData;
297 }
298 
300 {
301  return getStatistics().rxData;
302 }
303 
305 {
306  return getStatistics().activeTime;
307 }
308 
309 
311  QNetworkConfiguration &toConfig,
312  bool deepCopy)
313 {
315  if (deepCopy) {
316  cpPriv = new IcdNetworkConfigurationPrivate;
318  } else {
319  cpPriv = toIcdConfig(privateConfiguration(toConfig));
320  }
321 
323 
324  QMutexLocker toLocker(&cpPriv->mutex);
325  QMutexLocker fromLocker(&fromPriv->mutex);
326 
327  cpPriv->name = fromPriv->name;
328  cpPriv->isValid = fromPriv->isValid;
329  // Note that we do not copy id field here as the publicConfig does
330  // not contain a valid IAP id.
331  cpPriv->state = fromPriv->state;
332  cpPriv->type = fromPriv->type;
333  cpPriv->roamingSupported = fromPriv->roamingSupported;
334  cpPriv->purpose = fromPriv->purpose;
335  cpPriv->network_id = fromPriv->network_id;
336  cpPriv->iap_type = fromPriv->iap_type;
337  cpPriv->bearerType = fromPriv->bearerType;
338  cpPriv->network_attrs = fromPriv->network_attrs;
339  cpPriv->service_type = fromPriv->service_type;
340  cpPriv->service_id = fromPriv->service_id;
341  cpPriv->service_attrs = fromPriv->service_attrs;
342 
343  return toConfig;
344 }
345 
346 
347 /* This is called by QNetworkSession constructor and it updates the current
348  * state of the configuration.
349  */
351 {
352  /* Initially we are not active although the configuration might be in
353  * connected state.
354  */
355  isOpen = false;
356  opened = false;
357 
359  this, SLOT(iapStateChanged(const QString&, uint)));
360 
362 
365 
366  switch (publicConfig.type()) {
369  break;
372  break;
374  // active config will contain correct data after open() has succeeded
376 
377  /* We create new configuration that holds the actual configuration
378  * returned by icd. This way publicConfig still contains the
379  * original user specified configuration.
380  *
381  * Note that the new activeConfig configuration is not inserted
382  * to configurationManager as manager class will get the newly
383  * connected configuration from gconf when the IAP is saved.
384  * This configuration manager update is done by IapMonitor class.
385  * If the ANY connection fails in open(), then the configuration
386  * data is not saved to gconf and will not be added to
387  * configuration manager IAP list.
388  */
389 #ifdef BEARER_MANAGEMENT_DEBUG
390  qDebug()<<"New configuration created for" << publicConfig.identifier();
391 #endif
392  break;
393  default:
394  /* Invalid configuration, no point continuing */
395  return;
396  }
397 
398  if (!activeConfig.isValid())
399  return;
400 
401  /* Get the initial state from icd */
402  Maemo::Icd icd;
403  QList<Maemo::IcdStateResult> state_results;
404 
405  /* Update the active config from first connection, this is ok as icd
406  * supports only one connection anyway.
407  */
408  if (icd.state(state_results) && !state_results.isEmpty()) {
409  /* If we did not get full state back, then we are not
410  * connected and can skip the next part.
411  */
412  if (!(state_results.first().params.network_attrs == 0 &&
413  state_results.first().params.network_id.isEmpty())) {
414 
415  /* If we try to connect to specific IAP and we get results back
416  * that tell the icd is actually connected to another IAP,
417  * then do not update current state etc.
418  */
420  publicConfig.identifier() == state_results.first().params.network_id) {
421  switch (state_results.first().state) {
422  case ICD_STATE_DISCONNECTED:
425  ptr->mutex.lock();
426  ptr->isValid = true;
427  ptr->mutex.unlock();
428  }
429  break;
430  case ICD_STATE_CONNECTING:
433  ptr->mutex.lock();
434  ptr->isValid = true;
435  ptr->mutex.unlock();
436  }
437  break;
438  case ICD_STATE_CONNECTED:
439  {
440  if (!state_results.first().error.isEmpty())
441  break;
442 
443  const QString id = state_results.first().params.network_id;
444 
446  if (config.isValid()) {
447  //we don't want the copied data if the config is already known by the manager
448  //just reuse it so that existing references to the old data get the same update
450  }
451 
453 
454  QMutexLocker configLocker(&ptr->mutex);
455 
457  toIcdConfig(ptr)->network_id = state_results.first().params.network_id;
458  ptr->id = toIcdConfig(ptr)->network_id;
459  toIcdConfig(ptr)->network_attrs = state_results.first().params.network_attrs;
460  toIcdConfig(ptr)->iap_type = state_results.first().params.network_type;
461  ptr->bearerType = bearerTypeFromIapType(toIcdConfig(ptr)->iap_type);
462  toIcdConfig(ptr)->service_type = state_results.first().params.service_type;
463  toIcdConfig(ptr)->service_id = state_results.first().params.service_id;
464  toIcdConfig(ptr)->service_attrs = state_results.first().params.service_attrs;
467  ptr->isValid = true;
469 
470  Maemo::IAPConf iap_name(ptr->id);
471  QString name_value = iap_name.value("name").toString();
472  if (!name_value.isEmpty())
473  ptr->name = name_value;
474  else
475  ptr->name = ptr->id;
476 
477  const QString identifier = ptr->id;
478 
479  configLocker.unlock();
480 
481  // Add the new active configuration to manager or update the old config
482  if (!engine->hasIdentifier(identifier))
484  else
486  }
487  break;
488 
489  case ICD_STATE_DISCONNECTING:
492  ptr->mutex.lock();
493  ptr->isValid = true;
494  ptr->mutex.unlock();
495  }
496  break;
497  default:
498  break;
499  }
500  }
501  } else {
502 #ifdef BEARER_MANAGEMENT_DEBUG
503  qDebug() << "status_req tells icd is not connected";
504 #endif
505  }
506  } else {
507 #ifdef BEARER_MANAGEMENT_DEBUG
508  qDebug() << "status_req did not return any results from icd";
509 #endif
510  }
511 
513 }
514 
515 
517 {
518  if (serviceConfig.isValid())
520  else
522 }
523 
524 
526 {
527  QNetworkSession::State oldState = state;
528 
529  foreach (const QNetworkConfiguration &config, serviceConfig.children()) {
531  continue;
532 
533  if (activeConfig != config) {
536  }
537 
539  if (state != oldState)
541 
542  return;
543  }
544 
545  if (serviceConfig.children().isEmpty())
547  else
549 
550  if (state != oldState)
552 }
553 
554 
556 {
558 
559  QMutexLocker locker(&icdConfig->mutex);
560 
561  icdConfig->network_id.clear();
562  icdConfig->iap_type.clear();
563  icdConfig->network_attrs = 0;
564  icdConfig->service_type.clear();
565  icdConfig->service_id.clear();
566  icdConfig->service_attrs = 0;
567 }
568 
569 
571 {
572  QNetworkSession::State oldState = state;
573 
574  bool newActive = false;
575 
576  if (!activeConfig.isValid())
577  return;
578 
579  if (!activeConfig.isValid()) {
584  newActive = opened;
591  }
592 
593  bool oldActive = isOpen;
594  isOpen = newActive;
595 
596  if (!oldActive && isOpen)
598 
599  if (oldActive && !isOpen)
600  emit closed();
601 
602  if (oldState != state) {
604 
605  if (state == QNetworkSession::Disconnected && oldActive) {
606 #ifdef BEARER_MANAGEMENT_DEBUG
607  //qDebug()<<"session aborted error emitted for"<<activeConfig.identifier();
608 #endif
611  }
612  }
613 
614 #ifdef BEARER_MANAGEMENT_DEBUG
615  //qDebug()<<"oldState ="<<oldState<<" state ="<<state<<" oldActive ="<<oldActive<<" newActive ="<<newActive<<" opened ="<<opened;
616 #endif
617 }
618 
620 {
621  Maemo::Icd icd;
623  uint ret;
624  QString iface;
625 
626  ret = icd.addrinfo(addr_results);
627  if (ret == 0) {
628  /* No results */
629 #ifdef BEARER_MANAGEMENT_DEBUG
630  qDebug() << "Cannot get addrinfo from icd, are you connected or is icd running?";
631 #endif
632  return iface;
633  }
634 
635  if (addr_results.first().ip_info.isEmpty())
636  return QString();
637 
638  QByteArray data = addr_results.first().ip_info.first().address.toAscii();
639  struct in_addr addr;
640  if (inet_aton(data.constData(), &addr) == 0) {
641 #ifdef BEARER_MANAGEMENT_DEBUG
642  qDebug() << "address" << data.constData() << "invalid";
643 #endif
644  return iface;
645  }
646 
647  struct ifaddrs *ifaddr, *ifa;
648  int family;
649 
650  if (getifaddrs(&ifaddr) == -1) {
651 #ifdef BEARER_MANAGEMENT_DEBUG
652  qDebug() << "getifaddrs() failed";
653 #endif
654  return iface;
655  }
656 
657  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
658  if (ifa->ifa_addr) {
659  family = ifa->ifa_addr->sa_family;
660  if (family != AF_INET) {
661  continue; /* Currently only IPv4 is supported by icd dbus interface */
662  }
663  if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == addr.s_addr) {
664  iface = QString(ifa->ifa_name);
665  break;
666  }
667  }
668  }
669 
670  freeifaddrs(ifaddr);
671  return iface;
672 }
673 
674 
676 {
677  if (m_stopTimer.isActive()) {
678  m_stopTimer.stop();
679  }
680  if (!publicConfig.isValid()) {
683  return;
684  }
685  if (serviceConfig.isValid()) {
688  } else if (!opened) {
690  /* Caller is trying to connect to default IAP.
691  * At this time we will not know the IAP details so we just
692  * connect and update the active config when the IAP is
693  * connected.
694  */
695  opened = true;
698  QTimer::singleShot(0, this, SLOT(do_open()));
699  return;
700  }
701 
702  /* User is connecting to one specific IAP. If that IAP is not
703  * in discovered state we cannot continue.
704  */
709  return;
710  }
711  opened = true;
712 
716  QTimer::singleShot(0, this, SLOT(do_open()));
717  return;
718  }
720  if (isOpen)
722  } else {
723  /* We seem to be active so inform caller */
725  }
726 }
727 
729 {
730  icd_connection_flags flags = connectFlags;
732 
734 #ifdef BEARER_MANAGEMENT_DEBUG
735  qDebug() << "Already connected to" << activeConfig.identifier();
736 #endif
739  return;
740  }
741 
744  else
746 
747  if (iap == OSSO_IAP_ANY) {
748 #ifdef BEARER_MANAGEMENT_DEBUG
749  qDebug() << "connecting to default IAP" << iap;
750 #endif
752  m_dbusInterface->asyncCall(ICD_DBUS_API_CONNECT_REQ, (uint)flags); // Return value ignored
753  m_asynchCallActive = true;
754  } else {
756 
757  icdConfig->mutex.lock();
759  icd2.serviceType = icdConfig->service_type;
760  icd2.serviceAttributes = icdConfig->service_attrs;
761  icd2.setviceId = icdConfig->service_id;
762  icd2.networkType = icdConfig->iap_type;
763  icd2.networkAttributes = icdConfig->network_attrs;
764  if (icdConfig->network_attrs & ICD_NW_ATTR_IAPNAME) {
765  icd2.networkId = QByteArray(iap.toLatin1());
766  } else {
767  icd2.networkId = icdConfig->network_id;
768  }
769  icdConfig->mutex.unlock();
770 
771 #ifdef BEARER_MANAGEMENT_DEBUG
772  qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s",
773  icd2.networkId.data(),
774  icd2.networkType.toAscii().constData(),
775  icd2.networkAttributes,
776  icd2.serviceType.toAscii().constData(),
777  icd2.serviceAttributes,
778  icd2.setviceId.toAscii().constData());
779 #endif
780 
781  ICd2DetailsList paramArray;
782  paramArray.append(icd2);
784  m_dbusInterface->asyncCall(ICD_DBUS_API_CONNECT_REQ, (uint)flags, QVariant::fromValue(paramArray)); // Return value ignored
785  m_asynchCallActive = true;
786  }
787 }
788 
790 {
791  if (m_asynchCallActive == true) {
794  m_asynchCallActive = false;
795 
796  QString result = rep.arguments().at(5).toString(); // network id or empty string
797  QString connected_iap = result;
798  if (connected_iap.isEmpty()) {
799 #ifdef BEARER_MANAGEMENT_DEBUG
800  qDebug() << "connect to"<< publicConfig.identifier() << "failed, result is empty";
801 #endif
806  return;
807  }
808 
809  /* If the user tried to connect to some specific connection (foo)
810  * and we were already connected to some other connection (bar),
811  * then we cannot activate this session although icd has a valid
812  * connection to somewhere.
813  */
815  (connected_iap != config.identifier())) {
818  return;
819  }
820 
822 
823  /* Did we connect to non saved IAP? */
824  icdConfig->mutex.lock();
825  if (!(icdConfig->network_attrs & ICD_NW_ATTR_IAPNAME)) {
826  /* Because the connection succeeded, the IAP is now known.
827  */
828  icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME;
829  icdConfig->id = connected_iap;
830  }
831 
832  /* User might have changed the IAP name when a new IAP was saved */
833  Maemo::IAPConf iap_name(icdConfig->id);
834  QString name = iap_name.value("name").toString();
835  if (!name.isEmpty())
836  icdConfig->name = name;
837 
838  icdConfig->iap_type = rep.arguments().at(3).toString(); // connect_result.connect.network_type;
839  icdConfig->bearerType = bearerTypeFromIapType(icdConfig->iap_type);
840  icdConfig->isValid = true;
843 
844  icdConfig->mutex.unlock();
845 
848  //currentNetworkInterface = get_network_interface();
849 #ifdef BEARER_MANAGEMENT_DEBUG
850  //qDebug() << "connected to" << result << config.name() << "at" << currentNetworkInterface;
851 #endif
852 
853  /* We first check if the configuration already exists in the manager
854  * and if it is not found there, we then insert it. Note that this
855  * is only done for user choice config only because it can be missing
856  * from config manager list.
857  */
859  if (!engine->hasIdentifier(result)) {
861  } else {
863  QNetworkConfiguration reference;
864  setPrivateConfiguration(reference, priv);
865  copyConfig(config, reference, false);
866  privateConfiguration(reference)->id = result; // Note: Id was not copied in copyConfig() function
867  config = reference;
868  activeConfig = reference;
870 
871 #ifdef BEARER_MANAGEMENT_DEBUG
872  qDebug()<<"Existing configuration"<<result<<"updated in manager in open";
873 #endif
874  }
875  }
876 
878  }
879 }
880 
882 {
887 }
888 
890 {
893 
894  if (serviceConfig.isValid()) {
897  } else if (isOpen) {
899  // We will not wait any disconnect from icd as it might never come
900 #ifdef BEARER_MANAGEMENT_DEBUG
901  qDebug() << "closing session" << publicConfig.identifier();
902 #endif
905 
906  // we fake a disconnection, session error is sent
908 
909  opened = false;
910  isOpen = false;
911 
912  m_dbusInterface->call(ICD_DBUS_API_DISCONNECT_REQ, ICD_CONNECTION_FLAG_APPLICATION_EVENT);
913  startTime = QDateTime();
914  } else {
915  opened = false;
916  isOpen = false;
917  emit closed();
918  }
919  }
920 }
921 
922 
924 {
927 
928  if (serviceConfig.isValid()) {
931  } else {
933 #ifdef BEARER_MANAGEMENT_DEBUG
934  qDebug() << "stopping session" << publicConfig.identifier();
935 #endif
938 
939  // we fake a disconnection, a session error is sent also
941 
942  opened = false;
943  isOpen = false;
944 
945  m_dbusInterface->call(ICD_DBUS_API_DISCONNECT_REQ, ICD_CONNECTION_FLAG_APPLICATION_EVENT);
946  startTime = QDateTime();
947  } else {
948  opened = false;
949  isOpen = false;
950  emit closed();
951  }
952  }
953 }
954 
956 {
960  }
961 
962  emit closed();
963 }
964 
966 {
967 }
968 
969 
971 {
972 }
973 
974 
976 {
977 }
978 
979 
981 {
982 }
983 
984 #ifndef QT_NO_NETWORKINTERFACE
986 {
988  return QNetworkInterface();
989 
991  return QNetworkInterface();
992 
994 }
995 #endif
996 
998 {
999  if (value.isValid()) {
1000  properties.insert(key, value);
1001 
1002  if (key == "ConnectInBackground") {
1003  bool v = value.toBool();
1004  if (v)
1005  connectFlags = ICD_CONNECTION_FLAG_APPLICATION_EVENT;
1006  else
1007  connectFlags = ICD_CONNECTION_FLAG_USER_EVENT;
1008  }
1009  } else {
1010  properties.remove(key);
1011 
1012  /* Set default value when property is removed */
1013  if (key == "ConnectInBackground")
1014  connectFlags = ICD_CONNECTION_FLAG_USER_EVENT;
1015  }
1016 }
1017 
1018 
1020 {
1021  return properties.value(key);
1022 }
1023 
1024 
1026 {
1027  QString errorStr;
1028  switch(q->error()) {
1030  errorStr = QNetworkSessionPrivateImpl::tr("Roaming error");
1031  break;
1033  errorStr = QNetworkSessionPrivateImpl::tr("Session aborted by user or system");
1034  break;
1036  errorStr = QNetworkSessionPrivateImpl::tr("The specified configuration cannot be used.");
1037  break;
1038  default:
1040  errorStr = QNetworkSessionPrivateImpl::tr("Unidentified Error");
1041  break;
1042  }
1043  return errorStr;
1044 }
1045 
1046 
1048 {
1050 }
1051 
1053 {
1054  if ((newState == QNetworkSession::Connected) &&
1055  (newState != currentState))
1057  else if ((newState == QNetworkSession::Disconnected) &&
1060 
1061  currentState = newState;
1062 }
1063 
1064 
1066 {
1068 }
1069 
1070 
1072 {
1074 }
1075 
1077 
1078 #endif // QT_NO_BEARERMANAGEMENT
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QNetworkConfiguration config
static QNetworkInterface interfaceFromName(const QString &name)
Returns a QNetworkInterface object for the interface named name.
void endArray()
Closes a D-Bus array opened with beginArray().
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QNetworkSession::State currentState
QNetworkConfigurationPrivatePointer privateConfiguration(const QNetworkConfiguration &config) const
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QNetworkConfiguration::StateFlags state
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
icd_connection_flags connectFlags
void beginArray(int elementMetaTypeId)
Opens a new D-Bus array suitable for appending elements of meta-type id.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString service_id
Definition: maemo_icd.h:69
QNetworkSession::SessionError lastError
QDBusPendingCall asyncCall(const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
Calls the method method on this interface and passes the parameters to this function to the method...
#define SLOT(a)
Definition: qobjectdefs.h:226
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
QByteArray network_id
Definition: maemo_icd.h:72
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
State
This enum describes the connectivity state of the session.
QVariant sessionProperty(const QString &key) const
QNetworkConfiguration serviceConfig
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
SessionError error() const
Returns the type of error that last occurred.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QNetworkConfiguration > children() const
Returns all sub configurations of this network configuration in priority order.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QNetworkConfiguration activeConfig
QNetworkConfiguration::BearerType bearerType
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QNetworkConfiguration & copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy=true)
#define ICD_LONG_CONNECT_TIMEOUT
Definition: maemo_icd.h:62
void addSessionConfiguration(QNetworkConfigurationPrivatePointer ptr)
Definition: qicdengine.h:125
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool isValid() const
Returns true if this QNetworkConfiguration object is valid.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
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
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
virtual QNetworkSession::SessionError error() const =0
bool atEnd() const
Returns true if there are no more elements to be extracted from this QDBusArgument.
unsigned __int64 quint64
Definition: qglobal.h:943
void setPrivateConfiguration(QNetworkConfiguration &config, QNetworkConfigurationPrivatePointer ptr) const
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void updateProxies(QNetworkSession::State newState)
QNetworkSession::State state
struct CommonParams params
Definition: maemo_icd.h:101
QNetworkConfigurationManager manager
static const char * data(const QByteArray &arr)
void clearConfiguration(QNetworkConfiguration &config)
unsigned int uint
Definition: qglobal.h:996
void changedSessionConfiguration(QNetworkConfigurationPrivatePointer ptr)
Definition: qicdengine.h:135
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition: qtimer.h:69
const T * ptr(const T &t)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
void clear()
Removes all items from the list.
Definition: qlist.h:764
struct CommonParams params
Definition: maemo_icd.h:95
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
static void update(void)
Definition: proxyconf.cpp:401
void iapStateChanged(const QString &iapid, uint icd_connection_state)
QNetworkConfiguration publicConfig
QList< IcdIPInformation > ip_info
Definition: maemo_icd.h:119
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
uint state(QString &service_type, uint service_attrs, QString &service_id, QString &network_type, uint network_attrs, QByteArray &network_id, IcdStateResult &state_result)
Definition: maemo_icd.cpp:798
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
uint addrinfo(QString &service_type, uint service_attrs, QString &service_id, QString &network_type, uint network_attrs, QByteArray &network_id, IcdAddressInfoResult &addr_result)
Definition: maemo_icd.cpp:809
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString identifier() const
Returns the unique and platform specific identifier for this network configuration; otherwise an empt...
QNetworkConfiguration::Purpose purpose
void stateChanged(QNetworkSession::State state)
void updateIdentifier(const QString &newId)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
void setSessionProperty(const QString &key, const QVariant &value)
IcdNetworkConfigurationPrivate * toIcdConfig(QNetworkConfigurationPrivatePointer ptr)
Definition: qicdengine.h:92
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > QNetworkConfigurationPrivatePointer
bool hasIdentifier(const QString &id)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QNetworkConfiguration::Type type
QNetworkSession::SessionError error() const
void endStructure()
Closes a D-Bus structure opened with beginStructure().
int key
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
StateFlags state() const
Returns the current state of the configuration.
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
static const QMetaObjectPrivate * priv(const uint *data)
QNetworkInterface currentInterface() const
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
uint statistics(QList< IcdStatisticsResult > &stats_results)
Definition: maemo_icd.cpp:826
void beginStructure()
Opens a new D-Bus structure suitable for appending new arguments.
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
Returns the QNetworkConfiguration for identifier; otherwise returns an invalid QNetworkConfiguration...
void updateState(QNetworkSession::State)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QNetworkInterface class provides a listing of the host&#39;s IP addresses and network interfaces...
void stateChange(const QDBusMessage &rep)
QString service_type
Definition: maemo_icd.h:67
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void stop()
Stops the timer.
Definition: qtimer.cpp:284
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
static QString get_network_interface()
static void clear(void)
Definition: proxyconf.cpp:410
void clear()
Clears the contents of the byte array and makes it empty.
static QHash< QString, QVariant > properties
QVariant value(const QString &key) const
Definition: iapconf.cpp:215
QNetworkConfiguration::BearerType bearerTypeFromIapType(const QString &iapType)
Definition: qicdengine.h:58
QNetworkConfigurationPrivatePointer configuration(const QString &id)
Definition: qicdengine.h:118
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Type type() const
Returns the type of the configuration.
QDBusMessage call(const QString &method, const QVariant &arg1=QVariant(), const QVariant &arg2=QVariant(), const QVariant &arg3=QVariant(), const QVariant &arg4=QVariant(), const QVariant &arg5=QVariant(), const QVariant &arg6=QVariant(), const QVariant &arg7=QVariant(), const QVariant &arg8=QVariant())
Calls the method method on this interface and passes the parameters to this function to the method...
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774
QString network_type
Definition: maemo_icd.h:70