Commit 15fbacd7 authored by Bastien Nocera's avatar Bastien Nocera Committed by Daniel Drake
Browse files

More identification work

- Add a finger selected signal, so that when an "automatic" finger
  is selected for verification, we know which one to scan
- Fix the finger print numbers list to use GPOINTER_TO_INT /
  GINT_TO_POINTER
- Make sure the gallery is NULL when there's no prints available
- Don't use identification when a finger number is provided
- Add support for selecting the finger number in verify
- Add support for fatal warnings there as well
parent ee874bb1
......@@ -104,6 +104,7 @@ enum fprint_device_properties {
enum fprint_device_signals {
SIGNAL_VERIFY_STATUS,
SIGNAL_VERIFY_FINGER_SELECTED,
SIGNAL_ENROLL_STATUS,
NUM_SIGNALS,
};
......@@ -158,6 +159,9 @@ static void fprint_device_class_init(FprintDeviceClass *klass)
signals[SIGNAL_ENROLL_STATUS] = g_signal_new("enroll-status",
G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
signals[SIGNAL_VERIFY_FINGER_SELECTED] = g_signal_new("verify-finger-selected",
G_TYPE_FROM_CLASS(gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}
static gboolean
......@@ -523,7 +527,7 @@ static void identify_cb(struct fp_dev *dev, int r,
size_t match_offset, struct fp_img *img, void *user_data)
{
struct FprintDevice *rdev = user_data;
g_message("verify_cb: result %d", r);
g_message("identify_cb: result %d", r);
g_signal_emit(rdev, signals[SIGNAL_VERIFY_STATUS], 0, r);
fp_img_free(img);
......@@ -554,6 +558,7 @@ static void fprint_device_verify_start(FprintDevice *rdev,
prints = store.discover_prints(priv->ddev, priv->username);
if (prints == NULL) {
//FIXME exit
g_message ("NO PRINTS");
return;
}
if (fp_dev_supports_identification(priv->dev)) {
......@@ -563,23 +568,30 @@ static void fprint_device_verify_start(FprintDevice *rdev,
array = g_ptr_array_new ();
for (l = prints; l != NULL; l = l->next) {
r = store.print_data_load(priv->dev, (enum fp_finger) l->data,
g_message ("adding finger %d to the gallery", GPOINTER_TO_INT (l->data));
r = store.print_data_load(priv->dev, GPOINTER_TO_INT (l->data),
&data, priv->username);
//FIXME r < 0 ?
g_ptr_array_add (array, data);
}
g_slist_free (l);
gallery = (struct fp_print_data **) g_ptr_array_free (array, FALSE);
data = NULL;
if (array->len > 0) {
g_ptr_array_add (array, NULL);
gallery = (struct fp_print_data **) g_ptr_array_free (array, FALSE);
} else {
gallery = NULL;
}
} else {
finger_num = (enum fp_finger) prints->data;
finger_num = GPOINTER_TO_INT (prints->data);
}
g_slist_free(prints);
}
if (fp_dev_supports_identification(priv->dev)) {
if (fp_dev_supports_identification(priv->dev) && finger_num == -1) {
if (gallery == NULL) {
//FIXME exit
g_message ("NO GALLERY");
return;
}
priv->is_identify = TRUE;
......@@ -601,7 +613,11 @@ static void fprint_device_verify_start(FprintDevice *rdev,
dbus_g_method_return_error(context, error);
return;
}
/* Emit VerifyFingerSelected telling the front-end which finger
* we selected for auth */
g_signal_emit(rdev, signals[SIGNAL_VERIFY_FINGER_SELECTED], 0, finger_num);
/* FIXME fp_async_verify_start should copy the fp_print_data */
r = fp_async_verify_start(priv->dev, data, verify_cb, rdev);
}
......@@ -785,8 +801,7 @@ static void fprint_device_list_enrolled_fingers(FprintDevice *rdev,
ret = g_array_new(FALSE, FALSE, sizeof(int));
for (item = prints; item; item = item->next) {
int *fingerptr = (int *)item->data;
ret = g_array_append_val(ret, *fingerptr);
ret = g_array_append_val(ret, item->data);
}
g_slist_free(prints);
......
......@@ -33,6 +33,10 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
</method>
<signal name="VerifyFingerSelected">
<arg type="i" name="finger_num" />
</signal>
<signal name="VerifyStatus">
<arg type="i" name="result" />
</signal>
......
......@@ -237,7 +237,6 @@ static GSList *scan_dev_storedir(char *devpath, uint16_t driver_id,
while ((ent = g_dir_read_name(dir))) {
/* ent is an 1 hex character fp_finger code */
guint64 val;
int *list_item;
gchar *endptr;
if (*ent == 0 || strlen(ent) != 1)
......@@ -249,9 +248,7 @@ static GSList *scan_dev_storedir(char *devpath, uint16_t driver_id,
continue;
}
list_item = g_slice_new(int);
*list_item = val;
list = g_slist_prepend(list, list_item);
list = g_slist_prepend(list, GINT_TO_POINTER(val));
}
g_dir_close(dir);
......
......@@ -25,6 +25,9 @@
static DBusGProxy *manager = NULL;
static DBusGConnection *connection = NULL;
static int finger_num = -1;
static gboolean g_fatal_warnings = FALSE;
static char **usernames = NULL;
enum fp_verify_result {
VERIFY_NO_MATCH = 0,
......@@ -91,6 +94,8 @@ static const char *fingerstr(guint32 fingernum)
return "Right ring finger";
case RIGHT_LITTLE:
return "Right little finger";
case -1:
return "First fingerprint available";
default:
return "Unknown finger";
}
......@@ -146,7 +151,7 @@ static DBusGProxy *open_device(const char *username)
return dev;
}
static guint32 find_finger(DBusGProxy *dev, const char *username)
static void find_finger(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
GArray *fingers;
......@@ -169,10 +174,6 @@ static guint32 find_finger(DBusGProxy *dev, const char *username)
fingernum = g_array_index(fingers, guint32, 0);
g_array_free(fingers, TRUE);
g_print("Verifying: %s\n", fingerstr(fingernum));
return fingernum;
}
static void verify_result(GObject *object, int result, void *user_data)
......@@ -183,14 +184,22 @@ static void verify_result(GObject *object, int result, void *user_data)
*verify_completed = TRUE;
}
static void do_verify(DBusGProxy *dev, guint32 finger_num)
static void verify_finger_selected(GObject *object, int finger, void *user_data)
{
g_print("Verifying: %s\n", fingerstr(finger));
}
static void do_verify(DBusGProxy *dev)
{
GError *error;
gboolean verify_completed = FALSE;
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_INT, NULL);
dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_INT, NULL);
dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result),
&verify_completed, NULL);
dbus_g_proxy_connect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected),
NULL, NULL);
if (!net_reactivated_Fprint_Device_verify_start(dev, finger_num, &error))
g_error("VerifyStart failed: %s", error->message);
......@@ -199,6 +208,7 @@ static void do_verify(DBusGProxy *dev, guint32 finger_num)
g_main_context_iteration(NULL, TRUE);
dbus_g_proxy_disconnect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result), &verify_completed);
dbus_g_proxy_disconnect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected), NULL);
if (!net_reactivated_Fprint_Device_verify_stop(dev, &error))
g_error("VerifyStop failed: %s", error->message);
......@@ -211,24 +221,52 @@ static void release_device(DBusGProxy *dev)
g_error("ReleaseDevice failed: %s", error->message);
}
static const GOptionEntry entries[] = {
{ "finger", 'f', 0, G_OPTION_ARG_INT, &finger_num, "Finger selected to verify (default is automatic)", NULL },
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &usernames, NULL, "[username]" },
{ NULL }
};
int main(int argc, char **argv)
{
GOptionContext *context;
GMainLoop *loop;
GError *err = NULL;
DBusGProxy *dev;
guint32 finger_num;
char *username;
g_type_init();
context = g_option_context_new ("Verify a fingerprint");
g_option_context_add_main_entries (context, entries, NULL);
if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
g_print ("couldn't parse command-line options: %s\n", err->message);
g_error_free (err);
return 1;
}
if (usernames == NULL) {
username = "";
} else {
username = usernames[0];
}
if (g_fatal_warnings) {
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
}
loop = g_main_loop_new(NULL, FALSE);
create_manager();
username = NULL;
if (argc == 2)
username = argv[1];
dev = open_device(username);
finger_num = find_finger(dev, username);
do_verify(dev, finger_num);
find_finger(dev, username);
do_verify(dev);
release_device(dev);
return 0;
}
......
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