~rsalveti/telepathy-ofono/improve_pa_event_handling

« back to all changes in this revision

Viewing changes to emergencymodeiface.cpp

  • Committer: CI bot
  • Author(s): Gustavo Pichorim Boiko
  • Date: 2014-07-01 16:16:07 UTC
  • mfrom: (82.1.4 telepathy-ofono-emergency_mode)
  • Revision ID: ps-jenkins@lists.canonical.com-20140701161607-0p1fon3q1oneas7g
Expose the emergency numbers via DBus so that clients can query it. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License version 3, as published by
 
6
 * the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors: Tiago Salem Herrmann <tiago.herrmann@canonical.com>
 
17
 *          Gustavo Pichorim Boiko <gustavo.boiko@gmail.com>
 
18
 */
 
19
 
 
20
#include <QDebug>
 
21
 
 
22
#include <TelepathyQt/Constants>
 
23
#include <TelepathyQt/DBusObject>
 
24
 
 
25
#include "emergencymodeiface.h"
 
26
 
 
27
BaseConnectionEmergencyModeInterface::Adaptee::Adaptee(BaseConnectionEmergencyModeInterface *interface)
 
28
    : QObject(interface),
 
29
      mInterface(interface)
 
30
{
 
31
}
 
32
 
 
33
 
 
34
struct TP_QT_NO_EXPORT BaseConnectionEmergencyModeInterface::Private {
 
35
    Private(BaseConnectionEmergencyModeInterface *parent)
 
36
        : adaptee(new BaseConnectionEmergencyModeInterface::Adaptee(parent)) {
 
37
    }
 
38
    EmergencyNumbersCallback emergencyNumbersCB;
 
39
    BaseConnectionEmergencyModeInterface::Adaptee *adaptee;
 
40
};
 
41
 
 
42
BaseConnectionEmergencyModeInterface::Adaptee::~Adaptee()
 
43
{
 
44
}
 
45
 
 
46
void BaseConnectionEmergencyModeInterface::Adaptee::emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context)
 
47
{
 
48
    if (!mInterface->mPriv->emergencyNumbersCB.isValid()) {
 
49
        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
 
50
        return;
 
51
    }
 
52
    Tp::DBusError error;
 
53
    QStringList numbers = mInterface->mPriv->emergencyNumbersCB(&error);
 
54
    if (error.isValid()) {
 
55
        context->setFinishedWithError(error.name(), error.message());
 
56
        return;
 
57
    }
 
58
    context->setFinished(numbers);
 
59
}
 
60
 
 
61
BaseConnectionEmergencyModeInterface::BaseConnectionEmergencyModeInterface()
 
62
    : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_EMERGENCYMODE),
 
63
      mPriv(new Private(this))
 
64
{
 
65
}
 
66
 
 
67
BaseConnectionEmergencyModeInterface::~BaseConnectionEmergencyModeInterface()
 
68
{
 
69
    delete mPriv;
 
70
}
 
71
 
 
72
void BaseConnectionEmergencyModeInterface::setEmergencyNumbersCallback(const EmergencyNumbersCallback &cb)
 
73
{
 
74
    mPriv->emergencyNumbersCB = cb;
 
75
}
 
76
 
 
77
void BaseConnectionEmergencyModeInterface::setEmergencyNumbers(const QStringList &numbers)
 
78
{
 
79
    Q_EMIT mPriv->adaptee->emergencyNumbersChanged(numbers);
 
80
}
 
81
 
 
82
QVariantMap BaseConnectionEmergencyModeInterface::immutableProperties() const
 
83
{
 
84
    QVariantMap map;
 
85
    return map;
 
86
}
 
87
 
 
88
void BaseConnectionEmergencyModeInterface::createAdaptor()
 
89
{
 
90
    (void) new ConnectionInterfaceEmergencyModeAdaptor(dbusObject()->dbusConnection(),
 
91
            mPriv->adaptee, dbusObject());
 
92
}
 
93
 
 
94
 
 
95
ConnectionInterfaceEmergencyModeAdaptor::ConnectionInterfaceEmergencyModeAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
 
96
    : Tp::AbstractAdaptor(bus, adaptee, parent)
 
97
{
 
98
    connect(adaptee, SIGNAL(emergencyNumbersChanged(QStringList)), SIGNAL(EmergencyNumbersChanged(QStringList)));
 
99
}
 
100
 
 
101
ConnectionInterfaceEmergencyModeAdaptor::~ConnectionInterfaceEmergencyModeAdaptor()
 
102
{
 
103
}
 
104
 
 
105
QStringList ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbers(const QDBusMessage& dbusMessage)
 
106
{
 
107
    if (!adaptee()->metaObject()->indexOfMethod("emergencyNumbers(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr)") == -1) {
 
108
        dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
 
109
        return QStringList();
 
110
    }
 
111
 
 
112
    EmergencyNumbersContextPtr ctx = EmergencyNumbersContextPtr(
 
113
            new Tp::MethodInvocationContext< QStringList >(dbusConnection(), dbusMessage));
 
114
    QMetaObject::invokeMethod(adaptee(), "emergencyNumbers",
 
115
        Q_ARG(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr, ctx));
 
116
    return QStringList();
 
117
}