Adding CallVolume interface support in ofono-qt Bindings Signed-off-by: Arun Ravindra...
[profile/ivi/ofono-qt.git] / lib / ofononetworkregistration.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * 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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
26
27 #include "ofononetworkregistration.h"
28 #include "ofonointerface.h"
29
30 #define REGISTER_TIMEOUT 300000
31 #define SCAN_TIMEOUT 300000
32
33 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoOperatorStruct &op)
34 {
35     argument.beginStructure();
36     argument << op.path << op.properties;
37     argument.endStructure();
38     return argument;
39 }   
40
41 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoOperatorStruct &op)
42 {   
43     argument.beginStructure();
44     argument >> op.path >> op.properties; 
45     argument.endStructure();
46     return argument;
47 }
48
49
50 OfonoNetworkRegistration::OfonoNetworkRegistration(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
51     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.NetworkRegistration", OfonoGetAllOnStartup, parent)
52 {
53     qDBusRegisterMetaType<OfonoOperatorStruct>();
54     qDBusRegisterMetaType<OfonoOperatorList>();
55
56     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
57             this, SLOT(propertyChanged(const QString&, const QVariant&)));
58 }
59
60 OfonoNetworkRegistration::~OfonoNetworkRegistration()
61 {
62 }
63
64 void OfonoNetworkRegistration::registerOp()
65 {
66     QDBusMessage request;
67
68     request = QDBusMessage::createMethodCall("org.ofono",
69                                              path(), m_if->ifname(),
70                                              "Register");
71
72     QDBusConnection::systemBus().callWithCallback(request, this,
73                                         SLOT(registerResp()),
74                                         SLOT(registerErr(const QDBusError&)),
75                                         REGISTER_TIMEOUT);
76 }
77
78 void OfonoNetworkRegistration::scan()
79 {
80     QDBusMessage request;
81
82     request = QDBusMessage::createMethodCall("org.ofono",
83                                              path(), m_if->ifname(),
84                                              "Scan");
85
86     QDBusConnection::systemBus().callWithCallback(request, this,
87                                         SLOT(scanResp(OfonoOperatorList)),
88                                         SLOT(scanErr(const QDBusError&)),
89                                         REGISTER_TIMEOUT);
90 }
91
92 void OfonoNetworkRegistration::getOperators()
93 {
94     QDBusMessage request;
95
96     request = QDBusMessage::createMethodCall("org.ofono",
97                                              path(), m_if->ifname(),
98                                              "GetOperators");
99
100     QDBusConnection::systemBus().callWithCallback(request, this,
101                                         SLOT(getOperatorsResp(OfonoOperatorList)),
102                                         SLOT(getOperatorsErr(const QDBusError&)),
103                                         SCAN_TIMEOUT);
104 }
105
106 QString OfonoNetworkRegistration::mode() const
107 {
108     return m_if->properties()["Mode"].value<QString>();
109 }
110
111 QString OfonoNetworkRegistration::status() const
112 {
113     return m_if->properties()["Status"].value<QString>();
114 }
115
116 uint OfonoNetworkRegistration::locationAreaCode() const
117 {
118     return m_if->properties()["LocationAreaCode"].value<uint>();
119 }
120
121 uint OfonoNetworkRegistration::cellId() const
122 {
123     return m_if->properties()["CellId"].value<uint>();
124 }
125
126 QString OfonoNetworkRegistration::mcc() const
127 {
128     return m_if->properties()["MobileCountryCode"].value<QString>();
129 }
130
131 QString OfonoNetworkRegistration::mnc() const
132 {
133     return m_if->properties()["MobileNetworkCode"].value<QString>();
134 }
135
136 QString OfonoNetworkRegistration::technology() const
137 {
138     return m_if->properties()["Technology"].value<QString>();
139 }
140
141 QString OfonoNetworkRegistration::name() const
142 {
143     return m_if->properties()["Name"].value<QString>();
144 }
145
146 uint OfonoNetworkRegistration::strength() const
147 {
148     return m_if->properties()["Strength"].value<uint>();
149 }
150
151 QString OfonoNetworkRegistration::baseStation() const
152 {
153     return m_if->properties()["BaseStation"].value<QString>();
154 }
155
156 void OfonoNetworkRegistration::propertyChanged(const QString& property, const QVariant& value)
157 {
158     if (property == "Mode") {   
159         emit modeChanged(value.value<QString>());
160     } else if (property == "Status") {  
161         emit statusChanged(value.value<QString>());
162     } else if (property == "LocationAreaCode") {        
163         emit locationAreaCodeChanged(value.value<uint>());
164     } else if (property == "CellId") {  
165         emit cellIdChanged(value.value<uint>());
166     } else if (property == "MobileCountryCode") {       
167         emit mccChanged(value.value<QString>());
168     } else if (property == "MobileNetworkCode") {       
169         emit mncChanged(value.value<QString>());
170     } else if (property == "Technology") {      
171         emit technologyChanged(value.value<QString>());
172     } else if (property == "Name") {    
173         emit nameChanged(value.value<QString>());
174     } else if (property == "Strength") {        
175         emit strengthChanged(value.value<uint>());
176     } else if (property == "BaseStation") {     
177         emit baseStationChanged(value.value<QString>());
178     }
179 }
180
181 void OfonoNetworkRegistration::registerResp()
182 {
183     emit registerComplete(TRUE);
184 }
185
186 void OfonoNetworkRegistration::registerErr(QDBusError error)
187 {
188     qDebug() << "Register failed" << error;
189     m_if->setError(error.name(), error.message());
190     emit registerComplete(FALSE);
191 }
192
193 void OfonoNetworkRegistration::getOperatorsResp(OfonoOperatorList list)
194 {
195     QStringList oplist;
196     foreach(OfonoOperatorStruct op, list) {
197         oplist << op.path.path();
198     }
199     emit getOperatorsComplete(TRUE, oplist);
200 }
201
202 void OfonoNetworkRegistration::getOperatorsErr(QDBusError error)
203 {
204     qDebug() << "GetOperators failed" << error;
205     m_if->setError(error.name(), error.message());
206     emit getOperatorsComplete(FALSE, QStringList());
207 }
208
209 void OfonoNetworkRegistration::scanResp(OfonoOperatorList list)
210 {
211     QStringList oplist;
212     foreach(OfonoOperatorStruct op, list) {
213         oplist << op.path.path();
214     }
215     emit scanComplete(TRUE, oplist);
216 }
217
218 void OfonoNetworkRegistration::scanErr(QDBusError error)
219 {
220     qDebug() << "Scan failed" << error;
221     m_if->setError(error.name(), error.message());
222     emit scanComplete(FALSE, QStringList());
223 }
224