Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / src / dbusbind.c
index 0b5d32c..1f3168e 100644 (file)
@@ -1,5 +1,5 @@
 /* Elisp bindings for D-Bus.
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -854,6 +854,9 @@ This is an internal function, it shall not be used outside dbus.el.  */)
                                            NULL, (void*) XHASH (bus), NULL))
     XD_SIGNAL1 (build_string ("Cannot add watch functions"));
 
+  /* We do not want to abort.  */
+  putenv ("DBUS_FATAL_WARNINGS=0");
+
   /* Return.  */
   return Qnil;
 }
@@ -1172,6 +1175,10 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
                    SDATA (interface),
                    SDATA (method));
 
+  /* Check dbus-registered-objects-table.  */
+  if (!HASH_TABLE_P (Vdbus_registered_objects_table))
+    XD_SIGNAL1 (build_string ("dbus.el is not loaded"));
+
   /* Open a connection to the bus.  */
   connection = xd_initialize (bus);
 
@@ -1568,7 +1575,7 @@ usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS)  */)
 
 /* Check, whether there is pending input in the message queue of the
    D-Bus BUS.  BUS is a Lisp symbol, either :system or :session.  */
-int
+static Lisp_Object
 xd_get_dispatch_status (bus)
      Lisp_Object bus;
 {
@@ -1584,23 +1591,34 @@ xd_get_dispatch_status (bus)
   return
     (dbus_connection_get_dispatch_status (connection)
      == DBUS_DISPATCH_DATA_REMAINS)
-    ? TRUE : FALSE;
+    ? Qt : Qnil;
 }
 
 /* Check for queued incoming messages from the system and session buses.  */
 int
 xd_pending_messages ()
 {
+  int ret = FALSE;
+  xd_in_read_queued_messages = 1;
 
   /* Vdbus_registered_objects_table will be initialized as hash table
      in dbus.el.  When this package isn't loaded yet, it doesn't make
      sense to handle D-Bus messages.  */
-  return (HASH_TABLE_P (Vdbus_registered_objects_table)
-         ? (xd_get_dispatch_status (QCdbus_system_bus)
-            || ((getenv ("DBUS_SESSION_BUS_ADDRESS") != NULL)
-                ? xd_get_dispatch_status (QCdbus_session_bus)
-                : FALSE))
-         : FALSE);
+  if (HASH_TABLE_P (Vdbus_registered_objects_table))
+    {
+      ret = (!NILP (internal_catch (Qdbus_error, xd_get_dispatch_status,
+                                   QCdbus_system_bus)));
+      if (ret) goto theend;
+
+      ret = ((getenv ("DBUS_SESSION_BUS_ADDRESS") != NULL) &&
+            (!NILP (internal_catch (Qdbus_error, xd_get_dispatch_status,
+                                    QCdbus_session_bus))));
+    }
+
+  /* Return.  */
+ theend:
+  xd_in_read_queued_messages = 0;
+  return ret;
 }
 
 /* Read queued incoming message of the D-Bus BUS.  BUS is a Lisp
@@ -1849,6 +1867,10 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
     wrong_type_argument (intern ("functionp"), handler);
   GCPRO6 (bus, service, path, interface, signal, handler);
 
+  /* Check dbus-registered-objects-table.  */
+  if (!HASH_TABLE_P (Vdbus_registered_objects_table))
+    XD_SIGNAL1 (build_string ("dbus.el is not loaded"));
+
   /* Retrieve unique name of service.  If service is a known name, we
      will register for the corresponding unique name, if any.  Signals
      are sent always with the unique name as sender.  Note: the unique
@@ -1962,6 +1984,10 @@ used for composing the returning D-Bus message.  */)
   /* TODO: We must check for a valid service name, otherwise there is
      a segmentation fault.  */
 
+  /* Check dbus-registered-objects-table.  */
+  if (!HASH_TABLE_P (Vdbus_registered_objects_table))
+    XD_SIGNAL1 (build_string ("dbus.el is not loaded"));
+
   /* Open a connection to the bus.  */
   connection = xd_initialize (bus);
 
@@ -2130,12 +2156,11 @@ message arrives.  */);
     doc: /* If non-nil, debug messages of D-Bus bindings are raised.  */);
 #ifdef DBUS_DEBUG
   Vdbus_debug = Qt;
-  /* We can also set environment DBUS_VERBOSE=1 in order to see more
-     traces.  */
+  /* We can also set environment variable DBUS_VERBOSE=1 in order to
+     see more traces.  This requires libdbus-1 to be configured with
+     --enable-verbose-mode.  */
 #else
   Vdbus_debug = Qnil;
-  /* We do not want to abort.  */
-  setenv ("DBUS_FATAL_WARNINGS", 0, 1);
 #endif
 
   Fprovide (intern_c_string ("dbusbind"), Qnil);