sensord: move operate_sensor function to sensor_client_info 98/75598/1
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 2 Jun 2016 04:49:19 +0000 (13:49 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Mon, 20 Jun 2016 13:27:31 +0000 (22:27 +0900)
- it would be better to move operate_sensor() to sensor_client_info class,
  because it is only related with that class.
- because "operate_sensor" name is ambiguous, rename it to
  set_pause_policy.

Change-Id: I593f1380015e7d38ed413e5cda8141718942d23a
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/client.cpp
src/client/sensor_client_info.cpp
src/client/sensor_client_info.h
src/client/sensor_event_listener.cpp
src/client/sensor_event_listener.h

index 7effcda881d6ea297b73322d41b60a590a736d31..e818bd8e8180972b6c480fb321c98c412b68ad88 100644 (file)
@@ -164,7 +164,7 @@ static void power_save_state_cb(keynode_t *node, void *data)
 
        while (it_sensor != sensors.end()) {
                sensor_client_info::get_instance().get_sensor_rep(*it_sensor, prev_rep);
-               sensor_event_listener::get_instance().operate_sensor(*it_sensor, cur_power_save_state);
+               sensor_client_info::get_instance().set_pause_policy(*it_sensor, cur_power_save_state);
                sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep);
                change_sensor_rep(*it_sensor, prev_rep, cur_rep);
 
index 6ac154c5fd3a8d98ecb559d05298624b3f6df993..fcd4e80ef9221a72a7805453bbf30696a3308d97 100644 (file)
@@ -616,6 +616,30 @@ bool sensor_client_info::is_event_active(int handle, unsigned int event_type, un
        return true;
 }
 
+void sensor_client_info::set_pause_policy(sensor_id_t sensor, int pause_policy)
+{
+       sensor_handle_info_map handles_info;
+
+       get_sensor_handle_info(sensor, handles_info);
+
+       for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) {
+               if (it_handle->second.m_sensor_id != sensor)
+                       continue;
+
+               if (pause_policy && (it_handle->second.m_pause_policy & pause_policy)) {
+                       if (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) {
+                               set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED);
+                               _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first);
+                       }
+               } else {
+                       if (it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) {
+                               set_sensor_state(it_handle->first, SENSOR_STATE_STARTED);
+                               _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first);
+                       }
+               }
+       }
+}
+
 void sensor_client_info::clear(void)
 {
        close_command_channel();
index ac3a56fe29a5c17242bb5619353f936a19edf352..1d2ba9babb9b2e86856cf9318f3a92385e76cea7 100644 (file)
@@ -107,6 +107,8 @@ public:
        void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info);
        void get_all_handle_info(sensor_handle_info_map &handles_info);
 
+       void set_pause_policy(sensor_id_t sensor, int power_save_state);
+
        void clear(void);
 
        sensor_client_info();
index 1b9cd07e325fb25bc2ecf063b013c2927b5f5630..ec8da17b399a225dfcd46b5df4022dee9cac1296 100644 (file)
@@ -60,40 +60,6 @@ sensor_event_listener& sensor_event_listener::get_instance(void)
        return inst;
 }
 
-bool sensor_event_listener::start_handle(int handle)
-{
-       return m_client_info.set_sensor_state(handle, SENSOR_STATE_STARTED);
-}
-
-bool sensor_event_listener::stop_handle(int handle)
-{
-       return m_client_info.set_sensor_state(handle, SENSOR_STATE_STOPPED);
-}
-
-void sensor_event_listener::operate_sensor(sensor_id_t sensor, int power_save_state)
-{
-       sensor_handle_info_map handles_info;
-
-       m_client_info.get_sensor_handle_info(sensor, handles_info);
-
-       for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) {
-               if (it_handle->second.m_sensor_id != sensor)
-                       continue;
-
-               if ((it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) &&
-                       power_save_state &&
-                       (it_handle->second.m_pause_policy & power_save_state)) {
-                       m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED);
-                       _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first);
-
-               } else if ((it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) &&
-                       (!power_save_state || !(it_handle->second.m_pause_policy & power_save_state))) {
-                       m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_STARTED);
-                       _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first);
-               }
-       }
-}
-
 client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy)
 {
        unsigned int cal_event_type = get_calibration_event_type(event_type);
index 5bb92ab2ba68a0ade5c087df0a3542b4a713e4b1..417d0ad402a434f72a66bfd0814dccca750aa1e5 100644 (file)
@@ -66,10 +66,7 @@ typedef void (*hup_observer_t)(void);
 class sensor_event_listener {
 public:
        static sensor_event_listener& get_instance(void);
-       bool start_handle(int handle);
-       bool stop_handle(int handle);
 
-       void operate_sensor(sensor_id_t sensor, int power_save_state);
        void get_listening_sensors(sensor_id_vector &sensors);
 
        bool start_event_listener(void);