fpi-dev.c 3.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * fp_dev types manipulation
 * Copyright (C) 2018 Bastien Nocera <hadess@hadess.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "fp_internal.h"
#include <glib.h>
22

23 24
/**
 * SECTION:fpi-dev
25
 * @title: Device operations
26
 * @short_description: Device operation functions
27 28 29 30 31 32
 *
 * Those macros and functions will help get access to and from struct #fp_dev,
 * and struct #fp_img_dev types, as well as get and set the instance struct
 * data, eg. the structure containing the data specific to each driver.
 */

33 34 35 36 37
/**
 * FP_DEV:
 * @dev: a struct #fp_img_dev
 *
 * Returns the struct #fp_dev associated with @dev, or %NULL on failure.
38 39
 *
 * Returns: a struct #fp_dev or %NULL
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 */
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.
 *
55 56 57
 * Returns a struct #fp_img_dev associated with @dev, or %NULL on failure.
 *
 * Returns: a struct #fp_img_dev or %NULL
58 59 60 61 62 63
 */
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);
64
	g_return_val_if_fail (dev->drv->type == DRIVER_IMAGING, NULL);
65 66
	return dev->img_dev;
}
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

/**
 * fp_dev_set_instance_data:
 * @dev: a struct #fp_dev
 * @instance_data: a pointer to the instance data
 *
 * Set the instance data for a struct #fp_dev. This is usually a structure
 * private to the driver used to keep state and pass it as user_data to
 * asynchronous functions.
 *
 * The core does not do any memory management for this data, so the driver
 * itself will have to create and free its own structure when appropriate.
 */
void
fp_dev_set_instance_data (struct fp_dev *dev,
			  void          *instance_data)
{
	g_return_if_fail (dev);
	g_return_if_fail (instance_data != NULL);
	g_return_if_fail (dev->instance_data == NULL);

	dev->instance_data = instance_data;
}

/**
 * FP_INSTANCE_DATA:
 * @dev: a struct #fp_dev
 *
 * Returns the instance data set using fp_dev_set_instance_data().
 */
void *
FP_INSTANCE_DATA (struct fp_dev *dev)
{
	g_return_val_if_fail (dev, NULL);

	return dev->instance_data;
}
104

105 106 107 108
/**
 * fpi_dev_get_usb_dev:
 * @dev: a struct #fp_dev
 *
109 110 111 112
 * Returns the #libusb_device_handle associated with @dev or %NULL
 * if none are associated.
 *
 * Returns: a #libusb_device_handle pointer or %NULL
113
 */
114 115 116 117 118 119
libusb_device_handle *
fpi_dev_get_usb_dev(struct fp_dev *dev)
{
	return dev->udev;
}

120 121 122 123 124 125 126 127 128
/**
 * fpi_dev_set_nr_enroll_stages:
 * @dev: a struct #fp_dev
 * @nr_enroll_stages: the number of enroll stages
 *
 * Sets the number of enroll stages that this device uses. This is
 * usually only necessary for primitive devices which have a hard-coded
 * number of enroll stages baked into their protocol.
 */
129 130 131 132 133 134 135
void
fpi_dev_set_nr_enroll_stages(struct fp_dev *dev,
	int nr_enroll_stages)
{
	dev->nr_enroll_stages = nr_enroll_stages;
}

136 137 138 139
/**
 * fpi_dev_get_verify_data:
 * @dev: a struct #fp_dev
 *
140
 * Returns the verify data associated with @dev.
141 142
 * This is usually only necessary for primitive devices which need to
 * have access to the raw verify data as it might have been stored on disk.
143 144
 *
 * Returns: a struct #fp_print_data pointer or %NULL
145
 */
146 147 148 149 150
struct fp_print_data *
fpi_dev_get_verify_data(struct fp_dev *dev)
{
	return dev->verify_data;
}