#define MAX_PENDING_CONNECTION 32
sensor_event_dispatcher::sensor_event_dispatcher()
+: m_running(false)
{
}
bool sensor_event_dispatcher::run(void)
{
+ m_running = true;
+
thread dispatcher(&sensor_event_dispatcher::dispatch_event, this);
dispatcher.detach();
return true;
}
+bool sensor_event_dispatcher::stop(void)
+{
+ m_running = false;
+
+ return true;
+}
+
void sensor_event_dispatcher::accept_event_channel(csocket client_socket)
{
int client_id;
_I("Event Dispatcher started");
- while (true) {
+ while (m_running) {
void *seed_event = get_event_queue().pop();
vector<void *> sensor_events;
{
AUTOLOCK(m_active_virtual_sensors_mutex);
+ if (!m_running)
+ return true;
+
if (has_active_virtual_sensor(sensor)) {
_E("[%s] sensor is already added on active virtual sensors", sensor->get_name());
return false;
{
AUTOLOCK(m_active_virtual_sensors_mutex);
- auto it_v_sensor = find(m_active_virtual_sensors.begin(), m_active_virtual_sensors.end(), sensor);
-
- if (it_v_sensor == m_active_virtual_sensors.end()) {
- _E("Fail to delete non-existent [%s] sensor on active virtual sensors", sensor->get_name());
- return false;
- }
+ if (!m_running)
+ return true;
- m_active_virtual_sensors.erase(it_v_sensor);
+ if (sensor)
+ m_active_virtual_sensors.remove(sensor);
return true;
}
static sensor_event_dispatcher& get_instance();
bool run(void);
+ bool stop(void);
void accept_event_connections(csocket client_socket);
void request_last_event(int client_id, sensor_id_t sensor_id);
event_type_last_event_map m_last_events;
virtual_sensors m_active_virtual_sensors;
cmutex m_active_virtual_sensors_mutex;
+ bool m_running;
sensor_event_dispatcher();
~sensor_event_dispatcher();