Commit 161c3ccf authored by Bastien Nocera's avatar Bastien Nocera

lib: Link fp_dev to fp_img_dev and back

So it's easy to switch between the 2 structs, and remove fp_img_dev->dev
direct access, as well as fp_dev->priv "user data" usage.
parent 170da7fe
......@@ -622,7 +622,7 @@ static struct fp_img_dev *dev_to_img_dev(struct fp_dev *dev)
{
if (dev->drv->type != DRIVER_IMAGING)
return NULL;
return dev->priv;
return dev->img_dev;
}
/**
......
......@@ -68,6 +68,9 @@ struct fp_dev {
uint32_t devtype;
void *priv;
/* only valid if drv->type == DRIVER_IMAGING */
struct fp_img_dev *img_dev;
int nr_enroll_stages;
/* read-only to drivers */
......@@ -136,8 +139,9 @@ enum fp_imgdev_verify_state {
};
struct fp_img_dev {
struct fp_dev *dev;
libusb_device_handle *udev;
struct fp_dev *parent;
enum fp_imgdev_action action;
int action_state;
......
......@@ -19,3 +19,34 @@
#include "fp_internal.h"
#include <glib.h>
/**
* FP_DEV:
* @dev: a struct #fp_img_dev
*
* Returns the struct #fp_dev associated with @dev, or %NULL on failure.
*/
struct fp_dev *
FP_DEV(struct fp_img_dev *dev)
{
struct fp_img_dev *imgdev;
g_return_val_if_fail (dev, NULL);
imgdev = (struct fp_img_dev *) dev;
return imgdev->parent;
}
/**
* FP_IMG_DEV:
* @dev: a struct #fp_dev representing an imaging device.
*
* Returns: a struct #fp_img_dev or %NULL on failure.
*/
struct fp_img_dev *
FP_IMG_DEV(struct fp_dev *dev)
{
g_return_val_if_fail (dev, NULL);
g_return_val_if_fail (dev->drv, NULL);
g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL);
return dev->img_dev;
}
......@@ -26,3 +26,6 @@ struct fp_dev;
* appropriate functions.
*/
struct fp_img_dev;
struct fp_dev *FP_DEV (struct fp_img_dev *dev);
struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev);
......@@ -58,7 +58,7 @@ struct fp_img *fpi_img_new(size_t length)
struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev)
{
struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv);
struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(FP_DEV(imgdev)->drv);
int width = imgdrv->img_width;
int height = imgdrv->img_height;
struct fp_img *img = fpi_img_new(width * height);
......@@ -349,7 +349,7 @@ int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img,
/* FIXME: space is wasted if we dont hit the max minutiae count. would
* be good to make this dynamic. */
print = fpi_print_data_new(imgdev->dev);
print = fpi_print_data_new(FP_DEV(imgdev));
item = fpi_print_data_item_new(sizeof(struct xyt_struct));
print->type = PRINT_DATA_NBIS_MINUTIAE;
minutiae_to_xyt(img->minutiae, img->width, img->height, item->data);
......@@ -555,7 +555,7 @@ fpi_imgdev_get_user_data(struct fp_img_dev *imgdev)
struct fp_dev *
fpi_imgdev_get_dev(struct fp_img_dev *imgdev)
{
return imgdev->dev;
return FP_DEV(imgdev);
}
enum fp_imgdev_enroll_state
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment