From 711bb1151b161f3696d97b78de975221ccee82cd Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 8 Oct 2007 17:01:08 +0100 Subject: [PATCH] open/close device functions --- libfprint/core.c | 34 ++++++++++++++++++++++++++++++++++ libfprint/fp_internal.h | 10 ++++++++++ libfprint/fprint.h | 5 +++++ 3 files changed, 49 insertions(+) diff --git a/libfprint/core.c b/libfprint/core.c index 744424f..a8922c5 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -118,6 +118,40 @@ API_EXPORTED void fp_dscv_devs_free(struct fp_dscv_dev **devs) g_free(devs); } +API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev) +{ + struct fp_dev *dev; + const struct fp_driver *drv = ddev->drv; + int r; + + usb_dev_handle *udevh = usb_open(ddev->udev); + if (!udevh) + return NULL; + + dev = g_malloc0(sizeof(*dev)); + dev->drv = drv; + dev->udev = udevh; + + if (drv->init) { + r = drv->init(dev); + if (r) { + usb_close(udevh); + g_free(dev); + return NULL; + } + } + + return dev; +} + +API_EXPORTED void fp_dev_close(struct fp_dev *dev) +{ + if (dev->drv->exit) + dev->drv->exit(dev); + usb_close(dev->udev); + g_free(dev); +} + API_EXPORTED int fp_init(void) { usb_init(); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 3b6ab05..c4629de 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -28,6 +28,12 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) +struct fp_dev { + const struct fp_driver *drv; + usb_dev_handle *udev; + void *priv; +}; + struct usb_id { uint16_t vendor; uint16_t product; @@ -38,6 +44,10 @@ struct fp_driver { const char *name; const char *full_name; const struct usb_id * const id_table; + + /* Device operations */ + int (*init)(struct fp_dev *dev); + void (*exit)(struct fp_dev *dev); }; extern const struct fp_driver upekts_driver; diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 5be5311..07d35d3 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -22,11 +22,16 @@ /* structs that applications are not allowed to peek into */ struct fp_dscv_dev; +struct fp_dev; /* Device discovery */ struct fp_dscv_dev **fp_discover_devs(void); void fp_dscv_devs_free(struct fp_dscv_dev **devs); +/* Device handling */ +struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev); +void fp_dev_close(struct fp_dev *dev); + int fp_init(void); #endif