eeze/sensor: Simplify object handling in async paths.

This follows the simplified handling of sensor object we are already
doing for the sync paths. Its a bit more complicated here as we need
to pass all data through the module specific async handling. But the
result should be the same.
This commit is contained in:
Stefan Schmidt 2013-04-19 09:55:02 +01:00
parent 116013320a
commit c2da27328b
6 changed files with 194 additions and 212 deletions

View File

@ -148,6 +148,7 @@ typedef struct _Eeze_Sensor_Obj
float data[3]; /**< Sensor data depending on the sensor type */
double timestamp; /**< Timestamp of data read */
Eina_Bool continuous_flow; /**< FUTURE USE: Continuous flow of sensor read out */
void *user_data; /**< Data pointer used for passing data to the asynchronous callback */
} Eeze_Sensor_Obj;
#ifdef __cplusplus
@ -297,6 +298,9 @@ EAPI Eina_Bool eeze_sensor_read(Eeze_Sensor_Obj *sens);
* physical sensor. That might be a long time depending on the hardware and its
* interface.
*
* The extra data passed in as user_data here will be available in the user_data
* pointer of the sensor object when the ecore event arrives.
*
* @since 1.8
*/
EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data);

View File

@ -295,7 +295,7 @@ eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data)
module = _highest_priority_module_get();
if (!module) return EINA_FALSE;
if (module->async_read)
return module->async_read(sens->type, user_data);
return module->async_read(sens, user_data);
return EINA_FALSE;
}

View File

@ -56,7 +56,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 (*async_read)(Eeze_Sensor_Obj *obj, void *user_data); /**< Pointer to module async_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;

View File

@ -24,6 +24,14 @@ static int _eeze_sensor_fake_log_dom = -1;
static Eeze_Sensor_Module *esensor_module;
static void
_dummy_free(void *user_data EINA_UNUSED, void *func_data EINA_UNUSED)
{
/* Don't free the event data after dispatching the event. We keep track of
* it on our own
*/
}
static Eina_Bool
fake_init(void)
{
@ -89,16 +97,10 @@ fake_read(Eeze_Sensor_Obj *obj)
}
static Eina_Bool
fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
fake_async_read(Eeze_Sensor_Obj *obj, void *user_data)
{
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;
}
if (user_data)
obj->user_data = user_data;
/* Default values for sensor objects with three data points */
obj->accuracy = -1;
@ -107,54 +109,53 @@ fake_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
obj->data[2] = 42;
obj->timestamp = ecore_time_get();
switch (sensor_type)
switch (obj->type)
{
case EEZE_SENSOR_TYPE_ACCELEROMETER:
ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_ACCELEROMETER, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_GRAVITY:
ecore_event_add(EEZE_SENSOR_EVENT_GRAVITY, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_GRAVITY, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_LINEAR_ACCELERATION:
ecore_event_add(EEZE_SENSOR_EVENT_LINEAR_ACCELERATION, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_LINEAR_ACCELERATION, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_DEVICE_ORIENTATION:
ecore_event_add(EEZE_SENSOR_EVENT_DEVICE_ORIENTATION, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_DEVICE_ORIENTATION, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_MAGNETIC:
ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_MAGNETIC, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_ORIENTATION:
ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_ORIENTATION, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_GYROSCOPE:
ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_GYROSCOPE, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_LIGHT:
/* Reset values that are not used for sensor object with one data point */
obj->data[1] = 0;
obj->data[2] = 0;
ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_LIGHT, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_PROXIMITY:
obj->data[1] = 0;
obj->data[2] = 0;
ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_PROXIMITY, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_BAROMETER:
obj->data[1] = 0;
obj->data[2] = 0;
ecore_event_add(EEZE_SENSOR_EVENT_BAROMETER, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_BAROMETER, obj, _dummy_free, NULL);
break;
case EEZE_SENSOR_TYPE_TEMPERATURE:
obj->data[1] = 0;
obj->data[2] = 0;
ecore_event_add(EEZE_SENSOR_EVENT_TEMPERATURE, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_TEMPERATURE, obj, _dummy_free, NULL);
break;
default:
ERR("Not possible to read from this sensor type.");
free(obj);
return EINA_FALSE;
}
return EINA_TRUE;

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,14 @@ static Eeze_Sensor_Module *esensor_module;
static Eina_List *devices;
static void
_dummy_free(void *user_data EINA_UNUSED, void *func_data EINA_UNUSED)
{
/* Don't free the event data after dispatching the event. We keep track of
* it on our own
*/
}
static Eina_Bool
udev_init(void)
{
@ -110,18 +118,12 @@ udev_read(Eeze_Sensor_Obj *obj)
}
static Eina_Bool
udev_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
udev_async_read(Eeze_Sensor_Obj *obj, void *user_data)
{
Eeze_Sensor_Obj *obj = NULL;
if (user_data)
obj->user_data = user_data;
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;
@ -129,12 +131,11 @@ udev_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
obj->data[1] = 0;
obj->data[2] = 0;
obj->timestamp = ecore_time_get();
ecore_event_add(EEZE_SENSOR_EVENT_TEMPERATURE, obj, NULL, NULL);
ecore_event_add(EEZE_SENSOR_EVENT_TEMPERATURE, obj, _dummy_free, NULL);
break;
default:
ERR("Not possible to read from this sensor type.");
free(obj);
return EINA_FALSE;
}
return EINA_TRUE;