Skip to content

Commit

Permalink
Merge branch '0.1.4-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mounaiban committed May 9, 2020
2 parents ce90ae2 + f227e7e commit 44c8874
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
46 changes: 21 additions & 25 deletions src/capt-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

static uint8_t capt_iobuf[0x10000];
static size_t capt_iosize;
static uint8_t sendrecv_progress = NO_SENDRECV;
static cups_sc_status_t last_send_status = CUPS_SC_STATUS_NONE;
static bool sendrecv_started = false;

static void capt_debug_buf(const char *level, size_t size)
{
Expand All @@ -57,11 +58,7 @@ static void capt_send_buf(void)
capt_debug_buf("DEBUG", 128);
}

if (sendrecv_progress && SENDRECV_IN_PROGRESS)
sendrecv_progress |= SENDRECV_SEND_STARTED;

while (iosize) {
cups_sc_status_t status;
uint8_t tmpbuf[128];
size_t tmpsize = sizeof(tmpbuf);
size_t sendsize = iosize;
Expand All @@ -73,17 +70,16 @@ static void capt_send_buf(void)
iosize -= sendsize;
fflush(stdout);

status = cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT,
last_send_status = cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT,
(char *) tmpbuf, (int *) &tmpsize, 1.0);
if (sendrecv_progress && SENDRECV_IN_PROGRESS)
sendrecv_progress |= SENDRECV_SEND_DONE;
if (status != CUPS_SC_STATUS_OK) {
if (status == CUPS_SC_STATUS_TIMEOUT) {

if (last_send_status != CUPS_SC_STATUS_OK) {
if (last_send_status == CUPS_SC_STATUS_TIMEOUT) {
/* Overcome race conditions in usb backend */
fprintf(stderr, "DEBUG: CAPT: output already empty, not drained\n");
} else {
fprintf(stderr, "ERROR: CAPT: no reply from backend, err=%i\n",
(int) status);
(int) last_send_status);
exit(1);
}
}
Expand All @@ -99,8 +95,6 @@ static void capt_recv_buf(size_t offset, size_t expected)
}
fprintf(stderr, "DEBUG: CAPT: waiting for %u bytes\n", (unsigned) expected);
size = cupsBackChannelRead((char *) capt_iobuf + offset, expected, 15.0);
if (sendrecv_progress && SENDRECV_IN_PROGRESS)
sendrecv_progress |= SENDRECV_RECV_DONE;
if (size < 0) {
fprintf(stderr, "ERROR: CAPT: no reply from printer\n");
exit(1);
Expand Down Expand Up @@ -153,7 +147,9 @@ void capt_send(uint16_t cmd, const void *buf, size_t size)

void capt_sendrecv(uint16_t cmd, const void *buf, size_t size, void *reply, size_t *reply_size)
{
sendrecv_progress |= SENDRECV_IN_PROGRESS;
sendrecv_started = true;
last_send_status = CUPS_SC_STATUS_NONE;

capt_send(cmd, buf, size);
capt_recv_buf(0, 6);
if (capt_iosize != 6 || WORD(capt_iobuf[0], capt_iobuf[1]) != cmd) {
Expand Down Expand Up @@ -191,7 +187,9 @@ void capt_sendrecv(uint16_t cmd, const void *buf, size_t size, void *reply, size
}
if (reply_size)
*reply_size = capt_iosize;
sendrecv_progress = NO_SENDRECV;

sendrecv_started = false;
last_send_status = CUPS_SC_STATUS_NONE;
}

void capt_multi_begin(uint16_t cmd)
Expand All @@ -216,28 +214,26 @@ void capt_multi_send(void)
void capt_cleanup(void)
{
/* For use with handling job cancellations */
fprintf(stderr, "DEBUG: CAPT: sendrecv interrupted progress code %u\n", sendrecv_progress);
if (sendrecv_progress && SENDRECV_IN_PROGRESS) {
uint8_t chk_send_cleanup = (SENDRECV_IN_PROGRESS | SENDRECV_SEND_STARTED);
uint8_t chk_recv_cleanup = (SENDRECV_IN_PROGRESS | SENDRECV_SEND_STARTED | SENDRECV_SEND_DONE);

if (sendrecv_started) {

if (sendrecv_progress == chk_send_cleanup) {
if (last_send_status != CUPS_SC_STATUS_OK) {
capt_send_buf();
fprintf(stderr, "DEBUG: CAPT: finished interrupted send\n");
}
if (sendrecv_progress == chk_recv_cleanup) {

/* not else because recv cleanup is needed after finishing send */
if (last_send_status == CUPS_SC_STATUS_OK) {
size_t bytes = 0x10000;
size_t bs = 64;
size_t reply_size = WORD(capt_iobuf[2], capt_iobuf[3]);
if (reply_size > 0)
bytes = reply_size;
while(bytes > 0) {
bytes -= bs;
cupsBackChannelRead(NULL, bs, 0.01);
}
fprintf(stderr, "DEBUG: CAPT: finished interrupted recv\n");
}

capt_iosize = 0;
sendrecv_started = false;
}
}

8 changes: 0 additions & 8 deletions src/capt-command.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ enum capt_command {
CAPT_GPIO = 0xE1A2,
};

enum sendrecv_progress {
NO_SENDRECV = 0x00,
SENDRECV_IN_PROGRESS = 0x01,
SENDRECV_SEND_STARTED = 0x02,
SENDRECV_SEND_DONE = 0x04,
SENDRECV_RECV_DONE = 0x08,
};

const char *capt_identify(void);

void capt_send(uint16_t cmd, const void *data, size_t size);
Expand Down
2 changes: 2 additions & 0 deletions src/generic-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ size_t ops_compress_band_hiscoa(struct printer_state_s *state,

void ops_send_band_hiscoa(struct printer_state_s *state, const void *data, size_t size)
{
(void) job_cancel; /* suppress unused static variable warning */

const uint8_t *pdata = (const uint8_t *) data;
while (size) {
size_t send = 0xFF00;
Expand Down
2 changes: 1 addition & 1 deletion src/printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>

bool job_cancel = false;
static bool job_cancel = false;

struct printer_rec {
struct printer_rec *next;
Expand Down
2 changes: 1 addition & 1 deletion src/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum printer_support {
FULLY,
};

bool job_cancel;
static bool job_cancel;

struct page_dims_s;

Expand Down

0 comments on commit 44c8874

Please sign in to comment.