summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorRemigiusz Marcinkiewicz <enleth@enleth.com>2007-04-11 01:09:26 +0300
committerDaniel Stone <daniels@endtroducing.fooishbar.org>2007-04-11 01:09:26 +0300
commit0910540e4322bba72a2fa0a907072eab2547a7b6 (patch)
tree87768f64e5a17451c8aaeba99b68ad90fef334c0 /config
parentaecbc712144dd1aaf462bd758821438b1d22d957 (diff)
Config: Extend D-BUS API
Return device ID where available. Add listDevices call, which does what it says on the box.
Diffstat (limited to 'config')
-rw-r--r--config/config.c86
1 files changed, 71 insertions, 15 deletions
diff --git a/config/config.c b/config/config.c
index aae5c6e4d..9828091f4 100644
--- a/config/config.c
+++ b/config/config.c
@@ -92,12 +92,15 @@ configTeardown(void)
}
static int
-configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error)
+configAddDevice(DBusMessage *message, DBusMessageIter *iter,
+ DBusMessage *reply, DBusMessageIter *r_iter,
+ DBusError *error)
{
DBusMessageIter subiter;
InputOption *tmpo = NULL, *options = NULL;
char *tmp = NULL;
int ret = BadMatch;
+ DeviceIntPtr dev = NULL;
DebugF("[config] adding device\n");
@@ -165,12 +168,28 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error)
dbus_message_iter_next(iter);
}
- ret = NewInputDeviceRequest(options);
- if (ret != Success)
+ ret = NewInputDeviceRequest(options, &dev);
+ if (ret != Success) {
DebugF("[config] NewInputDeviceRequest failed\n");
+ goto unwind;
+ }
+
+ if (!dev) {
+ DebugF("[config] NewInputDeviceRequest succeeded, without device\n");
+ ret = BadMatch;
+ goto unwind;
+ }
+
+ if (!dbus_message_iter_append_basic(r_iter, DBUS_TYPE_INT32, &(dev->id))) {
+ ErrorF("[config] couldn't append to iterator\n");
+ ret = BadAlloc;
+ goto unwind;
+ }
- /* Fall through, must deallocate memory we've allocated */
unwind:
+ if (dev && ret != Success)
+ RemoveDevice(dev);
+
while (options) {
tmpo = options;
options = options->next;
@@ -218,17 +237,47 @@ unwind:
return ret;
}
+static int
+configListDevices(DBusMessage *message, DBusMessageIter *iter,
+ DBusMessage *reply, DBusMessageIter *r_iter,
+ DBusError *error)
+{
+ DeviceIntPtr d;
+ int ret = BadMatch;
+
+ for (d = inputInfo.devices; d; d = d->next) {
+ if (!dbus_message_iter_append_basic(r_iter, DBUS_TYPE_INT32,
+ &(d->id))) {
+ ErrorF("[config] couldn't append to iterator\n");
+ ret = BadAlloc;
+ goto unwind;
+ }
+ if (!dbus_message_iter_append_basic(r_iter, DBUS_TYPE_STRING,
+ &(d->name))) {
+ ErrorF("[config] couldn't append to iterator\n");
+ ret = BadAlloc;
+ goto unwind;
+ }
+ }
+
+unwind:
+ return ret;
+}
+
static DBusHandlerResult
configMessage(DBusConnection *connection, DBusMessage *message, void *closure)
{
DBusMessageIter iter;
DBusError error;
DBusMessage *reply;
+ DBusMessageIter r_iter;
DBusConnection *bus = closure;
int ret = BadDrawable; /* nonsensical value */
dbus_error_init(&error);
+ DebugF("[config] received a message\n");
+
if (strcmp(dbus_message_get_interface(message),
"org.x.config.input") == 0) {
if (!dbus_message_iter_init(message, &iter)) {
@@ -237,26 +286,33 @@ configMessage(DBusConnection *connection, DBusMessage *message, void *closure)
return DBUS_HANDLER_RESULT_NEED_MEMORY; /* ?? */
}
+ if (!(reply = dbus_message_new_method_return(message))) {
+ ErrorF("[config] failed to create the reply message\n");
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+ dbus_message_iter_init_append(reply, &r_iter);
+
if (strcmp(dbus_message_get_member(message), "add") == 0)
- ret = configAddDevice(message, &iter, &error);
+ ret = configAddDevice(message, &iter, reply, &r_iter, &error);
else if (strcmp(dbus_message_get_member(message), "remove") == 0)
ret = configRemoveDevice(message, &iter, &error);
+ else if (strcmp(dbus_message_get_member(message), "listDevices") == 0)
+ ret = configListDevices(message, &iter, reply, &r_iter, &error);
if (ret != BadDrawable && ret != BadAlloc) {
- reply = dbus_message_new_method_return(message);
- dbus_message_iter_init_append(reply, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret)) {
- ErrorF("[config] couldn't append to iterator\n");
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
+ if (!strlen(dbus_message_get_signature(reply)))
+ if (!dbus_message_iter_append_basic(&r_iter, DBUS_TYPE_INT32, &ret)) {
+ ErrorF("[config] couldn't append to iterator\n");
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
if (!dbus_connection_send(bus, reply, NULL))
ErrorF("[config] failed to send reply\n");
- dbus_connection_flush(bus);
-
- dbus_message_unref(reply);
}
+ dbus_message_unref(reply);
+ dbus_connection_flush(bus);
}
dbus_error_free(&error);