return change_attribute_int(handle, attribute, value);
}
-API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len)
+API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
{
sensor_id_t sensor_id;
command_channel *cmd_channel;
return -EPERM;
}
- retvm_if((value_len < 0) || (value == NULL), -EINVAL,
+ retvm_if((len < 0) || (value == NULL), -EINVAL,
"Invalid value_len: %d, value: %#x, handle: %d, %s, %s",
- value_len, value, handle, get_sensor_name(sensor_id), get_client_name());
+ len, value, handle, get_sensor_name(sensor_id), get_client_name());
client_id = sensor_client_info::get_instance().get_client_id();
retvm_if((client_id < 0), -EPERM,
"Invalid client id : %d, handle: %d, %s, %s",
client_id, handle, get_sensor_name(sensor_id), get_client_name());
- if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) {
+ if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) {
_E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s",
- client_id, value_len, value, get_client_name());
+ client_id, len, value, get_client_name());
return -EPERM;
}
- sensor_client_info::get_instance().set_attribute(handle, attribute, value, value_len);
+ sensor_client_info::get_instance().set_attribute(handle, attribute, value, len);
return OP_SUCCESS;
}
return true;
}
-bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int value_len)
+bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int len)
{
AUTOLOCK(m_handle_info_lock);
return false;
}
- auto it_attribute = it_handle->second.attributes_str.find(attribute);
+ auto it_attr = it_handle->second.attributes_str.find(attribute);
- if (it_attribute != it_handle->second.attributes_str.end()) {
- it_attribute->second->set(value, value_len);
+ if (it_attr != it_handle->second.attributes_str.end()) {
+ it_attr->second->set(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);
+ info->set(value, len);
it_handle->second.attributes_str[attribute] = info;
return true;
bool set_passive_mode(int handle, bool passive);
bool set_attribute(int handle, int attribute, int value);
- bool set_attribute(int handle, int attribute, const char *value, int value_len);
+ bool set_attribute(int handle, int attribute, const char *value, int 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);
m_len = 0;
}
-bool attribute_info::set(const char *value, unsigned int len)
+bool attribute_info::set(const char *value, int len)
{
+ retvm_if(len < 0, false, "Invalid length");
+
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);
+ memcpy(m_attr, value, (unsigned int)len);
m_len = len;
return true;
void sensor_handle_info::clear(void)
{
- sensor_attribute_str_map::iterator it_attribute;
+ sensor_attribute_str_map::iterator it_attr;
- for (it_attribute = attributes_str.begin(); it_attribute != attributes_str.end(); ++it_attribute)
- delete it_attribute->second;
+ for (it_attr = attributes_str.begin(); it_attr != attributes_str.end(); ++it_attr)
+ delete it_attr->second;
attributes_int.clear();
attributes_str.clear();
~attribute_info();
char *get(void);
- bool set(const char *value, unsigned int len);
+ bool set(const char *value, int len);
unsigned int size(void);
ret = inst->dispatch_command(header.cmd, payload);
delete[] payload;
-
return ret;
}