From f81aa47a19a8ab7c1e53d9b483ead064fdd85884 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 8 Oct 2007 17:15:21 +0100 Subject: [PATCH] Add 'verify' example skeleton This will become an example program to enroll a fingerprint and then verify a finger against it. --- Makefile.am | 8 +++++- autogen.sh | 2 +- configure.ac | 9 +++++- examples/Makefile.am | 6 ++++ examples/verify.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 examples/Makefile.am create mode 100644 examples/verify.c diff --git a/Makefile.am b/Makefile.am index df6f390a..57f8dfe1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,8 @@ -SUBDIRS = libfprint EXTRA_DIST = THANKS + +SUBDIRS = libfprint + +if BUILD_EXAMPLES +SUBDIRS += examples +endif + diff --git a/autogen.sh b/autogen.sh index 90932ea8..fe264051 100755 --- a/autogen.sh +++ b/autogen.sh @@ -4,4 +4,4 @@ aclocal || exit 1 autoheader || exit 1 autoconf || exit 1 automake -a -c || exit 1 -./configure --enable-maintainer-mode $* +./configure --enable-maintainer-mode --enable-examples-build $* diff --git a/configure.ac b/configure.ac index ca9f19b8..9e76bd84 100644 --- a/configure.ac +++ b/configure.ac @@ -24,8 +24,15 @@ PKG_CHECK_MODULES(GLIB, "glib-2.0") AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) +# Examples build +AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build], + [build example applications (default n)])], + [build_examples=$enableval], + [build_examples='no']) +AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"]) + AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility]) -AC_CONFIG_FILES([Makefile] [libfprint/Makefile]) +AC_CONFIG_FILES([Makefile] [libfprint/Makefile] [examples/Makefile]) AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 00000000..5b676c62 --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,6 @@ +INCLUDES = -I$(top_srcdir) +noinst_PROGRAMS = verify + +verify_SOURCES = verify.c +verify_LDADD = ../libfprint/libfprint.la -lfprint + diff --git a/examples/verify.c b/examples/verify.c new file mode 100644 index 00000000..7ada2c61 --- /dev/null +++ b/examples/verify.c @@ -0,0 +1,67 @@ +/* + * Example fingerprint verification program + * Copyright (C) 2007 Daniel Drake + * + * 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 +#include + +#include + +struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) +{ + struct fp_dscv_dev *ddev = NULL; + struct fp_dscv_dev *tmpdev; + int i; + + for (i = 0; tmpdev = discovered_devs[i]; i++) { + const struct fp_driver *drv = fp_dscv_dev_get_driver(tmpdev); + printf("Found device claimed by %s driver\n", + fp_driver_get_full_name(drv)); + return ddev; + } + + return ddev; +} + +int main(void) +{ + int r; + struct fp_dscv_dev *ddev; + struct fp_dscv_dev **discovered_devs; + + r = fp_init(); + if (r < 0) { + fprintf(stderr, "Failed to initialize libfprint\n"); + exit(1); + } + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) { + fprintf(stderr, "Could not discover devices\n"); + exit(1); + } + + ddev = discover_device(discovered_devs); + if (!ddev) { + fprintf(stderr, "No devices detected.\n"); + exit(1); + } + + fp_dscv_devs_free(discovered_devs); +} +