kopia lustrzana https://gitlab.com/sane-project/backends
epson2: fixed handling of cancel requests
rodzic
08a27b7b5a
commit
506c1be1a4
|
@ -383,3 +383,10 @@ e2_ack_next(Epson_Scanner * s, size_t reply_len)
|
|||
e2_send(s, S_ACK, 1, reply_len, &status);
|
||||
return status;
|
||||
}
|
||||
|
||||
SANE_Status
|
||||
e2_cancel(Epson_Scanner * s)
|
||||
{
|
||||
DBG(1, "%s\n", __func__);
|
||||
return e2_cmd_simple(s, S_CAN, 1);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ e2_cmd_info_block(SANE_Handle handle, unsigned char *params,
|
|||
|
||||
SANE_Status e2_ack(Epson_Scanner * s);
|
||||
SANE_Status e2_ack_next(Epson_Scanner * s, size_t reply_len);
|
||||
SANE_Status e2_cancel(Epson_Scanner * s);
|
||||
|
||||
SANE_Status
|
||||
e2_esc_cmd(Epson_Scanner * s, unsigned char cmd, unsigned char val);
|
||||
|
|
|
@ -1241,7 +1241,7 @@ e2_setup_block_mode(Epson_Scanner * s)
|
|||
*/
|
||||
|
||||
/* XXX check bith depth? */
|
||||
if (s->lcount > 3 && s->lcount % 2)
|
||||
if (s->hw->cmd->level[0] == 'D' && s->lcount > 3 && s->lcount % 2)
|
||||
s->lcount -= 1;
|
||||
|
||||
DBG(1, "final line count is %d\n", s->lcount);
|
||||
|
@ -1482,6 +1482,10 @@ e2_wait_warm_up(Epson_Scanner * s)
|
|||
s->retry_count = 0;
|
||||
|
||||
while (1) {
|
||||
|
||||
if (s->canceling)
|
||||
return SANE_STATUS_CANCELLED;
|
||||
|
||||
status = e2_check_warm_up(s, &wup);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
return status;
|
||||
|
@ -1601,7 +1605,7 @@ e2_start_ext_scan(Epson_Scanner * s)
|
|||
|
||||
if (s->ext_last_len) {
|
||||
s->ext_blocks++;
|
||||
DBG(1, "adj block count: %d\n", s->ext_blocks);
|
||||
DBG(1, "adjusted block count: %d\n", s->ext_blocks);
|
||||
}
|
||||
|
||||
/* adjust block len if we have only one block to read */
|
||||
|
@ -1685,8 +1689,9 @@ e2_ext_read(struct Epson_Scanner *s)
|
|||
if (s->ext_counter == s->ext_blocks && s->ext_last_len)
|
||||
buf_len = s->ext_last_len;
|
||||
|
||||
DBG(18, "%s: block %d, size %lu\n", __func__, s->ext_counter,
|
||||
(unsigned long) buf_len);
|
||||
DBG(18, "%s: block %d/%d, size %lu\n", __func__,
|
||||
s->ext_counter, s->ext_blocks,
|
||||
(unsigned long) buf_len);
|
||||
|
||||
/* receive image data + error code */
|
||||
read = e2_recv(s, s->buf, buf_len + 1, &status);
|
||||
|
@ -1707,6 +1712,11 @@ e2_ext_read(struct Epson_Scanner *s)
|
|||
if (s->ext_counter == (s->ext_blocks - 1))
|
||||
next_len = s->ext_last_len;
|
||||
|
||||
if (s->canceling) {
|
||||
e2_cancel(s);
|
||||
return SANE_STATUS_CANCELLED;
|
||||
}
|
||||
|
||||
status = e2_ack_next(s, next_len + 1);
|
||||
} else
|
||||
s->eof = SANE_TRUE;
|
||||
|
@ -2024,7 +2034,7 @@ e2_block_read(struct Epson_Scanner *s)
|
|||
s->eof = SANE_TRUE;
|
||||
} else {
|
||||
if (s->canceling) {
|
||||
status = e2_cmd_simple(s, S_CAN, 1);
|
||||
e2_cancel(s);
|
||||
return SANE_STATUS_CANCELLED;
|
||||
} else {
|
||||
status = e2_ack(s);
|
||||
|
|
|
@ -2247,6 +2247,9 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length,
|
|||
SANE_Status status;
|
||||
Epson_Scanner *s = (Epson_Scanner *) handle;
|
||||
|
||||
if (s->buf == NULL || s->canceling)
|
||||
return SANE_STATUS_CANCELLED;
|
||||
|
||||
*length = 0;
|
||||
|
||||
if (s->hw->extended_commands)
|
||||
|
@ -2254,6 +2257,11 @@ sane_read(SANE_Handle handle, SANE_Byte *data, SANE_Int max_length,
|
|||
else
|
||||
status = e2_block_read(s);
|
||||
|
||||
if (status == SANE_STATUS_CANCELLED) {
|
||||
e2_scan_finish(s);
|
||||
return status;
|
||||
}
|
||||
|
||||
DBG(18, "moving data %p %p, %d (%d lines)\n",
|
||||
s->ptr, s->end,
|
||||
max_length, max_length / s->params.bytes_per_line);
|
||||
|
@ -2284,41 +2292,8 @@ void
|
|||
sane_cancel(SANE_Handle handle)
|
||||
{
|
||||
Epson_Scanner *s = (Epson_Scanner *) handle;
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
|
||||
/*
|
||||
* If the s->ptr pointer is not NULL, then a scan operation
|
||||
* was started and if s->eof is FALSE, it was not finished.
|
||||
*/
|
||||
|
||||
if (s->buf) {
|
||||
unsigned char *dummy;
|
||||
int len;
|
||||
|
||||
/* malloc one line */
|
||||
dummy = malloc(s->params.bytes_per_line);
|
||||
if (dummy == NULL) {
|
||||
DBG(1, "Out of memory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* there is still data to read from the scanner */
|
||||
s->canceling = SANE_TRUE;
|
||||
|
||||
/* XXX check this condition, we used to check
|
||||
* for SANE_STATUS_CANCELLED */
|
||||
while (!s->eof &&
|
||||
(status == SANE_STATUS_GOOD
|
||||
|| status == SANE_STATUS_DEVICE_BUSY)) {
|
||||
/* empty body, the while condition does the processing */
|
||||
/* XXX ? */
|
||||
status = sane_read(s, dummy,
|
||||
s->params.bytes_per_line,
|
||||
&len);
|
||||
}
|
||||
|
||||
free(dummy);
|
||||
}
|
||||
s->canceling = SANE_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Ładowanie…
Reference in New Issue