Adding CallVolume interface support in ofono-qt Bindings Signed-off-by: Arun Ravindra...
[profile/ivi/ofono-qt.git] / lib / ofonovoicecallmanager.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 "ofonovoicecallmanager.h"
28 #include "ofonointerface.h"
29
30 #define DIAL_TIMEOUT 30000
31 #define TONE_TIMEOUT 10000
32 #define TRANSFER_TIMEOUT 20000
33 #define SWAP_TIMEOUT 20000
34 #define HANGUP_TIMEOUT 30000
35 #define HOLD_TIMEOUT 30000
36
37 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoVoiceCallManagerStruct &call)
38 {
39     argument.beginStructure();
40     argument << call.path << call.properties;
41     argument.endStructure();
42     return argument;
43 }
44
45 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoVoiceCallManagerStruct &call)
46 {
47     argument.beginStructure();
48     argument >> call.path >> call.properties;
49     argument.endStructure();
50     return argument;
51 }
52
53 OfonoVoiceCallManager::OfonoVoiceCallManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
54     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.VoiceCallManager", OfonoGetAllOnStartup, parent)
55 {
56     QDBusReply<OfonoVoiceCallManagerList> reply;
57     OfonoVoiceCallManagerList calls;
58
59     QDBusMessage request;
60
61     qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
62     qDBusRegisterMetaType<OfonoVoiceCallManagerStruct>();
63
64     request = QDBusMessage::createMethodCall("org.ofono",
65                                              path(), m_if->ifname(),
66                                              "GetCalls");
67     reply = QDBusConnection::systemBus().call(request);
68
69     calls = reply;
70     foreach(OfonoVoiceCallManagerStruct call, calls) {
71         m_calllist<< call.path.path();
72     }
73
74     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
75             this, SLOT(propertyChanged(const QString&, const QVariant&)));
76
77     QDBusConnection::systemBus().connect("org.ofono",path(),m_if->ifname(),
78                                          "CallAdded", this,
79                                          SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&)));
80
81     QDBusConnection::systemBus().connect("org.ofono",path(),m_if->ifname(),
82                                          "CallRemoved", this,
83                                          SLOT(callRemovedChanged(const QDBusObjectPath&)));
84 }
85
86 OfonoVoiceCallManager::~OfonoVoiceCallManager()
87 {
88 }
89
90 void OfonoVoiceCallManager::dial(const QString &number, const QString &callerid_hide)
91 {
92     QDBusMessage request;
93     request = QDBusMessage::createMethodCall("org.ofono",
94                                              path(), m_if->ifname(),
95                                              "Dial");
96     QList<QVariant>arg;
97     arg.append(QVariant(number));
98     arg.append(QVariant(callerid_hide));
99     request.setArguments(arg);
100     QDBusConnection::systemBus().callWithCallback(request, this,
101                                         SLOT(dialResp()),
102                                         SLOT(dialErr(const QDBusError&)),
103                                         DIAL_TIMEOUT);
104 }
105
106 void OfonoVoiceCallManager::hangupAll()
107 {
108     QDBusMessage request;
109     request = QDBusMessage::createMethodCall("org.ofono",
110                                              path(), m_if->ifname(),
111                                              "HangupAll");
112
113     QDBusConnection::systemBus().callWithCallback(request, this,
114                                         SLOT(hangupAllResp()),
115                                         SLOT(hangupAllErr(const QDBusError&)),
116                                         HANGUP_TIMEOUT);
117 }
118
119 void OfonoVoiceCallManager::sendTones(const QString &tonestring)
120 {
121     QDBusMessage request;
122     request = QDBusMessage::createMethodCall("org.ofono",
123                                              path(), m_if->ifname(),
124                                              "SendTones");
125     QList<QVariant>arg;
126     arg.append(QVariant(tonestring));
127     request.setArguments(arg);
128
129     QDBusConnection::systemBus().callWithCallback(request, this,
130                                         SLOT(sendTonesResp()),
131                                         SLOT(sendTonesErr(const QDBusError&)),
132                                         (TONE_TIMEOUT*tonestring.length()));
133 }
134
135 void OfonoVoiceCallManager::transfer()
136 {
137     QDBusMessage request;
138     request = QDBusMessage::createMethodCall("org.ofono",
139                                              path(), m_if->ifname(),
140                                              "Transfer");
141
142     QDBusConnection::systemBus().callWithCallback(request, this,
143                                         SLOT(transferResp()),
144                                         SLOT(transferErr(const QDBusError&)),
145                                         TRANSFER_TIMEOUT);
146 }
147
148 void OfonoVoiceCallManager::swapCalls()
149 {
150     QDBusMessage request;
151     request = QDBusMessage::createMethodCall("org.ofono",
152                                              path(), m_if->ifname(),
153                                              "SwapCalls");
154
155     QDBusConnection::systemBus().callWithCallback(request, this,
156                                         SLOT(swapCallsResp()),
157                                         SLOT(swapCallsErr(const QDBusError&)),
158                                         SWAP_TIMEOUT);
159 }
160
161 void OfonoVoiceCallManager::releaseAndAnswer()
162 {
163     QDBusMessage request;
164     request = QDBusMessage::createMethodCall("org.ofono",
165                                              path(), m_if->ifname(),
166                                              "ReleaseAndAnswer");
167
168     QDBusConnection::systemBus().callWithCallback(request, this,
169                                         SLOT(releaseAndAnswerResp()),
170                                         SLOT(releaseAndAnswerErr(const QDBusError&)),
171                                         HANGUP_TIMEOUT);
172 }
173
174 void OfonoVoiceCallManager::holdAndAnswer()
175 {
176     QDBusMessage request;
177     request = QDBusMessage::createMethodCall("org.ofono",
178                                              path(), m_if->ifname(),
179                                              "HoldAndAnswer");
180
181     QDBusConnection::systemBus().callWithCallback(request, this,
182                                         SLOT(holdAndAnswerResp()),
183                                         SLOT(holdAndAnswerErr(const QDBusError&)),
184                                         HOLD_TIMEOUT);
185 }
186
187 void OfonoVoiceCallManager::holdAndAnswerResp()
188 {
189     emit holdAndAnswerComplete(TRUE);
190 }
191
192 void OfonoVoiceCallManager::holdAndAnswerErr(const QDBusError &error)
193 {
194     qDebug() << "request failed" << error;
195     m_if->setError(error.name(), error.message());
196     emit holdAndAnswerComplete(FALSE);
197 }
198
199 void OfonoVoiceCallManager::releaseAndAnswerResp()
200 {
201     emit releaseAndAnswerComplete(TRUE);
202 }
203
204 void OfonoVoiceCallManager::releaseAndAnswerErr(const QDBusError &error)
205 {
206     qDebug() << "request failed" << error;
207     m_if->setError(error.name(), error.message());
208     emit releaseAndAnswerComplete(FALSE);
209 }
210
211 void OfonoVoiceCallManager::swapCallsResp()
212 {
213     emit swapCallsComplete(TRUE);
214 }
215
216 void OfonoVoiceCallManager::swapCallsErr(const QDBusError &error)
217 {
218     qDebug() << "request failed" << error;
219     m_if->setError(error.name(), error.message());
220     emit swapCallsComplete(FALSE);
221 }
222
223 void OfonoVoiceCallManager::dialResp()
224 {
225     emit dialComplete(TRUE);
226 }
227
228 void OfonoVoiceCallManager::dialErr(const QDBusError &error)
229 {
230     qDebug() << "request failed" << error;
231     m_if->setError(error.name(), error.message());
232     emit dialComplete(FALSE);
233 }
234
235 void OfonoVoiceCallManager::hangupAllResp()
236 {
237     emit hangupAllComplete(TRUE);
238 }
239
240 void OfonoVoiceCallManager::hangupAllErr(const QDBusError &error)
241 {
242     qDebug() << "request failed" << error;
243     m_if->setError(error.name(), error.message());
244     emit hangupAllComplete(FALSE);
245 }
246 void OfonoVoiceCallManager::sendTonesResp()
247 {
248     emit sendTonesComplete(TRUE);
249 }
250
251 void OfonoVoiceCallManager::sendTonesErr(const QDBusError &error)
252 {
253     qDebug() << "request failed" << error;
254     m_if->setError(error.name(), error.message());
255     emit sendTonesComplete(FALSE);
256 }
257
258 void OfonoVoiceCallManager::transferResp()
259 {
260     emit transferComplete(TRUE);
261 }
262
263 void OfonoVoiceCallManager::transferErr(const QDBusError &error)
264 {
265     qDebug() << "request failed" << error;
266     m_if->setError(error.name(), error.message());
267     emit transferComplete(FALSE);
268 }
269
270 QStringList OfonoVoiceCallManager::emergencyNumbers() const
271 {
272     return m_if->properties()["EmergencyNumbers"].value<QStringList>();
273 }
274
275 void OfonoVoiceCallManager::propertyChanged(const QString &property, const QVariant &value)
276 {
277     if (property == "EmergencyNumbers") {       
278         emit emergencyNumbersChanged(value.value<QStringList>());
279     }
280 }
281
282 QStringList OfonoVoiceCallManager::getCalls() const
283 {
284     return m_calllist;
285 }
286
287 void OfonoVoiceCallManager::callAddedChanged(const QDBusObjectPath &path, const QVariantMap& /*values*/)
288 {
289     m_calllist << path.path();
290     emit callAdded(path.path());
291 }
292
293 void OfonoVoiceCallManager::callRemovedChanged(const QDBusObjectPath &path)
294 {
295     m_calllist.removeAll(path.path());
296     emit callRemoved(path.path());
297 }