xserver: Branch 'master' - 2 commits

Daniel Stone daniels at kemper.freedesktop.org
Wed Apr 11 01:09:24 EEST 2007


 Xi/stubs.c                     |    2 
 config/config.c                |   86 +++++++++++++++++++++++++++++++++--------
 hw/kdrive/src/kinput.c         |    8 +++
 hw/xfree86/common/xf86Xinput.c |    3 -
 include/input.h                |    3 -
 5 files changed, 83 insertions(+), 19 deletions(-)

New commits:
diff-tree 0910540e4322bba72a2fa0a907072eab2547a7b6 (from aecbc712144dd1aaf462bd758821438b1d22d957)
Author: Remigiusz Marcinkiewicz <enleth at enleth.com>
Date:   Wed Apr 11 01:09:26 2007 +0300

    Config: Extend D-BUS API
    
    Return device ID where available.
    Add listDevices call, which does what it says on the box.

diff --git a/config/config.c b/config/config.c
index aae5c6e..9828091 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, DB
         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
             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);
diff-tree aecbc712144dd1aaf462bd758821438b1d22d957 (from 4f05f9591e5492c72f3856bd7a2ff13378f59f2b)
Author: Remigiusz Marcinkiewicz <enleth at enleth.com>
Date:   Wed Apr 11 00:38:16 2007 +0300

    Input: Allow a pointer to a device to be returned in NIDR
    
    Allow a pointer to the first device added to be returned, so we know which
    device(s) were added by the NIDR call.

diff --git a/Xi/stubs.c b/Xi/stubs.c
index d425fe9..40cd02f 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -226,7 +226,7 @@ ChangeDeviceControl(ClientPtr client, De
  *
  */
 int
-NewInputDeviceRequest(InputOption *options)
+NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
 {
     return BadValue;
 }
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index a9a743b..7edcc51 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -2307,7 +2307,7 @@ ChangeDeviceControl(register ClientPtr c
 }
 
 int
-NewInputDeviceRequest(InputOption *options)
+NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
 {
     InputOption *option = NULL;
     KdPointerInfo *pi = NULL;
@@ -2372,6 +2372,12 @@ NewInputDeviceRequest(InputOption *optio
         }
     }
 
+    if (pi) {
+        *pdev = pi->dixdev;
+    } else if(ki) {
+        *pdev = ki->dixdev;
+    }
+
     return Success;
 }
 
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index f662c17..6ebb087 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -315,7 +315,7 @@ AddOtherInputDevices()
 #endif
 
 int
-NewInputDeviceRequest (InputOption *options)
+NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
 {
     IDevRec *idev = NULL;
     InputDriverPtr drv = NULL;
@@ -409,6 +409,7 @@ NewInputDeviceRequest (InputOption *opti
     if (dev->inited && dev->startup)
         EnableDevice(dev);
 
+    *pdev = dev;
     return Success;
 
 unwind:
diff --git a/include/input.h b/include/input.h
index 1e65709..b399d3a 100644
--- a/include/input.h
+++ b/include/input.h
@@ -445,7 +445,8 @@ extern DeviceIntPtr LookupDeviceIntRec(
 
 /* Implemented by the DDX. */
 extern int NewInputDeviceRequest(
-    InputOption *options);
+    InputOption *options,
+    DeviceIntPtr *dev);
 extern void DeleteInputDeviceRequest(
     DeviceIntPtr dev);
 



More information about the xorg-commit mailing list