~mterry/telephony-service/start-on

« back to all changes in this revision

Viewing changes to handler/tests/mock/speakeriface.cpp

  • Committer: CI bot
  • Author(s): Gustavo Pichorim Boiko
  • Date: 2014-04-02 12:41:29 UTC
  • mfrom: (765.2.24 telephony-service-conf_call)
  • Revision ID: ps-jenkins@lists.canonical.com-20140402124129-oywt8u6u9f4253bg
Add support for handling conference calls. 

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
 */
 
18
 
 
19
#include <QDebug>
 
20
 
 
21
#include <TelepathyQt/Constants>
 
22
#include <TelepathyQt/DBusObject>
 
23
 
 
24
#include "speakeriface.h"
 
25
 
 
26
// Chan.I.Speaker
 
27
BaseChannelSpeakerInterface::Adaptee::Adaptee(BaseChannelSpeakerInterface *interface)
 
28
    : QObject(interface),
 
29
      mInterface(interface)
 
30
{
 
31
}
 
32
 
 
33
struct TP_QT_NO_EXPORT BaseChannelSpeakerInterface::Private {
 
34
    Private(BaseChannelSpeakerInterface *parent)
 
35
        : speakerMode(false),
 
36
          adaptee(new BaseChannelSpeakerInterface::Adaptee(parent)) {
 
37
    }
 
38
    bool speakerMode;
 
39
    turnOnSpeakerCallback turnOnSpeakerCB;
 
40
    BaseChannelSpeakerInterface::Adaptee *adaptee;
 
41
};
 
42
 
 
43
BaseChannelSpeakerInterface::Adaptee::~Adaptee()
 
44
{
 
45
}
 
46
 
 
47
void BaseChannelSpeakerInterface::Adaptee::turnOnSpeaker(bool active, const ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr &context)
 
48
{
 
49
    if (!mInterface->mPriv->turnOnSpeakerCB.isValid()) {
 
50
        context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
 
51
        return;
 
52
    }
 
53
    Tp::DBusError error;
 
54
    mInterface->mPriv->turnOnSpeakerCB(active, &error);
 
55
    if (error.isValid()) {
 
56
        context->setFinishedWithError(error.name(), error.message());
 
57
        return;
 
58
    }
 
59
    context->setFinished();
 
60
}
 
61
 
 
62
BaseChannelSpeakerInterface::BaseChannelSpeakerInterface()
 
63
    : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_SPEAKER),
 
64
      mPriv(new Private(this))
 
65
{
 
66
}
 
67
 
 
68
BaseChannelSpeakerInterface::~BaseChannelSpeakerInterface()
 
69
{
 
70
    delete mPriv;
 
71
}
 
72
 
 
73
bool BaseChannelSpeakerInterface::speakerMode() const
 
74
{
 
75
    return mPriv->speakerMode;
 
76
}
 
77
 
 
78
void BaseChannelSpeakerInterface::setTurnOnSpeakerCallback(const turnOnSpeakerCallback &cb)
 
79
{
 
80
    mPriv->turnOnSpeakerCB = cb;
 
81
}
 
82
 
 
83
void BaseChannelSpeakerInterface::setSpeakerMode(bool active)
 
84
{
 
85
    mPriv->speakerMode = active;
 
86
    Q_EMIT mPriv->adaptee->speakerChanged(active);
 
87
}
 
88
 
 
89
QVariantMap BaseChannelSpeakerInterface::immutableProperties() const
 
90
{
 
91
    QVariantMap map;
 
92
    return map;
 
93
}
 
94
 
 
95
void BaseChannelSpeakerInterface::createAdaptor()
 
96
{
 
97
    (void) new ChannelInterfaceSpeakerAdaptor(dbusObject()->dbusConnection(),
 
98
            mPriv->adaptee, dbusObject());
 
99
}
 
100
 
 
101
 
 
102
ChannelInterfaceSpeakerAdaptor::ChannelInterfaceSpeakerAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent)
 
103
    : Tp::AbstractAdaptor(bus, adaptee, parent)
 
104
{
 
105
    connect(adaptee, SIGNAL(speakerChanged(bool)), SIGNAL(SpeakerChanged(bool)));
 
106
}
 
107
 
 
108
ChannelInterfaceSpeakerAdaptor::~ChannelInterfaceSpeakerAdaptor()
 
109
{
 
110
}
 
111
 
 
112
void ChannelInterfaceSpeakerAdaptor::turnOnSpeaker(bool active, const QDBusMessage& dbusMessage)
 
113
{
 
114
    if (!adaptee()->metaObject()->indexOfMethod("turnOnSpeaker(bool,ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr)") == -1) {
 
115
        dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
 
116
        return;
 
117
    }
 
118
 
 
119
    turnOnSpeakerContextPtr ctx = turnOnSpeakerContextPtr(
 
120
            new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage));
 
121
    QMetaObject::invokeMethod(adaptee(), "turnOnSpeaker",
 
122
        Q_ARG(bool, active),
 
123
        Q_ARG(ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr, ctx));
 
124
    return;
 
125
}
 
126
 
 
127
bool ChannelInterfaceSpeakerAdaptor::SpeakerMode() const
 
128
{
 
129
    return qvariant_cast< bool >(adaptee()->property("speakerMode"));
 
130
}
 
131