common: Change backend->attach API to allow status returns

This commit is contained in:
Solomon Peachy 2018-04-27 15:07:43 -04:00
parent 1e6604d05a
commit 06dbf0fa91
17 changed files with 81 additions and 35 deletions

View File

@ -642,7 +642,7 @@ static void *canonselphy_init(void)
extern struct dyesub_backend canonselphy_backend;
static void canonselphy_attach(void *vctx, struct libusb_device_handle *dev,
static int canonselphy_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct canonselphy_ctx *ctx = vctx;
@ -672,7 +672,11 @@ static void canonselphy_attach(void *vctx, struct libusb_device_handle *dev,
}
if (!ctx->printer) {
ERROR("Error looking up printer type!\n");
return CUPS_BACKEND_FAILED;
}
/* TODO: Query & Update Marker */
return CUPS_BACKEND_OK;
}
static void canonselphy_teardown(void *vctx) {

View File

@ -189,7 +189,7 @@ static void *selphyneo_init(void)
extern struct dyesub_backend selphyneo_backend;
static void selphyneo_attach(void *vctx, struct libusb_device_handle *dev,
static int selphyneo_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct selphyneo_ctx *ctx = vctx;
@ -204,6 +204,10 @@ static void selphyneo_attach(void *vctx, struct libusb_device_handle *dev,
device = libusb_get_device(dev);
libusb_get_device_descriptor(device, &desc);
// TODO: Query & Update Marker
return CUPS_BACKEND_OK;
}
static void selphyneo_teardown(void *vctx) {

View File

@ -29,7 +29,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.80"
#define BACKEND_VERSION "0.81"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif

View File

@ -156,7 +156,7 @@ struct dyesub_backend {
const char **uri_prefixes;
void (*cmdline_usage)(void); /* Optional */
void *(*init)(void);
void (*attach)(void *ctx, struct libusb_device_handle *dev,
int (*attach)(void *ctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid);
void (*teardown)(void *ctx);
int (*cmdline_arg)(void *ctx, int argc, char **argv);

View File

@ -548,7 +548,7 @@ static void *dnpds40_init(void)
((ctx->ver_major > (__major)) || \
(ctx->ver_major == (__major) && ctx->ver_minor >= (__minor)))
static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct dnpds40_ctx *ctx = vctx;
@ -629,7 +629,7 @@ static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
libusb_get_string_descriptor_ascii(dev, desc->iManufacturer, (unsigned char*)buf, STR_LEN_MAX);
sanitize_string(buf);
if (strncmp(buf, "Dai", 3))
return 0;
return CUPS_BACKEND_FAILED;
}
#endif
#ifdef CITIZEN_ONLY /* Only allow CITIZEN printers to work. */
@ -639,7 +639,7 @@ static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
libusb_get_string_descriptor_ascii(dev, desc->iManufacturer, (unsigned char*)buf, STR_LEN_MAX);
sanitize_string(buf);
if (strncmp(buf, "CIT", 3))
return 0;
return CUPS_BACKEND_FAILED;
}
#endif
@ -779,7 +779,7 @@ static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
break;
default:
ERROR("Unknown vid/pid %04x/%04x (%d)\n", desc.idVendor, desc.idProduct, ctx->type);
return;
return CUPS_BACKEND_FAILED;
}
ctx->last_matte = -1;
@ -923,6 +923,10 @@ static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
break;
}
}
// TODO: fail out on other errors
// TODO: Update Marker
return CUPS_BACKEND_OK;
}
static void dnpds40_teardown(void *vctx) {

View File

@ -294,7 +294,7 @@ static void *kodak1400_init(void)
return ctx;
}
static void kodak1400_attach(void *vctx, struct libusb_device_handle *dev,
static int kodak1400_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct kodak1400_ctx *ctx = vctx;
@ -312,6 +312,8 @@ static void kodak1400_attach(void *vctx, struct libusb_device_handle *dev,
ctx->type = lookup_printer_type(&kodak1400_backend,
desc.idVendor, desc.idProduct);
return CUPS_BACKEND_OK;
}
static void kodak1400_teardown(void *vctx) {

View File

@ -234,7 +234,7 @@ static void *kodak605_init(void)
return ctx;
}
static void kodak605_attach(void *vctx, struct libusb_device_handle *dev,
static int kodak605_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct kodak605_ctx *ctx = vctx;
@ -262,7 +262,11 @@ static void kodak605_attach(void *vctx, struct libusb_device_handle *dev,
/* Query media info */
if (kodak605_get_media(ctx, ctx->media)) {
ERROR("Can't query media\n");
return CUPS_BACKEND_FAILED;
}
// TODO: Update Marker
return CUPS_BACKEND_OK;
}
static void kodak605_teardown(void *vctx) {

View File

@ -1012,7 +1012,7 @@ static void *kodak6800_init(void)
return ctx;
}
static void kodak6800_attach(void *vctx, struct libusb_device_handle *dev,
static int kodak6800_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct kodak6800_ctx *ctx = vctx;
@ -1040,7 +1040,11 @@ static void kodak6800_attach(void *vctx, struct libusb_device_handle *dev,
/* Query media info */
if (kodak6800_get_mediainfo(ctx, ctx->media)) {
ERROR("Can't query media\n");
return CUPS_BACKEND_FAILED;
}
// TODO: Update Marker
return CUPS_BACKEND_OK;
}
static void kodak6800_teardown(void *vctx) {

View File

@ -451,7 +451,7 @@ static void* magicard_init(void)
return ctx;
}
static void magicard_attach(void *vctx, struct libusb_device_handle *dev,
static int magicard_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct magicard_ctx *ctx = vctx;
@ -470,6 +470,7 @@ static void magicard_attach(void *vctx, struct libusb_device_handle *dev,
ctx->type = lookup_printer_type(&magicard_backend,
desc.idVendor, desc.idProduct);
return CUPS_BACKEND_OK;
}
static void magicard_teardown(void *vctx) {

View File

@ -688,7 +688,7 @@ static void *mitsu70x_init(void)
return ctx;
}
static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct mitsu70x_ctx *ctx = vctx;
@ -723,13 +723,13 @@ static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
ERROR("Problem resolving API Version symbol in imaging processing library, too old or not installed?\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return;
return CUPS_BACKEND_FAILED;
}
if (ctx->GetAPIVersion() != REQUIRED_LIB_APIVERSION) {
ERROR("Image processing library API version mismatch!\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return;
return CUPS_BACKEND_FAILED;
}
ctx->Get3DColorTable = DL_SYM(ctx->dl_handle, "CColorConv3D_Get3DColorTable");
@ -750,6 +750,7 @@ static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
ERROR("Problem resolving symbols in imaging processing library\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return CUPS_BACKEND_FAILED;
} else {
DEBUG("Image processing library successfully loaded\n");
}
@ -777,7 +778,7 @@ static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
ret = mitsu70x_get_printerstatus(ctx, &resp);
if (ret) {
ERROR("Unable to get printer status! (%d)\n", ret);
return;
return CUPS_BACKEND_FAILED;
}
if (ctx->type == P_MITSU_D70X &&
@ -786,6 +787,9 @@ static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
ctx->num_decks = 2;
else
ctx->num_decks = 1;
// TODO: Update Marker
return CUPS_BACKEND_OK;
}
static void mitsu70x_teardown(void *vctx) {

View File

@ -540,7 +540,7 @@ static void *mitsu9550_init(void)
return ctx;
}
static void mitsu9550_attach(void *vctx, struct libusb_device_handle *dev,
static int mitsu9550_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct mitsu9550_ctx *ctx = vctx;
@ -569,6 +569,9 @@ static void mitsu9550_attach(void *vctx, struct libusb_device_handle *dev,
ctx->is_98xx = 1;
ctx->last_donor = ctx->last_remain = 65535;
// TODO: Query & Update Marker
return CUPS_BACKEND_OK;
}
static void mitsu9550_teardown(void *vctx) {

View File

@ -89,7 +89,7 @@ static void *mitsup95d_init(void)
return ctx;
}
static void mitsup95d_attach(void *vctx, struct libusb_device_handle *dev,
static int mitsup95d_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct mitsup95d_ctx *ctx = vctx;
@ -107,6 +107,8 @@ static void mitsup95d_attach(void *vctx, struct libusb_device_handle *dev,
ctx->type = lookup_printer_type(&mitsup95d_backend,
desc.idVendor, desc.idProduct);
return CUPS_BACKEND_OK;
}
static void mitsup95d_teardown(void *vctx) {

View File

@ -1274,7 +1274,7 @@ static void *shinkos1245_init(void)
return ctx;
}
static void shinkos1245_attach(void *vctx, struct libusb_device_handle *dev,
static int shinkos1245_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct shinkos1245_ctx *ctx = vctx;
@ -1295,6 +1295,9 @@ static void shinkos1245_attach(void *vctx, struct libusb_device_handle *dev,
ctx->jobid = jobid & 0x7f;
if (!ctx->jobid)
ctx->jobid++;
/* TODO: Query & Update Marker */
return CUPS_BACKEND_OK;
}

View File

@ -1401,7 +1401,7 @@ static void *shinkos2145_init(void)
return ctx;
}
static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
static int shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct shinkos2145_ctx *ctx = vctx;
@ -1417,6 +1417,9 @@ static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
/* Initialize donor */
ctx->last_donor = ctx->last_remain = ctx->media_prints = 65535;
// TODO: Query & Update Marker
return CUPS_BACKEND_OK;
}
static void shinkos2145_teardown(void *vctx) {

View File

@ -1911,7 +1911,7 @@ static void *shinkos6145_init(void)
return ctx;
}
static void shinkos6145_attach(void *vctx, struct libusb_device_handle *dev,
static int shinkos6145_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct shinkos6145_ctx *ctx = vctx;
@ -1956,6 +1956,9 @@ static void shinkos6145_attach(void *vctx, struct libusb_device_handle *dev,
/* Initialize donor */
ctx->last_donor = ctx->last_remain = 65535;
// TODO: Query & Update Marker
return CUPS_BACKEND_OK;
}
static void shinkos6145_teardown(void *vctx) {

View File

@ -1493,7 +1493,7 @@ static void *shinkos6245_init(void)
return ctx;
}
static void shinkos6245_attach(void *vctx, struct libusb_device_handle *dev,
static int shinkos6245_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct shinkos6245_ctx *ctx = vctx;
@ -1517,6 +1517,9 @@ static void shinkos6245_attach(void *vctx, struct libusb_device_handle *dev,
/* Initialize donor */
ctx->last_donor = ctx->last_remain = 65535;
// TODO: Query & Update Marker
return CUPS_BACKEND_OK;
}
static void shinkos6245_teardown(void *vctx) {

View File

@ -71,7 +71,7 @@ static void* updr150_init(void)
return ctx;
}
static void updr150_attach(void *vctx, struct libusb_device_handle *dev,
static int updr150_attach(void *vctx, struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
{
struct updr150_ctx *ctx = vctx;
@ -91,6 +91,8 @@ static void updr150_attach(void *vctx, struct libusb_device_handle *dev,
desc.idVendor, desc.idProduct);
ctx->copies_offset = 0;
return CUPS_BACKEND_OK;
}
static void updr150_teardown(void *vctx) {