fpi-ssm.h 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
 * 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
 */

#ifndef __FPI_SSM_H__
#define __FPI_SSM_H__

#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <libusb.h>

/* async drv <--> lib comms */

32 33 34 35
/**
 * fpi_ssm:
 *
 * Sequential state machine that iterates sequentially over
36 37
 * a predefined series of states. Can be terminated by either completion or
 * failure error conditions.
38
 */
Bastien Nocera's avatar
Bastien Nocera committed
39
typedef struct fpi_ssm fpi_ssm;
40 41 42 43

/**
 * ssm_completed_fn:
 * @ssm: a #fpi_ssm state machine
44 45
 * @dev: the #fp_dev fingerprint device
 * @user_data: the user data passed to fpi_ssm_new()
46 47 48 49
 *
 * The callback called when a state machine completes successfully,
 * as set when calling fpi_ssm_start().
 */
50 51 52
typedef void (*ssm_completed_fn)(fpi_ssm *ssm,
				 struct fp_dev *dev,
				 void *user_data);
53

54 55 56
/**
 * ssm_handler_fn:
 * @ssm: a #fpi_ssm state machine
57 58
 * @dev: the #fp_dev fingerprint device
 * @user_data: the user data passed to fpi_ssm_new()
59 60 61 62
 *
 * The callback called when a state machine transitions from one
 * state to the next, as set when calling fpi_ssm_new().
 */
63 64 65
typedef void (*ssm_handler_fn)(fpi_ssm *ssm,
			       struct fp_dev *dev,
			       void *user_data);
66 67

/* for library and drivers */
68 69 70 71
fpi_ssm *fpi_ssm_new(struct fp_dev *dev,
		     ssm_handler_fn handler,
		     int nr_states,
		     void *user_data);
Bastien Nocera's avatar
Bastien Nocera committed
72
void fpi_ssm_free(fpi_ssm *machine);
73
void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback);
Bastien Nocera's avatar
Bastien Nocera committed
74
void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child);
75 76

/* for drivers */
Bastien Nocera's avatar
Bastien Nocera committed
77
void fpi_ssm_next_state(fpi_ssm *machine);
78
void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data);
Bastien Nocera's avatar
Bastien Nocera committed
79 80
void fpi_ssm_jump_to_state(fpi_ssm *machine, int state);
void fpi_ssm_mark_completed(fpi_ssm *machine);
81
void fpi_ssm_mark_failed(fpi_ssm *machine, int error);
82
void *fpi_ssm_get_user_data(fpi_ssm *machine);
Bastien Nocera's avatar
Bastien Nocera committed
83 84
int fpi_ssm_get_error(fpi_ssm *machine);
int fpi_ssm_get_cur_state(fpi_ssm *machine);
85 86

#endif