~unity-api-team/indicator-network/second-sim-data-vivid

« back to all changes in this revision

Viewing changes to sniffer/eventprinter.cpp

  • Committer: CI Train Bot
  • Author(s): Jussi Pakkanen
  • Date: 2014-12-16 08:14:43 UTC
  • mfrom: (462.4.3 indicator-network)
  • Revision ID: ci-train-bot@canonical.com-20141216081443-d0tqrxmhngcyvssw
Created network status sniffer tool to aid in debugging. 
Approved by: Antti Kaijanmäki, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *     Jussi Pakkanen <jussi.pakkanen@canonical.com>
 
18
 */
 
19
 
 
20
#include "eventprinter.h"
 
21
 
 
22
#include "dbusdata.h"
 
23
#include "nmroot.h"
 
24
#include "ofonomodemmodem.h"
 
25
#include "ofonomodemnetworkregistration.h"
 
26
#include "ofonomodemsimmanager.h"
 
27
#include "ofonoroot.h"
 
28
#include "urfkillroot.h"
 
29
#include "urfkillswitch.h"
 
30
 
 
31
EventPrinter::EventPrinter(QObject *parent) : QObject(parent) {
 
32
    urfkill = new UrfkillRoot(URFKILL_SERVICE, URFKILL_OBJECT, QDBusConnection::systemBus(), this);
 
33
    btkill = new UrfkillSwitch(URFKILL_SERVICE, URFKILL_BLUETOOTH_OBJECT, QDBusConnection::systemBus(), this);
 
34
    wlankill = new UrfkillSwitch(URFKILL_SERVICE, URFKILL_WLAN_OBJECT, QDBusConnection::systemBus(), this);
 
35
    nmroot = new NetworkManagerRoot(NM_SERVICE, NM_OBJECT, QDBusConnection::systemBus(), this);
 
36
 
 
37
    connect(urfkill, SIGNAL(FlightModeChanged(bool)), this, SLOT(flightModeChanged(bool)));
 
38
    connect(btkill, SIGNAL(StateChanged()), this, SLOT(btKillswitchChanged()));
 
39
    connect(wlankill, SIGNAL(StateChanged()), this, SLOT(wlanKillswitchChanged()));
 
40
    connect(nmroot, SIGNAL(StateChanged(uint)), this, SLOT(nmStateChanged(uint)));
 
41
    connect(nmroot, SIGNAL(PropertiesChanged(const QVariantMap&)), this, SLOT(nmPropertiesChanged(const QVariantMap&)));
 
42
 
 
43
    OfonoRoot ofono(OFONO_SERVICE, OFONO_OBJECT, QDBusConnection::systemBus(), nullptr);
 
44
    auto modems = ofono.GetModems().value();
 
45
    if(modems.length() > 0) {
 
46
        modem1 = new OfonoModemModem(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
 
47
        connect(modem1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
48
                SLOT(modem1PropertyChanged(const QString, const QDBusVariant)));
 
49
        simman1 = new OfonoModemSimManager(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
 
50
        connect(simman1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
51
                SLOT(simman1PropertyChanged(const QString, const QDBusVariant)));
 
52
        netreg1 = new OfonoModemNetworkRegistration(OFONO_SERVICE, modems[0].first.path(), QDBusConnection::systemBus(), this);
 
53
        connect(netreg1, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
54
                SLOT(netreg1PropertyChanged(const QString, const QDBusVariant)));
 
55
    } else {
 
56
        modem1 = nullptr;
 
57
        simman1 = nullptr;
 
58
        netreg1 = nullptr;
 
59
    }
 
60
    if(modems.length() > 1) {
 
61
        modem2 = new OfonoModemModem(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
 
62
        connect(modem2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
63
                SLOT(modem2PropertyChanged(const QString, const QDBusVariant)));
 
64
        simman2 = new OfonoModemSimManager(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
 
65
        connect(simman2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
66
                SLOT(simman2PropertyChanged(const QString, const QDBusVariant)));
 
67
        netreg2 = new OfonoModemNetworkRegistration(OFONO_SERVICE, modems[1].first.path(), QDBusConnection::systemBus(), this);
 
68
        connect(netreg2, SIGNAL(PropertyChanged(const QString, const QDBusVariant)), this,
 
69
                SLOT(netreg2PropertyChanged(const QString, const QDBusVariant)));
 
70
    } else {
 
71
        modem2 = nullptr;
 
72
        simman2 = nullptr;
 
73
    }
 
74
}
 
75
 
 
76
EventPrinter::~EventPrinter() {
 
77
}
 
78
 
 
79
void EventPrinter::flightModeChanged(bool newMode) {
 
80
    printf("Flight mode changed to: %d\n", newMode);
 
81
}
 
82
 
 
83
void EventPrinter::btKillswitchChanged() {
 
84
    printf("Bluetooth killswitch changed to: %d\n", btkill->state());
 
85
}
 
86
 
 
87
void EventPrinter::wlanKillswitchChanged() {
 
88
    printf("Wlan killswitch changed to: %d\n", wlankill->state());
 
89
}
 
90
 
 
91
void EventPrinter::nmStateChanged(uint new_state) {
 
92
    printf("NetworkManager state changed to: %d\n", new_state);
 
93
}
 
94
 
 
95
void EventPrinter::nmPropertiesChanged(const QVariantMap &props) {
 
96
    const static QString activeConnections("ActiveConnections");
 
97
    const static QString primaryConnectionType("PrimaryConnectionType");
 
98
    printf("NetworkManager properties changed:\n");
 
99
    for(const auto &p : props.keys()) {
 
100
        if(p == activeConnections || p == primaryConnectionType)
 
101
            continue;
 
102
        printf("  %s %s\n", p.toUtf8().data(), props[p].toString().toUtf8().data());
 
103
    }
 
104
 
 
105
    auto i = props.find(activeConnections);
 
106
    if(i != props.end()) {
 
107
        activeConnectionsChanged(*i);
 
108
    }
 
109
    i = props.find(primaryConnectionType);
 
110
    if(i != props.end()) {
 
111
        primaryConnectionTypeChanged(i->toString());
 
112
    }
 
113
}
 
114
 
 
115
void EventPrinter::primaryConnectionTypeChanged(const QString &type) {
 
116
    printf("NetworkManager primary connection type changed to %s.\n", type.toUtf8().data());
 
117
}
 
118
 
 
119
void EventPrinter::activeConnectionsChanged(const QVariant &/*list*/) {
 
120
    // list.value<QList<QDBusObjectPath>>() does not work for some reason
 
121
    // so grab again over dbus. Yes it sucks.
 
122
    printf("  ActiveConnections (now have %d)\n", nmroot->activeConnections().size());
 
123
}
 
124
 
 
125
void EventPrinter::modem1PropertyChanged(const QString name, const QDBusVariant value) {
 
126
    modemPropertyChanged(1, name, value);
 
127
}
 
128
 
 
129
void EventPrinter::modem2PropertyChanged(const QString name, const QDBusVariant value) {
 
130
    modemPropertyChanged(2, name, value);
 
131
}
 
132
 
 
133
void EventPrinter::modemPropertyChanged(const int modem, const QString &name, const QDBusVariant &value) {
 
134
    auto str = value.variant().toString();
 
135
    if(str.length() > 0) {
 
136
        str = " to " + str;
 
137
    }
 
138
    printf("Ofono modem %d property %s changed%s.\n", modem, name.toUtf8().data(), str.toUtf8().data());
 
139
}
 
140
 
 
141
void EventPrinter::simman1PropertyChanged(const QString name, const QDBusVariant value) {
 
142
    simmanPropertyChanged(1, name, value);
 
143
}
 
144
 
 
145
void EventPrinter::simman2PropertyChanged(const QString name, const QDBusVariant value) {
 
146
    simmanPropertyChanged(2, name, value);
 
147
}
 
148
 
 
149
void EventPrinter::simmanPropertyChanged(const int simman, const QString &name, const QDBusVariant &value) {
 
150
    if(name == "PinRequired") {
 
151
        printf("Ofono modem %d pin required changed to %s.\n", simman, value.variant().toString().toUtf8().data());
 
152
    }
 
153
}
 
154
 
 
155
void EventPrinter::netreg1PropertyChanged(const QString name, const QDBusVariant value) {
 
156
    netregPropertyChanged(1, name, value);
 
157
}
 
158
 
 
159
void EventPrinter::netreg2PropertyChanged(const QString name, const QDBusVariant value) {
 
160
    netregPropertyChanged(2, name, value);
 
161
}
 
162
 
 
163
void EventPrinter::netregPropertyChanged(const int netreg, const QString &name, const QDBusVariant &value) {
 
164
    QString valuetext;
 
165
    if(name == "Strength") {
 
166
        valuetext = QString::number(value.variant().toInt());
 
167
    } else {
 
168
        valuetext = value.variant().toString();
 
169
    }
 
170
 
 
171
    printf("Ofono network registration %d property %s changed to %s.\n", netreg, name.toUtf8().data(), valuetext.toUtf8().data());
 
172
}