From 7863c4a857f056b2eb489593e97c97d9d13a9795 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 25 May 2016 18:23:22 +0900 Subject: [PATCH 01/16] sensord: remove EVENT_TYPE_SHIFT macro in sensor_log.h - they are duplicated macro, so remove them. Change-Id: I1a635c7b49657229da2edf539a3f183033d4de64 Signed-off-by: kibak.yoon --- src/client/client_common.cpp | 5 +++-- src/shared/sensor_log.h | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index ce0eab2..a91dbb0 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -17,6 +17,7 @@ * */ #include +#include #include #include #include @@ -40,7 +41,7 @@ const char* get_sensor_name(sensor_id_t id) const char* get_event_name(unsigned int event_type) { - sensor_type_t type = (sensor_type_t) (event_type >> EVENT_TYPE_SHIFT); + sensor_type_t type = (sensor_type_t) (event_type >> SENSOR_EVENT_SHIFT); std::string name(util_sensor_type_t::get_string(type)); return name.append("_EVENT").c_str(); @@ -48,7 +49,7 @@ const char* get_event_name(unsigned int event_type) unsigned int get_calibration_event_type(unsigned int event_type) { - sensor_type_t type = (sensor_type_t)(event_type >> EVENT_TYPE_SHIFT); + sensor_type_t type = (sensor_type_t)(event_type >> SENSOR_EVENT_SHIFT); switch (type) { case GEOMAGNETIC_SENSOR: diff --git a/src/shared/sensor_log.h b/src/shared/sensor_log.h index d478e07..22d1d7d 100644 --- a/src/shared/sensor_log.h +++ b/src/shared/sensor_log.h @@ -23,9 +23,6 @@ #include #include -#define EVENT_TYPE_SHIFT 16 -#define SENSOR_TYPE_SHIFT 32 - #define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec) #ifdef LOG_TAG -- 2.7.4 From 1ced21e7b94e30b57b93803b19debfa38ca35fcb Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 25 May 2016 23:12:05 +0900 Subject: [PATCH 02/16] sensord: change the log level from _E to _I - this state is not error Change-Id: I9f294f14e6071f7cab8f40eaf8d296fd836a57a9 Signed-off-by: kibak.yoon --- src/sensor/accel/accel_sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensor/accel/accel_sensor.cpp b/src/sensor/accel/accel_sensor.cpp index 3470850..892ecb0 100644 --- a/src/sensor/accel/accel_sensor.cpp +++ b/src/sensor/accel/accel_sensor.cpp @@ -23,7 +23,7 @@ accel_sensor::accel_sensor() { - _E("accel_sensor is created : %#x", this); + _I("accel_sensor is created : %#x", this); } accel_sensor::~accel_sensor() -- 2.7.4 From fd9c129f5af7769c37082c2628bf5016b041c430 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 25 May 2016 23:12:55 +0900 Subject: [PATCH 03/16] sensord: remove unused APIs - there is no module which uses these APIs - sf_check_rotation is used in xwalk.... Change-Id: I3c462da847015f54f3aa1d573a7380342f941205 Signed-off-by: kibak.yoon --- src/client/client_deprecated.cpp | 10 ---------- src/client/sensor_internal_deprecated.h | 28 ++-------------------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/src/client/client_deprecated.cpp b/src/client/client_deprecated.cpp index 38cf33f..e721bed 100644 --- a/src/client/client_deprecated.cpp +++ b/src/client/client_deprecated.cpp @@ -82,13 +82,3 @@ API int sf_is_sensor_event_available(sensor_type_t sensor_type, unsigned int eve { return OP_ERROR; } - -API int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties) -{ - return OP_ERROR; -} - -API int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties) -{ - return OP_ERROR; -} diff --git a/src/client/sensor_internal_deprecated.h b/src/client/sensor_internal_deprecated.h index d74cab8..a2b5b30 100644 --- a/src/client/sensor_internal_deprecated.h +++ b/src/client/sensor_internal_deprecated.h @@ -38,8 +38,6 @@ extern "C" { #endif -#define MAX_KEY_LEN 30 - typedef struct { condition_op_t cond_op; float cond_value1; @@ -59,30 +57,6 @@ typedef struct { int z; } sensor_panning_data_t; -typedef struct { - int sensor_unit_idx; - float sensor_min_range; - float sensor_max_range; - float sensor_resolution; - char sensor_name[MAX_KEY_LEN]; - char sensor_vendor[MAX_KEY_LEN]; -} sensor_properties_t; - -typedef struct { - int sensor_unit_idx; - float sensor_min_range; - float sensor_max_range; - float sensor_resolution; -} sensor_data_properties_t; - -DEPRECATED int sf_is_sensor_event_available(sensor_type_t sensor_type, unsigned int event_type); - -DEPRECATED int sf_get_data_properties(unsigned int data_id, sensor_data_properties_t *return_data_properties); - -DEPRECATED int sf_get_properties(sensor_type_t sensor_type, sensor_properties_t *return_properties); - -DEPRECATED int sf_check_rotation(unsigned long *rotation); - /** * @fn int sf_connect(sensor_type_t sensor) * @brief This API connects a sensor type to respective sensor. The application calls with the type of the sensor (ex. ACCELEROMETER_SENSOR) and on basis of that server takes decision of which plug-in to be connected. Once sensor connected application can proceed for data processing. This API returns a positive handle which should be used by application to communicate on sensor type. @@ -177,6 +151,8 @@ DEPRECATED int sf_change_sensor_option(int handle, int option); */ DEPRECATED int sf_send_sensorhub_data(int handle, const char* data, int data_len); +DEPRECATED int sf_check_rotation(unsigned long *rotation); + #ifdef __cplusplus } #endif -- 2.7.4 From df00850a3de2f89fbfd61d12ab61295d8e2ff0d1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 25 May 2016 23:20:03 +0900 Subject: [PATCH 04/16] sensord: clean up permission_checker for syncing with tizen_2.3 - in tizen 2.3, there is another security module, security_server. - clean up permission_checker for converting it easily Change-Id: I4489849fbb4e8178058e1b1d403dde99c402b0bd Signed-off-by: kibak.yoon --- src/server/permission_checker.cpp | 34 ++++++++++++++++------------------ src/server/permission_checker.h | 12 +++++++----- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/server/permission_checker.cpp b/src/server/permission_checker.cpp index 72fef47..3da9ac6 100644 --- a/src/server/permission_checker.cpp +++ b/src/server/permission_checker.cpp @@ -21,15 +21,17 @@ #include #include #include +#include #include #include #include +#include #define CACHE_SIZE 16 static cynara *cynara_env = NULL; -static bool check_privilege_by_sockfd(int sock_fd, const char *priv) +static bool check_privilege_by_sockfd(int sock_fd, const char *priv, const char *access) { retvm_if(cynara_env == NULL, false, "Cynara not initialized"); @@ -60,15 +62,16 @@ static bool check_privilege_by_sockfd(int sock_fd, const char *priv) return (ret == CYNARA_API_ACCESS_ALLOWED); } -permission_checker::permission_checker(void) +permission_checker::permission_checker() : m_permission_set(0) { init(); + init_cynara(); } -permission_checker::~permission_checker(void) +permission_checker::~permission_checker() { - deinit(); + deinit_cynara(); } permission_checker& permission_checker::get_instance(void) @@ -79,10 +82,7 @@ permission_checker& permission_checker::get_instance(void) void permission_checker::init(void) { - AUTOLOCK(m_mutex); - - m_permission_infos.push_back(std::make_shared (SENSOR_PERMISSION_STANDARD, false, "")); - m_permission_infos.push_back(std::make_shared (SENSOR_PERMISSION_BIO, true, "http://tizen.org/privilege/healthinfo")); + m_permission_infos.push_back(std::make_shared(SENSOR_PERMISSION_BIO, "http://tizen.org/privilege/healthinfo", "")); std::vector sensors; sensors = sensor_loader::get_instance().get_sensors(ALL_SENSOR); @@ -91,12 +91,12 @@ void permission_checker::init(void) m_permission_set |= sensors[i]->get_permission(); _I("Permission Set = %d", m_permission_set); - - init_cynara(); } void permission_checker::init_cynara(void) { + AUTOLOCK(m_mutex); + cynara_configuration *conf; int err = cynara_configuration_create(&conf); @@ -121,7 +121,7 @@ void permission_checker::init_cynara(void) _I("Cynara initialized"); } -void permission_checker::deinit(void) +void permission_checker::deinit_cynara(void) { AUTOLOCK(m_mutex); @@ -135,16 +135,14 @@ int permission_checker::get_permission(int sock_fd) { AUTOLOCK(m_mutex); - int permission = SENSOR_PERMISSION_NONE; + int permission = SENSOR_PERMISSION_STANDARD; for (unsigned int i = 0; i < m_permission_infos.size(); ++i) { - if (!m_permission_infos[i]->need_to_check) { + if (!(m_permission_set & m_permission_infos[i]->permission)) + continue; + + if (check_privilege_by_sockfd(sock_fd, m_permission_infos[i]->privilege.c_str(), m_permission_infos[i]->access.c_str())) permission |= m_permission_infos[i]->permission; - } else if (m_permission_set & m_permission_infos[i]->permission) { - if (check_privilege_by_sockfd(sock_fd, m_permission_infos[i]->privilege.c_str())) { - permission |= m_permission_infos[i]->permission; - } - } } return permission; diff --git a/src/server/permission_checker.h b/src/server/permission_checker.h index d47524d..d42ba09 100644 --- a/src/server/permission_checker.h +++ b/src/server/permission_checker.h @@ -34,33 +34,35 @@ public: private: class permission_info { public: - permission_info(int _permission, bool _need_to_check, std::string _priv) + permission_info(int _permission, std::string _priv, std::string _access) : permission(_permission) - , need_to_check(_need_to_check) , privilege(_priv) + , access(_access) { } int permission; - bool need_to_check; std::string privilege; + std::string access; }; typedef std::vector> permission_info_vector; permission_checker(); - ~permission_checker(); permission_checker(permission_checker const&) {}; permission_checker& operator=(permission_checker const&); + ~permission_checker(); + void init(void); - void deinit(void); private: permission_info_vector m_permission_infos; int m_permission_set; cmutex m_mutex; +private: void init_cynara(void); + void deinit_cynara(void); }; #endif /* _PERMISSION_CHECKER_H_ */ -- 2.7.4 From 887697234acea07dbb6c31a1803ea871f7c7cbda Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 26 May 2016 00:15:26 +0900 Subject: [PATCH 05/16] sensord: fix double free problem after the allocation of memory is failed - if the allocation of memory is failed, this function has to be finished. Change-Id: Iea3ca9184812a82b34b3ad3bd299b2d33a382323 Signed-off-by: kibak.yoon --- src/client/external_sensor_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/external_sensor_manager.cpp b/src/client/external_sensor_manager.cpp index e19b403..9a0b3c4 100644 --- a/src/client/external_sensor_manager.cpp +++ b/src/client/external_sensor_manager.cpp @@ -430,6 +430,7 @@ void external_sensor_manager::handle_command(sensor_id_t sensor, char* data, int if (!cb_info) { _E("Failed to allocate memory"); delete[] data; + return; } if (!get_cb_info(sensor, data, data_cnt, *cb_info)) { -- 2.7.4 From 1f5abbbbf44de95493bb42ba001a26ec809ff60a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 30 May 2016 19:12:01 +0900 Subject: [PATCH 06/16] sensord: move udev rules to HAL packages - there are some devices which doesn't have sensorhub, e.g. TM1. - so udev rules should be moved to HAL packages Change-Id: Ib0c7b36fdf9973b1b72e0cdda5b897351fc8b514 Signed-off-by: kibak.yoon --- packaging/99-sensor.rules | 13 ------------- packaging/99-sensorhub.rules | 5 ----- packaging/sensord.spec | 7 ------- 3 files changed, 25 deletions(-) delete mode 100644 packaging/99-sensor.rules delete mode 100644 packaging/99-sensorhub.rules diff --git a/packaging/99-sensor.rules b/packaging/99-sensor.rules deleted file mode 100644 index 3d07132..0000000 --- a/packaging/99-sensor.rules +++ /dev/null @@ -1,13 +0,0 @@ -SUBSYSTEM!="input", GOTO="sensor_rules_end" -ENV{ID_INPUT_TOUCHPAD}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_TOUCHSCREEN}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_KEY}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_KEYPAD}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_KEYBOARD}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_MOUSE}=="1", GOTO="sensor_rules_end" -ENV{ID_INPUT_JOYSTICK}=="1", GOTO="sensor_rules_end" - -SUBSYSTEM=="input", ACTION=="add", RUN+="/bin/chown sensor:input %S/%p/enable %S/%p/poll_delay" -SUBSYSTEM=="input", ACTION=="add", RUN+="/bin/chsmack -a * %S/%p/enable %S/%p/poll_delay" - -LABEL="sensor_rules_end" diff --git a/packaging/99-sensorhub.rules b/packaging/99-sensorhub.rules deleted file mode 100644 index ae4b350..0000000 --- a/packaging/99-sensorhub.rules +++ /dev/null @@ -1,5 +0,0 @@ -SUBSYSTEMS=="sensors", DEVPATH=="*ssp_sensor*", \ -RUN+="/bin/sh -c '/bin/chown :input %S/%p/enable %S/%p/set_cal_data %S/%p/*_poll_delay'" - -SUBSYSTEMS=="sensors", DEVPATH=="*ssp_sensor*", \ -RUN+="/bin/sh -c '/bin/chsmack -a \* %S/%p/enable %S/%p/set_cal_data %S/%p/*_poll_delay'" diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 4457a4f..e743bc9 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -8,8 +8,6 @@ Source0: %{name}-%{version}.tar.gz Source1: sensord.service Source2: sensord_command.socket Source3: sensord_event.socket -Source4: 99-sensor.rules -Source5: 99-sensorhub.rules BuildRequires: cmake BuildRequires: libattr-devel @@ -75,13 +73,10 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{_unitdir} -mkdir -p %{buildroot}%{_libdir}/udev/rules.d install -m 0644 %SOURCE1 %{buildroot}%{_unitdir} install -m 0644 %SOURCE2 %{buildroot}%{_unitdir} install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} -install -m 0644 %SOURCE4 %{buildroot}%{_libdir}/udev/rules.d -install -m 0644 %SOURCE5 %{buildroot}%{_libdir}/udev/rules.d %install_service multi-user.target.wants sensord.service %install_service sockets.target.wants sensord_event.socket @@ -109,8 +104,6 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %{_unitdir}/multi-user.target.wants/sensord.service %{_unitdir}/sockets.target.wants/sensord_command.socket %{_unitdir}/sockets.target.wants/sensord_event.socket -%{_libdir}/udev/rules.d/99-sensor.rules -%{_libdir}/udev/rules.d/99-sensorhub.rules %license LICENSE.APLv2 %files -n libsensord -- 2.7.4 From e60c874f5d4a6dbeb6d23aa5d3b2913f0d09dc29 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 30 May 2016 19:58:51 +0900 Subject: [PATCH 07/16] sensord: fix to not loading sensor which is already loaded - a sensor has to be loaded just once. Change-Id: I9cbd1897e6a582a85ed90cc8f36812503c2d08c3 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 7 +++++-- src/server/sensor_loader.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 5e0e0f9..a873d71 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -63,8 +63,8 @@ sensor_loader::~sensor_loader() sensor_device_map_t::iterator it_device; std::vector::iterator it_handle; - for (it_device = m_devices.begin(); it_device != m_devices.end();) - it_device = m_devices.erase(it_device); + for (it_device = m_active_devices.begin(); it_device != m_active_devices.end();) + it_device = m_active_devices.erase(it_device); for (it_handle = m_handles.begin(); it_handle != m_handles.end(); ++it_handle) dlclose(*it_handle); @@ -220,6 +220,9 @@ void sensor_loader::create_physical_sensors(sensor_type_t type) std::shared_ptr sensor_ptr(sensor); m_sensors.insert(std::make_pair(_type, sensor_ptr)); + m_active_devices[it->first] = it->second; + m_devices.erase(it->first); + _I("created [%s] sensor", sensor->get_name()); } } diff --git a/src/server/sensor_loader.h b/src/server/sensor_loader.h index c10c4bb..4d9f179 100644 --- a/src/server/sensor_loader.h +++ b/src/server/sensor_loader.h @@ -56,6 +56,7 @@ private: sensor_map_t m_sensors; sensor_device_map_t m_devices; + sensor_device_map_t m_active_devices; std::vector m_handles; public: static sensor_loader& get_instance(void); -- 2.7.4 From 6a64accc185cf655b20b6d5b5055133c997f25bb Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 1 Jun 2016 00:13:28 +0900 Subject: [PATCH 08/16] sensord: rename return variables from err to ret - change the condition about state is not equal to PSMODE_NORMAL Change-Id: I7d8de4b7434a5c857760ae81789b8805f9c38607 Signed-off-by: kibak.yoon --- src/client/client.cpp | 10 +++++----- src/server/sensor_loader.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index e77b1b3..861aa43 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -119,18 +119,18 @@ void clean_up(void) static int get_power_save_state(void) { - int err; + int ret; int state = 0; int pm_state, ps_state; - err = vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state); - if (!err && pm_state == VCONFKEY_PM_STATE_LCDOFF) + if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF) state |= SENSOR_OPTION_ON_IN_SCREEN_OFF; - err = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state); + ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state); - if (!err && ps_state == SETTING_PSMODE_NORMAL) + if (!ret && ps_state != SETTING_PSMODE_NORMAL) state |= SENSOR_OPTION_ON_IN_POWERSAVE_MODE; return state; diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index a873d71..0d12915 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -326,7 +326,7 @@ bool sensor_loader::get_paths_from_dir(const string &dir_path, vector &h struct dirent dir_entry; struct dirent *result; string name; - int error; + int ret; dir = opendir(dir_path.c_str()); @@ -336,9 +336,9 @@ bool sensor_loader::get_paths_from_dir(const string &dir_path, vector &h } while (true) { - error = readdir_r(dir, &dir_entry, &result); + ret = readdir_r(dir, &dir_entry, &result); - if (error != 0) + if (ret != 0) continue; if (result == NULL) -- 2.7.4 From 31ea2cd85c02df30cb51e301c59d1fe37e829c71 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 1 Jun 2016 00:15:20 +0900 Subject: [PATCH 09/16] sensord: fix comments properly about getting sensor data logic - remove wrong tab before assignment Change-Id: I49f18ea005c3f6f69209a30ebe4d03f0029353d9 Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index b2a61aa..13c8260 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -706,30 +706,28 @@ bool command_worker::cmd_get_data(void *payload) state = m_module->get_cache(&data); - // In case of not getting sensor data, wait short time and retry again - // 1. changing interval to be less than 10ms - // 2. In case of first time, wait for INIT_WAIT_TIME - // 3. at another time, wait for WAIT_TIME - // 4. retrying to get data - // 5. repeat 2 ~ 4 operations RETRY_CNT times - // 6. reverting back to original interval + /* if there is no cached data, wait short time and retry to get data again */ if (state == -ENODATA) { - const int RETRY_CNT = 10; + const int RETRY_CNT = 10; int retry = 0; unsigned int interval = m_module->get_interval(m_client_id, false); + /* 1. change interval to 10ms. */ if (interval > GET_DATA_MIN_INTERVAL) { m_module->add_interval(m_client_id, GET_DATA_MIN_INTERVAL, false); adjusted = true; } + /* 2. try to get sensor data increasing the waited time(20ms, 40ms, 80ms, 160ms, 160ms...) */ + /* 3. if data cannot be found in 10 times, stop it. */ while ((state == -ENODATA) && (retry++ < RETRY_CNT)) { _I("Wait sensor[%#llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep(WAIT_TIME(retry)); state = m_module->get_cache(&data); } + /* 4. revert to original interval */ if (adjusted) m_module->add_interval(m_client_id, interval, false); } -- 2.7.4 From 6c74491e0abe56efac3f217ddcd34323cc135272 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 8 Jun 2016 12:45:22 +0900 Subject: [PATCH 10/16] sensord: store unknown rotation event when auto_rotation sensor starts - when sensor starts, it would be better to store unknown rotation event for getting auto_rotation sensor data. Change-Id: I68e25ec9460b7959b200185ef674adc2293a3b55 Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 3 +++ src/server/sensor_base.cpp | 4 ++-- src/server/sensor_base.h | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 0cebedd..470d5d8 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -196,8 +196,11 @@ bool auto_rotation_sensor::set_wakeup(int wakeup) bool auto_rotation_sensor::on_start(void) { + int length; m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; + get_data(&m_last_data, &length); + m_alg->start(); m_accel_sensor->add_interval((intptr_t)this , m_interval, true); diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index dd78a2a..5ff2566 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -31,11 +31,11 @@ using std::make_pair; using std::vector; sensor_base::sensor_base() -: m_id(SENSOR_ID_INVALID) +: m_last_data(NULL) +, m_id(SENSOR_ID_INVALID) , m_permission(SENSOR_PERMISSION_STANDARD) , m_started(false) , m_client(0) -, m_last_data(NULL) { } diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 22f0e66..04883d8 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -77,6 +77,8 @@ public: int get_permission(void); protected: + sensor_data_t *m_last_data; + void set_permission(int permission); unsigned long long get_timestamp(void); @@ -93,7 +95,6 @@ private: unsigned int m_client; cmutex m_client_mutex; - sensor_data_t *m_last_data; cmutex m_data_cache_mutex; virtual int set_attribute(int32_t attribute, int32_t value); -- 2.7.4 From 4e3a78c1fd7e44c714ad54edebc8f23723907a4f Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 7 Jun 2016 21:34:47 +0900 Subject: [PATCH 11/16] sensord: support attribute interface & clean up option - SENSORD_PAUSE_POLICY( = sensor option) - SENSORD_AXIS_ORIENTATION - SENSORD_ATTRIBUTE_* Change-Id: Ida4039b55fc72a5cff4cbe021ef79c33429c3948 Signed-off-by: kibak.yoon --- src/client/client.cpp | 74 +++++++++++++++++++++++++++++++++------------- src/shared/sensor_common.h | 18 +++++++++++ 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 861aa43..99b96d0 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -44,9 +44,13 @@ using std::vector; #define DEFAULT_INTERVAL POLL_10HZ_MS +#define CONVERT_OPTION_PAUSE_POLICY(option) \ + (option == SENSOR_OPTION_DEFAULT || option == SENSOR_OPTION_ALWAYS_ON) ? \ + (option ^ 0b11) : option + static cmutex lock; -static int g_power_save_state = 0; +static int g_power_save_state = SENSORD_PAUSE_NONE; static int get_power_save_state(void); static void power_save_state_cb(keynode_t *node, void *data); @@ -126,12 +130,12 @@ static int get_power_save_state(void) ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state); if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF) - state |= SENSOR_OPTION_ON_IN_SCREEN_OFF; + state |= SENSORD_PAUSE_ON_DISPLAY_OFF; ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state); if (!ret && ps_state != SETTING_PSMODE_NORMAL) - state |= SENSOR_OPTION_ON_IN_POWERSAVE_MODE; + state |= SENSORD_PAUSE_ON_POWERSAVE_MODE; return state; } @@ -633,7 +637,7 @@ API int sensord_connect(sensor_t sensor) _I("%s[%d] connects with %s[%d]", get_client_name(), client_id, get_sensor_name(sensor_id), handle); - sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STOPPED, SENSOR_OPTION_DEFAULT); + sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STOPPED, SENSORD_PAUSE_ALL); if (!sensor_registered) { if (!cmd_channel->cmd_hello(sensor_id)) { @@ -829,6 +833,7 @@ API bool sensord_start(int handle, int option) sensor_rep prev_rep, cur_rep; bool ret; int prev_state, prev_option; + int pause; AUTOLOCK(lock); @@ -843,14 +848,16 @@ API bool sensord_start(int handle, int option) _I("%s starts %s[%d], with option: %d, power save state: %d", get_client_name(), get_sensor_name(sensor_id), handle, option, g_power_save_state); - if (g_power_save_state && !(g_power_save_state & option)) { - sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_PAUSED, option); + pause = CONVERT_OPTION_PAUSE_POLICY(option); + + if (g_power_save_state && (g_power_save_state & pause)) { + sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_PAUSED, pause); return true; } sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_option); - sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STARTED, option); + sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STARTED, pause); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); @@ -968,46 +975,52 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t return change_event_batch(handle, event_type, prev_interval, max_batch_latency); } -API bool sensord_set_option(int handle, int option) +static int change_pause_policy(int handle, int pause) { sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; int sensor_state; bool ret; - int prev_state, prev_option; + int prev_state, prev_pause; AUTOLOCK(lock); + retvm_if((pause < 0) || (pause >= SENSORD_PAUSE_END), -EINVAL, + "Invalid pause value : %d, handle: %d, %s, %s", + pause, handle, get_sensor_name(sensor_id), get_client_name()); + if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)|| !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) { _E("client %s failed to get handle information", get_client_name()); - return false; + return -EPERM; } - retvm_if((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s", - option, handle, get_sensor_name(sensor_id), get_client_name()); - sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_option); + sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause); if (g_power_save_state) { - if ((option & g_power_save_state) && (sensor_state == SENSOR_STATE_PAUSED)) - sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STARTED); - else if (!(option & g_power_save_state) && (sensor_state == SENSOR_STATE_STARTED)) + if ((pause & g_power_save_state) && (sensor_state == SENSOR_STATE_STARTED)) sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_PAUSED); + else if (!(pause & g_power_save_state) && (sensor_state == SENSOR_STATE_PAUSED)) + sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STARTED); } - sensor_client_info::get_instance().set_sensor_option(handle, option); + sensor_client_info::get_instance().set_sensor_option(handle, pause); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - sensor_client_info::get_instance().set_sensor_option(handle, prev_option); + sensor_client_info::get_instance().set_sensor_option(handle, prev_pause); - return ret; + return (ret ? OP_SUCCESS : OP_ERROR); } -API int sensord_set_attribute_int(int handle, int attribute, int value) +static int change_axis_orientation(int handle, int axis_orientation) +{ + return OP_SUCCESS; +} + +static int change_attribute_int(int handle, int attribute, int value) { sensor_id_t sensor_id; command_channel *cmd_channel; @@ -1039,6 +1052,25 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return OP_SUCCESS; } +API bool sensord_set_option(int handle, int option) +{ + return (change_pause_policy(handle, CONVERT_OPTION_PAUSE_POLICY(option)) == OP_SUCCESS); +} + +API int sensord_set_attribute_int(int handle, int attribute, int value) +{ + switch (attribute) { + case SENSORD_ATTRIBUTE_PAUSE_POLICY: + return change_pause_policy(handle, value); + case SENSORD_ATTRIBUTE_AXIS_ORIENTATION: + return change_axis_orientation(handle, value); + default: + return change_attribute_int(handle, attribute, value); + } + + return OP_SUCCESS; +} + API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len) { sensor_id_t sensor_id; diff --git a/src/shared/sensor_common.h b/src/shared/sensor_common.h index a1c0541..d308549 100644 --- a/src/shared/sensor_common.h +++ b/src/shared/sensor_common.h @@ -75,6 +75,24 @@ enum sensor_option_t { typedef enum sensor_option_t sensor_option_e; #endif +enum sensord_attribute_e { + SENSORD_ATTRIBUTE_AXIS_ORIENTATION = 1, + SENSORD_ATTRIBUTE_PAUSE_POLICY, +}; + +enum sensord_axis_e { + SENSORD_AXIS_DEVICE_ORIENTED = 1, + SENSORD_AXIS_DISPLAY_ORIENTED, +}; + +enum sensord_pause_e { + SENSORD_PAUSE_NONE = 0, + SENSORD_PAUSE_ON_DISPLAY_OFF = 1, + SENSORD_PAUSE_ON_POWERSAVE_MODE = 2, + SENSORD_PAUSE_ALL = 3, + SENSORD_PAUSE_END, +}; + enum poll_interval_t { POLL_100HZ_MS = 10, POLL_50HZ_MS = 20, -- 2.7.4 From 2d29dbd9dffa335735afcbc0098388fbb76e1150 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 8 Jun 2016 13:42:44 +0900 Subject: [PATCH 12/16] sensord: rename option to pause policy Change-Id: I2bcb62312af65f693aa83a1071bac1eee3d3a4a5 Signed-off-by: kibak.yoon --- src/client/client.cpp | 24 ++++++++++++------------ src/client/client_common.cpp | 4 ++-- src/client/command_channel.cpp | 24 ++++++++++++------------ src/client/command_channel.h | 2 +- src/client/sensor_client_info.cpp | 28 ++++++++++++++-------------- src/client/sensor_client_info.h | 10 +++++----- src/client/sensor_event_listener.cpp | 4 ++-- src/client/sensor_handle_info.cpp | 2 +- src/client/sensor_handle_info.h | 2 +- src/server/client_info_manager.cpp | 4 ++-- src/server/client_info_manager.h | 2 +- src/server/client_sensor_record.cpp | 6 +++--- src/server/client_sensor_record.h | 2 +- src/server/command_worker.cpp | 18 +++++++++--------- src/server/command_worker.h | 2 +- src/server/sensor_usage.cpp | 2 +- src/server/sensor_usage.h | 2 +- src/shared/command_common.h | 6 +++--- 18 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 99b96d0..7effcda 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -224,7 +224,7 @@ void restore_session(void) sensor_rep prev_rep, cur_rep; prev_rep.active = false; - prev_rep.option = SENSOR_OPTION_DEFAULT; + prev_rep.pause_policy = SENSORD_PAUSE_ALL; prev_rep.interval = 0; sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep); @@ -273,9 +273,9 @@ static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, senso get_events_diff(prev_rep.event_types, cur_rep.event_types, add_event_types, del_event_types); if (cur_rep.active) { - if (prev_rep.option != cur_rep.option) { - if (!cmd_channel->cmd_set_option(cur_rep.option)) { - _E("Sending cmd_set_option(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.option, get_client_name()); + if (prev_rep.pause_policy != cur_rep.pause_policy) { + if (!cmd_channel->cmd_set_pause_policy(cur_rep.pause_policy)) { + _E("Sending cmd_set_pause_policy(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.pause_policy, get_client_name()); return false; } } @@ -832,7 +832,7 @@ API bool sensord_start(int handle, int option) sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; bool ret; - int prev_state, prev_option; + int prev_state, prev_pause; int pause; AUTOLOCK(lock); @@ -856,14 +856,14 @@ API bool sensord_start(int handle, int option) } sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_option); + sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause); sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STARTED, pause); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_option); + sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause); return ret; } @@ -873,7 +873,7 @@ API bool sensord_stop(int handle) sensor_id_t sensor_id; int sensor_state; bool ret; - int prev_state, prev_option; + int prev_state, prev_pause; sensor_rep prev_rep, cur_rep; @@ -891,14 +891,14 @@ API bool sensord_stop(int handle) _I("%s stops sensor %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle); sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); - sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_option); + sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause); sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STOPPED); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_option); + sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause); return ret; } @@ -1004,13 +1004,13 @@ static int change_pause_policy(int handle, int pause) else if (!(pause & g_power_save_state) && (sensor_state == SENSOR_STATE_PAUSED)) sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STARTED); } - sensor_client_info::get_instance().set_sensor_option(handle, pause); + sensor_client_info::get_instance().set_sensor_pause_policy(handle, pause); sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - sensor_client_info::get_instance().set_sensor_option(handle, prev_pause); + sensor_client_info::get_instance().set_sensor_pause_policy(handle, prev_pause); return (ret ? OP_SUCCESS : OP_ERROR); } diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index a91dbb0..ec17a1f 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -95,9 +95,9 @@ void print_event_occurrence_log(sensor_handle_info &info) if ((count != 1) && (count % log_per_count != 0)) return; - _D("%s receives %s[%d][state: %d, option: %d, count: %d]", get_client_name(), + _D("%s receives %s[%d][state: %d, pause policy: %d, count: %d]", get_client_name(), get_sensor_name(info.m_sensor_id), info.m_handle, - info.m_sensor_state, info.m_sensor_option, count); + info.m_sensor_state, info.m_pause_policy, count); } /* diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index ff49a54..39c3d4d 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -339,33 +339,33 @@ bool command_channel::cmd_stop(void) return true; } -bool command_channel::cmd_set_option(int option) +bool command_channel::cmd_set_pause_policy(int pause_policy) { cpacket *packet; - cmd_set_option_t *cmd_set_option; + cmd_set_pause_policy_t *cmd_set_pause_policy; cmd_done_t *cmd_done; - packet = new(std::nothrow) cpacket(sizeof(cmd_set_option_t)); + packet = new(std::nothrow) cpacket(sizeof(cmd_set_pause_policy_t)); retvm_if(!packet, false, "Failed to allocate memory"); - packet->set_cmd(CMD_SET_OPTION); + packet->set_cmd(CMD_SET_PAUSE_POLICY); - cmd_set_option = (cmd_set_option_t*)packet->data(); - cmd_set_option->option = option; + cmd_set_pause_policy = (cmd_set_pause_policy_t*)packet->data(); + cmd_set_pause_policy->pause_policy = pause_policy; - _I("%s send cmd_set_option(client_id=%d, %s, option=%d)", - get_client_name(), m_client_id, get_sensor_name(m_sensor_id), option); + _I("%s send cmd_set_pause_policy(client_id=%d, %s, pause_policy=%d)", + get_client_name(), m_client_id, get_sensor_name(m_sensor_id), pause_policy); if (!command_handler(packet, (void **)&cmd_done)) { - _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], option[%d]", - get_client_name(), get_sensor_name(m_sensor_id), m_client_id, option); + _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], pause_policy[%d]", + get_client_name(), get_sensor_name(m_sensor_id), m_client_id, pause_policy); delete packet; return false; } if (cmd_done->value < 0) { - _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d], option[%d]", - get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, option); + _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d], pause_policy[%d]", + get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, pause_policy); delete[] (char *)cmd_done; delete packet; diff --git a/src/client/command_channel.h b/src/client/command_channel.h index 15b579e..2dd3589 100644 --- a/src/client/command_channel.h +++ b/src/client/command_channel.h @@ -39,7 +39,7 @@ public: bool cmd_byebye(void); bool cmd_start(void); bool cmd_stop(void); - bool cmd_set_option(int option); + bool cmd_set_pause_policy(int pause_policy); bool cmd_register_event(unsigned int event_type); bool cmd_register_events(event_type_vector &event_vec); bool cmd_unregister_event(unsigned int event_type); diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index ecb453e..6ac154c 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -59,7 +59,7 @@ int sensor_client_info::create_handle(sensor_id_t sensor) handle_info.m_sensor_id = sensor; handle_info.m_sensor_state = SENSOR_STATE_STOPPED; - handle_info.m_sensor_option = SENSOR_OPTION_DEFAULT; + handle_info.m_pause_policy = SENSORD_PAUSE_ALL; handle_info.m_handle = handle; handle_info.m_accuracy = -1; handle_info.m_accuracy_cb = NULL; @@ -163,7 +163,7 @@ bool sensor_client_info::unregister_accuracy_cb(int handle) return true; } -bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int sensor_option) +bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int pause_policy) { AUTOLOCK(m_handle_info_lock); @@ -175,12 +175,12 @@ bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int sen } it_handle->second.m_sensor_state = sensor_state; - it_handle->second.m_sensor_option = sensor_option; + it_handle->second.m_pause_policy = pause_policy; return true; } -bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &sensor_option) +bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &pause_policy) { AUTOLOCK(m_handle_info_lock); @@ -192,7 +192,7 @@ bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &s } sensor_state = it_handle->second.m_sensor_state; - sensor_option = it_handle->second.m_sensor_option; + pause_policy = it_handle->second.m_pause_policy; return true; } @@ -213,7 +213,7 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state) return true; } -bool sensor_client_info::set_sensor_option(int handle, int sensor_option) +bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy) { AUTOLOCK(m_handle_info_lock); @@ -224,7 +224,7 @@ bool sensor_client_info::set_sensor_option(int handle, int sensor_option) return false; } - it_handle->second.m_sensor_option = sensor_option; + it_handle->second.m_pause_policy = pause_policy; return true; } @@ -323,7 +323,7 @@ void sensor_client_info::get_sensor_rep(sensor_id_t sensor, sensor_rep& rep) { const unsigned int INVALID_BATCH_VALUE = std::numeric_limits::max(); rep.active = is_sensor_active(sensor); - rep.option = get_active_option(sensor); + rep.pause_policy = get_active_pause_policy(sensor); if (!get_active_batch(sensor, rep.interval, rep.latency)) { rep.interval = INVALID_BATCH_VALUE; rep.latency = INVALID_BATCH_VALUE; @@ -441,11 +441,11 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte return true; } -unsigned int sensor_client_info::get_active_option(sensor_id_t sensor) +unsigned int sensor_client_info::get_active_pause_policy(sensor_id_t sensor) { - int active_option = SENSOR_OPTION_DEFAULT; + int active_pause = SENSORD_PAUSE_ALL; bool active_sensor_found = false; - int option; + int pause; AUTOLOCK(m_handle_info_lock); @@ -455,8 +455,8 @@ unsigned int sensor_client_info::get_active_option(sensor_id_t sensor) if ((it_handle->second.m_sensor_id == sensor) && (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) { active_sensor_found = true; - option = it_handle->second.m_sensor_option; - active_option = (option > active_option) ? option : active_option; + pause = it_handle->second.m_pause_policy; + active_pause = (pause < active_pause) ? pause: active_pause; } ++it_handle; @@ -465,7 +465,7 @@ unsigned int sensor_client_info::get_active_option(sensor_id_t sensor) if (!active_sensor_found) _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name()); - return active_option; + return active_pause; } bool sensor_client_info::get_sensor_id(int handle, sensor_id_t &sensor) diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 275e674..ac3a56f 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -53,7 +53,7 @@ typedef unordered_map sensor_command_channel_map typedef struct sensor_rep { bool active; - int option; + int pause_policy; unsigned int interval; unsigned int latency; event_type_vector event_types; @@ -71,10 +71,10 @@ public: bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data); bool unregister_accuracy_cb(int handle); - bool set_sensor_params(int handle, int sensor_state, int sensor_option); - bool get_sensor_params(int handle, int &sensor_state, int &sensor_option); + bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy); + bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy); bool set_sensor_state(int handle, int sensor_state); - bool set_sensor_option(int handle, int sensor_option); + 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); bool set_accuracy(int handle, int accuracy); bool set_bad_accuracy(int handle, int bad_accuracy); @@ -83,7 +83,7 @@ public: void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep); bool get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency); - unsigned int get_active_option(sensor_id_t sensor_id); + unsigned int get_active_pause_policy(sensor_id_t sensor_id); void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types); bool get_sensor_id(int handle, sensor_id_t &sensor_id); diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 3182b78..1b9cd07 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -82,12 +82,12 @@ void sensor_event_listener::operate_sensor(sensor_id_t sensor, int power_save_st if ((it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) && power_save_state && - !(it_handle->second.m_sensor_option & power_save_state)) { + (it_handle->second.m_pause_policy & power_save_state)) { m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED); _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first); } else if ((it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) && - (!power_save_state || (it_handle->second.m_sensor_option & power_save_state))) { + (!power_save_state || !(it_handle->second.m_pause_policy & power_save_state))) { m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_STARTED); _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first); } diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 6dc1984..175c567 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -29,7 +29,7 @@ sensor_handle_info::sensor_handle_info() : m_handle(0) , m_sensor_id(UNKNOWN_SENSOR) , m_sensor_state(SENSOR_STATE_UNKNOWN) -, m_sensor_option(SENSOR_OPTION_DEFAULT) +, m_pause_policy(SENSORD_PAUSE_ALL) , m_bad_accuracy(false) , m_accuracy(-1) , m_accuracy_cb(NULL) diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index 00eba28..f64b2a6 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -33,7 +33,7 @@ public: int m_handle; sensor_id_t m_sensor_id; int m_sensor_state; - int m_sensor_option; + int m_pause_policy; int m_bad_accuracy; int m_accuracy; sensor_accuracy_changed_cb_t m_accuracy_cb; diff --git a/src/server/client_info_manager.cpp b/src/server/client_info_manager.cpp index efdaec0..4a72308 100644 --- a/src/server/client_info_manager.cpp +++ b/src/server/client_info_manager.cpp @@ -131,7 +131,7 @@ bool client_info_manager::get_batch(int client_id, sensor_id_t sensor_id, unsign return it_record->second.get_batch(sensor_id, interval, latency); } -bool client_info_manager::set_option(int client_id, sensor_id_t sensor_id, int option) +bool client_info_manager::set_pause_policy(int client_id, sensor_id_t sensor_id, int pause_policy) { AUTOLOCK(m_mutex); @@ -144,7 +144,7 @@ bool client_info_manager::set_option(int client_id, sensor_id_t sensor_id, int o return false; } - if (!it_record->second.set_option(sensor_id, option)) + if (!it_record->second.set_pause_policy(sensor_id, pause_policy)) return false; return true; diff --git a/src/server/client_info_manager.h b/src/server/client_info_manager.h index b65c4bf..ad7add8 100644 --- a/src/server/client_info_manager.h +++ b/src/server/client_info_manager.h @@ -52,7 +52,7 @@ public: bool set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned int latency); bool get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency); - bool set_option(int client_id, sensor_id_t sensor_id, int option); + bool set_pause_policy(int client_id, sensor_id_t sensor_id, int pause_policy); bool set_start(int client_id, sensor_id_t sensor_id, bool start); bool is_started(int client_id, sensor_id_t sensor_id); diff --git a/src/server/client_sensor_record.cpp b/src/server/client_sensor_record.cpp index e2e647e..8eeafca 100644 --- a/src/server/client_sensor_record.cpp +++ b/src/server/client_sensor_record.cpp @@ -72,16 +72,16 @@ bool client_sensor_record::unregister_event(sensor_id_t sensor_id, unsigned int return true; } -bool client_sensor_record::set_option(sensor_id_t sensor_id, int option) +bool client_sensor_record::set_pause_policy(sensor_id_t sensor_id, int pause_policy) { auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { sensor_usage usage; - usage.m_option = option; + usage.m_pause_policy = pause_policy; m_sensor_usages.insert(pair(sensor_id, usage)); } else { - it_usage->second.m_option = option; + it_usage->second.m_pause_policy = pause_policy; } return true; diff --git a/src/server/client_sensor_record.h b/src/server/client_sensor_record.h index defc3d9..ad4835c 100644 --- a/src/server/client_sensor_record.h +++ b/src/server/client_sensor_record.h @@ -47,7 +47,7 @@ public: bool set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency); bool get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency); - bool set_option(sensor_id_t sensor_id, int option); + bool set_pause_policy(sensor_id_t sensor_id, int pause_policy); bool set_start(sensor_id_t sensor_id, bool start); bool is_started(sensor_id_t sensor_id); diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 13c8260..f8a6075 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -82,7 +82,7 @@ void command_worker::init_cmd_handlers(void) m_cmd_handlers[CMD_STOP] = &command_worker::cmd_stop; m_cmd_handlers[CMD_REG] = &command_worker::cmd_register_event; m_cmd_handlers[CMD_UNREG] = &command_worker::cmd_unregister_event; - m_cmd_handlers[CMD_SET_OPTION] = &command_worker::cmd_set_option; + m_cmd_handlers[CMD_SET_PAUSE_POLICY] = &command_worker::cmd_set_pause_policy; m_cmd_handlers[CMD_SET_BATCH] = &command_worker::cmd_set_batch; m_cmd_handlers[CMD_UNSET_BATCH] = &command_worker::cmd_unset_batch; m_cmd_handlers[CMD_GET_DATA] = &command_worker::cmd_get_data; @@ -658,23 +658,23 @@ out: return true; } -bool command_worker::cmd_set_option(void *payload) +bool command_worker::cmd_set_pause_policy(void *payload) { - cmd_set_option_t *cmd; + cmd_set_pause_policy_t *cmd; long ret_value = OP_ERROR; - cmd = (cmd_set_option_t*)payload; + cmd = (cmd_set_pause_policy_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to set interval for client [%d], for sensor [%#llx] with option [%d] to client info manager", - m_client_id, m_sensor_id, cmd->option); + _E("Permission denied to set interval for client [%d], for sensor [%#llx] with pause_policy [%d] to client info manager", + m_client_id, m_sensor_id, cmd->pause_policy); ret_value = OP_ERROR; goto out; } - if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) { - _E("Failed to set option for client [%d], for sensor [%#llx] with option [%d] to client info manager", - m_client_id, m_sensor_id, cmd->option); + if (!get_client_info_manager().set_pause_policy(m_client_id, m_sensor_id, cmd->pause_policy)) { + _E("Failed to set pause_policy for client [%d], for sensor [%#llx] with pause_policy [%d] to client info manager", + m_client_id, m_sensor_id, cmd->pause_policy); ret_value = OP_ERROR; goto out; } diff --git a/src/server/command_worker.h b/src/server/command_worker.h index 78661ad..3e1b62c 100644 --- a/src/server/command_worker.h +++ b/src/server/command_worker.h @@ -69,7 +69,7 @@ private: bool cmd_unregister_event(void *payload); bool cmd_set_batch(void *payload); bool cmd_unset_batch(void *payload); - bool cmd_set_option(void *payload); + bool cmd_set_pause_policy(void *payload); bool cmd_get_data(void *payload); bool cmd_set_attribute_int(void *payload); bool cmd_set_attribute_str(void *payload); diff --git a/src/server/sensor_usage.cpp b/src/server/sensor_usage.cpp index 780bdff..e4f0ffc 100644 --- a/src/server/sensor_usage.cpp +++ b/src/server/sensor_usage.cpp @@ -25,7 +25,7 @@ sensor_usage::sensor_usage() : m_interval(POLL_1HZ_MS) , m_latency(0) -, m_option(SENSOR_OPTION_DEFAULT) +, m_pause_policy(SENSORD_PAUSE_ALL) , m_start(false) { } diff --git a/src/server/sensor_usage.h b/src/server/sensor_usage.h index 91c4571..e3fd247 100644 --- a/src/server/sensor_usage.h +++ b/src/server/sensor_usage.h @@ -29,7 +29,7 @@ class sensor_usage { public: unsigned int m_interval; unsigned int m_latency; - int m_option; + int m_pause_policy; reg_event_vector m_reg_events; bool m_start; diff --git a/src/shared/command_common.h b/src/shared/command_common.h index 3973a92..2afb3bd 100644 --- a/src/shared/command_common.h +++ b/src/shared/command_common.h @@ -42,7 +42,7 @@ enum packet_type_t { CMD_STOP, CMD_REG, CMD_UNREG, - CMD_SET_OPTION, + CMD_SET_PAUSE_POLICY, CMD_SET_BATCH, CMD_UNSET_BATCH, CMD_GET_DATA, @@ -122,8 +122,8 @@ typedef struct { } cmd_unset_batch_t; typedef struct { - int option; -} cmd_set_option_t; + int pause_policy; +} cmd_set_pause_policy_t; typedef struct { int attribute; -- 2.7.4 From 48a6c5a2953fcb3156d839200ce81471c73eab17 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 2 Jun 2016 13:49:19 +0900 Subject: [PATCH 13/16] sensord: move operate_sensor function to sensor_client_info - it would be better to move operate_sensor() to sensor_client_info class, because it is only related with that class. - because "operate_sensor" name is ambiguous, rename it to set_pause_policy. Change-Id: I593f1380015e7d38ed413e5cda8141718942d23a Signed-off-by: kibak.yoon --- src/client/client.cpp | 2 +- src/client/sensor_client_info.cpp | 24 ++++++++++++++++++++++++ src/client/sensor_client_info.h | 2 ++ src/client/sensor_event_listener.cpp | 34 ---------------------------------- src/client/sensor_event_listener.h | 3 --- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 7effcda..e818bd8 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -164,7 +164,7 @@ static void power_save_state_cb(keynode_t *node, void *data) while (it_sensor != sensors.end()) { sensor_client_info::get_instance().get_sensor_rep(*it_sensor, prev_rep); - sensor_event_listener::get_instance().operate_sensor(*it_sensor, cur_power_save_state); + sensor_client_info::get_instance().set_pause_policy(*it_sensor, cur_power_save_state); sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep); change_sensor_rep(*it_sensor, prev_rep, cur_rep); diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 6ac154c..fcd4e80 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -616,6 +616,30 @@ bool sensor_client_info::is_event_active(int handle, unsigned int event_type, un return true; } +void sensor_client_info::set_pause_policy(sensor_id_t sensor, int pause_policy) +{ + sensor_handle_info_map handles_info; + + get_sensor_handle_info(sensor, handles_info); + + for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) { + if (it_handle->second.m_sensor_id != sensor) + continue; + + if (pause_policy && (it_handle->second.m_pause_policy & pause_policy)) { + if (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) { + set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED); + _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first); + } + } else { + if (it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) { + set_sensor_state(it_handle->first, SENSOR_STATE_STARTED); + _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first); + } + } + } +} + void sensor_client_info::clear(void) { close_command_channel(); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index ac3a56f..1d2ba9b 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -107,6 +107,8 @@ public: void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info); void get_all_handle_info(sensor_handle_info_map &handles_info); + void set_pause_policy(sensor_id_t sensor, int power_save_state); + void clear(void); sensor_client_info(); diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 1b9cd07..ec8da17 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -60,40 +60,6 @@ sensor_event_listener& sensor_event_listener::get_instance(void) return inst; } -bool sensor_event_listener::start_handle(int handle) -{ - return m_client_info.set_sensor_state(handle, SENSOR_STATE_STARTED); -} - -bool sensor_event_listener::stop_handle(int handle) -{ - return m_client_info.set_sensor_state(handle, SENSOR_STATE_STOPPED); -} - -void sensor_event_listener::operate_sensor(sensor_id_t sensor, int power_save_state) -{ - sensor_handle_info_map handles_info; - - m_client_info.get_sensor_handle_info(sensor, handles_info); - - for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) { - if (it_handle->second.m_sensor_id != sensor) - continue; - - if ((it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) && - power_save_state && - (it_handle->second.m_pause_policy & power_save_state)) { - m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED); - _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first); - - } else if ((it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) && - (!power_save_state || !(it_handle->second.m_pause_policy & power_save_state))) { - m_client_info.set_sensor_state(it_handle->first, SENSOR_STATE_STARTED); - _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first); - } - } -} - client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy) { unsigned int cal_event_type = get_calibration_event_type(event_type); diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 5bb92ab..417d0ad 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -66,10 +66,7 @@ typedef void (*hup_observer_t)(void); class sensor_event_listener { public: static sensor_event_listener& get_instance(void); - bool start_handle(int handle); - bool stop_handle(int handle); - void operate_sensor(sensor_id_t sensor, int power_save_state); void get_listening_sensors(sensor_id_vector &sensors); bool start_event_listener(void); -- 2.7.4 From cba95e8c6a0981d952980ea07f2fb4354a9df709 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 2 Jun 2016 14:07:47 +0900 Subject: [PATCH 14/16] sensord: change to use is_started() instead of using member variable directly - it would be better to use member function Change-Id: I2475768459215731d36bdd3ef00df263688c4431 Signed-off-by: kibak.yoon --- src/client/sensor_client_info.cpp | 28 ++++++++++++---------------- src/client/sensor_event_listener.cpp | 4 ++-- src/client/sensor_handle_info.cpp | 5 +++++ src/client/sensor_handle_info.h | 3 +++ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index fcd4e80..62de536 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -410,7 +410,6 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte unsigned int min_interval = POLL_MAX_HZ_MS; unsigned int min_latency = std::numeric_limits::max(); - bool active_sensor_found = false; unsigned int _interval; unsigned int _latency; @@ -420,17 +419,16 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte while (it_handle != m_sensor_handle_infos.end()) { if ((it_handle->second.m_sensor_id == sensor) && - (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) { - active_sensor_found = true; - it_handle->second.get_batch(_interval, _latency); - min_interval = (_interval < min_interval) ? _interval : min_interval; - min_latency = (_latency < min_latency) ? _latency : min_latency; + it_handle->second.is_started()) { + it_handle->second.get_batch(_interval, _latency); + min_interval = (_interval < min_interval) ? _interval : min_interval; + min_latency = (_latency < min_latency) ? _latency : min_latency; } ++it_handle; } - if (!active_sensor_found) { + if (!is_sensor_active(sensor)) { _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name()); return false; } @@ -444,7 +442,6 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte unsigned int sensor_client_info::get_active_pause_policy(sensor_id_t sensor) { int active_pause = SENSORD_PAUSE_ALL; - bool active_sensor_found = false; int pause; AUTOLOCK(m_handle_info_lock); @@ -453,16 +450,15 @@ unsigned int sensor_client_info::get_active_pause_policy(sensor_id_t sensor) while (it_handle != m_sensor_handle_infos.end()) { if ((it_handle->second.m_sensor_id == sensor) && - (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) { - active_sensor_found = true; - pause = it_handle->second.m_pause_policy; - active_pause = (pause < active_pause) ? pause: active_pause; + it_handle->second.is_started()) { + pause = it_handle->second.m_pause_policy; + active_pause = (pause < active_pause) ? pause: active_pause; } ++it_handle; } - if (!active_sensor_found) + if (!is_sensor_active(sensor)) _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name()); return active_pause; @@ -510,8 +506,8 @@ void sensor_client_info::get_active_event_types(sensor_id_t sensor, event_type_v while (it_handle != m_sensor_handle_infos.end()) { if ((it_handle->second.m_sensor_id == sensor) && - (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) - it_handle->second.get_reg_event_types(event_types); + it_handle->second.is_started()) + it_handle->second.get_reg_event_types(event_types); ++it_handle; } @@ -586,7 +582,7 @@ bool sensor_client_info::is_sensor_active(sensor_id_t sensor) while (it_handle != m_sensor_handle_infos.end()) { if ((it_handle->second.m_sensor_id == sensor) && - (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) + it_handle->second.is_started()) return true; ++it_handle; diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index ec8da17..80c280b 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -128,8 +128,8 @@ void sensor_event_listener::handle_events(void* event) event_info = sensor_handle_info.get_reg_event_info(event_type); if ((sensor_handle_info.m_sensor_id != sensor_id) || - (sensor_handle_info.m_sensor_state != SENSOR_STATE_STARTED) || - !event_info) + !sensor_handle_info.is_started() || + !event_info) continue; if (event_info->m_fired) diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 175c567..b394990 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -160,3 +160,8 @@ unsigned int sensor_handle_info::get_reg_event_count(void) { return m_reg_event_infos.size(); } + +bool sensor_handle_info::is_started(void) +{ + return (m_sensor_state == SENSOR_STATE_STARTED); +} diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index f64b2a6..28e5a01 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -54,6 +54,9 @@ public: void clear_all_events(void); static unsigned long long renew_event_id(void); + + bool is_started(void); + private: event_info_map m_reg_event_infos; static unsigned long long m_event_id; -- 2.7.4 From a305da78e60760135f49e9783b8d6f39cb04d791 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 2 Jun 2016 14:11:04 +0900 Subject: [PATCH 15/16] sensord: support the passive mode which listens sensor event only if a client wants to be listening sensor event which other clients start sensor, use sensord_set_passive_mode() before sensord_register_event(). Change-Id: Idbe59ed663c8a0bc268c406afcdc8cac13286b98 Signed-off-by: kibak.yoon --- src/client/client.cpp | 34 ++++++++++++++++++++++++++++++++++ src/client/sensor_client_info.cpp | 30 ++++++++++++++++++++++++++++++ src/client/sensor_client_info.h | 4 ++++ src/client/sensor_handle_info.cpp | 13 ++++++++++++- src/client/sensor_handle_info.h | 21 ++++++++++++--------- src/client/sensor_internal.h | 1 + 6 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index e818bd8..769aa9d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -682,6 +682,28 @@ API bool sensord_disconnect(int handle) _I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle); + if (sensor_client_info::get_instance().get_passive_mode(handle)) { + _W("%s[%d] for %s is on passive mode while disconnecting.", + get_sensor_name(sensor_id), handle, get_client_name()); + + command_channel *cmd_channel; + event_type_vector event_types; + sensor_client_info::get_instance().get_active_event_types(sensor_id, event_types); + + for (auto it = event_types.begin(); it != event_types.end(); ++it) + sensord_unregister_event(handle, *it); + + if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) { + _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id)); + return false; + } + + if (!cmd_channel->cmd_unset_batch()) { + _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name()); + return false; + } + } + if (sensor_state != SENSOR_STATE_STOPPED) { _W("%s[%d] for %s is not stopped before disconnecting.", get_sensor_name(sensor_id), handle, get_client_name()); @@ -781,6 +803,9 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); + if (sensor_client_info::get_instance().get_passive_mode(handle)) + sensor_client_info::get_instance().set_passive_mode(handle, false); + if (!ret) sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data); @@ -1197,3 +1222,12 @@ API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigne return false; } +API bool sensord_set_passive_mode(int handle, bool passive) +{ + if (!sensor_client_info::get_instance().set_passive_mode(handle, passive)) { + _E("Failed to set passive mode %d", passive); + return false; + } + + return true; +} diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 62de536..08b5a9d 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -213,6 +213,36 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state) return true; } +bool sensor_client_info::get_passive_mode(int handle) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + return it_handle->second.get_passive_mode(); +} + +bool sensor_client_info::set_passive_mode(int handle, bool passive) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.set_passive_mode(passive); + + return true; +} + bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy) { AUTOLOCK(m_handle_info_lock); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 1d2ba9b..7c46323 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -74,6 +74,10 @@ public: bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy); bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy); bool set_sensor_state(int handle, int sensor_state); + + bool get_passive_mode(int handle); + bool set_passive_mode(int handle, bool passive); + 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); bool set_accuracy(int handle, int accuracy); diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index b394990..f1e9c65 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -34,6 +34,7 @@ sensor_handle_info::sensor_handle_info() , m_accuracy(-1) , m_accuracy_cb(NULL) , m_accuracy_user_data(NULL) +, m_passive(false) { } @@ -161,7 +162,17 @@ unsigned int sensor_handle_info::get_reg_event_count(void) return m_reg_event_infos.size(); } +bool sensor_handle_info::get_passive_mode(void) +{ + return m_passive; +} + +void sensor_handle_info::set_passive_mode(bool passive) +{ + m_passive = passive; +} + bool sensor_handle_info::is_started(void) { - return (m_sensor_state == SENSOR_STATE_STARTED); + return (m_sensor_state == SENSOR_STATE_STARTED) || m_passive; } diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index 28e5a01..c74c3a5 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -30,15 +30,6 @@ typedef std::unordered_map event_info_map; class sensor_handle_info { public: - int m_handle; - sensor_id_t m_sensor_id; - int m_sensor_state; - int m_pause_policy; - int m_bad_accuracy; - int m_accuracy; - sensor_accuracy_changed_cb_t m_accuracy_cb; - void *m_accuracy_user_data; - sensor_handle_info(); ~sensor_handle_info(); @@ -55,8 +46,20 @@ public: void clear_all_events(void); static unsigned long long renew_event_id(void); + bool get_passive_mode(void); + void set_passive_mode(bool passive); bool is_started(void); + int m_handle; + sensor_id_t m_sensor_id; + int m_sensor_state; + int m_pause_policy; + int m_bad_accuracy; + int m_accuracy; + sensor_accuracy_changed_cb_t m_accuracy_cb; + void *m_accuracy_user_data; + bool m_passive; + private: event_info_map m_reg_event_infos; static unsigned long long m_event_id; diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index c4c3fce..3cc6641 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -386,6 +386,7 @@ int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, v bool sensord_external_disconnect(int handle); bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt); +bool sensord_set_passive_mode(int handle, bool passive); /** * @} */ -- 2.7.4 From da9123180996923a1449f47d5a4965ca4780ffc2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 8 Jun 2016 20:18:58 +0900 Subject: [PATCH 16/16] sensord: restore attributes after sensor daemon is restarted sensor attributes also has to restored when daemon is restarted, like listener, interval, batch latency. Change-Id: Id9bfb37fc9ab9b71caca08639f2106710a65741f Signed-off-by: kibak.yoon --- src/client/client.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/client/sensor_client_info.cpp | 32 +++++++++++++++++++++++++++++ src/client/sensor_client_info.h | 24 +++++++--------------- src/client/sensor_handle_info.h | 6 ++++++ 4 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 769aa9d..e26ba85 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -172,6 +172,40 @@ static void power_save_state_cb(keynode_t *node, void *data) } } +bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_channel) +{ + sensor_handle_info_map handle_infos; + + sensor_client_info::get_instance().get_sensor_handle_info(sensor, handle_infos); + + for (auto it_handles = handle_infos.begin(); it_handles != handle_infos.end(); ++it_handles) { + sensor_handle_info info = it_handles->second; + + for (auto it = info.attributes_int.begin(); it != info.attributes_int.end(); ++it) { + int attribute = it->first; + int value = it->second; + if (!cmd_channel->cmd_set_attribute_int(attribute, value)) { + _E("Failed to send cmd_set_attribute_int(%d, %d) for %s", + client_id, value, get_client_name()); + return false; + } + } + + 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(); + 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 false; + } + } + } + + return true; +} + void restore_session(void) { AUTOLOCK(lock); @@ -233,6 +267,10 @@ void restore_session(void) goto FAILED; } + if (!restore_attributes(client_id, *it_sensor, cmd_channel)) { + _E("Failed to restore attributes(%s) for %s", get_sensor_name(*it_sensor), get_client_name()); + goto FAILED; + } ++it_sensor; } @@ -1074,6 +1112,8 @@ static int change_attribute_int(int handle, int attribute, int value) return -EPERM; } + sensor_client_info::get_instance().set_attribute(handle, attribute, value); + return OP_SUCCESS; } @@ -1130,6 +1170,8 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, return -EPERM; } + sensor_client_info::get_instance().set_attribute(handle, attribute, value); + return OP_SUCCESS; } diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 08b5a9d..54a6d7e 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -666,6 +666,38 @@ void sensor_client_info::set_pause_policy(sensor_id_t sensor, int pause_policy) } } +bool sensor_client_info::set_attribute(int handle, int attribute, int value) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.attributes_int[attribute] = value; + + return true; +} + +bool sensor_client_info::set_attribute(int handle, int attribute, std::string value) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.attributes_str[attribute] = value; + + return true; +} + void sensor_client_info::clear(void) { close_command_channel(); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 7c46323..ab3a384 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -29,27 +29,14 @@ #include #include #include -#include -#include -#include -#include #include #include #include -using std::unordered_map; -using std::vector; -using std::string; -using std::queue; -using std::mutex; -using std::lock_guard; -using std::unique_lock; -using std::condition_variable; - -typedef vector handle_vector; -typedef vector sensor_id_vector; -typedef unordered_map sensor_handle_info_map; -typedef unordered_map sensor_command_channel_map; +typedef std::vector handle_vector; +typedef std::vector sensor_id_vector; +typedef std::unordered_map sensor_handle_info_map; +typedef std::unordered_map sensor_command_channel_map; typedef struct sensor_rep { bool active; @@ -78,6 +65,9 @@ public: bool get_passive_mode(int handle); 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_sensor_pause_policy(int handle, int pause_policy); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); bool set_accuracy(int handle, int accuracy); diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index c74c3a5..b62f646 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -25,8 +25,12 @@ #include #include #include +#include +#include typedef std::unordered_map event_info_map; +typedef std::map sensor_attribute_int_map; +typedef std::map sensor_attribute_str_map; class sensor_handle_info { public: @@ -59,6 +63,8 @@ public: sensor_accuracy_changed_cb_t m_accuracy_cb; void *m_accuracy_user_data; bool m_passive; + sensor_attribute_int_map attributes_int; + sensor_attribute_str_map attributes_str; private: event_info_map m_reg_event_infos; -- 2.7.4