diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-04-12 09:59:15 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-04-12 09:59:15 +0000 |
commit | e3aec1dd412fc0adb0587edf750979e4d18906b0 (patch) | |
tree | 67224966c44b0670b12f934b998cc167c518b94f /input | |
parent | 1f6bcd79a30ce899eec1245956c48876831439eb (diff) |
Keep the device structure local
Diffstat (limited to 'input')
-rw-r--r-- | input/device.c | 48 | ||||
-rw-r--r-- | input/device.h | 26 | ||||
-rw-r--r-- | input/manager.c | 31 |
3 files changed, 61 insertions, 44 deletions
diff --git a/input/device.c b/input/device.c index 5ebeb1ec..a29cc095 100644 --- a/input/device.c +++ b/input/device.c @@ -61,6 +61,29 @@ #define UPDOWN_ENABLED 1 +struct pending_connect { + DBusConnection *conn; + DBusMessage *msg; +}; + +struct fake_input { + GIOChannel *io; + int rfcomm; /* RFCOMM socket */ + int uinput; /* uinput socket */ + uint8_t ch; /* RFCOMM channel number */ +}; + +struct device { + bdaddr_t src; + bdaddr_t dst; + char *name; + uint8_t major; + uint8_t minor; + struct hidp_connadd_req hidp; /* FIXME: Use dynamic alloc? */ + struct fake_input *fake; + struct pending_connect *pending_connect; +}; + static struct device *device_new(bdaddr_t *src, bdaddr_t *dst) { struct device *idev; @@ -1086,6 +1109,13 @@ int fake_input_register(DBusConnection *conn, bdaddr_t *src, int input_device_unregister(DBusConnection *conn, const char *path) { DBusMessage *msg; + struct device *idev; + + if (!dbus_connection_get_object_path_data(conn, + path, (void *) &idev)) + return -1; + + del_stored_device_info(&idev->src, &idev->dst); if (!dbus_connection_unregister_object_path(conn, path)) { error("Input device path unregister failed"); @@ -1105,3 +1135,21 @@ int input_device_unregister(DBusConnection *conn, const char *path) return 0; } + +int input_device_get_bdaddr(DBusConnection *conn, const char *path, + bdaddr_t *src, bdaddr_t *dst) +{ + struct device *idev; + + if (!dbus_connection_get_object_path_data(conn, path, + (void *) &idev)) + return -1; + + if (!idev) + return -1; + + bacpy(src, &idev->src); + bacpy(dst, &idev->dst); + + return 0; +} diff --git a/input/device.h b/input/device.h index 398e3751..b156b985 100644 --- a/input/device.h +++ b/input/device.h @@ -21,31 +21,11 @@ * */ -struct fake_input { - GIOChannel *io; - int rfcomm; /* RFCOMM socket */ - int uinput; /* uinput socket */ - uint8_t ch; /* RFCOMM channel number */ -}; - -struct pending_connect { - DBusConnection *conn; - DBusMessage *msg; -}; - -struct device { - bdaddr_t src; - bdaddr_t dst; - char *name; - uint8_t major; - uint8_t minor; - struct hidp_connadd_req hidp; /* FIXME: Use dynamic alloc? */ - struct fake_input *fake; - struct pending_connect *pending_connect; -}; - int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst, struct hidp_connadd_req *hidp, const char **ppath); int fake_input_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst, uint8_t ch, const char **ppath); int input_device_unregister(DBusConnection *conn, const char *path); + +int input_device_get_bdaddr(DBusConnection *conn, const char *path, + bdaddr_t *src, bdaddr_t *dst); diff --git a/input/manager.c b/input/manager.c index bd75dc5a..f74349df 100644 --- a/input/manager.c +++ b/input/manager.c @@ -115,20 +115,6 @@ static void pending_req_free(struct pending_req *pr) g_free(pr); } -static int path_bdaddr_cmp(const char *path, const bdaddr_t *bdaddr) -{ - struct device *idev; - - if (!dbus_connection_get_object_path_data(connection, path, - (void *) &idev)) - return -1; - - if (!idev) - return -1; - - return bacmp(&idev->dst, bdaddr); -} - static int get_record(struct pending_req *pr, uint32_t handle, DBusPendingCallNotifyFunction cb) { @@ -637,6 +623,16 @@ done: dbus_pending_call_unref(call); } +static int path_bdaddr_cmp(const char *path, const bdaddr_t *bdaddr) +{ + bdaddr_t src, dst; + + if (input_device_get_bdaddr(connection, path, &src, &dst) < 0) + return -1; + + return bacmp(&dst, bdaddr); +} + static DBusHandlerResult create_device(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -710,7 +706,6 @@ static DBusHandlerResult create_device(DBusConnection *conn, static DBusHandlerResult remove_device(DBusConnection *conn, DBusMessage *msg, void *data) { - struct device *idev; DBusMessage *reply; DBusError derr; GSList *l; @@ -736,12 +731,6 @@ static DBusHandlerResult remove_device(DBusConnection *conn, g_free(l->data); device_paths = g_slist_remove(device_paths, l->data); - if (!dbus_connection_get_object_path_data(connection, - path, (void *) &idev)) - return err_does_not_exist(conn, msg, "Input doesn't exist"); - - del_stored_device_info(&idev->src, &idev->dst); - if (input_device_unregister(conn, path) < 0) { dbus_message_unref(reply); return err_failed(conn, msg, "D-Bus path unregistration failed"); |