1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDBus module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtCore/qglobal.h>
43 #ifndef QT_BOOTSTRAPPED
44 #include <QtCore/qlibrary.h>
46 #include <QtCore/qmutex.h>
47 #include <private/qmutexpool_p.h>
53 void (*qdbus_resolve_me(const char *name))();
55 #if !defined QT_LINKED_LIBDBUS
57 #ifndef QT_BOOTSTRAPPED
58 static QLibrary *qdbus_libdbus = 0;
60 void qdbus_unloadLibDBus()
67 bool qdbus_loadLibDBus()
69 #ifndef QT_BOOTSTRAPPED
70 #ifdef QT_BUILD_INTERNAL
71 // this is to simulate a library load failure for our autotest suite.
72 if (!qgetenv("QT_SIMULATE_DBUS_LIBFAIL").isEmpty())
76 static volatile bool triedToLoadLibrary = false;
78 QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&qdbus_resolve_me));
80 QLibrary *&lib = qdbus_libdbus;
81 if (triedToLoadLibrary)
82 return lib && lib->isLoaded();
85 triedToLoadLibrary = true;
87 static int majorversions[] = { 3, 2, -1 };
89 lib->setFileName(QLatin1String("dbus-1"));
90 for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) {
91 lib->setFileNameAndVersion(lib->fileName(), majorversions[i]);
92 if (lib->load() && lib->resolve("dbus_connection_open_private"))
106 #ifndef QT_BOOTSTRAPPED
107 void (*qdbus_resolve_conditionally(const char *name))()
109 if (qdbus_loadLibDBus())
110 return qdbus_libdbus->resolve(name);
115 void (*qdbus_resolve_me(const char *name))()
117 #ifndef QT_BOOTSTRAPPED
118 if (!qdbus_loadLibDBus())
119 qFatal("Cannot find libdbus-1 in your system to resolve symbol '%s'.", name);
121 QFunctionPointer ptr = qdbus_libdbus->resolve(name);
123 qFatal("Cannot resolve '%s' in your libdbus-1.", name);
132 #ifndef QT_BOOTSTRAPPED
133 Q_DESTRUCTOR_FUNCTION(qdbus_unloadLibDBus)
136 #endif // QT_LINKED_LIBDBUS