int input_device_register(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); const char *path = device_get_path(device); struct input_device *idev; DBG("%s", path); idev = input_device_new(service); if (!idev) return -EINVAL; if (uhid_enabled) { idev->uhid = bt_uhid_new_default(); if (!idev->uhid) { error("bt_uhid_new_default: failed"); input_device_free(idev); return -EIO; } } if (g_dbus_register_interface(btd_get_dbus_connection(), idev->path, INPUT_INTERFACE, NULL, NULL, input_properties, idev, NULL) == FALSE) { error("Unable to register %s interface", INPUT_INTERFACE); input_device_free(idev); return -EINVAL; } btd_service_set_user_data(service, idev); return 0; }
static struct input_device *input_device_new(DBusConnection *conn, struct btd_device *device, const char *path, const bdaddr_t *src, const bdaddr_t *dst, const uint32_t handle) { struct input_device *idev; char name[249], src_addr[18], dst_addr[18]; idev = g_new0(struct input_device, 1); bacpy(&idev->src, src); bacpy(&idev->dst, dst); idev->device = btd_device_ref(device); idev->path = g_strdup(path); idev->conn = dbus_connection_ref(conn); idev->handle = handle; ba2str(src, src_addr); ba2str(dst, dst_addr); if (read_device_name(src_addr, dst_addr, name) == 0) idev->name = g_strdup(name); if (g_dbus_register_interface(conn, idev->path, INPUT_DEVICE_INTERFACE, device_methods, device_signals, NULL, idev, device_unregister) == FALSE) { error("Failed to register interface %s on path %s", INPUT_DEVICE_INTERFACE, path); input_device_free(idev); return NULL; } DBG("Registered interface %s on path %s", INPUT_DEVICE_INTERFACE, idev->path); return idev; }
static void device_unregister(void *data) { struct input_device *idev = data; DBG("Unregistered interface %s on path %s", INPUT_DEVICE_INTERFACE, idev->path); devices = g_slist_remove(devices, idev); input_device_free(idev); }
void input_device_unregister(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); const char *path = device_get_path(device); struct input_device *idev = btd_service_get_user_data(service); DBG("%s", path); g_dbus_unregister_interface(btd_get_dbus_connection(), idev->path, INPUT_INTERFACE); input_device_free(idev); }