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, TQ_SIGNAL(activated(
int)), TQ_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, TQ_SIGNAL(activated(
int)), TQ_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, TQ_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);
345 WatcherHash::iterator it =
watchers.begin();
349 WatcherList::iterator listIt = list.begin();
350 while (listIt != list.end())
377 for (WatcherHash::const_iterator it = oldWatchers.begin(); it != oldWatchers.end(); ++it)
380 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit)
382 if (!(*wit).read && !(*wit).write) {
398 WatcherHash::const_iterator it =
watchers.find(fd);
401 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
402 if ((*wit).read && (*wit).read->isEnabled()) {
403 if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_READABLE))
404 tqDebug(
"OUT OF MEM");
415 WatcherHash::const_iterator it =
watchers.find(fd);
418 for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
419 if ((*wit).write && (*wit).write->isEnabled()) {
420 if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_WRITABLE))
421 tqDebug(
"OUT OF MEM");
432 TQObject* receiver = (TQObject*) it.data()->receiver;
433 if (receiver ==
object || receiver == 0)
435 PendingCallMap::iterator copyIt = it;
438 dbus_pending_call_cancel(copyIt.key());
439 dbus_pending_call_unref(copyIt.key());
440 delete copyIt.data();
455 delete (*listIt).read;
456 delete (*listIt).write;
461 WatcherHash::iterator it =
watchers.begin();
465 listIt = list.begin();
466 while (listIt != list.end())
468 if (!((*listIt).read) && !((*listIt).write))
470 listIt = list.erase(listIt);
477 WatcherHash::iterator copyIt = it;
495 printf(
"[dbus-1-tqt] WARNING: Attempt to call dispatch() recursively was silently ignored to prevent lockup!\n\r"); fflush(stdout);
502 if (dbus_connection_dispatch(
connection) != DBUS_DISPATCH_DATA_REMAINS)
514 TQT_DBusConnectionPrivate::PendingMessagesForEmit::iterator pmfe;
531 return it.data()->handleMethodCall(msg);
586 dbus_connection_set_exit_on_disconnect(
connection,
false);
598 const char *service = dbus_bus_get_unique_name(
connection);
601 filter +=
"destination='";
611 tqWarning(
"TQT_DBusConnectionPrivate::SetConnection: Unable to get unique name");
623 TQT_DBusConnectionPrivate::PendingCallMap::iterator it = d->
pendingCalls.find(pending);
625 DBusMessage *dbusReply = dbus_pending_call_steal_reply(pending);
627 dbus_set_error_from_message(&d->
error, dbusReply);
636 dbusResult.
receiver = it.data()->receiver;
637 dbusResult.
method = it.data()->method.data();
642 dbus_message_unref(dbusReply);
643 dbus_pending_call_unref(pending);
652 if (!receiver || !method)
655 if (!TQObject::connect(receiver, TQ_SIGNAL(destroyed(TQObject*)),
664 DBusPendingCall *pending = 0;
665 if (dbus_connection_send_with_reply(
connection, msg, &pending, message.
timeout())) {
674 msg_serial = dbus_message_get_serial(msg);
677 dbus_message_unref(msg);
696 TQT_DBusResultInfoList::Iterator it;
710#include "tqdbusconnection_p.moc"
void transmitMessageEmissionQueue()
TQT_DBusResultInfoList m_resultEmissionQueue
TQValueList< DBusTimeout * > pendingTimeouts
void newMethodInResultEmissionQueue()
TQT_DBusConnectionPrivate(TQObject *parent=0)
void setConnection(DBusConnection *connection)
static int registerMessageMetaType()
PendingMessagesForEmit pendingMessages
TQMap< int, WatcherList > WatcherHash
void purgeRemovedWatches()
void transmitResultEmissionQueue()
void objectDestroyed(TQObject *object)
DBusConnection * connection
bool handleUnreadMessages()
WatcherList removedWatches
void emitPendingCallReply(const TQT_DBusMessage &message)
void dbusSignal(const TQT_DBusMessage &message)
bool handleObjectCall(DBusMessage *message)
PendingCallMap pendingCalls
static int messageMetaType
ObjectMap registeredObjects
TQTimer * m_messageEmissionQueueTimer
TQTimer * m_resultEmissionQueueTimer
void setServer(DBusServer *server)
~TQT_DBusConnectionPrivate()
int sendWithReplyAsync(const TQT_DBusMessage &message, TQObject *receiver, const char *method)
void dbusPendingCallReply(const TQT_DBusMessage &message)
bool handleSignal(DBusMessage *msg)
Class for transporting D-Bus errors.
bool isValid() const
Returns whether the error object is valid.
A message converts and transports data over D-Bus.
int timeout() const
Returns the message's timeout.
TQString path() const
Returns the message's object path.
DBusMessage * toDBusMessage() const
Creates a raw D-Bus message from this TQt3-bindings message.
static TQT_DBusMessage fromDBusMessage(DBusMessage *dmsg)
Creates a TQt3-bindings message from the given raw D-Bus message.
TQGuardedPtr< TQObject > receiver
DBusPendingCall * pending
static void qDBusNewConnection(DBusServer *server, DBusConnection *c, void *data)
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
static void qDBusResultReceived(DBusPendingCall *pending, void *user_data)
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data)
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
static DBusHandlerResult qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)
static void qDBusToggleWatch(DBusWatch *watch, void *data)
static dbus_int32_t server_slot