[fprint] Problem with g_main_loop_run libfprint v1.90.7

Carlos Garcia gavajc at live.com
Wed Apr 14 16:04:51 UTC 2021


Hi everyone.

I have problems with g_main_loop_run executing it in another thread. I’m using  a Digital Persona U are U 4500 device.

I have an init function that opens a device, when the device is opened, then g_main_loop_run is execute in another thread.
When I close the device calling fp_device_close_sync  the result is TRUE but I have the following error:

(process:38166): libfprint-image_device-DEBUG: 10:56:02.418: Image device close completed
(process:38166): libfprint-device-DEBUG: 10:56:02.418: Device reported close completion
(process:38166): libfprint-device-DEBUG: 10:56:02.418: Completing action FPI_DEVICE_ACTION_CLOSE in idle!

(process:38166): GLib-CRITICAL **: 10:56:02.418: g_source_unref: assertion 'source != NULL' failed


The documentation for  fp_device_close_sync  says that the return value is: FALSE on error, TRUE otherwise. So, if the function returns TRUE why this error?

Another problem is that sometimes calling fp_device_close_sync freezes the app because fp_device_close_sync never returns.

Here is my code:


typedef struct
{
    FpContext *ctx;             ///< Libfprint context.
    FpDevice *device;           ///< Libfprint device.
    pthread_t event_t;          ///< The glib event loop thread.
    GMainLoop *gmloop;          ///< Glib event manager loop.
}tETR_FP_CONTEXT;

typedef struct
{
    tKERNEL_FSM *fsm;           ///< Finite State Machine structure pointer.
    tETR_FP_CONTEXT ctx;        ///< Fingerprint context structure.
}tAUTOMATON_DATA;

static void * etr_fp_execute_loop(void *data)
{
    tAUTOMATON_DATA *aut = (tAUTOMATON_DATA *) data;

    aut->ctx.gmloop = g_main_loop_new(NULL,FALSE);
    g_main_loop_run(aut->ctx.gmloop);

    return NULL;
}

void init__entry(tAUTOMATON_DATA *aut)
{
    FpDevice *device;
    GPtrArray *devices;
    g_autoptr(GError) gerror = NULL;

    aut->ctx.ctx = fp_context_new();
    devices      = fp_context_get_devices(aut->ctx.ctx);

    if (devices && devices->len)
    {
        device = g_ptr_array_index(devices,0);
        aut->ctx.device = device;

        // Open device
        if (fp_device_open_sync(aut->ctx.device,aut->ctx.clops,&gerror))
        {
            // Execute g_main_loop_run in another thread
            if (!pthread_create(&aut->ctx.event_t,NULL,&etr_fp_execute_loop,aut)) {
                pthread_detach(aut->ctx.event_t);
                KernelInsertEvent(aut->fsm->aut_id,AUT_EVT_OPENED,NULL,0);
            }
            else
                LogError("Unable to create glib event loop thread");
        }
        else
            LogError("Unable to open device. %s",gerror->message);
    }
    else LogError("Unable to find a compatible device");
}

static void etr_fp_dev_close(tAUTOMATON_DATA *aut)
{
    g_autoptr(GError) gerror = NULL;

    if (!fp_device_close_sync(aut->ctx.device,NULL,&gerror)) // Sometimes calling this function
    {                                                        // freezes the app. Because never returns.
        LogError("Error closing device: %s",gerror->message);
    }

    g_clear_object(&aut->ctx.ctx);
    g_clear_object(&aut->ctx.clops);

    if (aut->ctx.gmloop != NULL) {
        g_main_loop_quit(aut->ctx.gmloop);
        g_main_loop_unref(aut->ctx.gmloop);
    }
}

If I create a new context with g_main_context_new and apply to g_main_loop_new as follows:

new_context = g_main_context_new();
aut->ctx.gmloop = g_main_loop_new(new_context, false);

and use the follow functions in the thread function:

static void * etr_fp_execute_loop(void *data)
{
       tAUTOMATON_DATA *aut = (tAUTOMATON_DATA *) data;

       g_main_context_push_thread_default(new_context);
       g_main_loop_run(aut->ctx.gmloop);
       g_main_context_pop_thread_default(new_context);

       return NULL;
}

Nothing works.

Hope someone can help me. Thank you all.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/fprint/attachments/20210414/c94d199f/attachment-0001.htm>


More information about the fprint mailing list