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
|
/****************************************************************************
**
** Copyright (C) 2013-2015 Jolla Ltd.
** Contact: lorn.potter@jollamobile.com
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#include "qofonosmartmessaging.h"
#include "ofono_smart_messaging_interface.h"
#define SUPER QOfonoModemInterface2
class QOfonoSmartMessagingCallWatcher : public QDBusPendingCallWatcher {
public:
typedef void (QOfonoSmartMessaging::*SignalSuccess)(const QString&);
typedef void (QOfonoSmartMessaging::*SignalError)(const QString&, const QString&);
const char* name;
QString objectPath;
SignalSuccess success;
SignalError error;
QOfonoSmartMessagingCallWatcher(QOfonoSmartMessaging* target,
OfonoSmartMessaging *parent, const char* callName,
const QString &path, const QDBusPendingCall &call,
SignalSuccess ok, SignalError err) :
QDBusPendingCallWatcher(call, parent),
name(callName), objectPath(path), success(ok), error(err)
{
connect(this, SIGNAL(finished(QDBusPendingCallWatcher*)),
target, SLOT(onDbusCallFinished(QDBusPendingCallWatcher*)));
}
};
QOfonoSmartMessaging::QOfonoSmartMessaging(QObject *parent) :
SUPER(OfonoSmartMessaging::staticInterfaceName(), parent)
{
}
QOfonoSmartMessaging::~QOfonoSmartMessaging()
{
}
QDBusAbstractInterface *QOfonoSmartMessaging::createDbusInterface(const QString &path)
{
return new OfonoSmartMessaging("org.ofono", path, QDBusConnection::systemBus(), this);
}
QDBusObjectPath QOfonoSmartMessaging::sendAppointment(const QString &toPhoneNumber, const QByteArray &appointment)
{
OfonoSmartMessaging *iface = (OfonoSmartMessaging*)dbusInterface();
if (iface) {
// BLOCKING CALL!
QDBusPendingReply<QDBusObjectPath> returnPath = iface->SendAppointment(toPhoneNumber, appointment);
returnPath.waitForFinished();
return returnPath.value();
}
return QDBusObjectPath();
}
QDBusObjectPath QOfonoSmartMessaging::sendBusinessCard(const QString &toPhoneNumber, const QByteArray &card)
{
OfonoSmartMessaging *iface = (OfonoSmartMessaging*)dbusInterface();
if (iface) {
// BLOCKING CALL!
QDBusPendingReply<QDBusObjectPath> returnPath = iface->SendBusinessCard(toPhoneNumber,card);
returnPath.waitForFinished();
return returnPath.value();
}
return QDBusObjectPath();
}
void QOfonoSmartMessaging::registerAgent(const QString &objectPath)
{
OfonoSmartMessaging *iface = (OfonoSmartMessaging*)dbusInterface();
if (iface) {
new QOfonoSmartMessagingCallWatcher(this, iface, "RegisterAgent",
objectPath, iface->RegisterAgent(QDBusObjectPath(objectPath)),
&QOfonoSmartMessaging::registered,
&QOfonoSmartMessaging::registerFailed);
}
}
void QOfonoSmartMessaging::unregisterAgent(const QString &objectPath)
{
OfonoSmartMessaging *iface = (OfonoSmartMessaging*)dbusInterface();
if (iface) {
new QOfonoSmartMessagingCallWatcher(this, iface, "UnregisterAgent",
objectPath, iface->UnregisterAgent(QDBusObjectPath(objectPath)),
&QOfonoSmartMessaging::unregistered,
&QOfonoSmartMessaging::unregisterFailed);
}
}
QString QOfonoSmartMessaging::modemPath() const
{
return SUPER::modemPath();
}
void QOfonoSmartMessaging::setModemPath(const QString &path)
{
SUPER::setModemPath(path);
}
bool QOfonoSmartMessaging::isValid() const
{
return SUPER::isValid();
}
void QOfonoSmartMessaging::onDbusCallFinished(QDBusPendingCallWatcher *watch)
{
QOfonoSmartMessagingCallWatcher* call = (QOfonoSmartMessagingCallWatcher*)watch;
QDBusPendingReply<> reply(*call);
if (reply.isError()) {
qWarning() << call->name << "failed:" << reply.error();
(this->*call->error)(call->objectPath, reply.error().name());
} else {
(this->*call->success)(call->objectPath);
}
call->deleteLater();
}
|