Adding CallVolume interface support in ofono-qt Bindings Signed-off-by: Arun Ravindra...
[profile/ivi/ofono-qt.git] / lib / ofonosupplementaryservices.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
26
27 #include "ofonosupplementaryservices.h"
28 #include "ofonointerface.h"
29
30 #define REQUEST_TIMEOUT 60000
31
32 OfonoSupplementaryServices::OfonoSupplementaryServices(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent)
33     : OfonoModemInterface(modemSetting, modemPath, "org.ofono.SupplementaryServices", OfonoGetAllOnStartup, parent)
34 {
35
36     connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), 
37             this, SLOT(propertyChanged(const QString&, const QVariant&)));
38     QDBusConnection::systemBus().connect("org.ofono", path(), m_if->ifname(), 
39                                              "NotificationReceived",
40                                              this,
41                                              SIGNAL(notificationReceived(QString)));
42     QDBusConnection::systemBus().connect("org.ofono", path(), m_if->ifname(), 
43                                              "RequestReceived",
44                                              this,
45                                              SIGNAL(requestReceived(QString)));
46 }
47
48 OfonoSupplementaryServices::~OfonoSupplementaryServices()
49 {
50 }
51
52 void OfonoSupplementaryServices::initiate(const QString &command)
53 {
54     QDBusMessage request;
55
56     request = QDBusMessage::createMethodCall("org.ofono",
57                                              path(), m_if->ifname(),
58                                              "Initiate");
59     request << command;
60
61     QDBusConnection::systemBus().callWithCallback(request, this,
62                                         SLOT(initiateResp(QString, QDBusVariant)),
63                                         SLOT(initiateErr(const QDBusError&)),
64                                         REQUEST_TIMEOUT);
65 }
66
67 void OfonoSupplementaryServices::respond(const QString &reply)
68 {
69     QDBusMessage request;
70
71     request = QDBusMessage::createMethodCall("org.ofono",
72                                              path(), m_if->ifname(),
73                                              "Respond");
74     request << reply;
75
76     QDBusConnection::systemBus().callWithCallback(request, this,
77                                         SLOT(respondResp(QString)),
78                                         SLOT(respondErr(const QDBusError&)),
79                                         REQUEST_TIMEOUT);
80 }
81
82 void OfonoSupplementaryServices::cancel()
83 {
84     QDBusMessage request;
85
86     request = QDBusMessage::createMethodCall("org.ofono",
87                                              path(), m_if->ifname(),
88                                              "Cancel");
89
90     QDBusConnection::systemBus().callWithCallback(request, this,
91                                         SLOT(cancelResp()),
92                                         SLOT(cancelErr(const QDBusError&)),
93                                         REQUEST_TIMEOUT);
94 }
95
96 QString OfonoSupplementaryServices::state() const
97 {
98     return m_if->properties()["State"].value<QString>();
99 }
100
101 void OfonoSupplementaryServices::propertyChanged(const QString& property, const QVariant& value)
102 {
103     if (property == "State") {  
104         emit stateChanged(value.value<QString>());
105     } 
106 }
107
108 void OfonoSupplementaryServices::initiateResp(QString message, QDBusVariant details)
109 {
110     const QDBusArgument argument = details.variant().value<QDBusArgument>();
111     if (message == "USSD") {
112         QString ussdResp = details.variant().toString();
113         emit initiateUSSDComplete(ussdResp);
114     } else if (message == "CallBarring") {
115         QString ssOp, cbService;
116         QVariantMap cbMap;
117         argument.beginStructure();
118         argument >> ssOp >> cbService >> cbMap;
119         argument.endStructure();
120         emit barringComplete(ssOp, cbService, cbMap);
121     } else if (message == "CallForwarding") {
122         QString ssOp, cfService;
123         QVariantMap cfMap;
124         argument.beginStructure();
125         argument >> ssOp >> cfService >> cfMap;
126         argument.endStructure();
127         emit forwardingComplete(ssOp, cfService, cfMap);
128     } else if (message == "CallWaiting") {
129         QString ssOp;
130         QVariantMap cwMap;
131         argument.beginStructure();
132         argument >> ssOp >> cwMap;
133         argument.endStructure();
134         emit waitingComplete(ssOp, cwMap);
135     } else if (message == "CallingLinePresentation") {
136         QString ssOp, status;
137         argument.beginStructure();
138         argument >> ssOp >> status;
139         argument.endStructure();
140         emit callingLinePresentationComplete(ssOp, status);
141     } else if (message == "ConnectedLinePresentation") {
142         QString ssOp, status;
143         argument.beginStructure();
144         argument >> ssOp >> status;
145         argument.endStructure();
146         emit connectedLinePresentationComplete(ssOp, status);
147     } else if (message == "CallingLineRestriction") {
148         QString ssOp, status;
149         argument.beginStructure();
150         argument >> ssOp >> status;
151         argument.endStructure();
152         emit callingLineRestrictionComplete(ssOp, status);
153     } else if (message == "ConnectedLineRestriction") {
154         QString ssOp, status;
155         argument.beginStructure();
156         argument >> ssOp >> status;
157         argument.endStructure();
158         emit connectedLineRestrictionComplete(ssOp, status);
159     } else {
160         m_if->setError(QString(), QString("Unknown initiate response"));
161         emit initiateFailed();
162     }
163 }
164
165 void OfonoSupplementaryServices::initiateErr(QDBusError error)
166 {
167     qDebug() << "Initiate failed" << error;
168     m_if->setError(error.name(), error.message());
169     emit initiateFailed();
170 }
171
172
173 void OfonoSupplementaryServices::respondResp(QString message)
174 {
175     emit respondComplete(TRUE, message);
176 }
177
178 void OfonoSupplementaryServices::respondErr(QDBusError error)
179 {
180     qDebug() << "Respond failed" << error;
181     m_if->setError(error.name(), error.message());
182     emit respondComplete(FALSE, QString());
183 }
184
185 void OfonoSupplementaryServices::cancelResp()
186 {
187     emit cancelComplete(TRUE);
188 }
189
190 void OfonoSupplementaryServices::cancelErr(QDBusError error)
191 {
192     qDebug() << "Cancel failed" << error;
193     m_if->setError(error.name(), error.message());
194     emit cancelComplete(FALSE);
195 }
196