wakeup_supported: false
};
-static void update_event_cb(void *data)
+static bool update_event_cb(void *data)
{
accel_device *device = (accel_device *)data;
if (device)
- device->update_value();
+ return device->update_value();
+
+ return false;
}
m_y = temp[1];
m_z = temp[2];
- m_update_event.invoke();
-
//time stamp
return true;
}
{
retvm_if(ids == NULL || ids == nullptr, -EINVAL, "%s:NULL interface", SENSOR_NAME);
- m_update_event.reset();
+ m_update_event.clear();
event_ids.clear();
event_ids.push_back(sensor_info.id);
wakeup_supported: false
};
-static void update_event_cb(void *data)
+static bool update_event_cb(void *data)
{
gyro_device *device = (gyro_device *)data;
if (device)
- device->update_value();
+ return device->update_value();
+
+ return false;
}
gyro_device::gyro_device()
m_y = temp[1];
m_z = temp[2];
- m_update_event.invoke();
-
return true;
}
{
retvm_if(ids == NULL || ids == nullptr, -EINVAL, "%s:NULL interface", SENSOR_NAME);
- m_update_event.reset();
+ m_update_event.clear();
event_ids.clear();
event_ids.push_back(sensor_info.id);
wakeup_supported: false
};
-static void update_event_cb(void *data)
+static bool update_event_cb(void *data)
{
magnet_device *device = (magnet_device *)data;
if (device)
- device->update_value();
+ return device->update_value();
+
+ return false;
}
magnet_device::magnet_device()
m_y = temp[1];
m_z = temp[2];
- m_update_event.invoke();
-
return true;
}
{
retvm_if(ids == NULL || ids == nullptr, -EINVAL, "%s:NULL interface", SENSOR_NAME);
- m_update_event.reset();
+ m_update_event.clear();
event_ids.clear();
event_ids.push_back(sensor_info.id);
#include <unistd.h>
#include <sensor_log.h>
#include <glib.h>
+#include <poll.h>
#include <sys/eventfd.h>
#include "sensor_update_event.h"
void sensor_update_event::update(void)
{
- m_update_func(m_user_data);
+ if(m_update_func(m_user_data))
+ invoke();
}
void sensor_update_event::invoke(void)
_E("%s: Failed to notify.", m_sensor_name.c_str());
}
-void sensor_update_event::reset(void)
+void sensor_update_event::clear(void)
{
uint64_t data;
ssize_t size;
- size = read(m_event_fd, &data, sizeof(uint64_t));
- if (size != sizeof(uint64_t))
- _E("%s: Failed to flush.", m_sensor_name.c_str());
+ struct pollfd pfd;
+ pfd.fd = m_event_fd;
+ pfd.events = POLLIN | POLLERR;
+ pfd.revents = 0;
+
+ int ret = poll(&pfd, 1, 0);
+ if (ret <= 0) {
+ _E("%s: There is no event data.", m_sensor_name.c_str());
+ return ;
+ }
+
+ if (pfd.revents & POLLIN) {
+ size = read(m_event_fd, &data, sizeof(uint64_t));
+ if (size != sizeof(uint64_t))
+ _E("%s: Failed to flush.", m_sensor_name.c_str());
+ }
}
#include <string>
-typedef void (*fp_update_func)(void *data);
+typedef bool (*fp_update_func)(void *data);
class sensor_update_event {
public:
int get_event_fd();
void invoke();
- void reset();
+ void clear();
bool start();
void stop();