summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-01-23 22:02:47 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-01-23 22:02:47 +0000
commitbf9a0168854c71faff3e67c42c6265069230f6ce (patch)
tree7be1cdfbbf8dad658ec672f110004890777e441d /input
parent5f80c518582acd9045c952b73bc0f25f97628b37 (diff)
Added HID unplug method
Diffstat (limited to 'input')
-rw-r--r--input/input-service.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/input/input-service.c b/input/input-service.c
index 5a891709..f5568bb4 100644
--- a/input/input-service.c
+++ b/input/input-service.c
@@ -205,15 +205,6 @@ static DBusHandlerResult err_connection_failed(DBusConnection *conn,
str));
}
-static DBusHandlerResult err_not_connected(DBusConnection *conn,
- DBusMessage *msg)
-{
- return send_message_and_unref(conn,
- dbus_message_new_error(msg,
- INPUT_ERROR_INTERFACE".NotConnected",
- "Input device not connected"));
-}
-
static DBusHandlerResult err_already_exists(DBusConnection *conn,
DBusMessage *msg, const char *str)
{
@@ -663,51 +654,66 @@ static DBusHandlerResult device_connect(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult device_disconnect(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static int disconnect(struct input_device *idev, uint32_t flags)
{
- struct input_device *idev = data;
struct hidp_conndel_req req;
- int ctl;
+ int ctl, err;
- if ((idev->hidp.intr_sock < 0) || (idev->hidp.ctrl_sock < 0))
- return err_not_connected(conn, msg);
+ if ((idev->hidp.intr_sock < 0) || (idev->hidp.ctrl_sock < 0)) {
+ errno = ENOTCONN;
+ return -1;
+ }
ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HIDP);
if (ctl < 0) {
error("Can't open HIDP control socket");
- goto fail;
+ return -1;
}
memset(&req, 0, sizeof(struct hidp_conndel_req));
- req.flags = idev->hidp.flags;
str2ba(idev->addr, &req.bdaddr);
+ req.flags = flags;
if (ioctl(ctl, HIDPCONNDEL, &req) < 0) {
+ err = errno;
error("Can't delete the HID device: %s(%d)",
strerror(errno), errno);
- goto fail;
+ close(ctl);
+ errno = err;
+ return -1;
}
close(ctl);
- close(idev->hidp.intr_sock);
idev->hidp.intr_sock = -1;
-
- close(idev->hidp.ctrl_sock);
idev->hidp.ctrl_sock = -1;
+ return 0;
+}
+
+static DBusHandlerResult device_disconnect(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct input_device *idev = data;
+
+ if (disconnect(idev, 0) < 0)
+ return err_failed(conn, msg, strerror(errno));
+
return send_message_and_unref(conn,
dbus_message_new_method_return(msg));
-fail:
- return err_failed(conn, msg, strerror(errno));
}
static DBusHandlerResult device_unplug(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ struct input_device *idev = data;
+
+ if (disconnect(idev, (1 << HIDP_VIRTUAL_CABLE_UNPLUG)) < 0)
+ return err_failed(conn, msg, strerror(errno));
+
+ return send_message_and_unref(conn,
+ dbus_message_new_method_return(msg));
}
static DBusHandlerResult device_is_connected(DBusConnection *conn,