From 87e0a9d16c46947766927f3fb0ca3e0257ad28ee Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 2 Feb 2016 11:47:00 +0900 Subject: [PATCH] sensord: [2/4] add the refactored HAL interface * sensor_id_t is changed to int64_t type - 0xFFFFFFFF(32bit) : sensor_type - 0xFFFF(16bit) : sensor_id(index from sensord) - 0xFFFF(16bit) : device_id(index from HAL) * it will be changed to union type Change-Id: I2f75d3ed3405d9cf3e6fc5ffcf51bab425d15a87 Signed-off-by: kibak.yoon --- src/client/client_common.cpp | 4 +-- src/client/sensor_client_info.cpp | 4 +-- src/server/command_worker.cpp | 54 +++++++++++++++++++-------------------- src/server/sensor_base.cpp | 16 ++++++------ src/server/sensor_loader.cpp.in | 20 ++++++++++----- src/shared/sensor_info.cpp | 26 ++++++++++++++++--- src/shared/sensor_info.h | 3 +++ src/shared/sensor_logs.cpp | 2 +- src/shared/sensor_logs.h | 3 ++- 9 files changed, 80 insertions(+), 52 deletions(-) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index bc48da0..cc2e919 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -121,7 +121,7 @@ const char* get_log_element_name(log_id id, unsigned int type) const char* get_sensor_name(sensor_id_t sensor_id) { - sensor_type_t sensor_type = (sensor_type_t) (sensor_id & SENSOR_TYPE_MASK); + sensor_type_t sensor_type = (sensor_type_t) (sensor_id >> SENSOR_TYPE_SHIFT); return get_log_element_name(LOG_ID_SENSOR_TYPE, sensor_type); } @@ -185,7 +185,7 @@ unsigned int get_calibration_event_type(unsigned int event_type) { sensor_type_t sensor; - sensor = (sensor_type_t)(event_type >> SENSOR_TYPE_SHIFT); + sensor = (sensor_type_t)(event_type >> EVENT_TYPE_SHIFT); switch (sensor) { default: diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 0917459..bdae177 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -460,7 +460,7 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte } if (!active_sensor_found) { - DBG("Active sensor[0x%x] is not found for client %s", sensor, get_client_name()); + DBG("Active sensor[0x%llx] is not found for client %s", sensor, get_client_name()); return false; } @@ -492,7 +492,7 @@ unsigned int sensor_client_info::get_active_option(sensor_id_t sensor) } if (!active_sensor_found) - DBG("Active sensor[0x%x] is not found for client %s", sensor, get_client_name()); + DBG("Active sensor[0x%llx] is not found for client %s", sensor, get_client_name()); return active_option; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index cd0b628..c550ce3 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -229,7 +229,7 @@ bool command_worker::stopped(void *ctx) if (inst->m_sensor_id) { if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) { - INFO("Removing sensor[0x%x] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); + INFO("Removing sensor[0x%llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id); } } @@ -415,14 +415,14 @@ bool command_worker::cmd_hello(void *payload) } if (!is_permission_allowed()) { - ERR("Permission denied to connect sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Permission denied to connect sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("Hello sensor [0x%x], client id [%d]", m_sensor_id, m_client_id); + DBG("Hello sensor [0x%llx], client id [%d]", m_sensor_id, m_client_id); get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id); - INFO("New sensor record created for sensor [0x%x], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id); + INFO("New sensor record created for sensor [0x%llx], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id); ret_value = OP_SUCCESS; out: if (!send_cmd_done(ret_value)) @@ -436,12 +436,12 @@ bool command_worker::cmd_byebye(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("CMD_BYEBYE for client [%d], sensor [0x%x]", m_client_id, m_sensor_id); + DBG("CMD_BYEBYE for client [%d], sensor [0x%llx]", m_client_id, m_sensor_id); if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) { ERR("Error removing sensor_record for client [%d]", m_client_id); @@ -467,12 +467,12 @@ bool command_worker::cmd_start(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to start sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Permission denied to start sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("START Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id); + DBG("START Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id); if (m_module->start()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, true); @@ -484,7 +484,7 @@ bool command_worker::cmd_start(void *payload) get_event_dispathcher().request_last_event(m_client_id, m_sensor_id); ret_value = OP_SUCCESS; } else { - ERR("Failed to start sensor [0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Failed to start sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -500,18 +500,18 @@ bool command_worker::cmd_stop(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("STOP Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id); + DBG("STOP Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id); if (m_module->stop()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, false); ret_value = OP_SUCCESS; } else { - ERR("Failed to stop sensor [0x%x] for client [%d]", m_sensor_id, m_client_id); + ERR("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -595,28 +595,28 @@ bool command_worker::cmd_set_batch(void *payload) cmd = (cmd_set_batch_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager", + ERR("Permission denied to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager", m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) { - ERR("Failed to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager", + ERR("Failed to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager", m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } if (!m_module->add_interval(m_client_id, cmd->interval, false)) { - ERR("Failed to set interval for client [%d], for sensor [0x%x] with interval [%d]", + ERR("Failed to set interval for client [%d], for sensor [0x%llx] with interval [%d]", m_client_id, m_sensor_id, cmd->interval); ret_value = OP_ERROR; goto out; } if (!m_module->add_batch(m_client_id, cmd->latency)) { - ERR("Failed to set latency for client [%d], for sensor [0x%x] with latency [%d]", + ERR("Failed to set latency for client [%d], for sensor [0x%llx] with latency [%d]", m_client_id, m_sensor_id, cmd->latency); ret_value = OP_ERROR; goto out; @@ -636,14 +636,14 @@ bool command_worker::cmd_unset_batch(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to unset batch for client [%d], for sensor [0x%x] to client info manager", + ERR("Permission denied to unset batch for client [%d], for sensor [0x%llx] to client info manager", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) { - ERR("Failed to unset batch for client [%d], for sensor [0x%x] to client info manager", + ERR("Failed to unset batch for client [%d], for sensor [0x%llx] to client info manager", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; @@ -678,14 +678,14 @@ bool command_worker::cmd_set_option(void *payload) cmd = (cmd_set_option_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to set interval for client [%d], for sensor [0x%x] with option [%d] to client info manager", + ERR("Permission denied to set interval for client [%d], for sensor [0x%llx] with option [%d] to client info manager", m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) { - ERR("Failed to set option for client [%d], for sensor [0x%x] with option [%d] to client info manager", + ERR("Failed to set option for client [%d], for sensor [0x%llx] with option [%d] to client info manager", m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; @@ -707,14 +707,14 @@ bool command_worker::cmd_set_wakeup(void *payload) cmd = (cmd_set_wakeup_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to set wakeup for client [%d], for sensor [0x%x] with wakeup [%d] to client info manager", + ERR("Permission denied to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager", m_client_id, m_sensor_id, cmd->wakeup); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_wakeup(m_client_id, m_sensor_id, cmd->wakeup)) { - ERR("Failed to set wakeup for client [%d], for sensor [0x%x] with wakeup [%d] to client info manager", + ERR("Failed to set wakeup for client [%d], for sensor [0x%llx] with wakeup [%d] to client info manager", m_client_id, m_sensor_id, cmd->wakeup); ret_value = OP_ERROR; goto out; @@ -739,7 +739,7 @@ bool command_worker::cmd_set_command(void *payload) cmd = (cmd_set_command_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to set command for client [%d], for sensor [0x%x] with cmd [%d]", + ERR("Permission denied to set command for client [%d], for sensor [0x%llx] with cmd [%d]", m_client_id, m_sensor_id, cmd->cmd); ret_value = OP_ERROR; goto out; @@ -765,7 +765,7 @@ bool command_worker::cmd_get_data(void *payload) DBG("CMD_GET_VALUE Handler invoked\n"); if (!is_permission_allowed()) { - ERR("Permission denied to get data for client [%d], for sensor [0x%x]", + ERR("Permission denied to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); state = OP_ERROR; goto out; @@ -794,7 +794,7 @@ bool command_worker::cmd_get_data(void *payload) } while (!state && !data.timestamp && (retry++ < RETRY_CNT)) { - INFO("Wait sensor[0x%x] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); + INFO("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME); state = m_module->get_sensor_data(data); } @@ -807,7 +807,7 @@ bool command_worker::cmd_get_data(void *payload) state = OP_ERROR; if (state) { - ERR("Failed to get data for client [%d], for sensor [0x%x]", + ERR("Failed to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); } @@ -827,7 +827,7 @@ bool command_worker::cmd_send_sensorhub_data(void *payload) cmd = (cmd_send_sensorhub_data_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to send sensorhub_data for client [%d], for sensor [0x%x]", + ERR("Permission denied to send sensorhub_data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 16028f5..1acd466 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -115,7 +115,7 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro cur_min = m_plugin_info_list.get_min_interval(); if (cur_min != prev_min) { - INFO("Min interval for sensor[0x%x] is changed from %dms to %dms" + INFO("Min interval for sensor[0x%llx] is changed from %dms to %dms" " by%sclient[%d] adding interval", get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); @@ -139,14 +139,14 @@ bool sensor_base::delete_interval(int client_id, bool is_processor) cur_min = m_plugin_info_list.get_min_interval(); if (!cur_min) { - INFO("No interval for sensor[0x%x] by%sclient[%d] deleting interval, " + INFO("No interval for sensor[0x%llx] by%sclient[%d] deleting interval, " "so set to default %dms", get_id(), is_processor ? " processor " : " ", client_id, POLL_1HZ_MS); set_interval(POLL_1HZ_MS); } else if (cur_min != prev_min) { - INFO("Min interval for sensor[0x%x] is changed from %dms to %dms" + INFO("Min interval for sensor[0x%llx] is changed from %dms to %dms" " by%sclient[%d] deleting interval", get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); @@ -178,7 +178,7 @@ bool sensor_base::add_batch(int client_id, unsigned int latency) cur_max = m_plugin_info_list.get_max_batch(); if (cur_max != prev_max) { - INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency", + INFO("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] adding latency", get_id(), prev_max, cur_max, client_id); set_batch(cur_max); } @@ -199,12 +199,12 @@ bool sensor_base::delete_batch(int client_id) cur_max = m_plugin_info_list.get_max_batch(); if (!cur_max) { - INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms", + INFO("No latency for sensor[0x%llx] by client[%d] deleting latency, so set to default 0 ms", get_id(), client_id); set_batch(0); } else if (cur_max != prev_max) { - INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency", + INFO("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] deleting latency", get_id(), prev_max, cur_max, client_id); set_batch(cur_max); @@ -234,7 +234,7 @@ bool sensor_base::add_wakeup(int client_id, int wakeup) cur_wakeup = m_plugin_info_list.is_wakeup_on(); if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) { - INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] adding wakeup", + INFO("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] adding wakeup", get_id(), prev_wakeup, cur_wakeup, client_id); set_wakeup(SENSOR_WAKEUP_ON); } @@ -255,7 +255,7 @@ bool sensor_base::delete_wakeup(int client_id) cur_wakeup = m_plugin_info_list.is_wakeup_on(); if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) { - INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] deleting wakeup", + INFO("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] deleting wakeup", get_id(), prev_wakeup, cur_wakeup, client_id); set_wakeup(SENSOR_WAKEUP_OFF); } diff --git a/src/server/sensor_loader.cpp.in b/src/server/sensor_loader.cpp.in index 25d885b..d46ad81 100644 --- a/src/server/sensor_loader.cpp.in +++ b/src/server/sensor_loader.cpp.in @@ -37,6 +37,7 @@ using std::vector; using std::string; #define DEVICE_PLUGINS_DIR_PATH "/usr/lib/sensor" +#define SENSOR_TYPE_SHIFT 32 #define SENSOR_INDEX_SHIFT 16 sensor_loader::sensor_loader() @@ -89,10 +90,10 @@ bool sensor_loader::load_devices(const string &path, vector &devices, voi physical_sensor* sensor_loader::create_sensor(sensor_handle_t handle, sensor_device *device) { - int index; + int16_t index; physical_sensor *sensor; - index = m_sensors.count((sensor_type_t)handle.type); + index = (int16_t) (m_sensors.count((sensor_type_t)handle.type)); sensor = new(std::nothrow) physical_sensor(); if (!sensor) { @@ -100,7 +101,7 @@ physical_sensor* sensor_loader::create_sensor(sensor_handle_t handle, sensor_dev return NULL; } - sensor->set_id(index << SENSOR_INDEX_SHIFT | handle.type); + sensor->set_id((int64_t)handle.type << SENSOR_TYPE_SHIFT | index << SENSOR_INDEX_SHIFT | handle.id); sensor->set_sensor_handle(handle); sensor->set_sensor_device(device); @@ -172,6 +173,8 @@ bool sensor_loader::load_sensors(void) template void sensor_loader::load_virtual_sensor(const char *name) { + sensor_type_t type; + int16_t index; virtual_sensor *instance = NULL; try { @@ -191,9 +194,12 @@ void sensor_loader::load_virtual_sensor(const char *name) } std::shared_ptr sensor(instance); - sensor_type_t type = sensor->get_type(); - sensor->set_id(type); + type = sensor->get_type(); + index = (int16_t)(m_sensors.count(type)); + + sensor->set_id((int64_t)type << SENSOR_TYPE_SHIFT | index); + m_sensors.insert(std::make_pair(type, sensor)); } @@ -260,8 +266,8 @@ sensor_base* sensor_loader::get_sensor(sensor_id_t id) { vector sensors; - sensor_type_t type = static_cast (id & SENSOR_TYPE_MASK); - unsigned int index = id >> SENSOR_INDEX_SHIFT; + sensor_type_t type = static_cast (id >> SENSOR_TYPE_SHIFT); + unsigned int index = (id >> SENSOR_INDEX_SHIFT) & 0xFFFF; sensors = get_sensors(type); diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index 030b2dc..79dbfee 100644 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -166,8 +166,8 @@ void sensor_info::set_wakeup_supported(bool supported) void sensor_info::get_raw_data(raw_data_t &data) { - put(data, (int)m_type); - put(data, (int) m_id); + put(data, (int) m_type); + put(data, (int64_t) (m_id)); put(data, (int) m_privilege); put(data, m_name); put(data, m_vendor); @@ -187,7 +187,8 @@ void sensor_info::set_raw_data(const char *data, int data_len) auto it_r_data = raw_data.begin(); - int type, id, privilege; + int type, privilege; + int64_t id; it_r_data = get(it_r_data, type); m_type = (sensor_type_t) type; @@ -210,7 +211,7 @@ void sensor_info::set_raw_data(const char *data, int data_len) void sensor_info::show(void) { INFO("Type = %d", m_type); - INFO("ID = 0x%x", (int)m_id); + INFO("ID = 0x%llx", (uint64_t)m_id); INFO("Privilege = %d", (int)m_privilege); INFO("Name = %s", m_name.c_str()); INFO("Vendor = %s", m_vendor.c_str()); @@ -264,6 +265,16 @@ void sensor_info::put(raw_data_t &data, unsigned int value) copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } +void sensor_info::put(raw_data_t &data, int64_t value) +{ + char buffer[sizeof(value)]; + + int64_t *temp = (int64_t *) buffer; + *temp = value; + + copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); +} + void sensor_info::put(raw_data_t &data, float value) { char buffer[sizeof(value)]; @@ -305,6 +316,13 @@ raw_data_iterator sensor_info::get(raw_data_iterator it, unsigned int &value) return it + sizeof(value); } +raw_data_iterator sensor_info::get(raw_data_iterator it, int64_t &value) +{ + copy(it, it + sizeof(value), (char*) &value); + + return it + sizeof(value); +} + raw_data_iterator sensor_info::get(raw_data_iterator it, float &value) { copy(it, it + sizeof(value), (char*) &value); diff --git a/src/shared/sensor_info.h b/src/shared/sensor_info.h index 732cc62..3b20ff3 100644 --- a/src/shared/sensor_info.h +++ b/src/shared/sensor_info.h @@ -20,6 +20,7 @@ #ifndef _SENSOR_INFO_H_ #define _SENSOR_INFO_H_ +#include #include #include #include @@ -83,12 +84,14 @@ private: void put(raw_data_t &data, int value); void put(raw_data_t &data, unsigned int value); + void put(raw_data_t &data, int64_t value); void put(raw_data_t &data, float value); void put(raw_data_t &data, std::string &value); void put(raw_data_t &data, bool value); raw_data_iterator get(raw_data_iterator it, int &value); raw_data_iterator get(raw_data_iterator it, unsigned int &value); + raw_data_iterator get(raw_data_iterator it, int64_t &value); raw_data_iterator get(raw_data_iterator it, float &value); raw_data_iterator get(raw_data_iterator it, std::string &value); raw_data_iterator get(raw_data_iterator it, bool &value); diff --git a/src/shared/sensor_logs.cpp b/src/shared/sensor_logs.cpp index 6af6cc5..8abd66a 100644 --- a/src/shared/sensor_logs.cpp +++ b/src/shared/sensor_logs.cpp @@ -175,7 +175,7 @@ const char* get_client_name(void) bool is_sensorhub_event(unsigned int event_type) { - if ((event_type >> SENSOR_TYPE_SHIFT) == CONTEXT_SENSOR) + if ((event_type >> EVENT_TYPE_SHIFT) == CONTEXT_SENSOR) return true; return false; diff --git a/src/shared/sensor_logs.h b/src/shared/sensor_logs.h index 4192123..98cdf63 100644 --- a/src/shared/sensor_logs.h +++ b/src/shared/sensor_logs.h @@ -41,7 +41,8 @@ extern "C" #endif -#define SENSOR_TYPE_SHIFT 16 +#define EVENT_TYPE_SHIFT 16 +#define SENSOR_TYPE_SHIFT 32 enum sf_log_type { SF_LOG_PRINT_FILE = 1, -- 2.7.4