Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusintegrator.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | static dbus_int32_t server_slot = -1; | - | ||||||||||||||||||
10 | - | |||||||||||||||||||
11 | static QBasicAtomicInt isDebugging = { -1 }; | - | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | static inline QDebug operator<<(QDebug dbg, const QThread *th) | - | ||||||||||||||||||
15 | { | - | ||||||||||||||||||
16 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
17 | dbg.nospace() << "QThread(ptr=" << (const void*)th; | - | ||||||||||||||||||
18 | if (th && !th->objectName().isEmpty()) | - | ||||||||||||||||||
19 | dbg.nospace() << ", name=" << th->objectName(); | - | ||||||||||||||||||
20 | else if (th) | - | ||||||||||||||||||
21 | dbg.nospace() << ", name=" << th->metaObject()->className(); | - | ||||||||||||||||||
22 | dbg.nospace() << ')'; | - | ||||||||||||||||||
23 | return dbg; | - | ||||||||||||||||||
24 | } | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | - | |||||||||||||||||||
27 | static inline QDebug operator<<(QDebug dbg, const QDBusConnectionPrivate *conn) | - | ||||||||||||||||||
28 | { | - | ||||||||||||||||||
29 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
30 | dbg.nospace() << "QDBusConnection(" | - | ||||||||||||||||||
31 | << "ptr=" << (const void*)conn | - | ||||||||||||||||||
32 | << ", name=" << conn->name | - | ||||||||||||||||||
33 | << ", baseService=" << conn->baseService | - | ||||||||||||||||||
34 | << ')'; | - | ||||||||||||||||||
35 | return dbg; | - | ||||||||||||||||||
36 | } | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | void qdbusDefaultThreadDebug(int action, int condition, QDBusConnectionPrivate *conn) | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 106112, __PRETTY_FUNCTION__).debug() << QThread::currentThread() | - | ||||||||||||||||||
41 | << "Qt D-Bus threading action" << action | - | ||||||||||||||||||
42 | << (condition == QDBusLockerBase::BeforeLock ? "before lock" : | - | ||||||||||||||||||
43 | condition == QDBusLockerBase::AfterLock ? "after lock" : | - | ||||||||||||||||||
44 | condition == QDBusLockerBase::BeforeUnlock ? "before unlock" : | - | ||||||||||||||||||
45 | condition == QDBusLockerBase::AfterUnlock ? "after unlock" : | - | ||||||||||||||||||
46 | condition == QDBusLockerBase::BeforePost ? "before event posting" : | - | ||||||||||||||||||
47 | condition == QDBusLockerBase::AfterPost ? "after event posting" : | - | ||||||||||||||||||
48 | condition == QDBusLockerBase::BeforeDeliver ? "before event delivery" : | - | ||||||||||||||||||
49 | condition == QDBusLockerBase::AfterDeliver ? "after event delivery" : | - | ||||||||||||||||||
50 | condition == QDBusLockerBase::BeforeAcquire ? "before acquire" : | - | ||||||||||||||||||
51 | condition == QDBusLockerBase::AfterAcquire ? "after acquire" : | - | ||||||||||||||||||
52 | condition == QDBusLockerBase::BeforeRelease ? "before release" : | - | ||||||||||||||||||
53 | condition == QDBusLockerBase::AfterRelease ? "after release" : | - | ||||||||||||||||||
54 | "condition unknown") | - | ||||||||||||||||||
55 | << "in connection" << conn; | - | ||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | qdbusThreadDebugFunc qdbusThreadDebug = 0; | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | - | |||||||||||||||||||
60 | typedef QVarLengthArray<QDBusSpyCallEvent::Hook, 4> QDBusSpyHookList; | - | ||||||||||||||||||
61 | namespace { namespace Q_QGS_qDBusSpyHookList { typedef QDBusSpyHookList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QDBusSpyHookList, Q_QGS_qDBusSpyHookList::innerFunction, Q_QGS_qDBusSpyHookList::guard> qDBusSpyHookList; | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | extern "C" { | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | - | |||||||||||||||||||
66 | - | |||||||||||||||||||
67 | static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data) | - | ||||||||||||||||||
68 | { | - | ||||||||||||||||||
69 | ((!(timeout)) ? qt_assert("timeout",__FILE__,135141) : qt_noop()); | - | ||||||||||||||||||
70 | ((!(data)) ? qt_assert("data",__FILE__,136142) : qt_noop()); | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | - | |||||||||||||||||||
73 | - | |||||||||||||||||||
74 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
75 | ((!(QThread::currentThread() == d->thread())) ? qt_assert("QThread::currentThread() == d->thread()",__FILE__,141147) : qt_noop()); | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | - | |||||||||||||||||||
78 | if (__builtin_expect(!!(!q_dbus_timeout_get_enabled(timeout)), false)) | - | ||||||||||||||||||
79 | return false; | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | QDBusDispatchLocker locker(AddTimeoutAction, d); | - | ||||||||||||||||||
82 | ((!(d->timeouts.key(timeout, 0) == 0)) ? qt_assert("d->timeouts.key(timeout, 0) == 0",__FILE__,148154) : qt_noop()); | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | int timerId = d->startTimer(q_dbus_timeout_get_interval(timeout)); | - | ||||||||||||||||||
85 | ((!(timerId)) ? qt_assert_x("QDBusConnection", "Failed to start a timer",__FILE__,151157) : qt_noop()); | - | ||||||||||||||||||
86 | if (!timerId) | - | ||||||||||||||||||
87 | return false; | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | d->timeouts[timerId] = timeout; | - | ||||||||||||||||||
90 | return true; | - | ||||||||||||||||||
91 | } | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data) | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | ((!(timeout)) ? qt_assert("timeout",__FILE__,161167) : qt_noop()); | - | ||||||||||||||||||
96 | ((!(data)) ? qt_assert("data",__FILE__,162168) : qt_noop()); | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | - | |||||||||||||||||||
99 | - | |||||||||||||||||||
100 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
101 | ((!(QThread::currentThread() == d->thread())) ? qt_assert("QThread::currentThread() == d->thread()",__FILE__,167173) : qt_noop()); | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | QDBusDispatchLocker locker(RemoveTimeoutAction, d); | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | QDBusConnectionPrivate::TimeoutHash::iterator it = d->timeouts.begin(); | - | ||||||||||||||||||
106 | while (it != d->timeouts.end()) { | - | ||||||||||||||||||
107 | if (it.value() == timeout) { | - | ||||||||||||||||||
108 | d->killTimer(it.key()); | - | ||||||||||||||||||
109 | it = d->timeouts.erase(it); | - | ||||||||||||||||||
110 | break; | - | ||||||||||||||||||
111 | } else { | - | ||||||||||||||||||
112 | ++it; | - | ||||||||||||||||||
113 | } | - | ||||||||||||||||||
114 | } | - | ||||||||||||||||||
115 | } | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | static void qDBusToggleTimeout(DBusTimeout *timeout, void *data) | - | ||||||||||||||||||
118 | { | - | ||||||||||||||||||
119 | ((!(timeout)) ? qt_assert("timeout",__FILE__,185191) : qt_noop()); | - | ||||||||||||||||||
120 | ((!(data)) ? qt_assert("data",__FILE__,186192) : qt_noop()); | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | - | |||||||||||||||||||
123 | - | |||||||||||||||||||
124 | qDBusRemoveTimeout(timeout, data); | - | ||||||||||||||||||
125 | qDBusAddTimeout(timeout, data); | - | ||||||||||||||||||
126 | } | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data) | - | ||||||||||||||||||
129 | { | - | ||||||||||||||||||
130 | ((!(watch)) ? qt_assert("watch",__FILE__,196202) : qt_noop()); | - | ||||||||||||||||||
131 | ((!(data)) ? qt_assert("data",__FILE__,197203) : qt_noop()); | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
134 | ((!(QThread::currentThread() == d->thread())) ? qt_assert("QThread::currentThread() == d->thread()",__FILE__,200206) : qt_noop()); | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | int flags = q_dbus_watch_get_flags(watch); | - | ||||||||||||||||||
137 | int fd = q_dbus_watch_get_unix_fd(watch); | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | QDBusConnectionPrivate::Watcher watcher; | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | QDBusDispatchLocker locker(AddWatchAction, d); | - | ||||||||||||||||||
142 | if (flags & DBUS_WATCH_READABLE
| 637-657 | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | watcher.watch = watch; | - | ||||||||||||||||||
145 | watcher.read = new QSocketNotifier(fd, QSocketNotifier::Read, d); | - | ||||||||||||||||||
146 | watcher.read->setEnabled(q_dbus_watch_get_enabled(watch)); | - | ||||||||||||||||||
147 | d->connect(watcher.read, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "213"), qFlagLocation("1""socketRead(int)" "\0" __FILE__ ":" "213"));&QSocketNotifier::activated, d, &QDBusConnectionPrivate::socketRead); | - | ||||||||||||||||||
148 | } executed 657 times by 158 tests: end of block Executed by:
| 657 | ||||||||||||||||||
149 | if (flags & DBUS_WATCH_WRITABLE
| 637-657 | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | watcher.watch = watch; | - | ||||||||||||||||||
152 | watcher.write = new QSocketNotifier(fd, QSocketNotifier::Write, d); | - | ||||||||||||||||||
153 | watcher.write->setEnabled(q_dbus_watch_get_enabled(watch)); | - | ||||||||||||||||||
154 | d->connect(watcher.write, qFlagLocation("2""activated(int)" "\0" __FILE__ ":" "220"), qFlagLocation("1""socketWrite(int)" "\0" __FILE__ ":" "220"));&QSocketNotifier::activated, d, &QDBusConnectionPrivate::socketWrite); | - | ||||||||||||||||||
155 | } executed 637 times by 158 tests: end of block Executed by:
| 637 | ||||||||||||||||||
156 | d->watchers.insertMulti(fd, watcher); | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | return executed 1294 times by 158 tests: true;return true; Executed by:
executed 1294 times by 158 tests: return true; Executed by:
| 1294 | ||||||||||||||||||
159 | } | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | static void qDBusRemoveWatch(DBusWatch *watch, void *data) | - | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | ((!(watch)) ? qt_assert("watch",__FILE__,229235) : qt_noop()); | - | ||||||||||||||||||
164 | ((!(data)) ? qt_assert("data",__FILE__,230236) : qt_noop()); | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | - | |||||||||||||||||||
167 | - | |||||||||||||||||||
168 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
169 | ((!(QThread::currentThread() == d->thread())) ? qt_assert("QThread::currentThread() == d->thread()",__FILE__,235241) : qt_noop()); | - | ||||||||||||||||||
170 | int fd = q_dbus_watch_get_unix_fd(watch); | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | QDBusDispatchLocker locker(RemoveWatchAction, d); | - | ||||||||||||||||||
173 | QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd); | - | ||||||||||||||||||
174 | while (i != d->watchers.end() && i.key() == fd) { | - | ||||||||||||||||||
175 | if (i.value().watch == watch) { | - | ||||||||||||||||||
176 | delete i.value().read; | - | ||||||||||||||||||
177 | delete i.value().write; | - | ||||||||||||||||||
178 | i = d->watchers.erase(i); | - | ||||||||||||||||||
179 | } else { | - | ||||||||||||||||||
180 | ++i; | - | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | } | - | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | static void qDBusToggleWatch(DBusWatch *watch, void *data) | - | ||||||||||||||||||
186 | { | - | ||||||||||||||||||
187 | ((!(watch)) ? qt_assert("watch",__FILE__,253259) : qt_noop()); | - | ||||||||||||||||||
188 | ((!(data)) ? qt_assert("data",__FILE__,254260) : qt_noop()); | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
191 | ((!(QThread::currentThread() == d->thread())) ? qt_assert("QThread::currentThread() == d->thread()",__FILE__,257263) : qt_noop()); | - | ||||||||||||||||||
192 | int fd = q_dbus_watch_get_unix_fd(watch); | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | QDBusDispatchLocker locker(ToggleWatchAction, d); | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd); | - | ||||||||||||||||||
197 | while (i != d->watchers.end() && i.key() == fd) { | - | ||||||||||||||||||
198 | if (i.value().watch == watch) { | - | ||||||||||||||||||
199 | bool enabled = q_dbus_watch_get_enabled(watch); | - | ||||||||||||||||||
200 | int flags = q_dbus_watch_get_flags(watch); | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
203 | - | |||||||||||||||||||
204 | if (flags & DBUS_WATCH_READABLE && i.value().read) | - | ||||||||||||||||||
205 | i.value().read->setEnabled(enabled); | - | ||||||||||||||||||
206 | if (flags & DBUS_WATCH_WRITABLE && i.value().write) | - | ||||||||||||||||||
207 | i.value().write->setEnabled(enabled); | - | ||||||||||||||||||
208 | return; | - | ||||||||||||||||||
209 | } | - | ||||||||||||||||||
210 | ++i; | - | ||||||||||||||||||
211 | } | - | ||||||||||||||||||
212 | } | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchStatus new_status, void *data) | - | ||||||||||||||||||
215 | { | - | ||||||||||||||||||
216 | ((!(connection)) ? qt_assert("connection",__FILE__,282288) : qt_noop()); | - | ||||||||||||||||||
217 | (void)connection;; | - | ||||||||||||||||||
218 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
219 | if (new_status == DBUS_DISPATCH_DATA_REMAINS) | - | ||||||||||||||||||
220 | d->dispatchStatusChanged(); | - | ||||||||||||||||||
221 | } | - | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data) | - | ||||||||||||||||||
224 | { | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | ((!(server)) ? qt_assert("server",__FILE__,292298) : qt_noop()); (void)server;; | - | ||||||||||||||||||
227 | ((!(connection)) ? qt_assert("connection",__FILE__,293299) : qt_noop()); | - | ||||||||||||||||||
228 | ((!(data)) ? qt_assert("data",__FILE__,294300) : qt_noop()); | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | - | |||||||||||||||||||
231 | q_dbus_connection_ref(connection); | - | ||||||||||||||||||
232 | QDBusConnectionPrivate *serverConnection = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | - | |||||||||||||||||||
235 | if (serverConnection->anonymousAuthenticationAllowed) | - | ||||||||||||||||||
236 | q_dbus_connection_set_allow_anonymous(connection, true); | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent()); | - | ||||||||||||||||||
239 | QMutexLocker locker(&QDBusConnectionManager::instance()->mutex); | - | ||||||||||||||||||
240 | QDBusConnectionManager::instance()->setConnection(QLatin1String("QDBusServer-") + QString::number(reinterpret_cast<qulonglong>(newConnection), 16), newConnection); | - | ||||||||||||||||||
241 | serverConnection->serverConnectionNames << newConnection->name; | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | - | |||||||||||||||||||
244 | QDBusErrorInternal error; | - | ||||||||||||||||||
245 | newConnection->setPeer(connection, error); | - | ||||||||||||||||||
246 | newConnection->setDispatchEnabled(false); | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | - | |||||||||||||||||||
249 | serverConnection->newServerConnection(newConnection); | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | - | |||||||||||||||||||
255 | newConnection->ref.ref(); | - | ||||||||||||||||||
256 | QReadLocker serverLock(&serverConnection->lock); | - | ||||||||||||||||||
257 | QDBusConnectionDispatchEnabler *o = new QDBusConnectionDispatchEnabler(newConnection); | - | ||||||||||||||||||
258 | QTimer::singleShot(0, o, qFlagLocation("1""execute()" "\0" __FILE__ ":" "324""330")); | - | ||||||||||||||||||
259 | if (serverConnection->serverObject) | - | ||||||||||||||||||
260 | o->moveToThread(serverConnection->serverObject->thread()); | - | ||||||||||||||||||
261 | } | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | void QDBusConnectionPrivate::_q_newConnection(QDBusConnectionPrivate *newConnection) | - | ||||||||||||||||||
264 | { | - | ||||||||||||||||||
265 | ((!(mode == ServerMode)) ? qt_assert("mode == ServerMode",__FILE__,331337) : qt_noop()); | - | ||||||||||||||||||
266 | serverObject->newConnection(QDBusConnectionPrivate::q(newConnection)); | - | ||||||||||||||||||
267 | } | - | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | } | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | static QByteArray buildMatchRule(const QString &service, | - | ||||||||||||||||||
272 | const QString &objectPath, const QString &interface, | - | ||||||||||||||||||
273 | const QString &member, const QStringList &argMatch, const QString & ) | - | ||||||||||||||||||
274 | { | - | ||||||||||||||||||
275 | QString result = QLatin1String("type='signal',"); | - | ||||||||||||||||||
276 | QString keyValue = QLatin1String("%1='%2',"); | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | if (!service.isEmpty()) | - | ||||||||||||||||||
279 | result += keyValue.arg(QLatin1String("sender"), service); | - | ||||||||||||||||||
280 | if (!objectPath.isEmpty()) | - | ||||||||||||||||||
281 | result += keyValue.arg(QLatin1String("path"), objectPath); | - | ||||||||||||||||||
282 | if (!interface.isEmpty()) | - | ||||||||||||||||||
283 | result += keyValue.arg(QLatin1String("interface"), interface); | - | ||||||||||||||||||
284 | if (!member.isEmpty()) | - | ||||||||||||||||||
285 | result += keyValue.arg(QLatin1String("member"), member); | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | - | |||||||||||||||||||
288 | if (!argMatch.isEmpty()) { | - | ||||||||||||||||||
289 | keyValue = QLatin1String("arg%1='%2',"); | - | ||||||||||||||||||
290 | for (int i = 0; i < argMatch.count(); ++i) | - | ||||||||||||||||||
291 | if (!argMatch.at(i).isNull()) | - | ||||||||||||||||||
292 | result += keyValue.arg(i).arg(argMatch.at(i)); | - | ||||||||||||||||||
293 | } | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | result.chop(1); | - | ||||||||||||||||||
296 | return result.toLatin1(); | - | ||||||||||||||||||
297 | } | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root, | - | ||||||||||||||||||
300 | const QString &fullpath, int &usedLength, | - | ||||||||||||||||||
301 | QDBusConnectionPrivate::ObjectTreeNode &result) | - | ||||||||||||||||||
302 | { | - | ||||||||||||||||||
303 | if (!fullpath.compare(QLatin1String("/")) && root->obj) { | - | ||||||||||||||||||
304 | usedLength = 1; | - | ||||||||||||||||||
305 | result = *root; | - | ||||||||||||||||||
306 | return root; | - | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | int start = 0; | - | ||||||||||||||||||
309 | int length = fullpath.length(); | - | ||||||||||||||||||
310 | if (fullpath.at(0) == QLatin1Char('/')) | - | ||||||||||||||||||
311 | start = 1; | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | - | |||||||||||||||||||
314 | QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator node = root; | - | ||||||||||||||||||
315 | while (start < length && node) { | - | ||||||||||||||||||
316 | if (node->flags & QDBusConnection::ExportChildObjects) | - | ||||||||||||||||||
317 | break; | - | ||||||||||||||||||
318 | if ((node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath)) | - | ||||||||||||||||||
319 | break; | - | ||||||||||||||||||
320 | int end = fullpath.indexOf(QLatin1Char('/'), start); | - | ||||||||||||||||||
321 | end = (end == -1 ? length : end); | - | ||||||||||||||||||
322 | QStringRef pathComponent(&fullpath, start, end - start); | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = | - | ||||||||||||||||||
325 | std::lower_bound(node->children.constBegin(), node->children.constEnd(), pathComponent); | - | ||||||||||||||||||
326 | if (it != node->children.constEnd() && it->name == pathComponent) | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | node = it; | - | ||||||||||||||||||
329 | else | - | ||||||||||||||||||
330 | node = 0; | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | start = end + 1; | - | ||||||||||||||||||
333 | } | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | - | |||||||||||||||||||
336 | usedLength = (start > length ? length : start); | - | ||||||||||||||||||
337 | if (node) { | - | ||||||||||||||||||
338 | if (node->obj || !node->children.isEmpty()) | - | ||||||||||||||||||
339 | result = *node; | - | ||||||||||||||||||
340 | else | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | - | |||||||||||||||||||
343 | node = 0; | - | ||||||||||||||||||
344 | } | - | ||||||||||||||||||
345 | return node; | - | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *root, | - | ||||||||||||||||||
349 | const QString &fullpath, int start) | - | ||||||||||||||||||
350 | { | - | ||||||||||||||||||
351 | int length = fullpath.length(); | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | - | |||||||||||||||||||
354 | const QDBusConnectionPrivate::ObjectTreeNode *node = root; | - | ||||||||||||||||||
355 | if (node && node->flags & QDBusConnection::ExportChildObjects) { | - | ||||||||||||||||||
356 | QObject *obj = node->obj; | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | while (obj) { | - | ||||||||||||||||||
359 | if (start >= length) | - | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | return obj; | - | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | int pos = fullpath.indexOf(QLatin1Char('/'), start); | - | ||||||||||||||||||
364 | pos = (pos == -1 ? length : pos); | - | ||||||||||||||||||
365 | QStringRef pathComponent(&fullpath, start, pos - start); | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | const QObjectList children = obj->children(); | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | - | |||||||||||||||||||
370 | QObject *next = 0; | - | ||||||||||||||||||
371 | QObjectList::ConstIterator it = children.constBegin(); | - | ||||||||||||||||||
372 | QObjectList::ConstIterator end = children.constEnd(); | - | ||||||||||||||||||
373 | for ( ; it != end; ++it) | - | ||||||||||||||||||
374 | if ((*it)->objectName() == pathComponent) { | - | ||||||||||||||||||
375 | next = *it; | - | ||||||||||||||||||
376 | break; | - | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | if (!next) | - | ||||||||||||||||||
380 | break; | - | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | obj = next; | - | ||||||||||||||||||
383 | start = pos + 1; | - | ||||||||||||||||||
384 | } | - | ||||||||||||||||||
385 | } | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | - | |||||||||||||||||||
388 | return 0; | - | ||||||||||||||||||
389 | } | - | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | static QStringList matchArgsForService(const QString &service, QDBusServiceWatcher::WatchMode mode) | - | ||||||||||||||||||
392 | { | - | ||||||||||||||||||
393 | QStringList matchArgs; | - | ||||||||||||||||||
394 | matchArgs << service; | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | switch (mode) { | - | ||||||||||||||||||
397 | case QDBusServiceWatcher::WatchForOwnerChange: | - | ||||||||||||||||||
398 | break; | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | case QDBusServiceWatcher::WatchForRegistration: | - | ||||||||||||||||||
401 | matchArgs << QString::fromLatin1("", 0); | - | ||||||||||||||||||
402 | break; | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | case QDBusServiceWatcher::WatchForUnregistration: | - | ||||||||||||||||||
405 | matchArgs << QString() << QString::fromLatin1("", 0); | - | ||||||||||||||||||
406 | break; | - | ||||||||||||||||||
407 | } | - | ||||||||||||||||||
408 | return matchArgs; | - | ||||||||||||||||||
409 | } | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | - | |||||||||||||||||||
412 | extern __attribute__((visibility("default"))) void qDBusAddSpyHook(QDBusSpyCallEvent::Hook); | - | ||||||||||||||||||
413 | void qDBusAddSpyHook(QDBusSpyCallEvent::Hook hook) | - | ||||||||||||||||||
414 | { | - | ||||||||||||||||||
415 | qDBusSpyHookList()->append(hook); | - | ||||||||||||||||||
416 | } | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | QDBusSpyCallEvent::~QDBusSpyCallEvent() | - | ||||||||||||||||||
419 | { | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | - | |||||||||||||||||||
423 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(const_cast<QObject *>(sender())); | - | ||||||||||||||||||
424 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 490496, __PRETTY_FUNCTION__).debug() << d << "message spies done for" << msg; | - | ||||||||||||||||||
425 | d->spyHooksFinished(msg); | - | ||||||||||||||||||
426 | } | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | void QDBusSpyCallEvent::placeMetaCall(QObject *) | - | ||||||||||||||||||
429 | { | - | ||||||||||||||||||
430 | invokeSpyHooks(msg, hooks, hookCount); | - | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | inline void QDBusSpyCallEvent::invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount) | - | ||||||||||||||||||
434 | { | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | for (int i = 0; i < hookCount; ++i) | - | ||||||||||||||||||
437 | hooks[i](msg); | - | ||||||||||||||||||
438 | } | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | extern "C" { | - | ||||||||||||||||||
441 | static DBusHandlerResult | - | ||||||||||||||||||
442 | qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data) | - | ||||||||||||||||||
443 | { | - | ||||||||||||||||||
444 | ((!(data)) ? qt_assert("data",__FILE__,510516) : qt_noop()); | - | ||||||||||||||||||
445 | (void)connection;; | - | ||||||||||||||||||
446 | QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); | - | ||||||||||||||||||
447 | if (d->mode == QDBusConnectionPrivate::InvalidMode) | - | ||||||||||||||||||
448 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message, d->capabilities); | - | ||||||||||||||||||
451 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 517523, __PRETTY_FUNCTION__).debug() << d << "got message (signal):" << amsg; | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | return d->handleMessage(amsg) ? | - | ||||||||||||||||||
454 | DBUS_HANDLER_RESULT_HANDLED : | - | ||||||||||||||||||
455 | DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | - | ||||||||||||||||||
456 | } | - | ||||||||||||||||||
457 | } | - | ||||||||||||||||||
458 | - | |||||||||||||||||||
459 | bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) | - | ||||||||||||||||||
460 | { | - | ||||||||||||||||||
461 | if (!ref.load()) | - | ||||||||||||||||||
462 | return false; | - | ||||||||||||||||||
463 | - | |||||||||||||||||||
464 | - | |||||||||||||||||||
465 | - | |||||||||||||||||||
466 | bool isLocal = QDBusMessagePrivate::isLocal(amsg); | - | ||||||||||||||||||
467 | - | |||||||||||||||||||
468 | if (!dispatchEnabled && !isLocal) { | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 536542, __PRETTY_FUNCTION__).debug() << this << "delivery is suspended"; | - | ||||||||||||||||||
471 | pendingMessages << amsg; | - | ||||||||||||||||||
472 | return amsg.type() == QDBusMessage::MethodCallMessage; | - | ||||||||||||||||||
473 | } | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | switch (amsg.type()) { | - | ||||||||||||||||||
476 | case QDBusMessage::SignalMessage: | - | ||||||||||||||||||
477 | handleSignal(amsg); | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | - | |||||||||||||||||||
480 | return false; | - | ||||||||||||||||||
481 | case QDBusMessage::MethodCallMessage: | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | - | |||||||||||||||||||
484 | - | |||||||||||||||||||
485 | if (__builtin_expect(!!(qDBusSpyHookList.exists()), false) && QCoreApplication::instance()) { | - | ||||||||||||||||||
486 | const QDBusSpyHookList &list = *qDBusSpyHookList; | - | ||||||||||||||||||
487 | if (isLocal) { | - | ||||||||||||||||||
488 | ((!(QThread::currentThread() != thread())) ? qt_assert("QThread::currentThread() != thread()",__FILE__,554560) : qt_noop()); | - | ||||||||||||||||||
489 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 555561, __PRETTY_FUNCTION__).debug() << this << "invoking message spies directly"; | - | ||||||||||||||||||
490 | QDBusSpyCallEvent::invokeSpyHooks(amsg, list.constData(), list.size()); | - | ||||||||||||||||||
491 | } else { | - | ||||||||||||||||||
492 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 558564, __PRETTY_FUNCTION__).debug() << this << "invoking message spies via event"; | - | ||||||||||||||||||
493 | QCoreApplication::postEvent(QCoreApplication::instance(), new QDBusSpyCallEvent(this, QDBusConnection(this), | - | ||||||||||||||||||
494 | amsg, list.constData(), list.size())); | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | - | |||||||||||||||||||
497 | return true; | - | ||||||||||||||||||
498 | } | - | ||||||||||||||||||
499 | } | - | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | handleObjectCall(amsg); | - | ||||||||||||||||||
502 | return true; | - | ||||||||||||||||||
503 | case QDBusMessage::ReplyMessage: | - | ||||||||||||||||||
504 | case QDBusMessage::ErrorMessage: | - | ||||||||||||||||||
505 | case QDBusMessage::InvalidMessage: | - | ||||||||||||||||||
506 | return false; | - | ||||||||||||||||||
507 | } | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | return false; | - | ||||||||||||||||||
510 | } | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack) | - | ||||||||||||||||||
513 | { | - | ||||||||||||||||||
514 | for (auto &node : haystack.children) | - | ||||||||||||||||||
515 | huntAndDestroy(needle, node); executed 352 times by 9 tests: huntAndDestroy(needle, node); Executed by:
| 352 | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | auto isInactive = [](QDBusConnectionPrivate::ObjectTreeNode ::DataList&node) { return executed 352 times by 9 tests: !node.isActive();return !node.isActive(); Executed by:
executed 352 times by 9 tests: };return !node.isActive(); Executed by:
| 352 | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | haystack.children.erase(std::Iterator it =remove_if(haystack.children.begin(); | - | ||||||||||||||||||
while (it !=(), haystack.children.end()) { | ||||||||||||||||||||
huntAndDestroy(needle, *it); | ||||||||||||||||||||
if (!it->isActive()) | ||||||||||||||||||||
it =(), | ||||||||||||||||||||
520 | isInactive), | - | ||||||||||||||||||
521 | haystack.children.erase(it); | - | ||||||||||||||||||
else | ||||||||||||||||||||
it++; | ||||||||||||||||||||
}end()); | ||||||||||||||||||||
522 | - | |||||||||||||||||||
523 | if (needle == haystack.obj
| 342-1490 | ||||||||||||||||||
524 | haystack.obj = 0; | - | ||||||||||||||||||
525 | haystack.flags = 0; | - | ||||||||||||||||||
526 | } executed 342 times by 14 tests: end of block Executed by:
| 342 | ||||||||||||||||||
527 | } executed 1832 times by 178 tests: end of block Executed by:
| 1832 | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | static void huntAndUnregister(const QStringListQVector<QStringRef> &pathComponents, int i, QDBusConnection::UnregisterMode mode, | - | ||||||||||||||||||
530 | QDBusConnectionPrivate::ObjectTreeNode *node) | - | ||||||||||||||||||
531 | { | - | ||||||||||||||||||
532 | if (pathComponents.count() == i
| 48-108 | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | node->obj = 0; | - | ||||||||||||||||||
535 | node->flags = 0; | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | if (mode == QDBusConnection::UnregisterTree
| 5-43 | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | node->children.clear(); | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | } executed 5 times by 3 tests: end of block Executed by:
| 5 | ||||||||||||||||||
542 | } executed 48 times by 3 tests: else {end of block Executed by:
| 48 | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator end = node->children.end(); | - | ||||||||||||||||||
545 | QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = | - | ||||||||||||||||||
546 | std::lower_bound(node->children.begin(), end, pathComponents.at(i)); | - | ||||||||||||||||||
547 | if (it == end
| 5-93 | ||||||||||||||||||
548 | return; executed 20 times by 3 tests: return; Executed by:
| 20 | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | huntAndUnregister(pathComponents, i + 1, mode, it); | - | ||||||||||||||||||
551 | if (!it->isActive()
| 25-63 | ||||||||||||||||||
552 | node->children.erase(it); executed 63 times by 3 tests: node->children.erase(it); Executed by:
| 63 | ||||||||||||||||||
553 | } executed 88 times by 3 tests: end of block Executed by:
| 88 | ||||||||||||||||||
554 | } | - | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | static void huntAndEmit(DBusConnection *connection, DBusMessage *msg, | - | ||||||||||||||||||
557 | QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack, | - | ||||||||||||||||||
558 | bool isScriptable, bool isAdaptor, const QString &path = QString()) | - | ||||||||||||||||||
559 | { | - | ||||||||||||||||||
560 | QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = haystack.children.constBegin(); | - | ||||||||||||||||||
561 | QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end = haystack.children.constEnd(); | - | ||||||||||||||||||
562 | for ( ; it != end; ++it) { | - | ||||||||||||||||||
563 | if (it->isActive()) | - | ||||||||||||||||||
564 | huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + QLatin1Char('/') + it->name); | - | ||||||||||||||||||
565 | } | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | if (needle == haystack.obj) { | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | if (isAdaptor && (haystack.flags & QDBusConnection::ExportAdaptors) == 0) | - | ||||||||||||||||||
570 | return; | - | ||||||||||||||||||
571 | else if (!isAdaptor) { | - | ||||||||||||||||||
572 | int mask = isScriptable | - | ||||||||||||||||||
573 | ? QDBusConnection::ExportScriptableSignals | - | ||||||||||||||||||
574 | : QDBusConnection::ExportNonScriptableSignals; | - | ||||||||||||||||||
575 | if ((haystack.flags & mask) == 0) | - | ||||||||||||||||||
576 | return; | - | ||||||||||||||||||
577 | } | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | QByteArray p = path.toLatin1(); | - | ||||||||||||||||||
580 | if (p.isEmpty()) | - | ||||||||||||||||||
581 | p = "/"; | - | ||||||||||||||||||
582 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 649654, __PRETTY_FUNCTION__).debug() << QThread::currentThread() << "emitting signal at" << p; | - | ||||||||||||||||||
583 | DBusMessage *msg2 = q_dbus_message_copy(msg); | - | ||||||||||||||||||
584 | q_dbus_message_set_path(msg2, p); | - | ||||||||||||||||||
585 | q_dbus_connection_send(connection, msg2, 0); | - | ||||||||||||||||||
586 | q_dbus_message_unref(msg2); | - | ||||||||||||||||||
587 | } | - | ||||||||||||||||||
588 | } | - | ||||||||||||||||||
589 | - | |||||||||||||||||||
590 | static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, | - | ||||||||||||||||||
591 | const QString &signature_, QVector<int> &metaTypes) | - | ||||||||||||||||||
592 | { | - | ||||||||||||||||||
593 | QByteArray msgSignature = signature_.toLatin1(); | - | ||||||||||||||||||
594 | - | |||||||||||||||||||
595 | for (int idx = mo->methodCount() - 1 ; idx >= QObject::staticMetaObject.methodCount(); --idx) { | - | ||||||||||||||||||
596 | QMetaMethod mm = mo->method(idx); | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | - | |||||||||||||||||||
599 | if (mm.access() != QMetaMethod::Public) | - | ||||||||||||||||||
600 | continue; | - | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | - | |||||||||||||||||||
603 | if (mm.methodType() != QMetaMethod::Slot && mm.methodType() != QMetaMethod::Method) | - | ||||||||||||||||||
604 | continue; | - | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | - | |||||||||||||||||||
607 | if (mm.name() != name) | - | ||||||||||||||||||
608 | continue; | - | ||||||||||||||||||
609 | - | |||||||||||||||||||
610 | int returnType = mm.returnType(); | - | ||||||||||||||||||
611 | bool isAsync = qDBusCheckAsyncTag(mm.tag()); | - | ||||||||||||||||||
612 | bool isScriptable = mm.attributes() & QMetaMethod::Scriptable; | - | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | - | |||||||||||||||||||
615 | if (isAsync && returnType != QMetaType::Void) | - | ||||||||||||||||||
616 | continue; | - | ||||||||||||||||||
617 | - | |||||||||||||||||||
618 | QString errorMsg; | - | ||||||||||||||||||
619 | int inputCount = qDBusParametersForMethod(mm, metaTypes, errorMsg); | - | ||||||||||||||||||
620 | if (inputCount == -1) | - | ||||||||||||||||||
621 | continue; | - | ||||||||||||||||||
622 | - | |||||||||||||||||||
623 | metaTypes[0] = returnType; | - | ||||||||||||||||||
624 | bool hasMessage = false; | - | ||||||||||||||||||
625 | if (inputCount > 0 && | - | ||||||||||||||||||
626 | metaTypes.at(inputCount) == QDBusMetaTypeId::message()) { | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | hasMessage = true; | - | ||||||||||||||||||
629 | --inputCount; | - | ||||||||||||||||||
630 | } | - | ||||||||||||||||||
631 | - | |||||||||||||||||||
632 | - | |||||||||||||||||||
633 | int i; | - | ||||||||||||||||||
634 | QByteArray reconstructedSignature; | - | ||||||||||||||||||
635 | for (i = 1; i <= inputCount; ++i) { | - | ||||||||||||||||||
636 | const char *typeSignature = QDBusMetaType::typeToSignature( metaTypes.at(i) ); | - | ||||||||||||||||||
637 | if (!typeSignature) | - | ||||||||||||||||||
638 | break; | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | reconstructedSignature += typeSignature; | - | ||||||||||||||||||
641 | if (!msgSignature.startsWith(reconstructedSignature)) | - | ||||||||||||||||||
642 | break; | - | ||||||||||||||||||
643 | } | - | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | if (reconstructedSignature != msgSignature) | - | ||||||||||||||||||
646 | continue; | - | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | if (hasMessage) | - | ||||||||||||||||||
649 | ++i; | - | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | - | |||||||||||||||||||
652 | if (returnType != QMetaType::UnknownType && returnType != QMetaType::Void && QDBusMetaType::typeToSignature(returnType) == 0) | - | ||||||||||||||||||
653 | continue; | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | bool ok = true; | - | ||||||||||||||||||
656 | for (int j = i; ok && j < metaTypes.count(); ++j) | - | ||||||||||||||||||
657 | if (QDBusMetaType::typeToSignature(metaTypes.at(i)) == 0) | - | ||||||||||||||||||
658 | ok = false; | - | ||||||||||||||||||
659 | if (!ok) | - | ||||||||||||||||||
660 | continue; | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | - | |||||||||||||||||||
663 | if (isAsync && metaTypes.count() > i + 1) | - | ||||||||||||||||||
664 | continue; | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | if (mm.methodType() == QMetaMethod::Slot) { | - | ||||||||||||||||||
667 | if (isScriptable && (flags & QDBusConnection::ExportScriptableSlots) == 0) | - | ||||||||||||||||||
668 | continue; | - | ||||||||||||||||||
669 | if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableSlots) == 0) | - | ||||||||||||||||||
670 | continue; | - | ||||||||||||||||||
671 | } else { | - | ||||||||||||||||||
672 | if (isScriptable && (flags & QDBusConnection::ExportScriptableInvokables) == 0) | - | ||||||||||||||||||
673 | continue; | - | ||||||||||||||||||
674 | if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableInvokables) == 0) | - | ||||||||||||||||||
675 | continue; | - | ||||||||||||||||||
676 | } | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | - | |||||||||||||||||||
679 | return idx; | - | ||||||||||||||||||
680 | } | - | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | - | |||||||||||||||||||
683 | return -1; | - | ||||||||||||||||||
684 | } | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | - | |||||||||||||||||||
687 | - | |||||||||||||||||||
688 | - | |||||||||||||||||||
689 | - | |||||||||||||||||||
690 | - | |||||||||||||||||||
691 | - | |||||||||||||||||||
692 | void QDBusConnectionPrivate::setDispatchEnabled(bool enable) | - | ||||||||||||||||||
693 | { | - | ||||||||||||||||||
694 | QDBusDispatchLocker locker(SetDispatchEnabledAction, this); | - | ||||||||||||||||||
695 | dispatchEnabled = enable; | - | ||||||||||||||||||
696 | if (enable) | - | ||||||||||||||||||
697 | dispatchStatusChanged(); | - | ||||||||||||||||||
698 | } | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1; | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target, | - | ||||||||||||||||||
703 | QObject *object, int idx, | - | ||||||||||||||||||
704 | const QVector<int> &metaTypes, | - | ||||||||||||||||||
705 | const QDBusMessage &msg) | - | ||||||||||||||||||
706 | { | - | ||||||||||||||||||
707 | ((!(object)) ? qt_assert("object",__FILE__,774779) : qt_noop()); | - | ||||||||||||||||||
708 | (void)object;; | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | int n = metaTypes.count() - 1; | - | ||||||||||||||||||
711 | if (metaTypes[n] == QDBusMetaTypeId::message()) | - | ||||||||||||||||||
712 | --n; | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | if (msg.arguments().count() < n) | - | ||||||||||||||||||
715 | return 0; | - | ||||||||||||||||||
716 | - | |||||||||||||||||||
717 | - | |||||||||||||||||||
718 | for (int i = 0; i < n; ++i) | - | ||||||||||||||||||
719 | if (metaTypes.at(i + 1) != msg.arguments().at(i).userType() && | - | ||||||||||||||||||
720 | msg.arguments().at(i).userType() != qMetaTypeId<QDBusArgument>()) | - | ||||||||||||||||||
721 | return 0; | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | - | |||||||||||||||||||
724 | - | |||||||||||||||||||
725 | if (target == object) | - | ||||||||||||||||||
726 | return DIRECT_DELIVERY; | - | ||||||||||||||||||
727 | return new QDBusCallDeliveryEvent(QDBusConnection(target), idx, target, msg, metaTypes); | - | ||||||||||||||||||
728 | } | - | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | void QDBusConnectionPrivate::activateSignal(const QDBusConnectionPrivate::SignalHook& hook, | - | ||||||||||||||||||
731 | const QDBusMessage &msg) | - | ||||||||||||||||||
732 | { | - | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | - | |||||||||||||||||||
735 | - | |||||||||||||||||||
736 | - | |||||||||||||||||||
737 | - | |||||||||||||||||||
738 | - | |||||||||||||||||||
739 | - | |||||||||||||||||||
740 | QDBusCallDeliveryEvent *call = prepareReply(this, hook.obj, hook.midx, hook.params, msg); | - | ||||||||||||||||||
741 | if (call == DIRECT_DELIVERY) { | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | ((!(this == hook.obj)) ? qt_assert("this == hook.obj",__FILE__,810815) : qt_noop()); | - | ||||||||||||||||||
744 | deliverCall(this, 0, msg, hook.params, hook.midx); | - | ||||||||||||||||||
745 | return; | - | ||||||||||||||||||
746 | } | - | ||||||||||||||||||
747 | if (call) | - | ||||||||||||||||||
748 | postEventToThread(ActivateSignalAction, hook.obj, call); | - | ||||||||||||||||||
749 | } | - | ||||||||||||||||||
750 | - | |||||||||||||||||||
751 | bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBusMessage &msg) | - | ||||||||||||||||||
752 | { | - | ||||||||||||||||||
753 | static const char cachePropertyName[] = "_qdbus_slotCache"; | - | ||||||||||||||||||
754 | - | |||||||||||||||||||
755 | if (!object) | - | ||||||||||||||||||
756 | return false; | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | ((!(QThread::currentThread() == object->thread())) ? qt_assert_x("QDBusConnection: internal threading error", "function called for an object that is in another thread!!", | - | ||||||||||||||||||
759 | - | |||||||||||||||||||
760 | __FILE__ | - | ||||||||||||||||||
761 | , | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | 847852 | - | ||||||||||||||||||
764 | ) : qt_noop()) | - | ||||||||||||||||||
765 | - | |||||||||||||||||||
766 | ; | - | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | QDBusSlotCache slotCache = | - | ||||||||||||||||||
769 | qvariant_cast<QDBusSlotCache>(object->property(cachePropertyName)); | - | ||||||||||||||||||
770 | QString cacheKey = msg.member(), signature = msg.signature(); | - | ||||||||||||||||||
771 | if (!signature.isEmpty()) { | - | ||||||||||||||||||
772 | cacheKey.reserve(cacheKey.length() + 1 + signature.length()); | - | ||||||||||||||||||
773 | cacheKey += QLatin1Char('.'); | - | ||||||||||||||||||
774 | cacheKey += signature; | - | ||||||||||||||||||
775 | } | - | ||||||||||||||||||
776 | - | |||||||||||||||||||
777 | QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(cacheKey); | - | ||||||||||||||||||
778 | while (cacheIt != slotCache.hash.constEnd() && cacheIt->flags != flags && | - | ||||||||||||||||||
779 | cacheIt.key() == cacheKey) | - | ||||||||||||||||||
780 | ++cacheIt; | - | ||||||||||||||||||
781 | if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey) | - | ||||||||||||||||||
782 | { | - | ||||||||||||||||||
783 | - | |||||||||||||||||||
784 | const QMetaObject *mo = object->metaObject(); | - | ||||||||||||||||||
785 | QByteArray memberName = msg.member().toUtf8(); | - | ||||||||||||||||||
786 | - | |||||||||||||||||||
787 | - | |||||||||||||||||||
788 | QDBusSlotCache::Data slotData; | - | ||||||||||||||||||
789 | slotData.flags = flags; | - | ||||||||||||||||||
790 | slotData.slotIdx = ::findSlot(mo, memberName, flags, msg.signature(), slotData.metaTypes); | - | ||||||||||||||||||
791 | if (slotData.slotIdx == -1) { | - | ||||||||||||||||||
792 | - | |||||||||||||||||||
793 | - | |||||||||||||||||||
794 | slotData.slotIdx = ::findSlot(mo, memberName, flags, QString(), slotData.metaTypes); | - | ||||||||||||||||||
795 | if (slotData.metaTypes.count() != 2 || | - | ||||||||||||||||||
796 | slotData.metaTypes.at(1) != QDBusMetaTypeId::message()) { | - | ||||||||||||||||||
797 | - | |||||||||||||||||||
798 | - | |||||||||||||||||||
799 | slotData.slotIdx = -1; | - | ||||||||||||||||||
800 | slotData.metaTypes.clear(); | - | ||||||||||||||||||
801 | slotCache.hash.insert(cacheKey, slotData); | - | ||||||||||||||||||
802 | object->setProperty(cachePropertyName, QVariant::fromValue(slotCache)); | - | ||||||||||||||||||
803 | return false; | - | ||||||||||||||||||
804 | } | - | ||||||||||||||||||
805 | } | - | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | - | |||||||||||||||||||
808 | slotCache.hash.insert(cacheKey, slotData); | - | ||||||||||||||||||
809 | object->setProperty(cachePropertyName, QVariant::fromValue(slotCache)); | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | - | |||||||||||||||||||
812 | deliverCall(object, flags, msg, slotData.metaTypes, slotData.slotIdx); | - | ||||||||||||||||||
813 | return true; | - | ||||||||||||||||||
814 | } else if (cacheIt->slotIdx == -1) { | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | return false; | - | ||||||||||||||||||
817 | } else { | - | ||||||||||||||||||
818 | - | |||||||||||||||||||
819 | deliverCall(object, flags, msg, cacheIt->metaTypes, cacheIt->slotIdx); | - | ||||||||||||||||||
820 | return true; | - | ||||||||||||||||||
821 | } | - | ||||||||||||||||||
822 | return dead code: false;return false; dead code: return false; | - | ||||||||||||||||||
823 | } | - | ||||||||||||||||||
824 | - | |||||||||||||||||||
825 | void QDBusConnectionPrivate::deliverCall(QObject *object, int , const QDBusMessage &msg, | - | ||||||||||||||||||
826 | const QVector<int> &metaTypes, int slotIdx) | - | ||||||||||||||||||
827 | { | - | ||||||||||||||||||
828 | ((!(!object || QThread::currentThread() == object->thread())) ? qt_assert_x("QDBusConnection: internal threading error", "function called for an object that is in another thread!!", | - | ||||||||||||||||||
829 | - | |||||||||||||||||||
830 | __FILE__ | - | ||||||||||||||||||
831 | , | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | 911916 | - | ||||||||||||||||||
834 | ) : qt_noop()) | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | ; | - | ||||||||||||||||||
837 | - | |||||||||||||||||||
838 | QVarLengthArray<void *, 10> params; | - | ||||||||||||||||||
839 | params.reserve(metaTypes.count()); | - | ||||||||||||||||||
840 | - | |||||||||||||||||||
841 | QVariantList auxParameters; | - | ||||||||||||||||||
842 | - | |||||||||||||||||||
843 | - | |||||||||||||||||||
844 | - | |||||||||||||||||||
845 | params.append(0); | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | - | |||||||||||||||||||
848 | int i; | - | ||||||||||||||||||
849 | int pCount = qMin(msg.arguments().count(), metaTypes.count() - 1); | - | ||||||||||||||||||
850 | for (i = 1; i <= pCount
| 1298-1513 | ||||||||||||||||||
851 | int id = metaTypes[i]; | - | ||||||||||||||||||
852 | if (id == QDBusMetaTypeId::message()
| 406-892 | ||||||||||||||||||
853 | break; executed 406 times by 5 tests: break; Executed by:
| 406 | ||||||||||||||||||
854 | - | |||||||||||||||||||
855 | const QVariant &arg = msg.arguments().at(i - 1); | - | ||||||||||||||||||
856 | if (arg.userType() == id
| 18-874 | ||||||||||||||||||
857 | - | |||||||||||||||||||
858 | params.append(const_cast<void *>(arg.constData())); executed 874 times by 156 tests: params.append(const_cast<void *>(arg.constData())); Executed by:
| 874 | ||||||||||||||||||
859 | else if (arg.userType() == qMetaTypeId<QDBusArgument>()
| 0-18 | ||||||||||||||||||
860 | - | |||||||||||||||||||
861 | void *null = 0; | - | ||||||||||||||||||
862 | auxParameters.append(QVariant(id, null)); | - | ||||||||||||||||||
863 | - | |||||||||||||||||||
864 | const QDBusArgument &in = | - | ||||||||||||||||||
865 | *reinterpret_cast<const QDBusArgument *>(arg.constData()); | - | ||||||||||||||||||
866 | QVariant &out = auxParameters[auxParameters.count() - 1]; | - | ||||||||||||||||||
867 | - | |||||||||||||||||||
868 | if (!(__builtin_expect(!!(!
| 0-18 | ||||||||||||||||||
869 | QMessageLogger(__FILE__, 944949, __PRETTY_FUNCTION__).fatal("Internal error: demarshalling function for type '%s' (%d) failed!", never executed: QMessageLogger(__FILE__, 949, __PRETTY_FUNCTION__).fatal("Internal error: demarshalling function for type '%s' (%d) failed!", out.typeName(), out.userType()); | 0 | ||||||||||||||||||
870 | out.typeName(), out.userType()); never executed: QMessageLogger(__FILE__, 949, __PRETTY_FUNCTION__).fatal("Internal error: demarshalling function for type '%s' (%d) failed!", out.typeName(), out.userType()); | 0 | ||||||||||||||||||
871 | - | |||||||||||||||||||
872 | params.append(const_cast<void *>(out.constData())); | - | ||||||||||||||||||
873 | } executed 18 times by 4 tests: else {end of block Executed by:
| 18 | ||||||||||||||||||
874 | QMessageLogger(__FILE__, 949954, __PRETTY_FUNCTION__).fatal("Internal error: got invalid meta type %d (%s) " | - | ||||||||||||||||||
875 | "when trying to convert to meta type %d (%s)", | - | ||||||||||||||||||
876 | arg.userType(), QMetaType::typeName(arg.userType()), | - | ||||||||||||||||||
877 | id, QMetaType::typeName(id)); | - | ||||||||||||||||||
878 | } never executed: end of block | 0 | ||||||||||||||||||
879 | } | - | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | if (metaTypes.count() > i
| 9-1324 | ||||||||||||||||||
882 | params.append(const_cast<void*>(static_cast<const void*>(&msg))); | - | ||||||||||||||||||
883 | ++i; | - | ||||||||||||||||||
884 | } executed 586 times by 9 tests: end of block Executed by:
| 586 | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | - | |||||||||||||||||||
887 | const int numMetaTypes = metaTypes.count(); | - | ||||||||||||||||||
888 | QVariantList outputArgs; | - | ||||||||||||||||||
889 | void *null = 0; | - | ||||||||||||||||||
890 | if (metaTypes[0] != QMetaType::Void
| 170-1559 | ||||||||||||||||||
891 | outputArgs.reserve(numMetaTypes - i + 1); | - | ||||||||||||||||||
892 | QVariant arg(metaTypes[0], null); | - | ||||||||||||||||||
893 | outputArgs.append( arg ); | - | ||||||||||||||||||
894 | params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()); | - | ||||||||||||||||||
895 | } executed 190 times by 12 tests: else {end of block Executed by:
| 190 | ||||||||||||||||||
896 | outputArgs.reserve(numMetaTypes - i); | - | ||||||||||||||||||
897 | } executed 1729 times by 158 tests: end of block Executed by:
| 1729 | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | for ( ; i < numMetaTypes
| 10-1919 | ||||||||||||||||||
900 | QVariant arg(metaTypes[i], null); | - | ||||||||||||||||||
901 | outputArgs.append( arg ); | - | ||||||||||||||||||
902 | params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData())); | - | ||||||||||||||||||
903 | } executed 10 times by 4 tests: end of block Executed by:
| 10 | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | - | |||||||||||||||||||
906 | bool fail; | - | ||||||||||||||||||
907 | if (!object
| 0-1919 | ||||||||||||||||||
908 | fail = true; | - | ||||||||||||||||||
909 | } never executed: else {end of block | 0 | ||||||||||||||||||
910 | - | |||||||||||||||||||
911 | QDBusContextPrivate context(QDBusConnection(this), msg); | - | ||||||||||||||||||
912 | QDBusContextPrivate *old = QDBusContextPrivate::set(object, &context); | - | ||||||||||||||||||
913 | - | |||||||||||||||||||
914 | QPointer<QObject> ptr = object; | - | ||||||||||||||||||
915 | fail = object->qt_metacall(QMetaObject::InvokeMetaMethod, | - | ||||||||||||||||||
916 | slotIdx, params.data()) >= 0; | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | if (!ptr.isNull()
| 0-1919 | ||||||||||||||||||
919 | QDBusContextPrivate::set(object, old); executed 1919 times by 159 tests: QDBusContextPrivate::set(object, old); Executed by:
| 1919 | ||||||||||||||||||
920 | } executed 1919 times by 159 tests: end of block Executed by:
| 1919 | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | - | |||||||||||||||||||
923 | - | |||||||||||||||||||
924 | if (msg.isReplyRequired()
| 424-1115 | ||||||||||||||||||
925 | if (!fail
| 0-691 | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | if (::
executed 691 times by 13 tests: else QMessageLogger(__FILE__, 10021007, __PRETTY_FUNCTION__).debug() << this << "Automatically sending reply:" << outputArgs;; Executed by:
never executed: QMessageLogger(__FILE__, 1007, __PRETTY_FUNCTION__).debug() << this << "Automatically sending reply:" << outputArgs; | 0-691 | ||||||||||||||||||
928 | send(msg.createReply(outputArgs)); | - | ||||||||||||||||||
929 | } executed 691 times by 13 tests: else {end of block Executed by:
| 691 | ||||||||||||||||||
930 | - | |||||||||||||||||||
931 | QMessageLogger(__FILE__, 10061011, __PRETTY_FUNCTION__).warning("Internal error: Failed to deliver message"); | - | ||||||||||||||||||
932 | send(msg.createErrorReply(QDBusError::InternalError, | - | ||||||||||||||||||
933 | QLatin1String("Failed to deliver message"))); | - | ||||||||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||||||||
935 | } | - | ||||||||||||||||||
936 | - | |||||||||||||||||||
937 | return; executed 1919 times by 159 tests: return; Executed by:
| 1919 | ||||||||||||||||||
938 | } | - | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | extern bool qDBusInitThreads(); | - | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) | - | ||||||||||||||||||
943 | : QObject(p), ref(1), capabilities(0), mode(InvalidMode), busService(0), | - | ||||||||||||||||||
944 | dispatchLock(QMutex::Recursive), connection(0), | - | ||||||||||||||||||
945 | rootNode(QString(QLatin1Char('/'))), | - | ||||||||||||||||||
946 | anonymousAuthenticationAllowed(false), | - | ||||||||||||||||||
947 | dispatchEnabled(true) | - | ||||||||||||||||||
948 | { | - | ||||||||||||||||||
949 | static const bool threads = q_dbus_threads_init_default(); | - | ||||||||||||||||||
950 | if (::isDebugging == -1) | - | ||||||||||||||||||
951 | ::isDebugging = qEnvironmentVariableIntValue("QDBUS_DEBUG"); | - | ||||||||||||||||||
952 | (void)threads; | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | - | |||||||||||||||||||
955 | if (::isDebugging > 1) | - | ||||||||||||||||||
956 | qdbusThreadDebug = qdbusDefaultThreadDebug; | - | ||||||||||||||||||
957 | - | |||||||||||||||||||
958 | - | |||||||||||||||||||
959 | QDBusMetaTypeId::init(); | - | ||||||||||||||||||
960 | connect(this, &QDBusConnectionPrivate::dispatchStatusChanged, | - | ||||||||||||||||||
961 | this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection); | - | ||||||||||||||||||
962 | connect(this, &QDBusConnectionPrivate::spyHooksFinished, | - | ||||||||||||||||||
963 | this, &QDBusConnectionPrivate::handleObjectCall, Qt::QueuedConnection); | - | ||||||||||||||||||
964 | connect(this, &QDBusConnectionPrivate::messageNeedsSending, | - | ||||||||||||||||||
965 | this, &QDBusConnectionPrivate::sendInternal); | - | ||||||||||||||||||
966 | connect(this, &QDBusConnectionPrivate::signalNeedsConnecting, | - | ||||||||||||||||||
967 | this, &QDBusConnectionPrivate::addSignalHook, Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
968 | connect(this, &QDBusConnectionPrivate::signalNeedsDisconnecting, | - | ||||||||||||||||||
969 | this, &QDBusConnectionPrivate::removeSignalHook, Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | rootNode.flags = 0; | - | ||||||||||||||||||
972 | - | |||||||||||||||||||
973 | - | |||||||||||||||||||
974 | - | |||||||||||||||||||
975 | watchedServices.insert(QDBusUtil::dbusService(), WatchedServiceData(QDBusUtil::dbusService(), 1)); | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | - | |||||||||||||||||||
978 | - | |||||||||||||||||||
979 | matchRefCounts.insert("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='org.freedesktop.DBus'", 1); | - | ||||||||||||||||||
980 | } | - | ||||||||||||||||||
981 | - | |||||||||||||||||||
982 | QDBusConnectionPrivate::~QDBusConnectionPrivate() | - | ||||||||||||||||||
983 | { | - | ||||||||||||||||||
984 | if (thread() && thread() != QThread::currentThread()) | - | ||||||||||||||||||
985 | QMessageLogger(__FILE__, 10601065, __PRETTY_FUNCTION__).warning("QDBusConnection(name=\"%s\")'s last reference in not in its creation thread! " | - | ||||||||||||||||||
986 | "Timer and socket errors will follow and the program will probably crash", | - | ||||||||||||||||||
987 | QString(name).toLocal8Bit().constData()); | - | ||||||||||||||||||
988 | - | |||||||||||||||||||
989 | closeConnection(); | - | ||||||||||||||||||
990 | qDeleteAll(cachedMetaObjects); | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | if (mode == ClientMode || mode == PeerMode) { | - | ||||||||||||||||||
993 | - | |||||||||||||||||||
994 | - | |||||||||||||||||||
995 | ((!(ref.load() == 0)) ? qt_assert("ref.load() == 0",__FILE__,10701075) : qt_noop()); | - | ||||||||||||||||||
996 | QObject *obj = (QObject *)busService; | - | ||||||||||||||||||
997 | if (obj) { | - | ||||||||||||||||||
998 | disconnect(obj, nullptr, this, nullptr); | - | ||||||||||||||||||
999 | delete obj; | - | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | if (connection) | - | ||||||||||||||||||
1002 | q_dbus_connection_unref(connection); | - | ||||||||||||||||||
1003 | connection = 0; | - | ||||||||||||||||||
1004 | } else if (mode == ServerMode) { | - | ||||||||||||||||||
1005 | if (server) | - | ||||||||||||||||||
1006 | q_dbus_server_unref(server); | - | ||||||||||||||||||
1007 | server = 0; | - | ||||||||||||||||||
1008 | } | - | ||||||||||||||||||
1009 | } | - | ||||||||||||||||||
1010 | - | |||||||||||||||||||
1011 | void QDBusConnectionPrivate::collectAllObjects(QDBusConnectionPrivate::ObjectTreeNode &haystack, | - | ||||||||||||||||||
1012 | QSet<QObject *> &set) | - | ||||||||||||||||||
1013 | { | - | ||||||||||||||||||
1014 | QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = haystack.children.begin(); | - | ||||||||||||||||||
1015 | - | |||||||||||||||||||
1016 | while (it != haystack.children.end()) { | - | ||||||||||||||||||
1017 | collectAllObjects(*it, set); | - | ||||||||||||||||||
1018 | it++; | - | ||||||||||||||||||
1019 | } | - | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | if (haystack.obj) | - | ||||||||||||||||||
1022 | set.insert(haystack.obj); | - | ||||||||||||||||||
1023 | } | - | ||||||||||||||||||
1024 | - | |||||||||||||||||||
1025 | void QDBusConnectionPrivate::closeConnection() | - | ||||||||||||||||||
1026 | { | - | ||||||||||||||||||
1027 | QDBusWriteLocker locker(CloseConnectionAction, this); | - | ||||||||||||||||||
1028 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 11031108, __PRETTY_FUNCTION__).debug() << this << "Disconnected"; | - | ||||||||||||||||||
1029 | ConnectionMode oldMode = mode; | - | ||||||||||||||||||
1030 | mode = InvalidMode; | - | ||||||||||||||||||
1031 | baseService.clear(); | - | ||||||||||||||||||
1032 | - | |||||||||||||||||||
1033 | if (oldMode == ServerMode && server) { | - | ||||||||||||||||||
1034 | q_dbus_server_disconnect(server); | - | ||||||||||||||||||
1035 | q_dbus_server_free_data_slot(&server_slot); | - | ||||||||||||||||||
1036 | } | - | ||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | if (oldMode == ClientMode || oldMode == PeerMode) { | - | ||||||||||||||||||
1039 | if (connection) { | - | ||||||||||||||||||
1040 | q_dbus_connection_close(connection); | - | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) | - | ||||||||||||||||||
1043 | ; | - | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | } | - | ||||||||||||||||||
1046 | - | |||||||||||||||||||
1047 | qDeleteAll(pendingCalls); | - | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | - | |||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | QSet<QObject *> allObjects; | - | ||||||||||||||||||
1055 | collectAllObjects(rootNode, allObjects); | - | ||||||||||||||||||
1056 | SignalHookHash::const_iterator sit = signalHooks.constBegin(); | - | ||||||||||||||||||
1057 | while (sit != signalHooks.constEnd()) { | - | ||||||||||||||||||
1058 | allObjects.insert(sit.value().obj); | - | ||||||||||||||||||
1059 | ++sit; | - | ||||||||||||||||||
1060 | } | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | QSet<QObject *>::const_iterator oit = allObjects.constBegin(); | - | ||||||||||||||||||
1064 | while (oit != allObjects.constEnd()) { | - | ||||||||||||||||||
1065 | (*oit)->disconnect(this); | - | ||||||||||||||||||
1066 | ++oit; | - | ||||||||||||||||||
1067 | } | - | ||||||||||||||||||
1068 | } | - | ||||||||||||||||||
1069 | - | |||||||||||||||||||
1070 | void QDBusConnectionPrivate::handleDBusDisconnection() | - | ||||||||||||||||||
1071 | { | - | ||||||||||||||||||
1072 | while (!pendingCalls.isEmpty()) | - | ||||||||||||||||||
1073 | processFinishedCall(pendingCalls.first()); | - | ||||||||||||||||||
1074 | } | - | ||||||||||||||||||
1075 | - | |||||||||||||||||||
1076 | void QDBusConnectionPrivate::checkThread() | - | ||||||||||||||||||
1077 | { | - | ||||||||||||||||||
1078 | ((!(thread() == QDBusConnectionManager::instance())) ? qt_assert("thread() == QDBusConnectionManager::instance()",__FILE__,11531158) : qt_noop()); | - | ||||||||||||||||||
1079 | ((!(QThread::currentThread() == thread())) ? qt_assert("QThread::currentThread() == thread()",__FILE__,11541159) : qt_noop()); | - | ||||||||||||||||||
1080 | } | - | ||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | bool QDBusConnectionPrivate::handleError(const QDBusErrorInternal &error) | - | ||||||||||||||||||
1083 | { | - | ||||||||||||||||||
1084 | if (!error) | - | ||||||||||||||||||
1085 | return false; | - | ||||||||||||||||||
1086 | - | |||||||||||||||||||
1087 | - | |||||||||||||||||||
1088 | lastError = error; | - | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | return true; | - | ||||||||||||||||||
1091 | } | - | ||||||||||||||||||
1092 | - | |||||||||||||||||||
1093 | void QDBusConnectionPrivate::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||
1094 | { | - | ||||||||||||||||||
1095 | { | - | ||||||||||||||||||
1096 | QDBusDispatchLocker locker(TimerEventAction, this); | - | ||||||||||||||||||
1097 | DBusTimeout *timeout = timeouts.value(e->timerId(), 0); | - | ||||||||||||||||||
1098 | if (timeout) | - | ||||||||||||||||||
1099 | q_dbus_timeout_handle(timeout); | - | ||||||||||||||||||
1100 | } | - | ||||||||||||||||||
1101 | - | |||||||||||||||||||
1102 | doDispatch(); | - | ||||||||||||||||||
1103 | } | - | ||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | void QDBusConnectionPrivate::doDispatch() | - | ||||||||||||||||||
1106 | { | - | ||||||||||||||||||
1107 | QDBusDispatchLocker locker(DoDispatchAction, this); | - | ||||||||||||||||||
1108 | if (mode == ClientMode || mode == PeerMode) { | - | ||||||||||||||||||
1109 | while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) ; | - | ||||||||||||||||||
1110 | if (dispatchEnabled && !pendingMessages.isEmpty()) { | - | ||||||||||||||||||
1111 | - | |||||||||||||||||||
1112 | PendingMessageList::Iterator it = pendingMessages.begin(); | - | ||||||||||||||||||
1113 | PendingMessageList::Iterator end = pendingMessages.end(); | - | ||||||||||||||||||
1114 | for ( ; it != end; ++it) { | - | ||||||||||||||||||
1115 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 11901195, __PRETTY_FUNCTION__).debug() << this << "dequeueing message" << *it; | - | ||||||||||||||||||
1116 | handleMessage(std::move(*it)); | - | ||||||||||||||||||
1117 | } | - | ||||||||||||||||||
1118 | pendingMessages.clear(); | - | ||||||||||||||||||
1119 | } | - | ||||||||||||||||||
1120 | } | - | ||||||||||||||||||
1121 | } | - | ||||||||||||||||||
1122 | - | |||||||||||||||||||
1123 | void QDBusConnectionPrivate::socketRead(int fd) | - | ||||||||||||||||||
1124 | { | - | ||||||||||||||||||
1125 | QDBusDispatchLocker locker(SocketReadAction, this); | - | ||||||||||||||||||
1126 | WatcherHash::ConstIterator it = watchers.constFind(fd); | - | ||||||||||||||||||
1127 | while (it != watchers.constEnd() && it.key() == fd) { | - | ||||||||||||||||||
1128 | if (it->watch && it->read && it->read->isEnabled()) { | - | ||||||||||||||||||
1129 | if (!q_dbus_watch_handle(it.value().watch, DBUS_WATCH_READABLE)) | - | ||||||||||||||||||
1130 | QMessageLogger(__FILE__, 12051210, __PRETTY_FUNCTION__).debug("OUT OF MEM"); | - | ||||||||||||||||||
1131 | break; | - | ||||||||||||||||||
1132 | } | - | ||||||||||||||||||
1133 | ++it; | - | ||||||||||||||||||
1134 | } | - | ||||||||||||||||||
1135 | doDispatch(); | - | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | void QDBusConnectionPrivate::socketWrite(int fd) | - | ||||||||||||||||||
1139 | { | - | ||||||||||||||||||
1140 | QDBusDispatchLocker locker(SocketWriteAction, this); | - | ||||||||||||||||||
1141 | WatcherHash::ConstIterator it = watchers.constFind(fd); | - | ||||||||||||||||||
1142 | while (it != watchers.constEnd() && it.key() == fd) { | - | ||||||||||||||||||
1143 | if (it->watch && it->write && it->write->isEnabled()) { | - | ||||||||||||||||||
1144 | if (!q_dbus_watch_handle(it.value().watch, DBUS_WATCH_WRITABLE)) | - | ||||||||||||||||||
1145 | QMessageLogger(__FILE__, 12201225, __PRETTY_FUNCTION__).debug("OUT OF MEM"); | - | ||||||||||||||||||
1146 | break; | - | ||||||||||||||||||
1147 | } | - | ||||||||||||||||||
1148 | ++it; | - | ||||||||||||||||||
1149 | } | - | ||||||||||||||||||
1150 | } | - | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | void QDBusConnectionPrivate::objectDestroyed(QObject *obj) | - | ||||||||||||||||||
1153 | { | - | ||||||||||||||||||
1154 | QDBusWriteLocker locker(ObjectDestroyedAction, this); | - | ||||||||||||||||||
1155 | huntAndDestroy(obj, rootNode); | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | SignalHookHash::iterator sit = signalHooks.begin(); | - | ||||||||||||||||||
1158 | while (sit != signalHooks.end()) { | - | ||||||||||||||||||
1159 | if (static_cast<QObject *>(sit.value().obj) == obj) | - | ||||||||||||||||||
1160 | sit = removeSignalHookNoLock(sit); | - | ||||||||||||||||||
1161 | else | - | ||||||||||||||||||
1162 | ++sit; | - | ||||||||||||||||||
1163 | } | - | ||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | obj->disconnect(this); | - | ||||||||||||||||||
1166 | } | - | ||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, int signalId, | - | ||||||||||||||||||
1169 | const QVariantList &args) | - | ||||||||||||||||||
1170 | { | - | ||||||||||||||||||
1171 | QString interface = qDBusInterfaceFromMetaObject(mo); | - | ||||||||||||||||||
1172 | - | |||||||||||||||||||
1173 | QMetaMethod mm = mo->method(signalId); | - | ||||||||||||||||||
1174 | QByteArray memberName = mm.name(); | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | - | |||||||||||||||||||
1177 | bool isScriptable = mm.attributes() & QMetaMethod::Scriptable; | - | ||||||||||||||||||
1178 | bool isAdaptor = false; | - | ||||||||||||||||||
1179 | for ( ; mo; mo = mo->superClass()) | - | ||||||||||||||||||
1180 | if (mo == &QDBusAbstractAdaptor::staticMetaObject) { | - | ||||||||||||||||||
1181 | isAdaptor = true; | - | ||||||||||||||||||
1182 | break; | - | ||||||||||||||||||
1183 | } | - | ||||||||||||||||||
1184 | - | |||||||||||||||||||
1185 | checkThread(); | - | ||||||||||||||||||
1186 | QDBusReadLocker locker(RelaySignalAction, this); | - | ||||||||||||||||||
1187 | QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/"), interface, | - | ||||||||||||||||||
1188 | QLatin1String(memberName)); | - | ||||||||||||||||||
1189 | QDBusMessagePrivate::setParametersValidated(message, true); | - | ||||||||||||||||||
1190 | message.setArguments(args); | - | ||||||||||||||||||
1191 | QDBusError error; | - | ||||||||||||||||||
1192 | DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error); | - | ||||||||||||||||||
1193 | if (!msg) { | - | ||||||||||||||||||
1194 | QMessageLogger(__FILE__, 12691274, __PRETTY_FUNCTION__).warning("QDBusConnection: Could not emit signal %s.%s: %s", QString(interface).toLocal8Bit().constData(), memberName.constData(), | - | ||||||||||||||||||
1195 | QString(error.message()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1196 | lastError = error; | - | ||||||||||||||||||
1197 | return; | - | ||||||||||||||||||
1198 | } | - | ||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | - | |||||||||||||||||||
1202 | q_dbus_message_set_no_reply(msg, true); | - | ||||||||||||||||||
1203 | { | - | ||||||||||||||||||
1204 | QDBusDispatchLocker locker(HuntAndEmitAction, this); | - | ||||||||||||||||||
1205 | huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor); | - | ||||||||||||||||||
1206 | } | - | ||||||||||||||||||
1207 | q_dbus_message_unref(msg); | - | ||||||||||||||||||
1208 | } | - | ||||||||||||||||||
1209 | - | |||||||||||||||||||
1210 | void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name, | - | ||||||||||||||||||
1211 | const QString &oldOwner, const QString &newOwner) | - | ||||||||||||||||||
1212 | { | - | ||||||||||||||||||
1213 | (void)oldOwner;; | - | ||||||||||||||||||
1214 | - | |||||||||||||||||||
1215 | WatchedServicesHash::Iterator it = watchedServices.find(name); | - | ||||||||||||||||||
1216 | if (it == watchedServices.end()) | - | ||||||||||||||||||
1217 | return; | - | ||||||||||||||||||
1218 | if (oldOwner != it->owner) | - | ||||||||||||||||||
1219 | QMessageLogger(__FILE__, 12941299, __PRETTY_FUNCTION__).warning("QDBusConnection: name '%s' had owner '%s' but we thought it was '%s'", | - | ||||||||||||||||||
1220 | QString(name).toLocal8Bit().constData(), QString(oldOwner).toLocal8Bit().constData(), QString(it->owner).toLocal8Bit().constData()); | - | ||||||||||||||||||
1221 | - | |||||||||||||||||||
1222 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 12971302, __PRETTY_FUNCTION__).debug() << this << "Updating name" << name << "from" << oldOwner << "to" << newOwner; | - | ||||||||||||||||||
1223 | it->owner = newOwner; | - | ||||||||||||||||||
1224 | } | - | ||||||||||||||||||
1225 | - | |||||||||||||||||||
1226 | int QDBusConnectionPrivate::findSlot(QObject* obj, const QByteArray &normalizedName, | - | ||||||||||||||||||
1227 | QVector<int> ¶ms) | - | ||||||||||||||||||
1228 | { | - | ||||||||||||||||||
1229 | int midx = obj->metaObject()->indexOfMethod(normalizedName); | - | ||||||||||||||||||
1230 | if (midx == -1) | - | ||||||||||||||||||
1231 | return -1; | - | ||||||||||||||||||
1232 | - | |||||||||||||||||||
1233 | QString errorMsg; | - | ||||||||||||||||||
1234 | int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params, errorMsg); | - | ||||||||||||||||||
1235 | if ( inputCount == -1 || inputCount + 1 != params.count() ) | - | ||||||||||||||||||
1236 | return -1; | - | ||||||||||||||||||
1237 | - | |||||||||||||||||||
1238 | return midx; | - | ||||||||||||||||||
1239 | } | - | ||||||||||||||||||
1240 | - | |||||||||||||||||||
1241 | bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, | - | ||||||||||||||||||
1242 | const QString &service, | - | ||||||||||||||||||
1243 | const QString &path, const QString &interface, const QString &name, | - | ||||||||||||||||||
1244 | const QStringList &argMatch, | - | ||||||||||||||||||
1245 | QObject *receiver, const char *signal, int minMIdx, | - | ||||||||||||||||||
1246 | bool buildSignature) | - | ||||||||||||||||||
1247 | { | - | ||||||||||||||||||
1248 | QByteArray normalizedName = signal + 1; | - | ||||||||||||||||||
1249 | hook.midx = findSlot(receiver, signal + 1, hook.params); | - | ||||||||||||||||||
1250 | if (hook.midx == -1) { | - | ||||||||||||||||||
1251 | normalizedName = QMetaObject::normalizedSignature(signal + 1); | - | ||||||||||||||||||
1252 | hook.midx = findSlot(receiver, normalizedName, hook.params); | - | ||||||||||||||||||
1253 | } | - | ||||||||||||||||||
1254 | if (hook.midx < minMIdx) { | - | ||||||||||||||||||
1255 | if (hook.midx == -1) | - | ||||||||||||||||||
1256 | {} | - | ||||||||||||||||||
1257 | return false; | - | ||||||||||||||||||
1258 | } | - | ||||||||||||||||||
1259 | - | |||||||||||||||||||
1260 | hook.service = service; | - | ||||||||||||||||||
1261 | hook.path = path; | - | ||||||||||||||||||
1262 | hook.obj = receiver; | - | ||||||||||||||||||
1263 | hook.argumentMatch = argMatch; | - | ||||||||||||||||||
1264 | - | |||||||||||||||||||
1265 | - | |||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | - | |||||||||||||||||||
1268 | QString mname = name; | - | ||||||||||||||||||
1269 | if (buildSignature && mname.isNull()) { | - | ||||||||||||||||||
1270 | normalizedName.truncate(normalizedName.indexOf('(')); | - | ||||||||||||||||||
1271 | mname = QString::fromUtf8(normalizedName); | - | ||||||||||||||||||
1272 | } | - | ||||||||||||||||||
1273 | key = mname; | - | ||||||||||||||||||
1274 | key.reserve(interface.length() + 1 + mname.length()); | - | ||||||||||||||||||
1275 | key += QLatin1Char(':'); | - | ||||||||||||||||||
1276 | key += interface; | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | if (buildSignature) { | - | ||||||||||||||||||
1279 | hook.signature.clear(); | - | ||||||||||||||||||
1280 | for (int i = 1; i < hook.params.count(); ++i) | - | ||||||||||||||||||
1281 | if (hook.params.at(i) != QDBusMetaTypeId::message()) | - | ||||||||||||||||||
1282 | hook.signature += QLatin1String( QDBusMetaType::typeToSignature( hook.params.at(i) ) ); | - | ||||||||||||||||||
1283 | } | - | ||||||||||||||||||
1284 | - | |||||||||||||||||||
1285 | hook.matchRule = buildMatchRule(service, path, interface, mname, argMatch, hook.signature); | - | ||||||||||||||||||
1286 | return true; | - | ||||||||||||||||||
1287 | } | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | void QDBusConnectionPrivate::sendError(const QDBusMessage &msg, QDBusError::ErrorType code) | - | ||||||||||||||||||
1290 | { | - | ||||||||||||||||||
1291 | if (code == QDBusError::UnknownMethod) { | - | ||||||||||||||||||
1292 | QString interfaceMsg; | - | ||||||||||||||||||
1293 | if (msg.interface().isEmpty()) | - | ||||||||||||||||||
1294 | interfaceMsg = QLatin1String("any interface"); | - | ||||||||||||||||||
1295 | else | - | ||||||||||||||||||
1296 | interfaceMsg = QString::fromLatin1("interface '%1'").arg(msg.interface()); | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | send(msg.createErrorReply(code, | - | ||||||||||||||||||
1299 | QString::fromLatin1("No such method '%1' in %2 at object path '%3' " | - | ||||||||||||||||||
1300 | "(signature '%4')") | - | ||||||||||||||||||
1301 | .arg(msg.member(), interfaceMsg, msg.path(), msg.signature()))); | - | ||||||||||||||||||
1302 | } else if (code == QDBusError::UnknownInterface) { | - | ||||||||||||||||||
1303 | send(msg.createErrorReply(QDBusError::UnknownInterface, | - | ||||||||||||||||||
1304 | QString::fromLatin1("No such interface '%1' at object path '%2'") | - | ||||||||||||||||||
1305 | .arg(msg.interface(), msg.path()))); | - | ||||||||||||||||||
1306 | } else if (code == QDBusError::UnknownObject) { | - | ||||||||||||||||||
1307 | send(msg.createErrorReply(QDBusError::UnknownObject, | - | ||||||||||||||||||
1308 | QString::fromLatin1("No such object path '%1'").arg(msg.path()))); | - | ||||||||||||||||||
1309 | } | - | ||||||||||||||||||
1310 | } | - | ||||||||||||||||||
1311 | - | |||||||||||||||||||
1312 | bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node, | - | ||||||||||||||||||
1313 | const QDBusMessage &msg) | - | ||||||||||||||||||
1314 | { | - | ||||||||||||||||||
1315 | - | |||||||||||||||||||
1316 | const QString interface = msg.interface(); | - | ||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | if (interface.isEmpty() || interface == QDBusUtil::dbusInterfaceIntrospectable()) { | - | ||||||||||||||||||
1319 | if (msg.member() == QLatin1String("Introspect") && msg.signature().isEmpty()) { | - | ||||||||||||||||||
1320 | - | |||||||||||||||||||
1321 | QDBusMessage reply = msg.createReply(qDBusIntrospectObject(node, msg.path())); | - | ||||||||||||||||||
1322 | send(reply); | - | ||||||||||||||||||
1323 | return true; | - | ||||||||||||||||||
1324 | } | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | if (!interface.isEmpty()) { | - | ||||||||||||||||||
1327 | sendError(msg, QDBusError::UnknownMethod); | - | ||||||||||||||||||
1328 | return true; | - | ||||||||||||||||||
1329 | } | - | ||||||||||||||||||
1330 | } | - | ||||||||||||||||||
1331 | - | |||||||||||||||||||
1332 | if (node.obj && (interface.isEmpty() || | - | ||||||||||||||||||
1333 | interface == QDBusUtil::dbusInterfaceProperties())) { | - | ||||||||||||||||||
1334 | - | |||||||||||||||||||
1335 | if (msg.member() == QLatin1String("Get") && msg.signature() == QLatin1String("ss")) { | - | ||||||||||||||||||
1336 | QDBusMessage reply = qDBusPropertyGet(node, msg); | - | ||||||||||||||||||
1337 | send(reply); | - | ||||||||||||||||||
1338 | return true; | - | ||||||||||||||||||
1339 | } else if (msg.member() == QLatin1String("Set") && msg.signature() == QLatin1String("ssv")) { | - | ||||||||||||||||||
1340 | QDBusMessage reply = qDBusPropertySet(node, msg); | - | ||||||||||||||||||
1341 | send(reply); | - | ||||||||||||||||||
1342 | return true; | - | ||||||||||||||||||
1343 | } else if (msg.member() == QLatin1String("GetAll") && msg.signature() == QLatin1String("s")) { | - | ||||||||||||||||||
1344 | QDBusMessage reply = qDBusPropertyGetAll(node, msg); | - | ||||||||||||||||||
1345 | send(reply); | - | ||||||||||||||||||
1346 | return true; | - | ||||||||||||||||||
1347 | } | - | ||||||||||||||||||
1348 | - | |||||||||||||||||||
1349 | if (!interface.isEmpty()) { | - | ||||||||||||||||||
1350 | sendError(msg, QDBusError::UnknownMethod); | - | ||||||||||||||||||
1351 | return true; | - | ||||||||||||||||||
1352 | } | - | ||||||||||||||||||
1353 | } | - | ||||||||||||||||||
1354 | - | |||||||||||||||||||
1355 | return false; | - | ||||||||||||||||||
1356 | } | - | ||||||||||||||||||
1357 | - | |||||||||||||||||||
1358 | void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMessage &msg, | - | ||||||||||||||||||
1359 | int pathStartPos) | - | ||||||||||||||||||
1360 | { | - | ||||||||||||||||||
1361 | - | |||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | - | |||||||||||||||||||
1365 | - | |||||||||||||||||||
1366 | - | |||||||||||||||||||
1367 | - | |||||||||||||||||||
1368 | if (node.flags & QDBusConnectionPrivate::VirtualObject) { | - | ||||||||||||||||||
1369 | if (node.treeNode->handleMessage(msg, q(this))) { | - | ||||||||||||||||||
1370 | return; | - | ||||||||||||||||||
1371 | } else { | - | ||||||||||||||||||
1372 | if (activateInternalFilters(node, msg)) | - | ||||||||||||||||||
1373 | return; | - | ||||||||||||||||||
1374 | } | - | ||||||||||||||||||
1375 | } | - | ||||||||||||||||||
1376 | - | |||||||||||||||||||
1377 | if (pathStartPos != msg.path().length()) { | - | ||||||||||||||||||
1378 | node.flags &= ~QDBusConnection::ExportAllSignals; | - | ||||||||||||||||||
1379 | node.obj = findChildObject(&node, msg.path(), pathStartPos); | - | ||||||||||||||||||
1380 | if (!node.obj) { | - | ||||||||||||||||||
1381 | sendError(msg, QDBusError::UnknownObject); | - | ||||||||||||||||||
1382 | return; | - | ||||||||||||||||||
1383 | } | - | ||||||||||||||||||
1384 | } | - | ||||||||||||||||||
1385 | - | |||||||||||||||||||
1386 | QDBusAdaptorConnector *connector; | - | ||||||||||||||||||
1387 | if (node.flags & QDBusConnection::ExportAdaptors && | - | ||||||||||||||||||
1388 | (connector = qDBusFindAdaptorConnector(node.obj))) { | - | ||||||||||||||||||
1389 | int newflags = node.flags | QDBusConnection::ExportAllSlots; | - | ||||||||||||||||||
1390 | - | |||||||||||||||||||
1391 | if (msg.interface().isEmpty()) { | - | ||||||||||||||||||
1392 | - | |||||||||||||||||||
1393 | - | |||||||||||||||||||
1394 | QDBusAdaptorConnector::AdaptorMap::ConstIterator it = | - | ||||||||||||||||||
1395 | connector->adaptors.constBegin(); | - | ||||||||||||||||||
1396 | QDBusAdaptorConnector::AdaptorMap::ConstIterator end = | - | ||||||||||||||||||
1397 | connector->adaptors.constEnd(); | - | ||||||||||||||||||
1398 | - | |||||||||||||||||||
1399 | for ( ; it != end; ++it) | - | ||||||||||||||||||
1400 | if (activateCall(it->adaptor, newflags, msg)) | - | ||||||||||||||||||
1401 | return; | - | ||||||||||||||||||
1402 | } else { | - | ||||||||||||||||||
1403 | - | |||||||||||||||||||
1404 | QDBusAdaptorConnector::AdaptorMap::ConstIterator it; | - | ||||||||||||||||||
1405 | it = std::lower_bound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), | - | ||||||||||||||||||
1406 | msg.interface()); | - | ||||||||||||||||||
1407 | if (it != connector->adaptors.constEnd() && msg.interface() == QLatin1String(it->interface)) { | - | ||||||||||||||||||
1408 | if (!activateCall(it->adaptor, newflags, msg)) | - | ||||||||||||||||||
1409 | sendError(msg, QDBusError::UnknownMethod); | - | ||||||||||||||||||
1410 | return; | - | ||||||||||||||||||
1411 | } | - | ||||||||||||||||||
1412 | } | - | ||||||||||||||||||
1413 | } | - | ||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | - | |||||||||||||||||||
1416 | - | |||||||||||||||||||
1417 | if (activateInternalFilters(node, msg)) | - | ||||||||||||||||||
1418 | return; | - | ||||||||||||||||||
1419 | - | |||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots) || | - | ||||||||||||||||||
1422 | node.flags & (QDBusConnection::ExportScriptableInvokables|QDBusConnection::ExportNonScriptableInvokables)) { | - | ||||||||||||||||||
1423 | bool interfaceFound = true; | - | ||||||||||||||||||
1424 | if (!msg.interface().isEmpty()) { | - | ||||||||||||||||||
1425 | if (!node.interfaceName.isEmpty()) | - | ||||||||||||||||||
1426 | interfaceFound = msg.interface() == node.interfaceName; | - | ||||||||||||||||||
1427 | else | - | ||||||||||||||||||
1428 | interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface()); | - | ||||||||||||||||||
1429 | } | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | if (interfaceFound) { | - | ||||||||||||||||||
1432 | if (!activateCall(node.obj, node.flags, msg)) | - | ||||||||||||||||||
1433 | sendError(msg, QDBusError::UnknownMethod); | - | ||||||||||||||||||
1434 | return; | - | ||||||||||||||||||
1435 | } | - | ||||||||||||||||||
1436 | } | - | ||||||||||||||||||
1437 | - | |||||||||||||||||||
1438 | - | |||||||||||||||||||
1439 | if (msg.interface().isEmpty()) | - | ||||||||||||||||||
1440 | sendError(msg, QDBusError::UnknownMethod); | - | ||||||||||||||||||
1441 | else | - | ||||||||||||||||||
1442 | sendError(msg, QDBusError::UnknownInterface); | - | ||||||||||||||||||
1443 | } | - | ||||||||||||||||||
1444 | - | |||||||||||||||||||
1445 | void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg) | - | ||||||||||||||||||
1446 | { | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | - | |||||||||||||||||||
1449 | - | |||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | - | |||||||||||||||||||
1452 | - | |||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | ObjectTreeNode result; | - | ||||||||||||||||||
1455 | int usedLength; | - | ||||||||||||||||||
1456 | QThread *objThread = 0; | - | ||||||||||||||||||
1457 | QSemaphore sem; | - | ||||||||||||||||||
1458 | bool semWait; | - | ||||||||||||||||||
1459 | - | |||||||||||||||||||
1460 | { | - | ||||||||||||||||||
1461 | QDBusReadLocker locker(HandleObjectCallAction, this); | - | ||||||||||||||||||
1462 | if (!findObject(&rootNode, msg.path(), usedLength, result)) { | - | ||||||||||||||||||
1463 | - | |||||||||||||||||||
1464 | sendError(msg, QDBusError::UnknownObject); | - | ||||||||||||||||||
1465 | return; | - | ||||||||||||||||||
1466 | } | - | ||||||||||||||||||
1467 | - | |||||||||||||||||||
1468 | if (!result.obj) { | - | ||||||||||||||||||
1469 | - | |||||||||||||||||||
1470 | - | |||||||||||||||||||
1471 | activateObject(result, msg, usedLength); | - | ||||||||||||||||||
1472 | return; | - | ||||||||||||||||||
1473 | } | - | ||||||||||||||||||
1474 | - | |||||||||||||||||||
1475 | objThread = result.obj->thread(); | - | ||||||||||||||||||
1476 | if (!objThread) { | - | ||||||||||||||||||
1477 | send(msg.createErrorReply(QDBusError::InternalError, | - | ||||||||||||||||||
1478 | QString::fromLatin1("Object '%1' (at path '%2')" | - | ||||||||||||||||||
1479 | " has no thread. Cannot deliver message.") | - | ||||||||||||||||||
1480 | .arg(result.obj->objectName(), msg.path()))); | - | ||||||||||||||||||
1481 | return; | - | ||||||||||||||||||
1482 | } | - | ||||||||||||||||||
1483 | - | |||||||||||||||||||
1484 | if (!QDBusMessagePrivate::isLocal(msg)) { | - | ||||||||||||||||||
1485 | - | |||||||||||||||||||
1486 | - | |||||||||||||||||||
1487 | postEventToThread(HandleObjectCallPostEventAction, result.obj, | - | ||||||||||||||||||
1488 | new QDBusActivateObjectEvent(QDBusConnection(this), this, result, | - | ||||||||||||||||||
1489 | usedLength, msg)); | - | ||||||||||||||||||
1490 | return; | - | ||||||||||||||||||
1491 | } else if (objThread != QThread::currentThread()) { | - | ||||||||||||||||||
1492 | - | |||||||||||||||||||
1493 | - | |||||||||||||||||||
1494 | postEventToThread(HandleObjectCallPostEventAction, result.obj, | - | ||||||||||||||||||
1495 | new QDBusActivateObjectEvent(QDBusConnection(this), this, result, | - | ||||||||||||||||||
1496 | usedLength, msg, &sem)); | - | ||||||||||||||||||
1497 | semWait = true; | - | ||||||||||||||||||
1498 | } else { | - | ||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | semWait = false; | - | ||||||||||||||||||
1501 | } | - | ||||||||||||||||||
1502 | } | - | ||||||||||||||||||
1503 | - | |||||||||||||||||||
1504 | if (semWait) | - | ||||||||||||||||||
1505 | do { QDBusLockerBase::reportThreadAction(HandleObjectCallSemaphoreAction, QDBusLockerBase::BeforeAcquire, this); sem.acquire(); QDBusLockerBase::reportThreadAction(HandleObjectCallSemaphoreAction, QDBusLockerBase::AfterAcquire, this); } while (0); | - | ||||||||||||||||||
1506 | else | - | ||||||||||||||||||
1507 | activateObject(result, msg, usedLength); | - | ||||||||||||||||||
1508 | } | - | ||||||||||||||||||
1509 | - | |||||||||||||||||||
1510 | QDBusActivateObjectEvent::~QDBusActivateObjectEvent() | - | ||||||||||||||||||
1511 | { | - | ||||||||||||||||||
1512 | if (!handled) { | - | ||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | - | |||||||||||||||||||
1515 | QDBusConnectionPrivate *that = QDBusConnectionPrivate::d(connection); | - | ||||||||||||||||||
1516 | that->sendError(message, QDBusError::UnknownObject); | - | ||||||||||||||||||
1517 | } | - | ||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | - | |||||||||||||||||||
1520 | } | - | ||||||||||||||||||
1521 | - | |||||||||||||||||||
1522 | void QDBusActivateObjectEvent::placeMetaCall(QObject *) | - | ||||||||||||||||||
1523 | { | - | ||||||||||||||||||
1524 | QDBusConnectionPrivate *that = QDBusConnectionPrivate::d(connection); | - | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | QDBusLockerBase::reportThreadAction(HandleObjectCallPostEventAction, | - | ||||||||||||||||||
1527 | QDBusLockerBase::BeforeDeliver, that); | - | ||||||||||||||||||
1528 | that->activateObject(node, message, pathStartPos); | - | ||||||||||||||||||
1529 | QDBusLockerBase::reportThreadAction(HandleObjectCallPostEventAction, | - | ||||||||||||||||||
1530 | QDBusLockerBase::AfterDeliver, that); | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | handled = true; | - | ||||||||||||||||||
1533 | } | - | ||||||||||||||||||
1534 | - | |||||||||||||||||||
1535 | void QDBusConnectionPrivate::handleSignal(const QString &key, const QDBusMessage& msg) | - | ||||||||||||||||||
1536 | { | - | ||||||||||||||||||
1537 | SignalHookHash::const_iterator it = signalHooks.constFind(key); | - | ||||||||||||||||||
1538 | SignalHookHash::const_iterator end = signalHooks.constEnd(); | - | ||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | - | |||||||||||||||||||
1541 | for ( ; it != end && it.key() == key; ++it) { | - | ||||||||||||||||||
1542 | const SignalHook &hook = it.value(); | - | ||||||||||||||||||
1543 | if (!hook.service.isEmpty()) { | - | ||||||||||||||||||
1544 | QString owner = watchedServices.value(hook.service, WatchedServiceData(hook.service)).owner; | - | ||||||||||||||||||
1545 | if (owner != msg.service()) | - | ||||||||||||||||||
1546 | continue; | - | ||||||||||||||||||
1547 | } | - | ||||||||||||||||||
1548 | if (!hook.path.isEmpty() && hook.path != msg.path()) | - | ||||||||||||||||||
1549 | continue; | - | ||||||||||||||||||
1550 | if (!hook.signature.isEmpty() && hook.signature != msg.signature()) | - | ||||||||||||||||||
1551 | continue; | - | ||||||||||||||||||
1552 | if (hook.signature.isEmpty() && !hook.signature.isNull() && !msg.signature().isEmpty()) | - | ||||||||||||||||||
1553 | continue; | - | ||||||||||||||||||
1554 | if (!hook.argumentMatch.isEmpty()) { | - | ||||||||||||||||||
1555 | const QVariantList arguments = msg.arguments(); | - | ||||||||||||||||||
1556 | if (hook.argumentMatch.size() > arguments.size()) | - | ||||||||||||||||||
1557 | continue; | - | ||||||||||||||||||
1558 | - | |||||||||||||||||||
1559 | bool matched = true; | - | ||||||||||||||||||
1560 | for (int i = 0; i < hook.argumentMatch.size(); ++i) { | - | ||||||||||||||||||
1561 | const QString ¶m = hook.argumentMatch.at(i); | - | ||||||||||||||||||
1562 | if (param.isNull()) | - | ||||||||||||||||||
1563 | continue; | - | ||||||||||||||||||
1564 | if (param == arguments.at(i).toString()) | - | ||||||||||||||||||
1565 | continue; | - | ||||||||||||||||||
1566 | matched = false; | - | ||||||||||||||||||
1567 | break; | - | ||||||||||||||||||
1568 | } | - | ||||||||||||||||||
1569 | if (!matched) | - | ||||||||||||||||||
1570 | continue; | - | ||||||||||||||||||
1571 | } | - | ||||||||||||||||||
1572 | - | |||||||||||||||||||
1573 | activateSignal(hook, msg); | - | ||||||||||||||||||
1574 | } | - | ||||||||||||||||||
1575 | } | - | ||||||||||||||||||
1576 | - | |||||||||||||||||||
1577 | void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg) | - | ||||||||||||||||||
1578 | { | - | ||||||||||||||||||
1579 | - | |||||||||||||||||||
1580 | - | |||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | - | |||||||||||||||||||
1583 | - | |||||||||||||||||||
1584 | - | |||||||||||||||||||
1585 | - | |||||||||||||||||||
1586 | QString key = msg.member(); | - | ||||||||||||||||||
1587 | key.reserve(key.length() + 1 + msg.interface().length()); | - | ||||||||||||||||||
1588 | key += QLatin1Char(':'); | - | ||||||||||||||||||
1589 | key += msg.interface(); | - | ||||||||||||||||||
1590 | - | |||||||||||||||||||
1591 | QDBusReadLocker locker(HandleSignalAction, this); | - | ||||||||||||||||||
1592 | handleSignal(key, msg); | - | ||||||||||||||||||
1593 | - | |||||||||||||||||||
1594 | key.truncate(msg.member().length() + 1); | - | ||||||||||||||||||
1595 | handleSignal(key, msg); | - | ||||||||||||||||||
1596 | - | |||||||||||||||||||
1597 | key = QLatin1Char(':'); | - | ||||||||||||||||||
1598 | key += msg.interface(); | - | ||||||||||||||||||
1599 | handleSignal(key, msg); | - | ||||||||||||||||||
1600 | } | - | ||||||||||||||||||
1601 | - | |||||||||||||||||||
1602 | void QDBusConnectionPrivate::watchForDBusDisconnection() | - | ||||||||||||||||||
1603 | { | - | ||||||||||||||||||
1604 | SignalHook hook; | - | ||||||||||||||||||
1605 | - | |||||||||||||||||||
1606 | hook.service.clear(); | - | ||||||||||||||||||
1607 | hook.path = QDBusUtil::dbusPathLocal(); | - | ||||||||||||||||||
1608 | hook.obj = this; | - | ||||||||||||||||||
1609 | hook.params << QMetaType::Void; | - | ||||||||||||||||||
1610 | hook.midx = staticMetaObject.indexOfSlot("handleDBusDisconnection()"); | - | ||||||||||||||||||
1611 | ((!(hook.midx != -1)) ? qt_assert("hook.midx != -1",__FILE__,16861691) : qt_noop()); | - | ||||||||||||||||||
1612 | signalHooks.insert(QLatin1String("Disconnected:" "org.freedesktop.DBus.Local"), hook); | - | ||||||||||||||||||
1613 | } | - | ||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | void QDBusConnectionPrivate::setServer(QDBusServer *object, DBusServer *s, const QDBusErrorInternal &error) | - | ||||||||||||||||||
1616 | { | - | ||||||||||||||||||
1617 | mode = ServerMode; | - | ||||||||||||||||||
1618 | serverObject = object; | - | ||||||||||||||||||
1619 | object->d = this; | - | ||||||||||||||||||
1620 | if (!s) { | - | ||||||||||||||||||
1621 | handleError(error); | - | ||||||||||||||||||
1622 | return; | - | ||||||||||||||||||
1623 | } | - | ||||||||||||||||||
1624 | - | |||||||||||||||||||
1625 | server = s; | - | ||||||||||||||||||
1626 | - | |||||||||||||||||||
1627 | dbus_bool_t data_allocated = q_dbus_server_allocate_data_slot(&server_slot); | - | ||||||||||||||||||
1628 | if (data_allocated && server_slot < 0) | - | ||||||||||||||||||
1629 | return; | - | ||||||||||||||||||
1630 | - | |||||||||||||||||||
1631 | dbus_bool_t watch_functions_set = q_dbus_server_set_watch_functions(server, | - | ||||||||||||||||||
1632 | qDBusAddWatch, | - | ||||||||||||||||||
1633 | qDBusRemoveWatch, | - | ||||||||||||||||||
1634 | qDBusToggleWatch, | - | ||||||||||||||||||
1635 | this, 0); | - | ||||||||||||||||||
1636 | - | |||||||||||||||||||
1637 | (void)watch_functions_set;; | - | ||||||||||||||||||
1638 | - | |||||||||||||||||||
1639 | dbus_bool_t time_functions_set = q_dbus_server_set_timeout_functions(server, | - | ||||||||||||||||||
1640 | qDBusAddTimeout, | - | ||||||||||||||||||
1641 | qDBusRemoveTimeout, | - | ||||||||||||||||||
1642 | qDBusToggleTimeout, | - | ||||||||||||||||||
1643 | this, 0); | - | ||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | (void)time_functions_set;; | - | ||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0); | - | ||||||||||||||||||
1648 | - | |||||||||||||||||||
1649 | dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, 0); | - | ||||||||||||||||||
1650 | - | |||||||||||||||||||
1651 | (void)data_set;; | - | ||||||||||||||||||
1652 | } | - | ||||||||||||||||||
1653 | - | |||||||||||||||||||
1654 | void QDBusConnectionPrivate::setPeer(DBusConnection *c, const QDBusErrorInternal &error) | - | ||||||||||||||||||
1655 | { | - | ||||||||||||||||||
1656 | mode = PeerMode; | - | ||||||||||||||||||
1657 | if (!c) { | - | ||||||||||||||||||
1658 | handleError(error); | - | ||||||||||||||||||
1659 | return; | - | ||||||||||||||||||
1660 | } | - | ||||||||||||||||||
1661 | - | |||||||||||||||||||
1662 | connection = c; | - | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | q_dbus_connection_set_exit_on_disconnect(connection, false); | - | ||||||||||||||||||
1665 | q_dbus_connection_set_watch_functions(connection, | - | ||||||||||||||||||
1666 | qDBusAddWatch, | - | ||||||||||||||||||
1667 | qDBusRemoveWatch, | - | ||||||||||||||||||
1668 | qDBusToggleWatch, | - | ||||||||||||||||||
1669 | this, 0); | - | ||||||||||||||||||
1670 | q_dbus_connection_set_timeout_functions(connection, | - | ||||||||||||||||||
1671 | qDBusAddTimeout, | - | ||||||||||||||||||
1672 | qDBusRemoveTimeout, | - | ||||||||||||||||||
1673 | qDBusToggleTimeout, | - | ||||||||||||||||||
1674 | this, 0); | - | ||||||||||||||||||
1675 | q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0); | - | ||||||||||||||||||
1676 | q_dbus_connection_add_filter(connection, | - | ||||||||||||||||||
1677 | qDBusSignalFilter, | - | ||||||||||||||||||
1678 | this, 0); | - | ||||||||||||||||||
1679 | - | |||||||||||||||||||
1680 | watchForDBusDisconnection(); | - | ||||||||||||||||||
1681 | - | |||||||||||||||||||
1682 | QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection); | - | ||||||||||||||||||
1683 | } | - | ||||||||||||||||||
1684 | - | |||||||||||||||||||
1685 | static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnection *connection) | - | ||||||||||||||||||
1686 | { | - | ||||||||||||||||||
1687 | QDBusConnection::ConnectionCapabilities result = 0; | - | ||||||||||||||||||
1688 | typedef dbus_bool_t (*can_send_type_t)(DBusConnection *, int); | - | ||||||||||||||||||
1689 | static can_send_type_t can_send_type = 0; | - | ||||||||||||||||||
1690 | - | |||||||||||||||||||
1691 | - | |||||||||||||||||||
1692 | - | |||||||||||||||||||
1693 | can_send_type = dbus_connection_can_send_type; | - | ||||||||||||||||||
1694 | if (can_send_type && can_send_type(connection, ((int) 'h'))) | - | ||||||||||||||||||
1695 | result |= QDBusConnection::UnixFileDescriptorPassing; | - | ||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | return result; | - | ||||||||||||||||||
1698 | } | - | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusErrorInternal &error) | - | ||||||||||||||||||
1701 | { | - | ||||||||||||||||||
1702 | mode = ClientMode; | - | ||||||||||||||||||
1703 | if (!dbc) { | - | ||||||||||||||||||
1704 | handleError(error); | - | ||||||||||||||||||
1705 | return; | - | ||||||||||||||||||
1706 | } | - | ||||||||||||||||||
1707 | - | |||||||||||||||||||
1708 | connection = dbc; | - | ||||||||||||||||||
1709 | - | |||||||||||||||||||
1710 | const char *service = q_dbus_bus_get_unique_name(connection); | - | ||||||||||||||||||
1711 | ((!(service)) ? qt_assert("service",__FILE__,17951800) : qt_noop()); | - | ||||||||||||||||||
1712 | baseService = QString::fromUtf8(service); | - | ||||||||||||||||||
1713 | capabilities = connectionCapabilies(connection); | - | ||||||||||||||||||
1714 | - | |||||||||||||||||||
1715 | q_dbus_connection_set_exit_on_disconnect(connection, false); | - | ||||||||||||||||||
1716 | q_dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch, | - | ||||||||||||||||||
1717 | qDBusToggleWatch, this, 0); | - | ||||||||||||||||||
1718 | q_dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout, | - | ||||||||||||||||||
1719 | qDBusToggleTimeout, this, 0); | - | ||||||||||||||||||
1720 | q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0); | - | ||||||||||||||||||
1721 | q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0); | - | ||||||||||||||||||
1722 | - | |||||||||||||||||||
1723 | - | |||||||||||||||||||
1724 | - | |||||||||||||||||||
1725 | - | |||||||||||||||||||
1726 | SignalHook hook; | - | ||||||||||||||||||
1727 | hook.service = QDBusUtil::dbusService(); | - | ||||||||||||||||||
1728 | hook.path.clear(); | - | ||||||||||||||||||
1729 | hook.obj = this; | - | ||||||||||||||||||
1730 | hook.params << QMetaType::Void << QVariant::String; | - | ||||||||||||||||||
1731 | - | |||||||||||||||||||
1732 | hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)"); | - | ||||||||||||||||||
1733 | ((!(hook.midx != -1)) ? qt_assert("hook.midx != -1",__FILE__,18171822) : qt_noop()); | - | ||||||||||||||||||
1734 | signalHooks.insert(QLatin1String("NameAcquired:" "org.freedesktop.DBus"), hook); | - | ||||||||||||||||||
1735 | - | |||||||||||||||||||
1736 | hook.midx = staticMetaObject.indexOfSlot("unregisterServiceNoLock(QString)"); | - | ||||||||||||||||||
1737 | ((!(hook.midx != -1)) ? qt_assert("hook.midx != -1",__FILE__,18211826) : qt_noop()); | - | ||||||||||||||||||
1738 | signalHooks.insert(QLatin1String("NameLost:" "org.freedesktop.DBus"), hook); | - | ||||||||||||||||||
1739 | - | |||||||||||||||||||
1740 | - | |||||||||||||||||||
1741 | - | |||||||||||||||||||
1742 | hook.params.clear(); | - | ||||||||||||||||||
1743 | hook.params.reserve(4); | - | ||||||||||||||||||
1744 | hook.params << QMetaType::Void << QVariant::String << QVariant::String << QVariant::String; | - | ||||||||||||||||||
1745 | hook.midx = staticMetaObject.indexOfSlot("serviceOwnerChangedNoLock(QString,QString,QString)"); | - | ||||||||||||||||||
1746 | ((!(hook.midx != -1)) ? qt_assert("hook.midx != -1",__FILE__,18301835) : qt_noop()); | - | ||||||||||||||||||
1747 | signalHooks.insert(QLatin1String("NameOwnerChanged:" "org.freedesktop.DBus"), hook); | - | ||||||||||||||||||
1748 | - | |||||||||||||||||||
1749 | watchForDBusDisconnection(); | - | ||||||||||||||||||
1750 | - | |||||||||||||||||||
1751 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 18351840, __PRETTY_FUNCTION__).debug() << this << ": connected successfully"; | - | ||||||||||||||||||
1752 | - | |||||||||||||||||||
1753 | - | |||||||||||||||||||
1754 | QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection); | - | ||||||||||||||||||
1755 | } | - | ||||||||||||||||||
1756 | - | |||||||||||||||||||
1757 | extern "C"{ | - | ||||||||||||||||||
1758 | static void qDBusResultReceived(DBusPendingCall *pending, void *user_data) | - | ||||||||||||||||||
1759 | { | - | ||||||||||||||||||
1760 | QDBusPendingCallPrivate *call = reinterpret_cast<QDBusPendingCallPrivate *>(user_data); | - | ||||||||||||||||||
1761 | ((!(call->pending == pending)) ? qt_assert("call->pending == pending",__FILE__,18451850) : qt_noop()); | - | ||||||||||||||||||
1762 | (void)pending;; | - | ||||||||||||||||||
1763 | QDBusConnectionPrivate::processFinishedCall(call); | - | ||||||||||||||||||
1764 | } | - | ||||||||||||||||||
1765 | } | - | ||||||||||||||||||
1766 | - | |||||||||||||||||||
1767 | void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call) | - | ||||||||||||||||||
1768 | { | - | ||||||||||||||||||
1769 | QDBusConnectionPrivate *connection = const_cast<QDBusConnectionPrivate *>(call->connection); | - | ||||||||||||||||||
1770 | - | |||||||||||||||||||
1771 | QMutexLocker locker(&call->mutex); | - | ||||||||||||||||||
1772 | - | |||||||||||||||||||
1773 | connection->pendingCalls.removeOne(call); | - | ||||||||||||||||||
1774 | - | |||||||||||||||||||
1775 | QDBusMessage &msg = call->replyMessage; | - | ||||||||||||||||||
1776 | if (call->pending
| 542-2064 | ||||||||||||||||||
1777 | - | |||||||||||||||||||
1778 | - | |||||||||||||||||||
1779 | if (q_dbus_pending_call_get_completed(call->pending)
| 0-2064 | ||||||||||||||||||
1780 | - | |||||||||||||||||||
1781 | DBusMessage *reply = q_dbus_pending_call_steal_reply(call->pending); | - | ||||||||||||||||||
1782 | msg = QDBusMessagePrivate::fromDBusMessage(reply, connection->capabilities); | - | ||||||||||||||||||
1783 | q_dbus_message_unref(reply); | - | ||||||||||||||||||
1784 | } executed 2064 times by 154 tests: else {end of block Executed by:
| 2064 | ||||||||||||||||||
1785 | msg = QDBusMessage::createError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage()); | - | ||||||||||||||||||
1786 | } never executed: end of block | 0 | ||||||||||||||||||
1787 | } | - | ||||||||||||||||||
1788 | if (::
executed 2606 times by 158 tests: else QMessageLogger(__FILE__, 18721877, __PRETTY_FUNCTION__).debug() << connection << "got message reply:" << msg;; Executed by:
never executed: QMessageLogger(__FILE__, 1877, __PRETTY_FUNCTION__).debug() << connection << "got message reply:" << msg; | 0-2606 | ||||||||||||||||||
1789 | - | |||||||||||||||||||
1790 | - | |||||||||||||||||||
1791 | call->checkReceivedSignature(); | - | ||||||||||||||||||
1792 | - | |||||||||||||||||||
1793 | if (!call->receiver.isNull()
| 0-2594 | ||||||||||||||||||
1794 | QDBusCallDeliveryEvent *e = prepareReply(connection, call->receiver, call->methodIdx, | - | ||||||||||||||||||
1795 | call->metaTypes, msg); | - | ||||||||||||||||||
1796 | if (e
| 0-9 | ||||||||||||||||||
1797 | connection->postEventToThread(MessageResultReceivedAction, call->receiver, e); executed 9 times by 4 tests: connection->postEventToThread(MessageResultReceivedAction, call->receiver, e); Executed by:
| 9 | ||||||||||||||||||
1798 | else | - | ||||||||||||||||||
1799 | if (::
never executed: else QMessageLogger(__FILE__, 18911896, __PRETTY_FUNCTION__).debug() << ("Deliver failed!";);; never executed: QMessageLogger(__FILE__, 1896, __PRETTY_FUNCTION__).debug("Deliver failed!"); | 0 | ||||||||||||||||||
1800 | } | - | ||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | if (call->pending
| 542-2064 | ||||||||||||||||||
1803 | q_dbus_pending_call_unref(call->pending); | - | ||||||||||||||||||
1804 | call->pending = 0; | - | ||||||||||||||||||
1805 | } executed 2064 times by 154 tests: end of block Executed by:
| 2064 | ||||||||||||||||||
1806 | - | |||||||||||||||||||
1807 | - | |||||||||||||||||||
1808 | if (call->watcherHelper
| 176-2430 | ||||||||||||||||||
1809 | call->watcherHelper->emitSignals(msg, call->sentMessage); executed 176 times by 21 tests: call->watcherHelper->emitSignals(msg, call->sentMessage); Executed by:
| 176 | ||||||||||||||||||
1810 | - | |||||||||||||||||||
1811 | call->waitForFinishedCondition.wakeAll(); | - | ||||||||||||||||||
1812 | locker.unlock(); | - | ||||||||||||||||||
1813 | - | |||||||||||||||||||
1814 | if (msg.type() == QDBusMessage::ErrorMessage
| 396-2210 | ||||||||||||||||||
1815 | connection->callWithCallbackFailed(QDBusError(msg), call->sentMessage); executed 396 times by 29 tests: connection->callWithCallbackFailed(QDBusError(msg), call->sentMessage); Executed by:
| 396 | ||||||||||||||||||
1816 | - | |||||||||||||||||||
1817 | if (!call->ref.deref()
| 732-1874 | ||||||||||||||||||
1818 | delete call; executed 732 times by 29 tests: delete call; Executed by:
| 732 | ||||||||||||||||||
1819 | } executed 2606 times by 158 tests: end of block Executed by:
| 2606 | ||||||||||||||||||
1820 | - | |||||||||||||||||||
1821 | bool QDBusConnectionPrivate::send(const QDBusMessage& message) | - | ||||||||||||||||||
1822 | { | - | ||||||||||||||||||
1823 | if (QDBusMessagePrivate::isLocal(message)) | - | ||||||||||||||||||
1824 | return true; | - | ||||||||||||||||||
1825 | - | |||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | QDBusError error; | - | ||||||||||||||||||
1828 | DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error); | - | ||||||||||||||||||
1829 | if (!msg) { | - | ||||||||||||||||||
1830 | if (message.type() == QDBusMessage::MethodCallMessage) | - | ||||||||||||||||||
1831 | QMessageLogger(__FILE__, 19231928, __PRETTY_FUNCTION__).warning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", | - | ||||||||||||||||||
1832 | QString(message.service()).toLocal8Bit().constData(), QString(message.path()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1833 | QString(message.interface()).toLocal8Bit().constData(), QString(message.member()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1834 | QString(error.message()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1835 | else if (message.type() == QDBusMessage::SignalMessage) | - | ||||||||||||||||||
1836 | QMessageLogger(__FILE__, 19281933, __PRETTY_FUNCTION__).warning("QDBusConnection: error: could not send signal to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", | - | ||||||||||||||||||
1837 | QString(message.service()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1838 | QString(message.path()).toLocal8Bit().constData(), QString(message.interface()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1839 | QString(message.member()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1840 | QString(error.message()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1841 | else | - | ||||||||||||||||||
1842 | QMessageLogger(__FILE__, 19341939, __PRETTY_FUNCTION__).warning("QDBusConnection: error: could not send %s message to service \"%s\": %s", | - | ||||||||||||||||||
1843 | message.type() == QDBusMessage::ReplyMessage ? "reply" : | - | ||||||||||||||||||
1844 | message.type() == QDBusMessage::ErrorMessage ? "error" : | - | ||||||||||||||||||
1845 | "invalid", QString(message.service()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1846 | QString(error.message()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1847 | lastError = error; | - | ||||||||||||||||||
1848 | return false; | - | ||||||||||||||||||
1849 | } | - | ||||||||||||||||||
1850 | - | |||||||||||||||||||
1851 | q_dbus_message_set_no_reply(msg, true); | - | ||||||||||||||||||
1852 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 19441949, __PRETTY_FUNCTION__).debug() << this << "sending message (no reply):" << message; | - | ||||||||||||||||||
1853 | messageNeedsSending(nullptr, msg); | - | ||||||||||||||||||
1854 | return true; | - | ||||||||||||||||||
1855 | } | - | ||||||||||||||||||
1856 | - | |||||||||||||||||||
1857 | - | |||||||||||||||||||
1858 | - | |||||||||||||||||||
1859 | - | |||||||||||||||||||
1860 | - | |||||||||||||||||||
1861 | - | |||||||||||||||||||
1862 | - | |||||||||||||||||||
1863 | class QDBusBlockingCallWatcher | - | ||||||||||||||||||
1864 | { | - | ||||||||||||||||||
1865 | public: | - | ||||||||||||||||||
1866 | QDBusBlockingCallWatcher(const QDBusMessage &message) | - | ||||||||||||||||||
1867 | : m_message(message), m_maxCallTimeoutMs(0) | - | ||||||||||||||||||
1868 | { | - | ||||||||||||||||||
1869 | - | |||||||||||||||||||
1870 | - | |||||||||||||||||||
1871 | - | |||||||||||||||||||
1872 | - | |||||||||||||||||||
1873 | - | |||||||||||||||||||
1874 | - | |||||||||||||||||||
1875 | static int mainThreadWarningAmount = 200; | - | ||||||||||||||||||
1876 | static int otherThreadWarningAmount = 500; | - | ||||||||||||||||||
1877 | - | |||||||||||||||||||
1878 | static bool initializedAmounts = false; | - | ||||||||||||||||||
1879 | static QBasicMutex initializeMutex; | - | ||||||||||||||||||
1880 | QMutexLocker locker(&initializeMutex); | - | ||||||||||||||||||
1881 | - | |||||||||||||||||||
1882 | if (!initializedAmounts) { | - | ||||||||||||||||||
1883 | int tmp = 0; | - | ||||||||||||||||||
1884 | QByteArray env; | - | ||||||||||||||||||
1885 | bool ok = true; | - | ||||||||||||||||||
1886 | - | |||||||||||||||||||
1887 | env = qgetenv("Q_DBUS_BLOCKING_CALL_MAIN_THREAD_WARNING_MS"); | - | ||||||||||||||||||
1888 | if (!env.isEmpty()) { | - | ||||||||||||||||||
1889 | tmp = env.toInt(&ok); | - | ||||||||||||||||||
1890 | if (ok) | - | ||||||||||||||||||
1891 | mainThreadWarningAmount = tmp; | - | ||||||||||||||||||
1892 | else | - | ||||||||||||||||||
1893 | QMessageLogger(__FILE__, 19851990, __PRETTY_FUNCTION__).warning("QDBusBlockingCallWatcher: Q_DBUS_BLOCKING_CALL_MAIN_THREAD_WARNING_MS must be an integer; value ignored"); | - | ||||||||||||||||||
1894 | } | - | ||||||||||||||||||
1895 | - | |||||||||||||||||||
1896 | env = qgetenv("Q_DBUS_BLOCKING_CALL_OTHER_THREAD_WARNING_MS"); | - | ||||||||||||||||||
1897 | if (!env.isEmpty()) { | - | ||||||||||||||||||
1898 | tmp = env.toInt(&ok); | - | ||||||||||||||||||
1899 | if (ok) | - | ||||||||||||||||||
1900 | otherThreadWarningAmount = tmp; | - | ||||||||||||||||||
1901 | else | - | ||||||||||||||||||
1902 | QMessageLogger(__FILE__, 19941999, __PRETTY_FUNCTION__).warning("QDBusBlockingCallWatcher: Q_DBUS_BLOCKING_CALL_OTHER_THREAD_WARNING_MS must be an integer; value ignored"); | - | ||||||||||||||||||
1903 | } | - | ||||||||||||||||||
1904 | - | |||||||||||||||||||
1905 | initializedAmounts = true; | - | ||||||||||||||||||
1906 | } | - | ||||||||||||||||||
1907 | - | |||||||||||||||||||
1908 | locker.unlock(); | - | ||||||||||||||||||
1909 | - | |||||||||||||||||||
1910 | - | |||||||||||||||||||
1911 | - | |||||||||||||||||||
1912 | - | |||||||||||||||||||
1913 | if (QCoreApplication::instance() && QCoreApplication::instance()->thread() == QThread::currentThread()) | - | ||||||||||||||||||
1914 | m_maxCallTimeoutMs = mainThreadWarningAmount; | - | ||||||||||||||||||
1915 | else | - | ||||||||||||||||||
1916 | m_maxCallTimeoutMs = otherThreadWarningAmount; | - | ||||||||||||||||||
1917 | - | |||||||||||||||||||
1918 | m_callTimer.start(); | - | ||||||||||||||||||
1919 | } | - | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | ~QDBusBlockingCallWatcher() | - | ||||||||||||||||||
1922 | { | - | ||||||||||||||||||
1923 | if (m_maxCallTimeoutMs < 0) | - | ||||||||||||||||||
1924 | return; | - | ||||||||||||||||||
1925 | - | |||||||||||||||||||
1926 | if (m_callTimer.elapsed() >= m_maxCallTimeoutMs) { | - | ||||||||||||||||||
1927 | QMessageLogger(__FILE__, 20192024, __PRETTY_FUNCTION__).warning("QDBusConnection: warning: blocking call took a long time (%d ms, max for this thread is %d ms) to service \"%s\" path \"%s\" interface \"%s\" member \"%s\"", | - | ||||||||||||||||||
1928 | int(m_callTimer.elapsed()), m_maxCallTimeoutMs, | - | ||||||||||||||||||
1929 | QString(m_message.service()).toLocal8Bit().constData(), QString(m_message.path()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1930 | QString(m_message.interface()).toLocal8Bit().constData(), QString(m_message.member()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1931 | } | - | ||||||||||||||||||
1932 | } | - | ||||||||||||||||||
1933 | - | |||||||||||||||||||
1934 | private: | - | ||||||||||||||||||
1935 | QDBusMessage m_message; | - | ||||||||||||||||||
1936 | int m_maxCallTimeoutMs; | - | ||||||||||||||||||
1937 | QElapsedTimer m_callTimer; | - | ||||||||||||||||||
1938 | }; | - | ||||||||||||||||||
1939 | - | |||||||||||||||||||
1940 | - | |||||||||||||||||||
1941 | QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message, | - | ||||||||||||||||||
1942 | int sendMode, int timeout) | - | ||||||||||||||||||
1943 | { | - | ||||||||||||||||||
1944 | QDBusBlockingCallWatcher watcher(message); | - | ||||||||||||||||||
1945 | - | |||||||||||||||||||
1946 | QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, 0, 0, 0, timeout); | - | ||||||||||||||||||
1947 | ((!(pcall)) ? qt_assert("pcall",__FILE__,20392044) : qt_noop()); | - | ||||||||||||||||||
1948 | - | |||||||||||||||||||
1949 | if (pcall->replyMessage.type() == QDBusMessage::InvalidMessage
| 953-1150 | ||||||||||||||||||
1950 | - | |||||||||||||||||||
1951 | if (sendMode == QDBus::BlockWithGui
| 131-1019 | ||||||||||||||||||
1952 | pcall->watcherHelper = new QDBusPendingCallWatcherHelper; | - | ||||||||||||||||||
1953 | QEventLoop loop; | - | ||||||||||||||||||
1954 | loop.connect(pcall->watcherHelper, qFlagLocation("2""reply(QDBusMessage)" "\0" __FILE__ ":" "2046"), qFlagLocation("1""quit()" "\0" __FILE__ ":" "2046"));&QDBusPendingCallWatcherHelper::reply, &loop, &QEventLoop::quit); | - | ||||||||||||||||||
1955 | loop.connect(pcall->watcherHelper, qFlagLocation("2""error(QDBusError&QDBusPendingCallWatcherHelper::error, QDBusMessage)" "\0" __FILE__ ":" "2047"), qFlagLocation("1""quit()" "\0" __FILE__ ":" "2047"));&loop, &QEventLoop::quit); | - | ||||||||||||||||||
1956 | - | |||||||||||||||||||
1957 | - | |||||||||||||||||||
1958 | loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents); | - | ||||||||||||||||||
1959 | } executed 131 times by 4 tests: else {end of block Executed by:
| 131 | ||||||||||||||||||
1960 | pcall->waitForFinished(); | - | ||||||||||||||||||
1961 | } executed 1019 times by 153 tests: end of block Executed by:
| 1019 | ||||||||||||||||||
1962 | } | - | ||||||||||||||||||
1963 | - | |||||||||||||||||||
1964 | QDBusMessage reply = pcall->replyMessage; | - | ||||||||||||||||||
1965 | lastError = QDBusError(reply); | - | ||||||||||||||||||
1966 | - | |||||||||||||||||||
1967 | if (!pcall->ref.deref()
| 638-1465 | ||||||||||||||||||
1968 | delete pcall; executed 1465 times by 153 tests: delete pcall; Executed by:
| 1465 | ||||||||||||||||||
1969 | return executed 2103 times by 158 tests: reply;return reply; Executed by:
executed 2103 times by 158 tests: return reply; Executed by:
| 2103 | ||||||||||||||||||
1970 | } | - | ||||||||||||||||||
1971 | - | |||||||||||||||||||
1972 | QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal(const QDBusMessage &message) | - | ||||||||||||||||||
1973 | { | - | ||||||||||||||||||
1974 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 20662071, __PRETTY_FUNCTION__).debug() << this << "sending message via local-loop:" << message; | - | ||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | QDBusMessage localCallMsg = QDBusMessagePrivate::makeLocal(*this, message); | - | ||||||||||||||||||
1977 | bool handled = handleMessage(localCallMsg); | - | ||||||||||||||||||
1978 | - | |||||||||||||||||||
1979 | if (!handled) { | - | ||||||||||||||||||
1980 | QString interface = message.interface(); | - | ||||||||||||||||||
1981 | if (interface.isEmpty()) | - | ||||||||||||||||||
1982 | interface = QLatin1String("<no-interface>"); | - | ||||||||||||||||||
1983 | return QDBusMessage::createError(QDBusError::InternalError, | - | ||||||||||||||||||
1984 | QString::fromLatin1("Internal error trying to call %1.%2 at %3 (signature '%4'") | - | ||||||||||||||||||
1985 | .arg(interface, message.member(), | - | ||||||||||||||||||
1986 | message.path(), message.signature())); | - | ||||||||||||||||||
1987 | } | - | ||||||||||||||||||
1988 | - | |||||||||||||||||||
1989 | - | |||||||||||||||||||
1990 | QDBusMessage localReplyMsg = QDBusMessagePrivate::makeLocalReply(*this, localCallMsg); | - | ||||||||||||||||||
1991 | if (localReplyMsg.type() == QDBusMessage::InvalidMessage) { | - | ||||||||||||||||||
1992 | QMessageLogger(__FILE__, 20842089, __PRETTY_FUNCTION__).warning("QDBusConnection: cannot call local method '%s' at object %s (with signature '%s') " | - | ||||||||||||||||||
1993 | "on blocking mode", QString(message.member()).toLocal8Bit().constData(), QString(message.path()).toLocal8Bit().constData(), | - | ||||||||||||||||||
1994 | QString(message.signature()).toLocal8Bit().constData()); | - | ||||||||||||||||||
1995 | return QDBusMessage::createError( | - | ||||||||||||||||||
1996 | QDBusError(QDBusError::InternalError, | - | ||||||||||||||||||
1997 | QLatin1String("local-loop message cannot have delayed replies"))); | - | ||||||||||||||||||
1998 | } | - | ||||||||||||||||||
1999 | - | |||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 20932098, __PRETTY_FUNCTION__).debug() << this << "got message via local-loop:" << localReplyMsg; | - | ||||||||||||||||||
2002 | return localReplyMsg; | - | ||||||||||||||||||
2003 | } | - | ||||||||||||||||||
2004 | - | |||||||||||||||||||
2005 | QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusMessage &message, | - | ||||||||||||||||||
2006 | QObject *receiver, const char *returnMethod, | - | ||||||||||||||||||
2007 | const char *errorMethod, int timeout) | - | ||||||||||||||||||
2008 | { | - | ||||||||||||||||||
2009 | QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this); | - | ||||||||||||||||||
2010 | bool isLoopback; | - | ||||||||||||||||||
2011 | if ((isLoopback = isServiceRegisteredByThread(message.service()))) { | - | ||||||||||||||||||
2012 | - | |||||||||||||||||||
2013 | pcall->replyMessage = sendWithReplyLocal(message); | - | ||||||||||||||||||
2014 | } | - | ||||||||||||||||||
2015 | - | |||||||||||||||||||
2016 | if (receiver && returnMethod) | - | ||||||||||||||||||
2017 | pcall->setReplyCallback(receiver, returnMethod); | - | ||||||||||||||||||
2018 | - | |||||||||||||||||||
2019 | if (errorMethod) { | - | ||||||||||||||||||
2020 | pcall->watcherHelper = new QDBusPendingCallWatcherHelper; | - | ||||||||||||||||||
2021 | connect(pcall->watcherHelper, qFlagLocation("2""error(QDBusError,QDBusMessage)" "\0" __FILE__ ":" "2113""2118"), receiver, errorMethod, | - | ||||||||||||||||||
2022 | Qt::QueuedConnection); | - | ||||||||||||||||||
2023 | pcall->watcherHelper->moveToThread(thread()); | - | ||||||||||||||||||
2024 | } | - | ||||||||||||||||||
2025 | - | |||||||||||||||||||
2026 | if ((receiver && returnMethod) || errorMethod) { | - | ||||||||||||||||||
2027 | - | |||||||||||||||||||
2028 | pcall->ref.store(1); | - | ||||||||||||||||||
2029 | } else { | - | ||||||||||||||||||
2030 | - | |||||||||||||||||||
2031 | - | |||||||||||||||||||
2032 | pcall->ref.store(2); | - | ||||||||||||||||||
2033 | } | - | ||||||||||||||||||
2034 | - | |||||||||||||||||||
2035 | if (isLoopback) { | - | ||||||||||||||||||
2036 | - | |||||||||||||||||||
2037 | processFinishedCall(pcall); | - | ||||||||||||||||||
2038 | return pcall; | - | ||||||||||||||||||
2039 | } | - | ||||||||||||||||||
2040 | - | |||||||||||||||||||
2041 | QDBusError error; | - | ||||||||||||||||||
2042 | DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error); | - | ||||||||||||||||||
2043 | if (!msg) { | - | ||||||||||||||||||
2044 | QMessageLogger(__FILE__, 21362141, __PRETTY_FUNCTION__).warning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", | - | ||||||||||||||||||
2045 | QString(message.service()).toLocal8Bit().constData(), QString(message.path()).toLocal8Bit().constData(), | - | ||||||||||||||||||
2046 | QString(message.interface()).toLocal8Bit().constData(), QString(message.member()).toLocal8Bit().constData(), | - | ||||||||||||||||||
2047 | QString(error.message()).toLocal8Bit().constData()); | - | ||||||||||||||||||
2048 | pcall->replyMessage = QDBusMessage::createError(error); | - | ||||||||||||||||||
2049 | lastError = error; | - | ||||||||||||||||||
2050 | processFinishedCall(pcall); | - | ||||||||||||||||||
2051 | } else { | - | ||||||||||||||||||
2052 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 21442149, __PRETTY_FUNCTION__).debug() << this << "sending message:" << message; | - | ||||||||||||||||||
2053 | messageNeedsSending(pcall, msg, timeout); | - | ||||||||||||||||||
2054 | } | - | ||||||||||||||||||
2055 | return pcall; | - | ||||||||||||||||||
2056 | } | - | ||||||||||||||||||
2057 | - | |||||||||||||||||||
2058 | void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *message, int timeout) | - | ||||||||||||||||||
2059 | { | - | ||||||||||||||||||
2060 | QDBusError error; | - | ||||||||||||||||||
2061 | DBusPendingCall *pending = 0; | - | ||||||||||||||||||
2062 | DBusMessage *msg = static_cast<DBusMessage *>(message); | - | ||||||||||||||||||
2063 | bool isNoReply = !pcall; | - | ||||||||||||||||||
2064 | ((!(isNoReply == !!q_dbus_message_get_no_reply(msg))) ? qt_assert("isNoReply == !!q_dbus_message_get_no_reply(msg)",__FILE__,21562161) : qt_noop()); | - | ||||||||||||||||||
2065 | - | |||||||||||||||||||
2066 | checkThread(); | - | ||||||||||||||||||
2067 | QDBusDispatchLocker locker(SendMessageAction, this); | - | ||||||||||||||||||
2068 | - | |||||||||||||||||||
2069 | if (isNoReply && q_dbus_connection_send(connection, msg, nullptr)) { | - | ||||||||||||||||||
2070 | - | |||||||||||||||||||
2071 | } else if (!isNoReply && q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) { | - | ||||||||||||||||||
2072 | if (pending) { | - | ||||||||||||||||||
2073 | q_dbus_message_unref(msg); | - | ||||||||||||||||||
2074 | - | |||||||||||||||||||
2075 | pcall->pending = pending; | - | ||||||||||||||||||
2076 | q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, 0); | - | ||||||||||||||||||
2077 | - | |||||||||||||||||||
2078 | - | |||||||||||||||||||
2079 | if (mode == QDBusConnectionPrivate::PeerMode || mode == QDBusConnectionPrivate::ClientMode) | - | ||||||||||||||||||
2080 | pendingCalls.append(pcall); | - | ||||||||||||||||||
2081 | - | |||||||||||||||||||
2082 | return; | - | ||||||||||||||||||
2083 | } else { | - | ||||||||||||||||||
2084 | - | |||||||||||||||||||
2085 | lastError = error = QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage()); | - | ||||||||||||||||||
2086 | } | - | ||||||||||||||||||
2087 | } else { | - | ||||||||||||||||||
2088 | lastError = error = QDBusError(QDBusError::NoMemory, ([]() -> QString { enum { Size = sizeof(u"" "Out of memory")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Out of memory" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||
2089 | } | - | ||||||||||||||||||
2090 | - | |||||||||||||||||||
2091 | q_dbus_message_unref(msg); | - | ||||||||||||||||||
2092 | if (pcall) { | - | ||||||||||||||||||
2093 | pcall->replyMessage = QDBusMessage::createError(error); | - | ||||||||||||||||||
2094 | processFinishedCall(pcall); | - | ||||||||||||||||||
2095 | } | - | ||||||||||||||||||
2096 | } | - | ||||||||||||||||||
2097 | - | |||||||||||||||||||
2098 | bool QDBusConnectionPrivate::connectSignal(const QString &service, | - | ||||||||||||||||||
2099 | const QString &path, const QString &interface, const QString &name, | - | ||||||||||||||||||
2100 | const QStringList &argumentMatch, const QString &signature, | - | ||||||||||||||||||
2101 | QObject *receiver, const char *slot) | - | ||||||||||||||||||
2102 | { | - | ||||||||||||||||||
2103 | - | |||||||||||||||||||
2104 | QDBusConnectionPrivate::SignalHook hook; | - | ||||||||||||||||||
2105 | QString key; | - | ||||||||||||||||||
2106 | QString name2 = name; | - | ||||||||||||||||||
2107 | if (name2.isNull()) | - | ||||||||||||||||||
2108 | name2.detach(); | - | ||||||||||||||||||
2109 | - | |||||||||||||||||||
2110 | hook.signature = signature; | - | ||||||||||||||||||
2111 | if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false)) | - | ||||||||||||||||||
2112 | return false; | - | ||||||||||||||||||
2113 | - | |||||||||||||||||||
2114 | ((!(thread() != QThread::currentThread())) ? qt_assert("thread() != QThread::currentThread()",__FILE__,22062211) : qt_noop()); | - | ||||||||||||||||||
2115 | signalNeedsConnecting(key, hook); | - | ||||||||||||||||||
2116 | return true; | - | ||||||||||||||||||
2117 | } | - | ||||||||||||||||||
2118 | - | |||||||||||||||||||
2119 | void QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook &hook) | - | ||||||||||||||||||
2120 | { | - | ||||||||||||||||||
2121 | QDBusWriteLocker locker(ConnectAction, this); | - | ||||||||||||||||||
2122 | - | |||||||||||||||||||
2123 | - | |||||||||||||||||||
2124 | QDBusConnectionPrivate::SignalHookHash::ConstIterator it = signalHooks.constFind(key); | - | ||||||||||||||||||
2125 | QDBusConnectionPrivate::SignalHookHash::ConstIterator end = signalHooks.constEnd(); | - | ||||||||||||||||||
2126 | for ( ; it != end
| 714-3232 | ||||||||||||||||||
2127 | const QDBusConnectionPrivate::SignalHook &entry = it.value(); | - | ||||||||||||||||||
2128 | if (entry.service == hook.service
| 15-2485 | ||||||||||||||||||
2129 | entry.path == hook.path
| 34-2451 | ||||||||||||||||||
2130 | entry.signature == hook.signature
| 18-2433 | ||||||||||||||||||
2131 | entry.obj == hook.obj
| 58-2375 | ||||||||||||||||||
2132 | entry.midx == hook.midx
| 0-58 | ||||||||||||||||||
2133 | entry.argumentMatch == hook.argumentMatch
| 0-58 | ||||||||||||||||||
2134 | - | |||||||||||||||||||
2135 | return; executed 58 times by 18 tests: return; Executed by:
| 58 | ||||||||||||||||||
2136 | } | - | ||||||||||||||||||
2137 | } executed 2442 times by 156 tests: end of block Executed by:
| 2442 | ||||||||||||||||||
2138 | - | |||||||||||||||||||
2139 | signalHooks.insertMulti(key, hook); | - | ||||||||||||||||||
2140 | connect(hook.obj, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "2232"), qFlagLocation("1""objectDestroyed(QObject*)" "\0" __FILE__ ":" "2232"),&QObject::destroyed, this, &QDBusConnectionPrivate::objectDestroyed, | - | ||||||||||||||||||
2141 | Qt::ConnectionType(Qt::BlockingQueuedConnection | Qt::UniqueConnection)); | - | ||||||||||||||||||
2142 | - | |||||||||||||||||||
2143 | MatchRefCountHash::iterator mit = matchRefCounts.find(hook.matchRule); | - | ||||||||||||||||||
2144 | - | |||||||||||||||||||
2145 | if (mit != matchRefCounts.end()
| 288-1158 | ||||||||||||||||||
2146 | mit.value() = mit.value() + 1; | - | ||||||||||||||||||
2147 | return; executed 288 times by 21 tests: return; Executed by:
| 288 | ||||||||||||||||||
2148 | } | - | ||||||||||||||||||
2149 | - | |||||||||||||||||||
2150 | matchRefCounts.insert(hook.matchRule, 1); | - | ||||||||||||||||||
2151 | - | |||||||||||||||||||
2152 | if (connection
| 0-1158 | ||||||||||||||||||
2153 | if (mode != QDBusConnectionPrivate::PeerMode
| 111-1047 | ||||||||||||||||||
2154 | if (::
executed 1047 times by 156 tests: else QMessageLogger(__FILE__, 22462251, __PRETTY_FUNCTION__).debug() << this << "Adding rule:" << hook.matchRule;; Executed by:
never executed: QMessageLogger(__FILE__, 2251, __PRETTY_FUNCTION__).debug() << this << "Adding rule:" << hook.matchRule; | 0-1047 | ||||||||||||||||||
2155 | q_dbus_bus_add_match(connection, hook.matchRule, __null); | - | ||||||||||||||||||
2156 | - | |||||||||||||||||||
2157 | - | |||||||||||||||||||
2158 | - | |||||||||||||||||||
2159 | if (shouldWatchService(hook.service)
| 485-562 | ||||||||||||||||||
2160 | WatchedServicesHash::mapped_type &data = watchedServices[hook.service]; | - | ||||||||||||||||||
2161 | if (++
| 112-373 | ||||||||||||||||||
2162 | - | |||||||||||||||||||
2163 | q_dbus_bus_add_match(connection, | - | ||||||||||||||||||
2164 | buildMatchRule(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), | - | ||||||||||||||||||
2165 | QDBusUtil::nameOwnerChanged(), QStringList() << hook.service, QString()), | - | ||||||||||||||||||
2166 | __null); | - | ||||||||||||||||||
2167 | data.owner = getNameOwnerNoCache(hook.service); | - | ||||||||||||||||||
2168 | if (::
executed 112 times by 23 tests: else QMessageLogger(__FILE__, 22602265, __PRETTY_FUNCTION__).debug() << this << "Watching service" << hook.service << "for owner changes (current owner:"; Executed by:
never executed: QMessageLogger(__FILE__, 2265, __PRETTY_FUNCTION__).debug() << this << "Watching service" << hook.service << "for owner changes (current owner:" << data.owner << ")"; | 0-112 | ||||||||||||||||||
2169 | << data.owner << ")"; never executed: QMessageLogger(__FILE__, 2265, __PRETTY_FUNCTION__).debug() << this << "Watching service" << hook.service << "for owner changes (current owner:" << data.owner << ")"; | 0 | ||||||||||||||||||
2170 | } | - | ||||||||||||||||||
2171 | } executed 485 times by 23 tests: end of block Executed by:
| 485 | ||||||||||||||||||
2172 | } executed 1047 times by 156 tests: end of block Executed by:
| 1047 | ||||||||||||||||||
2173 | } executed 1158 times by 156 tests: end of block Executed by:
| 1158 | ||||||||||||||||||
2174 | } executed 1158 times by 156 tests: end of block Executed by:
| 1158 | ||||||||||||||||||
2175 | - | |||||||||||||||||||
2176 | bool QDBusConnectionPrivate::disconnectSignal(const QString &service, | - | ||||||||||||||||||
2177 | const QString &path, const QString &interface, const QString &name, | - | ||||||||||||||||||
2178 | const QStringList &argumentMatch, const QString &signature, | - | ||||||||||||||||||
2179 | QObject *receiver, const char *slot) | - | ||||||||||||||||||
2180 | { | - | ||||||||||||||||||
2181 | - | |||||||||||||||||||
2182 | QDBusConnectionPrivate::SignalHook hook; | - | ||||||||||||||||||
2183 | QString key; | - | ||||||||||||||||||
2184 | QString name2 = name; | - | ||||||||||||||||||
2185 | if (name2.isNull()) | - | ||||||||||||||||||
2186 | name2.detach(); | - | ||||||||||||||||||
2187 | - | |||||||||||||||||||
2188 | hook.signature = signature; | - | ||||||||||||||||||
2189 | if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false)) | - | ||||||||||||||||||
2190 | return false; | - | ||||||||||||||||||
2191 | - | |||||||||||||||||||
2192 | ((!(thread() != QThread::currentThread())) ? qt_assert("thread() != QThread::currentThread()",__FILE__,22842289) : qt_noop()); | - | ||||||||||||||||||
2193 | return signalNeedsDisconnecting(key, hook); | - | ||||||||||||||||||
2194 | } | - | ||||||||||||||||||
2195 | - | |||||||||||||||||||
2196 | bool QDBusConnectionPrivate::removeSignalHook(const QString &key, const SignalHook &hook) | - | ||||||||||||||||||
2197 | { | - | ||||||||||||||||||
2198 | - | |||||||||||||||||||
2199 | QDBusWriteLocker locker(ConnectAction, this); | - | ||||||||||||||||||
2200 | QDBusConnectionPrivate::SignalHookHash::Iterator it = signalHooks.find(key); | - | ||||||||||||||||||
2201 | QDBusConnectionPrivate::SignalHookHash::Iterator end = signalHooks.end(); | - | ||||||||||||||||||
2202 | for ( ; it != end && it.key() == key; ++it) { | - | ||||||||||||||||||
2203 | const QDBusConnectionPrivate::SignalHook &entry = it.value(); | - | ||||||||||||||||||
2204 | if (entry.service == hook.service && | - | ||||||||||||||||||
2205 | entry.path == hook.path && | - | ||||||||||||||||||
2206 | entry.signature == hook.signature && | - | ||||||||||||||||||
2207 | entry.obj == hook.obj && | - | ||||||||||||||||||
2208 | entry.midx == hook.midx && | - | ||||||||||||||||||
2209 | entry.argumentMatch == hook.argumentMatch) { | - | ||||||||||||||||||
2210 | - | |||||||||||||||||||
2211 | removeSignalHookNoLock(it); | - | ||||||||||||||||||
2212 | return true; | - | ||||||||||||||||||
2213 | } | - | ||||||||||||||||||
2214 | } | - | ||||||||||||||||||
2215 | - | |||||||||||||||||||
2216 | - | |||||||||||||||||||
2217 | return false; | - | ||||||||||||||||||
2218 | } | - | ||||||||||||||||||
2219 | - | |||||||||||||||||||
2220 | QDBusConnectionPrivate::SignalHookHash::Iterator | - | ||||||||||||||||||
2221 | QDBusConnectionPrivate::removeSignalHookNoLock(SignalHookHash::Iterator it) | - | ||||||||||||||||||
2222 | { | - | ||||||||||||||||||
2223 | const SignalHook &hook = it.value(); | - | ||||||||||||||||||
2224 | - | |||||||||||||||||||
2225 | bool erase = false; | - | ||||||||||||||||||
2226 | MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule); | - | ||||||||||||||||||
2227 | if (i == matchRefCounts.end()) { | - | ||||||||||||||||||
2228 | QMessageLogger(__FILE__, 23202325, __PRETTY_FUNCTION__).warning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!"); | - | ||||||||||||||||||
2229 | } else { | - | ||||||||||||||||||
2230 | if (i.value() == 1) { | - | ||||||||||||||||||
2231 | erase = true; | - | ||||||||||||||||||
2232 | matchRefCounts.erase(i); | - | ||||||||||||||||||
2233 | } | - | ||||||||||||||||||
2234 | else { | - | ||||||||||||||||||
2235 | i.value() = i.value() - 1; | - | ||||||||||||||||||
2236 | } | - | ||||||||||||||||||
2237 | } | - | ||||||||||||||||||
2238 | - | |||||||||||||||||||
2239 | - | |||||||||||||||||||
2240 | if (connection && erase) { | - | ||||||||||||||||||
2241 | if (mode != QDBusConnectionPrivate::PeerMode) { | - | ||||||||||||||||||
2242 | if (::isDebugging == 0); else QMessageLogger(__FILE__, 23342339, __PRETTY_FUNCTION__).debug() << this << "Removing rule:" << hook.matchRule; | - | ||||||||||||||||||
2243 | q_dbus_bus_remove_match(connection, hook.matchRule, __null); | - | ||||||||||||||||||
2244 | - | |||||||||||||||||||
2245 | - | |||||||||||||||||||
2246 | - | |||||||||||||||||||
2247 | WatchedServicesHash::Iterator sit = watchedServices.find(hook.service); | - | ||||||||||||||||||
2248 | if (sit != watchedServices.end()) { | - | ||||||||||||||||||
2249 | if (--sit.value().refcount == 0) { | - | ||||||||||||||||||
2250 | watchedServices.erase(sit); | - | ||||||||||||||||||
2251 | q_dbus_bus_remove_match(connection, | - | ||||||||||||||||||
2252 | buildMatchRule(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), | - | ||||||||||||||||||
2253 | QDBusUtil::nameOwnerChanged(), QStringList() << hook.service, QString()), | - | ||||||||||||||||||
2254 | __null); | - | ||||||||||||||||||
2255 | } | - | ||||||||||||||||||
2256 | } | - | ||||||||||||||||||
2257 | } | - | ||||||||||||||||||
2258 | - | |||||||||||||||||||
2259 | } | - | ||||||||||||||||||
2260 | - | |||||||||||||||||||
2261 | return signalHooks.erase(it); | - | ||||||||||||||||||
2262 | } | - | ||||||||||||||||||
2263 | - | |||||||||||||||||||
2264 | void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) | - | ||||||||||||||||||
2265 | { | - | ||||||||||||||||||
2266 | connect(node->obj, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "2358"), qFlagLocation("1""objectDestroyed(QObject*)" "\0" __FILE__ ":" "2358"),&QObject::destroyed, this, &QDBusConnectionPrivate::objectDestroyed, | - | ||||||||||||||||||
2267 | Qt::ConnectionType(Qt::BlockingQueuedConnection | Qt::UniqueConnection)); | - | ||||||||||||||||||
2268 | - | |||||||||||||||||||
2269 | if (node->flags & (QDBusConnection::ExportAdaptors
| 141-246 | ||||||||||||||||||
2270 | | QDBusConnection::ExportScriptableSignals
| 141-246 | ||||||||||||||||||
2271 | | QDBusConnection::ExportNonScriptableSignals)
| 141-246 | ||||||||||||||||||
2272 | QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(node->obj); | - | ||||||||||||||||||
2273 | - | |||||||||||||||||||
2274 | if (node->flags & (QDBusConnection::ExportScriptableSignals
| 86-160 | ||||||||||||||||||
2275 | | QDBusConnection::ExportNonScriptableSignals)
| 86-160 | ||||||||||||||||||
2276 | connector->disconnectAllSignals(node->obj); | - | ||||||||||||||||||
2277 | connector->connectAllSignals(node->obj); | - | ||||||||||||||||||
2278 | } executed 160 times by 7 tests: end of block Executed by:
| 160 | ||||||||||||||||||
2279 | - | |||||||||||||||||||
2280 | connect(connector, qFlagLocation("2""relaySignal(QObject*,const QMetaObject*,int,QVariantList)" "\0" __FILE__ ":" "2372""2377"), | - | ||||||||||||||||||
2281 | this, qFlagLocation("1""relaySignal(QObject*,const QMetaObject*,int,QVariantList)" "\0" __FILE__ ":" "2373""2378"), | - | ||||||||||||||||||
2282 | Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection)); | - | ||||||||||||||||||
2283 | } executed 246 times by 10 tests: end of block Executed by:
| 246 | ||||||||||||||||||
2284 | } executed 387 times by 14 tests: end of block Executed by:
| 387 | ||||||||||||||||||
2285 | - | |||||||||||||||||||
2286 | void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode) | - | ||||||||||||||||||
2287 | { | - | ||||||||||||||||||
2288 | QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode; | - | ||||||||||||||||||
2289 | QStringListQVector<QStringRef> pathComponents; | - | ||||||||||||||||||
2290 | int i; | - | ||||||||||||||||||
2291 | if (path == QLatin1String("/")
| 6-62 | ||||||||||||||||||
2292 | i = 0; | - | ||||||||||||||||||
2293 | } executed 6 times by 2 tests: else {end of block Executed by:
| 6 | ||||||||||||||||||
2294 | pathComponents = path.splitsplitRef(QLatin1Char('/')); | - | ||||||||||||||||||
2295 | i = 1; | - | ||||||||||||||||||
2296 | } executed 62 times by 3 tests: end of block Executed by:
| 62 | ||||||||||||||||||
2297 | - | |||||||||||||||||||
2298 | huntAndUnregister(pathComponents, i, mode, node); | - | ||||||||||||||||||
2299 | } executed 68 times by 3 tests: end of block Executed by:
| 68 | ||||||||||||||||||
2300 | - | |||||||||||||||||||
2301 | void QDBusConnectionPrivate::connectRelay(const QString &service, | - | ||||||||||||||||||
2302 | const QString &path, const QString &interface, | - | ||||||||||||||||||
2303 | QDBusAbstractInterface *receiver, | - | ||||||||||||||||||
2304 | const QMetaMethod &signal) | - | ||||||||||||||||||
2305 | { | - | ||||||||||||||||||
2306 | - | |||||||||||||||||||
2307 | - | |||||||||||||||||||
2308 | SignalHook hook; | - | ||||||||||||||||||
2309 | QString key; | - | ||||||||||||||||||
2310 | - | |||||||||||||||||||
2311 | QByteArray sig; | - | ||||||||||||||||||
2312 | sig.append(2 + '0'); | - | ||||||||||||||||||
2313 | sig.append(signal.methodSignature()); | - | ||||||||||||||||||
2314 | if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, sig, | - | ||||||||||||||||||
2315 | QDBusAbstractInterface::staticMetaObject.methodCount(), true)) | - | ||||||||||||||||||
2316 | return; | - | ||||||||||||||||||
2317 | - | |||||||||||||||||||
2318 | ((!(thread() != QThread::currentThread())) ? qt_assert("thread() != QThread::currentThread()",__FILE__,24102415) : qt_noop()); | - | ||||||||||||||||||
2319 | signalNeedsConnecting(key, hook); | - | ||||||||||||||||||
2320 | } | - | ||||||||||||||||||
2321 | - | |||||||||||||||||||
2322 | void QDBusConnectionPrivate::disconnectRelay(const QString &service, | - | ||||||||||||||||||
2323 | const QString &path, const QString &interface, | - | ||||||||||||||||||
2324 | QDBusAbstractInterface *receiver, | - | ||||||||||||||||||
2325 | const QMetaMethod &signal) | - | ||||||||||||||||||
2326 | { | - | ||||||||||||||||||
2327 | - | |||||||||||||||||||
2328 | - | |||||||||||||||||||
2329 | SignalHook hook; | - | ||||||||||||||||||
2330 | QString key; | - | ||||||||||||||||||
2331 | - | |||||||||||||||||||
2332 | QByteArray sig; | - | ||||||||||||||||||
2333 | sig.append(2 + '0'); | - | ||||||||||||||||||
2334 | sig.append(signal.methodSignature()); | - | ||||||||||||||||||
2335 | if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, sig, | - | ||||||||||||||||||
2336 | QDBusAbstractInterface::staticMetaObject.methodCount(), true)) | - | ||||||||||||||||||
2337 | return; | - | ||||||||||||||||||
2338 | - | |||||||||||||||||||
2339 | ((!(thread() != QThread::currentThread())) ? qt_assert("thread() != QThread::currentThread()",__FILE__,24312436) : qt_noop()); | - | ||||||||||||||||||
2340 | signalNeedsDisconnecting(key, hook); | - | ||||||||||||||||||
2341 | } | - | ||||||||||||||||||
2342 | - | |||||||||||||||||||
2343 | bool QDBusConnectionPrivate::shouldWatchService(const QString &service) | - | ||||||||||||||||||
2344 | { | - | ||||||||||||||||||
2345 | - | |||||||||||||||||||
2346 | if (mode != ClientMode) | - | ||||||||||||||||||
2347 | return false; | - | ||||||||||||||||||
2348 | - | |||||||||||||||||||
2349 | if (service.isEmpty()) | - | ||||||||||||||||||
2350 | return false; | - | ||||||||||||||||||
2351 | - | |||||||||||||||||||
2352 | if (service == QDBusUtil::dbusService()) | - | ||||||||||||||||||
2353 | return false; | - | ||||||||||||||||||
2354 | return true; | - | ||||||||||||||||||
2355 | } | - | ||||||||||||||||||
2356 | void QDBusConnectionPrivate::watchService(const QString &service, QDBusServiceWatcher::WatchMode mode, QObject *obj, const char *member) | - | ||||||||||||||||||
2357 | { | - | ||||||||||||||||||
2358 | QStringList matchArgs = matchArgsForService(service, mode); | - | ||||||||||||||||||
2359 | connectSignal(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), QDBusUtil::nameOwnerChanged(), | - | ||||||||||||||||||
2360 | matchArgs, QString(), obj, member); | - | ||||||||||||||||||
2361 | } | - | ||||||||||||||||||
2362 | void QDBusConnectionPrivate::unwatchService(const QString &service, QDBusServiceWatcher::WatchMode mode, QObject *obj, const char *member) | - | ||||||||||||||||||
2363 | { | - | ||||||||||||||||||
2364 | QStringList matchArgs = matchArgsForService(service, mode); | - | ||||||||||||||||||
2365 | disconnectSignal(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), QDBusUtil::nameOwnerChanged(), | - | ||||||||||||||||||
2366 | matchArgs, QString(), obj, member); | - | ||||||||||||||||||
2367 | } | - | ||||||||||||||||||
2368 | - | |||||||||||||||||||
2369 | QString QDBusConnectionPrivate::getNameOwner(const QString& serviceName) | - | ||||||||||||||||||
2370 | { | - | ||||||||||||||||||
2371 | if (QDBusUtil::isValidUniqueConnectionName(serviceName)) | - | ||||||||||||||||||
2372 | return serviceName; | - | ||||||||||||||||||
2373 | if (!connection) | - | ||||||||||||||||||
2374 | return QString(); | - | ||||||||||||||||||
2375 | - | |||||||||||||||||||
2376 | { | - | ||||||||||||||||||
2377 | - | |||||||||||||||||||
2378 | QReadLocker locker(&lock); | - | ||||||||||||||||||
2379 | WatchedServicesHash::ConstIterator it = watchedServices.constFind(serviceName); | - | ||||||||||||||||||
2380 | if (it != watchedServices.constEnd()) | - | ||||||||||||||||||
2381 | return it->owner; | - | ||||||||||||||||||
2382 | } | - | ||||||||||||||||||
2383 | - | |||||||||||||||||||
2384 | - | |||||||||||||||||||
2385 | return getNameOwnerNoCache(serviceName); | - | ||||||||||||||||||
2386 | } | - | ||||||||||||||||||
2387 | - | |||||||||||||||||||
2388 | QString QDBusConnectionPrivate::getNameOwnerNoCache(const QString &serviceName) | - | ||||||||||||||||||
2389 | { | - | ||||||||||||||||||
2390 | QDBusMessage msg = QDBusMessage::createMethodCall(QDBusUtil::dbusService(), | - | ||||||||||||||||||
2391 | QDBusUtil::dbusPath(), QDBusUtil::dbusInterface(), | - | ||||||||||||||||||
2392 | ([]() -> QString { enum { Size = sizeof(u"" "GetNameOwner")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "GetNameOwner" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||
2393 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
2394 | msg << serviceName; | - | ||||||||||||||||||
2395 | - | |||||||||||||||||||
2396 | QDBusPendingCallPrivate *pcall = sendWithReplyAsync(msg, nullptr, nullptr, nullptr); | - | ||||||||||||||||||
2397 | if (thread() == QThread::currentThread()) { | - | ||||||||||||||||||
2398 | - | |||||||||||||||||||
2399 | - | |||||||||||||||||||
2400 | q_dbus_pending_call_block(pcall->pending); | - | ||||||||||||||||||
2401 | } | - | ||||||||||||||||||
2402 | pcall->waitForFinished(); | - | ||||||||||||||||||
2403 | msg = pcall->replyMessage; | - | ||||||||||||||||||
2404 | - | |||||||||||||||||||
2405 | if (!pcall->ref.deref()) | - | ||||||||||||||||||
2406 | delete pcall; | - | ||||||||||||||||||
2407 | - | |||||||||||||||||||
2408 | if (msg.type() == QDBusMessage::ReplyMessage) | - | ||||||||||||||||||
2409 | return msg.arguments().at(0).toString(); | - | ||||||||||||||||||
2410 | return QString(); | - | ||||||||||||||||||
2411 | } | - | ||||||||||||||||||
2412 | - | |||||||||||||||||||
2413 | QDBusMetaObject * | - | ||||||||||||||||||
2414 | QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &path, | - | ||||||||||||||||||
2415 | const QString &interface, QDBusError &error) | - | ||||||||||||||||||
2416 | { | - | ||||||||||||||||||
2417 | - | |||||||||||||||||||
2418 | if (!interface.isEmpty()) { | - | ||||||||||||||||||
2419 | QDBusReadLocker locker(FindMetaObject1Action, this); | - | ||||||||||||||||||
2420 | QDBusMetaObject *mo = cachedMetaObjects.value(interface, 0); | - | ||||||||||||||||||
2421 | if (mo) | - | ||||||||||||||||||
2422 | return mo; | - | ||||||||||||||||||
2423 | } | - | ||||||||||||||||||
2424 | - | |||||||||||||||||||
2425 | - | |||||||||||||||||||
2426 | QDBusMessage msg = QDBusMessage::createMethodCall(service, path, | - | ||||||||||||||||||
2427 | QDBusUtil::dbusInterfaceIntrospectable(), | - | ||||||||||||||||||
2428 | ([]() -> QString { enum { Size = sizeof(u"" "Introspect")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Introspect" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||
2429 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | QDBusMessage reply = sendWithReply(msg, QDBus::Block); | - | ||||||||||||||||||
2432 | - | |||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | QDBusWriteLocker locker(FindMetaObject2Action, this); | - | ||||||||||||||||||
2435 | QDBusMetaObject *mo = 0; | - | ||||||||||||||||||
2436 | if (!interface.isEmpty()) | - | ||||||||||||||||||
2437 | mo = cachedMetaObjects.value(interface, 0); | - | ||||||||||||||||||
2438 | if (mo) | - | ||||||||||||||||||
2439 | - | |||||||||||||||||||
2440 | return mo; | - | ||||||||||||||||||
2441 | - | |||||||||||||||||||
2442 | QString xml; | - | ||||||||||||||||||
2443 | if (reply.type() == QDBusMessage::ReplyMessage) { | - | ||||||||||||||||||
2444 | if (reply.signature() == QLatin1String("s")) | - | ||||||||||||||||||
2445 | - | |||||||||||||||||||
2446 | xml = reply.arguments().at(0).toString(); | - | ||||||||||||||||||
2447 | } else { | - | ||||||||||||||||||
2448 | error = QDBusError(reply); | - | ||||||||||||||||||
2449 | lastError = error; | - | ||||||||||||||||||
2450 | if (reply.type() != QDBusMessage::ErrorMessage || error.type() != QDBusError::UnknownMethod) | - | ||||||||||||||||||
2451 | return 0; | - | ||||||||||||||||||
2452 | } | - | ||||||||||||||||||
2453 | - | |||||||||||||||||||
2454 | - | |||||||||||||||||||
2455 | QDBusMetaObject *result = QDBusMetaObject::createMetaObject(interface, xml, | - | ||||||||||||||||||
2456 | cachedMetaObjects, error); | - | ||||||||||||||||||
2457 | lastError = error; | - | ||||||||||||||||||
2458 | return result; | - | ||||||||||||||||||
2459 | } | - | ||||||||||||||||||
2460 | - | |||||||||||||||||||
2461 | void QDBusConnectionPrivate::registerService(const QString &serviceName) | - | ||||||||||||||||||
2462 | { | - | ||||||||||||||||||
2463 | QDBusWriteLocker locker(RegisterServiceAction, this); | - | ||||||||||||||||||
2464 | registerServiceNoLock(serviceName); | - | ||||||||||||||||||
2465 | } | - | ||||||||||||||||||
2466 | - | |||||||||||||||||||
2467 | void QDBusConnectionPrivate::registerServiceNoLock(const QString &serviceName) | - | ||||||||||||||||||
2468 | { | - | ||||||||||||||||||
2469 | serviceNames.append(serviceName); | - | ||||||||||||||||||
2470 | } | - | ||||||||||||||||||
2471 | - | |||||||||||||||||||
2472 | void QDBusConnectionPrivate::unregisterService(const QString &serviceName) | - | ||||||||||||||||||
2473 | { | - | ||||||||||||||||||
2474 | QDBusWriteLocker locker(UnregisterServiceAction, this); | - | ||||||||||||||||||
2475 | unregisterServiceNoLock(serviceName); | - | ||||||||||||||||||
2476 | } | - | ||||||||||||||||||
2477 | - | |||||||||||||||||||
2478 | void QDBusConnectionPrivate::unregisterServiceNoLock(const QString &serviceName) | - | ||||||||||||||||||
2479 | { | - | ||||||||||||||||||
2480 | serviceNames.removeAll(serviceName); | - | ||||||||||||||||||
2481 | } | - | ||||||||||||||||||
2482 | - | |||||||||||||||||||
2483 | bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceName) | - | ||||||||||||||||||
2484 | { | - | ||||||||||||||||||
2485 | if (!serviceName.isEmpty() && serviceName == baseService) | - | ||||||||||||||||||
2486 | return true; | - | ||||||||||||||||||
2487 | if (serviceName == QDBusUtil::dbusService()) | - | ||||||||||||||||||
2488 | return false; | - | ||||||||||||||||||
2489 | - | |||||||||||||||||||
2490 | QDBusReadLocker locker(UnregisterServiceAction, this); | - | ||||||||||||||||||
2491 | return serviceNames.contains(serviceName); | - | ||||||||||||||||||
2492 | } | - | ||||||||||||||||||
2493 | - | |||||||||||||||||||
2494 | void QDBusConnectionPrivate::postEventToThread(int action, QObject *object, QEvent *ev) | - | ||||||||||||||||||
2495 | { | - | ||||||||||||||||||
2496 | QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforePost, this); | - | ||||||||||||||||||
2497 | QCoreApplication::postEvent(object, ev); | - | ||||||||||||||||||
2498 | QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterPost, this); | - | ||||||||||||||||||
2499 | } | - | ||||||||||||||||||
2500 | - | |||||||||||||||||||
2501 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |