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.
This commit is contained in:
Daniel Stone 2007-07-08 14:30:53 +03:00
parent 1cdadc2f43
commit 9ac7e8a559
2 changed files with 53 additions and 18 deletions

View File

@ -1,4 +1,4 @@
D-BUS Configuration API v0.1 D-BUS Configuration API v2
---------------------------- ----------------------------
The X server will register the bus name org.x.config.displayN, and the The X server will register the bus name org.x.config.displayN, and the
@ -7,6 +7,9 @@ object /org/x/config/N, where N is the display number.
Currently only hotplugging of input devices is supported. Currently only hotplugging of input devices is supported.
org.x.config.input: org.x.config.input:
org.x.config.input.version:
Returns one unsigned int32, which is the API version.
org.x.config.input.add: org.x.config.input.add:
Takes an argument of key/value option pairs in arrays, e.g.: Takes an argument of key/value option pairs in arrays, e.g.:
[ss][ss][ss][ss] [ss][ss][ss][ss]
@ -15,18 +18,18 @@ org.x.config.input:
Option names beginning with _ are not allowed; they are reserved Option names beginning with _ are not allowed; they are reserved
for internal use. for internal use.
Returns one signed int32, which is the device id of the new device. Returns a number of signed int32s. Positive integers are the
If the return value is a negative number, it represents the X device IDs of new devices; negative numbers are X error codes,
Status, as defined in X.h. BadMatch will be returned if the options as defined in X.h. BadMatch will be returned if the options
given do not match any device. BadValue is returned for a malformed given do not match any device. BadValue is returned for a malformed
message. (Example: 8 is new device id 8. -8 is BadMatch.) message. (Example: 8 is new device ID 8; -8 is BadMatch.)
Notably, BadAlloc is never returned: the server internally signals Notably, BadAlloc is never returned: the server internally signals
to D-BUS that the attempt failed for lack of memory. to D-BUS that the attempt failed for lack of memory.
org.x.config.input.remove: org.x.config.input.remove:
Takes one int32 argument, which is the device ID to remove, i.e.: Takes one uint32 argument, which is the device ID to remove, i.e.:
i u
is the signature. is the signature.
Returns one signed int32 which represents an X status as defined in Returns one signed int32 which represents an X status as defined in
@ -34,4 +37,4 @@ org.x.config.input:
org.x.config.input.listDevices: org.x.config.input.listDevices:
Lists the currently active devices. No argument. Lists the currently active devices. No argument.
Return value is sequence of <id> <name> <id> <name> ... Return value is sequence of [<id> <name>] [<id> <name>] ..., i.e. [us].

View File

@ -36,7 +36,7 @@
#include "input.h" #include "input.h"
#include "inputstr.h" #include "inputstr.h"
#define API_VERSION 1 #define API_VERSION 2
#define MATCH_RULE "type='method_call',interface='org.x.config.input'" #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; goto unwind;
} }
if (!dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, /* XXX: If we fail halfway through, we don't seem to have any way to
&dev->id)) { * empty the iterator, so you'll end up with some device IDs,
ErrorF("[config/dbus] couldn't append to iterator\n"); * plus an error. This seems to be a shortcoming in the D-Bus
ret = BadAlloc; * API. */
goto unwind; 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: unwind:
@ -198,7 +204,7 @@ remove_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
} }
dbus_message_iter_init_append(reply, &reply_iter); 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)) { &deviceid, DBUS_TYPE_INVALID)) {
MALFORMED_MESSAGE_ERROR(); MALFORMED_MESSAGE_ERROR();
} }
@ -232,21 +238,45 @@ static int
list_devices(DBusMessage *message, DBusMessage *reply, DBusError *error) list_devices(DBusMessage *message, DBusMessage *reply, DBusError *error)
{ {
DeviceIntPtr dev; DeviceIntPtr dev;
DBusMessageIter iter; DBusMessageIter iter, subiter;
dbus_message_iter_init_append(reply, &iter); dbus_message_iter_init_append(reply, &iter);
for (dev = inputInfo.devices; dev; dev = dev->next) { 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)) { &dev->id)) {
ErrorF("[config/dbus] couldn't append to iterator\n"); ErrorF("[config/dbus] couldn't append to iterator\n");
return BadAlloc; return BadAlloc;
} }
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, if (!dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING,
&dev->name)) { &dev->name)) {
ErrorF("[config/dbus] couldn't append to iterator\n"); ErrorF("[config/dbus] couldn't append to iterator\n");
return BadAlloc; 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; return Success;
@ -282,6 +312,8 @@ message_handler(DBusConnection *connection, DBusMessage *message, void *data)
err = remove_device(message, reply, &error); err = remove_device(message, reply, &error);
else if (strcmp(dbus_message_get_member(message), "listDevices") == 0) else if (strcmp(dbus_message_get_member(message), "listDevices") == 0)
err = list_devices(message, reply, &error); err = list_devices(message, reply, &error);
else if (strcmp(dbus_message_get_member(message), "version") == 0)
err = get_version(message, reply, &error);
else else
goto err_reply; goto err_reply;