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)),
46 logUtility(new LogUtility("/var/log/vicar/vicar.log",parent))
48 Q_ASSERT(0 != adaptor);
52 ~ConnectionManagerPrivate() { delete(adaptor);}
53 ConnectionManagerAdaptor * const adaptor;
54 LogUtility * const logUtility;
55 Connection * activeConnection;
58 // ---------------------------------------------------------------------------
60 ConnectionManager::ConnectionManager(QObject * parent) :
62 d(new ConnectionManagerPrivate(this))
65 ConnectionManager::~ConnectionManager()
68 org::freedesktop::Telepathy::ParameterDefinitionList
69 ConnectionManager::GetParameters(const QString &proto)
73 Q_ASSERT(!proto.isEmpty());
75 strMessage = "VICAR: ConnectionManager::GetParameters(const QString &prot)";
76 qDebug() << strMessage;
77 d->logUtility->logMessage(strMessage);
78 org::freedesktop::Telepathy::ParameterDefinitionList result;
79 org::freedesktop::Telepathy::ParameterDefinition param;
81 //TODO - Match the parameters with telepathy-ring?
83 // Attention! Default constructed QDBusVariants cause havok on the D-Bus!
84 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.IMSI";
85 param.flags = Register;
86 param.signature = "s";
87 param.defaultValue = QDBusVariant(QString());
90 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
91 param.flags = Register|hasDefault;
92 param.signature = "s";
93 param.defaultValue = QDBusVariant(QString());
96 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre";
97 param.flags = Register;
98 param.signature = "s";
99 param.defaultValue = QDBusVariant(QString());
100 result.append(param);
102 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod";
103 param.flags = Register|hasDefault;
104 param.signature = "u";
105 param.defaultValue = QDBusVariant(0);
106 result.append(param);
108 param.name = "account";
110 param.signature = "s";
111 param.defaultValue = QDBusVariant(QString());
112 result.append(param);
114 param.name = "password";
116 param.signature = "s";
117 param.defaultValue = QDBusVariant(QString());
118 result.append(param);
123 QStringList ConnectionManager::ListProtocols()
125 QString strMessage = "VICaR ConnectionManager::ListProtocols()";
126 qDebug() << strMessage;
127 d->logUtility->logMessage(strMessage);
128 return QStringList(protocol_name);
131 QString ConnectionManager::RequestConnection(const QString & proto,
132 QVariantMap parameters,
133 QDBusObjectPath & object_path)
135 QString strMessage = "VICaR CM: Connection Requested for protocol "+proto;
136 qDebug() << strMessage;
137 d->logUtility->logMessage(strMessage);
138 QString connection_service;
139 //object_path = QDBusObjectPath();
141 if (proto != protocol_name)
144 sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
145 "VICaR - Unable to create Connection. Requested protocol is not implemented.");
147 strMessage = "VICaR CM::RequestConnection: proto mismatch.";
148 qDebug() << strMessage;
149 d->logUtility->logMessage(strMessage);
150 return connection_service;
152 if (d->activeConnection != 0){
153 strMessage = "VICaR CM::RequestConnection: An active connection already exists at "+d->activeConnection->serviceName();
154 qDebug() << strMessage;
155 d->logUtility->logMessage(strMessage);
157 object_path = d->activeConnection->objectPath();
158 connection_service = d->activeConnection->serviceName();
159 //emit NewConnection(connection_service, object_path, "tel"); //Just in case, emit the NewConnection again
160 return connection_service;
165 QString smsServiceCenter;
166 uint smsValidityPeriod(0);
172 foreach (param, parameters.keys())
174 if ("com.nokia.Telepathy.Connection.Interface.GSM.IMSI" == param)
175 { imsi = parameters[param].toString(); }
176 else if ("com.nokia.Telepathy.Connection.Interface.GSM.Privacy" == param)
177 { privacy = parameters[param].toString(); }
178 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre" == param)
179 { smsServiceCenter = parameters[param].toString(); }
180 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod" == param)
181 { smsValidityPeriod = parameters[param].toInt(); }
182 else if ("account" == param)
183 { account = parameters[param].toString(); }
184 else if ("password" == param)
185 { password = parameters[param].toString(); }
189 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
190 "VICaR - Unable to create Connection. Invalid parameters specified.");
192 strMessage = "VICaR CM::RequestConnection: invalid parameter" + param + "found.";
193 qDebug() << strMessage;
194 d->logUtility->logMessage(strMessage);
195 return connection_service;
199 strMessage = "DEBUG CM: Trying to create new connection with account "+account;
200 qDebug() << strMessage;
201 d->logUtility->logMessage(strMessage);
203 Connection * new_connection = new Connection(account, this);
204 Q_ASSERT(0 != new_connection);
206 strMessage = "DEBUG CM: Trying to register new connection";
207 qDebug() << strMessage;
208 d->logUtility->logMessage(strMessage);
210 if (!new_connection->registerObject())
212 strMessage = "VICaR CM: Error while registering Connection object with DBus.";
213 qDebug() << strMessage;
214 d->logUtility->logMessage(strMessage);
215 new_connection->deleteLater();
219 strMessage = "VICaR CM: New Connection Created. Status is " + QString(new_connection->GetStatus());
220 qDebug() << strMessage;
221 d->logUtility->logMessage(strMessage);
224 object_path = new_connection->objectPath();
225 connection_service = new_connection->serviceName();
227 strMessage = "VICaR CM: Emitting New Connection Signal";
228 qDebug() << strMessage;
229 d->logUtility->logMessage(strMessage);
231 emit NewConnection(connection_service, object_path, "tel");
233 //Set ActiveConnection - We only need one active connection at a time
234 d->activeConnection = new_connection;
235 return new_connection->serviceName();