1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
#include "voicecallhandler.h"
#include <QDebug>
#include <QTimer>
#include <QDBusInterface>
#include <QDBusPendingReply>
#include <QDBusReply>
#include <QVariantMap>
/*!
\class VoiceCallHandler
\brief This is the D-Bus proxy for communicating with the voice call manager
from a declarative context, this interface specifically interfaces with
the managers' voice call handler instances.
*/
class VoiceCallHandlerPrivate
{
Q_DECLARE_PUBLIC(VoiceCallHandler)
public:
VoiceCallHandlerPrivate(VoiceCallHandler *q, const QString &pHandlerId)
: q_ptr(q), handlerId(pHandlerId), interface(NULL), connected(false)
, duration(0), status(0), emergency(false), multiparty(false), forwarded(false)
{ /* ... */ }
VoiceCallHandler *q_ptr;
QString handlerId;
QDBusInterface *interface;
bool connected;
int duration;
int status;
QString statusText;
QString lineId;
QString providerId;
QDateTime startedAt;
bool emergency;
bool multiparty;
bool forwarded;
};
/*!
Constructs a new proxy interface for the provided voice call handlerId.
*/
VoiceCallHandler::VoiceCallHandler(const QString &handlerId, QObject *parent)
: QObject(parent), d_ptr(new VoiceCallHandlerPrivate(this, handlerId))
{
Q_D(VoiceCallHandler);
qDebug() << QString("Creating D-Bus interface to: ") + handlerId;
d->interface = new QDBusInterface("org.nemomobile.voicecall",
"/calls/" + handlerId,
"org.nemomobile.voicecall.VoiceCall",
QDBusConnection::sessionBus(),
this);
this->initialize(true);
}
VoiceCallHandler::~VoiceCallHandler()
{
Q_D(VoiceCallHandler);
delete d;
}
void VoiceCallHandler::initialize(bool notifyError)
{
Q_D(VoiceCallHandler);
bool success = false;
/*
method return sender=:1.13 -> dest=:1.150 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.nemomobile.voicecall.VoiceCall">
<property name="handlerId" type="s" access="read"/>
<property name="providerId" type="s" access="read"/>
<property name="status" type="i" access="read"/>
<property name="statusText" type="s" access="read"/>
<property name="lineId" type="s" access="read"/>
<property name="startedAt" type="((iii)(iiii)i)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QDateTime"/>
</property>
<property name="duration" type="i" access="read"/>
<property name="isIncoming" type="b" access="read"/>
<property name="isEmergency" type="b" access="read"/>
<property name="isMultiparty" type="b" access="read"/>
<property name="isForwarded" type="b" access="read"/>
<signal name="error">
<arg name="message" type="s" direction="out"/>
</signal>
<signal name="statusChanged">
</signal>
<signal name="lineIdChanged">
</signal>
<signal name="startedAtChanged">
</signal>
<signal name="durationChanged">
</signal>
<signal name="emergencyChanged">
</signal>
<signal name="multipartyChanged">
</signal>
<signal name="forwardedChanged">
</signal>
<method name="answer">
<arg type="b" direction="out"/>
</method>
<method name="hangup">
<arg type="b" direction="out"/>
</method>
<method name="hold">
<arg type="b" direction="out"/>
<arg name="on" type="b" direction="in"/>
</method>
<method name="deflect">
<arg type="b" direction="out"/>
<arg name="target" type="s" direction="in"/>
</method>
<method name="sendDtmf">
<arg name="tones" type="s" direction="in"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface_name" type="s" direction="in"/>
<arg name="values" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" type="s" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping"/>
<method name="GetMachineId">
<arg name="machine_uuid" type="s" direction="out"/>
</method>
</interface>
</node>
"
*/
if(d->interface->isValid())
{
success = true;
success &= (bool)QObject::connect(d->interface, SIGNAL(error(QString)), SIGNAL(error(QString)));
success &= (bool)QObject::connect(d->interface, SIGNAL(statusChanged()), SLOT(onStatusChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(lineIdChanged()), SLOT(onLineIdChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(durationChanged()), SLOT(onDurationChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(startedAtChanged()), SLOT(onStartedAtChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(emergencyChanged()), SLOT(onEmergencyChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(multipartyChanged()), SLOT(onMultipartyChanged()));
success &= (bool)QObject::connect(d->interface, SIGNAL(forwardedChanged()), SLOT(onForwardedChanged()));
}
if(!(d->connected = success))
{
QTimer::singleShot(2000, this, SLOT(initialize()));
if(notifyError) emit this->error("Failed to connect to VCM D-Bus service.");
} else {
QDBusReply<QVariantMap> reply = d->interface->call("getProperties");
if (reply.isValid()) {
QVariantMap props = reply.value();
qDebug() << "VoiceCallHandler::initialize:" << props;
d->providerId = props["providerId"].toString();
d->duration = props["duration"].toInt();
d->status = props["status"].toInt();
d->statusText = props["statusText"].toString();
d->lineId = props["lineId"].toString();
d->startedAt = QDateTime::fromMSecsSinceEpoch(props["startedAt"].toULongLong());
d->multiparty = props["isMultiparty"].toBool();
d->emergency = props["isEmergency"].toBool();
d->forwarded = props["isForwarded"].toBool();
emit durationChanged();
emit statusChanged();
emit lineIdChanged();
emit startedAtChanged();
emit multipartyChanged();
emit emergencyChanged();
emit forwardedChanged();
} else if (notifyError) {
emit this->error("Failed to getProperties() from VCM D-Bus service.");
}
}
}
void VoiceCallHandler::onDurationChanged()
{
Q_D(VoiceCallHandler);
d->duration = d->interface->property("duration").toInt();
emit durationChanged();
}
void VoiceCallHandler::onStatusChanged()
{
Q_D(VoiceCallHandler);
d->status = d->interface->property("status").toInt();
d->statusText = d->interface->property("statusText").toString();
emit statusChanged();
}
void VoiceCallHandler::onLineIdChanged()
{
Q_D(VoiceCallHandler);
d->lineId = d->interface->property("lineId").toString();
emit lineIdChanged();
}
void VoiceCallHandler::onStartedAtChanged()
{
Q_D(VoiceCallHandler);
d->startedAt = d->interface->property("startedAt").toDateTime();
emit startedAtChanged();
}
void VoiceCallHandler::onEmergencyChanged()
{
Q_D(VoiceCallHandler);
d->emergency = d->interface->property("isEmergency").toBool();
emit emergencyChanged();
}
void VoiceCallHandler::onMultipartyChanged()
{
Q_D(VoiceCallHandler);
d->multiparty = d->interface->property("isMultiparty").toBool();
emit multipartyChanged();
}
void VoiceCallHandler::onForwardedChanged()
{
Q_D(VoiceCallHandler);
d->forwarded = d->interface->property("isForwarded").toBool();
emit forwardedChanged();
}
/*!
Returns this voice calls' handler id.
*/
QString VoiceCallHandler::handlerId() const
{
Q_D(const VoiceCallHandler);
return d->handlerId;
}
/*!
Returns this voice calls' provider id.
*/
QString VoiceCallHandler::providerId() const
{
Q_D(const VoiceCallHandler);
return d->providerId;
}
/*!
Returns this voice calls' call status.
*/
int VoiceCallHandler::status() const
{
Q_D(const VoiceCallHandler);
return d->status;
}
/*!
Returns this voice calls' call status as a symbolic string.
*/
QString VoiceCallHandler::statusText() const
{
Q_D(const VoiceCallHandler);
return d->statusText;
}
/*!
Returns this voice calls' remote end-point line id.
*/
QString VoiceCallHandler::lineId() const
{
Q_D(const VoiceCallHandler);
return d->lineId;
}
/*!
Returns this voice calls' started at property.
*/
QDateTime VoiceCallHandler::startedAt() const
{
Q_D(const VoiceCallHandler);
return d->startedAt;
}
/*!
Returns this voice calls' duration property.
*/
int VoiceCallHandler::duration() const
{
Q_D(const VoiceCallHandler);
return d->duration;
}
/*!
Returns this voice calls' incoming call flag property.
*/
bool VoiceCallHandler::isIncoming() const
{
Q_D(const VoiceCallHandler);
return d->interface->property("isIncoming").toBool();
}
/*!
Returns this voice calls' multiparty flag property.
*/
bool VoiceCallHandler::isMultiparty() const
{
Q_D(const VoiceCallHandler);
return d->multiparty;
}
/*!
Returns this voice calls' forwarded flag property.
*/
bool VoiceCallHandler::isForwarded() const
{
Q_D(const VoiceCallHandler);
return d->forwarded;
}
/*!
Returns this voice calls' emergency flag property.
*/
bool VoiceCallHandler::isEmergency() const
{
Q_D(const VoiceCallHandler);
return d->emergency;
}
/*!
Initiates answering this call, if the call is an incoming call.
*/
void VoiceCallHandler::answer()
{
Q_D(VoiceCallHandler);
QDBusPendingCall call = d->interface->asyncCall("answer");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onPendingCallFinished(QDBusPendingCallWatcher*)));
}
/*!
Initiates droping the call, unless the call is disconnected.
*/
void VoiceCallHandler::hangup()
{
Q_D(VoiceCallHandler);
QDBusPendingCall call = d->interface->asyncCall("hangup");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onPendingCallFinished(QDBusPendingCallWatcher*)));
}
/*!
Initiates holding the call, unless the call is disconnected.
*/
void VoiceCallHandler::hold(bool on)
{
Q_D(VoiceCallHandler);
QDBusPendingCall call = d->interface->asyncCall("hold", on);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onPendingCallFinished(QDBusPendingCallWatcher*)));
}
/*!
Initiates deflecting the call to the provided target phone number.
*/
void VoiceCallHandler::deflect(const QString &target)
{
Q_D(VoiceCallHandler);
QDBusPendingCall call = d->interface->asyncCall("deflect", target);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onPendingCallFinished(QDBusPendingCallWatcher*)));
}
void VoiceCallHandler::sendDtmf(const QString &tones)
{
Q_D(VoiceCallHandler);
QDBusPendingCall call = d->interface->asyncCall("sendDtmf", tones);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onPendingCallFinished(QDBusPendingCallWatcher*)));
}
void VoiceCallHandler::onPendingCallFinished(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<bool> reply = *watcher;
if (reply.isError()) {
qWarning() << QString::fromLatin1("Received error reply for member: %1 (%2)").arg(reply.reply().member()).arg(reply.error().message());
emit this->error(reply.error().message());
watcher->deleteLater();
} else {
qDebug() << QString::fromLatin1("Received successful reply for member: %1").arg(reply.reply().member());
}
}
|