all: Make sure the requested jobid isn't already in use!

This commit is contained in:
Solomon Peachy 2016-01-15 08:24:23 -05:00
parent 23b6773b3a
commit 298d7a5d6d
6 changed files with 93 additions and 15 deletions

View File

@ -231,7 +231,9 @@ static void kodak605_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
/* Make sure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
ctx->jobid = jobid & 0x7f;
if (!ctx->jobid)
ctx->jobid++;
/* Query media info */
if (kodak605_get_media(ctx, ctx->media)) {
@ -366,9 +368,6 @@ static int kodak605_main_loop(void *vctx, int copies) {
return CUPS_BACKEND_HOLD;
}
/* Use specified jobid */
ctx->hdr.jobid = ctx->jobid;
INFO("Waiting for printer idle\n");
while(1) {
@ -377,6 +376,16 @@ static int kodak605_main_loop(void *vctx, int copies) {
// XXX check for errors
/* make sure we're not colliding with an existing
jobid */
while (ctx->jobid == sts.b1_id ||
ctx->jobid == sts.b2_id) {
ctx->jobid++;
ctx->jobid &= 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
/* Wait for a free buffer */
if (sts.b1_sts == BANK_STATUS_FREE ||
sts.b2_sts == BANK_STATUS_FREE) {
@ -386,8 +395,11 @@ static int kodak605_main_loop(void *vctx, int copies) {
sleep(1);
}
/* Use specified jobid */
ctx->hdr.jobid = ctx->jobid;
{
INFO("Sending image header\n");
INFO("Sending image header (internal id %d)\n", ctx->jobid);
if ((ret = send_data(ctx->dev, ctx->endp_down,
(uint8_t*)&ctx->hdr, sizeof(ctx->hdr))))
return CUPS_BACKEND_FAILED;
@ -597,7 +609,7 @@ static int kodak605_cmdline_arg(void *vctx, int argc, char **argv)
/* Exported */
struct dyesub_backend kodak605_backend = {
.name = "Kodak 605",
.version = "0.24",
.version = "0.25",
.uri_prefix = "kodak605",
.cmdline_usage = kodak605_cmdline,
.cmdline_arg = kodak605_cmdline_arg,

View File

@ -961,7 +961,9 @@ static void kodak6800_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
ctx->jobid = jobid & 0x7f;
if (!ctx->jobid)
ctx->jobid++;
/* Query media info */
if (kodak6800_get_mediainfo(ctx, ctx->media)) {
@ -1088,6 +1090,16 @@ static int kodak6800_main_loop(void *vctx, int copies) {
if (status.status == STATUS_IDLE)
break;
/* make sure we're not colliding with an existing
jobid */
while (ctx->jobid == status.b1_jobid ||
ctx->jobid == status.b2_jobid) {
ctx->jobid++;
ctx->jobid &= 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
/* See if we have an open bank */
if (!status.b1_remain ||
!status.b2_remain)
@ -1165,7 +1177,7 @@ static int kodak6800_main_loop(void *vctx, int copies) {
/* Exported */
struct dyesub_backend kodak6800_backend = {
.name = "Kodak 6800/6850",
.version = "0.51",
.version = "0.52",
.uri_prefix = "kodak6800",
.cmdline_usage = kodak6800_cmdline,
.cmdline_arg = kodak6800_cmdline_arg,

View File

@ -498,6 +498,8 @@ static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
struct libusb_device_descriptor desc;
ctx->jobid = jobid;
if (!ctx->jobid)
jobid++;
ctx->dev = dev;
ctx->endp_up = endp_up;
@ -781,6 +783,7 @@ static int mitsu70x_set_sleeptime(struct mitsu70x_ctx *ctx, uint8_t time)
static int mitsu70x_main_loop(void *vctx, int copies) {
struct mitsu70x_ctx *ctx = vctx;
struct mitsu70x_jobstatus jobstatus;
struct mitsu70x_jobs jobs;
struct mitsu70x_hdr *hdr = (struct mitsu70x_hdr*) (ctx->databuf + sizeof(struct mitsu70x_hdr));
int ret;
@ -790,6 +793,10 @@ static int mitsu70x_main_loop(void *vctx, int copies) {
INFO("Waiting for printer idle...\n");
ret = mitsu70x_get_jobs(ctx, &jobs);
if (ret)
return CUPS_BACKEND_FAILED;
top:
/* Query job status for jobid 0 (global) */
ret = mitsu70x_get_jobstatus(ctx, &jobstatus, 0x0000);
@ -847,6 +854,14 @@ top:
}
}
/* Make sure we don't have any jobid collisions */
while (hdr->jobid == be16_to_cpu(jobs.jobid_0) ||
hdr->jobid == be16_to_cpu(jobs.jobid_1)) {
ctx->jobid++;
if (!ctx->jobid)
ctx->jobid++;
}
/* Set jobid */
hdr->jobid = cpu_to_be16(ctx->jobid);
@ -1119,7 +1134,7 @@ static int mitsu70x_cmdline_arg(void *vctx, int argc, char **argv)
/* Exported */
struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70/D707/K60/D80",
.version = "0.36WIP",
.version = "0.37WIP",
.uri_prefix = "mitsu70x",
.cmdline_usage = mitsu70x_cmdline,
.cmdline_arg = mitsu70x_cmdline_arg,

View File

@ -1257,7 +1257,9 @@ static void shinkos1245_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
ctx->jobid = jobid & 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
@ -1437,6 +1439,17 @@ top:
/* If the printer is "busy" check to see if there's any
open memory banks so we can queue the next print */
/* make sure we're not colliding with an existing
jobid */
while (ctx->jobid == status1.counters2.bank1_id ||
ctx->jobid == status1.counters2.bank2_id) {
ctx->jobid++;
ctx->jobid &= 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
if (!status1.counters2.bank1_remain ||
!status1.counters2.bank2_remain) {
state = S_PRINTER_READY_CMD;
@ -1582,7 +1595,7 @@ static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos1245_backend = {
.name = "Shinko/Sinfonia CHC-S1245",
.version = "0.07WIP",
.version = "0.08WIP",
.uri_prefix = "shinkos1245",
.cmdline_usage = shinkos1245_cmdline,
.cmdline_arg = shinkos1245_cmdline_arg,

View File

@ -1391,7 +1391,9 @@ static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
ctx->jobid = (jobid & 0x7f);
if (!ctx->jobid)
ctx->jobid++;
}
static void shinkos2145_teardown(void *vctx) {
@ -1569,6 +1571,17 @@ top:
switch (state) {
case S_IDLE:
INFO("Waiting for printer idle\n");
/* make sure we're not colliding with an existing
jobid */
while (ctx->jobid == sts->bank1_printid ||
ctx->jobid == sts->bank2_printid) {
ctx->jobid++;
ctx->jobid &= 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
/* If either bank is free, continue */
if (sts->bank1_status == BANK_STATUS_FREE ||
sts->bank2_status == BANK_STATUS_FREE)
@ -1689,7 +1702,7 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145",
.version = "0.46",
.version = "0.47",
.uri_prefix = "shinkos2145",
.cmdline_usage = shinkos2145_cmdline,
.cmdline_arg = shinkos2145_cmdline_arg,

View File

@ -1478,7 +1478,9 @@ static void shinkos6245_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
ctx->jobid = jobid & 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
static void shinkos6245_teardown(void *vctx) {
@ -1705,6 +1707,17 @@ top:
switch (state) {
case S_IDLE:
INFO("Waiting for printer idle\n");
/* make sure we're not colliding with an existing
jobid */
while (ctx->jobid == sts->bank1_printid ||
ctx->jobid == sts->bank2_printid) {
ctx->jobid++;
ctx->jobid &= 0x7f;
if (!ctx->jobid)
ctx->jobid++;
}
/* If either bank is free, continue */
if (sts->bank1_status == BANK_STATUS_FREE ||
sts->bank2_status == BANK_STATUS_FREE)
@ -1825,7 +1838,7 @@ static int shinkos6245_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos6245_backend = {
.name = "Shinko/Sinfonia CHC-S6245",
.version = "0.04WIP",
.version = "0.05WIP",
.uri_prefix = "shinkos6245",
.cmdline_usage = shinkos6245_cmdline,
.cmdline_arg = shinkos6245_cmdline_arg,