#include "sensor_reader.h"
-#define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
+#define CONVERT_OPTION_TO_PAUSE_POLICY(option) ((option) ^ 0b11)
#define MAX_LISTENER 100
using namespace sensor;
listener = it->second;
- pause = CONVERT_OPTION_PAUSE_POLICY(option);
+ pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
prev_pause = listener->get_pause_policy();
if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
listener = it->second;
- pause = CONVERT_OPTION_PAUSE_POLICY(option);
+ pause = CONVERT_OPTION_TO_PAUSE_POLICY(option);
if (listener->set_attribute(SENSORD_ATTRIBUTE_PAUSE_POLICY, pause) < 0) {
_E("Failed to set option[%d(%d)] to listener", option, pause);
if (m_listener->get_attribute_int_changed_handler()) {
m_listener->get_attribute_int_changed_handler()->read(ch, msg);
}
-
- cmd_listener_attr_int_t* buf = (cmd_listener_attr_int_t*) msg.body();
- m_listener->update_attribute(buf->attribute, buf->value);
} break;
case CMD_LISTENER_SET_ATTR_STR: {
if (m_listener->get_attribute_str_changed_handler()) {
m_listener->get_attribute_str_changed_handler()->read(ch, msg);
}
-
- cmd_listener_attr_str_t* buf = (cmd_listener_attr_str_t*) msg.body();
- m_listener->update_attribute(buf->attribute, buf->value, buf->len);
} break;
default:
_W("Invalid command message");
auto interval = m_attributes_int.find(SENSORD_ATTRIBUTE_INTERVAL);
if (interval != m_attributes_int.end())
- set_interval( m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL]);
+ set_interval(m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL]);
auto latency = m_attributes_int.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY);
if (latency != m_attributes_int.end())
- set_max_batch_latency( m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]);
+ set_max_batch_latency(m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY]);
_D("Restored listener[%d]", get_id());
}
auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_INTERVAL);
retv_if(it == m_attributes_int.end(), -1);
- return m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL];
+ return m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL];
}
int sensor_listener::get_max_batch_latency(void)
auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY);
retv_if(it == m_attributes_int.end(), -1);
- return m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY];
+ return m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY];
}
int sensor_listener::get_pause_policy(void)
auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_PAUSE_POLICY);
retv_if(it == m_attributes_int.end(), -1);
- return m_attributes_int[SENSORD_ATTRIBUTE_PAUSE_POLICY];
+ return m_attributes_int[SENSORD_ATTRIBUTE_PAUSE_POLICY];
}
int sensor_listener::get_passive_mode(void)
auto it = m_attributes_int.find(SENSORD_ATTRIBUTE_PASSIVE_MODE);
retv_if(it == m_attributes_int.end(), -1);
- return m_attributes_int[SENSORD_ATTRIBUTE_PASSIVE_MODE];
+ return m_attributes_int[SENSORD_ATTRIBUTE_PASSIVE_MODE];
}
int sensor_listener::set_interval(unsigned int interval)
/* If it is not started, store the value only */
if (!m_started.load()) {
- m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL] = _interval;
+ m_attributes_int[SENSORD_ATTRIBUTE_INTERVAL] = _interval;
return OP_SUCCESS;
}
/* If it is not started, store the value only */
if (!m_started.load()) {
- m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency;
+ m_attributes_int[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency;
return OP_SUCCESS;
}
int sensor_listener::get_attribute(int attribute, int* value)
{
- auto it = m_attributes_int.find(attribute);
- if (it == m_attributes_int.end()) {
- ipc::message msg;
- ipc::message reply;
- cmd_listener_attr_int_t buf;
+ ipc::message msg;
+ ipc::message reply;
+ cmd_listener_attr_int_t buf;
- buf.listener_id = m_id;
- buf.attribute = attribute;
+ retvm_if(!m_cmd_channel, -EIO, "Failed to connect to server");
- msg.set_type(CMD_LISTENER_GET_ATTR_INT);
- msg.enclose((char *)&buf, sizeof(buf));
- m_cmd_channel->send_sync(msg);
+ buf.listener_id = m_id;
+ buf.attribute = attribute;
+ msg.set_type(CMD_LISTENER_GET_ATTR_INT);
+ msg.enclose((char *)&buf, sizeof(buf));
- m_cmd_channel->read_sync(reply);
+ m_cmd_channel->send_sync(msg);
+ m_cmd_channel->read_sync(reply);
- if (reply.header()->err < 0) {
- return reply.header()->err;
- }
- if (reply.header()->length && reply.body()) {
- update_attribute(attribute, ((cmd_listener_attr_int_t *)reply.body())->value);
- }
+ if (reply.header()->err < 0) {
+ return reply.header()->err;
}
- *value = m_attributes_int[attribute];
- return OP_SUCCESS;
+ if (reply.header()->length && reply.body()) {
+ *value = ((cmd_listener_attr_int_t *)reply.body())->value;
+ return OP_SUCCESS;
+ }
+
+ return OP_ERROR;
}
void sensor_listener::update_attribute(int attribute, int value)
{
+ AUTOLOCK(lock);
m_attributes_int[attribute] = value;
- _I("listener[%d]'s attribues(int) size : %d", get_id(), m_attributes_int.size());
+ _I("Update_attribute(int) listener[%d] attribute[%d] value[%d] attributes size[%d]", get_id(), attribute, value, m_attributes_int.size());
}
int sensor_listener::set_attribute(int attribute, const char *value, int len)
int sensor_listener::get_attribute(int attribute, char **value, int* len)
{
- auto it = m_attributes_str.find(attribute);
- if (it == m_attributes_str.end()) {
- ipc::message msg;
- ipc::message reply;
- cmd_listener_attr_str_t buf;
-
- buf.listener_id = m_id;
- buf.attribute = attribute;
+ ipc::message msg;
+ ipc::message reply;
+ cmd_listener_attr_str_t buf;
- msg.set_type(CMD_LISTENER_GET_ATTR_STR);
- msg.enclose((char *)&buf, sizeof(buf));
- m_cmd_channel->send_sync(msg);
+ buf.listener_id = m_id;
+ buf.attribute = attribute;
- m_cmd_channel->read_sync(reply);
- if (reply.header()->err < 0) {
- return reply.header()->err;
- }
+ msg.set_type(CMD_LISTENER_GET_ATTR_STR);
+ msg.enclose((char *)&buf, sizeof(buf));
+ m_cmd_channel->send_sync(msg);
- if (reply.header()->length && reply.body()) {
- cmd_listener_attr_str_t * recv_buf = (cmd_listener_attr_str_t *)reply.body();
- update_attribute(attribute, (char *)recv_buf->value, recv_buf->len);
- }
+ m_cmd_channel->read_sync(reply);
+ if (reply.header()->err < 0) {
+ return reply.header()->err;
}
- *len = m_attributes_str[attribute].size();
- *value = (char *) malloc(*len);
- std::copy(m_attributes_str[attribute].begin(), m_attributes_str[attribute].end(), *value);
+ if (reply.header()->length && reply.body()) {
+ cmd_listener_attr_str_t * recv_buf = (cmd_listener_attr_str_t *)reply.body();
+ char* p = (char *)recv_buf->value;
+ *len = recv_buf->len;
+ *value = (char *) malloc(*len);
+ std::copy(p, p + recv_buf->len, *value);
+ return OP_SUCCESS;
+ }
- return OP_SUCCESS;
+ return OP_ERROR;
}
void sensor_listener::update_attribute(int attribute, const char *value, int len)
{
+ AUTOLOCK(lock);
m_attributes_str[attribute].clear();
m_attributes_str[attribute].insert(m_attributes_str[attribute].begin(), value, value + len);
- _I("listener[%d]'s attribues(str) size : %d", get_id(), m_attributes_str.size());
+ _I("Update_attribute(str) listener[%d] attribute[%d] value[%s] attributes size[%zu]", get_id(), attribute, value, m_attributes_int.size());
}
int sensor_listener::get_sensor_data(sensor_data_t *data)
return true;
}
+TESTCASE(sensor_listener, set_get_attribute_int_3)
+{
+ int err = 0;
+ bool ret = true;
+ int handle = 0;
+ sensor_t sensor = NULL;
+ int attr = 20;
+ int value = -1;
+
+ err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor);
+ ASSERT_EQ(err, 0);
+
+ handle = sensord_connect(sensor);
+
+ err = sensord_set_attribute_int(handle, attr, 1);
+ ASSERT_EQ(err, 0);
+
+ for (int i = 0 ; i < 10; i ++) {
+ err = sensord_get_attribute_int(handle, attr, &value);
+ ASSERT_EQ(err, 0);
+ }
+
+ ASSERT_EQ(value, 1);
+
+ ret = sensord_disconnect(handle);
+ ASSERT_TRUE(ret);
+
+ return true;
+}
+
TESTCASE(sensor_listener, get_attribute_int_1)
{
int err = 0;
return true;
}
+TESTCASE(sensor_listener, set_get_attribute_string_3)
+{
+ int err = 0;
+ bool ret = true;
+ int handle = 0;
+ char *value = NULL;
+ int len = 0;
+ sensor_t sensor = NULL;
+ int attr = 1;
+
+ err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor);
+ ASSERT_EQ(err, 0);
+
+ handle = sensord_connect(sensor);
+ err = sensord_set_attribute_str(handle, attr, TEST_STRING, TEST_STRING_LEN);
+ ASSERT_EQ(err, 0);
+
+ for (int i = 0; i < 10; i++) {
+ err = sensord_get_attribute_str(handle, attr, &value, &len);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(len, TEST_STRING_LEN);
+ ASSERT_EQ(strncmp(value, TEST_STRING, len), 0);
+ }
+
+ ret = sensord_disconnect(handle);
+ ASSERT_TRUE(ret);
+
+ free(value);
+ return true;
+}
+
TESTCASE(sensor_listener, set_get_get_attribute_string_1)
{
int err;
ret = sensord_stop(handle);
ASSERT_TRUE(ret);
- ret = sensord_unregister_attribute_int_changed_cb(handle);
+ ret = sensord_unregister_attribute_str_changed_cb(handle);
ASSERT_TRUE(ret);
ret = sensord_disconnect(handle);
ASSERT_TRUE(ret);
return true;
-}
\ No newline at end of file
+}
+
+TESTCASE(skip_sensor_listener, light_sensor_set_attribute_int_1)
+{
+ int err = 0;
+ bool ret = true;
+ int handle = 0;
+ sensor_t sensor = NULL;
+ int attr = 2;
+ int value = 0;
+
+ err = sensord_get_default_sensor(LIGHT_SENSOR, &sensor);
+ ASSERT_EQ(err, 0);
+
+ handle = sensord_connect(sensor);
+ err = sensord_set_attribute_int(handle, attr, 2);
+ ASSERT_EQ(err, 0);
+
+ err = sensord_get_attribute_int(handle, attr, &value);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(value, 2);
+
+ ret = sensord_disconnect(handle);
+ ASSERT_TRUE(ret);
+
+ return true;
+}
+
+TESTCASE(skip_sensor_listener, light_sensor_get_attribute_int_1)
+{
+ int err = 0;
+ bool ret = true;
+ int handle = 0;
+ sensor_t sensor = NULL;
+ int attr = 2;
+ int value = 0;
+
+ err = sensord_get_default_sensor(LIGHT_SENSOR, &sensor);
+ ASSERT_EQ(err, 0);
+
+ handle = sensord_connect(sensor);
+ err = sensord_get_attribute_int(handle, attr, &value);
+ ASSERT_EQ(err, 0);
+ ASSERT_EQ(value, 2);
+
+ ret = sensord_disconnect(handle);
+ ASSERT_TRUE(ret);
+
+ return true;
+}
: sensor_handler(info)
, m_ch(ch)
, m_started(false)
-, m_prev_interval(0)
{
}
msg.enclose((const char *)&buf, sizeof(cmd_provider_attr_int_t));
m_ch->send_sync(msg);
- m_prev_interval = cur_interval;
-
- _I("Set interval[%d] to sensor[%s]", cur_interval, m_info.get_uri().c_str());
+ update_prev_interval(cur_interval);
+ return OP_SUCCESS;
+}
+int application_sensor_handler::get_interval(sensor_observer *ob, int32_t& interval)
+{
+ interval = m_prev_interval;
return OP_SUCCESS;
}
int application_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t latency)
{
+ update_prev_latency(latency);
+ return OP_SUCCESS;
+}
+
+int application_sensor_handler::get_batch_latency(sensor_observer *ob, int32_t &latency)
+{
+ latency = m_prev_latency;
return OP_SUCCESS;
}
int stop(sensor_observer *ob);
int set_interval(sensor_observer *ob, int32_t interval);
+ int get_interval(sensor_observer *ob, int32_t& interval);
int set_batch_latency(sensor_observer *ob, int32_t latency);
+ int get_batch_latency(sensor_observer *ob, int32_t &latency);
int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
int flush(sensor_observer *ob);
private:
ipc::channel *m_ch;
std::atomic<bool> m_started;
- int32_t m_prev_interval;
int get_min_interval(void);
std::vector<sensor_handler *> m_required_sensors;
std::unordered_map<sensor_observer *, int> m_interval_map;
+
};
}
retv_if(m_policy <= OP_ERROR, m_policy);
}
- m_interval_map[ob] = interval;
+ m_interval_map[ob] = _interval;
+ int ret = OP_SUCCESS;
if (m_policy == OP_DEFAULT && observer_count() > 0) {
_interval = get_min_interval();
- return m_sensor->set_interval(ob, _interval);
+ ret = m_sensor->set_interval(ob, _interval);
}
- _I("Set interval[%d] to sensor[%s]", _interval, m_info.get_uri().c_str());
+ update_prev_interval(_interval);
+ return ret;
+}
+int external_sensor_handler::get_interval(sensor_observer *ob, int32_t& interval)
+{
+ retv_if(!m_sensor, -EINVAL);
+ interval = m_prev_interval;
return OP_SUCCESS;
}
m_batch_latency_map[ob] = _latency;
+ int ret = OP_SUCCESS;
if (m_policy == OP_DEFAULT && observer_count() > 0) {
_latency = get_min_batch_latency();
- return m_sensor->set_batch_latency(ob, latency);
+ ret = m_sensor->set_batch_latency(ob, latency);
}
+
+ update_prev_latency(_latency);
+ return ret;
+}
+
+int external_sensor_handler::get_batch_latency(sensor_observer *ob, int32_t &latency)
+{
+ retv_if(!m_sensor, -EINVAL);
+ latency = m_prev_latency;
return OP_SUCCESS;
}
int stop(sensor_observer *ob);
int set_interval(sensor_observer *ob, int32_t interval);
+ int get_interval(sensor_observer *ob, int32_t& interval);
+
int set_batch_latency(sensor_observer *ob, int32_t latency);
+ int get_batch_latency(sensor_observer *ob, int32_t &latency);
+
int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
int flush(sensor_observer *ob);
policy = m_sensor->set_interval(ob, _interval);
retv_if(policy <= OP_ERROR, policy);
- m_interval_map[ob] = interval;
+ m_interval_map[ob] = _interval;
if (policy == OP_DEFAULT)
_interval = get_min_interval();
- _I("Set interval[%d] to sensor[%s]", _interval, m_info.get_uri().c_str());
+ update_prev_interval(_interval);
return set_interval_internal(_interval);
}
+int fusion_sensor_handler::get_interval(sensor_observer *ob, int32_t& interval)
+{
+ retv_if(!m_sensor, -EINVAL);
+
+ interval = m_prev_interval;
+ return OP_SUCCESS;
+}
+
int fusion_sensor_handler::get_min_batch_latency(void)
{
int batch_latency;
if (policy == OP_DEFAULT)
_latency = get_min_batch_latency();
+ update_prev_latency(_latency);
+
return set_batch_latency_internal(_latency);
}
+int fusion_sensor_handler::get_batch_latency(sensor_observer *ob, int32_t &latency)
+{
+ retv_if(!m_sensor, -EINVAL);
+
+ latency = m_prev_latency;
+ return OP_SUCCESS;
+}
+
int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int32_t value)
{
retv_if(!m_sensor, -EINVAL);
int stop(sensor_observer *ob);
int set_interval(sensor_observer *ob, int32_t interval);
+ int get_interval(sensor_observer *ob, int32_t& interval);
+
int set_batch_latency(sensor_observer *ob, int32_t latency);
+ int get_batch_latency(sensor_observer *ob, int32_t &latency);
+
int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
int flush(sensor_observer *ob);
, m_device(device)
, m_sensor(sensor)
, m_hal_id(hal_id)
-, m_prev_interval(0)
-, m_prev_latency(0)
{
}
ret = m_device->set_interval(m_hal_id, cur_interval);
- m_prev_interval = cur_interval;
-
- _I("Set interval[%d] to sensor[%s]", cur_interval, m_info.get_uri().c_str());
+ update_prev_interval(cur_interval);
return (ret ? OP_SUCCESS : OP_ERROR);
}
+int physical_sensor_handler::get_interval(sensor_observer *ob, int32_t& interval)
+{
+ retv_if(!m_device, -EINVAL);
+ interval = m_prev_interval;
+ return OP_SUCCESS;
+}
+
int physical_sensor_handler::get_min_batch_latency(void)
{
int batch_latency;
ret = m_device->set_batch_latency(m_hal_id, cur_latency);
- m_prev_latency = cur_latency;
-
- _I("Set batch latency[%d] to sensor[%s]", cur_latency, m_info.get_uri().c_str());
+ update_prev_latency(cur_latency);
return (ret ? OP_SUCCESS : OP_ERROR);
}
+int physical_sensor_handler::get_batch_latency(sensor_observer *ob, int32_t &latency)
+{
+ retv_if(!m_device, -EINVAL);
+ latency = m_prev_latency;
+ return OP_SUCCESS;
+}
+
int physical_sensor_handler::delete_batch_latency(sensor_observer *ob)
{
bool ret = false;
int stop(sensor_observer *ob);
int set_interval(sensor_observer *ob, int32_t interval);
+ int get_interval(sensor_observer *ob, int32_t& interval);
+
int set_batch_latency(sensor_observer *ob, int32_t latency);
+ int get_batch_latency(sensor_observer *ob, int32_t &latency);
+
int delete_batch_latency(sensor_observer *ob);
int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
sensor_device *m_device;
physical_sensor *m_sensor;
uint32_t m_hal_id;
- int32_t m_prev_interval;
- int32_t m_prev_latency;
std::unordered_map<sensor_observer *, int> m_interval_map;
std::unordered_map<sensor_observer *, int> m_batch_latency_map;
sensor_handler::sensor_handler(const sensor_info &info)
: m_info(info)
+, m_prev_interval(0)
+, m_prev_latency(0)
+, m_need_to_notify_attribute_changed(false)
{
const char *priv = sensor::utils::get_privilege(m_info.get_uri());
m_info.set_privilege(priv);
return 0;
}
-bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, int value)
+bool sensor_handler::notify_attribute_changed(uint32_t id, int32_t attribute, int32_t value)
{
if (observer_count() == 0)
return OP_ERROR;
return OP_SUCCESS;
}
-bool sensor_handler::notify_attribute_changed(uint32_t id, int attribute, const char *value, int len)
+bool sensor_handler::notify_attribute_changed(uint32_t id, int32_t attribute, const char *value, int len)
{
if (observer_count() == 0)
return OP_ERROR;
sensor_listener_proxy *proxy = NULL;
for (auto it = m_observers.begin(); it != m_observers.end(); ++it) {
proxy = dynamic_cast<sensor_listener_proxy *>(*it);
- if (proxy && proxy->get_id() != id) {
+ if (proxy) {
proxy->on_attribute_changed(msg);
}
}
void sensor_handler::update_attribute(int32_t attr, int32_t value)
{
- m_attributes_int[attr] = value;
- _I("[%s] attributes(int) size : %d", m_info.get_uri().c_str(), m_attributes_int.size());
+ auto it = m_attributes_int.find(attr);
+ if(it != m_attributes_int.end()) {
+ if (it->second != value) {
+ set_need_to_notify_attribute_changed(true);
+ }
+ } else {
+ set_need_to_notify_attribute_changed(true);
+ }
+ if (need_to_notify_attribute_changed()) {
+ m_attributes_int[attr] = value;
+ _I("[%s] attributes(int) attr[%d] value[%d] attributes size[%zu]", m_info.get_uri().c_str(), attr, value, m_attributes_int.size());
+ }
}
int sensor_handler::get_attribute(int32_t attr, char **value, int *len)
void sensor_handler::update_attribute(int32_t attr, const char *value, int len)
{
- m_attributes_str[attr].clear();
- m_attributes_str[attr].insert(m_attributes_str[attr].begin(), value, value + len);
- _I("[%s] attributes(int) size : %d", m_info.get_uri().c_str(), m_attributes_int.size());
+ auto it = m_attributes_str.find(attr);
+ if(it != m_attributes_str.end()) {
+ if (it->second.size() != (size_t)len) {
+ set_need_to_notify_attribute_changed(true);
+ } else {
+ for(int i = 0 ; i < len; i++) {
+ if (value[i] != it->second[i]) {
+ set_need_to_notify_attribute_changed(true);
+ break;
+ }
+ }
+ }
+ } else {
+ set_need_to_notify_attribute_changed(true);
+ }
+ if (need_to_notify_attribute_changed()) {
+ m_attributes_str[attr].clear();
+ m_attributes_str[attr].insert(m_attributes_str[attr].begin(), value, value + len);
+ _I("[%s] attributes(int) attr[%d] value[%s] attributes size[%zu]", m_info.get_uri().c_str(), attr, value, m_attributes_str.size());
+ }
+}
-}
\ No newline at end of file
+bool sensor_handler::need_to_notify_attribute_changed()
+{
+ return m_need_to_notify_attribute_changed;
+}
+
+void sensor_handler::set_need_to_notify_attribute_changed(bool value)
+{
+ m_need_to_notify_attribute_changed = value;
+}
+
+void sensor_handler::update_prev_interval(int32_t interval)
+{
+ if (m_prev_interval != interval) {
+ m_prev_interval = interval;
+ set_need_to_notify_attribute_changed(true);
+ _I("Set interval[%d] to sensor[%s]", m_prev_interval, m_info.get_uri().c_str());
+ }
+}
+
+void sensor_handler::update_prev_latency(int32_t latency)
+{
+ if (m_prev_latency != latency) {
+ m_prev_latency = latency;
+ set_need_to_notify_attribute_changed(true);
+ _I("Set interval[%d] to sensor[%s]", m_prev_latency, m_info.get_uri().c_str());
+ }
+}
virtual int stop(sensor_observer *ob) = 0;
virtual int set_interval(sensor_observer *ob, int32_t interval) = 0;
+ virtual int get_interval(sensor_observer *ob, int32_t &interval) = 0;
+
virtual int set_batch_latency(sensor_observer *ob, int32_t latency) = 0;
+ virtual int get_batch_latency(sensor_observer *ob, int32_t &latency) = 0;
+
virtual int delete_batch_latency(sensor_observer *ob);
virtual int set_attribute(sensor_observer *ob, int32_t attr, int32_t value) = 0;
virtual int get_attribute(int32_t attr, int32_t* value);
void set_cache(sensor_data_t *data, int size);
int get_cache(sensor_data_t **data, int *len);
- bool notify_attribute_changed(uint32_t id, int attribute, int value);
- bool notify_attribute_changed(uint32_t id, int attribute, const char *value, int len);
-
+ bool notify_attribute_changed(uint32_t id, int32_t attribute, int32_t value);
+ bool notify_attribute_changed(uint32_t id, int32_t attribute, const char *value, int len);
+ bool need_to_notify_attribute_changed();
+ void set_need_to_notify_attribute_changed(bool value);
protected:
+ void update_prev_interval(int32_t interval);
+ void update_prev_latency(int32_t latency);
+
sensor_info m_info;
+ int32_t m_prev_interval;
+ int32_t m_prev_latency;
+
std::map<int32_t, int32_t> m_attributes_int;
std::map<int32_t, std::vector<char>> m_attributes_str;
+ bool m_need_to_notify_attribute_changed;
private:
std::list<sensor_observer *> m_observers;
, m_pause_policy(SENSORD_PAUSE_ALL)
, m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED)
, m_last_accuracy(SENSOR_ACCURACY_UNDEFINED)
+, m_need_to_notify_attribute_changed(false)
{
sensor_policy_monitor::get_instance().add_listener(this);
}
return OP_SUCCESS;
}
-int sensor_listener_proxy::set_interval(unsigned int interval)
+int sensor_listener_proxy::set_interval(int32_t interval)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
_D("Listener[%d] try to set interval[%d]", get_id(), interval);
- return sensor->set_interval(this, interval);
+ int ret = sensor->set_interval(this, interval);
+ apply_sensor_handler_need_to_notify_attribute_changed(sensor);
+
+ return ret;
+}
+
+int sensor_listener_proxy::get_interval(int32_t& interval)
+{
+ sensor_handler *sensor = m_manager->get_sensor(m_uri);
+ retv_if(!sensor, -EINVAL);
+
+ _D("Listener[%d] try to get interval[%d]", get_id());
+
+ return sensor->get_interval(this, interval);
}
-int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency)
+int sensor_listener_proxy::set_max_batch_latency(int32_t max_batch_latency)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
_D("Listener[%d] try to set max batch latency[%d]", get_id(), max_batch_latency);
+ int ret = sensor->set_batch_latency(this, max_batch_latency);
+ apply_sensor_handler_need_to_notify_attribute_changed(sensor);
- return sensor->set_batch_latency(this, max_batch_latency);
+ return ret;
+}
+
+int sensor_listener_proxy::get_max_batch_latency(int32_t& max_batch_latency)
+{
+ sensor_handler *sensor = m_manager->get_sensor(m_uri);
+ retv_if(!sensor, -EINVAL);
+
+ _D("Listener[%d] try to get max batch latency[%d]", get_id());
+
+ return sensor->get_batch_latency(this, max_batch_latency);
}
int sensor_listener_proxy::delete_batch_latency(void)
return OP_SUCCESS;
}
-int sensor_listener_proxy::set_attribute(int attribute, int value)
+int sensor_listener_proxy::set_attribute(int32_t attribute, int32_t value)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
_D("Listener[%d] try to set attribute[%d, %d]", get_id(), attribute, value);
if (attribute == SENSORD_ATTRIBUTE_PAUSE_POLICY) {
- m_pause_policy = value;
+ if (m_pause_policy != value) {
+ m_pause_policy = value;
+ set_need_to_notify_attribute_changed(true);
+ }
return OP_SUCCESS;
} else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) {
- m_axis_orientation = value;
+ if (m_axis_orientation != value) {
+ m_axis_orientation = value;
+ set_need_to_notify_attribute_changed(true);
+ }
return OP_SUCCESS;
} else if (attribute == SENSORD_ATTRIBUTE_FLUSH) {
return flush();
}
- return sensor->set_attribute(this, attribute, value);
+ int ret = sensor->set_attribute(this, attribute, value);
+ apply_sensor_handler_need_to_notify_attribute_changed(sensor);
+
+ return ret;
}
-int sensor_listener_proxy::get_attribute(int attribute, int *value)
+int sensor_listener_proxy::get_attribute(int32_t attribute, int32_t *value)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
return sensor->get_attribute(attribute, value);
}
-int sensor_listener_proxy::set_attribute(int attribute, const char *value, int len)
+int sensor_listener_proxy::set_attribute(int32_t attribute, const char *value, int len)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
_D("Listener[%d] try to set string attribute[%d], len[%d]", get_id(), attribute, len);
- return sensor->set_attribute(this, attribute, value, len);
+ int ret = sensor->set_attribute(this, attribute, value, len);
+ apply_sensor_handler_need_to_notify_attribute_changed(sensor);
+
+ return ret;
}
-int sensor_listener_proxy::get_attribute(int attribute, char **value, int *len)
+int sensor_listener_proxy::get_attribute(int32_t attribute, char **value, int *len)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
start(true);
}
-bool sensor_listener_proxy::notify_attribute_changed(int attribute, int value)
+bool sensor_listener_proxy::notify_attribute_changed(int32_t attribute, int32_t value)
{
sensor_handler *sensor = m_manager->get_sensor(m_uri);
retv_if(!sensor, -EINVAL);
retv_if(!sensor, -EINVAL);
return sensor->notify_attribute_changed(m_id, attribute, value, len);
-}
\ No newline at end of file
+}
+
+bool sensor_listener_proxy::need_to_notify_attribute_changed()
+{
+ return m_need_to_notify_attribute_changed;
+}
+
+void sensor_listener_proxy::set_need_to_notify_attribute_changed(bool value)
+{
+ m_need_to_notify_attribute_changed = value;
+}
+
+void sensor_listener_proxy::apply_sensor_handler_need_to_notify_attribute_changed(sensor_handler *handler)
+{
+ set_need_to_notify_attribute_changed(handler->need_to_notify_attribute_changed());
+ handler->set_need_to_notify_attribute_changed(false);
+}
int start(bool policy = false);
int stop(bool policy = false);
- int set_interval(unsigned int interval);
- int set_max_batch_latency(unsigned int max_batch_latency);
+ int set_interval(int32_t interval);
+ int get_interval(int32_t& interval);
+ int set_max_batch_latency(int32_t max_batch_latency);
+ int get_max_batch_latency(int32_t& max_batch_latency);
int delete_batch_latency(void);
int set_passive_mode(bool passive);
- int set_attribute(int attribute, int value);
- int get_attribute(int attribute, int *value);
- int set_attribute(int attribute, const char *value, int len);
- int get_attribute(int attribute, char **value, int *len);
+ int set_attribute(int32_t attribute, int32_t value);
+ int get_attribute(int32_t attribute, int32_t *value);
+ int set_attribute(int32_t attribute, const char *value, int len);
+ int get_attribute(int32_t attribute, char **value, int *len);
int flush(void);
int get_data(sensor_data_t **data, int *len);
std::string get_required_privileges(void);
/* sensor_policy_listener interface */
void on_policy_changed(int policy, int value);
- bool notify_attribute_changed(int attribute, int value);
- bool notify_attribute_changed(int attribute, const char *value, int len);
+ bool notify_attribute_changed(int32_t attribute, int32_t value);
+ bool notify_attribute_changed(int32_t attribute, const char *value, int len);
+ bool need_to_notify_attribute_changed();
+ void set_need_to_notify_attribute_changed(bool value);
private:
void update_event(std::shared_ptr<ipc::message> msg);
void update_accuracy(std::shared_ptr<ipc::message> msg);
+ void apply_sensor_handler_need_to_notify_attribute_changed(sensor_handler* handler);
uint32_t m_id;
std::string m_uri;
bool m_started;
bool m_passive;
- int m_pause_policy;
- int m_axis_orientation;
- int m_last_accuracy;
+ int32_t m_pause_policy;
+ int32_t m_axis_orientation;
+ int32_t m_last_accuracy;
+ bool m_need_to_notify_attribute_changed;
};
}
case SENSORD_ATTRIBUTE_AXIS_ORIENTATION:
default:
ret = m_listeners[id]->set_attribute(buf.attribute, buf.value);
- if (ret == OP_SUCCESS) {
- need_notify = true;
- }
}
/* TODO : check return value */
if (ret < 0)
ret = send_reply(ch, OP_SUCCESS);
- if (need_notify) {
+ if (m_listeners[id]->need_to_notify_attribute_changed()) {
m_listeners[id]->notify_attribute_changed(buf.attribute, buf.value);
+ m_listeners[id]->set_need_to_notify_attribute_changed(false);
}
return ret;
}
ret = send_reply(ch, OP_SUCCESS);
- m_listeners[id]->notify_attribute_changed(buf->attribute, buf->value, buf->len);
+
+ if (m_listeners[id]->need_to_notify_attribute_changed()) {
+ m_listeners[id]->notify_attribute_changed(buf->attribute, buf->value, buf->len);
+ m_listeners[id]->set_need_to_notify_attribute_changed(false);
+ }
delete [] buf;
return ret;
cmd_listener_attr_int_t buf;
msg.disclose((char *)&buf);
uint32_t id = buf.listener_id;
-
+ int attr = buf.attribute;
+ int value = 0;
int ret = OP_SUCCESS;
auto it = m_listeners.find(id);
-EACCES, "Permission denied[%d, %s]",
id, m_listeners[id]->get_required_privileges().c_str());
- switch (buf.attribute) {
+ switch (attr) {
case SENSORD_ATTRIBUTE_INTERVAL:
+ ret = m_listeners[id]->get_interval(value); break;
case SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY:
+ ret = m_listeners[id]->get_max_batch_latency(value); break;
case SENSORD_ATTRIBUTE_PASSIVE_MODE:
// TODO : Are these features required?
ret = OP_ERROR;
case SENSORD_ATTRIBUTE_PAUSE_POLICY:
case SENSORD_ATTRIBUTE_AXIS_ORIENTATION:
default:
- ret = m_listeners[id]->get_attribute(buf.attribute, &buf.value);
+ ret = m_listeners[id]->get_attribute(attr, &value);
}
- if (ret == OP_SUCCESS) {
- message reply;
- reply.enclose((char *)&buf, sizeof(buf));
- reply.set_type(CMD_LISTENER_GET_ATTR_INT);
- ret = ch->send_sync(reply);
- } else {
- ret = send_reply(ch, OP_ERROR);
+ if (ret != OP_SUCCESS) {
+ _E("Failed to listener_get_attr_int");
+ return ret;
}
+ message reply;
+ cmd_listener_attr_int_t ret_buf;
- return ret;
+ ret_buf.listener_id = id;
+ ret_buf.attribute = attr;
+ ret_buf.value = value;
+
+ reply.enclose((char *)&ret_buf, sizeof(ret_buf));
+ reply.header()->err = OP_SUCCESS;
+ reply.set_type(CMD_LISTENER_GET_ATTR_INT);
+ ret = ch->send_sync(reply);
+
+ return OP_SUCCESS;
}
int server_channel_handler::listener_get_attr_str(ipc::channel *ch, ipc::message &msg)
int len = 0;
int ret = m_listeners[id]->get_attribute(attr, &value, &len);
- if (ret == OP_SUCCESS) {
- cmd_listener_attr_str_t *reply_buf;
- size_t size = sizeof(cmd_listener_attr_str_t) + len;
- reply_buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size];
- retvm_if(!reply_buf, -ENOMEM, "Failed to allocate memory");
-
- reply_buf->attribute = attr;
- memcpy(reply_buf->value, value, len);
- reply_buf->len = len;
- delete [] value;
-
- ipc::message reply;
- reply.enclose((char *)reply_buf, size);
- reply.set_type(CMD_LISTENER_GET_ATTR_STR);
-
- ret = ch->send_sync(reply);
- delete [] reply_buf;
- } else {
- ret = send_reply(ch, OP_ERROR);
+ if (ret != OP_SUCCESS) {
+ _E("Failed to listener_get_attr_str");
+ return ret;
}
- return ret;
+ cmd_listener_attr_str_t *reply_buf;
+ size_t size = sizeof(cmd_listener_attr_str_t) + len;
+ reply_buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size];
+ retvm_if(!reply_buf, -ENOMEM, "Failed to allocate memory");
+
+ reply_buf->attribute = attr;
+ memcpy(reply_buf->value, value, len);
+ reply_buf->len = len;
+ delete [] value;
+
+ ipc::message reply;
+ reply.enclose((char *)reply_buf, size);
+ reply.set_type(CMD_LISTENER_GET_ATTR_STR);
+
+ ret = ch->send_sync(reply);
+ delete [] reply_buf;
+
+ return OP_SUCCESS;
}
int server_channel_handler::listener_get_data(channel *ch, message &msg)