~ken-vandine/telepathy-ofono/rebuild_libphonenumber7

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
/**
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
 */

#include <QDebug>

#include <TelepathyQt/Constants>
#include <TelepathyQt/DBusObject>

#include "ussdiface.h"

// Conn.I.USSD
BaseConnectionUSSDInterface::Adaptee::Adaptee(BaseConnectionUSSDInterface *interface)
    : QObject(interface),
      mInterface(interface)
{
}


struct TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Private {
    Private(BaseConnectionUSSDInterface *parent)
        : adaptee(new BaseConnectionUSSDInterface::Adaptee(parent)) {
    }
    QString state;
    QString serial;
    InitiateCallback initiateCB;
    RespondCallback respondCB;
    CancelCallback cancelCB;
    BaseConnectionUSSDInterface::Adaptee *adaptee;
};

BaseConnectionUSSDInterface::Adaptee::~Adaptee()
{
}

void BaseConnectionUSSDInterface::Adaptee::initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context)
{
    if (!mInterface->mPriv->initiateCB.isValid()) {
        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
        return;
    }
    Tp::DBusError error;
    mInterface->mPriv->initiateCB(command, &error);
    if (error.isValid()) {
        context->setFinishedWithError(error.name(), error.message());
        return;
    }
    context->setFinished();
}

void BaseConnectionUSSDInterface::Adaptee::respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context)
{
    if (!mInterface->mPriv->respondCB.isValid()) {
        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
        return;
    }
    Tp::DBusError error;
    mInterface->mPriv->respondCB(reply, &error);
    if (error.isValid()) {
        context->setFinishedWithError(error.name(), error.message());
        return;
    }
    context->setFinished();
}

void BaseConnectionUSSDInterface::Adaptee::cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context)
{
    if (!mInterface->mPriv->cancelCB.isValid()) {
        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
        return;
    }
    Tp::DBusError error;
    mInterface->mPriv->cancelCB(&error);
    if (error.isValid()) {
        context->setFinishedWithError(error.name(), error.message());
        return;
    }
    context->setFinished();
}

BaseConnectionUSSDInterface::BaseConnectionUSSDInterface()
    : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_USSD),
      mPriv(new Private(this))
{
}

BaseConnectionUSSDInterface::~BaseConnectionUSSDInterface()
{
    delete mPriv;
}

void BaseConnectionUSSDInterface::setInitiateCallback(const InitiateCallback &cb)
{
    mPriv->initiateCB = cb;
}

void BaseConnectionUSSDInterface::setRespondCallback(const RespondCallback &cb)
{
    mPriv->respondCB = cb;
}

void BaseConnectionUSSDInterface::setCancelCallback(const CancelCallback &cb)
{
    mPriv->cancelCB = cb;
}

QString BaseConnectionUSSDInterface::state() const
{
    return mPriv->state;
}

void BaseConnectionUSSDInterface::setSerial(const QString &serial) const
{
    mPriv->serial = serial;
}


QString BaseConnectionUSSDInterface::serial() const
{
    return mPriv->serial;
}

void BaseConnectionUSSDInterface::StateChanged(const QString &state)
{
    mPriv->state = state;
    Q_EMIT mPriv->adaptee->stateChanged(state);
}

void BaseConnectionUSSDInterface::InitiateUSSDComplete(const QString &ussdResp)
{
    Q_EMIT mPriv->adaptee->initiateUSSDComplete(ussdResp);
}

void BaseConnectionUSSDInterface::RespondComplete(bool success, const QString &ussdResp)
{
    Q_EMIT mPriv->adaptee->respondComplete(success, ussdResp);
}

void BaseConnectionUSSDInterface::BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap)
{
    Q_EMIT mPriv->adaptee->barringComplete(ssOp, cbService, cbMap);
}

void BaseConnectionUSSDInterface::ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap)
{
    Q_EMIT mPriv->adaptee->forwardingComplete(ssOp, cfService, cfMap);
}

void BaseConnectionUSSDInterface::WaitingComplete(const QString &ssOp, const QVariantMap &cwMap)
{
    Q_EMIT mPriv->adaptee->waitingComplete(ssOp, cwMap);
}

void BaseConnectionUSSDInterface::CallingLinePresentationComplete(const QString &ssOp, const QString &status)
{
    Q_EMIT mPriv->adaptee->callingLinePresentationComplete(ssOp, status);
}

void BaseConnectionUSSDInterface::ConnectedLinePresentationComplete(const QString &ssOp, const QString &status)
{
    Q_EMIT mPriv->adaptee->connectedLinePresentationComplete(ssOp, status);
}

void BaseConnectionUSSDInterface::CallingLineRestrictionComplete(const QString &ssOp, const QString &status)
{
    Q_EMIT mPriv->adaptee->callingLineRestrictionComplete(ssOp, status);
}

void BaseConnectionUSSDInterface::ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status)
{
    Q_EMIT mPriv->adaptee->connectedLineRestrictionComplete(ssOp, status);
}

void BaseConnectionUSSDInterface::InitiateFailed()
{
    Q_EMIT mPriv->adaptee->initiateFailed();
}

