vfs5011: add proper dev_deactivate() support

Driver is not able to cancel imaging process without this change
This commit is contained in:
Vasily Khoruzhick 2015-09-29 17:10:42 -07:00
parent 67d29f7936
commit ffef6c2bcc

View file

@ -347,6 +347,7 @@ struct vfs5011_data {
gboolean loop_running; gboolean loop_running;
gboolean deactivating; gboolean deactivating;
struct usbexchange_data init_sequence; struct usbexchange_data init_sequence;
struct libusb_transfer *flying_transfer;
}; };
enum { enum {
@ -468,10 +469,15 @@ static void chunk_capture_callback(struct libusb_transfer *transfer)
else else
fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_READ_DATA); fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_READ_DATA);
} else { } else {
fp_err("Failed to capture data"); if (!data->deactivating) {
fpi_ssm_mark_aborted(ssm, -1); fp_err("Failed to capture data");
fpi_ssm_mark_aborted(ssm, -1);
} else {
fpi_ssm_mark_completed(ssm);
}
} }
libusb_free_transfer(transfer); libusb_free_transfer(transfer);
data->flying_transfer = NULL;
} }
static int capture_chunk_async(struct vfs5011_data *data, static int capture_chunk_async(struct vfs5011_data *data,
@ -486,12 +492,12 @@ static int capture_chunk_async(struct vfs5011_data *data,
STOP_CHECK_LINES = 50 STOP_CHECK_LINES = 50
}; };
struct libusb_transfer *transfer = libusb_alloc_transfer(0); data->flying_transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, handle, VFS5011_IN_ENDPOINT_DATA, libusb_fill_bulk_transfer(data->flying_transfer, handle, VFS5011_IN_ENDPOINT_DATA,
data->capture_buffer, data->capture_buffer,
nline * VFS5011_LINE_SIZE, nline * VFS5011_LINE_SIZE,
chunk_capture_callback, ssm, timeout); chunk_capture_callback, ssm, timeout);
return libusb_submit_transfer(transfer); return libusb_submit_transfer(data->flying_transfer);
} }
static void async_sleep_cb(void *data) static void async_sleep_cb(void *data)
@ -700,6 +706,12 @@ static void activate_loop(struct fpi_ssm *ssm)
fp_dbg("main_loop: state %d", ssm->cur_state); fp_dbg("main_loop: state %d", ssm->cur_state);
if (data->deactivating) {
fp_dbg("deactivating, marking completed");
fpi_ssm_mark_completed(ssm);
return;
}
switch (ssm->cur_state) { switch (ssm->cur_state) {
case DEV_ACTIVATE_REQUEST_FPRINT: case DEV_ACTIVATE_REQUEST_FPRINT:
data->init_sequence.stepcount = data->init_sequence.stepcount =
@ -723,17 +735,12 @@ static void activate_loop(struct fpi_ssm *ssm)
break; break;
case DEV_ACTIVATE_READ_DATA: case DEV_ACTIVATE_READ_DATA:
if (data->deactivating) { r = capture_chunk_async(data, dev->udev, CAPTURE_LINES,
fp_dbg("deactivating, marking completed"); READ_TIMEOUT, ssm);
fpi_ssm_mark_completed(ssm); if (r != 0) {
} else { fp_err("Failed to capture data");
r = capture_chunk_async(data, dev->udev, CAPTURE_LINES, fpi_imgdev_session_error(dev, r);
READ_TIMEOUT, ssm); fpi_ssm_mark_aborted(ssm, r);
if (r != 0) {
fp_err("Failed to capture data");
fpi_imgdev_session_error(dev, r);
fpi_ssm_mark_aborted(ssm, r);
}
} }
break; break;
@ -773,8 +780,11 @@ static void activate_loop_complete(struct fpi_ssm *ssm)
if (data->init_sequence.receive_buf != NULL) if (data->init_sequence.receive_buf != NULL)
g_free(data->init_sequence.receive_buf); g_free(data->init_sequence.receive_buf);
data->init_sequence.receive_buf = NULL; data->init_sequence.receive_buf = NULL;
submit_image(ssm, data); /* We don't want to submit image if we're in deactivating process */
fpi_imgdev_report_finger_status(dev, FALSE); if (!data->deactivating) {
submit_image(ssm, data);
fpi_imgdev_report_finger_status(dev, FALSE);
}
fpi_ssm_free(ssm); fpi_ssm_free(ssm);
data->loop_running = FALSE; data->loop_running = FALSE;
@ -891,10 +901,16 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state)
static void dev_deactivate(struct fp_img_dev *dev) static void dev_deactivate(struct fp_img_dev *dev)
{ {
int r;
struct vfs5011_data *data = dev->priv; struct vfs5011_data *data = dev->priv;
if (data->loop_running) if (data->loop_running) {
data->deactivating = TRUE; data->deactivating = TRUE;
else if (data->flying_transfer) {
r = libusb_cancel_transfer(data->flying_transfer);
if (r < 0)
fp_dbg("cancel failed error %d", r);
}
} else
fpi_imgdev_deactivate_complete(dev); fpi_imgdev_deactivate_complete(dev);
} }