Verified Commit 5b8d7d4a authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Remove DBusConnectionPool

DBusConnectionPool was a local copy of the deprecated KDBusConnectionPool,
which is no longer needed since a long time.
parent c22bf908
......@@ -25,7 +25,7 @@
#include <akonadi/servermanager.h>
#include <akonadi/session_p.h>
#include <QDBusInterface>
#include <dbusconnectionpool.h>
#include <QDbusConnection>
#include <QStringList>
#define EXEC(job) \
......@@ -44,7 +44,7 @@ VirtualResource::VirtualResource(const QString &name, QObject *parent)
// QDBusInterface *interface = new QDBusInterface(ServerManager::serviceName(ServerManager::Control),
// QString::fromLatin1("/"),
// QString::fromLatin1("org.freedesktop.Akonadi.AgentManager"),
// DBusConnectionPool::threadConnection(), this);
// QDBusConnection::sessionBus(), this);
// if (interface->isValid()) {
// const QDBusMessage reply = interface->call(QString::fromUtf8("createAgentInstance"), name, QStringList());
// if (reply.type() == QDBusMessage::ErrorMessage) {
......
......@@ -46,7 +46,6 @@ set(libakonadiserver_SRCS
commandcontext.cpp
connection.cpp
collectionscheduler.cpp
dbusconnectionpool.cpp
handler.cpp
handlerhelper.cpp
intervalcheck.cpp
......
/*
* Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "dbusconnectionpool.h"
#include <QCoreApplication>
#include <QThread>
#include <QThreadStorage>
namespace
{
QAtomicInt s_connectionCounter;
class DBusConnectionPoolPrivate
{
public:
DBusConnectionPoolPrivate()
: m_connection(QDBusConnection::connectToBus(
QDBusConnection::SessionBus,
QStringLiteral("AkonadiServer-%1").arg(newNumber())))
{
}
~DBusConnectionPoolPrivate()
{
QDBusConnection::disconnectFromBus(m_connection.name());
}
QDBusConnection connection() const
{
return m_connection;
}
private:
static int newNumber()
{
return s_connectionCounter.fetchAndAddAcquire(1);
}
QDBusConnection m_connection;
};
}
QThreadStorage<DBusConnectionPoolPrivate *> s_perThreadConnection;
QDBusConnection Akonadi::Server::DBusConnectionPool::threadConnection()
{
if (!QCoreApplication::instance() || QCoreApplication::instance()->thread() == QThread::currentThread()) {
return QDBusConnection::sessionBus(); // main thread, use the default session bus
}
if (!s_perThreadConnection.hasLocalData()) {
s_perThreadConnection.setLocalData(new DBusConnectionPoolPrivate);
}
return s_perThreadConnection.localData()->connection();
}
/*
* Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef DBUSCONNECTIONPOOL_H
#define DBUSCONNECTIONPOOL_H
#include <QDBusConnection>
namespace Akonadi
{
namespace Server
{
namespace DBusConnectionPool
{
/**
* Returns a new QDBusConnection for each thread, because QDBusConnection is
* not thread-safe in Qt 4.
*
* FIXME: Remove in KF5
*/
QDBusConnection threadConnection();
}
}
}
#endif
......@@ -36,7 +36,6 @@
#include "utils.h"
#include "intervalcheck.h"
#include "agentmanagerinterface.h"
#include "dbusconnectionpool.h"
#include "tagfetchhelper.h"
#include "relationfetchhandler.h"
#include "akonadiserver_debug.h"
......@@ -318,7 +317,7 @@ bool ItemFetchHelper::isScopeLocal(const Scope &scope)
org::freedesktop::Akonadi::AgentManager manager(DBus::serviceName(DBus::Control),
QStringLiteral("/AgentManager"),
DBusConnectionPool::threadConnection());
QDBusConnection::sessionBus());
const QString typeIdentifier = manager.agentInstanceType(resourceName);
const QVariantMap properties = manager.agentCustomProperties(typeIdentifier);
return properties.value(QStringLiteral("HasLocalStorage"), false).toBool();
......
......@@ -20,7 +20,6 @@
#include "agentsearchinstance.h"
#include "agentsearchinterface.h"
#include "searchtaskmanager.h"
#include "dbusconnectionpool.h"
#include <private/dbus_p.h>
......@@ -46,7 +45,7 @@ bool AgentSearchInstance::init()
mInterface = new OrgFreedesktopAkonadiAgentSearchInterface(
DBus::agentServiceName(mId, DBus::Agent),
QStringLiteral("/Search"),
DBusConnectionPool::threadConnection());
QDBusConnection::sessionBus());
if (!mInterface || !mInterface->isValid()) {
delete mInterface;
......@@ -55,7 +54,7 @@ bool AgentSearchInstance::init()
}
mServiceWatcher = std::make_unique<QDBusServiceWatcher>(
DBus::agentServiceName(mId, DBus::Agent), DBusConnectionPool::threadConnection(),
DBus::agentServiceName(mId, DBus::Agent), QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForUnregistration);
connect(mServiceWatcher.get(), &QDBusServiceWatcher::serviceUnregistered,
this, [this]() {
......
......@@ -25,7 +25,6 @@
#include "akonadi.h"
#include "agentsearchengine.h"
#include "notificationmanager.h"
#include "dbusconnectionpool.h"
#include "searchrequest.h"
#include "searchtaskmanager.h"
#include "storage/datastore.h"
......@@ -98,7 +97,7 @@ void SearchManager::init()
void SearchManager::quit()
{
QDBusConnection conn = DBusConnectionPool::threadConnection();
QDBusConnection conn = QDBusConnection::sessionBus();
conn.unregisterObject(QStringLiteral("/SearchManager"), QDBusConnection::UnregisterTree);
conn.disconnectFromBus(conn.name());
......
......@@ -21,7 +21,6 @@
#include "agentsearchinstance.h"
#include "connection.h"
#include "storage/selectquerybuilder.h"
#include "dbusconnectionpool.h"
#include "entities.h"
#include "akonadiserver_search_debug.h"
......@@ -30,6 +29,7 @@
#include <QSqlError>
#include <QTimer>
#include <QTime>
#include <QDBusConnection>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QDeadlineTimer>
#endif
......@@ -120,7 +120,7 @@ void SearchTaskManager::addTask(SearchTask *task)
mInstancesLock.lock();
org::freedesktop::Akonadi::AgentManager agentManager(DBus::serviceName(DBus::Control), QStringLiteral("/AgentManager"),
DBusConnectionPool::threadConnection());
QDBusConnection::sessionBus());
do {
const QString resourceId = query.value(1).toString();
if (!mInstances.contains(resourceId)) {
......
......@@ -20,7 +20,6 @@
#include "itemretrievalmanager.h"
#include "itemretrievalrequest.h"
#include "itemretrievaljob.h"
#include "dbusconnectionpool.h"
#include "akonadiserver_debug.h"
#include "resourceinterface.h"
......@@ -64,7 +63,7 @@ void ItemRetrievalManager::init()
{
AkThread::init();
QDBusConnection conn = DBusConnectionPool::threadConnection();
QDBusConnection conn = QDBusConnection::sessionBus();
connect(conn.interface(), &QDBusConnectionInterface::serviceOwnerChanged,
this, &ItemRetrievalManager::serviceOwnerChanged);
connect(this, &ItemRetrievalManager::requestAdded,
......@@ -100,7 +99,7 @@ org::freedesktop::Akonadi::Resource *ItemRetrievalManager::resourceInterface(con
}
auto iface = std::make_unique<org::freedesktop::Akonadi::Resource>(
DBus::agentServiceName(id, DBus::Resource), QStringLiteral("/"), DBusConnectionPool::threadConnection());
DBus::agentServiceName(id, DBus::Resource), QStringLiteral("/"), QDBusConnection::sessionBus());
if (!iface->isValid()) {
qCCritical(AKONADISERVER_LOG, "Cannot connect to agent instance with identifier '%s', error message: '%s'",
qUtf8Printable(id), qUtf8Printable(iface ? iface->lastError().message() : QString()));
......
......@@ -30,7 +30,6 @@
#include "search/searchmanager.h"
#include "resourcemanager.h"
#include "entities.h"
#include "dbusconnectionpool.h"
#include "agentmanagerinterface.h"
#include "akonadiserver_debug.h"
......@@ -69,7 +68,7 @@ void StorageJanitor::init()
{
AkThread::init();
QDBusConnection conn = DBusConnectionPool::threadConnection();
QDBusConnection conn = QDBusConnection::sessionBus();
conn.registerService(DBus::serviceName(DBus::StorageJanitor));
conn.registerObject(QStringLiteral(AKONADI_DBUS_STORAGEJANITOR_PATH), this,
QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableSignals);
......@@ -77,7 +76,7 @@ void StorageJanitor::init()
void StorageJanitor::quit()
{
QDBusConnection conn = DBusConnectionPool::threadConnection();
QDBusConnection conn = QDBusConnection::sessionBus();
conn.unregisterObject(QStringLiteral(AKONADI_DBUS_STORAGEJANITOR_PATH), QDBusConnection::UnregisterTree);
conn.unregisterService(DBus::serviceName(DBus::StorageJanitor));
conn.disconnectFromBus(conn.name());
......@@ -779,7 +778,7 @@ void StorageJanitor::findOrphanSearchIndexEntries()
QDBusInterface iface(DBus::agentServiceName(QStringLiteral("akonadi_indexing_agent"), DBus::Agent),
QStringLiteral("/"),
QStringLiteral("org.freedesktop.Akonadi.Indexer"),
DBusConnectionPool::threadConnection());
QDBusConnection::sessionBus());
if (!iface.isValid()) {
inform("Akonadi Indexing Agent is not running, skipping test");
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment