summaryrefslogtreecommitdiff
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2010-09-27 17:34:04 +0200
committerMichael Albinus <michael.albinus@gmx.de>2010-09-27 17:34:04 +0200
commit08609ffd4c1b513f50712046f955f0a0d68364e0 (patch)
tree33945758aa207eb8abfc43b003bff16e8c9a61d7 /src/dbusbind.c
parentec9f09be7b5252d6bb462d6b58aee58e61129f96 (diff)
* dbusbind.c (dbus_fd_cb, xd_get_dispatch_status)
(xd_pending_messages): Functions removed. (xd_read_queued_messages): Add parameters fd, *data, for_read in order to be compatible with add_read_fd. Determine bus from data, and call xd_read_message just for this bus. (xd_add_watch): Use xd_read_queued_messages as callback function. Add data. * lisp.h (xd_pending_messages, xd_read_queued_messages): Remove.
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c96
1 files changed, 25 insertions, 71 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index a8db1c510c..a0881a06f6 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -800,16 +800,7 @@ xd_initialize (Lisp_Object bus, int raise_error)
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)
{
@@ -824,9 +815,11 @@ 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)
{
@@ -843,9 +836,9 @@ 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;
}
@@ -853,7 +846,6 @@ xd_add_watch (DBusWatch *watch, void *data)
/* 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)
{
@@ -862,8 +854,8 @@ 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))
@@ -879,7 +871,6 @@ xd_remove_watch (DBusWatch *watch, void *data)
}
/* Toggle monitoring WATCH for possible I/O. */
-
static void
xd_toggle_watch (DBusWatch *watch, void *data)
{
@@ -1613,54 +1604,9 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
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)
{
@@ -1814,7 +1760,6 @@ 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)
{
@@ -1830,19 +1775,28 @@ 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;
}