sensord: add stop() in event_dispatcher thread 00/70200/2
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 18 May 2016 11:56:26 +0000 (20:56 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 19 May 2016 05:21:24 +0000 (22:21 -0700)
- because sensord can be shutdown, event_dispatcher can be stopped.

Change-Id: Idd59e0f34dad468c3f4a32d3a47e4329cdec0936
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/server/sensor_event_dispatcher.cpp
src/server/sensor_event_dispatcher.h

index 200cc95..c1fc3cb 100644 (file)
@@ -30,6 +30,7 @@ using std::pair;
 #define MAX_PENDING_CONNECTION 32
 
 sensor_event_dispatcher::sensor_event_dispatcher()
+: m_running(false)
 {
 }
 
@@ -45,12 +46,21 @@ sensor_event_dispatcher& sensor_event_dispatcher::get_instance()
 
 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;
@@ -99,7 +109,7 @@ void sensor_event_dispatcher::dispatch_event(void)
 
        _I("Event Dispatcher started");
 
-       while (true) {
+       while (m_running) {
                void *seed_event = get_event_queue().pop();
 
                vector<void *> sensor_events;
@@ -273,6 +283,9 @@ bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor *sensor)
 {
        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;
@@ -287,14 +300,11 @@ bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor *senso
 {
        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;
 }
index 243fb70..ee7e630 100644 (file)
@@ -37,6 +37,7 @@ public:
        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);
@@ -51,6 +52,7 @@ private:
        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();