void BaseConnectionUSSDInterface::NotificationReceived(const QString &message)
{
    Q_EMIT mPriv->adaptee->notificationReceived(message);
}

void BaseConnectionUSSDInterface::RequestReceived(const QString &message)
{
    Q_EMIT mPriv->adaptee->requestReceived(message);
}


QVariantMap BaseConnectionUSSDInterface::immutableProperties() const
{
    QVariantMap map;
    return map;
}

void BaseConnectionUSSDInterface::createAdaptor()
{
    (void) new ConnectionInterfaceUSSDAdaptor(dbusObject()->dbusConnection(),
            mPriv->adaptee, dbusObject());
}


ConnectionInterfaceUSSDAdaptor::ConnectionInterfaceUSSDAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
    : Tp::AbstractAdaptor(bus, adaptee, parent)
{
    connect(adaptee, SIGNAL(notificationReceived(const QString &)), SIGNAL(NotificationReceived(const QString &)));
    connect(adaptee, SIGNAL(requestReceived(const QString &)), SIGNAL(RequestReceived(const QString &)));

    connect(adaptee, SIGNAL(initiateUSSDComplete(const QString &)), SIGNAL(InitiateUSSDComplete(const QString &)));

    connect(adaptee, SIGNAL(barringComplete(const QString &, const QString &, const QVariantMap &)), 
        SIGNAL(BarringComplete(const QString &, const QString &, const QVariantMap &)));

    connect(adaptee, SIGNAL(forwardingComplete(const QString &, const QString &, const QVariantMap &)), 
        SIGNAL(ForwardingComplete(const QString &, const QString &, const QVariantMap &)));

    connect(adaptee, SIGNAL(waitingComplete(const QString &, const QVariantMap &)), 
        SIGNAL(WaitingComplete(const QString &, const QVariantMap &)));

    connect(adaptee, SIGNAL(callingLinePresentationComplete(const QString &, const QString &)), 
        SIGNAL(CallingLinePresentationComplete(const QString &, const QString &)));

    connect(adaptee, SIGNAL(connectedLinePresentationComplete(const QString &, const QString &)), 
        SIGNAL(ConnectedLinePresentationComplete(const QString &, const QString &)));

    connect(adaptee, SIGNAL(callingLineRestrictionComplete(const QString &, const QString &)), 
        SIGNAL(CallingLineRestrictionComplete(const QString &, const QString &)));

    connect(adaptee, SIGNAL(connectedLineRestrictionComplete(const QString &, const QString &)), 
        SIGNAL(ConnectedLineRestrictionComplete(const QString &, const QString &)));

    connect(adaptee, SIGNAL(initiateFailed()), SIGNAL(InitiateFailed()));

    connect(adaptee, SIGNAL(stateChanged(const QString&)), SIGNAL(StateChanged(const QString&)));

    connect(adaptee, SIGNAL(respondComplete(bool, const QString &)), SIGNAL(RespondComplete(bool, const QString &)));
}

ConnectionInterfaceUSSDAdaptor::~ConnectionInterfaceUSSDAdaptor()
{
}

void ConnectionInterfaceUSSDAdaptor::Initiate(const QString &command, const QDBusMessage& dbusMessage)
{
    if (!adaptee()->metaObject()->indexOfMethod("initiate(const QString &,ConnectionInterfaceUSSDAdaptor::InitiateContextPtr)") == -1) {
        dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
        return;
    }

    InitiateContextPtr ctx = InitiateContextPtr(
            new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
    QMetaObject::invokeMethod(adaptee(), "initiate",
        Q_ARG(QString, command),
        Q_ARG(ConnectionInterfaceUSSDAdaptor::InitiateContextPtr, ctx));
    return;
}

void ConnectionInterfaceUSSDAdaptor::Respond(const QString &reply, const QDBusMessage& dbusMessage)
{
    if (!adaptee()->metaObject()->indexOfMethod("respond(QConnectionInterfaceUSSDAdaptor::RespondContextPtr)") == -1) {
        dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
        return;
    }

    RespondContextPtr ctx = RespondContextPtr(
            new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
    QMetaObject::invokeMethod(adaptee(), "respond",
        Q_ARG(QString, reply),
        Q_ARG(ConnectionInterfaceUSSDAdaptor::RespondContextPtr, ctx));
    return;
}

void ConnectionInterfaceUSSDAdaptor::Cancel(const QDBusMessage& dbusMessage)
{
    if (!adaptee()->metaObject()->indexOfMethod("cancel(ConnectionInterfaceUSSDAdaptor::CancelContextPtr)") == -1) {
        dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
        return;
    }

    CancelContextPtr ctx = CancelContextPtr(
            new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage));
    QMetaObject::invokeMethod(adaptee(), "cancel",
        Q_ARG(ConnectionInterfaceUSSDAdaptor::CancelContextPtr, ctx));
    return;
}

QString ConnectionInterfaceUSSDAdaptor::Serial() const
{
    return qvariant_cast< QString >(adaptee()->property("serial"));
}


QString ConnectionInterfaceUSSDAdaptor::State() const
{
    return qvariant_cast< QString >(adaptee()->property("state"));
}