static struct leds_data *get_leds_data(struct udev_device *udevice) { struct leds_data *data; int number; number = get_js_number(udevice); DBG("number %d", number); data = malloc0(sizeof(*data)); if (!data) return NULL; data->bitmap = calc_leds_bitmap(number); if (data->bitmap == 0) { leds_data_destroy(data); return NULL; } /* * It's OK if this fails, set_leds_hidraw() will be used in * case data->syspath_prefix is NULL. */ data->syspath_prefix = get_leds_syspath_prefix(udevice); return data; }
static void device_added(struct udev_device *udevice) { struct btd_adapter *adapter; GIOChannel *io; uint16_t bus; int index; int fd; adapter = btd_adapter_get_default(); if (!adapter) return; index = get_supported_device(udevice, &bus); if (index < 0) return; info("sixaxis: compatible device connected: %s (%04X:%04X)", devices[index].name, devices[index].vid, devices[index].pid); fd = open(udev_device_get_devnode(udevice), O_RDWR); if (fd < 0) return; io = g_io_channel_unix_new(fd); switch (bus) { case BUS_USB: if (!setup_device(fd, index, adapter)) break; /* fall through */ case BUS_BLUETOOTH: /* wait for events before setting leds */ g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, setup_leds, GINT_TO_POINTER(get_js_number(udevice))); break; default: DBG("uknown bus type (%u)", bus); break; } g_io_channel_set_close_on_unref(io, TRUE); g_io_channel_unref(io); }