diff --git a/examples/demo.c b/examples/demo.c index 3729150..8c4152f 100644 --- a/examples/demo.c +++ b/examples/demo.c @@ -179,26 +179,33 @@ static guint32 find_finger(DBusGProxy *dev) return print_id; } -static int do_verify(DBusGProxy *dev, guint32 print_id) +static void verify_result(GObject *object, int result, void *user_data) +{ + gboolean *verify_completed = user_data; + g_print("Verify result: %s (%d)\n", verify_result_str(result), result); + if (result == VERIFY_NO_MATCH || result == VERIFY_MATCH) + *verify_completed = TRUE; +} + +static void do_verify(DBusGProxy *dev, guint32 print_id) { GError *error; - gboolean more_results; - int result; + gboolean verify_completed = FALSE; + + dbus_g_proxy_add_signal(dev, "VerifyResult", G_TYPE_INT, NULL); + dbus_g_proxy_connect_signal(dev, "VerifyResult", G_CALLBACK(verify_result), + &verify_completed, NULL); if (!net_reactivated_Fprint_Device_verify_start(dev, print_id, &error)) g_error("VerifyStart failed: %s", error->message); - do { - if (!net_reactivated_Fprint_Device_get_verify_result(dev, &result, &more_results, &error)) - g_error("GetVerifyResult failed: %s", error->message); + while (!verify_completed) + g_main_context_iteration(NULL, TRUE); - g_print("Verify result: %s (%d)\n", verify_result_str(result), result); - } while (result != VERIFY_NO_MATCH && result != VERIFY_MATCH); + dbus_g_proxy_disconnect_signal(dev, "VerifyResult", G_CALLBACK(verify_result), &verify_completed); if (!net_reactivated_Fprint_Device_verify_stop(dev, &error)) g_error("VerifyStop failed: %s", error->message); - - return result; } static void unload_print(DBusGProxy *dev, guint32 print_id) @@ -220,7 +227,6 @@ int main(int argc, char **argv) GMainLoop *loop; DBusGProxy *dev; guint32 print_id; - int verify_result; g_type_init(); loop = g_main_loop_new(NULL, FALSE); @@ -228,7 +234,7 @@ int main(int argc, char **argv) dev = open_device(); print_id = find_finger(dev); - verify_result = do_verify(dev, print_id); + do_verify(dev, print_id); unload_print(dev, print_id); release_device(dev); return 0; diff --git a/src/device.c b/src/device.c index 2e37456..3faaf44 100644 --- a/src/device.c +++ b/src/device.c @@ -38,33 +38,20 @@ static gboolean fprint_device_verify_start(FprintDevice *rdev, guint32 print_id, GError **error); static gboolean fprint_device_verify_stop(FprintDevice *rdev, DBusGMethodInvocation *context); -static gboolean fprint_device_get_verify_result(FprintDevice *rdev, - DBusGMethodInvocation *context); #include "device-dbus-glue.h" struct session_data { - /* a list of pending verify results to be returned via GetVerifyResult() */ - GList *verify_results; - /* method invocation for async ClaimDevice() */ DBusGMethodInvocation *context_claim_device; /* method invocation for async ReleaseDevice() */ DBusGMethodInvocation *context_release_device; - /* method invocation for async GetVerifyResult() */ - DBusGMethodInvocation *context_get_verify_result; - /* a list of loaded prints */ GSList *loaded_prints; }; -struct verify_result { - int result; - struct fp_img *img; -}; - struct loaded_print { guint32 id; struct fp_print_data *data; @@ -85,8 +72,14 @@ enum fprint_device_properties { FPRINT_DEVICE_CONSTRUCT_DDEV = 1, }; +enum fprint_device_signals { + SIGNAL_VERIFY_RESULT, + NUM_SIGNALS, +}; + static GObjectClass *parent_class = NULL; static guint32 last_id = ~0; +static guint signals[NUM_SIGNALS] = { 0, }; static void device_finalize(GObject *object) { @@ -120,6 +113,7 @@ static void device_class_init(FprintDeviceClass *klass) gobject_class->finalize = device_finalize; gobject_class->set_property = device_set_property; + g_type_class_add_private(klass, sizeof(FprintDevicePrivate)); pspec = g_param_spec_pointer("discovered-dev", "Discovered device", "Set discovered device construction property", @@ -127,7 +121,9 @@ static void device_class_init(FprintDeviceClass *klass) g_object_class_install_property(gobject_class, FPRINT_DEVICE_CONSTRUCT_DDEV, pspec); - g_type_class_add_private(klass, sizeof(FprintDevicePrivate)); + signals[SIGNAL_VERIFY_RESULT] = g_signal_new("verify-result", + 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 void device_init(GTypeInstance *instance, gpointer g_class) @@ -359,25 +355,10 @@ static void verify_cb(struct fp_dev *dev, int r, struct fp_img *img, void *user_data) { struct FprintDevice *rdev = user_data; - FprintDevicePrivate *priv = DEVICE_GET_PRIVATE(rdev); - struct session_data *session = priv->session; g_message("verify_cb: result %d", r); - if (session->context_get_verify_result) { - /* if we have an app waiting on a verify result, report it - * immediately */ - dbus_g_method_return(session->context_get_verify_result, r, FALSE); - fp_img_free(img); - session->context_get_verify_result = NULL; - } else { - /* otherwise nobody is listening. add it to the queue of pending - * results */ - struct verify_result *result = g_slice_new(struct verify_result); - result->result = r; - result->img = img; - session->verify_results = g_list_append(session->verify_results, - result); - } + g_signal_emit(rdev, signals[SIGNAL_VERIFY_RESULT], 0, r); + fp_img_free(img); } static gboolean fprint_device_verify_start(FprintDevice *rdev, @@ -421,32 +402,6 @@ static gboolean fprint_device_verify_start(FprintDevice *rdev, return TRUE; } -static gboolean fprint_device_get_verify_result(FprintDevice *rdev, - DBusGMethodInvocation *context) -{ - FprintDevicePrivate *priv = DEVICE_GET_PRIVATE(rdev); - struct session_data *session = priv->session; - GList *elem = session->verify_results; - - if (elem == NULL) { - /* no pending results, asynchronously wait for the next one */ - session->context_get_verify_result = context; - g_message("get_verify_result: none pending, waiting for next one"); - } else { - struct verify_result *result = elem->data; - gboolean has_next = (g_list_next(elem) != NULL); - g_message("GetVerifyResult: returning pending result %d", - result->result); - dbus_g_method_return(context, result->result, has_next); - fp_img_free(result->img); - session->verify_results = g_list_delete_link(session->verify_results, - elem); - g_slice_free(struct verify_result, result); - } - - return TRUE; -} - static void verify_stop_cb(struct fp_dev *dev, void *user_data) { dbus_g_method_return((DBusGMethodInvocation *) user_data); @@ -456,21 +411,8 @@ static gboolean fprint_device_verify_stop(FprintDevice *rdev, DBusGMethodInvocation *context) { FprintDevicePrivate *priv = DEVICE_GET_PRIVATE(rdev); - struct session_data *session = priv->session; - GList *elem = session->verify_results; int r; - /* Free all unreaped verify results */ - if (elem) { - do { - struct verify_result *result = elem->data; - fp_img_free(result->img); - g_slice_free(struct verify_result, result); - } while ((elem = g_list_next(elem)) != NULL); - g_list_free(session->verify_results); - session->verify_results = NULL; - } - r = fp_async_verify_stop(priv->dev, verify_stop_cb, context); if (r < 0) { GError *error; diff --git a/src/device.xml b/src/device.xml index 4afba0e..2a684b4 100644 --- a/src/device.xml +++ b/src/device.xml @@ -34,16 +34,9 @@ - - - - - - - +