• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
dbusconnectionpool.cpp
1/*
2 * Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
3 * Copyright (C) 2010 David Faure <faure@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "dbusconnectionpool.h"
22#include <QCoreApplication>
23#include <QThread>
24#include <QThreadStorage>
25
26namespace {
27QAtomicInt s_connectionCounter;
28
29class DBusConnectionPoolPrivate
30{
31public:
32 DBusConnectionPoolPrivate()
33 : m_connection(QDBusConnection::connectToBus(
34 QDBusConnection::SessionBus,
35 QString::fromLatin1("AkonadiKde%1").arg(newNumber())))
36 {
37 }
38 ~DBusConnectionPoolPrivate() {
39 QDBusConnection::disconnectFromBus(m_connection.name());
40 }
41
42 QDBusConnection connection() const {
43 return m_connection;
44 }
45
46private:
47 static int newNumber() {
48 return s_connectionCounter.fetchAndAddAcquire(1);
49 }
50 QDBusConnection m_connection;
51};
52}
53
54QThreadStorage<DBusConnectionPoolPrivate *> s_perThreadConnection;
55
56QDBusConnection Akonadi::DBusConnectionPool::threadConnection()
57{
58 if (!QCoreApplication::instance() || QCoreApplication::instance()->thread() == QThread::currentThread()) {
59 return QDBusConnection::sessionBus(); // main thread, use the default session bus, breaks unported resources otherwise
60 }
61 if (!s_perThreadConnection.hasLocalData()) {
62 s_perThreadConnection.setLocalData(new DBusConnectionPoolPrivate);
63 }
64 return s_perThreadConnection.localData()->connection();
65}
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal