const unsigned int GET_DATA_MIN_INTERVAL = 10;
int state = OP_ERROR;
bool adjusted = false;
+ int length;
sensor_data_t *data;
goto out;
}
- state = m_module->get_data(&data);
+ state = m_module->get_data(&data, &length);
// In case of not getting sensor data, wait short time and retry again
// 1. changing interval to be less than 10ms
// 4. retrying to get data
// 5. repeat 2 ~ 4 operations RETRY_CNT times
// 6. reverting back to original interval
- if ((state > 0) && !data->timestamp) {
+ if ((state >= 0) && !data->timestamp) {
const int RETRY_CNT = 5;
const unsigned long long INIT_WAIT_TIME = 20000; //20ms
const unsigned long WAIT_TIME = 100000; //100ms
adjusted = true;
}
- while ((state > 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
+ while ((state >= 0) && !data->timestamp && (retry++ < RETRY_CNT)) {
INFO("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry);
usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME);
- state = m_module->get_data(&data);
+ state = m_module->get_data(&data, &length);
}
if (adjusted)
return true;
}
-int physical_sensor::get_data(sensor_data_t **data)
+int physical_sensor::get_data(sensor_data_t **data, int *length)
{
AUTOLOCK(m_mutex);
if (!m_sensor_device)
- return false;
+ return -1;
- int length = -1;
- length = m_sensor_device->get_data(m_handle.id, data);
+ int remains = 0;
+ remains = m_sensor_device->get_data(m_handle.id, data, length);
- if (length < 0) {
+ if (*length < 0) {
ERR("Failed to get sensor event");
return -1;
}
- return length;
+ return remains;
}
bool physical_sensor::flush(void)
int get_poll_fd();
virtual bool read_fd(std::vector<uint16_t> &ids);
- virtual int get_data(sensor_data_t **data);
+ virtual int get_data(sensor_data_t **data, int *length);
virtual bool flush(void);
private:
static cmutex m_mutex;
sensor_event_t *rotation_event;
sensor_data_t *rotation_data;
- unsigned int data_length;
+ int data_length;
+ int remains;
rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- data_length = get_data(&rotation_data);
+ remains = get_data(&rotation_data, &data_length);
+
+ if (remains < 0)
+ return;
rotation_event->sensor_id = get_id();
rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT;
return;
}
-int auto_rotation_sensor::get_data(sensor_data_t **data)
+int auto_rotation_sensor::get_data(sensor_data_t **data, int *length)
{
+ /* if It is batch sensor, remains can be 2+ */
+ int remains = 1;
+
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
sensor_data->value_count = 1;
*data = sensor_data;
+ *length = sizeof(sensor_data_t);
- return sizeof(sensor_data_t);
+ return --remains;
}
bool auto_rotation_sensor::set_interval(unsigned long interval)
virtual void synthesize(const sensor_event_t& event);
/* get data */
- virtual int get_data(sensor_data_t **data);
+ virtual int get_data(sensor_data_t **data, int *length);
private:
sensor_base *m_accel_sensor;
auto_rotation_alg *m_alg;
return false;
}
-int sensor_base::get_data(sensor_data_t **data)
+int sensor_base::get_data(sensor_data_t **data, int *length)
{
return -1;
}
virtual bool is_virtual(void);
/* set/get data */
- virtual int get_data(sensor_data_t **data);
+ virtual int get_data(sensor_data_t **data, int *length);
virtual bool flush(void);
virtual int set_attribute(int32_t attribute, int32_t value);
sensor_event_t *event;
sensor_data_t *data;
int data_length;
+ int remains = 1;
sensor = it_sensor->second;
if (result == std::end(ids))
continue;
- event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+ while (remains > 0) {
+ event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- data_length = sensor->get_data(&data);
- event->sensor_id = sensor->get_id();
- event->event_type = sensor->get_event_type();
- event->data_length = data_length;
- event->data = data;
+ remains = sensor->get_data(&data, &data_length);
- sensor->push(event);
+ event->sensor_id = sensor->get_id();
+ event->event_type = sensor->get_event_type();
+ event->data_length = data_length;
+ event->data = data;
+
+ sensor->push(event);
+ }
}
return true;
virtual void synthesize(const sensor_event_t& event) = 0;
/* get data */
- virtual int get_data(sensor_data_t **data) = 0;
+ virtual int get_data(sensor_data_t **data, int *length) = 0;
bool is_virtual(void);
virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0;
virtual int read_fd(uint16_t **ids) = 0;
- virtual int get_data(uint16_t id, sensor_data_t **data) = 0;
+ virtual int get_data(uint16_t id, sensor_data_t **data, int *length) = 0;
virtual bool flush(uint16_t id) = 0;
};