virtual-device: Move shared functions into the internal scope

We are currently exporting such functions in the library, even though
they are meant to be only private.
This commit is contained in:
Marco Trevisan (Treviño) 2021-02-22 21:07:36 +01:00
parent e4a297887b
commit 8fd1fcbe49
4 changed files with 143 additions and 143 deletions

View file

@ -28,35 +28,35 @@
#include "virtual-device-private.h" #include "virtual-device-private.h"
struct _FpDeviceVirtualListener struct _FpiDeviceVirtualListener
{ {
GSocketListener parent_instance; GSocketListener parent_instance;
GSocketConnection *connection; GSocketConnection *connection;
GCancellable *cancellable; GCancellable *cancellable;
guint cancellable_id; guint cancellable_id;
FpDeviceVirtualListenerConnectionCb ready_cb; FpiDeviceVirtualListenerConnectionCb ready_cb;
gpointer ready_cb_data; gpointer ready_cb_data;
gint socket_fd; gint socket_fd;
gint client_fd; gint client_fd;
}; };
G_DEFINE_TYPE (FpDeviceVirtualListener, fp_device_virtual_listener, G_TYPE_SOCKET_LISTENER) G_DEFINE_TYPE (FpiDeviceVirtualListener, fpi_device_virtual_listener, G_TYPE_SOCKET_LISTENER)
static void start_listen (FpDeviceVirtualListener *self); static void start_listen (FpiDeviceVirtualListener *self);
FpDeviceVirtualListener * FpiDeviceVirtualListener *
fp_device_virtual_listener_new (void) fpi_device_virtual_listener_new (void)
{ {
return g_object_new (fp_device_virtual_listener_get_type (), NULL); return g_object_new (fpi_device_virtual_listener_get_type (), NULL);
} }
static void static void
fp_device_virtual_listener_dispose (GObject *object) fpi_device_virtual_listener_dispose (GObject *object)
{ {
FpDeviceVirtualListener *self = FP_DEVICE_VIRTUAL_LISTENER (object); FpiDeviceVirtualListener *self = FPI_DEVICE_VIRTUAL_LISTENER (object);
if (self->cancellable_id) if (self->cancellable_id)
{ {
@ -70,19 +70,19 @@ fp_device_virtual_listener_dispose (GObject *object)
self->ready_cb = NULL; self->ready_cb = NULL;
G_OBJECT_CLASS (fp_device_virtual_listener_parent_class)->dispose (object); G_OBJECT_CLASS (fpi_device_virtual_listener_parent_class)->dispose (object);
} }
static void static void
fp_device_virtual_listener_class_init (FpDeviceVirtualListenerClass *klass) fpi_device_virtual_listener_class_init (FpiDeviceVirtualListenerClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = fp_device_virtual_listener_dispose; object_class->dispose = fpi_device_virtual_listener_dispose;
} }
static void static void
fp_device_virtual_listener_init (FpDeviceVirtualListener *self) fpi_device_virtual_listener_init (FpiDeviceVirtualListener *self)
{ {
} }
@ -90,7 +90,7 @@ static void
new_connection_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) new_connection_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
FpDeviceVirtualListener *self = user_data; FpiDeviceVirtualListener *self = user_data;
GSocketConnection *connection; GSocketConnection *connection;
connection = g_socket_listener_accept_finish (G_SOCKET_LISTENER (source_object), connection = g_socket_listener_accept_finish (G_SOCKET_LISTENER (source_object),
@ -123,7 +123,7 @@ new_connection_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
} }
static void static void
start_listen (FpDeviceVirtualListener *self) start_listen (FpiDeviceVirtualListener *self)
{ {
g_socket_listener_accept_async (G_SOCKET_LISTENER (self), g_socket_listener_accept_async (G_SOCKET_LISTENER (self),
self->cancellable, self->cancellable,
@ -132,27 +132,27 @@ start_listen (FpDeviceVirtualListener *self)
} }
static void static void
on_cancelled (GCancellable *cancellable, on_cancelled (GCancellable *cancellable,
FpDeviceVirtualListener *self) FpiDeviceVirtualListener *self)
{ {
fp_device_virtual_listener_connection_close (self); fpi_device_virtual_listener_connection_close (self);
g_socket_listener_close (G_SOCKET_LISTENER (self)); g_socket_listener_close (G_SOCKET_LISTENER (self));
g_clear_object (&self->cancellable); g_clear_object (&self->cancellable);
self->ready_cb = NULL; self->ready_cb = NULL;
} }
gboolean gboolean
fp_device_virtual_listener_start (FpDeviceVirtualListener *self, fpi_device_virtual_listener_start (FpiDeviceVirtualListener *self,
const char *address, const char *address,
GCancellable *cancellable, GCancellable *cancellable,
FpDeviceVirtualListenerConnectionCb cb, FpiDeviceVirtualListenerConnectionCb cb,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
g_autoptr(GSocketAddress) addr = NULL; g_autoptr(GSocketAddress) addr = NULL;
G_DEBUG_HERE (); G_DEBUG_HERE ();
g_return_val_if_fail (FP_IS_DEVICE_VIRTUAL_LISTENER (self), FALSE); g_return_val_if_fail (FPI_IS_DEVICE_VIRTUAL_LISTENER (self), FALSE);
g_return_val_if_fail (cb != NULL, FALSE); g_return_val_if_fail (cb != NULL, FALSE);
g_return_val_if_fail (self->ready_cb == NULL, FALSE); g_return_val_if_fail (self->ready_cb == NULL, FALSE);
@ -191,9 +191,9 @@ fp_device_virtual_listener_start (FpDeviceVirtualListener *self,
} }
gboolean gboolean
fp_device_virtual_listener_connection_close (FpDeviceVirtualListener *self) fpi_device_virtual_listener_connection_close (FpiDeviceVirtualListener *self)
{ {
g_return_val_if_fail (FP_IS_DEVICE_VIRTUAL_LISTENER (self), FALSE); g_return_val_if_fail (FPI_IS_DEVICE_VIRTUAL_LISTENER (self), FALSE);
if (!self->connection) if (!self->connection)
return FALSE; return FALSE;
@ -211,7 +211,7 @@ on_stream_read_cb (GObject *source_object,
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data; g_autoptr(GTask) task = user_data;
FpDeviceVirtualListener *self = g_task_get_source_object (task); FpiDeviceVirtualListener *self = g_task_get_source_object (task);
gboolean all; gboolean all;
gboolean success; gboolean success;
gsize bytes; gsize bytes;
@ -282,17 +282,17 @@ on_stream_read_cb (GObject *source_object,
} }
void void
fp_device_virtual_listener_read (FpDeviceVirtualListener *self, fpi_device_virtual_listener_read (FpiDeviceVirtualListener *self,
gboolean all, gboolean all,
void *buffer, void *buffer,
gsize count, gsize count,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
g_autoptr(GTask) task = NULL; g_autoptr(GTask) task = NULL;
GInputStream *stream; GInputStream *stream;
g_return_if_fail (FP_IS_DEVICE_VIRTUAL_LISTENER (self)); g_return_if_fail (FPI_IS_DEVICE_VIRTUAL_LISTENER (self));
task = g_task_new (self, self->cancellable, callback, user_data); task = g_task_new (self, self->cancellable, callback, user_data);
g_object_set_data (G_OBJECT (task), "all", GINT_TO_POINTER (all)); g_object_set_data (G_OBJECT (task), "all", GINT_TO_POINTER (all));
@ -324,9 +324,9 @@ fp_device_virtual_listener_read (FpDeviceVirtualListener *self,
} }
gsize gsize
fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *self, fpi_device_virtual_listener_read_finish (FpiDeviceVirtualListener *self,
GAsyncResult *result, GAsyncResult *result,
GError **error) GError **error)
{ {
g_return_val_if_fail (g_task_is_valid (result, self), 0); g_return_val_if_fail (g_task_is_valid (result, self), 0);
@ -334,10 +334,10 @@ fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *self,
} }
gboolean gboolean
fp_device_virtual_listener_write_sync (FpDeviceVirtualListener *self, fpi_device_virtual_listener_write_sync (FpiDeviceVirtualListener *self,
const char *buffer, const char *buffer,
gsize count, gsize count,
GError **error) GError **error)
{ {
if (!self->connection || g_io_stream_is_closed (G_IO_STREAM (self->connection))) if (!self->connection || g_io_stream_is_closed (G_IO_STREAM (self->connection)))
{ {

View file

@ -32,59 +32,59 @@
#define MAX_LINE_LEN 1024 #define MAX_LINE_LEN 1024
G_DECLARE_FINAL_TYPE (FpDeviceVirtualListener, fp_device_virtual_listener, FP, DEVICE_VIRTUAL_LISTENER, GSocketListener) G_DECLARE_FINAL_TYPE (FpiDeviceVirtualListener, fpi_device_virtual_listener, FPI, DEVICE_VIRTUAL_LISTENER, GSocketListener)
typedef void (*FpDeviceVirtualListenerConnectionCb) (FpDeviceVirtualListener *listener, typedef void (*FpiDeviceVirtualListenerConnectionCb) (FpiDeviceVirtualListener *listener,
gpointer user_data); gpointer user_data);
FpDeviceVirtualListener * fp_device_virtual_listener_new (void); FpiDeviceVirtualListener * fpi_device_virtual_listener_new (void);
gboolean fp_device_virtual_listener_start (FpDeviceVirtualListener *listener, gboolean fpi_device_virtual_listener_start (FpiDeviceVirtualListener *listener,
const char *address, const char *address,
GCancellable *cancellable, GCancellable *cancellable,
FpDeviceVirtualListenerConnectionCb cb, FpiDeviceVirtualListenerConnectionCb cb,
gpointer user_data, gpointer user_data,
GError **error); GError **error);
gboolean fp_device_virtual_listener_connection_close (FpDeviceVirtualListener *listener); gboolean fpi_device_virtual_listener_connection_close (FpiDeviceVirtualListener *listener);
void fp_device_virtual_listener_read (FpDeviceVirtualListener *listener, void fpi_device_virtual_listener_read (FpiDeviceVirtualListener *listener,
gboolean all, gboolean all,
void *buffer, void *buffer,
gsize count, gsize count,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gsize fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *listener, gsize fpi_device_virtual_listener_read_finish (FpiDeviceVirtualListener *listener,
GAsyncResult *result, GAsyncResult *result,
GError **error); GError **error);
gboolean fp_device_virtual_listener_write_sync (FpDeviceVirtualListener *self, gboolean fpi_device_virtual_listener_write_sync (FpiDeviceVirtualListener *self,
const char *buffer, const char *buffer,
gsize count, gsize count,
GError **error); GError **error);
struct _FpDeviceVirtualDevice struct _FpDeviceVirtualDevice
{ {
FpDevice parent; FpDevice parent;
FpDeviceVirtualListener *listener; FpiDeviceVirtualListener *listener;
GCancellable *cancellable; GCancellable *cancellable;
char recv_buf[MAX_LINE_LEN]; char recv_buf[MAX_LINE_LEN];
GPtrArray *pending_commands; GPtrArray *pending_commands;
GHashTable *prints_storage; GHashTable *prints_storage;
guint wait_command_id; guint wait_command_id;
guint sleep_timeout_id; guint sleep_timeout_id;
guint enroll_stages_passed; guint enroll_stages_passed;
gboolean match_reported; gboolean match_reported;
gboolean supports_cancellation; gboolean supports_cancellation;
gboolean injected_synthetic_cmd; gboolean injected_synthetic_cmd;
gboolean ignore_wait; gboolean ignore_wait;
gboolean keep_alive; gboolean keep_alive;
}; };
/* Not really final here, but we can do this to share the FpDeviceVirtualDevice /* Not really final here, but we can do this to share the FpDeviceVirtualDevice

View file

@ -217,10 +217,10 @@ process_cmds (FpDeviceVirtualDevice * self,
static void static void
write_key_to_listener (void *key, void *val, void *user_data) write_key_to_listener (void *key, void *val, void *user_data)
{ {
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (user_data); FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (user_data);
if (!fp_device_virtual_listener_write_sync (listener, key, strlen (key), NULL) || if (!fpi_device_virtual_listener_write_sync (listener, key, strlen (key), NULL) ||
!fp_device_virtual_listener_write_sync (listener, "\n", 1, NULL)) !fpi_device_virtual_listener_write_sync (listener, "\n", 1, NULL))
g_warning ("Error writing reply to LIST command"); g_warning ("Error writing reply to LIST command");
} }
@ -230,10 +230,10 @@ recv_instruction_cb (GObject *source_object,
gpointer user_data) gpointer user_data)
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object); FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
gsize bytes; gsize bytes;
bytes = fp_device_virtual_listener_read_finish (listener, res, &error); bytes = fpi_device_virtual_listener_read_finish (listener, res, &error);
fp_dbg ("Got instructions of length %ld", bytes); fp_dbg ("Got instructions of length %ld", bytes);
if (error) if (error)
@ -306,23 +306,23 @@ recv_instruction_cb (GObject *source_object,
} }
} }
fp_device_virtual_listener_connection_close (listener); fpi_device_virtual_listener_connection_close (listener);
} }
static void static void
recv_instruction (FpDeviceVirtualDevice *self) recv_instruction (FpDeviceVirtualDevice *self)
{ {
fp_device_virtual_listener_read (self->listener, fpi_device_virtual_listener_read (self->listener,
FALSE, FALSE,
self->recv_buf, self->recv_buf,
sizeof (self->recv_buf), sizeof (self->recv_buf),
recv_instruction_cb, recv_instruction_cb,
self); self);
} }
static void static void
on_listener_connected (FpDeviceVirtualListener *listener, on_listener_connected (FpiDeviceVirtualListener *listener,
gpointer user_data) gpointer user_data)
{ {
FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (user_data); FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (user_data);
@ -334,7 +334,7 @@ dev_init (FpDevice *dev)
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(GCancellable) cancellable = NULL; g_autoptr(GCancellable) cancellable = NULL;
g_autoptr(FpDeviceVirtualListener) listener = NULL; g_autoptr(FpiDeviceVirtualListener) listener = NULL;
FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (dev); FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (dev);
G_DEBUG_HERE (); G_DEBUG_HERE ();
@ -355,15 +355,15 @@ dev_init (FpDevice *dev)
return; return;
} }
listener = fp_device_virtual_listener_new (); listener = fpi_device_virtual_listener_new ();
cancellable = g_cancellable_new (); cancellable = g_cancellable_new ();
if (!fp_device_virtual_listener_start (listener, if (!fpi_device_virtual_listener_start (listener,
fpi_device_get_virtual_env (FP_DEVICE (self)), fpi_device_get_virtual_env (FP_DEVICE (self)),
cancellable, cancellable,
on_listener_connected, on_listener_connected,
self, self,
&error)) &error))
{ {
fpi_device_open_complete (dev, g_steal_pointer (&error)); fpi_device_open_complete (dev, g_steal_pointer (&error));
return; return;

View file

@ -36,14 +36,14 @@
struct _FpDeviceVirtualImage struct _FpDeviceVirtualImage
{ {
FpImageDevice parent; FpImageDevice parent;
FpDeviceVirtualListener *listener; FpiDeviceVirtualListener *listener;
GCancellable *cancellable; GCancellable *cancellable;
gboolean automatic_finger; gboolean automatic_finger;
FpImage *recv_img; FpImage *recv_img;
gint recv_img_hdr[2]; gint recv_img_hdr[2];
}; };
G_DECLARE_FINAL_TYPE (FpDeviceVirtualImage, fpi_device_virtual_image, FPI, DEVICE_VIRTUAL_IMAGE, FpImageDevice) G_DECLARE_FINAL_TYPE (FpDeviceVirtualImage, fpi_device_virtual_image, FPI, DEVICE_VIRTUAL_IMAGE, FpImageDevice)
@ -57,12 +57,12 @@ recv_image_img_recv_cb (GObject *source_object,
gpointer user_data) gpointer user_data)
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object); FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
FpDeviceVirtualImage *self; FpDeviceVirtualImage *self;
FpImageDevice *device; FpImageDevice *device;
gsize bytes; gsize bytes;
bytes = fp_device_virtual_listener_read_finish (listener, res, &error); bytes = fpi_device_virtual_listener_read_finish (listener, res, &error);
if (!bytes || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || if (!bytes || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED)) g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED))
@ -88,10 +88,10 @@ recv_image_hdr_recv_cb (GObject *source_object,
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
FpDeviceVirtualImage *self; FpDeviceVirtualImage *self;
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object); FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
gsize bytes; gsize bytes;
bytes = fp_device_virtual_listener_read_finish (listener, res, &error); bytes = fpi_device_virtual_listener_read_finish (listener, res, &error);
if (error) if (error)
{ {
@ -111,7 +111,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
if (self->recv_img_hdr[0] > 5000 || self->recv_img_hdr[1] > 5000) if (self->recv_img_hdr[0] > 5000 || self->recv_img_hdr[1] > 5000)
{ {
g_warning ("Image header suggests an unrealistically large image, disconnecting client."); g_warning ("Image header suggests an unrealistically large image, disconnecting client.");
fp_device_virtual_listener_connection_close (listener); fpi_device_virtual_listener_connection_close (listener);
} }
if (self->recv_img_hdr[0] < 0 || self->recv_img_hdr[1] < 0) if (self->recv_img_hdr[0] < 0 || self->recv_img_hdr[1] < 0)
@ -147,7 +147,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
default: default:
/* disconnect client, it didn't play fair */ /* disconnect client, it didn't play fair */
fp_device_virtual_listener_connection_close (listener); fpi_device_virtual_listener_connection_close (listener);
} }
/* And, listen for more images from the same client. */ /* And, listen for more images from the same client. */
@ -157,28 +157,28 @@ recv_image_hdr_recv_cb (GObject *source_object,
self->recv_img = fp_image_new (self->recv_img_hdr[0], self->recv_img_hdr[1]); self->recv_img = fp_image_new (self->recv_img_hdr[0], self->recv_img_hdr[1]);
g_debug ("image data: %p", self->recv_img->data); g_debug ("image data: %p", self->recv_img->data);
fp_device_virtual_listener_read (listener, fpi_device_virtual_listener_read (listener,
TRUE, TRUE,
(guint8 *) self->recv_img->data, (guint8 *) self->recv_img->data,
self->recv_img->width * self->recv_img->height, self->recv_img->width * self->recv_img->height,
recv_image_img_recv_cb, recv_image_img_recv_cb,
self); self);
} }
static void static void
recv_image (FpDeviceVirtualImage *self) recv_image (FpDeviceVirtualImage *self)
{ {
fp_device_virtual_listener_read (self->listener, fpi_device_virtual_listener_read (self->listener,
TRUE, TRUE,
self->recv_img_hdr, self->recv_img_hdr,
sizeof (self->recv_img_hdr), sizeof (self->recv_img_hdr),
recv_image_hdr_recv_cb, recv_image_hdr_recv_cb,
self); self);
} }
static void static void
on_listener_connected (FpDeviceVirtualListener *listener, on_listener_connected (FpiDeviceVirtualListener *listener,
gpointer user_data) gpointer user_data)
{ {
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (user_data); FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
FpiImageDeviceState state; FpiImageDeviceState state;
@ -206,21 +206,21 @@ static void
dev_init (FpImageDevice *dev) dev_init (FpImageDevice *dev)
{ {
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(FpDeviceVirtualListener) listener = NULL; g_autoptr(FpiDeviceVirtualListener) listener = NULL;
g_autoptr(GCancellable) cancellable = NULL; g_autoptr(GCancellable) cancellable = NULL;
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev); FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev);
G_DEBUG_HERE (); G_DEBUG_HERE ();
listener = fp_device_virtual_listener_new (); listener = fpi_device_virtual_listener_new ();
cancellable = g_cancellable_new (); cancellable = g_cancellable_new ();
if (!fp_device_virtual_listener_start (listener, if (!fpi_device_virtual_listener_start (listener,
fpi_device_get_virtual_env (FP_DEVICE (self)), fpi_device_get_virtual_env (FP_DEVICE (self)),
cancellable, cancellable,
on_listener_connected, on_listener_connected,
self, self,
&error)) &error))
{ {
fpi_image_device_open_complete (dev, g_steal_pointer (&error)); fpi_image_device_open_complete (dev, g_steal_pointer (&error));
return; return;