From cadbe5311dc9bfc84c8de2488cd5c9dfd42c2d1f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 28 Mar 2016 22:40:33 +0900 Subject: [PATCH 01/16] sensor_base: modify get_timestamp() to protected functions Change-Id: Ideaf97be8e3b9440b4cb4446b6fb0db843e38fc5 Signed-off-by: Mu-Woong Lee --- src/server/sensor_base.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 95ea6c5..b69ca8e 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -77,6 +77,9 @@ public: protected: void set_permission(int permission); + static unsigned long long get_timestamp(void); + static unsigned long long get_timestamp(timeval *t); + private: sensor_id_t m_id; int m_permission; @@ -93,9 +96,6 @@ private: virtual bool on_start(void); virtual bool on_stop(void); - - static unsigned long long get_timestamp(void); - static unsigned long long get_timestamp(timeval *t); }; #endif /* _SENSOR_BASE_H_ */ -- 2.7.4 From 10128a9b5761c650df006b398d21e7a2778338b5 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 30 Mar 2016 22:16:07 +0900 Subject: [PATCH 02/16] sensord: init epoll_event variable * if it does not set the value and some problem is happened at first, later, other developers can make a mistake. so for preventing it, initialize this variable's members. Change-Id: I1c2fe47d816c50a524178d5a657b65cec929d4d2 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 5964ab6..99cf76e 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -338,6 +338,8 @@ void sensor_event_listener::listen_events(void) struct epoll_event event; ssize_t len = -1; + event.events = EPOLLIN | EPOLLPRI; + do { void *buffer_data; int data_len; -- 2.7.4 From dd29f31a34c4c08c358dc0fa4950332482a1a710 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:24:52 +0900 Subject: [PATCH 03/16] sensord: fix memory leak when legacy cb is used * when legacy cb is used, allocation of event is useless Change-Id: I1698884940a6744f78963a28746e5b9e4313ec00 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 99cf76e..d344554 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -110,14 +110,14 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle if (!event_info) return NULL; - sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - retvm_if(!cal_data, NULL, "Failed to allocate memory"); - 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; -- 2.7.4 From d3d8e40d87414f9fa8dacd66b7e60bea41e26825 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:26:41 +0900 Subject: [PATCH 04/16] sensord: remove useless buffer parameter * buffer in callback_info is not used anymore, remove it Change-Id: I5a52e869e48972dcde7593a1cfd4333b380cb728 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 9 ++++----- src/client/sensor_event_listener.h | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index d344554..273d0d1 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -125,7 +125,7 @@ client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle cal_sensor_data = cal_data; } - cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data, cal_sensor_data); + cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data); m_client_info.set_bad_accuracy(handle_info.m_handle, true); @@ -202,9 +202,9 @@ void sensor_event_listener::handle_events(void* event) 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, event); + callback_info = get_callback_info(sensor_id, event_info, &event_data); else - callback_info = get_callback_info(sensor_id, event_info, sensor_data, event); + callback_info = get_callback_info(sensor_id, event_info, sensor_data); if (!callback_info) { _E("Failed to get callback_info"); @@ -237,7 +237,7 @@ void sensor_event_listener::handle_events(void* event) } } -client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void* sensor_data, void *buffer) +client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void* sensor_data) { client_callback_info* callback_info; @@ -256,7 +256,6 @@ client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t senso callback_info->accuracy = -1; callback_info->accuracy_user_data = NULL; callback_info->sensor_data = sensor_data; - callback_info->buffer = buffer; return callback_info; } diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 54f5a40..47ff126 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -59,7 +59,6 @@ typedef struct { unsigned long long timestamp; int accuracy; void *accuracy_user_data; - void *buffer; } client_callback_info; typedef void (*hup_observer_t)(void); @@ -112,7 +111,7 @@ private: client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy); void handle_events(void* event); - client_callback_info* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void *sensor_data, void *buffer); + client_callback_info* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, void *sensor_data); unsigned long long renew_event_id(void); -- 2.7.4 From bf904c562107946fcbc00dd3f88916d3422591e9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:35:07 +0900 Subject: [PATCH 05/16] sensord: fix memory leak in virtual sensors * event memory has to be not released when error happens Change-Id: I53fe2d366069b773b6d9b05c052fa9ac56f85e0d Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 4 +++- src/sensor/gravity/gravity_sensor.cpp | 3 +++ src/sensor/linear_accel/linear_accel_sensor.cpp | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 3afd961..0c4888a 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -181,8 +181,10 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event) remains = get_data(&rotation_data, &data_length); - if (remains < 0) + if (remains < 0) { + free(rotation_event); return; + } rotation_event->sensor_id = get_id(); rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT; diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 2c39ebf..49ee0fe 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -171,6 +171,7 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } @@ -226,6 +227,7 @@ void gravity_sensor::synthesize_lowpass(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } @@ -275,6 +277,7 @@ void gravity_sensor::synthesize_fusion(const sensor_event_t& event) gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); if (!gravity_event->data) { _E("Failed to allocate memory"); + free(gravity_event); return; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 33d1548..eb50de9 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -141,8 +141,10 @@ void linear_accel_sensor::synthesize(const sensor_event_t& event) remains = get_data(&linear_accel_data, &data_length); - if (remains < 0) + if (remains < 0) { + free(linear_accel_event); return; + } linear_accel_event->sensor_id = get_id(); linear_accel_event->event_type = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME; -- 2.7.4 From 920984bc9621284217aea86728a1094c6a0a60d6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:41:24 +0900 Subject: [PATCH 06/16] sensord: close handles in sensor_loader destructor Change-Id: Ie24606b850a13708956808b36210a86983d62ae3 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 9 +++++++++ src/server/sensor_loader.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 785fab2..d525d98 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -50,6 +50,14 @@ sensor_loader::sensor_loader() { } +sensor_loader::~sensor_loader() +{ + for (auto it = m_handles.begin(); it != m_handles.end(); ++it) + dlclose(*it); + + m_handles.clear(); +} + sensor_loader& sensor_loader::get_instance() { static sensor_loader inst; @@ -79,6 +87,7 @@ bool sensor_loader::load(void) [&](const string &path) { void *handle; load_sensor_devices(path, handle); + m_handles.push_back(handle); } ); diff --git a/src/server/sensor_loader.h b/src/server/sensor_loader.h index 763ea9a..b303301 100644 --- a/src/server/sensor_loader.h +++ b/src/server/sensor_loader.h @@ -41,6 +41,7 @@ typedef std::map sensor_device_map_t; class sensor_loader { private: sensor_loader(); + virtual ~sensor_loader(); bool load_sensor_devices(const std::string &path, void* &handle); @@ -54,6 +55,7 @@ private: sensor_map_t m_sensors; sensor_device_map_t m_devices; + std::vector m_handles; public: static sensor_loader& get_instance(); bool load(void); -- 2.7.4 From ff14217dd4535fb3045fbf5c3d506af32faedfd9 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 21 Mar 2016 12:01:49 +0900 Subject: [PATCH 07/16] sensor_base: add data length parameter to on_event() Change-Id: I7b29eb919534e741816ceeb06fd5ddb72919707e Signed-off-by: Mu-Woong Lee --- src/server/physical_sensor.cpp | 2 +- src/server/physical_sensor.h | 2 +- src/server/sensor_event_poller.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 7964065..f7135ee 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -77,7 +77,7 @@ int physical_sensor::get_poll_fd() return m_sensor_device->get_poll_fd(); } -bool physical_sensor::on_event(const sensor_data_t *data, int remains) +bool physical_sensor::on_event(const sensor_data_t *data, int data_len, int remains) { return true; } diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index 393e4d7..d8628c1 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -40,7 +40,7 @@ public: int get_poll_fd(); - virtual bool on_event(const sensor_data_t *data, int remains); + virtual bool on_event(const sensor_data_t *data, int data_len, int remains); virtual bool read_fd(std::vector &ids); virtual int get_data(sensor_data_t **data, int *length); diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index a7ec9a4..f4a68c4 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -137,7 +137,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids break; } - if (!sensor->on_event(data, remains)) { + if (!sensor->on_event(data, data_length, remains)) { free(event); free(data); break; -- 2.7.4 From 31b8c4805238dccaa6fae117bd1fd9ee0f292d33 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 18 Mar 2016 20:50:20 +0900 Subject: [PATCH 08/16] poller: continue to handle remaining events even if on_event() returns false Change-Id: I93759e5aa8cfb46daacff01fff7763489e9827ee Signed-off-by: Mu-Woong Lee --- src/server/sensor_event_poller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index f4a68c4..6058eed 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -140,7 +140,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids if (!sensor->on_event(data, data_length, remains)) { free(event); free(data); - break; + continue; } event->sensor_id = sensor->get_id(); -- 2.7.4 From 66280a492ab672e4fd47d8ad4d5cc239c140b029 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 20:44:59 +0900 Subject: [PATCH 09/16] sensord: remove unused code in auto_rotation sensor * loading values from virtual_sensor config is not used in auto rotation sensor, so remove them and related-macros. * remove unused function Change-Id: I78b48351a334ab0861268587568fb77c3c5cdd3a Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 69 ++++------------------- src/sensor/auto_rotation/auto_rotation_sensor.h | 5 -- 2 files changed, 12 insertions(+), 62 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 0c4888a..0c50aca 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -27,63 +27,24 @@ #include #include +#include +#include #include #include #include -#include #include #include -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define SENSOR_NAME "AUTO_ROTATION_SENSOR" -#define SENSOR_TYPE_AUTO_ROTATION "AUTO_ROTATION" - -#define MS_TO_US 1000 - -#define ELEMENT_NAME "NAME" -#define ELEMENT_VENDOR "VENDOR" -#define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" -#define ELEMENT_DEFAULT_SAMPLING_TIME "DEFAULT_SAMPLING_TIME" - -#define AUTO_ROTATION_LIB "/usr/lib/sensord/libauto_rotation_sensor.so" +#define SENSOR_NAME "AUTO_ROTATION_SENSOR" auto_rotation_sensor::auto_rotation_sensor() : m_accel_sensor(NULL) , m_alg(NULL) , m_rotation(0) -, m_interval(1) -, m_rotation_time(1) // rotation state is valid from initial state, so set rotation time to non-zero value -, m_default_sampling_time(1) +, m_interval(100) +, m_rotation_time(0) { - virtual_sensor_config &config = virtual_sensor_config::get_instance(); - - if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_VENDOR, m_vendor)) { - _E("[VENDOR] is empty\n"); - throw ENXIO; - } - - _I("m_vendor = %s", m_vendor.c_str()); - - if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { - _E("[RAW_DATA_UNIT] is empty\n"); - throw ENXIO; - } - - _I("m_raw_data_unit = %s", m_raw_data_unit.c_str()); - - if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { - _E("[DEFAULT_SAMPLING_TIME] is empty\n"); - throw ENXIO; - } - - _I("m_default_sampling_time = %d", m_default_sampling_time); - - m_interval = m_default_sampling_time * MS_TO_US; } auto_rotation_sensor::~auto_rotation_sensor() @@ -124,7 +85,7 @@ sensor_type_t auto_rotation_sensor::get_type(void) unsigned int auto_rotation_sensor::get_event_type(void) { - return (AUTO_ROTATION_SENSOR << 16) | 0x0001; + return AUTO_ROTATION_EVENT_CHANGE_STATE; } const char* auto_rotation_sensor::get_name(void) @@ -153,7 +114,7 @@ bool auto_rotation_sensor::get_sensor_info(sensor_info &info) void auto_rotation_sensor::synthesize(const sensor_event_t& event) { - if (event.event_type != ACCELEROMETER_RAW_DATA_EVENT) + if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) return; int rotation; @@ -187,7 +148,7 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event) } rotation_event->sensor_id = get_id(); - rotation_event->event_type = AUTO_ROTATION_CHANGE_STATE_EVENT; + rotation_event->event_type = AUTO_ROTATION_EVENT_CHANGE_STATE; rotation_event->data_length = data_length; rotation_event->data = rotation_data; @@ -218,6 +179,9 @@ int auto_rotation_sensor::get_data(sensor_data_t **data, int *length) bool auto_rotation_sensor::set_interval(unsigned long interval) { + m_accel_sensor->add_interval((intptr_t)this , m_interval, true); + + m_interval = interval; return false; } @@ -237,7 +201,7 @@ bool auto_rotation_sensor::on_start(void) m_alg->start(); - m_accel_sensor->add_interval((intptr_t)this , (m_interval/MS_TO_US), true); + m_accel_sensor->add_interval((intptr_t)this , m_interval, true); m_accel_sensor->start(); return activate(); @@ -251,14 +215,6 @@ bool auto_rotation_sensor::on_stop(void) return deactivate(); } -bool auto_rotation_sensor::check_lib(void) -{ - if (access(AUTO_ROTATION_LIB, F_OK) < 0) - return false; - - return true; -} - auto_rotation_alg *auto_rotation_sensor::get_alg() { auto_rotation_alg *alg = new(std::nothrow) auto_rotation_alg_emul(); @@ -266,4 +222,3 @@ auto_rotation_alg *auto_rotation_sensor::get_alg() return alg; } - diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.h b/src/sensor/auto_rotation/auto_rotation_sensor.h index ef69a6d..506f244 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.h +++ b/src/sensor/auto_rotation/auto_rotation_sensor.h @@ -52,10 +52,6 @@ private: unsigned int m_interval; unsigned long long m_rotation_time; - std::string m_vendor; - std::string m_raw_data_unit; - int m_default_sampling_time; - virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); virtual bool set_wakeup(int wakeup); @@ -63,7 +59,6 @@ private: virtual bool on_start(void); virtual bool on_stop(void); - bool check_lib(void); auto_rotation_alg *get_alg(); }; -- 2.7.4 From 5145e175973bb02a4d84a2f09a28248ddfeedfb6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 16 Mar 2016 22:01:10 +0900 Subject: [PATCH 10/16] sensord: change sensor name to be the same as an sensor type name * "*_SENSOR" instead of "SENSOR_" * this patch is applied to virtual sensors Change-Id: I9c5af4a00f2e6dbff217ae6cc4bcaec4848d0a02 Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 2 +- src/sensor/gravity/gravity_sensor.cpp | 2 +- src/sensor/linear_accel/linear_accel_sensor.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 0c50aca..e1d90f1 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -36,7 +36,7 @@ #include #include -#define SENSOR_NAME "AUTO_ROTATION_SENSOR" +#define SENSOR_NAME "SENSOR_AUTO_ROTATION" auto_rotation_sensor::auto_rotation_sensor() : m_accel_sensor(NULL) diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 49ee0fe..e72f706 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -35,7 +35,7 @@ #include #include -#define SENSOR_NAME "GRAVITY_SENSOR" +#define SENSOR_NAME "SENSOR_GRAVITY" #define GRAVITY 9.80665 diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index eb50de9..7e89700 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -35,7 +35,7 @@ #include #include -#define SENSOR_NAME "LINEAR_ACCEL_SENSOR" +#define SENSOR_NAME "SENSOR_LINEAR_ACCELERATION" #define GRAVITY 9.80665 -- 2.7.4 From 850a6d5fc8313b94f4a46eb7b18b20e982879d74 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 22 Mar 2016 23:08:12 +0900 Subject: [PATCH 11/16] sensord: check whether the data is valid or not Change-Id: Ia456be16c90f949b1d32bbdc53579b41d58a477d Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 3 +++ src/server/sensor_event_poller.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index b10071f..83e5bce 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -712,6 +712,9 @@ bool command_worker::cmd_get_data(void *payload) remain_count = m_module->get_data(&data, &length); + if (remain_count < 0) + state = OP_ERROR; + // 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 diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index 6058eed..082d689 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -51,6 +51,9 @@ void sensor_event_poller::init_sensor_map() fd = sensor->get_poll_fd(); + if (fd < 0) + continue; + m_fd_sensors.insert(std::make_pair(fd, sensor)); } } -- 2.7.4 From 21430f54e9199542d00346cf735a3966d4ef92d7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 22 Mar 2016 23:09:30 +0900 Subject: [PATCH 12/16] sensord: add the comments for logic Change-Id: I68bf587381b3a9371512d3d2c74cb5091c496b94 Signed-off-by: kibak.yoon --- src/server/sensor_event_poller.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index 082d689..b6d46ca 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -117,6 +117,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids physical_sensor *sensor; std::pair ret; + /* find sensors which is based on same device(fd) */ ret = m_fd_sensors.equal_range(fd); for (auto it_sensor = ret.first; it_sensor != ret.second; ++it_sensor) { @@ -127,6 +128,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids sensor = it_sensor->second; + /* check whether the id of this sensor is in id list(parameter) or not */ auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id()); if (result == std::end(ids)) -- 2.7.4 From 5b8f49878ceeae939ee782a5b0b326eb39e64be2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 23 Mar 2016 12:20:52 +0900 Subject: [PATCH 13/16] sensord: hal: splite sensor_hal.h into sensor_hal interface and hal types Change-Id: If9ec7348721581839faecf022e29c88134debe68 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 1 + src/hal/CMakeLists.txt | 1 + src/hal/sensor_hal.h | 165 +------------------------------ src/hal/sensor_hal_types.h | 228 +++++++++++++++++++++++++++++++++++++++++++ src/server/physical_sensor.h | 1 + src/server/sensor_base.cpp | 2 +- src/server/sensor_base.h | 2 +- src/shared/sensor_common.h | 2 +- 8 files changed, 235 insertions(+), 167 deletions(-) create mode 100644 src/hal/sensor_hal_types.h diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 801cec4..5bc4a2b 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -141,6 +141,7 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files -n sensor-hal-devel %defattr(-,root,root,-) %{_includedir}/sensor/sensor_hal.h +%{_includedir}/sensor/sensor_hal_types.h %license LICENSE.APLv2 %if %{build_test_suite} == "ON" diff --git a/src/hal/CMakeLists.txt b/src/hal/CMakeLists.txt index ee01da1..7119639 100644 --- a/src/hal/CMakeLists.txt +++ b/src/hal/CMakeLists.txt @@ -2,3 +2,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensor-hal CXX) INSTALL(FILES sensor_hal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) +INSTALL(FILES sensor_hal_types.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) diff --git a/src/hal/sensor_hal.h b/src/hal/sensor_hal.h index c52f25d..21eb205 100644 --- a/src/hal/sensor_hal.h +++ b/src/hal/sensor_hal.h @@ -20,164 +20,7 @@ #include #include - -#define SENSOR_HAL_VERSION(maj, min) \ - ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* - * Sensor Types - * These types are used to controll the sensors - * - * - base unit - * acceleration values : meter per second^2 (m/s^2) - * magnetic values : micro-Tesla (uT) - * orientation values : degrees - * gyroscope values : degree/s - * temperature values : degrees centigrade - * proximity valeus : distance - * light values : lux - * pressure values : hectopascal (hPa) - * humidity : relative humidity (%) - */ -typedef enum { - SENSOR_DEVICE_UNKNOWN = -2, - SENSOR_DEVICE_ALL = -1, - SENSOR_DEVICE_ACCELEROMETER, - SENSOR_DEVICE_GRAVITY, - SENSOR_DEVICE_LINEAR_ACCELERATION, - SENSOR_DEVICE_GEOMAGNETIC, - SENSOR_DEVICE_ROTATION_VECTOR, - SENSOR_DEVICE_ORIENTATION, - SENSOR_DEVICE_GYROSCOPE, - SENSOR_DEVICE_LIGHT, - SENSOR_DEVICE_PROXIMITY, - SENSOR_DEVICE_PRESSURE, - SENSOR_DEVICE_ULTRAVIOLET, - SENSOR_DEVICE_TEMPERATURE, - SENSOR_DEVICE_HUMIDITY, - SENSOR_DEVICE_HRM, - SENSOR_DEVICE_HRM_LED_GREEN, - SENSOR_DEVICE_HRM_LED_IR, - SENSOR_DEVICE_HRM_LED_RED, - SENSOR_DEVICE_GYROSCOPE_UNCAL, - SENSOR_DEVICE_GEOMAGNETIC_UNCAL, - SENSOR_DEVICE_GYROSCOPE_RV, - SENSOR_DEVICE_GEOMAGNETIC_RV, - - SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, - SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, - - SENSOR_DEVICE_FUSION = 0x900, - SENSOR_DEVICE_AUTO_ROTATION, - SENSOR_DEVICE_AUTO_BRIGHTNESS, - - SENSOR_DEVICE_CONTEXT = 0x1000, - SENSOR_DEVICE_MOTION, - SENSOR_DEVICE_PIR, - SENSOR_DEVICE_PIR_LONG, - SENSOR_DEVICE_DUST, - SENSOR_DEVICE_THERMOMETER, - SENSOR_DEVICE_PEDOMETER, - SENSOR_DEVICE_FLAT, - SENSOR_DEVICE_HRM_RAW, - SENSOR_DEVICE_TILT, - SENSOR_DEVICE_ROTATION_VECTOR_RAW, - SENSOR_DEVICE_EXERCISE, - SENSOR_DEVICE_GSR, - SENSOR_DEVICE_SIMSENSE, - SENSOR_DEVICE_PPG, - - SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, - SENSOR_DEVICE_GESTURE_WRIST_UP, - SENSOR_DEVICE_GESTURE_WRIST_DOWN, - SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, - - SENSOR_DEVICE_WEAR_STATUS = 0x1A00, - SENSOR_DEVICE_WEAR_ON_MONITOR, - SENSOR_DEVICE_GPS_BATCH, - SENSOR_DEVICE_ACTIVITY_TRACKER, - SENSOR_DEVICE_SLEEP_DETECTOR, - SENSOR_DEVICE_NO_MOVE_DETECTOR = 0x1A80, - SENSOR_DEVICE_HRM_CTRL, - SENSOR_DEVICE_EXERCISE_COACH, - SENSOR_DEVICE_EXERCISE_HR, - SENSOR_DEVICE_RESTING_HR, - SENSOR_DEVICE_STEP_LEVEL_MONITOR, - SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, - SENSOR_DEVICE_CYCLE_MONITOR, - SENSOR_DEVICE_STRESS_MONITOR, - SENSOR_DEVICE_AUTOSESSION_EXERCISE, - SENSOR_DEVICE_STAIR_TRACKER, - -} sensor_device_type; - -/* - * A platform sensor handler is generated based on this handle - * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device. - */ -typedef struct sensor_info_t { - uint32_t id; - const char *name; - sensor_device_type type; - unsigned int event_type; // for Internal API - const char *model_name; - const char *vendor; - float min_range; - float max_range; - float resolution; - int min_interval; - int max_batch_count; - bool wakeup_supported; -} sensor_info_t; - -enum sensor_accuracy_t { - SENSOR_ACCURACY_UNDEFINED = -1, - SENSOR_ACCURACY_BAD = 0, - SENSOR_ACCURACY_NORMAL =1, - SENSOR_ACCURACY_GOOD = 2, - SENSOR_ACCURACY_VERYGOOD = 3 -}; - -#define SENSOR_DATA_VALUE_SIZE 16 - -/* sensor_data_t */ -typedef struct sensor_data_t { - int accuracy; - unsigned long long timestamp; - int value_count; - float values[SENSOR_DATA_VALUE_SIZE]; -} sensor_data_t; - -#define SENSORHUB_DATA_VALUE_SIZE 4096 - -/* sensorhub_data_t */ -typedef struct sensorhub_data_t { - int accuracy; - unsigned long long timestamp; - - /* - * Use "value_count" instead of "hub_data_size" - * which is going to be removed soon - */ - union { - int value_count; - int hub_data_size; /* deprecated */ - }; - - /* - * Use "values" instead of "hub_data" - * which is going to be removed soon - */ - union { - char values[SENSORHUB_DATA_VALUE_SIZE]; - char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ - }; -} sensorhub_data_t; +#include "sensor_hal_types.h" /* * Create devices @@ -185,11 +28,6 @@ typedef struct sensorhub_data_t { typedef void *sensor_device_t; typedef int (*create_t)(sensor_device_t **devices); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#ifdef __cplusplus /* * Sensor device interface * 1 device must be abstracted from 1 device event node @@ -233,6 +71,5 @@ public: return false; } }; -#endif /* __cplusplus */ #endif /* _SENSOR_HAL_H_ */ diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h new file mode 100644 index 0000000..9a4032b --- /dev/null +++ b/src/hal/sensor_hal_types.h @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _SENSOR_HAL_TYPES_H_ +#define _SENSOR_HAL_TYPES_H_ + +#include +#include + +#define SENSOR_HAL_VERSION(maj, min) \ + ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/* + * Sensor Types + * These types are used to controll the sensors + * + * - base unit + * acceleration values : meter per second^2 (m/s^2) + * magnetic values : micro-Tesla (uT) + * orientation values : degrees + * gyroscope values : degree/s + * temperature values : degrees centigrade + * proximity valeus : distance + * light values : lux + * pressure values : hectopascal (hPa) + * humidity : relative humidity (%) + */ +typedef enum { + SENSOR_DEVICE_UNKNOWN = -2, + SENSOR_DEVICE_ALL = -1, + SENSOR_DEVICE_ACCELEROMETER, + SENSOR_DEVICE_GRAVITY, + SENSOR_DEVICE_LINEAR_ACCELERATION, + SENSOR_DEVICE_GEOMAGNETIC, + SENSOR_DEVICE_ROTATION_VECTOR, + SENSOR_DEVICE_ORIENTATION, + SENSOR_DEVICE_GYROSCOPE, + SENSOR_DEVICE_LIGHT, + SENSOR_DEVICE_PROXIMITY, + SENSOR_DEVICE_PRESSURE, + SENSOR_DEVICE_ULTRAVIOLET, + SENSOR_DEVICE_TEMPERATURE, + SENSOR_DEVICE_HUMIDITY, + SENSOR_DEVICE_HRM, + SENSOR_DEVICE_HRM_LED_GREEN, + SENSOR_DEVICE_HRM_LED_IR, + SENSOR_DEVICE_HRM_LED_RED, + SENSOR_DEVICE_GYROSCOPE_UNCAL, + SENSOR_DEVICE_GEOMAGNETIC_UNCAL, + SENSOR_DEVICE_GYROSCOPE_RV, + SENSOR_DEVICE_GEOMAGNETIC_RV, + + SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, + SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, + + SENSOR_DEVICE_FUSION = 0x900, + SENSOR_DEVICE_AUTO_ROTATION, + SENSOR_DEVICE_AUTO_BRIGHTNESS, + + SENSOR_DEVICE_CONTEXT = 0x1000, + SENSOR_DEVICE_MOTION, + SENSOR_DEVICE_PIR, + SENSOR_DEVICE_PIR_LONG, + SENSOR_DEVICE_DUST, + SENSOR_DEVICE_THERMOMETER, + SENSOR_DEVICE_PEDOMETER, + SENSOR_DEVICE_FLAT, + SENSOR_DEVICE_HRM_RAW, + SENSOR_DEVICE_TILT, + SENSOR_DEVICE_ROTATION_VECTOR_RAW, + SENSOR_DEVICE_EXERCISE, + SENSOR_DEVICE_GSR, + SENSOR_DEVICE_SIMSENSE, + SENSOR_DEVICE_PPG, + + SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, + SENSOR_DEVICE_GESTURE_WRIST_UP, + SENSOR_DEVICE_GESTURE_WRIST_DOWN, + SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, + + SENSOR_DEVICE_WEAR_STATUS = 0x1A00, + SENSOR_DEVICE_WEAR_ON_MONITOR, + SENSOR_DEVICE_GPS_BATCH, + SENSOR_DEVICE_ACTIVITY_TRACKER, + SENSOR_DEVICE_SLEEP_DETECTOR, + SENSOR_DEVICE_NO_MOVE_DETECTOR = 0x1A80, + SENSOR_DEVICE_HRM_CTRL, + SENSOR_DEVICE_EXERCISE_COACH, + SENSOR_DEVICE_EXERCISE_HR, + SENSOR_DEVICE_RESTING_HR, + SENSOR_DEVICE_STEP_LEVEL_MONITOR, + SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, + SENSOR_DEVICE_CYCLE_MONITOR, + SENSOR_DEVICE_STRESS_MONITOR, + SENSOR_DEVICE_AUTOSESSION_EXERCISE, + SENSOR_DEVICE_STAIR_TRACKER, + +} sensor_device_type; + +/* + * A platform sensor handler is generated based on this handle + * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device. + */ +typedef struct sensor_info_t { + uint32_t id; + const char *name; + sensor_device_type type; + unsigned int event_type; // for Internal API + const char *model_name; + const char *vendor; + float min_range; + float max_range; + float resolution; + int min_interval; + int max_batch_count; + bool wakeup_supported; +} sensor_info_t; + +enum sensor_accuracy_t { + SENSOR_ACCURACY_UNDEFINED = -1, + SENSOR_ACCURACY_BAD = 0, + SENSOR_ACCURACY_NORMAL =1, + SENSOR_ACCURACY_GOOD = 2, + SENSOR_ACCURACY_VERYGOOD = 3 +}; + +#define SENSOR_DATA_VALUE_SIZE 16 + +/* sensor_data_t */ +typedef struct sensor_data_t { + int accuracy; + unsigned long long timestamp; + int value_count; + float values[SENSOR_DATA_VALUE_SIZE]; +} sensor_data_t; + +#define SENSORHUB_DATA_VALUE_SIZE 4096 + +/* sensorhub_data_t */ +typedef struct sensorhub_data_t { + int accuracy; + unsigned long long timestamp; + + /* + * Use "value_count" instead of "hub_data_size" + * which is going to be removed soon + */ + union { + int value_count; + int hub_data_size; /* deprecated */ + }; + + /* + * Use "values" instead of "hub_data" + * which is going to be removed soon + */ + union { + char values[SENSORHUB_DATA_VALUE_SIZE]; + char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ + }; +} sensorhub_data_t; + +#define SENSOR_PEDOMETER_DATA_DIFFS_SIZE 20 + +typedef struct { + int accuracy; + unsigned long long timestamp; + int value_count; /* value_count == 8 */ + float values[SENSOR_DATA_VALUE_SIZE]; + /* values = {step count, walk step count, run step count, + moving distance, calorie burned, last speed, + last stepping frequency (steps per sec), + last step status (walking, running, ...)} */ + /* Additional data attributes (not in sensor_data_t)*/ + int diffs_count; + struct differences { + int timestamp; + int steps; + int walk_steps; + int run_steps; + float distance; + float calories; + float speed; + } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; + unsigned long long accumulated_steps; + unsigned long long accumulated_walk_steps; + unsigned long long accumulated_run_steps; + double accumulated_distance; + double accumulated_calories; +} sensor_pedometer_data_t; + +enum sensor_attribute { + SENSOR_ATTR_ACTIVITY = 0x100, +}; + +enum sensor_activity { + SENSOR_ACTIVITY_UNKNOWN = 1, + SENSOR_ACTIVITY_STILL = 2, + SENSOR_ACTIVITY_WALKING = 4, + SENSOR_ACTIVITY_RUNNING = 8, + SENSOR_ACTIVITY_IN_VEHICLE = 16, + SENSOR_ACTIVITY_ON_BICYCLE = 32, +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _SENSOR_HAL_TYPES_H_ */ diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index d8628c1..cbcbc9a 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -22,6 +22,7 @@ #include #include +#include class physical_sensor : public sensor_base { public: diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 0936815..a08be8c 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index b69ca8e..5bc1c10 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include class sensor_base { diff --git a/src/shared/sensor_common.h b/src/shared/sensor_common.h index 40b95b8..e3d83ff 100644 --- a/src/shared/sensor_common.h +++ b/src/shared/sensor_common.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #define OP_ERROR -1 -- 2.7.4 From 6cc3752c971015128d8c5677f97ee88238020e32 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:43:55 +0900 Subject: [PATCH 14/16] sensord: skip the get_data process when there are some problems * after initializing data pointer, skip the get_data process Change-Id: Ie4fc53f7d3f529821542875ff97f6839dce0dfee Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 83e5bce..3583223 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -309,7 +309,8 @@ bool command_worker::send_cmd_get_data_done(int state, sensor_data_t *data) cmd_get_data_done = (cmd_get_data_done_t*)ret_packet->data(); cmd_get_data_done->state = state; - memcpy(&cmd_get_data_done->base_data , data, sizeof(sensor_data_t)); + if (data) + memcpy(&cmd_get_data_done->base_data, data, sizeof(sensor_data_t)); if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) { _E("Failed to send a cmd_get_data_done"); @@ -707,13 +708,17 @@ bool command_worker::cmd_get_data(void *payload) _E("Permission denied to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); state = OP_ERROR; + data = NULL; goto out; } remain_count = m_module->get_data(&data, &length); - if (remain_count < 0) + if (remain_count < 0) { state = OP_ERROR; + data = NULL; + goto out; + } // In case of not getting sensor data, wait short time and retry again // 1. changing interval to be less than 10ms -- 2.7.4 From f3df2191b4595f6f4db18579452135738cd05953 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 21 Mar 2016 18:48:08 +0900 Subject: [PATCH 15/16] sensord: in similar with the interval, sensor attributes are separately maintained for each client. Change-Id: If3ced3df21fd9cc84ae55d9d113487efa3d95895 Signed-off-by: Mu-Woong Lee --- src/server/command_worker.cpp | 5 +++-- src/server/sensor_base.cpp | 17 ++++++++++++++++- src/server/sensor_base.h | 8 ++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 3583223..48a3cb4 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -504,6 +504,7 @@ bool command_worker::cmd_stop(void *payload) if (m_module->stop()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, false); + m_module->delete_attribute(m_client_id); ret_value = OP_SUCCESS; } else { _E("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); @@ -778,7 +779,7 @@ bool command_worker::cmd_set_attribute_int(void *payload) goto out; } - ret_value = m_module->set_attribute(cmd->attribute, cmd->value); + ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value); out: if (!send_cmd_done(ret_value)) @@ -803,7 +804,7 @@ bool command_worker::cmd_set_attribute_str(void *payload) goto out; } - ret_value = m_module->set_attribute(cmd->attribute, cmd->value, cmd->value_len); + ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value, cmd->value_len); out: if (!send_cmd_done(ret_value)) diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index a08be8c..ad9ef95 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -90,7 +90,22 @@ bool sensor_base::flush(void) return true; } -int sensor_base::set_attribute(int32_t cmd, int32_t value) +int sensor_base::add_attribute(int client_id, int32_t attribute, int32_t value) +{ + return set_attribute(attribute, value); +} + +int sensor_base::add_attribute(int client_id, int32_t attribute, char *value, int value_size) +{ + return set_attribute(attribute, value, value_size); +} + +bool sensor_base::delete_attribute(int client_id) +{ + return true; +} + +int sensor_base::set_attribute(int32_t attribute, int32_t value) { return OP_ERROR; } diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 5bc1c10..0e013d1 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -52,8 +52,9 @@ public: virtual int get_data(sensor_data_t **data, int *length); virtual bool flush(void); - virtual int set_attribute(int32_t attribute, int32_t value); - virtual int set_attribute(int32_t attribute, char *value, int value_size); + virtual int add_attribute(int client_id, int32_t attribute, int32_t value); + virtual int add_attribute(int client_id, int32_t attribute, char *value, int value_size); + virtual bool delete_attribute(int client_id); /* start/stop */ bool start(void); @@ -91,6 +92,9 @@ private: unsigned int m_client; cmutex m_client_mutex; + virtual int set_attribute(int32_t attribute, int32_t value); + virtual int set_attribute(int32_t attribute, char *value, int value_size); + virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); -- 2.7.4 From ce4f6a793d5f3c70f834b8338464d079cbecb1e4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 19:19:13 +0900 Subject: [PATCH 16/16] sensord: use memcpy instead of copying values * if value_count is over 16(max value count), it makes a problem when values is copied in loop. Change-Id: I8f07fe76909fe995027a604ac18bb9cdb6fbf827 Signed-off-by: kibak.yoon --- src/client/command_channel.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index ca6b025..da07846 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -589,15 +589,7 @@ bool command_channel::cmd_get_data(unsigned int type, sensor_data_t* sensor_data return false; } - sensor_data_t *base_data; - base_data = &cmd_get_data_done->base_data; - - sensor_data->timestamp = base_data->timestamp; - sensor_data->accuracy = base_data->accuracy; - sensor_data->value_count = base_data->value_count; - - memcpy(sensor_data->values, base_data->values, - sizeof(sensor_data->values[0]) * base_data->value_count); + memcpy(sensor_data, &cmd_get_data_done->base_data, sizeof(sensor_data_t)); delete[] (char *)cmd_get_data_done; delete packet; -- 2.7.4