X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/0273a428450950cf846767982cdb77cc9937a1f3..2bfa3d3e1fb347ba76bddf77f3e288049635821d:/src/dbusbind.c diff --git a/src/dbusbind.c b/src/dbusbind.c index 863f7634eb..e8b077129e 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c @@ -1,5 +1,5 @@ /* Elisp bindings for D-Bus. - Copyright (C) 2007-2013 Free Software Foundation, Inc. + Copyright (C) 2007-2014 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -42,7 +42,7 @@ along with GNU Emacs. If not, see . */ /* Subroutines. */ -static Lisp_Object Qdbus_init_bus; +static Lisp_Object Qdbus__init_bus; static Lisp_Object Qdbus_get_unique_name; static Lisp_Object Qdbus_message_internal; @@ -142,7 +142,7 @@ static bool xd_in_read_queued_messages = 0; } while (0) #else /* !DBUS_DEBUG */ -#define XD_DEBUG_MESSAGE(...) \ +# define XD_DEBUG_MESSAGE(...) \ do { \ if (!NILP (Vdbus_debug)) \ { \ @@ -151,7 +151,7 @@ static bool xd_in_read_queued_messages = 0; message ("%s: %s", __func__, s); \ } \ } while (0) -#define XD_DEBUG_VALID_LISP_OBJECT_P(object) +# define XD_DEBUG_VALID_LISP_OBJECT_P(object) #endif /* Check whether TYPE is a basic DBusType. */ @@ -882,7 +882,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) #endif { dbus_uint32_t val; - unsigned int pval = val; + unsigned int pval; dbus_message_iter_get_basic (iter, &val); pval = val; XD_DEBUG_MESSAGE ("%c %u", dtype, pval); @@ -946,7 +946,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter) dbus_message_iter_next (&subiter); } XD_DEBUG_MESSAGE ("%c %s", dtype, XD_OBJECT_TO_STRING (result)); - RETURN_UNGCPRO (Fnreverse (result)); + return Fnreverse (result); } default: @@ -969,6 +969,13 @@ xd_get_connection_references (DBusConnection *connection) return *refcount; } +/* Convert a Lisp D-Bus object to a pointer. */ +static DBusConnection* +xd_lisp_dbus_to_dbus (Lisp_Object bus) +{ + return (DBusConnection *) (intptr_t) XFASTINT (bus); +} + /* Return D-Bus connection address. BUS is either a Lisp symbol, :system or :session, or a string denoting the bus address. */ static DBusConnection * @@ -981,7 +988,7 @@ xd_get_connection_address (Lisp_Object bus) if (NILP (val)) XD_SIGNAL2 (build_string ("No connection to bus"), bus); else - connection = (DBusConnection *) (intptr_t) XFASTINT (val); + connection = xd_lisp_dbus_to_dbus (val); if (!dbus_connection_get_is_connected (connection)) XD_SIGNAL2 (build_string ("No connection to bus"), bus); @@ -1076,14 +1083,21 @@ xd_close_bus (Lisp_Object bus) { DBusConnection *connection; Lisp_Object val; + Lisp_Object busobj; /* Check whether we are connected. */ val = Fassoc (bus, xd_registered_buses); if (NILP (val)) return; + busobj = CDR_SAFE (val); + if (NILP (busobj)) { + xd_registered_buses = Fdelete (val, xd_registered_buses); + return; + } + /* Retrieve bus address. */ - connection = xd_get_connection_address (bus); + connection = xd_lisp_dbus_to_dbus (busobj); if (xd_get_connection_references (connection) == 1) { @@ -1103,9 +1117,12 @@ xd_close_bus (Lisp_Object bus) return; } -DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 2, 0, +DEFUN ("dbus--init-bus", Fdbus__init_bus, Sdbus__init_bus, 1, 2, 0, doc: /* Establish the connection to D-Bus BUS. +This function is dbus internal. You almost certainly want to use +`dbus-init-bus'. + BUS can be either the symbol `:system' or the symbol `:session', or it can be a string denoting the address of the corresponding bus. For the system and session buses, this function is called when loading @@ -1517,7 +1534,7 @@ usage: (dbus-message-internal &rest REST) */) dbus_message_unref (dmessage); /* Return the result. */ - RETURN_UNGCPRO (result); + return result; } /* Read one queued incoming message of the D-Bus BUS. @@ -1723,22 +1740,16 @@ xd_read_queued_messages (int fd, void *data) void syms_of_dbusbind (void) { +#include "dbusbind.x" - DEFSYM (Qdbus_init_bus, "dbus-init-bus"); - defsubr (&Sdbus_init_bus); - + DEFSYM (Qdbus__init_bus, "dbus--init-bus"); DEFSYM (Qdbus_get_unique_name, "dbus-get-unique-name"); - defsubr (&Sdbus_get_unique_name); - DEFSYM (Qdbus_message_internal, "dbus-message-internal"); - defsubr (&Sdbus_message_internal); - DEFSYM (Qdbus_error, "dbus-error"); Fput (Qdbus_error, Qerror_conditions, list2 (Qdbus_error, Qerror)); Fput (Qdbus_error, Qerror_message, build_pure_c_string ("D-Bus error")); - DEFSYM (QCdbus_system_bus, ":system"); DEFSYM (QCdbus_session_bus, ":session"); DEFSYM (QCdbus_timeout, ":timeout");