2 * hfdialer - Hands Free Voice Call Manager
3 * Copyright (c) 2012, Intel Corporation.
5 * This program is licensed under the terms and conditions of the
6 * Apache License, version 2.0. The full text of the Apache License is at
7 * http://www.apache.org/licenses/LICENSE-2.0
11 #include "networkproxy.h"
14 /* **************************************************************
15 * Network Operator Class
16 * **************************************************************/
17 /* TODO: make property reference/storage more generic
24 enum OperatorPropertyID {
32 static OperatorProperty operatorProperty[] = {
33 { CountryCode, "MobileCountryCode", },
34 { NetworkCode, "MobileNetworkCode", },
36 { Status, "Status", },
37 { Technologies, "Technologies", },
41 OperatorProxy::OperatorProxy(const QString &operatorPath)
42 : org::ofono::NetworkOperator(OFONO_SERVICE,
44 QDBusConnection::systemBus()),
45 m_path(operatorPath), m_countryCode(""),
46 m_networkCode(""), m_name(""), m_status(""), m_technologies("")
49 qCritical() << org::ofono::NetworkOperator::staticInterfaceName() <<
50 " connection failed: " << lastError().message();
52 QDBusPendingReply<QVariantMap> reply;
53 QDBusPendingCallWatcher * watcher;
55 reply = GetProperties();
56 watcher = new QDBusPendingCallWatcher(reply);
58 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
59 this, SLOT(operatorDBusGetPropDone(QDBusPendingCallWatcher*)));
63 OperatorProxy::~OperatorProxy()
67 QString OperatorProxy::path() const { return m_path; }
68 QString OperatorProxy::countryCode() const { return m_countryCode; }
69 QString OperatorProxy::networkCode() const { return m_networkCode; }
70 QString OperatorProxy::name() const { return m_name; }
71 QString OperatorProxy::status() const { return m_status; }
72 QStringList OperatorProxy::technologies() const { return m_technologies; }
74 void OperatorProxy::operatorDBusGetPropDone(QDBusPendingCallWatcher *call)
76 QDBusPendingReply<QVariantMap> reply = *call;
78 if (reply.isError()) {
79 // TODO: Handle this properly
80 qCritical() << org::ofono::NetworkOperator::staticInterfaceName() <<
81 ".GetProperties() failed: " << reply.error().message();
83 QVariantMap properties = reply.value();
84 m_countryCode = qdbus_cast<QString>(properties["MobileCountryCode"]);
85 m_networkCode = qdbus_cast<QString>(properties["MobileNetworkCode"]);
86 m_name = qdbus_cast<QString>(properties["Name"]);
87 m_status = qdbus_cast<QString>(properties["Status"]);
88 m_technologies = qdbus_cast<QStringList>(properties["Technologies"]);
92 /* **************************************************************
93 * Network Registration Class
94 * **************************************************************/
95 NetworkProxy::NetworkProxy(const QString &modemPath)
96 : org::ofono::NetworkRegistration(OFONO_SERVICE,
98 QDBusConnection::systemBus()),
99 m_mode(""), m_name(""), m_status(""), m_connected(false)
102 qCritical() << org::ofono::NetworkRegistration::staticInterfaceName() <<
103 " connection failed: " << lastError().message();
105 QDBusPendingReply<QVariantMap> reply;
106 QDBusPendingCallWatcher * watcher;
108 reply = GetProperties();
109 watcher = new QDBusPendingCallWatcher(reply);
111 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
112 this, SLOT(networkDBusGetPropDone(QDBusPendingCallWatcher*)));
116 NetworkProxy::~NetworkProxy()
120 QList<OperatorProxy*> NetworkProxy::operators() const { return m_operators; }
121 OperatorProxy* NetworkProxy::currentOperator() const
123 return m_currentOperator;
125 QString NetworkProxy::mode() const { return m_mode; }
126 QString NetworkProxy::name() const { return m_name; }
127 QString NetworkProxy::status() const { return m_status; }
129 void NetworkProxy::networkDBusGetPropDone(QDBusPendingCallWatcher *call)
131 QDBusPendingReply<QVariantMap> reply = *call;
133 if (reply.isError()) {
134 // TODO: Handle this properly
135 qCritical() << org::ofono::NetworkRegistration::staticInterfaceName() <<
136 ".GetProperties() failed: " << reply.error().message();
138 QVariantMap properties = reply.value();
139 QList<QDBusObjectPath> paths =
140 qdbus_cast<QList<QDBusObjectPath> >(properties["AvailableOperators"]);
142 foreach (QDBusObjectPath p, paths) {
143 QString path = QString(p.path());
144 OperatorProxy *op = new OperatorProxy(path);
146 m_operatorPaths.append(path);
147 m_operators.append(op);
149 // GetProperties() has probably not completed yet, so this
150 // test will be unlikely to work.
151 // TODO: connect to the propertyChanged() signal and do this there
153 if (op->status() == "current") {
154 m_currentOperator = op;
155 qDebug() << "Current network operator is " <<
156 m_currentOperator->name() << " (" <<
157 m_currentOperator->path() << ")";
161 m_mode = qdbus_cast<QString>(properties["Mode"]);
162 m_name = qdbus_cast<QString>(properties["Operator"]);
163 m_status = qdbus_cast<QString>(properties["Status"]);
165 // First sucessfull GetProperties == connected