diff options
author | Daniel Stone <daniel@fooishbar.org> | 2007-07-08 14:30:53 +0300 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2007-08-01 01:53:31 +0300 |
commit | 9ac7e8a559fe6008cafc95e8264680c50e72ba19 (patch) | |
tree | 5777fcbda0daefa1d8f5d588667ec0b8b1d1c90b /config/dbus.c | |
parent | 1cdadc2f43d9069572814510d04b1a560c488fcb (diff) |
Hotplug: D-Bus: API version 2
Use uint32s instead of int32s where practical, and add an API version
request. Also, try to return all devices added, not just the first,
and box device arguments.
Diffstat (limited to 'config/dbus.c')
-rw-r--r-- | config/dbus.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/config/dbus.c b/config/dbus.c index 2450e0c00..861aa8ee8 100644 --- a/config/dbus.c +++ b/config/dbus.c @@ -36,7 +36,7 @@ #include "input.h" #include "inputstr.h" -#define API_VERSION 1 +#define API_VERSION 2 #define MATCH_RULE "type='method_call',interface='org.x.config.input'" @@ -156,11 +156,17 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) goto unwind; } - if (!dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, - &dev->id)) { - ErrorF("[config/dbus] couldn't append to iterator\n"); - ret = BadAlloc; - goto unwind; + /* XXX: If we fail halfway through, we don't seem to have any way to + * empty the iterator, so you'll end up with some device IDs, + * plus an error. This seems to be a shortcoming in the D-Bus + * API. */ + for (; dev; dev = dev->next) { + if (!dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, + &dev->id)) { + ErrorF("[config/dbus] couldn't append to iterator\n"); + ret = BadAlloc; + goto unwind; + } } unwind: @@ -198,7 +204,7 @@ remove_device(DBusMessage *message, DBusMessage *reply, DBusError *error) } dbus_message_iter_init_append(reply, &reply_iter); - if (!dbus_message_get_args(message, error, DBUS_TYPE_INT32, + if (!dbus_message_get_args(message, error, DBUS_TYPE_UINT32, &deviceid, DBUS_TYPE_INVALID)) { MALFORMED_MESSAGE_ERROR(); } @@ -232,21 +238,45 @@ static int list_devices(DBusMessage *message, DBusMessage *reply, DBusError *error) { DeviceIntPtr dev; - DBusMessageIter iter; + DBusMessageIter iter, subiter; dbus_message_iter_init_append(reply, &iter); for (dev = inputInfo.devices; dev; dev = dev->next) { - if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, + if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, + &subiter)) { + ErrorF("[config/dbus] couldn't init container\n"); + return BadAlloc; + } + if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_UINT32, &dev->id)) { ErrorF("[config/dbus] couldn't append to iterator\n"); return BadAlloc; } - if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, + if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &dev->name)) { ErrorF("[config/dbus] couldn't append to iterator\n"); return BadAlloc; } + if (!dbus_message_iter_close_container(&iter, &subiter)) { + ErrorF("[config/dbus] couldn't close container\n"); + return BadAlloc; + } + } + + return Success; +} + +static int +get_version(DBusMessage *message, DBusMessage *reply, DBusError *error) +{ + DBusMessageIter iter; + unsigned int version = API_VERSION; + + dbus_message_iter_init_append(reply, &iter); + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &version)) { + ErrorF("[config/dbus] couldn't append version\n"); + return BadAlloc; } return Success; @@ -282,6 +312,8 @@ message_handler(DBusConnection *connection, DBusMessage *message, void *data) err = remove_device(message, reply, &error); else if (strcmp(dbus_message_get_member(message), "listDevices") == 0) err = list_devices(message, reply, &error); + else if (strcmp(dbus_message_get_member(message), "version") == 0) + err = get_version(message, reply, &error); else goto err_reply; |