: DBUS_TYPE_INVALID);
}
-/* Determine the DBusType of a given Lisp symbol. OBJECT must be one
- of the predefined D-Bus type symbols. */
+/* Determine the Lisp symbol of a given type. If DTYPE isn't a valid
+ DBusType, Qnil is returned. */
static Lisp_Object
xd_dbus_type_to_symbol (int dtype)
{
#ifdef DBUS_TYPE_UNIX_FD
case DBUS_TYPE_UNIX_FD:
return QCdbus_type_unix_fd;
-
#endif
+
case DBUS_TYPE_ARRAY:
return QCdbus_type_array;
}
/* Convert argument type to a Lisp object. The type DTYPE of the
- argument of the D-Bus message must be a valid DBusType. */
+ argument of the D-Bus message must be a valid DBusType, otherwise
+ Qnil is returned. */
static Lisp_Object
xd_arg_type_to_lisp (int dtype, DBusMessageIter *iter)
{
{
DBusMessage *dmessage;
- /* Lisp objects used by Fdbus_message_internal. */
+ /* Lisp objects used by Fdbus_message_internal[_to_lisp]. */
Lisp_Object bus;
Lisp_Object handler;
+
int timeout;
};
static void
-xd_build_message (struct xd_message *xmessage,
+xd_build_message (Lisp_Object caller, struct xd_message *xmessage,
ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object message_type, bus, service, handler;
XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
XD_DBUS_VALIDATE_BUS_NAME (service);
if (nargs < count)
- xsignal2 (Qwrong_number_of_arguments,
- Qdbus_message_internal,
- make_number (nargs));
+ xsignal2 (Qwrong_number_of_arguments, caller, make_number (nargs));
if ((mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
|| (mtype == DBUS_MESSAGE_TYPE_SIGNAL))
xmessage.timeout = -1;
/* Create a D-Bus message. */
- xd_build_message (&xmessage, nargs, args);
+ xd_build_message (Qdbus_message_internal, &xmessage, nargs, args);
/* Retrieve bus address. */
connection = xd_get_connection_address (xmessage.bus);
result = Fplist_put (result, QCdbus_type_type,
build_string (XD_MESSAGE_TYPE_TO_STRING (mtype)));
-#define ADD_HEADER(name) \
+#define XD_ADD_HEADER(name) \
{ \
const char *name = dbus_message_get_##name (dmessage); \
if (name) \
build_string (name)); \
}
- ADD_HEADER (path);
- ADD_HEADER (interface);
- ADD_HEADER (member);
- ADD_HEADER (destination);
- ADD_HEADER (sender);
- ADD_HEADER (signature);
+ XD_ADD_HEADER (path);
+ XD_ADD_HEADER (interface);
+ XD_ADD_HEADER (member);
+ XD_ADD_HEADER (destination);
+ XD_ADD_HEADER (sender);
+ XD_ADD_HEADER (signature);
-#undef ADD_HEADER
+#undef XD_ADD_HEADER
/* Collect the parameters. */
args = Qnil;
xmessage.timeout = -1;
/* Create a D-Bus message. */
- xd_build_message (&xmessage, nargs, args);
+ xd_build_message (Qdbus_message_internal_to_lisp, &xmessage, nargs, args);
/* Convert the D-Bus message to a Lisp expression. */
result = xd_dbus_message_to_lisp (xmessage.dmessage);
defsubr (&Sdbus__init_bus);
defsubr (&Sdbus_get_unique_name);
- defsubr (&Sdbus_message_internal_to_lisp);
DEFSYM (Qdbus_message_internal, "dbus-message-internal");
defsubr (&Sdbus_message_internal);
+ DEFSYM (Qdbus_message_internal_to_lisp, "dbus-message-internal-to-lisp");
+ defsubr (&Sdbus_message_internal_to_lisp);
/* D-Bus error symbol. */
DEFSYM (Qdbus_error, "dbus-error");
(should-not (dbus-ping :session dbus-service-emacs 100)))
(defun dbus--test-create-message-with-args (&rest args)
+ "Create a D-Bus message according to ARGS."
(dbus-ignore-errors
(apply #'dbus-message-internal-to-lisp
dbus-message-type-method-call
:session
;; Passing nil as SERVICE means not to require bus connection.
nil
- dbus-path-dbus dbus-interface-dbus "Hello" #'ignore :timeout 100
+ dbus-path-emacs dbus-interface-emacs "Hello" #'ignore :timeout 100
args)))
(ert-deftest dbus-test04-create-message-parameters ()
:type :int32 1))
(should (equal (plist-get message :args) '((:int32 1))))
(should (equal (plist-get message :signature) "i"))
- ;; Test explicit type specifications for empty array.
+ ;; Test explicit type specifications for empty array with implicit
+ ;; element type.
(setq message (dbus--test-create-message-with-args
'(:array)))
(should (equal (plist-get message :args) '(((:array nil) nil))))
(should (equal (plist-get message :signature) "as"))
+ ;; Test explicit type specifications for empty array with explicit
+ ;; element type.
+ (setq message (dbus--test-create-message-with-args
+ '(:array :signature "u")))
+ (should (equal (plist-get message :args) '(((:array nil) nil))))
+ (should (equal (plist-get message :signature) "au"))
+ ;; Test explicit type specifications with `:type' keyword for empty array.
+ ;; DOES THIS WORK?
+ (setq message (dbus--test-create-message-with-args
+ :type '(:array :uint32)))
+ (should (equal (plist-get message :args) '(((:array nil) nil))))
+ (should (equal (plist-get message :signature) "au"))
;; Test implicit type specifications for non-empty array.
(setq message (dbus--test-create-message-with-args
'(1 2 3)))