examples: Move discover_device function to utilities

While there are various functions which similar usage in all the examples,
I'd prefer to keep each example to be self-containing most of the things.
However some clearly repeated action can be moved to a single codebase.
This commit is contained in:
Marco Trevisan (Treviño) 2019-11-20 14:36:57 +01:00 committed by Benjamin Berg
parent ab804f7f49
commit 39e3e2b794
5 changed files with 17 additions and 37 deletions

View file

@ -40,18 +40,6 @@ enroll_data_free (EnrollData *enroll_data)
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EnrollData, enroll_data_free)
FpDevice *discover_device (GPtrArray * devices)
{
FpDevice *dev;
if (!devices->len)
return NULL;
dev = g_ptr_array_index (devices, 0);
printf ("Found device claimed by %s driver\n", fp_device_get_driver (dev));
return dev;
}
static void
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
{

View file

@ -40,18 +40,6 @@ list_data_free (ListData *list_data)
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ListData, list_data_free)
FpDevice *discover_device (GPtrArray * devices)
{
FpDevice *dev;
if (!devices->len)
return NULL;
dev = g_ptr_array_index (devices, 0);
g_print ("Found device claimed by %s driver\n", fp_device_get_driver (dev));
return dev;
}
static void
on_device_closed (FpDevice *dev,
GAsyncResult *res,

View file

@ -23,6 +23,21 @@
#include "utilities.h"
FpDevice *
discover_device (GPtrArray * devices)
{
FpDevice *dev;
if (!devices->len)
return NULL;
dev = g_ptr_array_index (devices, 0);
g_print ("Found device %s (%s) claimed by %s driver\n",
fp_device_get_device_id (dev), fp_device_get_name (dev),
fp_device_get_driver (dev));
return dev;
}
const char *
finger_to_string (FpFinger finger)
{
@ -81,7 +96,7 @@ finger_chooser (void)
};
for (i = all_fingers[0]; i <= G_N_ELEMENTS (all_fingers); ++i)
g_print(" [%d] %s\n", (i - all_fingers[0]), finger_to_string (i));
g_print (" [%d] %s\n", (i - all_fingers[0]), finger_to_string (i));
g_print ("> ");
if (!scanf ("%d%*c", &i))

View file

@ -21,6 +21,7 @@
#ifndef __UTILITIES_H
#define __UTILITIES_H
FpDevice * discover_device (GPtrArray *devices);
FpFinger finger_chooser (void);
const char * finger_to_string (FpFinger finger);

View file

@ -40,18 +40,6 @@ verify_data_free (VerifyData *verify_data)
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VerifyData, verify_data_free)
FpDevice *discover_device (GPtrArray * devices)
{
FpDevice *dev;
if (!devices->len)
return NULL;
dev = g_ptr_array_index (devices, 0);
printf ("Found device claimed by %s driver\n", fp_device_get_driver (dev));
return dev;
}
static void
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
{