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:
parent
e4a297887b
commit
8fd1fcbe49
4 changed files with 143 additions and 143 deletions
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include "virtual-device-private.h"
|
||||
|
||||
struct _FpDeviceVirtualListener
|
||||
struct _FpiDeviceVirtualListener
|
||||
{
|
||||
GSocketListener parent_instance;
|
||||
|
||||
|
@ -36,27 +36,27 @@ struct _FpDeviceVirtualListener
|
|||
GCancellable *cancellable;
|
||||
guint cancellable_id;
|
||||
|
||||
FpDeviceVirtualListenerConnectionCb ready_cb;
|
||||
FpiDeviceVirtualListenerConnectionCb ready_cb;
|
||||
gpointer ready_cb_data;
|
||||
|
||||
gint socket_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 *
|
||||
fp_device_virtual_listener_new (void)
|
||||
FpiDeviceVirtualListener *
|
||||
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
|
||||
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)
|
||||
{
|
||||
|
@ -70,19 +70,19 @@ fp_device_virtual_listener_dispose (GObject *object)
|
|||
|
||||
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
|
||||
fp_device_virtual_listener_class_init (FpDeviceVirtualListenerClass *klass)
|
||||
fpi_device_virtual_listener_class_init (FpiDeviceVirtualListenerClass *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
|
||||
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)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDeviceVirtualListener *self = user_data;
|
||||
FpiDeviceVirtualListener *self = user_data;
|
||||
GSocketConnection *connection;
|
||||
|
||||
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
|
||||
start_listen (FpDeviceVirtualListener *self)
|
||||
start_listen (FpiDeviceVirtualListener *self)
|
||||
{
|
||||
g_socket_listener_accept_async (G_SOCKET_LISTENER (self),
|
||||
self->cancellable,
|
||||
|
@ -133,26 +133,26 @@ start_listen (FpDeviceVirtualListener *self)
|
|||
|
||||
static void
|
||||
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_clear_object (&self->cancellable);
|
||||
self->ready_cb = NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
fp_device_virtual_listener_start (FpDeviceVirtualListener *self,
|
||||
fpi_device_virtual_listener_start (FpiDeviceVirtualListener *self,
|
||||
const char *address,
|
||||
GCancellable *cancellable,
|
||||
FpDeviceVirtualListenerConnectionCb cb,
|
||||
FpiDeviceVirtualListenerConnectionCb cb,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GSocketAddress) addr = NULL;
|
||||
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 (self->ready_cb == NULL, FALSE);
|
||||
|
||||
|
@ -191,9 +191,9 @@ fp_device_virtual_listener_start (FpDeviceVirtualListener *self,
|
|||
}
|
||||
|
||||
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)
|
||||
return FALSE;
|
||||
|
@ -211,7 +211,7 @@ on_stream_read_cb (GObject *source_object,
|
|||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
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 success;
|
||||
gsize bytes;
|
||||
|
@ -282,7 +282,7 @@ on_stream_read_cb (GObject *source_object,
|
|||
}
|
||||
|
||||
void
|
||||
fp_device_virtual_listener_read (FpDeviceVirtualListener *self,
|
||||
fpi_device_virtual_listener_read (FpiDeviceVirtualListener *self,
|
||||
gboolean all,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
|
@ -292,7 +292,7 @@ fp_device_virtual_listener_read (FpDeviceVirtualListener *self,
|
|||
g_autoptr(GTask) task = NULL;
|
||||
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);
|
||||
g_object_set_data (G_OBJECT (task), "all", GINT_TO_POINTER (all));
|
||||
|
@ -324,7 +324,7 @@ fp_device_virtual_listener_read (FpDeviceVirtualListener *self,
|
|||
}
|
||||
|
||||
gsize
|
||||
fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *self,
|
||||
fpi_device_virtual_listener_read_finish (FpiDeviceVirtualListener *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
|
@ -334,7 +334,7 @@ fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *self,
|
|||
}
|
||||
|
||||
gboolean
|
||||
fp_device_virtual_listener_write_sync (FpDeviceVirtualListener *self,
|
||||
fpi_device_virtual_listener_write_sync (FpiDeviceVirtualListener *self,
|
||||
const char *buffer,
|
||||
gsize count,
|
||||
GError **error)
|
||||
|
|
|
@ -32,33 +32,33 @@
|
|||
|
||||
#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);
|
||||
|
||||
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,
|
||||
GCancellable *cancellable,
|
||||
FpDeviceVirtualListenerConnectionCb cb,
|
||||
FpiDeviceVirtualListenerConnectionCb cb,
|
||||
gpointer user_data,
|
||||
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,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gsize fp_device_virtual_listener_read_finish (FpDeviceVirtualListener *listener,
|
||||
gsize fpi_device_virtual_listener_read_finish (FpiDeviceVirtualListener *listener,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
gboolean fp_device_virtual_listener_write_sync (FpDeviceVirtualListener *self,
|
||||
gboolean fpi_device_virtual_listener_write_sync (FpiDeviceVirtualListener *self,
|
||||
const char *buffer,
|
||||
gsize count,
|
||||
GError **error);
|
||||
|
@ -68,7 +68,7 @@ struct _FpDeviceVirtualDevice
|
|||
{
|
||||
FpDevice parent;
|
||||
|
||||
FpDeviceVirtualListener *listener;
|
||||
FpiDeviceVirtualListener *listener;
|
||||
GCancellable *cancellable;
|
||||
|
||||
char recv_buf[MAX_LINE_LEN];
|
||||
|
|
|
@ -217,10 +217,10 @@ process_cmds (FpDeviceVirtualDevice * self,
|
|||
static void
|
||||
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) ||
|
||||
!fp_device_virtual_listener_write_sync (listener, "\n", 1, NULL))
|
||||
if (!fpi_device_virtual_listener_write_sync (listener, key, strlen (key), NULL) ||
|
||||
!fpi_device_virtual_listener_write_sync (listener, "\n", 1, NULL))
|
||||
g_warning ("Error writing reply to LIST command");
|
||||
}
|
||||
|
||||
|
@ -230,10 +230,10 @@ recv_instruction_cb (GObject *source_object,
|
|||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
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);
|
||||
|
||||
if (error)
|
||||
|
@ -306,13 +306,13 @@ recv_instruction_cb (GObject *source_object,
|
|||
}
|
||||
}
|
||||
|
||||
fp_device_virtual_listener_connection_close (listener);
|
||||
fpi_device_virtual_listener_connection_close (listener);
|
||||
}
|
||||
|
||||
static void
|
||||
recv_instruction (FpDeviceVirtualDevice *self)
|
||||
{
|
||||
fp_device_virtual_listener_read (self->listener,
|
||||
fpi_device_virtual_listener_read (self->listener,
|
||||
FALSE,
|
||||
self->recv_buf,
|
||||
sizeof (self->recv_buf),
|
||||
|
@ -321,7 +321,7 @@ recv_instruction (FpDeviceVirtualDevice *self)
|
|||
}
|
||||
|
||||
static void
|
||||
on_listener_connected (FpDeviceVirtualListener *listener,
|
||||
on_listener_connected (FpiDeviceVirtualListener *listener,
|
||||
gpointer 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(GCancellable) cancellable = NULL;
|
||||
g_autoptr(FpDeviceVirtualListener) listener = NULL;
|
||||
g_autoptr(FpiDeviceVirtualListener) listener = NULL;
|
||||
FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (dev);
|
||||
|
||||
G_DEBUG_HERE ();
|
||||
|
@ -355,10 +355,10 @@ dev_init (FpDevice *dev)
|
|||
return;
|
||||
}
|
||||
|
||||
listener = fp_device_virtual_listener_new ();
|
||||
listener = fpi_device_virtual_listener_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)),
|
||||
cancellable,
|
||||
on_listener_connected,
|
||||
|
|
|
@ -38,7 +38,7 @@ struct _FpDeviceVirtualImage
|
|||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
FpDeviceVirtualListener *listener;
|
||||
FpiDeviceVirtualListener *listener;
|
||||
GCancellable *cancellable;
|
||||
|
||||
gboolean automatic_finger;
|
||||
|
@ -57,12 +57,12 @@ recv_image_img_recv_cb (GObject *source_object,
|
|||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
FpDeviceVirtualImage *self;
|
||||
FpImageDevice *device;
|
||||
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) ||
|
||||
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;
|
||||
FpDeviceVirtualImage *self;
|
||||
FpDeviceVirtualListener *listener = FP_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
FpiDeviceVirtualListener *listener = FPI_DEVICE_VIRTUAL_LISTENER (source_object);
|
||||
gsize bytes;
|
||||
|
||||
bytes = fp_device_virtual_listener_read_finish (listener, res, &error);
|
||||
bytes = fpi_device_virtual_listener_read_finish (listener, res, &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)
|
||||
{
|
||||
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)
|
||||
|
@ -147,7 +147,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
|
|||
|
||||
default:
|
||||
/* 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. */
|
||||
|
@ -157,7 +157,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
|
|||
|
||||
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);
|
||||
fp_device_virtual_listener_read (listener,
|
||||
fpi_device_virtual_listener_read (listener,
|
||||
TRUE,
|
||||
(guint8 *) self->recv_img->data,
|
||||
self->recv_img->width * self->recv_img->height,
|
||||
|
@ -168,7 +168,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
|
|||
static void
|
||||
recv_image (FpDeviceVirtualImage *self)
|
||||
{
|
||||
fp_device_virtual_listener_read (self->listener,
|
||||
fpi_device_virtual_listener_read (self->listener,
|
||||
TRUE,
|
||||
self->recv_img_hdr,
|
||||
sizeof (self->recv_img_hdr),
|
||||
|
@ -177,7 +177,7 @@ recv_image (FpDeviceVirtualImage *self)
|
|||
}
|
||||
|
||||
static void
|
||||
on_listener_connected (FpDeviceVirtualListener *listener,
|
||||
on_listener_connected (FpiDeviceVirtualListener *listener,
|
||||
gpointer user_data)
|
||||
{
|
||||
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
|
||||
|
@ -206,16 +206,16 @@ static void
|
|||
dev_init (FpImageDevice *dev)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(FpDeviceVirtualListener) listener = NULL;
|
||||
g_autoptr(FpiDeviceVirtualListener) listener = NULL;
|
||||
g_autoptr(GCancellable) cancellable = NULL;
|
||||
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev);
|
||||
|
||||
G_DEBUG_HERE ();
|
||||
|
||||
listener = fp_device_virtual_listener_new ();
|
||||
listener = fpi_device_virtual_listener_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)),
|
||||
cancellable,
|
||||
on_listener_connected,
|
||||
|
|
Loading…
Reference in a new issue