forked from enlightenment/efl
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 :)
This commit is contained in:
parent
d601c15302
commit
27a711b83c
|
@ -153,7 +153,7 @@ eeze_sensor_module_unregister(const char *name)
|
||||||
|
|
||||||
module = eina_hash_find(g_handle->modules, name);
|
module = eina_hash_find(g_handle->modules, name);
|
||||||
if (!module) return EINA_FALSE;
|
if (!module) return EINA_FALSE;
|
||||||
|
|
||||||
if (module->shutdown)
|
if (module->shutdown)
|
||||||
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
|
* the downside that the sensor creation takes longer. But that is only a
|
||||||
*initial cost.
|
*initial cost.
|
||||||
*/
|
*/
|
||||||
if (module->read(sens->type, sens))
|
if (module->read(sens))
|
||||||
return sens;
|
return sens;
|
||||||
|
|
||||||
free(sens);
|
free(sens);
|
||||||
|
@ -277,7 +277,7 @@ eeze_sensor_read(Eeze_Sensor_Obj *sens)
|
||||||
if (!module) return EINA_FALSE;
|
if (!module) return EINA_FALSE;
|
||||||
|
|
||||||
if (module->read)
|
if (module->read)
|
||||||
return module->read(sens->type, sens);
|
return module->read(sens);
|
||||||
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ typedef struct _Eeze_Sensor_Module
|
||||||
Eina_Bool (*init)(void); /**< Pointer to module init function */
|
Eina_Bool (*init)(void); /**< Pointer to module init function */
|
||||||
Eina_Bool (*shutdown)(void); /**< Pointer to module shutdown 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 (*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 */
|
Eina_List *sensor_list; /**< List of sensor objects attached to the module */
|
||||||
} Eeze_Sensor_Module;
|
} Eeze_Sensor_Module;
|
||||||
|
|
||||||
|
|
|
@ -52,18 +52,9 @@ fake_shutdown(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
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;
|
switch (obj->type)
|
||||||
|
|
||||||
obj = eeze_sensor_obj_get(sensor_type);
|
|
||||||
if (obj == NULL)
|
|
||||||
{
|
|
||||||
ERR("No matching sensor object found in list");
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sensor_type)
|
|
||||||
{
|
{
|
||||||
case EEZE_SENSOR_TYPE_ACCELEROMETER:
|
case EEZE_SENSOR_TYPE_ACCELEROMETER:
|
||||||
case EEZE_SENSOR_TYPE_GRAVITY:
|
case EEZE_SENSOR_TYPE_GRAVITY:
|
||||||
|
@ -91,13 +82,9 @@ fake_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ERR("Not possible to read from this sensor type.");
|
ERR("Not possible to read from this sensor type.");
|
||||||
free(obj);
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
|
|
||||||
free(obj);
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
* the system. Normally it is better to use the asynchronous reading functions.
|
||||||
*/
|
*/
|
||||||
static Eina_Bool
|
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;
|
sensor_data_accuracy_e accuracy;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
float azimuth, pitch, roll, lux, distance, yaw;
|
float azimuth, pitch, roll, lux, distance, yaw;
|
||||||
bool supported;
|
bool supported;
|
||||||
sensor_type_e type;
|
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
|
/* Don't attempt to do anything if the sensor is not available on the system
|
||||||
* we are running on.
|
* 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);
|
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)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
@ -1083,12 +1076,9 @@ eeze_sensor_tizen_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ERR("Not possible to read from this sensor type.");
|
ERR("Not possible to read from this sensor type.");
|
||||||
free(obj);
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
|
|
||||||
free(obj);
|
|
||||||
sensor_stop(sensor_handle, type);
|
sensor_stop(sensor_handle, type);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,18 +89,9 @@ _udev_read(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
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;
|
switch (obj->type)
|
||||||
|
|
||||||
obj = eeze_sensor_obj_get(sensor_type);
|
|
||||||
if (obj == NULL)
|
|
||||||
{
|
|
||||||
ERR("No matching sensor object found in list");
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sensor_type)
|
|
||||||
{
|
{
|
||||||
case EEZE_SENSOR_TYPE_TEMPERATURE:
|
case EEZE_SENSOR_TYPE_TEMPERATURE:
|
||||||
obj->accuracy = -1;
|
obj->accuracy = -1;
|
||||||
|
@ -112,13 +103,9 @@ udev_read(Eeze_Sensor_Type sensor_type, Eeze_Sensor_Obj *lobj)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ERR("Not possible to read from this sensor type.");
|
ERR("Not possible to read from this sensor type.");
|
||||||
free(obj);
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(lobj, obj, sizeof(Eeze_Sensor_Obj));
|
|
||||||
free(obj);
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue