}
}
+bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_channel)
+{
+ sensor_handle_info_map handle_infos;
+
+ sensor_client_info::get_instance().get_sensor_handle_info(sensor, handle_infos);
+
+ for (auto it_handles = handle_infos.begin(); it_handles != handle_infos.end(); ++it_handles) {
+ sensor_handle_info info = it_handles->second;
+
+ for (auto it = info.attributes_int.begin(); it != info.attributes_int.end(); ++it) {
+ int attribute = it->first;
+ int value = it->second;
+ if (!cmd_channel->cmd_set_attribute_int(attribute, value)) {
+ _E("Failed to send cmd_set_attribute_int(%d, %d) for %s",
+ client_id, value, get_client_name());
+ return false;
+ }
+ }
+
+ for (auto it = info.attributes_str.begin(); it != info.attributes_str.end(); ++it) {
+ int attribute = it->first;
+ const char *value = it->second.c_str();
+ int value_len = it->second.size();
+ if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) {
+ _E("Failed to send cmd_set_attribute_str(%d, %d, %s) for %s",
+ client_id, value_len, value, get_client_name());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
void restore_session(void)
{
AUTOLOCK(lock);
goto FAILED;
}
+ if (!restore_attributes(client_id, *it_sensor, cmd_channel)) {
+ _E("Failed to restore attributes(%s) for %s", get_sensor_name(*it_sensor), get_client_name());
+ goto FAILED;
+ }
++it_sensor;
}
return -EPERM;
}
+ sensor_client_info::get_instance().set_attribute(handle, attribute, value);
+
return OP_SUCCESS;
}
return -EPERM;
}
+ sensor_client_info::get_instance().set_attribute(handle, attribute, value);
+
return OP_SUCCESS;
}
}
}
+bool sensor_client_info::set_attribute(int handle, int attribute, int value)
+{
+ 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.attributes_int[attribute] = value;
+
+ return true;
+}
+
+bool sensor_client_info::set_attribute(int handle, int attribute, std::string value)
+{
+ 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.attributes_str[attribute] = value;
+
+ return true;
+}
+
void sensor_client_info::clear(void)
{
close_command_channel();
#include <sstream>
#include <unordered_map>
#include <vector>
-#include <string>
-#include <queue>
-#include <mutex>
-#include <condition_variable>
#include <cmutex.h>
#include <sensor_handle_info.h>
#include <command_channel.h>
-using std::unordered_map;
-using std::vector;
-using std::string;
-using std::queue;
-using std::mutex;
-using std::lock_guard;
-using std::unique_lock;
-using std::condition_variable;
-
-typedef vector<unsigned int> handle_vector;
-typedef vector<sensor_id_t> sensor_id_vector;
-typedef unordered_map<int, sensor_handle_info> sensor_handle_info_map;
-typedef unordered_map<sensor_id_t, command_channel *> sensor_command_channel_map;
+typedef std::vector<unsigned int> handle_vector;
+typedef std::vector<sensor_id_t> sensor_id_vector;
+typedef std::unordered_map<int, sensor_handle_info> sensor_handle_info_map;
+typedef std::unordered_map<sensor_id_t, command_channel *> sensor_command_channel_map;
typedef struct sensor_rep {
bool active;
bool get_passive_mode(int handle);
bool set_passive_mode(int handle, bool passive);
+ bool set_attribute(int handle, int attribute, int value);
+ bool set_attribute(int handle, int attribute, std::string value);
+
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);
#include <sensor_log.h>
#include <string.h>
#include <unordered_map>
+#include <string>
+#include <map>
typedef std::unordered_map<unsigned int, reg_event_info> event_info_map;
+typedef std::map<int, int> sensor_attribute_int_map;
+typedef std::map<int, std::string> sensor_attribute_str_map;
class sensor_handle_info {
public:
sensor_accuracy_changed_cb_t m_accuracy_cb;
void *m_accuracy_user_data;
bool m_passive;
+ sensor_attribute_int_map attributes_int;
+ sensor_attribute_str_map attributes_str;
private:
event_info_map m_reg_event_infos;