[telepathy-qt4/master] ClientRegistrar: Removed ClientObject. Use AbstractClient to registerClients.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Mon May 11 12:01:17 PDT 2009
---
TelepathyQt4/ClientObject | 13 --------
TelepathyQt4/Makefile.am | 3 --
TelepathyQt4/client-object.cpp | 58 -------------------------------------
TelepathyQt4/client-object.h | 57 ------------------------------------
TelepathyQt4/client-registrar.cpp | 55 +++++++++++++---------------------
TelepathyQt4/client-registrar.h | 6 ++--
tests/dbus/client-handler.cpp | 24 +++++++--------
7 files changed, 35 insertions(+), 181 deletions(-)
delete mode 100644 TelepathyQt4/ClientObject
delete mode 100644 TelepathyQt4/client-object.cpp
delete mode 100644 TelepathyQt4/client-object.h
diff --git a/TelepathyQt4/ClientObject b/TelepathyQt4/ClientObject
deleted file mode 100644
index 722d250..0000000
--- a/TelepathyQt4/ClientObject
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _TelepathyQt4_Client_ClientObject_HEADER_GUARD_
-#define _TelepathyQt4_Client_ClientObject_HEADER_GUARD_
-
-#ifndef IN_TELEPATHY_QT4_HEADER
-#define IN_TELEPATHY_QT4_HEADER
-#endif
-
-#include <TelepathyQt4/client-object.h>
-
-#undef IN_TELEPATHY_QT4_HEADER
-
-#endif
-// vim:set ft=cpp:
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index dea87cd..920de10 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -52,7 +52,6 @@ libtelepathy_qt4_la_SOURCES = \
channel.cpp \
channel-request.cpp \
client-handler.cpp \
- client-object.cpp \
client-registrar.cpp \
client-registrar-internal.h \
connection.cpp \
@@ -157,7 +156,6 @@ tpqt4include_HEADERS = \
Channel \
ChannelRequest \
ClientHandler \
- ClientObject \
ClientRegistrar \
Connection \
ConnectionManager \
@@ -244,7 +242,6 @@ tpqt4include_HEADERS = \
channel.h \
channel-request.h \
client-handler.h \
- client-object.h \
client-registrar.h \
connection.h \
connection-manager.h \
diff --git a/TelepathyQt4/client-object.cpp b/TelepathyQt4/client-object.cpp
deleted file mode 100644
index bc88ed1..0000000
--- a/TelepathyQt4/client-object.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This file is part of TelepathyQt4
- *
- * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) 2009 Nokia Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <TelepathyQt4/ClientObject>
-
-#include <TelepathyQt4/AbstractClient>
-
-namespace Tp
-{
-
-struct ClientObject::Private
-{
- AbstractClientPtr client;
-};
-
-ClientObjectPtr ClientObject::create(const AbstractClientPtr &client)
-{
- if (!client) {
- return ClientObjectPtr();
- }
- return ClientObjectPtr(new ClientObject(client));
-}
-
-ClientObject::ClientObject(const AbstractClientPtr &client)
- : mPriv(new Private)
-{
- mPriv->client = client;
-}
-
-ClientObject::~ClientObject()
-{
- delete mPriv;
-}
-
-AbstractClientPtr ClientObject::client() const
-{
- return mPriv->client;
-}
-
-} // Tp
diff --git a/TelepathyQt4/client-object.h b/TelepathyQt4/client-object.h
deleted file mode 100644
index 87a9938..0000000
--- a/TelepathyQt4/client-object.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * This file is part of TelepathyQt4
- *
- * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright (C) 2009 Nokia Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _TelepathyQt4_cli_client_object_h_HEADER_GUARD_
-#define _TelepathyQt4_cli_client_object_h_HEADER_GUARD_
-
-#ifndef IN_TELEPATHY_QT4_HEADER
-#error IN_TELEPATHY_QT4_HEADER
-#endif
-
-#include <TelepathyQt4/RefCounted>
-#include <TelepathyQt4/Types>
-
-#include <QObject>
-
-namespace Tp
-{
-
-class ClientObject : public QObject, public RefCounted
-{
- Q_DISABLE_COPY(ClientObject)
-
-public:
- static ClientObjectPtr create(const AbstractClientPtr &clientHandler);
- ~ClientObject();
-
- AbstractClientPtr client() const;
-
-private:
- ClientObject(const AbstractClientPtr &clientHandler);
-
- struct Private;
- friend struct Private;
- Private *mPriv;
-};
-
-} // Tp
-
-#endif
diff --git a/TelepathyQt4/client-registrar.cpp b/TelepathyQt4/client-registrar.cpp
index 4888c73..9b93852 100644
--- a/TelepathyQt4/client-registrar.cpp
+++ b/TelepathyQt4/client-registrar.cpp
@@ -30,7 +30,6 @@
#include <TelepathyQt4/Account>
#include <TelepathyQt4/Channel>
#include <TelepathyQt4/ChannelRequest>
-#include <TelepathyQt4/ClientObject>
#include <TelepathyQt4/Connection>
#include <TelepathyQt4/PendingClientOperation>
#include <TelepathyQt4/PendingReady>
@@ -377,9 +376,9 @@ struct ClientRegistrar::Private
QDBusConnection bus;
QString busName;
QString clientName;
- QHash<ClientObjectPtr, QString> clients;
+ QHash<AbstractClientPtr, QString> clients;
+ QHash<AbstractClientPtr, QObject*> clientObjects;
QSet<QString> services;
- QHash<ClientObjectPtr, QList<QDBusAbstractAdaptor*> > adaptorsForClient;
};
QHash<QString, ClientRegistrar*> ClientRegistrar::registrarForConnection;
@@ -424,12 +423,12 @@ QString ClientRegistrar::clientName() const
return mPriv->clientName;
}
-QList<ClientObjectPtr> ClientRegistrar::registeredClients() const
+QList<AbstractClientPtr> ClientRegistrar::registeredClients() const
{
return mPriv->clients.keys();
}
-bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
+bool ClientRegistrar::registerClient(const AbstractClientPtr &client,
bool unique)
{
if (!client) {
@@ -442,7 +441,6 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
return true;
}
- QObject *object = client.data();
QString busName(mPriv->busName);
if (unique) {
// o.f.T.Client.<unique_bus_name>_<pointer> should be enough to identify
@@ -451,7 +449,7 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
.arg(mPriv->bus.baseService()
.replace(':', '_')
.replace('.', "._"))
- .arg((intptr_t) object));
+ .arg((intptr_t) client.data()));
}
if (mPriv->services.contains(busName) ||
@@ -461,25 +459,20 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
return false;
}
+ QObject *object = new QObject(this);
QStringList interfaces;
- ClientHandlerAdaptor *clientHandlerAdaptor = 0;
- ClientHandlerRequestsAdaptor *clientHandlerRequestsAdaptor = 0;
AbstractClientHandler *handler =
- dynamic_cast<AbstractClientHandler*>(client->client().data());
+ dynamic_cast<AbstractClientHandler*>(client.data());
- QList<QDBusAbstractAdaptor *> &adaptors = mPriv->adaptorsForClient[client];
if (handler) {
// export o.f.T.Client.Handler
- clientHandlerAdaptor = new ClientHandlerAdaptor(mPriv->bus, handler, object);
- adaptors.append(clientHandlerAdaptor);
+ new ClientHandlerAdaptor(mPriv->bus, handler, object);
interfaces.append(
QLatin1String("org.freedesktop.Telepathy.Client.Handler"));
if (handler->wantsRequestNotification()) {
// export o.f.T.Client.Interface.Requests
- clientHandlerRequestsAdaptor =
- new ClientHandlerRequestsAdaptor(mPriv->bus, handler, object);
- adaptors.append(clientHandlerRequestsAdaptor);
+ new ClientHandlerRequestsAdaptor(mPriv->bus, handler, object);
interfaces.append(
QLatin1String(
"org.freedesktop.Telepathy.Client.Interface.Requests"));
@@ -496,8 +489,7 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
}
// export o.f,T,Client interface
- ClientAdaptor *clientAdaptor = new ClientAdaptor(interfaces, object);
- adaptors.append(clientAdaptor);
+ new ClientAdaptor(interfaces, object);
QString objectPath = QString("/%1").arg(busName);
objectPath.replace('.', '/');
@@ -506,10 +498,7 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
warning() << "Unable to register client: objectPath" <<
objectPath << "already registered";
// cleanup
- mPriv->adaptorsForClient.remove(client);
- delete clientHandlerAdaptor;
- delete clientHandlerRequestsAdaptor;
- delete clientAdaptor;
+ delete object;
mPriv->bus.unregisterService(busName);
return false;
}
@@ -519,11 +508,12 @@ bool ClientRegistrar::registerClient(const ClientObjectPtr &client,
mPriv->services.insert(busName);
mPriv->clients.insert(client, objectPath);
+ mPriv->clientObjects.insert(client, object);
return true;
}
-bool ClientRegistrar::unregisterClient(const ClientObjectPtr &client)
+bool ClientRegistrar::unregisterClient(const AbstractClientPtr &client)
{
if (!mPriv->clients.contains(client)) {
warning() << "Trying to unregister an unregistered client";
@@ -533,19 +523,16 @@ bool ClientRegistrar::unregisterClient(const ClientObjectPtr &client)
QString objectPath = mPriv->clients.value(client);
mPriv->bus.unregisterObject(objectPath);
mPriv->clients.remove(client);
+ QObject *object = mPriv->clientObjects.value(client);
+ // delete object here and it's children (adaptors), to make sure if adaptor
+ // is keeping a static list of adaptors per connection, the list is updated.
+ delete object;
+ mPriv->clientObjects.remove(client);
QString busName = objectPath.mid(1).replace('/', '.');
mPriv->bus.unregisterService(busName);
mPriv->services.remove(busName);
- QList<QDBusAbstractAdaptor*> &adaptors = mPriv->adaptorsForClient[client];
- foreach (QDBusAbstractAdaptor *adaptor, adaptors) {
- // delete adaptor here, to make sure if adaptor is keeping a static list
- // of adaptors per connection, the list is updated.
- delete adaptor;
- }
- mPriv->adaptorsForClient.remove(client);
-
debug() << "Client unregistered - busName:" << busName <<
"objectPath:" << objectPath;
@@ -555,11 +542,11 @@ bool ClientRegistrar::unregisterClient(const ClientObjectPtr &client)
void ClientRegistrar::unregisterClients()
{
// copy the hash as it will be modified
- QHash<ClientObjectPtr, QString> clients = mPriv->clients;
+ QHash<AbstractClientPtr, QString> clients = mPriv->clients;
- QHash<ClientObjectPtr, QString>::const_iterator end =
+ QHash<AbstractClientPtr, QString>::const_iterator end =
clients.constEnd();
- QHash<ClientObjectPtr, QString>::const_iterator it =
+ QHash<AbstractClientPtr, QString>::const_iterator it =
clients.constBegin();
while (it != end) {
unregisterClient(it.key());
diff --git a/TelepathyQt4/client-registrar.h b/TelepathyQt4/client-registrar.h
index 12eb6ec..1f77b15 100644
--- a/TelepathyQt4/client-registrar.h
+++ b/TelepathyQt4/client-registrar.h
@@ -50,9 +50,9 @@ public:
QDBusConnection dbusConnection() const;
QString clientName() const;
- QList<ClientObjectPtr> registeredClients() const;
- bool registerClient(const ClientObjectPtr &client, bool unique = false);
- bool unregisterClient(const ClientObjectPtr &client);
+ QList<AbstractClientPtr> registeredClients() const;
+ bool registerClient(const AbstractClientPtr &client, bool unique = false);
+ bool unregisterClient(const AbstractClientPtr &client);
void unregisterClients();
private:
diff --git a/tests/dbus/client-handler.cpp b/tests/dbus/client-handler.cpp
index a8dda4c..e00f631 100644
--- a/tests/dbus/client-handler.cpp
+++ b/tests/dbus/client-handler.cpp
@@ -14,7 +14,6 @@
#include <TelepathyQt4/ChannelRequest>
#include <TelepathyQt4/ClientHandlerInterface>
#include <TelepathyQt4/ClientInterfaceRequestsInterface>
-#include <TelepathyQt4/ClientObject>
#include <TelepathyQt4/ClientRegistrar>
#include <TelepathyQt4/Connection>
#include <TelepathyQt4/Debug>
@@ -136,8 +135,9 @@ public:
bool bypassApproval = false,
bool wantsRequestNotification = false)
{
- return AbstractClientPtr(new MyHandler(channelFilter,
- bypassApproval, wantsRequestNotification));
+ return AbstractClientPtr::dynamicCast(SharedPtr<MyHandler>(
+ new MyHandler(channelFilter,
+ bypassApproval, wantsRequestNotification)));
}
MyHandler(const ChannelClassList &channelFilter,
@@ -263,10 +263,10 @@ private:
ClientRegistrarPtr mClientRegistrar;
QString mChannelRequestBusName;
QString mChannelRequestPath;
- ClientObjectPtr mClientObject1;
+ AbstractClientPtr mClientObject1;
QString mClientObject1BusName;
QString mClientObject1Path;
- ClientObjectPtr mClientObject2;
+ AbstractClientPtr mClientObject2;
QString mClientObject2BusName;
QString mClientObject2Path;
uint mUserActionTime;
@@ -394,7 +394,7 @@ void TestClientHandler::init()
void TestClientHandler::testRegister()
{
// invalid client
- QVERIFY(!mClientRegistrar->registerClient(ClientObjectPtr()));
+ QVERIFY(!mClientRegistrar->registerClient(AbstractClientPtr()));
ChannelClassList filters;
QMap<QString, QDBusVariant> filter;
@@ -403,8 +403,7 @@ void TestClientHandler::testRegister()
filter.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
QDBusVariant(Tp::HandleTypeContact));
filters.append(filter);
- mClientObject1 = ClientObject::create(
- MyHandler::create(filters, false, true));
+ mClientObject1 = MyHandler::create(filters, false, true);
QVERIFY(mClientRegistrar->registerClient(mClientObject1));
QVERIFY(mClientRegistrar->registeredClients().contains(mClientObject1));
@@ -418,8 +417,7 @@ void TestClientHandler::testRegister()
filter.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
QDBusVariant(Tp::HandleTypeContact));
filters.append(filter);
- mClientObject2 = ClientObject::create(
- MyHandler::create(filters, true, true));
+ mClientObject2 = MyHandler::create(filters, true, true);
QVERIFY(mClientRegistrar->registerClient(mClientObject2, true));
QVERIFY(mClientRegistrar->registeredClients().contains(mClientObject2));
@@ -448,7 +446,7 @@ void TestClientHandler::testRequests()
ClientInterfaceRequestsInterface *handlerRequestsIface = new ClientInterfaceRequestsInterface(bus,
mClientObject1BusName, mClientObject1Path, this);
- MyHandler *handler = dynamic_cast<MyHandler*>(mClientObject1->client().data());
+ MyHandler *handler = dynamic_cast<MyHandler*>(mClientObject1.data());
connect(handler,
SIGNAL(requestAdded(const Tp::ChannelRequestPtr &)),
SLOT(expectSignalEmission()));
@@ -484,7 +482,7 @@ void TestClientHandler::testHandleChannels()
// object 1
ClientHandlerInterface *handler1Iface = new ClientHandlerInterface(bus,
mClientObject1BusName, mClientObject1Path, this);
- MyHandler *handler1 = dynamic_cast<MyHandler*>(mClientObject1->client().data());
+ MyHandler *handler1 = dynamic_cast<MyHandler*>(mClientObject1.data());
connect(handler1,
SIGNAL(handleChannelsFinished()),
SLOT(expectSignalEmission()));
@@ -511,7 +509,7 @@ void TestClientHandler::testHandleChannels()
// object 2
ClientHandlerInterface *handler2Iface = new ClientHandlerInterface(bus,
mClientObject2BusName, mClientObject2Path, this);
- MyHandler *handler2 = dynamic_cast<MyHandler*>(mClientObject2->client().data());
+ MyHandler *handler2 = dynamic_cast<MyHandler*>(mClientObject2.data());
connect(handler2,
SIGNAL(handleChannelsFinished()),
SLOT(expectSignalEmission()));
--
1.5.6.5
More information about the telepathy-commits
mailing list