Mercurial > emacs
comparison src/dbusbind.c @ 112113:f68ebb34e243
* dbusbind.c (Fdbus_register_method): Added optional parameter
dont_register_service. Updated docstring accordingly.
| author | Michael Albinus <michael.albinus@gmx.de> |
|---|---|
| date | Tue, 04 Jan 2011 12:11:43 +0100 |
| parents | 143e567b63bc |
| children | e79369283aa1 |
comparison
equal
deleted
inserted
replaced
| 112112:318b7249ccd0 | 112113:f68ebb34e243 |
|---|---|
| 1 /* Elisp bindings for D-Bus. | 1 /* Elisp bindings for D-Bus. |
| 2 Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | 2 Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
| 3 | 3 |
| 4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
| 5 | 5 |
| 6 GNU Emacs is free software: you can redistribute it and/or modify | 6 GNU Emacs is free software: you can redistribute it and/or modify |
| 7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
| 1981 /* Return object. */ | 1981 /* Return object. */ |
| 1982 RETURN_UNGCPRO (list2 (key, list3 (service, path, handler))); | 1982 RETURN_UNGCPRO (list2 (key, list3 (service, path, handler))); |
| 1983 } | 1983 } |
| 1984 | 1984 |
| 1985 DEFUN ("dbus-register-method", Fdbus_register_method, Sdbus_register_method, | 1985 DEFUN ("dbus-register-method", Fdbus_register_method, Sdbus_register_method, |
| 1986 6, 6, 0, | 1986 6, 7, 0, |
| 1987 doc: /* Register for method METHOD on the D-Bus BUS. | 1987 doc: /* Register for method METHOD on the D-Bus BUS. |
| 1988 | 1988 |
| 1989 BUS is either a Lisp symbol, `:system' or `:session', or a string | 1989 BUS is either a Lisp symbol, `:system' or `:session', or a string |
| 1990 denoting the bus address. | 1990 denoting the bus address. |
| 1991 | 1991 |
| 1992 SERVICE is the D-Bus service name of the D-Bus object METHOD is | 1992 SERVICE is the D-Bus service name of the D-Bus object METHOD is |
| 1993 registered for. It must be a known name. | 1993 registered for. It must be a known name (See discussion of |
| 1994 | 1994 DONT-REGISTER-SERVICE below). |
| 1995 PATH is the D-Bus object path SERVICE is registered. INTERFACE is the | 1995 |
| 1996 interface offered by SERVICE. It must provide METHOD. HANDLER is a | 1996 PATH is the D-Bus object path SERVICE is registered (See discussion of |
| 1997 Lisp function to be called when a method call is received. It must | 1997 DONT-REGISTER-SERVICE below). INTERFACE is the interface offered by |
| 1998 accept the input arguments of METHOD. The return value of HANDLER is | 1998 SERVICE. It must provide METHOD. HANDLER is a Lisp function to be |
| 1999 used for composing the returning D-Bus message. */) | 1999 called when a method call is received. It must accept the input |
| 2000 (Lisp_Object bus, Lisp_Object service, Lisp_Object path, Lisp_Object interface, Lisp_Object method, Lisp_Object handler) | 2000 arguments of METHOD. The return value of HANDLER is used for |
| 2001 composing the returning D-Bus message. | |
| 2002 | |
| 2003 When DONT-REGISTER-SERVICE is non-nil, the known name SERVICE is not | |
| 2004 registered. This means that other D-Bus clients have no way of | |
| 2005 noticing the newly registered method. When interfaces are constructed | |
| 2006 incrementally by adding single methods or properties at a time, | |
| 2007 DONT-REGISTER-SERVICE can be use to prevent other clients from | |
| 2008 discovering the still incomplete interface.*/) | |
| 2009 (Lisp_Object bus, Lisp_Object service, Lisp_Object path, | |
| 2010 Lisp_Object interface, Lisp_Object method, Lisp_Object handler, | |
| 2011 Lisp_Object dont_register_service) | |
| 2001 { | 2012 { |
| 2002 Lisp_Object key, key1, value; | 2013 Lisp_Object key, key1, value; |
| 2003 DBusConnection *connection; | 2014 DBusConnection *connection; |
| 2004 int result; | 2015 int result; |
| 2005 DBusError derror; | 2016 DBusError derror; |
| 2017 /* Open a connection to the bus. */ | 2028 /* Open a connection to the bus. */ |
| 2018 connection = xd_initialize (bus, TRUE); | 2029 connection = xd_initialize (bus, TRUE); |
| 2019 | 2030 |
| 2020 /* Request the known name from the bus. We can ignore the result, | 2031 /* Request the known name from the bus. We can ignore the result, |
| 2021 it is set to -1 if there is an error - kind of redundancy. */ | 2032 it is set to -1 if there is an error - kind of redundancy. */ |
| 2022 dbus_error_init (&derror); | 2033 if (NILP (dont_register_service)) |
| 2023 result = dbus_bus_request_name (connection, SDATA (service), 0, &derror); | 2034 { |
| 2024 if (dbus_error_is_set (&derror)) | 2035 dbus_error_init (&derror); |
| 2025 XD_ERROR (derror); | 2036 result = dbus_bus_request_name (connection, SDATA (service), 0, &derror); |
| 2037 if (dbus_error_is_set (&derror)) | |
| 2038 XD_ERROR (derror); | |
| 2039 | |
| 2040 /* Cleanup. */ | |
| 2041 dbus_error_free (&derror); | |
| 2042 } | |
| 2026 | 2043 |
| 2027 /* Create a hash table entry. We use nil for the unique name, | 2044 /* Create a hash table entry. We use nil for the unique name, |
| 2028 because the method might be called from anybody. */ | 2045 because the method might be called from anybody. */ |
| 2029 key = list3 (bus, interface, method); | 2046 key = list3 (bus, interface, method); |
| 2030 key1 = list4 (Qnil, service, path, handler); | 2047 key1 = list4 (Qnil, service, path, handler); |
| 2031 value = Fgethash (key, Vdbus_registered_objects_table, Qnil); | 2048 value = Fgethash (key, Vdbus_registered_objects_table, Qnil); |
| 2032 | 2049 |
| 2033 if (NILP (Fmember (key1, value))) | 2050 if (NILP (Fmember (key1, value))) |
| 2034 Fputhash (key, Fcons (key1, value), Vdbus_registered_objects_table); | 2051 Fputhash (key, Fcons (key1, value), Vdbus_registered_objects_table); |
| 2035 | |
| 2036 /* Cleanup. */ | |
| 2037 dbus_error_free (&derror); | |
| 2038 | 2052 |
| 2039 /* Return object. */ | 2053 /* Return object. */ |
| 2040 return list2 (key, list3 (service, path, handler)); | 2054 return list2 (key, list3 (service, path, handler)); |
| 2041 } | 2055 } |
| 2042 | 2056 |
