Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | #include <QtCore/qglobal.h> | - |
35 | #ifndef QT_BOOTSTRAPPED | - |
36 | #include <QtCore/qlibrary.h> | - |
37 | #endif | - |
38 | #include <QtCore/qmutex.h> | - |
39 | | - |
40 | #ifndef QT_NO_DBUS | - |
41 | | - |
42 | extern "C" void dbus_shutdown(); | - |
43 | | - |
44 | QT_BEGIN_NAMESPACE | - |
45 | | - |
46 | void (*qdbus_resolve_me(const char *name))(); | - |
47 | | - |
48 | #if !defined QT_LINKED_LIBDBUS | - |
49 | | - |
50 | #ifndef QT_NO_LIBRARY | - |
51 | static QLibrary *qdbus_libdbus = 0; | - |
52 | | - |
53 | void qdbus_unloadLibDBus() | - |
54 | { | - |
55 | if (qdbus_libdbus) { | - |
56 | if (qEnvironmentVariableIsSet("QDBUS_FORCE_SHUTDOWN")) | - |
57 | qdbus_libdbus->resolve("dbus_shutdown")(); | - |
58 | qdbus_libdbus->unload(); | - |
59 | } | - |
60 | delete qdbus_libdbus; | - |
61 | qdbus_libdbus = 0; | - |
62 | } | - |
63 | #endif | - |
64 | | - |
65 | bool qdbus_loadLibDBus() | - |
66 | { | - |
67 | #ifndef QT_NO_LIBRARY | - |
68 | #ifdef QT_BUILD_INTERNAL | - |
69 | | - |
70 | if (!qEnvironmentVariableIsEmpty("QT_SIMULATE_DBUS_LIBFAIL")) | - |
71 | return false; | - |
72 | #endif | - |
73 | | - |
74 | static bool triedToLoadLibrary = false; | - |
75 | #ifndef QT_NO_THREAD | - |
76 | static QBasicMutex mutex; | - |
77 | QMutexLocker locker(&mutex); | - |
78 | #endif | - |
79 | | - |
80 | QLibrary *&lib = qdbus_libdbus; | - |
81 | if (triedToLoadLibrary) | - |
82 | return lib && lib->isLoaded(); | - |
83 | | - |
84 | lib = new QLibrary; | - |
85 | lib->setLoadHints(QLibrary::ExportExternalSymbolsHint); | - |
86 | triedToLoadLibrary = true; | - |
87 | | - |
88 | static int majorversions[] = { 3, 2, -1 }; | - |
89 | const QString baseNames[] = { | - |
90 | #ifdef Q_OS_WIN | - |
91 | QLatin1String("dbus-1"), | - |
92 | #endif | - |
93 | QLatin1String("libdbus-1") | - |
94 | }; | - |
95 | | - |
96 | lib->unload(); | - |
97 | for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) { | - |
98 | for (uint j = 0; j < sizeof(baseNames) / sizeof(baseNames[0]); ++j) { | - |
99 | #ifdef Q_OS_WIN | - |
100 | QString suffix; | - |
101 | if (majorversions[i] != -1) | - |
102 | suffix = QString::number(- majorversions[i]); | - |
103 | lib->setFileName(baseNames[j] + suffix); | - |
104 | #else | - |
105 | lib->setFileNameAndVersion(baseNames[j], majorversions[i]); | - |
106 | #endif | - |
107 | if (lib->load() && lib->resolve("dbus_connection_open_private")) | - |
108 | return true; | - |
109 | | - |
110 | lib->unload(); | - |
111 | } | - |
112 | } | - |
113 | | - |
114 | delete lib; | - |
115 | lib = 0; | - |
116 | return false; | - |
117 | #else | - |
118 | return true; | - |
119 | #endif | - |
120 | } | - |
121 | | - |
122 | #ifndef QT_NO_LIBRARY | - |
123 | void (*qdbus_resolve_conditionally(const char *name))() | - |
124 | { | - |
125 | if (qdbus_loadLibDBus()) | - |
126 | return qdbus_libdbus->resolve(name); | - |
127 | return 0; | - |
128 | } | - |
129 | #endif | - |
130 | | - |
131 | void (*qdbus_resolve_me(const char *name))() | - |
132 | { | - |
133 | #ifndef QT_NO_LIBRARY | - |
134 | if (!qdbus_loadLibDBus()) | - |
135 | qFatal("Cannot find libdbus-1 in your system to resolve symbol '%s'.", name); | - |
136 | | - |
137 | QFunctionPointer ptr = qdbus_libdbus->resolve(name); | - |
138 | if (!ptr) | - |
139 | qFatal("Cannot resolve '%s' in your libdbus-1.", name); | - |
140 | | - |
141 | return ptr; | - |
142 | #else | - |
143 | Q_UNUSED(name); | - |
144 | return 0; | - |
145 | #endif | - |
146 | } | - |
147 | | - |
148 | #else | - |
149 | static void qdbus_unloadLibDBus() | - |
150 | { | - |
151 | if (qEnvironmentVariableIsSet("QDBUS_FORCE_SHUTDOWN"))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
152 | dbus_shutdown(); never executed: dbus_shutdown(); | 0 |
153 | } never executed: end of block | 0 |
154 | | - |
155 | #endif // !QT_LINKED_LIBDBUS | - |
156 | | - |
157 | #if defined(QT_LINKED_LIBDBUS) || !defined(QT_NO_LIBRARY) | - |
158 | Q_DESTRUCTOR_FUNCTION(qdbus_unloadLibDBus) never executed: end of block | 0 |
159 | #endif | - |
160 | | - |
161 | QT_END_NAMESPACE | - |
162 | | - |
163 | #endif // QT_NO_DBUS | - |
| | |