3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
6 Based on Telepathy-SNOM with copyright notice below.
10 * Telepathy SNOM VoIP phone connection manager
11 * Copyright (C) 2006 by basyskom GmbH
12 * @author Tobias Hunger <info@basyskom.de>
14 * This library is free software; you can redisQObject::tribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License version 2.1 as published by the Free Software Foundation.
18 * This library is disQObject::tributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the
25 * Free Software Foundation, Inc.,
26 * 51 Franklin SQObject::treet, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "connectionmanager.h"
30 #include "connectionmanageradaptor.h"
31 #include "connection.h"
32 #include <logutility.h>
34 #include <QtCore/QDebug>
38 static const QString protocol_name("tel");
41 class ConnectionManagerPrivate
44 ConnectionManagerPrivate(ConnectionManager * parent) :
45 adaptor(new ConnectionManagerAdaptor(parent)),
47 logUtility(new LogUtility(parent))
49 logUtility(new LogUtility("/var/log/vicar/vicar.log",parent))
50 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
52 Q_ASSERT(0 != adaptor);
56 ~ConnectionManagerPrivate() { delete(adaptor);}
57 ConnectionManagerAdaptor * const adaptor;
58 LogUtility * const logUtility;
59 Connection * activeConnection;
62 // ---------------------------------------------------------------------------
64 ConnectionManager::ConnectionManager(QObject * parent) :
66 d(new ConnectionManagerPrivate(this))
69 ConnectionManager::~ConnectionManager()
72 org::freedesktop::Telepathy::ParameterDefinitionList
73 ConnectionManager::GetParameters(const QString &proto)
77 Q_ASSERT(!proto.isEmpty());
79 strMessage = "VICAR: ConnectionManager::GetParameters(const QString &prot)";
82 qDebug() << strMessage;
83 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
84 d->logUtility->logMessage(strMessage);
85 org::freedesktop::Telepathy::ParameterDefinitionList result;
86 org::freedesktop::Telepathy::ParameterDefinition param;
88 //TODO - Match the parameters with telepathy-ring?
90 // Attention! Default constructed QDBusVariants cause havok on the D-Bus!
91 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.IMSI";
92 param.flags = Register;
93 param.signature = "s";
94 param.defaultValue = QDBusVariant(QString());
97 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
98 param.flags = Register|hasDefault;
99 param.signature = "s";
100 param.defaultValue = QDBusVariant(QString());
101 result.append(param);
103 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre";
104 param.flags = Register;
105 param.signature = "s";
106 param.defaultValue = QDBusVariant(QString());
107 result.append(param);
109 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod";
110 param.flags = Register|hasDefault;
111 param.signature = "u";
112 param.defaultValue = QDBusVariant(0);
113 result.append(param);
115 param.name = "account";
117 param.signature = "s";
118 param.defaultValue = QDBusVariant(QString());
119 result.append(param);
121 param.name = "password";
123 param.signature = "s";
124 param.defaultValue = QDBusVariant(QString());
125 result.append(param);
130 QStringList ConnectionManager::ListProtocols()
132 QString strMessage = "VICaR ConnectionManager::ListProtocols()";
135 qDebug() << strMessage;
136 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
137 d->logUtility->logMessage(strMessage);
138 return QStringList(protocol_name);
141 QString ConnectionManager::RequestConnection(const QString & proto,
142 QVariantMap parameters,
143 QDBusObjectPath & object_path)
145 QString strMessage = "VICaR CM: Connection Requested for protocol "+proto;
148 qDebug() << strMessage;
149 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
150 d->logUtility->logMessage(strMessage);
151 QString connection_service;
152 //object_path = QDBusObjectPath();
154 if (proto != protocol_name)
157 sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
158 "VICaR - Unable to create Connection. Requested protocol is not implemented.");
160 strMessage = "VICaR CM::RequestConnection: proto mismatch.";
162 d->logUtility->logMessage(strMessage);
163 return connection_service;
165 if (d->activeConnection != 0){
166 strMessage = "VICaR CM::RequestConnection: An active connection already exists at "+d->activeConnection->serviceName();
167 d->logUtility->logMessage(strMessage);
169 object_path = d->activeConnection->objectPath();
170 connection_service = d->activeConnection->serviceName();
171 //emit NewConnection(connection_service, object_path, "tel"); //Just in case, emit the NewConnection again
172 return connection_service;
175 qDebug() << strMessage;
176 d->logUtility->logMessage(strMessage);
177 return connection_service;
179 if (d->activeConnection != 0){
180 strMessage = "VICaR CM::RequestConnection: An active connection already exists at "+d->activeConnection->serviceName();
181 qDebug() << strMessage;
182 d->logUtility->logMessage(strMessage);
184 object_path = d->activeConnection->objectPath();
185 connection_service = d->activeConnection->serviceName();
186 //emit NewConnection(connection_service, object_path, "tel"); //Just in case, emit the NewConnection again
187 return connection_service;
189 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
193 QString smsServiceCenter;
194 uint smsValidityPeriod(0);
200 foreach (param, parameters.keys())
202 if ("com.nokia.Telepathy.Connection.Interface.GSM.IMSI" == param)
203 { imsi = parameters[param].toString(); }
204 else if ("com.nokia.Telepathy.Connection.Interface.GSM.Privacy" == param)
205 { privacy = parameters[param].toString(); }
206 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre" == param)
207 { smsServiceCenter = parameters[param].toString(); }
208 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod" == param)
209 { smsValidityPeriod = parameters[param].toInt(); }
210 else if ("account" == param)
211 { account = parameters[param].toString(); }
212 else if ("password" == param)
213 { password = parameters[param].toString(); }
217 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
218 "VICaR - Unable to create Connection. Invalid parameters specified.");
220 strMessage = "VICaR CM::RequestConnection: invalid parameter" + param + "found.";
223 qDebug() << strMessage;
224 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
225 d->logUtility->logMessage(strMessage);
226 return connection_service;
230 strMessage = "DEBUG CM: Trying to create new connection with account "+account;
233 qDebug() << strMessage;
234 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
235 d->logUtility->logMessage(strMessage);
237 Connection * new_connection = new Connection(account, this);
238 Q_ASSERT(0 != new_connection);
240 strMessage = "DEBUG CM: Trying to register new connection";
243 qDebug() << strMessage;
244 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
245 d->logUtility->logMessage(strMessage);
247 if (!new_connection->registerObject())
249 strMessage = "VICaR CM: Error while registering Connection object with DBus.";
252 qDebug() << strMessage;
253 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
254 d->logUtility->logMessage(strMessage);
255 new_connection->deleteLater();
259 strMessage = "VICaR CM: New Connection Created. Status is " + QString(new_connection->GetStatus());
262 qDebug() << strMessage;
263 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
264 d->logUtility->logMessage(strMessage);
267 object_path = new_connection->objectPath();
268 connection_service = new_connection->serviceName();
270 strMessage = "VICaR CM: Emitting New Connection Signal";
273 qDebug() << strMessage;
274 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
275 d->logUtility->logMessage(strMessage);
277 emit NewConnection(connection_service, object_path, "tel");
279 //Set ActiveConnection - We only need one active connection at a time
280 d->activeConnection = new_connection;
281 return new_connection->serviceName();