bug 690938 - Get vendor id and product id on Linux for bluetooth gamepads. r=karlt
authorTed Mielczarek <ted@mielczarek.org>
Tue, 09 Apr 2013 08:43:24 -0400
changeset 135211 34296a24149224b669b4dce050f4459677521cc9
parent 135210 73adad5ded336441ca8ad6ade93fe740d127a705
child 135212 dcf67f13c6bb0e498b1045bb1a8da9623dc1ff11
push id3752
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 17:21:10 +0000
treeherdermozilla-aurora@1580544aef0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs690938
milestone23.0a1
bug 690938 - Get vendor id and product id on Linux for bluetooth gamepads. r=karlt
hal/linux/LinuxGamepad.cpp
hal/linux/udev.h
--- a/hal/linux/LinuxGamepad.cpp
+++ b/hal/linux/LinuxGamepad.cpp
@@ -113,16 +113,24 @@ LinuxGamepadService::AddDevice(struct ud
   char name[128];
   if (ioctl(fd, JSIOCGNAME(sizeof(name)), &name) == -1) {
     strcpy(name, "unknown");
   }
   const char* vendor_id =
     mUdev.udev_device_get_property_value(dev, "ID_VENDOR_ID");
   const char* model_id =
     mUdev.udev_device_get_property_value(dev, "ID_MODEL_ID");
+  if (!vendor_id || !model_id) {
+    struct udev_device* parent =
+      mUdev.udev_device_get_parent_with_subsystem_devtype(dev, "input", NULL);
+    if (parent) {
+      vendor_id = mUdev.udev_device_get_sysattr_value(parent, "id/vendor");
+      model_id = mUdev.udev_device_get_sysattr_value(parent, "id/product");
+    }
+  }
   snprintf(gamepad.idstring, sizeof(gamepad.idstring),
            "%s-%s-%s",
            vendor_id ? vendor_id : "unknown",
            model_id ? model_id : "unknown",
            name);
 
   char numAxes = 0, numButtons = 0;
   ioctl(fd, JSIOCGAXES, &numAxes);
--- a/hal/linux/udev.h
+++ b/hal/linux/udev.h
@@ -50,18 +50,20 @@ class udev_lib {
     if (!s) return false; \
   } while (0)
 
     DLSYM(udev_new);
     DLSYM(udev_unref);
     DLSYM(udev_device_unref);
     DLSYM(udev_device_new_from_syspath);
     DLSYM(udev_device_get_devnode);
+    DLSYM(udev_device_get_parent_with_subsystem_devtype);
     DLSYM(udev_device_get_property_value);
     DLSYM(udev_device_get_action);
+    DLSYM(udev_device_get_sysattr_value);
     DLSYM(udev_enumerate_new);
     DLSYM(udev_enumerate_unref);
     DLSYM(udev_enumerate_add_match_subsystem);
     DLSYM(udev_enumerate_scan_devices);
     DLSYM(udev_enumerate_get_list_entry);
     DLSYM(udev_list_entry_get_next);
     DLSYM(udev_list_entry_get_name);
     DLSYM(udev_monitor_new_from_netlink);
@@ -82,19 +84,23 @@ class udev_lib {
   // Function pointers returned from dlsym.
   struct udev* (*udev_new)(void);
   void (*udev_unref)(struct udev*);
 
   void (*udev_device_unref)(struct udev_device*);
   struct udev_device* (*udev_device_new_from_syspath)(struct udev*,
                                                       const char*);
   const char* (*udev_device_get_devnode)(struct udev_device*);
+  struct udev_device* (*udev_device_get_parent_with_subsystem_devtype)
+    (struct udev_device*, const char*, const char*);
   const char* (*udev_device_get_property_value)(struct udev_device*,
                                                 const char*);
   const char* (*udev_device_get_action)(struct udev_device*);
+  const char* (*udev_device_get_sysattr_value)(struct udev_device*,
+                                               const char*);
 
   struct udev_enumerate* (*udev_enumerate_new)(struct udev*);
   void (*udev_enumerate_unref)(struct udev_enumerate*);
   int (*udev_enumerate_add_match_subsystem)(struct udev_enumerate*,
                                             const char*);
   int (*udev_enumerate_scan_devices)(struct udev_enumerate*);
   struct udev_list_entry* (*udev_enumerate_get_list_entry)
     (struct udev_enumerate*);