comparison src/dbusbind.c @ 104339:dfa6f847adcd

* dbusbind.c (xd_add_watch, xd_remove_watch, Fdbus_init_bus): New functions. (xd_initialize): Revert change from 2009-08-16.
author Michael Albinus <michael.albinus@gmx.de>
date Tue, 18 Aug 2009 15:16:41 +0000
parents 73f76307d49b
children cb9bcec90aa8
comparison
equal deleted inserted replaced
104338:0ac0e5bde043 104339:dfa6f847adcd
27 #include "termhooks.h" 27 #include "termhooks.h"
28 #include "keyboard.h" 28 #include "keyboard.h"
29 29
30 30
31 /* Subroutines. */ 31 /* Subroutines. */
32 Lisp_Object Qdbus_init_bus;
32 Lisp_Object Qdbus_get_unique_name; 33 Lisp_Object Qdbus_get_unique_name;
33 Lisp_Object Qdbus_call_method; 34 Lisp_Object Qdbus_call_method;
34 Lisp_Object Qdbus_call_method_asynchronously; 35 Lisp_Object Qdbus_call_method_asynchronously;
35 Lisp_Object Qdbus_method_return_internal; 36 Lisp_Object Qdbus_method_return_internal;
36 Lisp_Object Qdbus_method_error_internal; 37 Lisp_Object Qdbus_method_error_internal;
696 xd_initialize (bus) 697 xd_initialize (bus)
697 Lisp_Object bus; 698 Lisp_Object bus;
698 { 699 {
699 DBusConnection *connection; 700 DBusConnection *connection;
700 DBusError derror; 701 DBusError derror;
701 int fd;
702 702
703 /* Parameter check. */ 703 /* Parameter check. */
704 CHECK_SYMBOL (bus); 704 CHECK_SYMBOL (bus);
705 if (!((EQ (bus, QCdbus_system_bus)) || (EQ (bus, QCdbus_session_bus)))) 705 if (!((EQ (bus, QCdbus_system_bus)) || (EQ (bus, QCdbus_session_bus))))
706 XD_SIGNAL2 (build_string ("Wrong bus name"), bus); 706 XD_SIGNAL2 (build_string ("Wrong bus name"), bus);
717 XD_ERROR (derror); 717 XD_ERROR (derror);
718 718
719 if (connection == NULL) 719 if (connection == NULL)
720 XD_SIGNAL2 (build_string ("No connection"), bus); 720 XD_SIGNAL2 (build_string ("No connection"), bus);
721 721
722 /* Add connection file descriptor to input_wait_mask, in order to
723 let select() detect, whether a new message has been arrived. */
724 if (dbus_connection_get_unix_fd (connection, &fd))
725 add_keyboard_wait_descriptor (fd);
726
727 /* Cleanup. */ 722 /* Cleanup. */
728 dbus_error_free (&derror); 723 dbus_error_free (&derror);
729 724
730 /* Return the result. */ 725 /* Return the result. */
731 return connection; 726 return connection;
727 }
728
729
730 /* Add connection file descriptor to input_wait_mask, in order to
731 let select() detect, whether a new message has been arrived. */
732 dbus_bool_t
733 xd_add_watch (watch, data)
734 DBusWatch *watch;
735 void *data;
736 {
737 /* We check only for incoming data. */
738 if (dbus_watch_get_flags (watch) & DBUS_WATCH_READABLE)
739 {
740 /* TODO: Reverse these on Win32, which prefers the opposite. */
741 int fd = dbus_watch_get_unix_fd(watch);
742 if (fd == -1)
743 fd = dbus_watch_get_socket(watch);
744 if (fd == -1)
745 return FALSE;
746
747 //printf ("xd_add_watch: %d\n", fd);
748 /* Add the file descriptor to input_wait_mask. */
749 add_keyboard_wait_descriptor (fd);
750 }
751
752 /* Return. */
753 return TRUE;
754 }
755
756 /* Remove connection file descriptor from input_wait_mask. */
757 void
758 xd_remove_watch (watch, data)
759 DBusWatch *watch;
760 void *data;
761 {
762 /* We check only for incoming data. */
763 if (dbus_watch_get_flags (watch) & DBUS_WATCH_READABLE)
764 {
765 /* TODO: Reverse these on Win32, which prefers the opposite. */
766 int fd = dbus_watch_get_unix_fd(watch);
767 if (fd == -1)
768 fd = dbus_watch_get_socket(watch);
769 if (fd == -1)
770 return;
771
772 //printf ("xd_remove_watch: %d\n", fd);
773 /* Remove the file descriptor from input_wait_mask. */
774 delete_keyboard_wait_descriptor (fd);
775 }
776
777 /* Return. */
778 return;
779 }
780
781 DEFUN ("dbus-init-bus", Fdbus_init_bus, Sdbus_init_bus, 1, 1, 0,
782 doc: /* Initialize connection to D-Bus BUS.
783 This is an internal function, it shall not be used outside dbus.el. */)
784 (bus)
785 Lisp_Object bus;
786 {
787 DBusConnection *connection;
788
789 /* Check parameters. */
790 CHECK_SYMBOL (bus);
791
792 /* Open a connection to the bus. */
793 connection = xd_initialize (bus);
794
795 /* Add the watch functions. */
796 if (!dbus_connection_set_watch_functions (connection,
797 xd_add_watch,
798 xd_remove_watch,
799 NULL, NULL, NULL))
800 XD_SIGNAL1 (build_string ("Cannot add watch functions"));
801
802 /* Return. */
803 return Qnil;
732 } 804 }
733 805
734 DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name, 806 DEFUN ("dbus-get-unique-name", Fdbus_get_unique_name, Sdbus_get_unique_name,
735 1, 1, 0, 807 1, 1, 0,
736 doc: /* Return the unique name of Emacs registered at D-Bus BUS. */) 808 doc: /* Return the unique name of Emacs registered at D-Bus BUS. */)
1863 1935
1864 void 1936 void
1865 syms_of_dbusbind () 1937 syms_of_dbusbind ()
1866 { 1938 {
1867 1939
1940 Qdbus_init_bus = intern ("dbus-init-bus");
1941 staticpro (&Qdbus_init_bus);
1942 defsubr (&Sdbus_init_bus);
1943
1868 Qdbus_get_unique_name = intern ("dbus-get-unique-name"); 1944 Qdbus_get_unique_name = intern ("dbus-get-unique-name");
1869 staticpro (&Qdbus_get_unique_name); 1945 staticpro (&Qdbus_get_unique_name);
1870 defsubr (&Sdbus_get_unique_name); 1946 defsubr (&Sdbus_get_unique_name);
1871 1947
1872 Qdbus_call_method = intern ("dbus-call-method"); 1948 Qdbus_call_method = intern ("dbus-call-method");