aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Albinus2011-01-10 10:56:17 +0100
committerMichael Albinus2011-01-10 10:56:17 +0100
commit5b83ba185d6762373653287043f40247293836b4 (patch)
tree3861594372c5a4aa9027b836488f388204d6b9e6 /src
parent0a203b611556f144e71adb5aaffc5a5adabeae71 (diff)
downloademacs-5b83ba185d6762373653287043f40247293836b4.tar.gz
emacs-5b83ba185d6762373653287043f40247293836b4.zip
* dbusbind.c (QCdbus_request_name_allow_replacement): New symbol;
used by Fdbus_register_service. (QCdbus_request_name_replace_existing): Likewise. (QCdbus_request_name_do_not_queue): Likewise. (QCdbus_request_name_reply_primary_owner): Likewise. (QCdbus_request_name_reply_in_queue): Likewise. (QCdbus_request_name_reply_exists): Likewise. (QCdbus_request_name_reply_already_owner): Likewise. (Fdbus_register_service): New function. (Fdbus_register_method): Use Fdbus_register_service to do the name registration. (syms_of_dbusbind): Add symbols dbus-register-service, :allow-replacement, :replace-existing, :do-not-queue, :primary-owner, :existing, :in-queue and :already-owner.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog17
-rw-r--r--src/dbusbind.c159
2 files changed, 164 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b94fc68fe3f..a8b8c87b09c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
12011-01-08 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
2
3 * dbusbind.c (QCdbus_request_name_allow_replacement): New symbol;
4 used by Fdbus_register_service.
5 (QCdbus_request_name_replace_existing): Likewise.
6 (QCdbus_request_name_do_not_queue): Likewise.
7 (QCdbus_request_name_reply_primary_owner): Likewise.
8 (QCdbus_request_name_reply_in_queue): Likewise.
9 (QCdbus_request_name_reply_exists): Likewise.
10 (QCdbus_request_name_reply_already_owner): Likewise.
11 (Fdbus_register_service): New function.
12 (Fdbus_register_method): Use Fdbus_register_service to do the name
13 registration.
14 (syms_of_dbusbind): Add symbols dbus-register-service,
15 :allow-replacement, :replace-existing, :do-not-queue,
16 :primary-owner, :existing, :in-queue and :already-owner.
17
12011-01-09 Chong Yidong <cyd@stupidchicken.com> 182011-01-09 Chong Yidong <cyd@stupidchicken.com>
2 19
3 * gtkutil.c (update_frame_tool_bar): Don't advance tool-bar index 20 * gtkutil.c (update_frame_tool_bar): Don't advance tool-bar index
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4ef962d1507..2e0a71cad62 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -38,6 +38,7 @@ Lisp_Object Qdbus_call_method_asynchronously;
38Lisp_Object Qdbus_method_return_internal; 38Lisp_Object Qdbus_method_return_internal;
39Lisp_Object Qdbus_method_error_internal; 39Lisp_Object Qdbus_method_error_internal;
40Lisp_Object Qdbus_send_signal; 40Lisp_Object Qdbus_send_signal;
41Lisp_Object Qdbus_register_service;
41Lisp_Object Qdbus_register_signal; 42Lisp_Object Qdbus_register_signal;
42Lisp_Object Qdbus_register_method; 43Lisp_Object Qdbus_register_method;
43 44
@@ -50,6 +51,17 @@ Lisp_Object QCdbus_system_bus, QCdbus_session_bus;
50/* Lisp symbol for method call timeout. */ 51/* Lisp symbol for method call timeout. */
51Lisp_Object QCdbus_timeout; 52Lisp_Object QCdbus_timeout;
52 53
54/* Lisp symbols for name request flags. */
55Lisp_Object QCdbus_request_name_allow_replacement;
56Lisp_Object QCdbus_request_name_replace_existing;
57Lisp_Object QCdbus_request_name_do_not_queue;
58
59/* Lisp symbols for name request replies. */
60Lisp_Object QCdbus_request_name_reply_primary_owner;
61Lisp_Object QCdbus_request_name_reply_in_queue;
62Lisp_Object QCdbus_request_name_reply_exists;
63Lisp_Object QCdbus_request_name_reply_already_owner;
64
53/* Lisp symbols of D-Bus types. */ 65/* Lisp symbols of D-Bus types. */
54Lisp_Object QCdbus_type_byte, QCdbus_type_boolean; 66Lisp_Object QCdbus_type_byte, QCdbus_type_boolean;
55Lisp_Object QCdbus_type_int16, QCdbus_type_uint16; 67Lisp_Object QCdbus_type_int16, QCdbus_type_uint16;
@@ -1835,6 +1847,112 @@ xd_read_queued_messages (int fd, void *data, int for_read)
1835 xd_in_read_queued_messages = 0; 1847 xd_in_read_queued_messages = 0;
1836} 1848}
1837 1849
1850DEFUN ("dbus-register-service", Fdbus_register_service, Sdbus_register_service,
1851 2, MANY, 0,
1852 doc: /* Register known name SERVICE on the D-Bus BUS.
1853
1854BUS is either a Lisp symbol, `:system' or `:session', or a string
1855denoting the bus address.
1856
1857SERVICE is the D-Bus service name that should be registered. It must
1858be a known name.
1859
1860FLAGS are keywords, which control how the service name is registered.
1861The following keywords are recognized:
1862
1863`:allow-replacement': Allow another service to become the primary
1864owner if requested.
1865
1866`:replace-existing': Request to replace the current primary owner.
1867
1868`:do-not-queue': If we can not become the primary owner do not place
1869us in the queue.
1870
1871The function returns a keyword, indicating the result of the
1872operation. One of the following keywords is returned:
1873
1874`:primary-owner': Service has become the primary owner of the
1875requested name.
1876
1877`:in-queue': Service could not become the primary owner and has been
1878placed in the queue.
1879
1880`:exists': Service is already in the queue.
1881
1882`:already-owner': Service is already the primary owner.
1883
1884Example:
1885
1886\(dbus-register-service :session dbus-service-emacs)
1887
1888 => :primary-owner.
1889
1890\(dbus-register-service
1891:session "org.freedesktop.TextEditor"
1892dbus-service-allow-replacement dbus-service-replace-existing)
1893
1894 => :already-owner.
1895
1896usage: (dbus-register-service BUS SERVICE &rest FLAGS) */)
1897 (int nargs, register Lisp_Object *args)
1898{
1899 Lisp_Object bus, service;
1900 struct gcpro gcpro1, gcpro2;
1901 DBusConnection *connection;
1902 unsigned int i;
1903 unsigned int value;
1904 unsigned int flags = 0;
1905 int result;
1906 DBusError derror;
1907
1908 bus = args[0];
1909 service = args[1];
1910
1911 /* Check parameters. */
1912 CHECK_STRING (service);
1913
1914 /* Process flags. */
1915 for (i = 2; i < nargs; ++i) {
1916 value = ((EQ (args[i], QCdbus_request_name_replace_existing))
1917 ? DBUS_NAME_FLAG_REPLACE_EXISTING
1918 : (EQ (args[i], QCdbus_request_name_allow_replacement))
1919 ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT
1920 : (EQ (args[i], QCdbus_request_name_do_not_queue))
1921 ? DBUS_NAME_FLAG_DO_NOT_QUEUE
1922 : -1);
1923 if (value == -1)
1924 XD_SIGNAL2 (build_string ("Unrecognized name request flag"), args[i]);
1925 flags |= value;
1926 }
1927
1928 /* Open a connection to the bus. */
1929 connection = xd_initialize (bus, TRUE);
1930
1931 /* Request the known name from the bus. */
1932 dbus_error_init (&derror);
1933 result = dbus_bus_request_name (connection, SDATA (service), flags,
1934 &derror);
1935 if (dbus_error_is_set (&derror))
1936 XD_ERROR (derror);
1937
1938 /* Cleanup. */
1939 dbus_error_free (&derror);
1940
1941 /* Return object. */
1942 switch (result) {
1943 case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
1944 return QCdbus_request_name_reply_primary_owner;
1945 case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
1946 return QCdbus_request_name_reply_in_queue;
1947 case DBUS_REQUEST_NAME_REPLY_EXISTS:
1948 return QCdbus_request_name_reply_exists;
1949 case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
1950 return QCdbus_request_name_reply_already_owner;
1951 default:
1952 return Qnil;
1953 }
1954}
1955
1838DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal, 1956DEFUN ("dbus-register-signal", Fdbus_register_signal, Sdbus_register_signal,
1839 6, MANY, 0, 1957 6, MANY, 0,
1840 doc: /* Register for signal SIGNAL on the D-Bus BUS. 1958 doc: /* Register for signal SIGNAL on the D-Bus BUS.
@@ -2014,6 +2132,7 @@ discovering the still incomplete interface.*/)
2014 DBusConnection *connection; 2132 DBusConnection *connection;
2015 int result; 2133 int result;
2016 DBusError derror; 2134 DBusError derror;
2135 Lisp_Object args[2] = { bus, service };
2017 2136
2018 /* Check parameters. */ 2137 /* Check parameters. */
2019 CHECK_STRING (service); 2138 CHECK_STRING (service);
@@ -2028,18 +2147,9 @@ discovering the still incomplete interface.*/)
2028 /* Open a connection to the bus. */ 2147 /* Open a connection to the bus. */
2029 connection = xd_initialize (bus, TRUE); 2148 connection = xd_initialize (bus, TRUE);
2030 2149
2031 /* Request the known name from the bus. We can ignore the result, 2150 /* Request the name. */
2032 it is set to -1 if there is an error - kind of redundancy. */ 2151 if (NILP(dont_register_service))
2033 if (NILP (dont_register_service)) 2152 Fdbus_register_service (2, args);
2034 {
2035 dbus_error_init (&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 }
2043 2153
2044 /* Create a hash table entry. We use nil for the unique name, 2154 /* Create a hash table entry. We use nil for the unique name,
2045 because the method might be called from anybody. */ 2155 because the method might be called from anybody. */
@@ -2091,6 +2201,10 @@ syms_of_dbusbind (void)
2091 staticpro (&Qdbus_send_signal); 2201 staticpro (&Qdbus_send_signal);
2092 defsubr (&Sdbus_send_signal); 2202 defsubr (&Sdbus_send_signal);
2093 2203
2204 Qdbus_register_service = intern_c_string ("dbus-register-service");
2205 staticpro (&Qdbus_register_service);
2206 defsubr (&Sdbus_register_service);
2207
2094 Qdbus_register_signal = intern_c_string ("dbus-register-signal"); 2208 Qdbus_register_signal = intern_c_string ("dbus-register-signal");
2095 staticpro (&Qdbus_register_signal); 2209 staticpro (&Qdbus_register_signal);
2096 defsubr (&Sdbus_register_signal); 2210 defsubr (&Sdbus_register_signal);
@@ -2112,6 +2226,27 @@ syms_of_dbusbind (void)
2112 QCdbus_session_bus = intern_c_string (":session"); 2226 QCdbus_session_bus = intern_c_string (":session");
2113 staticpro (&QCdbus_session_bus); 2227 staticpro (&QCdbus_session_bus);
2114 2228
2229 QCdbus_request_name_allow_replacement = intern_c_string (":allow-replacement");
2230 staticpro (&QCdbus_request_name_allow_replacement);
2231
2232 QCdbus_request_name_replace_existing = intern_c_string (":replace-existing");
2233 staticpro (&QCdbus_request_name_replace_existing);
2234
2235 QCdbus_request_name_do_not_queue = intern_c_string (":do-not-queue");
2236 staticpro (&QCdbus_request_name_do_not_queue);
2237
2238 QCdbus_request_name_reply_primary_owner = intern_c_string (":primary-owner");
2239 staticpro (&QCdbus_request_name_reply_primary_owner);
2240
2241 QCdbus_request_name_reply_exists = intern_c_string (":exists");
2242 staticpro (&QCdbus_request_name_reply_exists);
2243
2244 QCdbus_request_name_reply_in_queue = intern_c_string (":in-queue");
2245 staticpro (&QCdbus_request_name_reply_in_queue);
2246
2247 QCdbus_request_name_reply_already_owner = intern_c_string (":already-owner");
2248 staticpro (&QCdbus_request_name_reply_already_owner);
2249
2115 QCdbus_timeout = intern_c_string (":timeout"); 2250 QCdbus_timeout = intern_c_string (":timeout");
2116 staticpro (&QCdbus_timeout); 2251 staticpro (&QCdbus_timeout);
2117 2252