From 27a711b83cd8a8f56c6f4c103087523da374299b Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Thu, 18 Apr 2013 17:35:37 +0100 Subject: [PATCH] eeze/sensor: Simplify sensor object handling. We rely on the app to provide a sensible object pointer and we now longer need to have a copy of the object around to operate on it. Simplifies code, maintenance and reduces mem copies. Win-Win :) --- src/lib/eeze/eeze_sensor.c | 6 +++--- src/lib/eeze/eeze_sensor_private.h | 2 +- src/modules/eeze/sensor/fake/fake.c | 17 ++--------------- src/modules/eeze/sensor/tizen/tizen.c | 14 ++------------ src/modules/eeze/sensor/udev/udev.c | 17 ++--------------- 5 files changed, 10 insertions(+), 46 deletions(-) diff --git a/src/lib/eeze/eeze_sensor.c b/src/lib/eeze/eeze_sensor.c index 4086142..da12a12 100644 --- a/src/lib/eeze/eeze_sensor.c +++ b/src/lib/eeze/eeze_sensor.c @@ -153,7 +153,7 @@ eeze_sensor_module_unregister(const char *name) module = eina_hash_find(g_handle->modules, name); if (!module) return EINA_FALSE; - + if (module->shutdown) module->shutdown(); @@ -196,7 +196,7 @@ eeze_sensor_new(Eeze_Sensor_Type type) * the downside that the sensor creation takes longer. But that is only a *initial cost. */ - if (module->read(sens->type, sens)) + if (module->read(sens)) return sens; free(sens); @@ -277,7 +277,7 @@ eeze_sensor_read(Eeze_Sensor_Obj *sens) if (!module) return EINA_FALSE; if (module->read) - return module->read(sens->type, sens); + return module->read(sens); return EINA_FALSE; } diff --git a/src/lib/eeze/eeze_sensor_private.h b/src/lib/eeze/eeze_sensor_private.h index d8f0a28..3ba6198 100644 --- a/src/lib/eeze/eeze_sensor_private.h +++ b/src/lib/eeze/eeze_sensor_private.h @@ -57,7 +57,7 @@ typedef struct _Eeze_Sensor_Module Eina_Bool (*init)(void); /**< Pointer to module init function */ Eina_Bool (*shutdown)(void); /**< Pointer to module shutdown function */ Eina_Bool (*async_read)(Eeze_Sensor_Type sensor_type, void *user_data); /**< Pointer to module async_read function */ - Eina_Bool (*read)(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *obj); /**< Pointer to module read function */ + Eina_Bool (*read)(Eeze_Sensor_Obj *obj); /**< Pointer to module read function */ Eina_List *sensor_list; /**< List of sensor objects attached to the module */ } Eeze_Sensor_Module; diff --git a/src/modules/eeze/sensor/fake/fake.c b/src/modules/eeze/sensor/fake/fake.c index ee07b98..bf9d694 100644 --- a/src/modules/eeze/sensor/fake/fake.c +++ b/src/modules/eeze/sensor/fake/fake.c @@ -52,18 +52,9 @@ fake_shutdown(void) } static Eina_Bool -fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) +fake_read(Eeze_Sensor_Obj *obj) { - Eeze_Sensor_Obj *obj = NULL; - - obj = eeze_sensor_obj_get(sensor_type); - if (obj == NULL) - { - ERR("No matching sensor object found in list"); - return EINA_FALSE; - } - - switch (sensor_type) + switch (obj->type) { case EEZE_SENSOR_TYPE_ACCELEROMETER: case EEZE_SENSOR_TYPE_GRAVITY: @@ -91,13 +82,9 @@ fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) default: ERR("Not possible to read from this sensor type."); - free(obj); return EINA_FALSE; } - memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj)); - free(obj); - return EINA_TRUE; } diff --git a/src/modules/eeze/sensor/tizen/tizen.c b/src/modules/eeze/sensor/tizen/tizen.c index b6f44aa..7a06baa 100644 --- a/src/modules/eeze/sensor/tizen/tizen.c +++ b/src/modules/eeze/sensor/tizen/tizen.c @@ -971,16 +971,15 @@ no_move_read_cb(unsigned long long timestamp, void *user_data) * the system. Normally it is better to use the asynchronous reading functions. */ static Eina_Bool -eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) +eeze_sensor_tizen_read(Eeze_Sensor_Obj *obj) { sensor_data_accuracy_e accuracy; float x, y, z; float azimuth, pitch, roll, lux, distance, yaw; bool supported; sensor_type_e type; - Eeze_Sensor_Obj *obj; - type = eeze_to_tizen(sensor_type); + type = eeze_to_tizen(obj->type); /* Don't attempt to do anything if the sensor is not available on the system * we are running on. @@ -993,12 +992,6 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) } sensor_start(sensor_handle, type); - obj = eeze_sensor_obj_get(sensor_type); - if (obj == NULL) - { - ERR("No matching sensor object found in list."); - return EINA_FALSE; - } switch (type) { @@ -1083,12 +1076,9 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) default: ERR("Not possible to read from this sensor type."); - free(obj); return EINA_FALSE; } - memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj)); - free(obj); sensor_stop(sensor_handle, type); return EINA_TRUE; } diff --git a/src/modules/eeze/sensor/udev/udev.c b/src/modules/eeze/sensor/udev/udev.c index e958b06..a23bf5e 100644 --- a/src/modules/eeze/sensor/udev/udev.c +++ b/src/modules/eeze/sensor/udev/udev.c @@ -89,18 +89,9 @@ _udev_read(void) } static Eina_Bool -udev_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) +udev_read(Eeze_Sensor_Obj *obj) { - Eeze_Sensor_Obj *obj = NULL; - - obj = eeze_sensor_obj_get(sensor_type); - if (obj == NULL) - { - ERR("No matching sensor object found in list"); - return EINA_FALSE; - } - - switch (sensor_type) + switch (obj->type) { case EEZE_SENSOR_TYPE_TEMPERATURE: obj->accuracy = -1; @@ -112,13 +103,9 @@ udev_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj) default: ERR("Not possible to read from this sensor type."); - free(obj); return EINA_FALSE; } - memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj)); - free(obj); - return EINA_TRUE; } -- 2.7.4