all: split apart backend init into separate init/attach calls.

Also fixed every backend, 'dev' wasn't being set properly.
This commit is contained in:
Solomon Peachy 2013-07-19 09:23:53 -04:00
parent 6da476edab
commit 660cd2f3b0
7 changed files with 76 additions and 29 deletions

View File

@ -27,7 +27,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.11"
#define BACKEND_VERSION "0.12"
#ifndef URI_PREFIX
#define URI_PREFIX "gutenprint+usb"
#endif
@ -464,6 +464,9 @@ int main (int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, sigterm_handler);
/* Initialize backend */
backend_ctx = backend->init();
/* Libusb setup */
libusb_init(&ctx);
found = find_and_enumerate(ctx, &list, use_serno, printer_type, -1, 0);
@ -514,8 +517,8 @@ int main (int argc, char **argv)
}
}
/* Initialize backend */
backend_ctx = backend->init(dev, endp_up, endp_down, jobid);
/* Attach backend to device */
backend->attach(backend_ctx, dev, endp_up, endp_down, jobid);
if (query_only) {
backend->cmdline_arg(backend_ctx, 1, argv[1], argv[2]);

View File

@ -107,8 +107,9 @@ struct dyesub_backend {
char *version;
char *uri_prefix;
void (*cmdline_usage)(char *caller);
void *(*init)(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid);
void *(*init)(void);
void (*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 run, char *arg1, char *arg2);
int (*read_parse)(void *ctx, int data_fd);

View File

@ -254,19 +254,27 @@ int kodak1400_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
return -1;
}
static void *kodak1400_init(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
static void *kodak1400_init(void)
{
struct kodak1400_ctx *ctx = malloc(sizeof(struct kodak1400_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct kodak1400_ctx));
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
return ctx;
}
static void 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;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
}
static void kodak1400_teardown(void *vctx) {
struct kodak1400_ctx *ctx = vctx;
@ -552,6 +560,7 @@ struct dyesub_backend kodak1400_backend = {
.cmdline_usage = kodak1400_cmdline,
.cmdline_arg = kodak1400_cmdline_arg,
.init = kodak1400_init,
.attach = kodak1400_attach,
.teardown = kodak1400_teardown,
.read_parse = kodak1400_read_parse,
.main_loop = kodak1400_main_loop,

View File

@ -291,19 +291,27 @@ int kodak6800_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
}
static void *kodak6800_init(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
static void *kodak6800_init(void)
{
struct kodak6800_ctx *ctx = malloc(sizeof(struct kodak6800_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct kodak6800_ctx));
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
return ctx;
}
static void 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;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
}
static void kodak6800_teardown(void *vctx) {
struct kodak6800_ctx *ctx = vctx;
@ -526,6 +534,7 @@ struct dyesub_backend kodak6800_backend = {
.cmdline_usage = kodak6800_cmdline,
.cmdline_arg = kodak6800_cmdline_arg,
.init = kodak6800_init,
.attach = kodak6800_attach,
.teardown = kodak6800_teardown,
.read_parse = kodak6800_read_parse,
.main_loop = kodak6800_main_loop,

View File

@ -335,16 +335,12 @@ struct canonselphy_ctx {
uint8_t *footer;
};
static void *canonselphy_init(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
static void *canonselphy_init(void)
{
struct canonselphy_ctx *ctx = malloc(sizeof(struct canonselphy_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct canonselphy_ctx));
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
/* Static initialization */
setup_paper_codes();
@ -352,6 +348,16 @@ static void *canonselphy_init(struct libusb_device_handle *dev,
return ctx;
}
static void 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;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
}
static void canonselphy_teardown(void *vctx) {
struct canonselphy_ctx *ctx = vctx;
@ -610,6 +616,7 @@ struct dyesub_backend canonselphy_backend = {
.version = "0.58",
.uri_prefix = "canonselphy",
.init = canonselphy_init,
.attach = canonselphy_attach,
.teardown = canonselphy_teardown,
.read_parse = canonselphy_read_parse,
.main_loop = canonselphy_main_loop,

View File

@ -1119,29 +1119,40 @@ int shinkos2145_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
return -1;
}
static void *shinkos2145_init(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
static void *shinkos2145_init(void)
{
struct shinkos2145_ctx *ctx = malloc(sizeof(struct shinkos2145_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct shinkos2145_ctx));
return ctx;
}
static void 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;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7f) + 1;
return ctx;
}
static void shinkos2145_teardown(void *vctx) {
struct shinkos2145_ctx *ctx = vctx;
if (!ctx)
return;
if (ctx->databuf)
free(ctx->databuf);
free(ctx);
}
@ -1363,6 +1374,7 @@ struct dyesub_backend shinkos2145_backend = {
.cmdline_usage = shinkos2145_cmdline,
.cmdline_arg = shinkos2145_cmdline_arg,
.init = shinkos2145_init,
.attach = shinkos2145_attach,
.teardown = shinkos2145_teardown,
.read_parse = shinkos2145_read_parse,
.main_loop = shinkos2145_main_loop,

View File

@ -47,17 +47,23 @@ struct updr150_ctx {
int datalen;
};
static void* updr150_init(struct libusb_device_handle *dev,
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
static void* updr150_init(void)
{
struct updr150_ctx *ctx = malloc(sizeof(struct updr150_ctx));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct updr150_ctx));
return ctx;
}
static void 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;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
return ctx;
}
static void updr150_teardown(void *vctx) {
@ -159,8 +165,8 @@ struct dyesub_backend updr150_backend = {
.name = "Sony UP-DR150",
.version = "0.05",
.uri_prefix = "sonyupdr150",
// .cmdline_usage = updr150_cmdline,
.init = updr150_init,
.attach = updr150_attach,
.teardown = updr150_teardown,
.read_parse = updr150_read_parse,
.main_loop = updr150_main_loop,