_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());
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);
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;
+}
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);
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);
, m_accuracy(-1)
, m_accuracy_cb(NULL)
, m_accuracy_user_data(NULL)
+, m_passive(false)
{
}
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;
}
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();
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;
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);
/**
* @}
*/