static Lisp_Object QCdbus_type_double, QCdbus_type_string;
static Lisp_Object QCdbus_type_object_path, QCdbus_type_signature;
#ifdef DBUS_TYPE_UNIX_FD
-Lisp_Object QCdbus_type_unix_fd;
+static Lisp_Object QCdbus_type_unix_fd;
#endif
static Lisp_Object QCdbus_type_array, QCdbus_type_variant;
static Lisp_Object QCdbus_type_struct, QCdbus_type_dict_entry;
/* Raise a Lisp error from a D-Bus ERROR. */
#define XD_ERROR(error) \
do { \
- char s[1024]; \
- strncpy (s, error.message, 1023); \
- dbus_error_free (&error); \
/* Remove the trailing newline. */ \
- if (strchr (s, '\n') != NULL) \
- s[strlen (s) - 1] = '\0'; \
- XD_SIGNAL1 (build_string (s)); \
+ char const *mess = error.message; \
+ char const *nl = strchr (mess, '\n'); \
+ Lisp_Object err = make_string (mess, nl ? nl - mess : strlen (mess)); \
+ dbus_error_free (&error); \
+ XD_SIGNAL1 (err); \
} while (0)
/* Macros for debugging. In order to enable them, build with
#define XD_DEBUG_MESSAGE(...) \
do { \
char s[1024]; \
- snprintf (s, 1023, __VA_ARGS__); \
+ snprintf (s, sizeof s, __VA_ARGS__); \
printf ("%s: %s\n", __func__, s); \
message ("%s: %s", __func__, s); \
} while (0)
#define XD_NEXT_VALUE(object) \
((XD_DBUS_TYPE_P (CAR_SAFE (object))) ? CDR_SAFE (object) : object)
+/* Check whether X is a valid dbus serial number. If valid, set
+ SERIAL to its value. Otherwise, signal an error. */
+#define CHECK_DBUS_SERIAL_GET_SERIAL(x, serial) \
+ do \
+ { \
+ dbus_uint32_t DBUS_SERIAL_MAX = -1; \
+ if (NATNUMP (x) && XINT (x) <= DBUS_SERIAL_MAX) \
+ serial = XINT (x); \
+ else if (MOST_POSITIVE_FIXNUM < DBUS_SERIAL_MAX \
+ && FLOATP (x) \
+ && 0 <= XFLOAT_DATA (x) \
+ && XFLOAT_DATA (x) <= DBUS_SERIAL_MAX) \
+ serial = XFLOAT_DATA (x); \
+ else \
+ XD_SIGNAL2 (build_string ("Invalid dbus serial"), x); \
+ } \
+ while (0)
+
/* Compute SIGNATURE of OBJECT. It must have a form that it can be
used in dbus_message_iter_open_container. DTYPE is the DBusType
the object is related to. It is passed as argument, because it
switch (dtype)
{
case DBUS_TYPE_BYTE:
- CHECK_NUMBER (object);
+ CHECK_NATNUM (object);
{
- unsigned char val = XUINT (object) & 0xFF;
+ unsigned char val = XFASTINT (object) & 0xFF;
XD_DEBUG_MESSAGE ("%c %d", dtype, val);
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
}
case DBUS_TYPE_UINT16:
- CHECK_NUMBER (object);
+ CHECK_NATNUM (object);
{
- dbus_uint16_t val = XUINT (object);
+ dbus_uint16_t val = XFASTINT (object);
XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val);
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
#ifdef DBUS_TYPE_UNIX_FD
case DBUS_TYPE_UNIX_FD:
#endif
- CHECK_NUMBER (object);
+ CHECK_NATNUM (object);
{
- dbus_uint32_t val = XUINT (object);
+ dbus_uint32_t val = XFASTINT (object);
XD_DEBUG_MESSAGE ("%c %u", dtype, val);
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
}
case DBUS_TYPE_UINT64:
- CHECK_NUMBER (object);
+ CHECK_NATNUM (object);
{
- dbus_uint64_t val = XUINT (object);
- XD_DEBUG_MESSAGE ("%c %"pI"u", dtype, XUINT (object));
+ dbus_uint64_t val = XFASTINT (object);
+ XD_DEBUG_MESSAGE ("%c %"pI"d", dtype, XFASTINT (object));
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
return;
return;
/* Unset session environment. */
- if (SYMBOLP (QCdbus_session_bus) && XSYMBOL (QCdbus_session_bus) == data)
+ if (XSYMBOL (QCdbus_session_bus) == data)
{
XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS");
unsetenv ("DBUS_SESSION_BUS_ADDRESS");
(Lisp_Object bus)
{
DBusConnection *connection;
+ void *busp;
- CHECK_SYMBOL (bus);
+ /* Check parameter. */
+ if (SYMBOLP (bus))
+ busp = XSYMBOL (bus);
+ else if (STRINGP (bus))
+ busp = XSTRING (bus);
+ else
+ wrong_type_argument (intern ("D-Bus"), bus);
/* Open a connection to the bus. */
connection = xd_initialize (bus, TRUE);
xd_add_watch,
xd_remove_watch,
xd_toggle_watch,
- XSYMBOL (bus), NULL))
+ busp, NULL))
XD_SIGNAL1 (build_string ("Cannot add watch functions"));
/* Add bus to list of registered buses. */
=> "i686"
usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TIMEOUT &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object bus, service, path, interface, method;
Lisp_Object result;
DBusError derror;
unsigned int dtype;
int timeout = -1;
- size_t i = 5;
+ ptrdiff_t i = 5;
char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
/* Check parameters. */
if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
{
CHECK_NATNUM (args[i+1]);
- timeout = XUINT (args[i+1]);
+ timeout = XFASTINT (args[i+1]);
i = i+2;
}
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)),
SDATA (format2 ("%s", args[i+1], Qnil)));
++i;
else
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)));
}
/* Return the result. If there is only one single Lisp object,
return it as-it-is, otherwise return the reversed list. */
- if (XUINT (Flength (result)) == 1)
+ if (XFASTINT (Flength (result)) == 1)
RETURN_UNGCPRO (CAR_SAFE (result));
else
RETURN_UNGCPRO (Fnreverse (result));
-| i686
usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLER &optional :timeout TIMEOUT &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object bus, service, path, interface, method, handler;
Lisp_Object result;
DBusMessage *dmessage;
DBusMessageIter iter;
unsigned int dtype;
+ dbus_uint32_t serial;
int timeout = -1;
- size_t i = 6;
+ ptrdiff_t i = 6;
char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
/* Check parameters. */
CHECK_STRING (interface);
CHECK_STRING (method);
if (!NILP (handler) && !FUNCTIONP (handler))
- wrong_type_argument (intern ("functionp"), handler);
+ wrong_type_argument (Qinvalid_function, handler);
GCPRO6 (bus, service, path, interface, method, handler);
XD_DEBUG_MESSAGE ("%s %s %s %s",
if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
{
CHECK_NATNUM (args[i+1]);
- timeout = XUINT (args[i+1]);
+ timeout = XFASTINT (args[i+1]);
i = i+2;
}
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)),
SDATA (format2 ("%s", args[i+1], Qnil)));
++i;
else
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i - 4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)));
}
XD_SIGNAL1 (build_string ("Cannot send message"));
/* The result is the key in Vdbus_registered_objects_table. */
- result = (list2 (bus, make_number (dbus_message_get_serial (dmessage))));
+ serial = dbus_message_get_serial (dmessage);
+ result = list2 (bus, make_fixnum_or_float (serial));
/* Create a hash table entry. */
Fputhash (result, handler, Vdbus_registered_objects_table);
This is an internal function, it shall not be used outside dbus.el.
usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
- Lisp_Object bus, serial, service;
- struct gcpro gcpro1, gcpro2, gcpro3;
+ Lisp_Object bus, service;
+ struct gcpro gcpro1, gcpro2;
DBusConnection *connection;
DBusMessage *dmessage;
DBusMessageIter iter;
- unsigned int dtype;
- size_t i;
+ dbus_uint32_t serial;
+ unsigned int ui_serial, dtype;
+ ptrdiff_t i;
char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
/* Check parameters. */
bus = args[0];
- serial = args[1];
service = args[2];
- CHECK_NUMBER (serial);
+ CHECK_DBUS_SERIAL_GET_SERIAL (args[1], serial);
CHECK_STRING (service);
- GCPRO3 (bus, serial, service);
+ GCPRO2 (bus, service);
- XD_DEBUG_MESSAGE ("%"pI"u %s ", XUINT (serial), SDATA (service));
+ ui_serial = serial;
+ XD_DEBUG_MESSAGE ("%u %s ", ui_serial, SSDATA (service));
/* Open a connection to the bus. */
connection = xd_initialize (bus, TRUE);
/* Create the message. */
dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN);
if ((dmessage == NULL)
- || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
+ || (!dbus_message_set_reply_serial (dmessage, serial))
|| (!dbus_message_set_destination (dmessage, SSDATA (service))))
{
UNGCPRO;
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-2),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
SDATA (format2 ("%s", args[i], Qnil)),
SDATA (format2 ("%s", args[i+1], Qnil)));
++i;
else
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-2),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
SDATA (format2 ("%s", args[i], Qnil)));
}
This is an internal function, it shall not be used outside dbus.el.
usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
- Lisp_Object bus, serial, service;
- struct gcpro gcpro1, gcpro2, gcpro3;
+ Lisp_Object bus, service;
+ struct gcpro gcpro1, gcpro2;
DBusConnection *connection;
DBusMessage *dmessage;
DBusMessageIter iter;
- unsigned int dtype;
- size_t i;
+ dbus_uint32_t serial;
+ unsigned int ui_serial, dtype;
+ ptrdiff_t i;
char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
/* Check parameters. */
bus = args[0];
- serial = args[1];
service = args[2];
- CHECK_NUMBER (serial);
+ CHECK_DBUS_SERIAL_GET_SERIAL (args[1], serial);
CHECK_STRING (service);
- GCPRO3 (bus, serial, service);
+ GCPRO2 (bus, service);
- XD_DEBUG_MESSAGE ("%"pI"u %s ", XUINT (serial), SDATA (service));
+ ui_serial = serial;
+ XD_DEBUG_MESSAGE ("%u %s ", ui_serial, SSDATA (service));
/* Open a connection to the bus. */
connection = xd_initialize (bus, TRUE);
dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
if ((dmessage == NULL)
|| (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED))
- || (!dbus_message_set_reply_serial (dmessage, XUINT (serial)))
+ || (!dbus_message_set_reply_serial (dmessage, serial))
|| (!dbus_message_set_destination (dmessage, SSDATA (service))))
{
UNGCPRO;
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-2),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 2,
SDATA (format2 ("%s", args[i], Qnil)),
SDATA (format2 ("%s", args[i+1], Qnil)));
++i;
else
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-2),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 2,
SDATA (format2 ("%s", args[i], Qnil)));
}
"org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
usage: (dbus-send-signal BUS SERVICE PATH INTERFACE SIGNAL &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object bus, service, path, interface, signal;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
DBusMessage *dmessage;
DBusMessageIter iter;
unsigned int dtype;
- size_t i;
+ ptrdiff_t i;
char signature[DBUS_MAXIMUM_SIGNATURE_LENGTH];
/* Check parameters. */
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
XD_DEBUG_VALID_LISP_OBJECT_P (args[i+1]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s %s", (unsigned long) (i-4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)),
SDATA (format2 ("%s", args[i+1], Qnil)));
++i;
else
{
XD_DEBUG_VALID_LISP_OBJECT_P (args[i]);
- XD_DEBUG_MESSAGE ("Parameter%lu %s", (unsigned long) (i-4),
+ XD_DEBUG_MESSAGE ("Parameter%"pD"d %s", i - 4,
SDATA (format2 ("%s", args[i], Qnil)));
}
DBusMessage *dmessage;
DBusMessageIter iter;
unsigned int dtype;
- int mtype, serial;
+ int mtype;
+ dbus_uint32_t serial;
+ unsigned int ui_serial;
const char *uname, *path, *interface, *member;
dmessage = dbus_connection_pop_message (connection);
/* Read message type, message serial, unique name, object path,
interface and member from the message. */
mtype = dbus_message_get_type (dmessage);
- serial =
+ ui_serial = serial =
((mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN)
|| (mtype == DBUS_MESSAGE_TYPE_ERROR))
? dbus_message_get_reply_serial (dmessage)
interface = dbus_message_get_interface (dmessage);
member = dbus_message_get_member (dmessage);
- XD_DEBUG_MESSAGE ("Event received: %s %d %s %s %s %s %s",
+ XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s",
(mtype == DBUS_MESSAGE_TYPE_INVALID)
? "DBUS_MESSAGE_TYPE_INVALID"
: (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL)
: (mtype == DBUS_MESSAGE_TYPE_ERROR)
? "DBUS_MESSAGE_TYPE_ERROR"
: "DBUS_MESSAGE_TYPE_SIGNAL",
- serial, uname, path, interface, member,
+ ui_serial, uname, path, interface, member,
SDATA (format2 ("%s", args, Qnil)));
if ((mtype == DBUS_MESSAGE_TYPE_METHOD_RETURN)
|| (mtype == DBUS_MESSAGE_TYPE_ERROR))
{
/* Search for a registered function of the message. */
- key = list2 (bus, make_number (serial));
+ key = list2 (bus, make_fixnum_or_float (serial));
value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
/* There shall be exactly one entry. Construct an event. */
EVENT_INIT (event);
event.kind = DBUS_EVENT;
event.frame_or_window = Qnil;
- event.arg = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))),
- args);
+ event.arg
+ = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), args);
break;
}
value = CDR_SAFE (value);
event.arg);
event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)),
event.arg);
- event.arg = Fcons (make_number (serial), event.arg);
+ event.arg = Fcons (make_fixnum_or_float (serial), event.arg);
event.arg = Fcons (make_number (mtype), event.arg);
/* Add the bus symbol to the event. */
if (data != NULL)
while (!NILP (busp))
{
- if (SYMBOLP (CAR_SAFE (busp)) && XSYMBOL (CAR_SAFE (busp)) == data)
+ if ((SYMBOLP (CAR_SAFE (busp)) && XSYMBOL (CAR_SAFE (busp)) == data)
+ || (STRINGP (CAR_SAFE (busp)) && XSTRING (CAR_SAFE (busp)) == data))
bus = CAR_SAFE (busp);
busp = CDR_SAFE (busp);
}
=> :already-owner.
usage: (dbus-register-service BUS SERVICE &rest FLAGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object bus, service;
DBusConnection *connection;
- size_t i;
+ ptrdiff_t i;
unsigned int value;
unsigned int flags = 0;
int result;
`dbus-unregister-object' for removing the registration.
usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARGS) */)
- (size_t nargs, register Lisp_Object *args)
+ (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object bus, service, path, interface, signal, handler;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
Lisp_Object uname, key, key1, value;
DBusConnection *connection;
- size_t i;
+ ptrdiff_t i;
char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
DBusError derror;
CHECK_STRING (interface);
CHECK_STRING (signal);
if (!FUNCTIONP (handler))
- wrong_type_argument (intern ("functionp"), handler);
+ wrong_type_argument (Qinvalid_function, handler);
GCPRO6 (bus, service, path, interface, signal, handler);
/* Retrieve unique name of service. If service is a known name, we
if (!NILP (args[i]))
{
CHECK_STRING (args[i]);
- sprintf (x, ",arg%lu='%s'", (unsigned long) (i-6),
+ sprintf (x, ",arg%"pD"d='%s'", i - 6,
SDATA (args[i]));
strcat (rule, x);
}
CHECK_STRING (interface);
CHECK_STRING (method);
if (!FUNCTIONP (handler))
- wrong_type_argument (intern ("functionp"), handler);
+ wrong_type_argument (Qinvalid_function, handler);
/* TODO: We must check for a valid service name, otherwise there is
a segmentation fault. */
staticpro (&Qdbus_call_method);
defsubr (&Sdbus_call_method);
- Qdbus_call_method_asynchronously = intern_c_string ("dbus-call-method-asynchronously");
+ Qdbus_call_method_asynchronously
+ = intern_c_string ("dbus-call-method-asynchronously");
staticpro (&Qdbus_call_method_asynchronously);
defsubr (&Sdbus_call_method_asynchronously);
- Qdbus_method_return_internal = intern_c_string ("dbus-method-return-internal");
+ Qdbus_method_return_internal
+ = intern_c_string ("dbus-method-return-internal");
staticpro (&Qdbus_method_return_internal);
defsubr (&Sdbus_method_return_internal);
QCdbus_session_bus = intern_c_string (":session");
staticpro (&QCdbus_session_bus);
- QCdbus_request_name_allow_replacement = intern_c_string (":allow-replacement");
+ QCdbus_request_name_allow_replacement
+ = intern_c_string (":allow-replacement");
staticpro (&QCdbus_request_name_allow_replacement);
QCdbus_request_name_replace_existing = intern_c_string (":replace-existing");