25 #include <tqapplication.h>
27 #include <tqmetaobject.h>
28 #include <tqsocketnotifier.h>
60 if (!dbus_timeout_get_enabled(timeout))
67 int timerId = d->startTimer(dbus_timeout_get_interval(timeout));
85 if ((*it) == timeout) {
92 TQT_DBusConnectionPrivate::TimeoutHash::iterator it = d->
timeouts.begin();
94 if (it.data() == timeout) {
95 d->killTimer(it.key());
96 TQT_DBusConnectionPrivate::TimeoutHash::iterator copyIt = it;
123 int flags = dbus_watch_get_flags(watch);
124 int fd = dbus_watch_get_unix_fd(watch);
127 if (flags & DBUS_WATCH_READABLE) {
128 bool enabled = dbus_watch_get_enabled(watch);
130 watcher.
watch = watch;
132 watcher.
read =
new TQSocketNotifier(fd, TQSocketNotifier::Read, d);
133 if (!enabled) watcher.
read->setEnabled(
false);
134 d->connect(watcher.
read, TQT_SIGNAL(activated(
int)), TQT_SLOT(socketRead(
int)));
137 if (flags & DBUS_WATCH_WRITABLE) {
138 bool enabled = dbus_watch_get_enabled(watch);
140 watcher.
watch = watch;
142 watcher.
write =
new TQSocketNotifier(fd, TQSocketNotifier::Write, d);
143 if (!enabled) watcher.
write->setEnabled(
false);
144 d->connect(watcher.
write, TQT_SIGNAL(activated(
int)), TQT_SLOT(socketWrite(
int)));
148 TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->
watchers.find(fd);
153 it.data().append(watcher);
166 int fd = dbus_watch_get_unix_fd(watch);
168 TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->
watchers.find(fd);
172 for (TQT_DBusConnectionPrivate::WatcherList::iterator wit = list.begin();
173 wit != list.end(); ++wit)
175 if ((*wit).watch == watch)
183 (*wit).read->disconnect(d);
188 (*wit).write->disconnect(d);
197 TQTimer::singleShot(0, d, TQT_SLOT(purgeRemovedWatches()));
208 int fd = dbus_watch_get_unix_fd(watch);
210 TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->
watchers.find(fd);
213 for (TQT_DBusConnectionPrivate::WatcherList::iterator wit = list.begin(); wit != list.end();
216 if ((*wit).watch == watch) {
217 bool enabled = dbus_watch_get_enabled(watch);
218 int flags = dbus_watch_get_flags(watch);
224 if (flags & DBUS_WATCH_READABLE && (*wit).read)
225 (*wit).read->setEnabled(enabled);
226 if (flags & DBUS_WATCH_WRITABLE && (*wit).write)
227 (*wit).write->setEnabled(enabled);
236 Q_ASSERT(data); Q_ASSERT(server); Q_ASSERT(c);
238 tqDebug(
"SERVER: GOT A NEW CONNECTION");
242 DBusMessage *message,
void *data)
245 Q_UNUSED(connection);
249 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
251 int msgType = dbus_message_get_type(message);
252 bool handled =
false;
257 if (msgType == DBUS_MESSAGE_TYPE_SIGNAL) {
259 }
else if (msgType == DBUS_MESSAGE_TYPE_METHOD_CALL) {
263 return handled ? DBUS_HANDLER_RESULT_HANDLED :
264 DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
275 : TQObject(parent), ref(1), mode(InvalidMode), connection(0), server(0),
276 dispatcher(0), inDispatch(false)
281 dbus_error_init(&
error);
296 PendingCallMap::iterator copyIt = it;
298 dbus_pending_call_cancel(copyIt.key());
299 dbus_pending_call_unref(copyIt.key());
300 delete copyIt.data();
304 if (dbus_error_is_set(&
error))
305 dbus_error_free(&
error);
316 dbus_server_disconnect(
server);
317 dbus_server_unref(
server);
326 while (dbus_connection_dispatch(
connection) == DBUS_DISPATCH_DATA_REMAINS);
337 if (dbus_error_is_set(&
error))
338 dbus_error_free(&
error);
354 for (WatcherHash::const_iterator it = oldWatchers.begin(); it != oldWatchers.end(); ++it)
357 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit)
359 if (!(*wit).read && !(*wit).write) {
375 WatcherHash::const_iterator it =
watchers.find(fd);
378 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
379 if ((*wit).read && (*wit).read->isEnabled()) {
380 if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_READABLE))
381 tqDebug(
"OUT OF MEM");
392 WatcherHash::const_iterator it =
watchers.find(fd);
395 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
396 if ((*wit).write && (*wit).write->isEnabled()) {
397 if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_WRITABLE))
398 tqDebug(
"OUT OF MEM");
409 TQObject* receiver = (TQObject*) it.data()->receiver;
410 if (receiver ==
object || receiver == 0)
412 PendingCallMap::iterator copyIt = it;
415 dbus_pending_call_cancel(copyIt.key());
416 dbus_pending_call_unref(copyIt.key());
417 delete copyIt.data();
432 delete (*listIt).read;
433 delete (*listIt).write;
438 WatcherHash::iterator it =
watchers.begin();
442 listIt = list.begin();
443 while (listIt != list.end())
445 if (!((*listIt).read) && !((*listIt).write))
447 listIt = list.erase(listIt);
454 WatcherHash::iterator copyIt = it;
472 printf(
"[dbus-1-tqt] WARNING: Attempt to call dispatch() recursively was silently ignored to prevent lockup!\n\r"); fflush(stdout);
479 if (dbus_connection_dispatch(
connection) != DBUS_DISPATCH_DATA_REMAINS)
491 TQT_DBusConnectionPrivate::PendingMessagesForEmit::iterator pmfe;
508 return it.data()->handleMethodCall(msg);
563 dbus_connection_set_exit_on_disconnect(
connection,
false);
577 const char *service = dbus_bus_get_unique_name(
connection);
580 filter +=
"destination='";
590 tqWarning(
"TQT_DBusConnectionPrivate::SetConnection: Unable to get unique name");
602 TQT_DBusConnectionPrivate::PendingCallMap::iterator it = d->
pendingCalls.find(pending);
604 DBusMessage *dbusReply = dbus_pending_call_steal_reply(pending);
606 dbus_set_error_from_message(&d->
error, dbusReply);
615 dbusResult.
receiver = it.data()->receiver;
616 dbusResult.
method = it.data()->method.data();
621 dbus_message_unref(dbusReply);
622 dbus_pending_call_unref(pending);
631 if (!receiver || !method)
634 if (!TQObject::connect(receiver, TQT_SIGNAL(destroyed(TQObject*)),
643 DBusPendingCall *pending = 0;
644 if (dbus_connection_send_with_reply(
connection, msg, &pending, message.
timeout())) {
653 msg_serial = dbus_message_get_serial(msg);
656 dbus_message_unref(msg);
675 TQT_DBusResultInfoList::Iterator it;
689 #include "tqdbusconnection_p.moc"