From 16a206247a922d47cd7b4cf610c98ff47b92aad7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 15 Jan 2021 15:25:52 +0100 Subject: [PATCH] main: Simplify setting callback func and user_data Set those in the drivers functions, rather than in each driver implementation. --- src/drivers.h | 14 +++++---- src/drv-fake-compass.c | 14 ++------- src/drv-fake-light.c | 14 ++------- src/drv-hwmon-light.c | 11 ++------ src/drv-iio-buffer-accel.c | 55 ++++++++++++++++-------------------- src/drv-iio-buffer-compass.c | 49 +++++++++++++++----------------- src/drv-iio-buffer-light.c | 49 +++++++++++++++----------------- src/drv-iio-poll-accel.c | 10 ++----- src/drv-iio-poll-light.c | 11 ++------ src/drv-iio-poll-proximity.c | 10 ++----- src/drv-input-accel.c | 10 ++----- 11 files changed, 92 insertions(+), 155 deletions(-) diff --git a/src/drivers.h b/src/drivers.h index 198c564..776f25f 100644 --- a/src/drivers.h +++ b/src/drivers.h @@ -79,9 +79,7 @@ struct SensorDriver { DriverType type; gboolean (*discover) (GUdevDevice *device); - SensorDevice * (*open) (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data); + SensorDevice * (*open) (GUdevDevice *device); void (*set_polling) (SensorDevice *device, gboolean state); void (*close) (SensorDevice *device); @@ -89,7 +87,11 @@ struct SensorDriver { struct SensorDevice { struct SensorDriver *drv; - gpointer priv; + gpointer priv; + + /* Callback function and data as pass to driver_open() */ + ReadingsUpdateFunc callback_func; + gpointer user_data; }; static inline gboolean @@ -122,10 +124,12 @@ driver_open (SensorDriver *driver, g_return_val_if_fail (device, NULL); g_return_val_if_fail (callback_func, NULL); - sensor_device = driver->open (device, callback_func, user_data); + sensor_device = driver->open (device); if (!sensor_device) return NULL; sensor_device->drv = driver; + sensor_device->callback_func = callback_func; + sensor_device->user_data = user_data; return sensor_device; } diff --git a/src/drv-fake-compass.c b/src/drv-fake-compass.c index a11d397..099b09b 100644 --- a/src/drv-fake-compass.c +++ b/src/drv-fake-compass.c @@ -17,9 +17,6 @@ #include typedef struct DrvData { - ReadingsUpdateFunc callback_func; - gpointer user_data; - guint timeout_id; } DrvData; @@ -44,7 +41,6 @@ static gboolean compass_changed (gpointer user_data) { SensorDevice *sensor_device = user_data; - DrvData *drv_data = (DrvData *) sensor_device->priv; static gdouble heading = 0; CompassReadings readings; @@ -54,7 +50,7 @@ compass_changed (gpointer user_data) g_debug ("Changed heading to %f", heading); readings.heading = heading; - drv_data->callback_func (&fake_compass, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&fake_compass, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } @@ -72,18 +68,12 @@ first_values (gpointer user_data) } static SensorDevice * -fake_compass_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +fake_compass_open (GUdevDevice *device) { SensorDevice *sensor_device; - DrvData *drv_data; sensor_device = g_new0 (SensorDevice, 1); sensor_device->priv = g_new0 (DrvData, 1); - drv_data = (DrvData *) sensor_device->priv; - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; return sensor_device; } diff --git a/src/drv-fake-light.c b/src/drv-fake-light.c index 23d500a..f4f286c 100644 --- a/src/drv-fake-light.c +++ b/src/drv-fake-light.c @@ -17,9 +17,6 @@ #include typedef struct DrvData { - ReadingsUpdateFunc callback_func; - gpointer user_data; - guint timeout_id; } DrvData; @@ -44,7 +41,6 @@ static gboolean light_changed (gpointer user_data) { SensorDevice *sensor_device = user_data; - DrvData *drv_data = (DrvData *) sensor_device->priv; static gdouble level = -1.0; LightReadings readings; @@ -54,7 +50,7 @@ light_changed (gpointer user_data) level += 1.0; readings.level = level; readings.uses_lux = TRUE; - drv_data->callback_func (&fake_light, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&fake_light, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } @@ -72,18 +68,12 @@ first_values (gpointer user_data) } static SensorDevice * -fake_light_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +fake_light_open (GUdevDevice *device) { SensorDevice *sensor_device; - DrvData *drv_data; sensor_device = g_new0 (SensorDevice, 1); sensor_device->priv = g_new0 (DrvData, 1); - drv_data = (DrvData *) sensor_device->priv; - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; return sensor_device; } diff --git a/src/drv-hwmon-light.c b/src/drv-hwmon-light.c index 923698c..852b613 100644 --- a/src/drv-hwmon-light.c +++ b/src/drv-hwmon-light.c @@ -18,9 +18,6 @@ #define MAX_LIGHT_LEVEL 255 typedef struct DrvData { - ReadingsUpdateFunc callback_func; - gpointer user_data; - GUdevDevice *device; guint timeout_id; } DrvData; @@ -53,15 +50,13 @@ light_changed (gpointer user_data) readings.level = level; readings.uses_lux = FALSE; - drv_data->callback_func (&hwmon_light, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&hwmon_light, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } static SensorDevice * -hwmon_light_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +hwmon_light_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -69,8 +64,6 @@ hwmon_light_open (GUdevDevice *device, sensor_device = g_new0 (SensorDevice, 1); sensor_device->priv = g_new0 (DrvData, 1); drv_data = (DrvData *) sensor_device->priv; - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; drv_data->device = g_object_ref (device); diff --git a/src/drv-iio-buffer-accel.c b/src/drv-iio-buffer-accel.c index 5a36e35..5cd0a1b 100644 --- a/src/drv-iio-buffer-accel.c +++ b/src/drv-iio-buffer-accel.c @@ -17,8 +17,6 @@ typedef struct { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevDevice *dev; const char *dev_path; @@ -30,8 +28,9 @@ typedef struct { } DrvData; static int -process_scan (IIOSensorData data, DrvData *or_data) +process_scan (IIOSensorData data, SensorDevice *sensor_device) { + DrvData *drv_data = (DrvData *) sensor_device->priv; int i; int accel_x, accel_y, accel_z; gboolean present_x, present_y, present_z; @@ -40,25 +39,25 @@ process_scan (IIOSensorData data, DrvData *or_data) AccelScale scale; if (data.read_size < 0) { - g_warning ("Couldn't read from device '%s': %s", or_data->name, g_strerror (errno)); + g_warning ("Couldn't read from device '%s': %s", drv_data->name, g_strerror (errno)); return 0; } /* Rather than read everything: - * for (i = 0; i < data.read_size / or_data->scan_size; i++)... + * for (i = 0; i < data.read_size / drv_data->scan_size; i++)... * Just read the last one */ - i = (data.read_size / or_data->buffer_data->scan_size) - 1; + i = (data.read_size / drv_data->buffer_data->scan_size) - 1; if (i < 0) { - g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", or_data->name, - (int) data.read_size, or_data->buffer_data->scan_size); + g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", drv_data->name, + (int) data.read_size, drv_data->buffer_data->scan_size); return 0; } - process_scan_1(data.data + or_data->buffer_data->scan_size*i, or_data->buffer_data, "in_accel_x", &accel_x, &scale.x, &present_x); - process_scan_1(data.data + or_data->buffer_data->scan_size*i, or_data->buffer_data, "in_accel_y", &accel_y, &scale.y, &present_y); - process_scan_1(data.data + or_data->buffer_data->scan_size*i, or_data->buffer_data, "in_accel_z", &accel_z, &scale.z, &present_z); + process_scan_1(data.data + drv_data->buffer_data->scan_size*i, drv_data->buffer_data, "in_accel_x", &accel_x, &scale.x, &present_x); + process_scan_1(data.data + drv_data->buffer_data->scan_size*i, drv_data->buffer_data, "in_accel_y", &accel_y, &scale.y, &present_y); + process_scan_1(data.data + drv_data->buffer_data->scan_size*i, drv_data->buffer_data, "in_accel_z", &accel_z, &scale.z, &present_z); - g_debug ("Accel read from IIO on '%s': %d, %d, %d (scale %lf,%lf,%lf)", or_data->name, + g_debug ("Accel read from IIO on '%s': %d, %d, %d (scale %lf,%lf,%lf)", drv_data->name, accel_x, accel_y, accel_z, scale.x, scale.y, scale.z); @@ -66,7 +65,7 @@ process_scan (IIOSensorData data, DrvData *or_data) tmp.y = accel_y; tmp.z = accel_z; - if (!apply_mount_matrix (or_data->mount_matrix, &tmp)) + if (!apply_mount_matrix (drv_data->mount_matrix, &tmp)) g_warning ("Could not apply mount matrix"); //FIXME report errors @@ -74,35 +73,36 @@ process_scan (IIOSensorData data, DrvData *or_data) readings.accel_y = tmp.y; readings.accel_z = tmp.z; copy_accel_scale (&readings.scale, scale); - or_data->callback_func (&iio_buffer_accel, (gpointer) &readings, or_data->user_data); + sensor_device->callback_func (&iio_buffer_accel, (gpointer) &readings, sensor_device->user_data); return 1; } static void -prepare_output (DrvData *or_data, - const char *dev_dir_name, - const char *trigger_name) +prepare_output (SensorDevice *sensor_device, + const char *dev_dir_name, + const char *trigger_name) { + DrvData *drv_data = (DrvData *) sensor_device->priv; IIOSensorData data; int fp, buf_len = 127; - data.data = g_malloc(or_data->buffer_data->scan_size * buf_len); + data.data = g_malloc0(drv_data->buffer_data->scan_size * buf_len); /* Attempt to open non blocking to access dev */ - fp = open (or_data->dev_path, O_RDONLY | O_NONBLOCK); + fp = open (drv_data->dev_path, O_RDONLY | O_NONBLOCK); if (fp == -1) { /* If it isn't there make the node */ - g_warning ("Failed to open '%s' at %s: %s", or_data->name, or_data->dev_path, g_strerror (errno)); + g_warning ("Failed to open '%s' at %s: %s", drv_data->name, drv_data->dev_path, g_strerror (errno)); goto bail; } /* Actually read the data */ - data.read_size = read (fp, data.data, buf_len * or_data->buffer_data->scan_size); + data.read_size = read (fp, data.data, buf_len * drv_data->buffer_data->scan_size); if (data.read_size == -1 && errno == EAGAIN) { - g_debug ("No new data available on '%s'", or_data->name); + g_debug ("No new data available on '%s'", drv_data->name); } else { - process_scan(data, or_data); + process_scan (data, sensor_device); } close(fp); @@ -154,7 +154,7 @@ read_orientation (gpointer user_data) SensorDevice *sensor_device = user_data; DrvData *drv_data = (DrvData *) sensor_device->priv; - prepare_output (drv_data, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); + prepare_output (sensor_device, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); return G_SOURCE_CONTINUE; } @@ -200,9 +200,7 @@ iio_buffer_accel_set_polling (SensorDevice *sensor_device, } static SensorDevice * -iio_buffer_accel_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_buffer_accel_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -230,9 +228,6 @@ iio_buffer_accel_open (GUdevDevice *device, if (!drv_data->name) drv_data->name = g_udev_device_get_name (device); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; - return sensor_device; } diff --git a/src/drv-iio-buffer-compass.c b/src/drv-iio-buffer-compass.c index 4574707..9a57a73 100644 --- a/src/drv-iio-buffer-compass.c +++ b/src/drv-iio-buffer-compass.c @@ -17,8 +17,6 @@ typedef struct { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevDevice *dev; const char *dev_path; @@ -28,8 +26,9 @@ typedef struct { } DrvData; static int -process_scan (IIOSensorData data, DrvData *or_data) +process_scan (IIOSensorData data, SensorDevice *sensor_device) { + DrvData *drv_data = (DrvData *) sensor_device->priv; int i; int raw_heading; const char *channel_name = "in_rot_from_north_magnetic_tilt_comp"; @@ -38,55 +37,56 @@ process_scan (IIOSensorData data, DrvData *or_data) CompassReadings readings; if (data.read_size < 0) { - g_warning ("Couldn't read from device '%s': %s", or_data->name, g_strerror (errno)); + g_warning ("Couldn't read from device '%s': %s", drv_data->name, g_strerror (errno)); return 0; } /* Rather than read everything: - * for (i = 0; i < data.read_size / or_data->scan_size; i++)... + * for (i = 0; i < data.read_size / drv_data->scan_size; i++)... * Just read the last one */ - i = (data.read_size / or_data->buffer_data->scan_size) - 1; + i = (data.read_size / drv_data->buffer_data->scan_size) - 1; if (i < 0) { - g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", or_data->name, - (int) data.read_size, or_data->buffer_data->scan_size); + g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", drv_data->name, + (int) data.read_size, drv_data->buffer_data->scan_size); return 0; } - process_scan_1 (data.data + or_data->buffer_data->scan_size*i, or_data->buffer_data, channel_name, &raw_heading, &scale, &present_level); + process_scan_1 (data.data + drv_data->buffer_data->scan_size*i, drv_data->buffer_data, channel_name, &raw_heading, &scale, &present_level); readings.heading = raw_heading * scale; - g_debug ("Heading read from IIO on '%s': %f (%d times %lf scale)", or_data->name, readings.heading, raw_heading, scale); + g_debug ("Heading read from IIO on '%s': %f (%d times %lf scale)", drv_data->name, readings.heading, raw_heading, scale); //FIXME report errors - or_data->callback_func (&iio_buffer_compass, (gpointer) &readings, or_data->user_data); + sensor_device->callback_func (&iio_buffer_compass, (gpointer) &readings, sensor_device->user_data); return 1; } static void -prepare_output (DrvData *or_data, - const char *dev_dir_name, - const char *trigger_name) +prepare_output (SensorDevice *sensor_device, + const char *dev_dir_name, + const char *trigger_name) { + DrvData *drv_data = (DrvData *) sensor_device->priv; IIOSensorData data; int fp, buf_len = 127; - data.data = g_malloc(or_data->buffer_data->scan_size * buf_len); + data.data = g_malloc (drv_data->buffer_data->scan_size * buf_len); /* Attempt to open non blocking to access dev */ - fp = open (or_data->dev_path, O_RDONLY | O_NONBLOCK); + fp = open (drv_data->dev_path, O_RDONLY | O_NONBLOCK); if (fp == -1) { /* If it isn't there make the node */ - g_warning ("Failed to open '%s' at %s : %s", or_data->name, or_data->dev_path, g_strerror (errno)); + g_warning ("Failed to open '%s' at %s : %s", drv_data->name, drv_data->dev_path, g_strerror (errno)); goto bail; } /* Actually read the data */ - data.read_size = read (fp, data.data, buf_len * or_data->buffer_data->scan_size); + data.read_size = read (fp, data.data, buf_len * drv_data->buffer_data->scan_size); if (data.read_size == -1 && errno == EAGAIN) { - g_debug ("No new data available on '%s'", or_data->name); + g_debug ("No new data available on '%s'", drv_data->name); } else { - process_scan(data, or_data); + process_scan (data, sensor_device); } close(fp); @@ -137,7 +137,7 @@ read_heading (gpointer user_data) SensorDevice *sensor_device = user_data; DrvData *drv_data = (DrvData *) sensor_device->priv; - prepare_output (drv_data, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); + prepare_output (sensor_device, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); return G_SOURCE_CONTINUE; } @@ -149,9 +149,7 @@ iio_buffer_compass_discover (GUdevDevice *device) } static SensorDevice * -iio_buffer_compass_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_buffer_compass_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -177,9 +175,6 @@ iio_buffer_compass_open (GUdevDevice *device, if (!drv_data->name) drv_data->name = g_udev_device_get_name (device); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; - return sensor_device; } diff --git a/src/drv-iio-buffer-light.c b/src/drv-iio-buffer-light.c index 5af7824..c3b8992 100644 --- a/src/drv-iio-buffer-light.c +++ b/src/drv-iio-buffer-light.c @@ -17,8 +17,6 @@ typedef struct { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevDevice *dev; const char *dev_path; @@ -28,8 +26,9 @@ typedef struct { } DrvData; static int -process_scan (IIOSensorData data, DrvData *or_data) +process_scan (IIOSensorData data, SensorDevice *sensor_device) { + DrvData *drv_data = (DrvData *) sensor_device->priv; int i; int level = 0; gdouble scale; @@ -37,23 +36,23 @@ process_scan (IIOSensorData data, DrvData *or_data) LightReadings readings; if (data.read_size < 0) { - g_warning ("Couldn't read from device '%s': %s", or_data->name, g_strerror (errno)); + g_warning ("Couldn't read from device '%s': %s", drv_data->name, g_strerror (errno)); return 0; } /* Rather than read everything: - * for (i = 0; i < data.read_size / or_data->scan_size; i++)... + * for (i = 0; i < data.read_size / drv_data->scan_size; i++)... * Just read the last one */ - i = (data.read_size / or_data->buffer_data->scan_size) - 1; + i = (data.read_size / drv_data->buffer_data->scan_size) - 1; if (i < 0) { - g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", or_data->name, - (int) data.read_size, or_data->buffer_data->scan_size); + g_debug ("Not enough data to read from '%s' (read_size: %d scan_size: %d)", drv_data->name, + (int) data.read_size, drv_data->buffer_data->scan_size); return 0; } - process_scan_1(data.data + or_data->buffer_data->scan_size*i, or_data->buffer_data, "in_intensity_both", &level, &scale, &present_level); + process_scan_1(data.data + drv_data->buffer_data->scan_size*i, drv_data->buffer_data, "in_intensity_both", &level, &scale, &present_level); - g_debug ("Light read from IIO on '%s': %d (scale %lf) = %lf", or_data->name, level, scale, level * scale); + g_debug ("Light read from IIO on '%s': %d (scale %lf) = %lf", drv_data->name, level, scale, level * scale); readings.level = level * scale; /* Even though the IIO kernel API declares in_intensity* values as unitless, @@ -63,35 +62,36 @@ process_scan (IIOSensorData data, DrvData *or_data) readings.uses_lux = TRUE; //FIXME report errors - or_data->callback_func (&iio_buffer_light, (gpointer) &readings, or_data->user_data); + sensor_device->callback_func (&iio_buffer_light, (gpointer) &readings, sensor_device->user_data); return 1; } static void -prepare_output (DrvData *or_data, - const char *dev_dir_name, - const char *trigger_name) +prepare_output (SensorDevice *sensor_device, + const char *dev_dir_name, + const char *trigger_name) { + DrvData *drv_data = (DrvData *) sensor_device->priv; IIOSensorData data; int fp, buf_len = 127; - data.data = g_malloc(or_data->buffer_data->scan_size * buf_len); + data.data = g_malloc(drv_data->buffer_data->scan_size * buf_len); /* Attempt to open non blocking to access dev */ - fp = open (or_data->dev_path, O_RDONLY | O_NONBLOCK); + fp = open (drv_data->dev_path, O_RDONLY | O_NONBLOCK); if (fp == -1) { /* If it isn't there make the node */ - g_warning ("Failed to open '%s' at %s : %s", or_data->name, or_data->dev_path, g_strerror (errno)); + g_warning ("Failed to open '%s' at %s : %s", drv_data->name, drv_data->dev_path, g_strerror (errno)); goto bail; } /* Actually read the data */ - data.read_size = read (fp, data.data, buf_len * or_data->buffer_data->scan_size); + data.read_size = read (fp, data.data, buf_len * drv_data->buffer_data->scan_size); if (data.read_size == -1 && errno == EAGAIN) { - g_debug ("No new data available on '%s'", or_data->name); + g_debug ("No new data available on '%s'", drv_data->name); } else { - process_scan(data, or_data); + process_scan (data, sensor_device); } close(fp); @@ -142,7 +142,7 @@ read_light (gpointer user_data) SensorDevice *sensor_device = user_data; DrvData *drv_data = (DrvData *) sensor_device->priv; - prepare_output (drv_data, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); + prepare_output (sensor_device, drv_data->buffer_data->dev_dir_name, drv_data->buffer_data->trigger_name); return G_SOURCE_CONTINUE; } @@ -176,9 +176,7 @@ iio_buffer_light_set_polling (SensorDevice *sensor_device, } static SensorDevice * -iio_buffer_light_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_buffer_light_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -203,9 +201,6 @@ iio_buffer_light_open (GUdevDevice *device, if (!drv_data->name) drv_data->name = g_udev_device_get_name (device); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; - return sensor_device; } diff --git a/src/drv-iio-poll-accel.c b/src/drv-iio-poll-accel.c index 1d93e37..6c1bb75 100644 --- a/src/drv-iio-poll-accel.c +++ b/src/drv-iio-poll-accel.c @@ -19,8 +19,6 @@ typedef struct DrvData { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevDevice *dev; const char *name; AccelVec3 *mount_matrix; @@ -58,7 +56,7 @@ poll_orientation (gpointer user_data) readings.accel_y = tmp.y; readings.accel_z = tmp.z; - drv_data->callback_func (&iio_poll_accel, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&iio_poll_accel, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } @@ -98,9 +96,7 @@ iio_poll_accel_set_polling (SensorDevice *sensor_device, } static SensorDevice * -iio_poll_accel_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_poll_accel_open (GUdevDevice *device) { SensorDevice *sensor_device; @@ -115,8 +111,6 @@ iio_poll_accel_open (GUdevDevice *device, drv_data->name = g_udev_device_get_sysfs_attr (device, "name"); drv_data->mount_matrix = setup_mount_matrix (device); drv_data->location = setup_accel_location (device); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; if (!get_accel_scale (device, &drv_data->scale)) reset_accel_scale (&drv_data->scale); diff --git a/src/drv-iio-poll-light.c b/src/drv-iio-poll-light.c index f6ad42d..1923e30 100644 --- a/src/drv-iio-poll-light.c +++ b/src/drv-iio-poll-light.c @@ -18,9 +18,6 @@ #define DEFAULT_POLL_TIME 0.8 typedef struct DrvData { - ReadingsUpdateFunc callback_func; - gpointer user_data; - char *input_path; guint interval; guint timeout_id; @@ -61,7 +58,7 @@ light_changed (gpointer user_data) * will be Windows 8 compatible */ readings.uses_lux = TRUE; - drv_data->callback_func (&iio_poll_light, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&iio_poll_light, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } @@ -134,9 +131,7 @@ iio_poll_light_set_polling (SensorDevice *sensor_device, } static SensorDevice * -iio_poll_light_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_poll_light_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -153,8 +148,6 @@ iio_poll_light_open (GUdevDevice *device, sensor_device = g_new0 (SensorDevice, 1); sensor_device->priv = g_new0 (DrvData, 1); drv_data = (DrvData *) sensor_device->priv; - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; drv_data->interval = get_interval (device); diff --git a/src/drv-iio-poll-proximity.c b/src/drv-iio-poll-proximity.c index f27d580..b950c5c 100644 --- a/src/drv-iio-poll-proximity.c +++ b/src/drv-iio-poll-proximity.c @@ -23,8 +23,6 @@ typedef struct DrvData { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevDevice *dev; const char *name; gint near_level; @@ -48,7 +46,7 @@ poll_proximity (gpointer user_data) g_debug ("Proximity read from IIO on '%s': %d/%f, near: %d", drv_data->name, prox, near_level, readings.is_near); drv_data->last_level = prox; - drv_data->callback_func (&iio_poll_proximity, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&iio_poll_proximity, (gpointer) &readings, sensor_device->user_data); return G_SOURCE_CONTINUE; } @@ -98,9 +96,7 @@ get_near_level (GUdevDevice *device) static SensorDevice * -iio_poll_proximity_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +iio_poll_proximity_open (GUdevDevice *device) { SensorDevice *sensor_device; DrvData *drv_data; @@ -116,8 +112,6 @@ iio_poll_proximity_open (GUdevDevice *device, drv_data = (DrvData *) sensor_device->priv; drv_data->dev = g_object_ref (device); drv_data->name = g_udev_device_get_sysfs_attr (device, "name"); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; drv_data->near_level = near_level; return sensor_device; diff --git a/src/drv-input-accel.c b/src/drv-input-accel.c index 6046ac5..e10a898 100644 --- a/src/drv-input-accel.c +++ b/src/drv-input-accel.c @@ -19,8 +19,6 @@ typedef struct DrvData { guint timeout_id; - ReadingsUpdateFunc callback_func; - gpointer user_data; GUdevClient *client; GUdevDevice *dev, *parent; @@ -159,7 +157,7 @@ accelerometer_changed (gpointer user_data) readings.accel_y = tmp.y; readings.accel_z = tmp.z; - drv_data->callback_func (&input_accel, (gpointer) &readings, drv_data->user_data); + sensor_device->callback_func (&input_accel, (gpointer) &readings, sensor_device->user_data); } static void @@ -194,9 +192,7 @@ first_values (gpointer user_data) } static SensorDevice * -input_accel_open (GUdevDevice *device, - ReadingsUpdateFunc callback_func, - gpointer user_data) +input_accel_open (GUdevDevice *device) { const gchar * const subsystems[] = { "input", NULL }; SensorDevice *sensor_device; @@ -220,8 +216,6 @@ input_accel_open (GUdevDevice *device, drv_data->client = g_udev_client_new (subsystems); drv_data->mount_matrix = setup_mount_matrix (device); drv_data->location = setup_accel_location (device); - drv_data->callback_func = callback_func; - drv_data->user_data = user_data; g_signal_connect (drv_data->client, "uevent", G_CALLBACK (uevent_received), sensor_device);