forked from enlightenment/efl
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:
parent
116013320a
commit
c2da27328b
|
@ -148,6 +148,7 @@ typedef struct _Eeze_Sensor_Obj
|
||||||
float data[3]; /**< Sensor data depending on the sensor type */
|
float data[3]; /**< Sensor data depending on the sensor type */
|
||||||
double timestamp; /**< Timestamp of data read */
|
double timestamp; /**< Timestamp of data read */
|
||||||
Eina_Bool continuous_flow; /**< FUTURE USE: Continuous flow of sensor read out */
|
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;
|
} Eeze_Sensor_Obj;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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
|
* physical sensor. That might be a long time depending on the hardware and its
|
||||||
* interface.
|
* 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
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data);
|
EAPI Eina_Bool eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data);
|
||||||
|
|
|
@ -295,7 +295,7 @@ eeze_sensor_async_read(Eeze_Sensor_Obj *sens, void *user_data)
|
||||||
module = _highest_priority_module_get();
|
module = _highest_priority_module_get();
|
||||||
if (!module) return EINA_FALSE;
|
if (!module) return EINA_FALSE;
|
||||||
if (module->async_read)
|
if (module->async_read)
|
||||||
return module->async_read(sens->type, user_data);
|
return module->async_read(sens, user_data);
|
||||||
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,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_Obj *obj, void *user_data); /**< Pointer to module async_read function */
|
||||||
Eina_Bool (*read)(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;
|
||||||
|
|
|
@ -24,6 +24,14 @@ static int _eeze_sensor_fake_log_dom = -1;
|
||||||
|
|
||||||
static Eeze_Sensor_Module *esensor_module;
|
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
|
static Eina_Bool
|
||||||
fake_init(void)
|
fake_init(void)
|
||||||
{
|
{
|
||||||
|
@ -89,16 +97,10 @@ fake_read(Eeze_Sensor_Obj *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
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;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Default values for sensor objects with three data points */
|
/* Default values for sensor objects with three data points */
|
||||||
obj->accuracy = -1;
|
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->data[2] = 42;
|
||||||
obj->timestamp = ecore_time_get();
|
obj->timestamp = ecore_time_get();
|
||||||
|
|
||||||
switch (sensor_type)
|
switch (obj->type)
|
||||||
{
|
{
|
||||||
case EEZE_SENSOR_TYPE_ACCELEROMETER:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_GRAVITY:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_LINEAR_ACCELERATION:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_DEVICE_ORIENTATION:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_MAGNETIC:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_ORIENTATION:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_GYROSCOPE:
|
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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_LIGHT:
|
case EEZE_SENSOR_TYPE_LIGHT:
|
||||||
/* Reset values that are not used for sensor object with one data point */
|
/* Reset values that are not used for sensor object with one data point */
|
||||||
obj->data[1] = 0;
|
obj->data[1] = 0;
|
||||||
obj->data[2] = 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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_PROXIMITY:
|
case EEZE_SENSOR_TYPE_PROXIMITY:
|
||||||
obj->data[1] = 0;
|
obj->data[1] = 0;
|
||||||
obj->data[2] = 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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_BAROMETER:
|
case EEZE_SENSOR_TYPE_BAROMETER:
|
||||||
obj->data[1] = 0;
|
obj->data[1] = 0;
|
||||||
obj->data[2] = 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;
|
break;
|
||||||
case EEZE_SENSOR_TYPE_TEMPERATURE:
|
case EEZE_SENSOR_TYPE_TEMPERATURE:
|
||||||
obj->data[1] = 0;
|
obj->data[1] = 0;
|
||||||
obj->data[2] = 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;
|
break;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,6 +22,14 @@ static Eeze_Sensor_Module *esensor_module;
|
||||||
|
|
||||||
static Eina_List *devices;
|
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
|
static Eina_Bool
|
||||||
udev_init(void)
|
udev_init(void)
|
||||||
{
|
{
|
||||||
|
@ -110,18 +118,12 @@ udev_read(Eeze_Sensor_Obj *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
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);
|
switch (obj->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;
|
||||||
|
@ -129,12 +131,11 @@ udev_async_read(Eeze_Sensor_Type sensor_type, void *user_data EINA_UNUSED)
|
||||||
obj->data[1] = 0;
|
obj->data[1] = 0;
|
||||||
obj->data[2] = 0;
|
obj->data[2] = 0;
|
||||||
obj->timestamp = ecore_time_get();
|
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;
|
break;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
Loading…
Reference in New Issue