~neon/project-neon/libmm-qt

« back to all changes in this revision

Viewing changes to bearer.cpp

  • Committer: Jan Grulich
  • Date: 2013-10-06 11:42:12 UTC
  • Revision ID: git-v1:6b330d21e12353005970209902f3e02b2786e265
Rename files to mach classes and dbus interfaces

Update README a little bit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
 
3
 
 
4
This library is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU Lesser General Public
 
6
License as published by the Free Software Foundation; either
 
7
version 2.1 of the License, or (at your option) version 3, or any
 
8
later version accepted by the membership of KDE e.V. (or its
 
9
successor approved by the membership of KDE e.V.), which shall
 
10
act as a proxy defined in Section 6 of version 3 of the license.
 
11
 
 
12
This library is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
Lesser General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public
 
18
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#include "bearer.h"
 
22
#include "bearer_p.h"
 
23
#include "mmdebug.h"
 
24
#include "dbus/dbus.h"
 
25
 
 
26
BearerPrivate::BearerPrivate(const QString &path)
 
27
    : bearerIface(MM_DBUS_SERVICE, path, QDBusConnection::systemBus())
 
28
{
 
29
}
 
30
 
 
31
ModemManager::Bearer::Bearer(const QString &path, QObject *parent)
 
32
    : QObject(parent)
 
33
    , d_ptr(new Bearer(path))
 
34
{
 
35
    Q_D(Bearer);
 
36
 
 
37
    QDBusConnection::systemBus().connect(MM_DBUS_SERVICE, path, DBUS_INTERFACE_PROPS, "PropertiesChanged", this,
 
38
                                         SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
 
39
}
 
40
 
 
41
ModemManager::Bearer::~Bearer()
 
42
{
 
43
}
 
44
 
 
45
QString ModemManager::Bearer::interface() const
 
46
{
 
47
    Q_D(const Bearer);
 
48
    return d->bearerIface.interface();
 
49
}
 
50
 
 
51
bool ModemManager::Bearer::isConnected() const
 
52
{
 
53
    Q_D(const Bearer);
 
54
    return d->bearerIface.connected();
 
55
}
 
56
 
 
57
bool ModemManager::Bearer::isSuspended() const
 
58
{
 
59
    Q_D(const Bearer);
 
60
    return d->bearerIface.suspended();
 
61
}
 
62
 
 
63
ModemManager::Bearer::IpConfig ModemManager::Bearer::ip4Config() const
 
64
{
 
65
    Q_D(const Bearer);
 
66
    IpConfig result;
 
67
    const QVariantMap map = d->bearerIface.ip4Config();
 
68
    result.method = (MMBearerIpMethod)map.value("method").toUInt();
 
69
 
 
70
    if (result.method == MM_BEARER_IP_METHOD_STATIC) {
 
71
        result.address = map.value("address").toString();
 
72
        result.prefix = map.value("prefix").toUInt();
 
73
        result.dns1 = map.value("dns1").toString();
 
74
        result.dns2 = map.value("dns2").toString();
 
75
        result.dns3 = map.value("dns3").toString();
 
76
        result.gateway = map.value("gateway").toString();
 
77
    }
 
78
 
 
79
    return result;
 
80
}
 
81
 
 
82
ModemManager::Bearer::IpConfig ModemManager::Bearer::ip6Config() const
 
83
{
 
84
    Q_D(const Bearer);
 
85
    IpConfig result;
 
86
    const QVariantMap map = d->bearerIface.ip6Config();
 
87
    result.method = (MMBearerIpMethod)map.value("method").toUInt();
 
88
 
 
89
    if (result.method == MM_BEARER_IP_METHOD_STATIC) {
 
90
        result.address = map.value("address").toString();
 
91
        result.prefix = map.value("prefix").toUInt();
 
92
        result.dns1 = map.value("dns1").toString();
 
93
        result.dns2 = map.value("dns2").toString();
 
94
        result.dns3 = map.value("dns3").toString();
 
95
        result.gateway = map.value("gateway").toString();
 
96
    }
 
97
 
 
98
    return result;
 
99
}
 
100
 
 
101
uint ModemManager::Bearer::ipTimeout() const
 
102
{
 
103
    Q_D(const Bearer);
 
104
    return d->bearerIface.ipTimeout();
 
105
}
 
106
 
 
107
QVariantMap ModemManager::Bearer::properties() const
 
108
{
 
109
    Q_D(const Bearer);
 
110
    return d->bearerIface.properties();
 
111
}
 
112
 
 
113
void ModemManager::Bearer::connectBearer()
 
114
{
 
115
    Q_D(Bearer);
 
116
    d->bearerIface.Connect();
 
117
}
 
118
 
 
119
void ModemManager::Bearer::disconnectBearer()
 
120
{
 
121
    Q_D(Bearer);
 
122
    d->bearerIface.Disconnect();
 
123
}
 
124
 
 
125
void ModemManager::Bearer::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
 
126
{
 
127
    mmDebug() << interface << properties.keys();
 
128
 
 
129
    if (interface == QString(MM_DBUS_INTERFACE_BEARER)) {
 
130
        QLatin1String interface(MM_BEARER_PROPERTY_INTERFACE);
 
131
        QLatin1String connected(MM_BEARER_PROPERTY_CONNECTED);
 
132
        QLatin1String suspended(MM_BEARER_PROPERTY_SUSPENDED);
 
133
        QLatin1String ip4Config(MM_BEARER_PROPERTY_IP4CONFIG);
 
134
        QLatin1String ip6Config(MM_BEARER_PROPERTY_IP6CONFIG);
 
135
 
 
136
        QVariantMap::const_iterator it = properties.constFind(interface);
 
137
        if (it != properties.constEnd()) {
 
138
            emit interfaceChanged(it->toString());
 
139
        }
 
140
        it = properties.constFind(connected);
 
141
        if (it != properties.constEnd()) {
 
142
            emit connectedChanged(it->toBool());
 
143
        }
 
144
        it = properties.constFind(suspended);
 
145
        if (it != properties.constEnd()) {
 
146
            emit suspendedChanged(it->toBool());
 
147
        }
 
148
        it = properties.constFind(ip4Config);
 
149
        if (it != properties.constEnd()) {
 
150
            emit ip4ConfigChanged();
 
151
        }
 
152
        it = properties.constFind(ip6Config);
 
153
        if (it != properties.constEnd()) {
 
154
            emit ip6ConfigChanged();
 
155
        }
 
156
    }
 
157
}