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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 
26 namespace {
27 QAtomicInt s_connectionCounter;
28 
29 class DBusConnectionPoolPrivate
30 {
31 public:
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 { return m_connection; }
43 
44 private:
45  static int newNumber() {
46  return s_connectionCounter.fetchAndAddAcquire( 1 );
47  }
48  QDBusConnection m_connection;
49 };
50 }
51 
52 QThreadStorage<DBusConnectionPoolPrivate *> s_perThreadConnection;
53 
54 QDBusConnection Akonadi::DBusConnectionPool::threadConnection()
55 {
56  if ( !QCoreApplication::instance() || QCoreApplication::instance()->thread() == QThread::currentThread() ) {
57  return QDBusConnection::sessionBus(); // main thread, use the default session bus, breaks unported resources otherwise
58  }
59  if ( !s_perThreadConnection.hasLocalData() ) {
60  s_perThreadConnection.setLocalData( new DBusConnectionPoolPrivate );
61  }
62  return s_perThreadConnection.localData()->connection();
63 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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