sensord: support the passive mode which listens sensor event only 00/75600/1
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 2 Jun 2016 05:11:04 +0000 (14:11 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Mon, 20 Jun 2016 13:30:31 +0000 (22:30 +0900)
if a client wants to be listening sensor event which other clients start
sensor, use sensord_set_passive_mode() before sensord_register_event().

Change-Id: Idbe59ed663c8a0bc268c406afcdc8cac13286b98
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_handle_info.cpp
src/client/sensor_handle_info.h
src/client/sensor_internal.h

index e818bd8..769aa9d 100644 (file)
@@ -682,6 +682,28 @@ API bool sensord_disconnect(int handle)
 
        _I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
 
+       if (sensor_client_info::get_instance().get_passive_mode(handle)) {
+               _W("%s[%d] for %s is on passive mode while disconnecting.",
+                       get_sensor_name(sensor_id), handle, get_client_name());
+
+               command_channel *cmd_channel;
+               event_type_vector event_types;
+               sensor_client_info::get_instance().get_active_event_types(sensor_id, event_types);
+
+               for (auto it = event_types.begin(); it != event_types.end(); ++it)
+                       sensord_unregister_event(handle, *it);
+
+               if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
+                       _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
+                       return false;
+               }
+
+               if (!cmd_channel->cmd_unset_batch()) {
+                       _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
+                       return false;
+               }
+       }
+
        if (sensor_state != SENSOR_STATE_STOPPED) {
                _W("%s[%d] for %s is not stopped before disconnecting.",
                        get_sensor_name(sensor_id), handle, get_client_name());
@@ -781,6 +803,9 @@ API bool sensord_unregister_event(int handle, unsigned int event_type)
        sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
        ret =  change_sensor_rep(sensor_id, prev_rep, cur_rep);
 
+       if (sensor_client_info::get_instance().get_passive_mode(handle))
+               sensor_client_info::get_instance().set_passive_mode(handle, false);
+
        if (!ret)
                sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
 
@@ -1197,3 +1222,12 @@ API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigne
        return false;
 }
 
+API bool sensord_set_passive_mode(int handle, bool passive)
+{
+       if (!sensor_client_info::get_instance().set_passive_mode(handle, passive)) {
+               _E("Failed to set passive mode %d", passive);
+               return false;
+       }
+
+       return true;
+}
index 62de536..08b5a9d 100644 (file)
@@ -213,6 +213,36 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state)
        return true;
 }
 
+bool sensor_client_info::get_passive_mode(int handle)
+{
+       AUTOLOCK(m_handle_info_lock);
+
+       auto it_handle = m_sensor_handle_infos.find(handle);
+
+       if (it_handle == m_sensor_handle_infos.end()) {
+               _E("Handle[%d] is not found for client %s", handle, get_client_name());
+               return false;
+       }
+
+       return it_handle->second.get_passive_mode();
+}
+
+bool sensor_client_info::set_passive_mode(int handle, bool passive)
+{
+       AUTOLOCK(m_handle_info_lock);
+
+       auto it_handle = m_sensor_handle_infos.find(handle);
+
+       if (it_handle == m_sensor_handle_infos.end()) {
+               _E("Handle[%d] is not found for client %s", handle, get_client_name());
+               return false;
+       }
+
+       it_handle->second.set_passive_mode(passive);
+
+       return true;
+}
+
 bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy)
 {
        AUTOLOCK(m_handle_info_lock);
index 1d2ba9b..7c46323 100644 (file)
@@ -74,6 +74,10 @@ public:
        bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy);
        bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy);
        bool set_sensor_state(int handle, int sensor_state);
+
+       bool get_passive_mode(int handle);
+       bool set_passive_mode(int handle, bool passive);
+
        bool set_sensor_pause_policy(int handle, int pause_policy);
        bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
        bool set_accuracy(int handle, int accuracy);
index b394990..f1e9c65 100644 (file)
@@ -34,6 +34,7 @@ sensor_handle_info::sensor_handle_info()
 , m_accuracy(-1)
 , m_accuracy_cb(NULL)
 , m_accuracy_user_data(NULL)
+, m_passive(false)
 {
 }
 
@@ -161,7 +162,17 @@ unsigned int sensor_handle_info::get_reg_event_count(void)
        return m_reg_event_infos.size();
 }
 
+bool sensor_handle_info::get_passive_mode(void)
+{
+       return m_passive;
+}
+
+void sensor_handle_info::set_passive_mode(bool passive)
+{
+       m_passive = passive;
+}
+
 bool sensor_handle_info::is_started(void)
 {
-       return (m_sensor_state == SENSOR_STATE_STARTED);
+       return (m_sensor_state == SENSOR_STATE_STARTED) || m_passive;
 }
index 28e5a01..c74c3a5 100644 (file)
@@ -30,15 +30,6 @@ typedef std::unordered_map<unsigned int, reg_event_info> event_info_map;
 
 class sensor_handle_info {
 public:
-       int m_handle;
-       sensor_id_t m_sensor_id;
-       int m_sensor_state;
-       int m_pause_policy;
-       int m_bad_accuracy;
-       int m_accuracy;
-       sensor_accuracy_changed_cb_t m_accuracy_cb;
-       void *m_accuracy_user_data;
-
        sensor_handle_info();
        ~sensor_handle_info();
 
@@ -55,8 +46,20 @@ public:
        void clear_all_events(void);
        static unsigned long long renew_event_id(void);
 
+       bool get_passive_mode(void);
+       void set_passive_mode(bool passive);
        bool is_started(void);
 
+       int m_handle;
+       sensor_id_t m_sensor_id;
+       int m_sensor_state;
+       int m_pause_policy;
+       int m_bad_accuracy;
+       int m_accuracy;
+       sensor_accuracy_changed_cb_t m_accuracy_cb;
+       void *m_accuracy_user_data;
+       bool m_passive;
+
 private:
        event_info_map m_reg_event_infos;
        static unsigned long long m_event_id;
index c4c3fce..3cc6641 100644 (file)
@@ -386,6 +386,7 @@ int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, v
 bool sensord_external_disconnect(int handle);
 bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
 
+bool sensord_set_passive_mode(int handle, bool passive);
 /**
   * @}
  */