Qt 4.8
Functions | Variables
qnetworksession_impl.cpp File Reference
#include "qnetworksession_impl.h"
#include "qicdengine.h"
#include <QHash>
#include <maemo_icd.h>
#include <iapconf.h>
#include <proxyconf.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>

Go to the source code of this file.

Functions

static QString get_network_interface ()
 
QDBusArgumentoperator<< (QDBusArgument &argument, const ICd2DetailsDBusStruct &icd2)
 
QDBusArgumentoperator<< (QDBusArgument &argument, const ICd2DetailsList &detailsList)
 
const QDBusArgumentoperator>> (const QDBusArgument &argument, ICd2DetailsDBusStruct &icd2)
 
const QDBusArgumentoperator>> (const QDBusArgument &argument, ICd2DetailsList &detailsList)
 

Variables

static QHash< QString, QVariantproperties
 

Function Documentation

◆ get_network_interface()

static QString get_network_interface ( )
static

Definition at line 619 of file qnetworksession_impl.cpp.

Referenced by QNetworkSessionPrivateImpl::syncStateWithInterface().

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 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
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
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
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 QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ operator<<() [1/2]

QDBusArgument& operator<< ( QDBusArgument argument,
const ICd2DetailsDBusStruct icd2 
)

Definition at line 59 of file qnetworksession_impl.cpp.

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 }
void endStructure()
Closes a D-Bus structure opened with beginStructure().
void beginStructure()
Opens a new D-Bus structure suitable for appending new arguments.

◆ operator<<() [2/2]

QDBusArgument& operator<< ( QDBusArgument argument,
const ICd2DetailsList detailsList 
)

Definition at line 109 of file qnetworksession_impl.cpp.

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 }
void endArray()
Closes a D-Bus array opened with beginArray().
void beginArray(int elementMetaTypeId)
Opens a new D-Bus array suitable for appending elements of meta-type id.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891

◆ operator>>() [1/2]

const QDBusArgument& operator>> ( const QDBusArgument argument,
ICd2DetailsDBusStruct icd2 
)

Definition at line 76 of file qnetworksession_impl.cpp.

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 }
void endStructure()
Closes a D-Bus structure opened with beginStructure().
void beginStructure()
Opens a new D-Bus structure suitable for appending new arguments.

◆ operator>>() [2/2]

const QDBusArgument& operator>> ( const QDBusArgument argument,
ICd2DetailsList detailsList 
)

Definition at line 93 of file qnetworksession_impl.cpp.

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 }
void endArray()
Closes a D-Bus array opened with beginArray().
void beginArray(int elementMetaTypeId)
Opens a new D-Bus array suitable for appending elements of meta-type id.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool atEnd() const
Returns true if there are no more elements to be extracted from this QDBusArgument.
void clear()
Removes all items from the list.
Definition: qlist.h:764

Variable Documentation

◆ properties

QHash<QString, QVariant> properties
static

Definition at line 122 of file qnetworksession_impl.cpp.