Commit 4f75e63e authored by Bastien Nocera's avatar Bastien Nocera
Browse files

lib: Remove fp_dev->priv

Not precise enough, and it was only used in upekts to get/set the
instance private struct and keep it around, so add a new, more precisely
defined field to fp_dev for that.
parent 2e50ff5e
...@@ -190,4 +190,6 @@ fp_img_dev ...@@ -190,4 +190,6 @@ fp_img_dev
FP_DEV FP_DEV
FP_IMG_DEV FP_IMG_DEV
fp_dev_set_instance_data
FP_INSTANCE_DATA
</SECTION> </SECTION>
...@@ -534,19 +534,6 @@ fpi_dev_get_usb_dev(struct fp_dev *dev) ...@@ -534,19 +534,6 @@ fpi_dev_get_usb_dev(struct fp_dev *dev)
return dev->udev; return dev->udev;
} }
void *
fpi_dev_get_user_data (struct fp_dev *dev)
{
return dev->priv;
}
void
fpi_dev_set_user_data (struct fp_dev *dev,
void *user_data)
{
dev->priv = user_data;
}
int int
fpi_dev_get_nr_enroll_stages(struct fp_dev *dev) fpi_dev_get_nr_enroll_stages(struct fp_dev *dev)
{ {
......
...@@ -137,7 +137,7 @@ static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev, ...@@ -137,7 +137,7 @@ static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev,
uint16_t _innerlen = innerlen; uint16_t _innerlen = innerlen;
size_t len = innerlen + 6; size_t len = innerlen + 6;
unsigned char *buf = g_malloc0(len); unsigned char *buf = g_malloc0(len);
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT; uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT;
struct libusb_transfer *ret; struct libusb_transfer *ret;
...@@ -489,7 +489,7 @@ static void initsm_read_msg_response_cb(fpi_ssm *ssm, ...@@ -489,7 +489,7 @@ static void initsm_read_msg_response_cb(fpi_ssm *ssm,
unsigned char expect_subcmd, unsigned char subcmd) unsigned char expect_subcmd, unsigned char subcmd)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (status != READ_MSG_RESPONSE) { if (status != READ_MSG_RESPONSE) {
fp_err("expected response, got %d seq=%x in state %d", status, seq, fp_err("expected response, got %d seq=%x in state %d", status, seq,
...@@ -553,7 +553,7 @@ static void initsm_read_msg_cmd_cb(fpi_ssm *ssm, ...@@ -553,7 +553,7 @@ static void initsm_read_msg_cmd_cb(fpi_ssm *ssm,
enum read_msg_status status, uint8_t expect_seq, uint8_t seq) enum read_msg_status status, uint8_t expect_seq, uint8_t seq)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (status == READ_MSG_ERROR) { if (status == READ_MSG_ERROR) {
fpi_ssm_mark_failed(ssm, -1); fpi_ssm_mark_failed(ssm, -1);
...@@ -652,7 +652,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, ...@@ -652,7 +652,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm,
static void initsm_run_state(fpi_ssm *ssm) static void initsm_run_state(fpi_ssm *ssm)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
struct libusb_transfer *transfer; struct libusb_transfer *transfer;
int r; int r;
...@@ -764,7 +764,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, ...@@ -764,7 +764,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status,
void *user_data) void *user_data)
{ {
fpi_ssm *ssm = user_data; fpi_ssm *ssm = user_data;
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (status == READ_MSG_ERROR) { if (status == READ_MSG_ERROR) {
fpi_ssm_mark_failed(ssm, -1); fpi_ssm_mark_failed(ssm, -1);
...@@ -834,7 +834,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data) ...@@ -834,7 +834,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
upekdev = g_malloc(sizeof(*upekdev)); upekdev = g_malloc(sizeof(*upekdev));
upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */ upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */
fpi_dev_set_user_data(dev, upekdev); fp_dev_set_instance_data(dev, upekdev);
fpi_dev_set_nr_enroll_stages(dev, 3); fpi_dev_set_nr_enroll_stages(dev, 3);
fpi_drvcb_open_complete(dev, 0); fpi_drvcb_open_complete(dev, 0);
...@@ -843,10 +843,10 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data) ...@@ -843,10 +843,10 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
static void dev_exit(struct fp_dev *dev) static void dev_exit(struct fp_dev *dev)
{ {
void *user_data; struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
libusb_release_interface(fpi_dev_get_usb_dev(dev), 0); libusb_release_interface(fpi_dev_get_usb_dev(dev), 0);
user_data = fpi_dev_get_user_data(dev); g_free(upekdev);
g_free(user_data);
fpi_drvcb_close_complete(dev); fpi_drvcb_close_complete(dev);
} }
...@@ -897,7 +897,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, ...@@ -897,7 +897,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev,
enum read_msg_status status, uint8_t seq, unsigned char subcmd, enum read_msg_status status, uint8_t seq, unsigned char subcmd,
unsigned char *data, size_t data_len, void *user_data) unsigned char *data, size_t data_len, void *user_data)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
fpi_ssm *ssm = user_data; fpi_ssm *ssm = user_data;
if (status != READ_MSG_RESPONSE) { if (status != READ_MSG_RESPONSE) {
...@@ -960,7 +960,7 @@ static void enroll_iterate(struct fp_dev *dev); ...@@ -960,7 +960,7 @@ static void enroll_iterate(struct fp_dev *dev);
static void e_handle_resp00(struct fp_dev *dev, unsigned char *data, static void e_handle_resp00(struct fp_dev *dev, unsigned char *data,
size_t data_len) size_t data_len)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
unsigned char status; unsigned char status;
int result = 0; int result = 0;
...@@ -1125,7 +1125,7 @@ static void enroll_started(fpi_ssm *ssm) ...@@ -1125,7 +1125,7 @@ static void enroll_started(fpi_ssm *ssm)
static int enroll_start(struct fp_dev *dev) static int enroll_start(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
/* do_init state machine first */ /* do_init state machine first */
fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state,
...@@ -1319,7 +1319,7 @@ static void verify_rd2800_cb(struct fp_dev *dev, enum read_msg_status msgstat, ...@@ -1319,7 +1319,7 @@ static void verify_rd2800_cb(struct fp_dev *dev, enum read_msg_status msgstat,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data) void *user_data)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (msgstat != READ_MSG_RESPONSE) { if (msgstat != READ_MSG_RESPONSE) {
fp_err("expected response, got %d seq=%x", msgstat, seq); fp_err("expected response, got %d seq=%x", msgstat, seq);
...@@ -1358,7 +1358,7 @@ static void verify_wr2800_cb(struct libusb_transfer *transfer) ...@@ -1358,7 +1358,7 @@ static void verify_wr2800_cb(struct libusb_transfer *transfer)
static void verify_iterate(struct fp_dev *dev) static void verify_iterate(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (upekdev->stop_verify) { if (upekdev->stop_verify) {
do_verify_stop(dev); do_verify_stop(dev);
...@@ -1394,7 +1394,7 @@ static void verify_iterate(struct fp_dev *dev) ...@@ -1394,7 +1394,7 @@ static void verify_iterate(struct fp_dev *dev)
static void verify_started(fpi_ssm *ssm) static void verify_started(fpi_ssm *ssm)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm)); fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm));
if (!fpi_ssm_get_error(ssm)) { if (!fpi_ssm_get_error(ssm)) {
...@@ -1407,7 +1407,7 @@ static void verify_started(fpi_ssm *ssm) ...@@ -1407,7 +1407,7 @@ static void verify_started(fpi_ssm *ssm)
static int verify_start(struct fp_dev *dev) static int verify_start(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state,
VERIFY_NUM_STATES); VERIFY_NUM_STATES);
upekdev->stop_verify = FALSE; upekdev->stop_verify = FALSE;
...@@ -1417,7 +1417,7 @@ static int verify_start(struct fp_dev *dev) ...@@ -1417,7 +1417,7 @@ static int verify_start(struct fp_dev *dev)
static int verify_stop(struct fp_dev *dev, gboolean iterating) static int verify_stop(struct fp_dev *dev, gboolean iterating)
{ {
struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev);
if (!iterating) if (!iterating)
do_verify_stop(dev); do_verify_stop(dev);
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
#include "drivers/driver_ids.h" #include "drivers/driver_ids.h"
libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev);
void *fpi_dev_get_user_data (struct fp_dev *dev);
void fpi_dev_set_user_data (struct fp_dev *dev, void *user_data);
int fpi_dev_get_nr_enroll_stages(struct fp_dev *dev); int fpi_dev_get_nr_enroll_stages(struct fp_dev *dev);
void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, int nr_enroll_stages); void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, int nr_enroll_stages);
struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev);
......
...@@ -68,15 +68,14 @@ struct fp_dev { ...@@ -68,15 +68,14 @@ struct fp_dev {
/* only valid if drv->type == DRIVER_IMAGING */ /* only valid if drv->type == DRIVER_IMAGING */
struct fp_img_dev *img_dev; struct fp_img_dev *img_dev;
/* Link to the instance specific struct */
void *instance_data;
int nr_enroll_stages; int nr_enroll_stages;
/* FIXME: This will eventually have a bus type */ /* FIXME: This will eventually have a bus type */
libusb_device_handle *udev; libusb_device_handle *udev;
/* FIXME: Remove, should be the driver private data */
void *priv;
/* read-only to drivers */ /* read-only to drivers */
struct fp_print_data *verify_data; struct fp_print_data *verify_data;
......
...@@ -59,3 +59,40 @@ FP_IMG_DEV(struct fp_dev *dev) ...@@ -59,3 +59,40 @@ FP_IMG_DEV(struct fp_dev *dev)
g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL); g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL);
return dev->img_dev; return dev->img_dev;
} }
/**
* 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;
}
...@@ -29,3 +29,7 @@ struct fp_img_dev; ...@@ -29,3 +29,7 @@ struct fp_img_dev;
struct fp_dev *FP_DEV (struct fp_img_dev *dev); struct fp_dev *FP_DEV (struct fp_img_dev *dev);
struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev); struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev);
void fp_dev_set_instance_data (struct fp_dev *dev,
void *instance_data);
void *FP_INSTANCE_DATA (struct fp_dev *dev);
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