From 5ae2ef540776646e035a7d9fe3512a08c4aa8916 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 5 Sep 2018 12:39:16 +0200
Subject: [PATCH] lib: Split off fpi_ssm functions

Rename drv.c to something more fitting to its contents, and move state
machine code to its own header.
---
 libfprint/drivers_api.h        | 30 +----------------
 libfprint/fp_internal.h        | 34 -------------------
 libfprint/{drv.c => fpi-ssm.c} | 16 +++++++++
 libfprint/fpi-ssm.h            | 60 ++++++++++++++++++++++++++++++++++
 libfprint/meson.build          |  3 +-
 5 files changed, 79 insertions(+), 64 deletions(-)
 rename libfprint/{drv.c => fpi-ssm.c} (93%)
 create mode 100644 libfprint/fpi-ssm.h

diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h
index 2aba675..02fe43c 100644
--- a/libfprint/drivers_api.h
+++ b/libfprint/drivers_api.h
@@ -36,6 +36,7 @@
 #include <libusb.h>
 
 #include "fprint.h"
+#include "fpi-ssm.h"
 #include "assembling.h"
 #include "drivers/driver_ids.h"
 
@@ -211,35 +212,6 @@ struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback,
 	void *data);
 void fpi_timeout_cancel(struct fpi_timeout *timeout);
 
-/* async drv <--> lib comms */
-
-struct fpi_ssm;
-typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm);
-typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm);
-
-/* sequential state machine: state machine that iterates sequentially over
- * a predefined series of states. can be aborted by either completion or
- * abortion error conditions. */
-
-/* for library and drivers */
-struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler,
-	int nr_states);
-void fpi_ssm_free(struct fpi_ssm *machine);
-void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback);
-void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child);
-
-/* for drivers */
-void fpi_ssm_next_state(struct fpi_ssm *machine);
-void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state);
-void fpi_ssm_mark_completed(struct fpi_ssm *machine);
-void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error);
-struct fp_dev *fpi_ssm_get_dev(struct fpi_ssm *machine);
-void fpi_ssm_set_user_data(struct fpi_ssm *machine,
-	void *user_data);
-void *fpi_ssm_get_user_data(struct fpi_ssm *machine);
-int fpi_ssm_get_error(struct fpi_ssm *machine);
-int fpi_ssm_get_cur_state(struct fpi_ssm *machine);
-
 void fpi_drvcb_open_complete(struct fp_dev *dev, int status);
 void fpi_drvcb_close_complete(struct fp_dev *dev);
 
diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h
index e750182..48a2518 100644
--- a/libfprint/fp_internal.h
+++ b/libfprint/fp_internal.h
@@ -348,40 +348,6 @@ void fpi_poll_exit(void);
 
 typedef void (*fpi_timeout_fn)(void *data);
 
-/* async drv <--> lib comms */
-
-struct fpi_ssm;
-typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm);
-typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm);
-
-/* sequential state machine: state machine that iterates sequentially over
- * a predefined series of states. can be aborted by either completion or
- * abortion error conditions. */
-struct fpi_ssm {
-	struct fp_dev *dev;
-	struct fpi_ssm *parentsm;
-	void *priv;
-	int nr_states;
-	int cur_state;
-	gboolean completed;
-	int error;
-	ssm_completed_fn callback;
-	ssm_handler_fn handler;
-};
-
-
-/* for library and drivers */
-struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler,
-	int nr_states);
-void fpi_ssm_free(struct fpi_ssm *machine);
-void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback);
-
-/* for drivers */
-void fpi_ssm_next_state(struct fpi_ssm *machine);
-void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state);
-void fpi_ssm_mark_completed(struct fpi_ssm *machine);
-void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error);
-
 void fpi_drvcb_open_complete(struct fp_dev *dev, int status);
 void fpi_drvcb_close_complete(struct fp_dev *dev);
 
diff --git a/libfprint/drv.c b/libfprint/fpi-ssm.c
similarity index 93%
rename from libfprint/drv.c
rename to libfprint/fpi-ssm.c
index d550745..03aaf6e 100644
--- a/libfprint/drv.c
+++ b/libfprint/fpi-ssm.c
@@ -20,6 +20,7 @@
 #define FP_COMPONENT "drv"
 
 #include "fp_internal.h"
+#include "fpi-ssm.h"
 
 #include <config.h>
 #include <errno.h>
@@ -68,6 +69,21 @@
  * successful completion.
  */
 
+/* sequential state machine: state machine that iterates sequentially over
+ * a predefined series of states. can be aborted by either completion or
+ * abortion error conditions. */
+struct fpi_ssm {
+	struct fp_dev *dev;
+	struct fpi_ssm *parentsm;
+	void *priv;
+	int nr_states;
+	int cur_state;
+	gboolean completed;
+	int error;
+	ssm_completed_fn callback;
+	ssm_handler_fn handler;
+};
+
 /* Allocate a new ssm */
 struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler,
 	int nr_states)
diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h
new file mode 100644
index 0000000..ddb4195
--- /dev/null
+++ b/libfprint/fpi-ssm.h
@@ -0,0 +1,60 @@
+/*
+ * Driver API definitions
+ * 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 */
+
+struct fpi_ssm;
+typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm);
+typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm);
+
+/* sequential state machine: state machine that iterates sequentially over
+ * a predefined series of states. can be aborted by either completion or
+ * abortion error conditions. */
+
+/* for library and drivers */
+struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler,
+	int nr_states);
+void fpi_ssm_free(struct fpi_ssm *machine);
+void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback);
+void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child);
+
+/* for drivers */
+void fpi_ssm_next_state(struct fpi_ssm *machine);
+void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state);
+void fpi_ssm_mark_completed(struct fpi_ssm *machine);
+void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error);
+struct fp_dev *fpi_ssm_get_dev(struct fpi_ssm *machine);
+void fpi_ssm_set_user_data(struct fpi_ssm *machine,
+	void *user_data);
+void *fpi_ssm_get_user_data(struct fpi_ssm *machine);
+int fpi_ssm_get_error(struct fpi_ssm *machine);
+int fpi_ssm_get_cur_state(struct fpi_ssm *machine);
+
+#endif
diff --git a/libfprint/meson.build b/libfprint/meson.build
index c97dcf8..0a9ed02 100644
--- a/libfprint/meson.build
+++ b/libfprint/meson.build
@@ -4,7 +4,8 @@ libfprint_sources = [
     'async.c',
     'core.c',
     'data.c',
-    'drv.c',
+    'fpi-ssm.c',
+    'fpi-ssm.h',
     'img.c',
     'imgdev.c',
     'poll.c',