aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorMichael Albinus2020-09-16 14:32:57 +0200
committerMichael Albinus2020-09-16 14:32:57 +0200
commit92f342f38dd82aae4a662708dd6280fdfb2e013b (patch)
treed6c895200d165224678d04b51ae03d8f149ca23a /src/dbusbind.c
parent96f1fedf4dd662dbd5bba7eebc0b9c9e926fbce6 (diff)
downloademacs-92f342f38dd82aae4a662708dd6280fdfb2e013b.tar.gz
emacs-92f342f38dd82aae4a662708dd6280fdfb2e013b.zip
D-Bus: keep type information in D-Bus events
* doc/misc/dbus.texi (Errors and Events): * etc/NEWS: D-Bus events keep the type information of their arguments. * lisp/net/dbus.el (dbus-check-event): Fix docstring. (dbus-delete-types, dbus-flatten-types): New defuns. (dbus-handle-event, dbus-register-property, dbus-property-handler): Handle type information. (dbus-set-property): Fix thinko. * src/dbusbind.c (XD_BASIC_DBUS_TYPE): Simplify. (xd_dbus_type_to_symbol): New function. (xd_retrieve_arg): Return type information for the arguments. (xd_read_message_1): Return type information for the error name. (dbus-registered-objects-table): Fix docstring.
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c104
1 files changed, 60 insertions, 44 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 02af244ac38..46e2e22aa0e 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -129,36 +129,23 @@ static bool xd_in_read_queued_messages = 0;
129#define XD_BASIC_DBUS_TYPE(type) \ 129#define XD_BASIC_DBUS_TYPE(type) \
130 (dbus_type_is_valid (type) && dbus_type_is_basic (type)) 130 (dbus_type_is_valid (type) && dbus_type_is_basic (type))
131#else 131#else
132#ifdef DBUS_TYPE_UNIX_FD
133#define XD_BASIC_DBUS_TYPE(type) \
134 ((type == DBUS_TYPE_BYTE) \
135 || (type == DBUS_TYPE_BOOLEAN) \
136 || (type == DBUS_TYPE_INT16) \
137 || (type == DBUS_TYPE_UINT16) \
138 || (type == DBUS_TYPE_INT32) \
139 || (type == DBUS_TYPE_UINT32) \
140 || (type == DBUS_TYPE_INT64) \
141 || (type == DBUS_TYPE_UINT64) \
142 || (type == DBUS_TYPE_DOUBLE) \
143 || (type == DBUS_TYPE_STRING) \
144 || (type == DBUS_TYPE_OBJECT_PATH) \
145 || (type == DBUS_TYPE_SIGNATURE) \
146 || (type == DBUS_TYPE_UNIX_FD))
147#else
148#define XD_BASIC_DBUS_TYPE(type) \ 132#define XD_BASIC_DBUS_TYPE(type) \
149 ((type == DBUS_TYPE_BYTE) \ 133 ((type == DBUS_TYPE_BYTE) \
150 || (type == DBUS_TYPE_BOOLEAN) \ 134 || (type == DBUS_TYPE_BOOLEAN) \
151 || (type == DBUS_TYPE_INT16) \ 135 || (type == DBUS_TYPE_INT16) \
152 || (type == DBUS_TYPE_UINT16) \ 136 || (type == DBUS_TYPE_UINT16) \
153 || (type == DBUS_TYPE_INT32) \ 137 || (type == DBUS_TYPE_INT32) \
154 || (type == DBUS_TYPE_UINT32) \ 138 || (type == DBUS_TYPE_UINT32) \
155 || (type == DBUS_TYPE_INT64) \ 139 || (type == DBUS_TYPE_INT64) \
156 || (type == DBUS_TYPE_UINT64) \ 140 || (type == DBUS_TYPE_UINT64) \
157 || (type == DBUS_TYPE_DOUBLE) \ 141 || (type == DBUS_TYPE_DOUBLE) \
158 || (type == DBUS_TYPE_STRING) \ 142 || (type == DBUS_TYPE_STRING) \
159 || (type == DBUS_TYPE_OBJECT_PATH) \ 143 || (type == DBUS_TYPE_OBJECT_PATH) \
160 || (type == DBUS_TYPE_SIGNATURE)) 144 || (type == DBUS_TYPE_SIGNATURE) \
145#ifdef DBUS_TYPE_UNIX_FD
146 || (type == DBUS_TYPE_UNIX_FD) \
161#endif 147#endif
148 )
162#endif 149#endif
163 150
164/* This was a macro. On Solaris 2.11 it was said to compile for 151/* This was a macro. On Solaris 2.11 it was said to compile for
@@ -192,6 +179,33 @@ xd_symbol_to_dbus_type (Lisp_Object object)
192 : DBUS_TYPE_INVALID); 179 : DBUS_TYPE_INVALID);
193} 180}
194 181
182/* Determine the Lisp symbol of DBusType. */
183static Lisp_Object
184xd_dbus_type_to_symbol (int type)
185{
186 return
187 (type == DBUS_TYPE_BYTE) ? QCbyte
188 : (type == DBUS_TYPE_BOOLEAN) ? QCboolean
189 : (type == DBUS_TYPE_INT16) ? QCint16
190 : (type == DBUS_TYPE_UINT16) ? QCuint16
191 : (type == DBUS_TYPE_INT32) ? QCint32
192 : (type == DBUS_TYPE_UINT32) ? QCuint32
193 : (type == DBUS_TYPE_INT64) ? QCint64
194 : (type == DBUS_TYPE_UINT64) ? QCuint64
195 : (type == DBUS_TYPE_DOUBLE) ? QCdouble
196 : (type == DBUS_TYPE_STRING) ? QCstring
197 : (type == DBUS_TYPE_OBJECT_PATH) ? QCobject_path
198 : (type == DBUS_TYPE_SIGNATURE) ? QCsignature
199#ifdef DBUS_TYPE_UNIX_FD
200 : (type == DBUS_TYPE_UNIX_FD) ? QCunix_fd
201#endif
202 : (type == DBUS_TYPE_ARRAY) ? QCarray
203 : (type == DBUS_TYPE_VARIANT) ? QCvariant
204 : (type == DBUS_TYPE_STRUCT) ? QCstruct
205 : (type == DBUS_TYPE_DICT_ENTRY) ? QCdict_entry
206 : Qnil;
207}
208
195/* Check whether a Lisp symbol is a predefined D-Bus type symbol. */ 209/* Check whether a Lisp symbol is a predefined D-Bus type symbol. */
196#define XD_DBUS_TYPE_P(object) \ 210#define XD_DBUS_TYPE_P(object) \
197 (SYMBOLP (object) && ((xd_symbol_to_dbus_type (object) != DBUS_TYPE_INVALID))) 211 (SYMBOLP (object) && ((xd_symbol_to_dbus_type (object) != DBUS_TYPE_INVALID)))
@@ -816,7 +830,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
816 dbus_message_iter_get_basic (iter, &val); 830 dbus_message_iter_get_basic (iter, &val);
817 val = val & 0xFF; 831 val = val & 0xFF;
818 XD_DEBUG_MESSAGE ("%c %u", dtype, val); 832 XD_DEBUG_MESSAGE ("%c %u", dtype, val);
819 return make_fixnum (val); 833 return list2 (xd_dbus_type_to_symbol (dtype), make_fixnum (val));
820 } 834 }
821 835
822 case DBUS_TYPE_BOOLEAN: 836 case DBUS_TYPE_BOOLEAN:
@@ -824,7 +838,8 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
824 dbus_bool_t val; 838 dbus_bool_t val;
825 dbus_message_iter_get_basic (iter, &val); 839 dbus_message_iter_get_basic (iter, &val);
826 XD_DEBUG_MESSAGE ("%c %s", dtype, (val == FALSE) ? "false" : "true"); 840 XD_DEBUG_MESSAGE ("%c %s", dtype, (val == FALSE) ? "false" : "true");
827 return (val == FALSE) ? Qnil : Qt; 841 return list2 (xd_dbus_type_to_symbol (dtype),
842 (val == FALSE) ? Qnil : Qt);
828 } 843 }
829 844
830 case DBUS_TYPE_INT16: 845 case DBUS_TYPE_INT16:
@@ -834,7 +849,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
834 dbus_message_iter_get_basic (iter, &val); 849 dbus_message_iter_get_basic (iter, &val);
835 pval = val; 850 pval = val;
836 XD_DEBUG_MESSAGE ("%c %d", dtype, pval); 851 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
837 return make_fixnum (val); 852 return list2 (xd_dbus_type_to_symbol (dtype), make_fixnum (val));
838 } 853 }
839 854
840 case DBUS_TYPE_UINT16: 855 case DBUS_TYPE_UINT16:
@@ -844,7 +859,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
844 dbus_message_iter_get_basic (iter, &val); 859 dbus_message_iter_get_basic (iter, &val);
845 pval = val; 860 pval = val;
846 XD_DEBUG_MESSAGE ("%c %d", dtype, pval); 861 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
847 return make_fixnum (val); 862 return list2 (xd_dbus_type_to_symbol (dtype), make_fixnum (val));
848 } 863 }
849 864
850 case DBUS_TYPE_INT32: 865 case DBUS_TYPE_INT32:
@@ -854,7 +869,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
854 dbus_message_iter_get_basic (iter, &val); 869 dbus_message_iter_get_basic (iter, &val);
855 pval = val; 870 pval = val;
856 XD_DEBUG_MESSAGE ("%c %d", dtype, pval); 871 XD_DEBUG_MESSAGE ("%c %d", dtype, pval);
857 return INT_TO_INTEGER (val); 872 return list2 (xd_dbus_type_to_symbol (dtype), INT_TO_INTEGER (val));
858 } 873 }
859 874
860 case DBUS_TYPE_UINT32: 875 case DBUS_TYPE_UINT32:
@@ -867,7 +882,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
867 dbus_message_iter_get_basic (iter, &val); 882 dbus_message_iter_get_basic (iter, &val);
868 pval = val; 883 pval = val;
869 XD_DEBUG_MESSAGE ("%c %u", dtype, pval); 884 XD_DEBUG_MESSAGE ("%c %u", dtype, pval);
870 return INT_TO_INTEGER (val); 885 return list2 (xd_dbus_type_to_symbol (dtype), INT_TO_INTEGER (val));
871 } 886 }
872 887
873 case DBUS_TYPE_INT64: 888 case DBUS_TYPE_INT64:
@@ -876,7 +891,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
876 dbus_message_iter_get_basic (iter, &val); 891 dbus_message_iter_get_basic (iter, &val);
877 intmax_t pval = val; 892 intmax_t pval = val;
878 XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval); 893 XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval);
879 return INT_TO_INTEGER (val); 894 return list2 (xd_dbus_type_to_symbol (dtype), INT_TO_INTEGER (val));
880 } 895 }
881 896
882 case DBUS_TYPE_UINT64: 897 case DBUS_TYPE_UINT64:
@@ -885,7 +900,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
885 dbus_message_iter_get_basic (iter, &val); 900 dbus_message_iter_get_basic (iter, &val);
886 uintmax_t pval = val; 901 uintmax_t pval = val;
887 XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval); 902 XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval);
888 return INT_TO_INTEGER (val); 903 return list2 (xd_dbus_type_to_symbol (dtype), INT_TO_INTEGER (val));
889 } 904 }
890 905
891 case DBUS_TYPE_DOUBLE: 906 case DBUS_TYPE_DOUBLE:
@@ -893,7 +908,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
893 double val; 908 double val;
894 dbus_message_iter_get_basic (iter, &val); 909 dbus_message_iter_get_basic (iter, &val);
895 XD_DEBUG_MESSAGE ("%c %f", dtype, val); 910 XD_DEBUG_MESSAGE ("%c %f", dtype, val);
896 return make_float (val); 911 return list2 (xd_dbus_type_to_symbol (dtype), make_float (val));
897 } 912 }
898 913
899 case DBUS_TYPE_STRING: 914 case DBUS_TYPE_STRING:
@@ -903,7 +918,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
903 char *val; 918 char *val;
904 dbus_message_iter_get_basic (iter, &val); 919 dbus_message_iter_get_basic (iter, &val);
905 XD_DEBUG_MESSAGE ("%c %s", dtype, val); 920 XD_DEBUG_MESSAGE ("%c %s", dtype, val);
906 return build_string (val); 921 return list2 (xd_dbus_type_to_symbol (dtype), build_string (val));
907 } 922 }
908 923
909 case DBUS_TYPE_ARRAY: 924 case DBUS_TYPE_ARRAY:
@@ -923,7 +938,7 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
923 dbus_message_iter_next (&subiter); 938 dbus_message_iter_next (&subiter);
924 } 939 }
925 XD_DEBUG_MESSAGE ("%c %s", dtype, XD_OBJECT_TO_STRING (result)); 940 XD_DEBUG_MESSAGE ("%c %s", dtype, XD_OBJECT_TO_STRING (result));
926 return Fnreverse (result); 941 return Fcons (xd_dbus_type_to_symbol (dtype), Fnreverse (result));
927 } 942 }
928 943
929 default: 944 default:
@@ -1544,7 +1559,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1544 path = dbus_message_get_path (dmessage); 1559 path = dbus_message_get_path (dmessage);
1545 interface = dbus_message_get_interface (dmessage); 1560 interface = dbus_message_get_interface (dmessage);
1546 member = dbus_message_get_member (dmessage); 1561 member = dbus_message_get_member (dmessage);
1547 error_name =dbus_message_get_error_name (dmessage); 1562 error_name = dbus_message_get_error_name (dmessage);
1548 1563
1549 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s %s", 1564 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s %s",
1550 XD_MESSAGE_TYPE_TO_STRING (mtype), 1565 XD_MESSAGE_TYPE_TO_STRING (mtype),
@@ -1572,9 +1587,10 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1572 EVENT_INIT (event); 1587 EVENT_INIT (event);
1573 event.kind = DBUS_EVENT; 1588 event.kind = DBUS_EVENT;
1574 event.frame_or_window = Qnil; 1589 event.frame_or_window = Qnil;
1575 event.arg = Fcons (value, 1590 event.arg =
1576 (mtype == DBUS_MESSAGE_TYPE_ERROR) 1591 Fcons (value,
1577 ? (Fcons (build_string (error_name), args)) : args); 1592 (mtype == DBUS_MESSAGE_TYPE_ERROR)
1593 ? Fcons (list2 (QCstring, build_string (error_name)), args) : args);
1578 } 1594 }
1579 1595
1580 else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */ 1596 else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */
@@ -1828,7 +1844,7 @@ wildcard then.
1828 1844
1829OBJECT is either the handler to be called when a D-Bus message, which 1845OBJECT is either the handler to be called when a D-Bus message, which
1830matches the key criteria, arrives (TYPE `:method' and `:signal'), or a 1846matches the key criteria, arrives (TYPE `:method' and `:signal'), or a
1831list (ACCESS EMITS-SIGNAL SIGNATURE VALUE) for TYPE `:property'. 1847list (ACCESS EMITS-SIGNAL VALUE) for TYPE `:property'.
1832 1848
1833For entries of type `:signal', there is also a fifth element RULE, 1849For entries of type `:signal', there is also a fifth element RULE,
1834which keeps the match string the signal is registered with. 1850which keeps the match string the signal is registered with.