return connection;
}
-/* Callback called when something is read to read ow write. */
-
-static void
-dbus_fd_cb (int fd, void *data, int for_read)
-{
- xd_read_queued_messages ();
-}
-
/* Return the file descriptor for WATCH, -1 if not found. */
-
static int
xd_find_watch_fd (DBusWatch *watch)
{
return fd;
}
+/* Prototype. */
+static void
+xd_read_queued_messages (int fd, void *data, int for_read);
/* Start monitoring WATCH for possible I/O. */
-
static dbus_bool_t
xd_add_watch (DBusWatch *watch, void *data)
{
if (dbus_watch_get_enabled (watch))
{
if (flags & DBUS_WATCH_WRITABLE)
- add_write_fd (fd, dbus_fd_cb, NULL);
+ add_write_fd (fd, xd_read_queued_messages, data);
if (flags & DBUS_WATCH_READABLE)
- add_read_fd (fd, dbus_fd_cb, NULL);
+ add_read_fd (fd, xd_read_queued_messages, data);
}
return TRUE;
}
/* Stop monitoring WATCH for possible I/O.
DATA is the used bus, either a string or QCdbus_system_bus or
QCdbus_session_bus. */
-
static void
xd_remove_watch (DBusWatch *watch, void *data)
{
XD_DEBUG_MESSAGE ("fd %d", fd);
- if (fd == -1) return;
-
+ if (fd == -1)
+ return;
/* Unset session environment. */
if (data != NULL && data == (void*) XHASH (QCdbus_session_bus))
}
/* Toggle monitoring WATCH for possible I/O. */
-
static void
xd_toggle_watch (DBusWatch *watch, void *data)
{
return Qt;
}
-/* Check, whether there is pending input in the message queue of the
- D-Bus BUS. BUS is either a Lisp symbol, :system or :session, or a
- string denoting the bus address. */
-int
-xd_get_dispatch_status (Lisp_Object bus)
-{
- DBusConnection *connection;
-
- /* Open a connection to the bus. */
- connection = xd_initialize (bus, FALSE);
- if (connection == NULL) return FALSE;
-
- /* Non blocking read of the next available message. */
- dbus_connection_read_write (connection, 0);
-
- /* Return. */
- return
- (dbus_connection_get_dispatch_status (connection)
- == DBUS_DISPATCH_DATA_REMAINS)
- ? TRUE : FALSE;
-}
-
-/* Check for queued incoming messages from the buses. */
-int
-xd_pending_messages (void)
-{
- Lisp_Object busp = Vdbus_registered_buses;
-
- while (!NILP (busp))
- {
- /* We do not want to have an autolaunch for the session bus. */
- if (EQ ((CAR_SAFE (busp)), QCdbus_session_bus)
- && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL)
- continue;
-
- if (xd_get_dispatch_status (CAR_SAFE (busp)))
- return TRUE;
-
- busp = CDR_SAFE (busp);
- }
-
- return FALSE;
-}
-
/* Read one queued incoming message of the D-Bus BUS.
BUS is either a Lisp symbol, :system or :session, or a string denoting
the bus address. */
-
static void
xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
{
/* Read queued incoming messages of the D-Bus BUS.
BUS is either a Lisp symbol, :system or :session, or a string denoting
the bus address. */
-
static Lisp_Object
xd_read_message (Lisp_Object bus)
{
return Qnil;
}
-/* Read queued incoming messages from all buses. */
-void
-xd_read_queued_messages (void)
+/* Callback called when something is ready to read or write. */
+static void
+xd_read_queued_messages (int fd, void *data, int for_read)
{
Lisp_Object busp = Vdbus_registered_buses;
+ Lisp_Object bus = Qnil;
+
+ /* Find bus related to fd. */
+ if (data != NULL)
+ while (!NILP (busp))
+ {
+ if (data == (void*) XHASH (CAR_SAFE (busp)))
+ bus = CAR_SAFE (busp);
+ busp = CDR_SAFE (busp);
+ }
+
+ if (NILP(bus))
+ return;
+ /* We ignore all Lisp errors during the call. */
xd_in_read_queued_messages = 1;
- while (!NILP (busp))
- {
- /* We ignore all Lisp errors during the call. */
- internal_catch (Qdbus_error, xd_read_message, CAR_SAFE (busp));
- busp = CDR_SAFE (busp);
- }
+ internal_catch (Qdbus_error, xd_read_message, bus);
xd_in_read_queued_messages = 0;
}