sensord_disconnect(*it_handle);
++it_handle;
}
+
+ sensor_event_listener::get_instance().clear();
}
static int get_power_save_state(void)
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();
+ const char *value = it->second->get();
+ 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 -EPERM;
}
- sensor_client_info::get_instance().set_attribute(handle, attribute, value);
+ sensor_client_info::get_instance().set_attribute(handle, attribute, value, value_len);
return OP_SUCCESS;
}
return true;
}
-bool sensor_client_info::set_attribute(int handle, int attribute, std::string value)
+bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int value_len)
{
AUTOLOCK(m_handle_info_lock);
return false;
}
- it_handle->second.attributes_str[attribute] = value;
+ auto it_attribute = it_handle->second.attributes_str.find(attribute);
+
+ if (it_attribute != it_handle->second.attributes_str.end()) {
+ it_attribute->second->set(value, value_len);
+ return true;
+ }
+
+ attribute_info *info = new(std::nothrow) attribute_info();
+ retvm_if(!info, false, "Failed to allocate memory");
+
+ info->set(value, value_len);
+ it_handle->second.attributes_str[attribute] = info;
return true;
}
void sensor_client_info::clear(void)
{
+ auto it_handle = m_sensor_handle_infos.begin();
+
+ while (it_handle != m_sensor_handle_infos.end())
+ it_handle->second.clear();
+
close_command_channel();
m_sensor_handle_infos.clear();
m_command_channels.clear();
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_attribute(int handle, int attribute, const char *value, int value_len);
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);
unsigned long long sensor_handle_info::m_event_id = 0;
+attribute_info::attribute_info()
+: m_attr(NULL)
+, m_len(0)
+{
+}
+
+attribute_info::~attribute_info()
+{
+ if (m_attr) {
+ delete m_attr;
+ m_attr = NULL;
+ }
+ m_len = 0;
+}
+
+bool attribute_info::set(const char *value, unsigned int len)
+{
+ if (m_attr)
+ delete m_attr;
+
+ m_attr = new(std::nothrow) char[len];
+ retvm_if(!m_attr, false, "Failed to allocate memory");
+
+ memcpy(m_attr, value, len);
+ m_len = len;
+
+ return true;
+}
+
+char *attribute_info::get(void)
+{
+ return m_attr;
+}
+
+unsigned int attribute_info::size(void)
+{
+ return m_len;
+}
+
sensor_handle_info::sensor_handle_info()
: m_handle(0)
, m_sensor_id(UNKNOWN_SENSOR)
return true;
}
+void sensor_handle_info::clear(void)
+{
+ sensor_attribute_str_map::iterator it_attribute;
+
+ for (it_attribute = attributes_str.begin(); it_attribute != attributes_str.end(); ++it_attribute)
+ delete it_attribute->second;
+
+ attributes_int.clear();
+ attributes_str.clear();
+}
+
void sensor_handle_info::clear_all_events(void)
{
m_reg_event_infos.clear();
#include <string>
#include <map>
+class attribute_info {
+public:
+ attribute_info();
+ ~attribute_info();
+
+ char *get(void);
+ bool set(const char *value, unsigned int len);
+
+ unsigned int size(void);
+
+private:
+ char *m_attr;
+ unsigned int m_len;
+};
+
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;
+typedef std::map<int, attribute_info *> sensor_attribute_str_map;
class sensor_handle_info {
public:
void get_batch(unsigned int &interval, unsigned int &latency);
unsigned int get_reg_event_count(void);
+ void clear(void);
void clear_all_events(void);
static unsigned long long renew_event_id(void);