From 3e7d2e37cd833adc6f0f6700167661c975ea2453 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 7 Apr 2016 18:06:51 +0900 Subject: [PATCH] sensord: remove unused cb_type in library * because legacy API is not supported anymoyre, cb_type is unnecessary. Change-Id: I723c28555c1d08106d9b21e3bc332c7c3056a179 Signed-off-by: kibak.yoon --- src/client/client.cpp | 34 ++++++++--------- src/client/reg_event_info.h | 9 +---- src/client/sensor_client_info.cpp | 7 ++-- src/client/sensor_client_info.h | 4 +- src/client/sensor_event_listener.cpp | 73 +++++++++--------------------------- src/client/sensor_event_listener.h | 1 - src/client/sensor_handle_info.cpp | 3 +- src/client/sensor_handle_info.h | 2 +- 8 files changed, 41 insertions(+), 92 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 79a759c..a884b40 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -48,7 +48,7 @@ static void power_save_state_cb(keynode_t *node, void *data); static void clean_up(void); static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep); static void restore_session(void); -static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, int cb_type, void* cb, void *user_data); +static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data); class initiator { public: @@ -698,7 +698,7 @@ API bool sensord_disconnect(int handle) } -static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, int cb_type, void* cb, void *user_data) +static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data) { sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; @@ -721,7 +721,7 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int handle, interval, max_batch_latency, cb, user_data); sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().register_event(handle, event_type, interval, max_batch_latency, cb_type, cb, user_data); + sensor_client_info::get_instance().register_event(handle, event_type, interval, max_batch_latency, cb, user_data); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); @@ -733,22 +733,15 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int API bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data) { - return register_event(handle, event_type, interval, max_batch_latency, SENSOR_EVENT_CB, (void *)cb, user_data); + return register_event(handle, event_type, interval, max_batch_latency, (void *)cb, user_data); } -API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data) -{ - return register_event(handle, event_type, interval, max_batch_latency, SENSORHUB_EVENT_CB, (void *)cb, user_data); -} - - API bool sensord_unregister_event(int handle, unsigned int event_type) { sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; bool ret; unsigned int prev_interval, prev_latency; - int prev_cb_type; void *prev_cb; void *prev_user_data; @@ -763,7 +756,7 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) event_type, get_sensor_name(sensor_id), handle); sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); + sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data); if (!sensor_client_info::get_instance().unregister_event(handle, event_type)) { _E("%s try to unregister non registered event %s[%#x] for sensor %s[%d]", @@ -775,7 +768,7 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); + sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data); return ret; @@ -907,7 +900,6 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int sensor_rep prev_rep, cur_rep; bool ret; unsigned int prev_interval, prev_latency; - int prev_cb_type; void *prev_cb; void *prev_user_data; @@ -926,7 +918,7 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); + sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data); if (!sensor_client_info::get_instance().set_event_batch(handle, event_type, interval, latency)) return false; @@ -944,13 +936,12 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval) { unsigned int prev_interval, prev_latency; - int prev_cb_type; void *prev_cb; void *prev_user_data; AUTOLOCK(lock); - if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { + if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) { _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type); return false; } @@ -962,13 +953,12 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency) { unsigned int prev_interval, prev_latency; - int prev_cb_type; void *prev_cb; void *prev_user_data; AUTOLOCK(lock); - if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { + if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) { _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type); return false; } @@ -1169,3 +1159,9 @@ API bool sensord_flush(int handle) return true; } + +API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data) +{ + return false; +} + diff --git a/src/client/reg_event_info.h b/src/client/reg_event_info.h index bf20efc..1f65f1d 100644 --- a/src/client/reg_event_info.h +++ b/src/client/reg_event_info.h @@ -22,12 +22,6 @@ #include -typedef enum { - SENSOR_EVENT_CB, - SENSORHUB_EVENT_CB, - SENSOR_LEGACY_CB, -} event_cb_type_t; - class reg_event_info { public: unsigned long long m_id; @@ -35,7 +29,6 @@ public: unsigned int type; unsigned int m_interval; unsigned int m_latency; - int m_cb_type; void *m_cb; void *m_user_data; unsigned long long m_previous_event_time; @@ -44,7 +37,7 @@ public: reg_event_info() : m_id(0), m_handle(-1), type(0), m_interval(POLL_1HZ_MS), m_latency(0), - m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL), + m_cb(NULL), m_user_data(NULL), m_previous_event_time(0), m_fired(false) {} ~reg_event_info() {} diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index e4485af..d34df17 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -96,7 +96,7 @@ bool sensor_client_info::is_active() } bool sensor_client_info::register_event(int handle, unsigned int event_type, - unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data) + unsigned int interval, unsigned int latency, void *cb, void* user_data) { AUTOLOCK(m_handle_info_lock); @@ -107,7 +107,7 @@ bool sensor_client_info::register_event(int handle, unsigned int event_type, return false; } - if (!it_handle->second.add_reg_event_info(event_type, interval, latency, cb_type, cb, user_data)) + if (!it_handle->second.add_reg_event_info(event_type, interval, latency, cb, user_data)) return false; return true; @@ -281,7 +281,7 @@ bool sensor_client_info::set_bad_accuracy(int handle, int bad_accuracy) return true; } -bool sensor_client_info::get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data) +bool sensor_client_info::get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, void* &cb, void* &user_data) { AUTOLOCK(m_handle_info_lock); @@ -301,7 +301,6 @@ bool sensor_client_info::get_event_info(int handle, unsigned int event_type, uns interval = event_info->m_interval; - cb_type = event_info->m_cb_type; cb = event_info->m_cb; user_data = event_info->m_user_data; latency = event_info->m_latency; diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 33524f1..f6383bc 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -65,7 +65,7 @@ public: int create_handle(sensor_id_t sensor_id); bool delete_handle(int handle); bool register_event(int handle, unsigned int event_type, - unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data); + unsigned int interval, unsigned int latency, void *cb, void* user_data); bool unregister_event(int handle, unsigned int event_type); bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data); @@ -78,7 +78,7 @@ public: bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); bool set_accuracy(int handle, int accuracy); bool set_bad_accuracy(int handle, int bad_accuracy); - bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data); + bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, void* &cb, void* &user_data); void get_listening_sensors(sensor_id_vector &sensors); void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep); diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 56e877a..b7be281 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -101,7 +101,6 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle cal_event_info = handle_info.get_reg_event_info(cal_event_type); if ((accuracy == SENSOR_ACCURACY_BAD) && !handle_info.m_bad_accuracy && cal_event_info) { - sensor_event_data_t cal_event_data; void *cal_sensor_data; cal_event_info->m_previous_event_time = time; @@ -110,20 +109,14 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle if (!event_info) return NULL; - if (event_info->m_cb_type == SENSOR_LEGACY_CB) { - cal_event_data.event_data = (void *)&(accuracy); - cal_event_data.event_data_size = sizeof(accuracy); - cal_sensor_data = &cal_event_data; - } else { - sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - retvm_if(!cal_data, NULL, "Failed to allocate memory"); - - cal_data->accuracy = accuracy; - cal_data->timestamp = time; - cal_data->values[0] = accuracy; - cal_data->value_count = 1; - cal_sensor_data = cal_data; - } + sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!cal_data, NULL, "Failed to allocate memory"); + + cal_data->accuracy = accuracy; + cal_data->timestamp = time; + cal_data->values[0] = accuracy; + cal_data->value_count = 1; + cal_sensor_data = cal_data; cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data); @@ -143,14 +136,10 @@ void sensor_event_listener::handle_events(void* event) { unsigned long long cur_time; reg_event_info *event_info = NULL; - sensor_event_data_t event_data; sensor_id_t sensor_id; sensor_handle_info_map handles_info; void *sensor_data; - sensor_panning_data_t panning_data; - int single_state_event_data = 0; - int accuracy = SENSOR_ACCURACY_GOOD; unsigned int event_type = *((unsigned int *)(event)); @@ -164,20 +153,6 @@ void sensor_event_listener::handle_events(void* event) cur_time = sensor_event->data->timestamp; accuracy = sensor_event->data->accuracy; - if (is_single_state_event(event_type)) { - single_state_event_data = (int) sensor_event->data->values[0]; - event_data.event_data = (void *)&(single_state_event_data); - event_data.event_data_size = sizeof(single_state_event_data); - } else if (is_panning_event(event_type)) { - panning_data.x = (int)sensor_event->data->values[0]; - panning_data.y = (int)sensor_event->data->values[1]; - event_data.event_data = (void *)&panning_data; - event_data.event_data_size = sizeof(panning_data); - } else { - event_data.event_data = &(sensor_event->data); - event_data.event_data_size = sizeof(sensor_event->data); - } - { /* scope for the lock */ m_client_info.get_all_handle_info(handles_info); @@ -201,10 +176,7 @@ void sensor_event_listener::handle_events(void* event) if (cal_callback_info) client_callback_infos.push_back(cal_callback_info); - if (event_info->m_cb_type == SENSOR_LEGACY_CB) - callback_info = get_callback_info(sensor_id, event_info, &event_data); - else - callback_info = get_callback_info(sensor_id, event_info, sensor_data); + callback_info = get_callback_info(sensor_id, event_info, sensor_data); if (!callback_info) { _E("Failed to get callback_info"); @@ -247,7 +219,6 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso callback_info->sensor = sensor_info_to_sensor(sensor_info_manager::get_instance().get_info(sensor_id)); callback_info->event_id = event_info->m_id; callback_info->handle = event_info->m_handle; - callback_info->cb_type = event_info->m_cb_type; callback_info->cb = event_info->m_cb; callback_info->event_type = event_info->type; callback_info->user_data = event_info->m_user_data; @@ -274,27 +245,21 @@ gboolean sensor_event_listener::callback_dispatcher(gpointer data) { client_callback_info *cb_info = (client_callback_info*) data; - if (sensor_event_listener::get_instance().is_valid_callback(cb_info)) { - if (cb_info->accuracy_cb) - cb_info->accuracy_cb(cb_info->sensor, cb_info->timestamp, cb_info->accuracy, cb_info->accuracy_user_data); - - if (cb_info->cb_type == SENSOR_EVENT_CB) - ((sensor_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensor_data_t *) cb_info->sensor_data, cb_info->user_data); - else if (cb_info->cb_type == SENSORHUB_EVENT_CB) - ((sensorhub_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensorhub_data_t *) cb_info->sensor_data, cb_info->user_data); - else if (cb_info->cb_type == SENSOR_LEGACY_CB) - ((sensor_legacy_cb_t) cb_info->cb)(cb_info->event_type, (sensor_event_data_t *) cb_info->sensor_data, cb_info->user_data); - } else { + if (!sensor_event_listener::get_instance().is_valid_callback(cb_info)) { _W("Discard invalid callback cb(%#x)(%s, %#x, %#x) with id: %llu", cb_info->cb, get_event_name(cb_info->event_type), cb_info->sensor_data, cb_info->user_data, cb_info->event_id); - } - if (cb_info->cb_type == SENSOR_LEGACY_CB) { - sensor_event_data_t *data = (sensor_event_data_t *) cb_info->sensor_data; - delete[] (char *)data->event_data; + free(cb_info->sensor_data); + delete cb_info; + return false; } + if (cb_info->accuracy_cb) + cb_info->accuracy_cb(cb_info->sensor, cb_info->timestamp, cb_info->accuracy, cb_info->accuracy_user_data); + + ((sensor_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensor_data_t *) cb_info->sensor_data, cb_info->user_data); + free(cb_info->sensor_data); delete cb_info; @@ -304,8 +269,6 @@ gboolean sensor_event_listener::callback_dispatcher(gpointer data) return false; } - - ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event) { ssize_t len; diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 47ff126..baf6fb1 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -51,7 +51,6 @@ typedef struct { int handle; sensor_t sensor; unsigned int event_type; - int cb_type; void *cb; void *sensor_data; void *user_data; diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 2263ee0..21c6469 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -63,7 +63,7 @@ void sensor_handle_info::get_reg_event_types(event_type_vector &event_types) } } -bool sensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb, void *user_data) +bool sensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, void *cb, void *user_data) { reg_event_info event_info; @@ -79,7 +79,6 @@ bool sensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned in event_info.type = event_type; event_info.m_interval = interval; event_info.m_latency = latency; - event_info.m_cb_type = cb_type; event_info.m_cb = cb; event_info.m_user_data = user_data; diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index d551952..1836194 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -42,7 +42,7 @@ public: sensor_handle_info(); ~sensor_handle_info(); - bool add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb,void *user_data); + bool add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, void *cb, void *user_data); bool delete_reg_event_info(unsigned int event_type); bool change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency); -- 2.7.4