diff options
| author | Michael Albinus | 2010-07-04 11:52:57 +0200 |
|---|---|---|
| committer | Michael Albinus | 2010-07-04 11:52:57 +0200 |
| commit | b1ce08daa9bb90d7d4d6f978b9863c3853ca30cb (patch) | |
| tree | 4ac8806e48716bbd4c0e843e03b145e20f533efb | |
| parent | 971de7fb158335fbda39525feb2d7776a26bc030 (diff) | |
| download | emacs-b1ce08daa9bb90d7d4d6f978b9863c3853ca30cb.tar.gz emacs-b1ce08daa9bb90d7d4d6f978b9863c3853ca30cb.zip | |
* net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1).
(dbus-register-property): New optional argument EMITS-SIGNAL.
(dbus-property-handler): Send signal "PropertiesChanged" if requested.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/net/dbus.el | 57 |
2 files changed, 50 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b087fbb5b8e..2404509c920 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-07-04 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/dbus.el: Implement signal "PropertiesChanged" (from D-Bus 1.3.1). | ||
| 4 | (dbus-register-property): New optional argument EMITS-SIGNAL. | ||
| 5 | (dbus-property-handler): Send signal "PropertiesChanged" if requested. | ||
| 6 | |||
| 1 | 2010-07-03 Chong Yidong <cyd@stupidchicken.com> | 7 | 2010-07-03 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * mouse.el (mouse-drag-overlay): Variable deleted. | 9 | * mouse.el (mouse-drag-overlay): Variable deleted. |
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index 46cbb723d76..8c10074b25c 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el | |||
| @@ -869,7 +869,7 @@ name of the property, and its value. If there are no properties, | |||
| 869 | (add-to-list 'result (cons (car dict) (caadr dict)) 'append))))) | 869 | (add-to-list 'result (cons (car dict) (caadr dict)) 'append))))) |
| 870 | 870 | ||
| 871 | (defun dbus-register-property | 871 | (defun dbus-register-property |
| 872 | (bus service path interface property access value) | 872 | (bus service path interface property access value &optional emits-signal) |
| 873 | "Register property PROPERTY on the D-Bus BUS. | 873 | "Register property PROPERTY on the D-Bus BUS. |
| 874 | 874 | ||
| 875 | BUS is either the symbol `:system' or the symbol `:session'. | 875 | BUS is either the symbol `:system' or the symbol `:session'. |
| @@ -892,7 +892,9 @@ can be changed by `dbus-set-property'. | |||
| 892 | 892 | ||
| 893 | The interface \"org.freedesktop.DBus.Properties\" is added to | 893 | The interface \"org.freedesktop.DBus.Properties\" is added to |
| 894 | PATH, including a default handler for the \"Get\", \"GetAll\" and | 894 | PATH, including a default handler for the \"Get\", \"GetAll\" and |
| 895 | \"Set\" methods of this interface." | 895 | \"Set\" methods of this interface. When EMITS-SIGNAL is non-nil, |
| 896 | the signal \"PropertiesChanged\" is sent when the property is | ||
| 897 | changed by `dbus-set-property'." | ||
| 896 | (unless (member access '(:read :readwrite)) | 898 | (unless (member access '(:read :readwrite)) |
| 897 | (signal 'dbus-error (list "Access type invalid" access))) | 899 | (signal 'dbus-error (list "Access type invalid" access))) |
| 898 | 900 | ||
| @@ -911,10 +913,23 @@ PATH, including a default handler for the \"Get\", \"GetAll\" and | |||
| 911 | (dbus-register-method | 913 | (dbus-register-method |
| 912 | bus service path dbus-interface-properties "Set" 'dbus-property-handler) | 914 | bus service path dbus-interface-properties "Set" 'dbus-property-handler) |
| 913 | 915 | ||
| 916 | ;; Send the PropertiesChanged signal. | ||
| 917 | (when emits-signal | ||
| 918 | (dbus-send-signal | ||
| 919 | bus service path dbus-interface-properties "PropertiesChanged" | ||
| 920 | (list (list :dict-entry property (list :variant value))) | ||
| 921 | '(:array))) | ||
| 922 | |||
| 914 | ;; Create a hash table entry. We use nil for the unique name, | 923 | ;; Create a hash table entry. We use nil for the unique name, |
| 915 | ;; because the property might be accessed from anybody. | 924 | ;; because the property might be accessed from anybody. |
| 916 | (let ((key (list bus interface property)) | 925 | (let ((key (list bus interface property)) |
| 917 | (val (list (list nil service path (cons access value))))) | 926 | (val |
| 927 | (list | ||
| 928 | (list | ||
| 929 | nil service path | ||
| 930 | (cons | ||
| 931 | (if emits-signal (list access :emits-signal) (list access)) | ||
| 932 | value))))) | ||
| 918 | (puthash key val dbus-registered-objects-table) | 933 | (puthash key val dbus-registered-objects-table) |
| 919 | 934 | ||
| 920 | ;; Return the object. | 935 | ;; Return the object. |
| @@ -924,6 +939,7 @@ PATH, including a default handler for the \"Get\", \"GetAll\" and | |||
| 924 | "Default handler for the \"org.freedesktop.DBus.Properties\" interface. | 939 | "Default handler for the \"org.freedesktop.DBus.Properties\" interface. |
| 925 | It will be registered for all objects created by `dbus-register-object'." | 940 | It will be registered for all objects created by `dbus-register-object'." |
| 926 | (let ((bus (dbus-event-bus-name last-input-event)) | 941 | (let ((bus (dbus-event-bus-name last-input-event)) |
| 942 | (service (dbus-event-service-name last-input-event)) | ||
| 927 | (path (dbus-event-path-name last-input-event)) | 943 | (path (dbus-event-path-name last-input-event)) |
| 928 | (method (dbus-event-member-name last-input-event)) | 944 | (method (dbus-event-member-name last-input-event)) |
| 929 | (interface (car args)) | 945 | (interface (car args)) |
| @@ -931,25 +947,40 @@ It will be registered for all objects created by `dbus-register-object'." | |||
| 931 | (cond | 947 | (cond |
| 932 | ;; "Get" returns a variant. | 948 | ;; "Get" returns a variant. |
| 933 | ((string-equal method "Get") | 949 | ((string-equal method "Get") |
| 934 | (let ((val (gethash (list bus interface property) | 950 | (let ((entry (gethash (list bus interface property) |
| 935 | dbus-registered-objects-table))) | 951 | dbus-registered-objects-table))) |
| 936 | (when (string-equal path (nth 2 (car val))) | 952 | (when (string-equal path (nth 2 (car entry))) |
| 937 | (list (list :variant (cdar (last (car val)))))))) | 953 | (list (list :variant (cdar (last (car entry)))))))) |
| 938 | 954 | ||
| 939 | ;; "Set" expects a variant. | 955 | ;; "Set" expects a variant. |
| 940 | ((string-equal method "Set") | 956 | ((string-equal method "Set") |
| 941 | (let ((val (gethash (list bus interface property) | 957 | (let* ((value (caar (cddr args))) |
| 942 | dbus-registered-objects-table))) | 958 | (entry (gethash (list bus interface property) |
| 943 | (unless (consp (car (last (car val)))) | 959 | dbus-registered-objects-table)) |
| 960 | ;; The value of the hash table is a list; in case of | ||
| 961 | ;; properties it contains just one element (UNAME SERVICE | ||
| 962 | ;; PATH OBJECT). OBJECT is a cons cell of a list, which | ||
| 963 | ;; contains a list of annotations (like :read, | ||
| 964 | ;; :read-write, :emits-signal), and the value of the | ||
| 965 | ;; property. | ||
| 966 | (object (car (last (car entry))))) | ||
| 967 | (unless (consp object) | ||
| 944 | (signal 'dbus-error | 968 | (signal 'dbus-error |
| 945 | (list "Property not registered at path" property path))) | 969 | (list "Property not registered at path" property path))) |
| 946 | (unless (equal (caar (last (car val))) :readwrite) | 970 | (unless (member :readwrite (car object)) |
| 947 | (signal 'dbus-error | 971 | (signal 'dbus-error |
| 948 | (list "Property not writable at path" property path))) | 972 | (list "Property not writable at path" property path))) |
| 949 | (puthash (list bus interface property) | 973 | (puthash (list bus interface property) |
| 950 | (list (append (butlast (car val)) | 974 | (list (append (butlast (car entry)) |
| 951 | (list (cons :readwrite (caar (cddr args)))))) | 975 | (list (cons (car object) value)))) |
| 952 | dbus-registered-objects-table) | 976 | dbus-registered-objects-table) |
| 977 | ;; Send the "PropertiesChanged" signal. | ||
| 978 | (when (member :emits-signal (car object)) | ||
| 979 | (dbus-send-signal | ||
| 980 | bus service path dbus-interface-properties "PropertiesChanged" | ||
| 981 | (list (list :dict-entry property (list :variant value))) | ||
| 982 | '(:array))) | ||
| 983 | ;; Return empty reply. | ||
| 953 | :ignore)) | 984 | :ignore)) |
| 954 | 985 | ||
| 955 | ;; "GetAll" returns "a{sv}". | 986 | ;; "GetAll" returns "a{sv}". |