From 49826bd83f3d0a5aed484ab106c39f1a3453fddc Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 18 Dec 2015 19:47:07 +0900 Subject: [PATCH 01/16] sensord: fix the bug which returns true although there is an error Change-Id: I0ba655602ff782bd947fca3f10e66df4865d5c1c Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index dfb8ce1..9d80138 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -336,7 +336,7 @@ bool csocket::connect(const char *sock_path) } else if (!ret) { ERR("select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); close(); - return true; + return false; } if (!FD_ISSET(m_sock_fd, &write_fds)) { -- 2.7.4 From 575e3ccc29853fefcf091812afc77e6175fe91aa Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Fri, 18 Dec 2015 20:00:44 +0900 Subject: [PATCH 02/16] sensord: initialize member variables 2 csensor_event_dispatcher/accel/temperature Signed-off-by: Hongkuk, Son Change-Id: If4214b2e19dcf04fd9fe7031c22d72c7cecef3d7 --- src/server/csensor_event_dispatcher.cpp | 1 + src/server/plugins/accel/accel_sensor.cpp | 1 + src/server/plugins/temperature/temperature_sensor.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/server/csensor_event_dispatcher.cpp b/src/server/csensor_event_dispatcher.cpp index 970d776..7408520 100755 --- a/src/server/csensor_event_dispatcher.cpp +++ b/src/server/csensor_event_dispatcher.cpp @@ -30,6 +30,7 @@ using std::vector; #define MAX_PENDING_CONNECTION 32 csensor_event_dispatcher::csensor_event_dispatcher() +: m_lcd_on(false) { } diff --git a/src/server/plugins/accel/accel_sensor.cpp b/src/server/plugins/accel/accel_sensor.cpp index 9652fd4..b122f50 100755 --- a/src/server/plugins/accel/accel_sensor.cpp +++ b/src/server/plugins/accel/accel_sensor.cpp @@ -39,6 +39,7 @@ using std::vector; accel_sensor::accel_sensor() : m_sensor_hal(NULL) +, m_raw_data_unit(0.0f) , m_interval(POLL_1HZ_MS) { m_name = string(SENSOR_NAME); diff --git a/src/server/plugins/temperature/temperature_sensor.cpp b/src/server/plugins/temperature/temperature_sensor.cpp index 533dcca..5b18a5b 100755 --- a/src/server/plugins/temperature/temperature_sensor.cpp +++ b/src/server/plugins/temperature/temperature_sensor.cpp @@ -29,6 +29,7 @@ using std::vector; temperature_sensor::temperature_sensor() : m_sensor_hal(NULL) +, m_temperature(0.0f) , m_resolution(0.0f) { m_name = string(SENSOR_NAME); -- 2.7.4 From 5afcaf8ad0b140a6169486a29390a592c853c265 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 21 Dec 2015 10:41:19 +0900 Subject: [PATCH 03/16] Fix for build errors of packages that are using deprecated sensor api Change-Id: I16348de21848f571b77d24e15420e79b04cd7593 Signed-off-by: Mu-Woong Lee (cherry picked from commit 104ea8470b8dba2b6ee4990efcb10b6923ab540b) --- src/shared/sensor_internal_deprecated.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shared/sensor_internal_deprecated.h b/src/shared/sensor_internal_deprecated.h index 38665f7..cdf3084 100755 --- a/src/shared/sensor_internal_deprecated.h +++ b/src/shared/sensor_internal_deprecated.h @@ -39,6 +39,8 @@ extern "C" /*header for each sensor type*/ #include +#include + #define MAX_KEY_LEN 30 typedef struct { -- 2.7.4 From 9e0d4de2aa01f4e1f015c8a1df2797523e575c70 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 21 Dec 2015 12:01:55 +0900 Subject: [PATCH 04/16] sensord: close socket fd if accept() is failed Change-Id: I93093632a3f9bcbcbcf4007564bb6c7d9512bd7a Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 9d80138..5fbb2c1 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -154,8 +154,10 @@ bool csocket::accept(csocket& client_socket) const do { client_socket.m_sock_fd = ::accept(m_sock_fd, (sockaddr *)&m_addr, (socklen_t *)&addr_length); - if (!client_socket.is_valid()) + if (!client_socket.is_valid()) { err = errno; + ::close(client_socket.m_sock_fd); + } } while (err == EINTR); if (!client_socket.is_valid()) { -- 2.7.4 From c9a346716ee3ec1a8c0345338a9dd72757953f90 Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Tue, 22 Dec 2015 15:07:23 +0900 Subject: [PATCH 05/16] sensord: choose "Default" device when no matching device in virtual_sensors.xml -add "Default" device in virtual_sensors.xml file -when device id does not match with devices in virtual_sensors.xml, choose "Default" device Signed-off-by: Hongkuk, Son Change-Id: I37526479de706eccda36127e6d93ee66a1b32d55 --- src/server/cvirtual_sensor_config.cpp | 13 +++++++++++-- virtual_sensors.xml | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/server/cvirtual_sensor_config.cpp b/src/server/cvirtual_sensor_config.cpp index 25538ce..c963d48 100755 --- a/src/server/cvirtual_sensor_config.cpp +++ b/src/server/cvirtual_sensor_config.cpp @@ -35,6 +35,7 @@ using std::stringstream; #define DEFAULT_ATTR1 "value1" #define DEFAULT_ATTR2 "value2" #define DEFAULT_ATTR3 "value3" +#define DEFAULT_DEVICE "Default" cvirtual_sensor_config::cvirtual_sensor_config() { @@ -148,7 +149,6 @@ bool cvirtual_sensor_config::load_config(const string& config_path) attr_ptr = attr_ptr->next; } - element_node_ptr = element_node_ptr->next; } @@ -169,7 +169,16 @@ bool cvirtual_sensor_config::get(const string& sensor_type, const string& elemen if (it_device_list == m_virtual_sensor_config.end()) { ERR("There is no <%s> device\n",m_device_id.c_str()); - return false; + + m_device_id = DEFAULT_DEVICE; + it_device_list = m_virtual_sensor_config.find(m_device_id); + + if (it_device_list == m_virtual_sensor_config.end()) { + ERR("There is no Default device\n"); + return false; + } + + INFO("m_device_id is set to Default\n"); } auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); diff --git a/virtual_sensors.xml b/virtual_sensors.xml index 68282e8..c0c08f5 100755 --- a/virtual_sensors.xml +++ b/virtual_sensors.xml @@ -1,5 +1,14 @@ + + + + + + + + + -- 2.7.4 From 4846fc6c5071e734e99de9ec4ae0cb0f5d4f91d2 Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Tue, 22 Dec 2015 15:34:55 +0900 Subject: [PATCH 06/16] sensord: enable auto_rotation sensor Signed-off-by: Hongkuk, Son Change-Id: Ibce2bc591af30465c6511535a1aa1f198ebf11a9 --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 4b56aa6..d7516ed 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -21,7 +21,7 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) Requires: libsensord = %{version}-%{release} -%define auto_rotation_state OFF +%define auto_rotation_state ON %define orientation_state OFF %define gravity_state OFF %define linear_accel_state OFF -- 2.7.4 From 7d52f4c8878a16c36bf4c25b22bf796add8b93da Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 22 Dec 2015 20:53:16 +0900 Subject: [PATCH 07/16] sensord: version up to 2.0.1 Change-Id: I4d31eb4511eebc34d77bda5a2e185e8215ac6e81 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index d7516ed..cd22230 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.0 +Version: 2.0.1 Release: 0 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From 11bbc9d950316623ed4b108e9ba8fbea0f5dafa5 Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Wed, 30 Dec 2015 14:55:59 +0900 Subject: [PATCH 08/16] sensord: fix test code's sensord_() API's return type check fix to check return type as 'bool' Signed-off-by: Hongkuk, Son Change-Id: I39c4edde0be9569a187d35fe4a0310a50f705479 --- test/src/api-test.c | 11 +++-------- test/src/check-sensor.c | 15 +++++++++------ test/src/fusion-data-collection.c | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/src/api-test.c b/test/src/api-test.c index aa065f9..bdeec6a 100755 --- a/test/src/api-test.c +++ b/test/src/api-test.c @@ -38,7 +38,7 @@ void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, voi bool check_sensor_api(unsigned int event_type, int cond_value) { - int result, handle; + int handle; mainloop = g_main_loop_new(NULL, FALSE); @@ -126,9 +126,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) return false; } - result = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL); - - if (result < 0) { + result_boolean = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL); + if (!result_boolean) { free(output2); free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type); @@ -136,7 +135,6 @@ bool check_sensor_api(unsigned int event_type, int cond_value) } result_boolean = sensord_start(handle, 1); - if (!result_boolean) { sensord_unregister_event(handle, event_type); sensord_disconnect(handle); @@ -177,7 +175,6 @@ bool check_sensor_api(unsigned int event_type, int cond_value) } result_boolean = sensord_unregister_event(handle, event_type); - if (!result_boolean) { free(output2); free(output_list); @@ -186,7 +183,6 @@ bool check_sensor_api(unsigned int event_type, int cond_value) } result_boolean = sensord_stop(handle); - if (!result_boolean) { free(output2); free(output_list); @@ -195,7 +191,6 @@ bool check_sensor_api(unsigned int event_type, int cond_value) } result_boolean = sensord_disconnect(handle); - if (!result_boolean) { free(output2); free(output_list); diff --git a/test/src/check-sensor.c b/test/src/check-sensor.c index 160045e..0475880 100755 --- a/test/src/check-sensor.c +++ b/test/src/check-sensor.c @@ -243,7 +243,8 @@ void *check_sensor(void *arg) struct pthread_arguments * argu = (struct pthread_arguments *) arg; GMainLoop *mainloop; - int handle, result, start_handle, stop_handle; + int handle; + bool result, start_handle, stop_handle; mainloop = g_main_loop_new(NULL, FALSE); @@ -252,14 +253,14 @@ void *check_sensor(void *arg) result = sensord_register_event(handle, argu->event, argu->interval, 0, callback, NULL); - if (result < 0) { + if (!result) { printf("Can't register sensor\n"); return NULL; } start_handle = sensord_start(handle, 0); - if (start_handle < 0) { + if (!start_handle) { printf("Error\n\n\n\n"); sensord_unregister_event(handle, argu->event); sensord_disconnect(handle); @@ -271,14 +272,14 @@ void *check_sensor(void *arg) result = sensord_unregister_event(handle, argu->event); - if (result < 0) { + if (!result) { printf("Error\n\n"); return NULL; } stop_handle = sensord_stop(handle); - if (stop_handle < 0) { + if (!stop_handle) { printf("Error\n\n"); return NULL; } @@ -289,7 +290,9 @@ void *check_sensor(void *arg) int polling_sensor(sensor_type_t sensor_type, unsigned int event) { - int result, handle; + bool result; + int handle; + printf("Polling based\n"); sensor_t sensor; sensor = sensord_get_sensor(sensor_type); diff --git a/test/src/fusion-data-collection.c b/test/src/fusion-data-collection.c index 10c1091..6abd6f5 100755 --- a/test/src/fusion-data-collection.c +++ b/test/src/fusion-data-collection.c @@ -81,7 +81,7 @@ int main(int argc, char **argv) int i; int handle[MAXSIZE]; - int result[MAXSIZE], start_handle[MAXSIZE]; + bool result[MAXSIZE], start_handle[MAXSIZE]; unsigned int event[MAXSIZE]; int sensors[MAXSIZE]; @@ -102,13 +102,13 @@ int main(int argc, char **argv) event[i] = (sensors[i] << 16) | 0x0001; result[i] = sensord_register_event(handle[i], event[i], interval, 0, callback, NULL); - if (result[i] < 0) { + if (!result[i]) { printf("error: unable to register sensor\n"); return -1; } start_handle[i] = sensord_start(handle[i], 1); - if (start_handle[i] < 0) { + if (!start_handle[i]) { printf("error: unable to start handle\n"); sensord_unregister_event(handle[i], event[i]); sensord_disconnect(handle[i]); -- 2.7.4 From 6b2ab778c21e200d3b6a543b3ce7ed4a6dc5a7af Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Tue, 19 Jan 2016 18:25:23 +0900 Subject: [PATCH 09/16] sensord: fix default interval from 10ms to 100ms when user interval 0ms When user interval is 0, then fix it to default interval 100ms. Additionally, user can set small interval values(1~9ms) now. Signed-off-by: Hongkuk, Son Change-Id: I9f0e240b5954859a151b985e29f20b767ef50f52 --- src/client/client.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index f2b3db0..035d907 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -36,7 +36,7 @@ using std::vector; #define API __attribute__((visibility("default"))) #endif -#define MIN_INTERVAL 10 +#define DEFAULT_INTERVAL POLL_10HZ_MS static const int OP_SUCCESS = 0; static const int OP_ERROR = -1; @@ -768,8 +768,8 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int return false; } - if (interval < MIN_INTERVAL) - interval = MIN_INTERVAL; + if (interval == 0) + interval = DEFAULT_INTERVAL; INFO("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, latency: %d, cb: 0x%x, user_data: 0x%x", get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), @@ -973,9 +973,6 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int return false; } - if (interval == 0) - interval = 1; - INFO("%s changes batch of event %s[0x%x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle, interval, latency); @@ -983,8 +980,8 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int client_info.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); - if (interval < MIN_INTERVAL) - interval = MIN_INTERVAL; + if (interval == 0) + interval = DEFAULT_INTERVAL; if (!client_info.set_event_batch(handle, event_type, interval, latency)) return false; -- 2.7.4 From fb425e805e8d661b084bbb2adbcec1ad6a7ee70b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 20 Jan 2016 15:58:18 +0900 Subject: [PATCH 10/16] sensord: reordering the sensor internal type for managing them easily * Internal sensor types must be matched with sensor capi types Change-Id: Ib7ec34f67a72476e4492de57860627c08ecf7609 Signed-off-by: kibak.yoon --- src/shared/sensor_types.h | 63 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 6ac6aef..93fcfa1 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -8,42 +8,57 @@ extern "C" typedef enum { + UNKNOWN_SENSOR = -2, ALL_SENSOR = -1, - UNKNOWN_SENSOR = 0, ACCELEROMETER_SENSOR, - GEOMAGNETIC_SENSOR, - LIGHT_SENSOR, - PROXIMITY_SENSOR, - THERMOMETER_SENSOR, - GYROSCOPE_SENSOR, - PRESSURE_SENSOR, - MOTION_SENSOR, - FUSION_SENSOR, - PEDOMETER_SENSOR, - CONTEXT_SENSOR, - FLAT_SENSOR, - BIO_SENSOR, - BIO_HRM_SENSOR, - AUTO_ROTATION_SENSOR, GRAVITY_SENSOR, LINEAR_ACCEL_SENSOR, + GEOMAGNETIC_SENSOR, ROTATION_VECTOR_SENSOR, - GEOMAGNETIC_RV_SENSOR, - GAMING_RV_SENSOR, ORIENTATION_SENSOR, - TILT_SENSOR, - PIR_SENSOR, - PIR_LONG_SENSOR, + GYROSCOPE_SENSOR, + LIGHT_SENSOR, + PROXIMITY_SENSOR, + PRESSURE_SENSOR, + ULTRAVIOLET_SENSOR, TEMPERATURE_SENSOR, HUMIDITY_SENSOR, - ULTRAVIOLET_SENSOR, - DUST_SENSOR, + BIO_HRM_SENSOR, BIO_LED_GREEN_SENSOR, BIO_LED_IR_SENSOR, BIO_LED_RED_SENSOR, - RV_RAW_SENSOR, GYROSCOPE_UNCAL_SENSOR, - UNCAL_GEOMAGNETIC_SENSOR + UNCAL_GEOMAGNETIC_SENSOR, + GAMING_RV_SENSOR, + GEOMAGNETIC_RV_SENSOR, + + ACTIVITY_STATIONARY_SENSOR = 0x100, + ACTIVITY_WALK_SENSOR, + ACTIVITY_RUN_SENSOR, + ACTIVITY_IN_VEHICLE_SENSOR, + ACTIVITY_ON_BICYCLE_SENSOR, + + GESTURE_MOVEMENT_SENSOR = 0x200, + GESTURE_WRIST_UP_SENSOR, + GESTURE_WRIST_DOWN_SENSOR, + + HUMAN_PEDOMETER_SENSOR = 0x300, + HUMAN_SLEEP_MONITOR_SENSOR, + + FUSION_SENSOR = 0x900, + AUTO_ROTATION_SENSOR, + + CONTEXT_SENSOR = 0x1000, + MOTION_SENSOR, + PIR_SENSOR, + PIR_LONG_SENSOR, + DUST_SENSOR, + THERMOMETER_SENSOR, + PEDOMETER_SENSOR, + FLAT_SENSOR, + BIO_SENSOR, + TILT_SENSOR, + RV_RAW_SENSOR, } sensor_type_t; // Sensor Event Types -- 2.7.4 From ba6bb503bae07785159caf38079e523657111719 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 13:27:19 +0900 Subject: [PATCH 11/16] libsensord: support variable size of sensor data packets Change-Id: I24891583cf9b7c8d95ac09ff6e7e60388f83fb55 Signed-off-by: kibak.yoon --- src/client/csensor_event_listener.cpp | 62 ++++++++++++++++++++++++----------- src/client/csensor_event_listener.h | 3 +- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/client/csensor_event_listener.cpp b/src/client/csensor_event_listener.cpp index 8c298dc..17a1dbb 100644 --- a/src/client/csensor_event_listener.cpp +++ b/src/client/csensor_event_listener.cpp @@ -29,6 +29,9 @@ #define MS_TO_US 1000 #define MIN_DELIVERY_DIFF_FACTOR 0.75f +/* TODO: this macro should be adjusted */ +#define EVENT_BUFFER_SIZE sizeof(sensorhub_event_t) + using std::thread; using std::pair; using std::vector; @@ -54,7 +57,6 @@ csensor_event_listener::csensor_event_listener(const csensor_event_listener& lis { } - csensor_event_listener& csensor_event_listener::get_instance(void) { static csensor_event_listener inst; @@ -113,7 +115,6 @@ client_callback_info* csensor_event_listener::handle_calibration_cb(csensor_hand cal_event_info = handle_info.get_reg_event_info(cal_event_type); if ((accuracy == SENSOR_ACCURACY_BAD) && !handle_info.m_bad_accuracy && cal_event_info) { sensor_event_data_t cal_event_data; - sensor_data_t cal_data; void *cal_sensor_data; cal_event_info->m_previous_event_time = time; @@ -122,19 +123,22 @@ client_callback_info* csensor_event_listener::handle_calibration_cb(csensor_hand 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 { - cal_data.accuracy = accuracy; - cal_data.timestamp = time; - cal_data.values[0] = accuracy; - cal_data.value_count = 1; - cal_sensor_data = &cal_data; + cal_data->accuracy = accuracy; + cal_data->timestamp = time; + cal_data->values[0] = accuracy; + cal_data->value_count = 1; + cal_sensor_data = cal_data; } - cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data); + cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data, cal_sensor_data); m_client_info.set_bad_accuracy(handle_info.m_handle, true); @@ -222,9 +226,9 @@ void csensor_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); + callback_info = get_callback_info(sensor_id, event_info, &event_data, event); else - callback_info = get_callback_info(sensor_id, event_info, sensor_data); + callback_info = get_callback_info(sensor_id, event_info, sensor_data, event); if (!callback_info) { ERR("Failed to get callback_info"); @@ -259,7 +263,7 @@ void csensor_event_listener::handle_events(void* event) } -client_callback_info* csensor_event_listener::get_callback_info(sensor_id_t sensor_id, const creg_event_info *event_info, void* sensor_data) +client_callback_info* csensor_event_listener::get_callback_info(sensor_id_t sensor_id, const creg_event_info *event_info, void* sensor_data, void *buffer) { client_callback_info* callback_info; @@ -278,7 +282,10 @@ client_callback_info* csensor_event_listener::get_callback_info(sensor_id_t sens callback_info->accuracy = -1; callback_info->accuracy_user_data = NULL; callback_info->maincontext = event_info->m_maincontext; + callback_info->sensor_data = sensor_data; + callback_info->buffer = buffer; + /* if (event_info->m_cb_type == SENSOR_EVENT_CB) { callback_info->sensor_data = new(std::nothrow) char[sizeof(sensor_data_t)]; @@ -326,6 +333,7 @@ client_callback_info* csensor_event_listener::get_callback_info(sensor_id_t sens else memcpy(dest_sensor_data->event_data, src_sensor_data->event_data, src_sensor_data->event_data_size); } + */ return callback_info; } @@ -372,7 +380,7 @@ gboolean csensor_event_listener::callback_dispatcher(gpointer data) delete[] (char *)data->event_data; } - delete[] (char*)(cb_info->sensor_data); + free(cb_info->buffer); delete cb_info; /* @@ -391,39 +399,55 @@ bool csensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, int if (!len) { if(!m_poller->poll(event)) - return false; + return -1; len = m_event_socket.recv(buffer, buffer_len); if (!len) { INFO("%s failed to read after poll!", get_client_name()); - return false; + return -1; } } if (len < 0) { INFO("%s failed to recv event from event socket", get_client_name()); - return false; + return -1; } - return true; + return len; } void csensor_event_listener::listen_events(void) { - sensorhub_event_t buffer; int event; + ssize_t len = -1; do { lock l(m_thread_mutex); if (m_thread_state == THREAD_STATE_START) { - if (!sensor_event_poll(&buffer, sizeof(buffer), event)) { + void *buffer = malloc(EVENT_BUFFER_SIZE); + + if (!buffer) { + ERR("Failed to allocate memory"); + break; + } + + len = sensor_event_poll(buffer, EVENT_BUFFER_SIZE, event); + if (len <= 0) { INFO("sensor_event_poll failed"); + free(buffer); + break; + } + + void *buffer_shrinked = realloc(buffer, len); + if (!buffer_shrinked) { + ERR("Failed to allocate memory"); + free(buffer); break; } - handle_events(&buffer); + handle_events(buffer_shrinked); } else { break; } diff --git a/src/client/csensor_event_listener.h b/src/client/csensor_event_listener.h index a578f0d..21f28cf 100644 --- a/src/client/csensor_event_listener.h +++ b/src/client/csensor_event_listener.h @@ -58,6 +58,7 @@ typedef struct { int accuracy; void *accuracy_user_data; GMainContext *maincontext; + void *buffer; } client_callback_info; typedef void (*hup_observer_t)(void); @@ -109,7 +110,7 @@ private: client_callback_info* handle_calibration_cb(csensor_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 creg_event_info *event_info, void *sensor_data); + client_callback_info* get_callback_info(sensor_id_t sensor_id, const creg_event_info *event_info, void *sensor_data, void *buffer); unsigned long long renew_event_id(void); -- 2.7.4 From 1f37a109887306071e679353255ff9eb764436f4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 13:35:28 +0900 Subject: [PATCH 12/16] sensord: modify event queue & dispatcher to support new sensor event structures Change-Id: I4745524f042f7ba1ab3130928e63c33ef8d47a87 Signed-off-by: kibak.yoon --- src/server/csensor_event_dispatcher.cpp | 133 ++++++++++++++++++-------------- src/server/csensor_event_dispatcher.h | 7 +- src/server/csensor_event_queue.cpp | 48 ++---------- src/server/csensor_event_queue.h | 36 ++++++--- 4 files changed, 114 insertions(+), 110 deletions(-) diff --git a/src/server/csensor_event_dispatcher.cpp b/src/server/csensor_event_dispatcher.cpp index 7408520..06eb8a8 100755 --- a/src/server/csensor_event_dispatcher.cpp +++ b/src/server/csensor_event_dispatcher.cpp @@ -18,14 +18,13 @@ */ #include -#include #include #include #include -#include using std::thread; using std::vector; +using std::pair; #define MAX_PENDING_CONNECTION 32 @@ -130,9 +129,6 @@ void csensor_event_dispatcher::accept_connections(void) void csensor_event_dispatcher::dispatch_event(void) { - const int MAX_EVENT_PER_SENSOR = 16; - const int MAX_SENSOR_EVENT = 1 + (sensor_plugin_loader::get_instance().get_virtual_sensors().size() - * MAX_EVENT_PER_SENSOR); const int MAX_SYNTH_PER_SENSOR = 5; vector v_sensor_events(MAX_SYNTH_PER_SENSOR); @@ -141,8 +137,8 @@ void csensor_event_dispatcher::dispatch_event(void) while (true) { bool is_hub_event = false; - - void *seed_event = get_event_queue().pop(); + int seed_event_len = 0; + void *seed_event = get_event_queue().pop(&seed_event_len); unsigned int event_type = *((unsigned int *)(seed_event)); if (is_sensorhub_event(event_type)) @@ -150,11 +146,10 @@ void csensor_event_dispatcher::dispatch_event(void) if (is_hub_event) { sensorhub_event_t *sensorhub_event = (sensorhub_event_t *)seed_event; - send_sensor_events(sensorhub_event, 1, true); + send_sensorhub_events(sensorhub_event); } else { - sensor_event_t sensor_events[MAX_SENSOR_EVENT]; - unsigned int event_cnt = 0; - sensor_events[event_cnt++] = *((sensor_event_t *)seed_event); + vector< pair > sensor_events; + sensor_events.push_back(pair(seed_event, seed_event_len)); virtual_sensors v_sensors = get_active_virtual_sensors(); @@ -166,55 +161,48 @@ void csensor_event_dispatcher::dispatch_event(void) (*it_v_sensor)->synthesize(*((sensor_event_t *)seed_event), v_sensor_events); synthesized_cnt = v_sensor_events.size(); - for (int i = 0; i < synthesized_cnt; ++i) - sensor_events[event_cnt++] = v_sensor_events[i]; + for (int i = 0; i < synthesized_cnt; ++i) { + sensor_event_t *v_event = (sensor_event_t*)malloc(sizeof(sensor_event_t)); + if (!v_event) { + ERR("Failed to allocate memory"); + continue; + } + + memcpy(v_event, &v_sensor_events[i], sizeof(sensor_event_t)); + sensor_events.push_back(pair(v_event, sizeof(sensor_event_t))); + } ++it_v_sensor; } - sort_sensor_events(sensor_events, event_cnt); + sort_sensor_events(sensor_events); - for (unsigned int i = 0; i < event_cnt; ++i) { - if (is_record_event(sensor_events[i].event_type)) - put_last_event(sensor_events[i].event_type, sensor_events[i]); + for (unsigned int i = 0; i < sensor_events.size(); ++i) { + if (is_record_event(((sensor_event_t*)(sensor_events[i].first))->event_type)) + put_last_event(((sensor_event_t*)(sensor_events[i].first))->event_type, *((sensor_event_t*)(sensor_events[i].first))); } - send_sensor_events(sensor_events, event_cnt, false); + send_sensor_events(sensor_events); } - - if (is_hub_event) - delete (sensorhub_event_t *)seed_event; - else - delete (sensor_event_t *)seed_event; } } -void csensor_event_dispatcher::send_sensor_events(void* events, int event_cnt, bool is_hub_event) +void csensor_event_dispatcher::send_sensor_events(vector< pair > &events) { sensor_event_t *sensor_events = NULL; - sensorhub_event_t *sensor_hub_events = NULL; cclient_info_manager& client_info_manager = get_client_info_manager(); const int RESERVED_CLIENT_CNT = 20; static client_id_vec id_vec(RESERVED_CLIENT_CNT); - if (is_hub_event) - sensor_hub_events = (sensorhub_event_t *)events; - else - sensor_events = (sensor_event_t *)events; - - for (int i = 0; i < event_cnt; ++i) { + for (unsigned int i = 0; i < events.size(); ++i) { sensor_id_t sensor_id; unsigned int event_type; - - if (is_hub_event) { - sensor_id = sensor_hub_events[i].sensor_id; - event_type = sensor_hub_events[i].event_type; - } else { - sensor_id = sensor_events[i].sensor_id; - event_type = sensor_events[i].event_type; - } + sensor_events = (sensor_event_t*)events[i].first; + int length = events[i].second; + sensor_id = sensor_events->sensor_id; + event_type = sensor_events->event_type; id_vec.clear(); client_info_manager.get_listener_ids(sensor_id, event_type, id_vec); @@ -223,17 +211,8 @@ void csensor_event_dispatcher::send_sensor_events(void* events, int event_cnt, b while (it_client_id != id_vec.end()) { csocket client_socket; - bool ret; - - if (!client_info_manager.get_event_socket(*it_client_id, client_socket)) { - ++it_client_id; - continue; - } - - if (is_hub_event) - ret = (client_socket.send(sensor_hub_events + i, sizeof(sensorhub_event_t)) > 0); - else - ret = (client_socket.send(sensor_events + i, sizeof(sensor_event_t)) > 0); + client_info_manager.get_event_socket(*it_client_id, client_socket); + bool ret = (client_socket.send(sensor_events, length) > 0); if (ret) DBG("Event[0x%x] sent to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); @@ -242,9 +221,48 @@ void csensor_event_dispatcher::send_sensor_events(void* events, int event_cnt, b ++it_client_id; } + + free(sensor_events); } } +void csensor_event_dispatcher::send_sensorhub_events(void* events) +{ + sensorhub_event_t *sensor_hub_events; + cclient_info_manager& client_info_manager = get_client_info_manager(); + + const int RESERVED_CLIENT_CNT = 20; + static client_id_vec id_vec(RESERVED_CLIENT_CNT); + + sensor_hub_events = (sensorhub_event_t *)events; + + sensor_id_t sensor_id; + unsigned int event_type; + + sensor_id = sensor_hub_events->sensor_id; + event_type = sensor_hub_events->event_type; + + id_vec.clear(); + client_info_manager.get_listener_ids(sensor_id, event_type, id_vec); + + auto it_client_id = id_vec.begin(); + + while (it_client_id != id_vec.end()) { + csocket client_socket; + client_info_manager.get_event_socket(*it_client_id, client_socket); + bool ret = (client_socket.send(sensor_hub_events, sizeof(sensorhub_event_t)) > 0); + + if (ret) + DBG("Event[0x%x] sent to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); + else + ERR("Failed to send event[0x%x] to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); + + ++it_client_id; + } + + free(sensor_hub_events); +} + cclient_info_manager& csensor_event_dispatcher::get_client_info_manager(void) { return cclient_info_manager::get_instance(); @@ -296,16 +314,17 @@ virtual_sensors csensor_event_dispatcher::get_active_virtual_sensors(void) return m_active_virtual_sensors; } -void csensor_event_dispatcher::sort_sensor_events(sensor_event_t *events, unsigned int cnt) +struct sort_comp { + bool operator()(const pair &left, const pair &right) { + return ((sensor_event_t*)(left.first))->data.timestamp < ((sensor_event_t*)(right.first))->data.timestamp; + } +}; + +void csensor_event_dispatcher::sort_sensor_events(vector< pair > &events) { - std::sort(events, events + cnt, - [](const sensor_event_t& a, const sensor_event_t &b)->bool { - return a.data.timestamp < b.data.timestamp; - } - ); + std::sort(events.begin(), events.end(), sort_comp()); } - void csensor_event_dispatcher::request_last_event(int client_id, sensor_id_t sensor_id) { cclient_info_manager& client_info_manager = get_client_info_manager(); diff --git a/src/server/csensor_event_dispatcher.h b/src/server/csensor_event_dispatcher.h index 27131c2..bb40ac2 100755 --- a/src/server/csensor_event_dispatcher.h +++ b/src/server/csensor_event_dispatcher.h @@ -27,6 +27,8 @@ #include #include #include +#include + typedef std::unordered_map event_type_last_event_map; typedef std::list virtual_sensors; @@ -51,7 +53,8 @@ private: void accept_event_channel(csocket client_socket); void dispatch_event(void); - void send_sensor_events(void* events, int event_cnt, bool is_hub_event); + void send_sensor_events(std::vector< std::pair > &events); + void send_sensorhub_events(void* events); static cclient_info_manager& get_client_info_manager(void); static csensor_event_queue& get_event_queue(void); @@ -62,7 +65,7 @@ private: bool has_active_virtual_sensor(virtual_sensor *sensor); virtual_sensors get_active_virtual_sensors(void); - void sort_sensor_events(sensor_event_t *events, unsigned int cnt); + void sort_sensor_events(std::vector< std::pair > &events); public: static csensor_event_dispatcher& get_instance(); bool run(void); diff --git a/src/server/csensor_event_queue.cpp b/src/server/csensor_event_queue.cpp index f75fa42..bc907e1 100644 --- a/src/server/csensor_event_queue.cpp +++ b/src/server/csensor_event_queue.cpp @@ -26,63 +26,31 @@ csensor_event_queue& csensor_event_queue::get_instance() return inst; } -void csensor_event_queue::push(const sensor_event_t &event) -{ - sensor_event_t *new_event = new(std::nothrow) sensor_event_t; - retm_if(!new_event, "Failed to allocate memory"); - *new_event = event; - - push_internal(new_event); -} - -void csensor_event_queue::push(sensor_event_t *event) -{ - push_internal(event); -} - -void csensor_event_queue::push(const sensorhub_event_t &event) -{ - sensorhub_event_t *new_event = new(std::nothrow) sensorhub_event_t; - retm_if(!new_event, "Failed to allocate memory"); - *new_event = event; - - push_internal(new_event); -} - -void csensor_event_queue::push(sensorhub_event_t *event) -{ - push_internal(event); -} - -void csensor_event_queue::push_internal(void *event) +void csensor_event_queue::push_internal(void *event, int length) { lock l(m_mutex); bool wake = m_queue.empty(); if (m_queue.size() >= QUEUE_FULL_SIZE) { ERR("Queue is full, drop it!"); - - unsigned int event_type = *((unsigned int *)(event)); - - if (is_sensorhub_event(event_type)) - delete (sensorhub_event_t *)event; - else - delete (sensor_event_t *)event; + free(event); } else - m_queue.push(event); + m_queue.push(std::pair(event, length)); if (wake) m_cond_var.notify_one(); } -void* csensor_event_queue::pop(void) +void* csensor_event_queue::pop(int *length) { ulock u(m_mutex); while (m_queue.empty()) m_cond_var.wait(u); - void* event = m_queue.top(); + std::pair event = m_queue.top(); m_queue.pop(); - return event; + + *length = event.second; + return event.first; } diff --git a/src/server/csensor_event_queue.h b/src/server/csensor_event_queue.h index 8ae00d2..a72ca4a 100644 --- a/src/server/csensor_event_queue.h +++ b/src/server/csensor_event_queue.h @@ -20,6 +20,8 @@ #if !defined(_CSENSOR_EVENT_QUEUE_CLASS_H_) #define _CSENSOR_EVENT_QUEUE_CLASS_H_ #include +#include +#include #include #include #include @@ -34,9 +36,9 @@ private: class compare { public: - bool operator() (void* &v1,void *&v2) { - sensor_event_t *e1 = (sensor_event_t *)v1; - sensor_event_t *e2 = (sensor_event_t *)v2; + bool operator() (std::pair v1, std::pair v2) { + sensor_event_t *e1 = (sensor_event_t *)v1.first; + sensor_event_t *e2 = (sensor_event_t *)v2.first; bool prioritize_e1 = true; bool prioritize_e2 = true; @@ -72,7 +74,7 @@ private: } }; - std::priority_queue, compare> m_queue; + std::priority_queue, std::vector>, compare> m_queue; std::mutex m_mutex; std::condition_variable m_cond_var; @@ -84,15 +86,27 @@ private: ~csensor_event_queue() {}; csensor_event_queue(const csensor_event_queue &) {}; csensor_event_queue& operator=(const csensor_event_queue &); - void push_internal(void *event); + void push_internal(void *event, int length); public: static csensor_event_queue& get_instance(); - void push(const sensor_event_t &event); - void push(sensor_event_t *event); - void push(const sensorhub_event_t &event); - void push(sensorhub_event_t *event); - - void* pop(void); + template void push(const T &event); + template void push(T *event); + void* pop(int *length); }; +template +void csensor_event_queue::push(const T &event) +{ + void *new_event = malloc(sizeof(event)); + if (!new_event) + return; + memcpy(new_event, &event, sizeof(event)); + push_internal(new_event, sizeof(event)); +} + +template +void csensor_event_queue::push(T *event) +{ + push_internal(event, sizeof(event)); +} #endif -- 2.7.4 From b1a6932fef7cae5bbe92b447740bf3ed0cd8b7de Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 13:45:29 +0900 Subject: [PATCH 13/16] sensord: remove sensor plugins in sensor fw sensor plugins in sensor fw is not necessary anymore in new architecture. so they are removed. * virtual sensors will temporarily disable in order to build sensor fw Change-Id: Ib53dd20e853f06f6775c1b9bdfee2111ce6cf01f Signed-off-by: kibak.yoon --- src/server/CMakeLists.txt | 2 +- src/server/plugins/accel/accel_sensor.cpp | 185 ------------- src/server/plugins/accel/accel_sensor.h | 55 ---- .../plugins/bio_led_red/bio_led_red_sensor.cpp | 144 ---------- .../plugins/bio_led_red/bio_led_red_sensor.h | 50 ---- src/server/plugins/geo/geo_sensor.cpp | 168 ------------ src/server/plugins/geo/geo_sensor.h | 53 ---- src/server/plugins/gyro/gyro_sensor.cpp | 172 ------------ src/server/plugins/gyro/gyro_sensor.h | 51 ---- .../gyroscope_uncal/gyroscope_uncal_sensor.cpp | 303 --------------------- .../gyroscope_uncal/gyroscope_uncal_sensor.h | 70 ----- src/server/plugins/light/light_sensor.cpp | 193 ------------- src/server/plugins/light/light_sensor.h | 55 ---- src/server/plugins/pressure/pressure_sensor.cpp | 146 ---------- src/server/plugins/pressure/pressure_sensor.h | 53 ---- src/server/plugins/proxi/proxi_sensor.cpp | 173 ------------ src/server/plugins/proxi/proxi_sensor.h | 68 ----- .../rotation_vector/rv_raw/rv_raw_sensor.cpp | 150 ---------- .../plugins/rotation_vector/rv_raw/rv_raw_sensor.h | 50 ---- .../plugins/temperature/temperature_sensor.cpp | 157 ----------- .../plugins/temperature/temperature_sensor.h | 53 ---- .../plugins/ultraviolet/ultraviolet_sensor.cpp | 157 ----------- .../plugins/ultraviolet/ultraviolet_sensor.h | 50 ---- 23 files changed, 1 insertion(+), 2557 deletions(-) delete mode 100755 src/server/plugins/accel/accel_sensor.cpp delete mode 100755 src/server/plugins/accel/accel_sensor.h delete mode 100755 src/server/plugins/bio_led_red/bio_led_red_sensor.cpp delete mode 100755 src/server/plugins/bio_led_red/bio_led_red_sensor.h delete mode 100755 src/server/plugins/geo/geo_sensor.cpp delete mode 100755 src/server/plugins/geo/geo_sensor.h delete mode 100755 src/server/plugins/gyro/gyro_sensor.cpp delete mode 100755 src/server/plugins/gyro/gyro_sensor.h delete mode 100755 src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.cpp delete mode 100755 src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.h delete mode 100755 src/server/plugins/light/light_sensor.cpp delete mode 100755 src/server/plugins/light/light_sensor.h delete mode 100755 src/server/plugins/pressure/pressure_sensor.cpp delete mode 100755 src/server/plugins/pressure/pressure_sensor.h delete mode 100755 src/server/plugins/proxi/proxi_sensor.cpp delete mode 100755 src/server/plugins/proxi/proxi_sensor.h delete mode 100755 src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp delete mode 100755 src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.h delete mode 100755 src/server/plugins/temperature/temperature_sensor.cpp delete mode 100755 src/server/plugins/temperature/temperature_sensor.h delete mode 100755 src/server/plugins/ultraviolet/ultraviolet_sensor.cpp delete mode 100755 src/server/plugins/ultraviolet/ultraviolet_sensor.h diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index a17facd..e059764 100755 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -4,7 +4,7 @@ project(sensord CXX) INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(server_pkgs REQUIRED glib-2.0 gio-2.0 dlog libsystemd-daemon libxml-2.0 cynara-client cynara-creds-socket cynara-session) -add_subdirectory(plugins) +#add_subdirectory(plugins) add_definitions(${PLUGIN_DEFS}) diff --git a/src/server/plugins/accel/accel_sensor.cpp b/src/server/plugins/accel/accel_sensor.cpp deleted file mode 100755 index b122f50..0000000 --- a/src/server/plugins/accel/accel_sensor.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include - -#include -#include -#include - -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define GRAVITY 9.80665 -#define G_TO_MG 1000 - -#define RAW_DATA_TO_G_UNIT(X) (((float)(X))/((float)G_TO_MG)) -#define RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(X) (GRAVITY * (RAW_DATA_TO_G_UNIT(X))) - -#define SENSOR_NAME "ACCELEROMETER_SENSOR" - -accel_sensor::accel_sensor() -: m_sensor_hal(NULL) -, m_raw_data_unit(0.0f) -, m_interval(POLL_1HZ_MS) -{ - m_name = string(SENSOR_NAME); - - vector supported_events = { - ACCELEROMETER_RAW_DATA_EVENT, - ACCELEROMETER_UNPROCESSED_DATA_EVENT, - }; - - for_each(supported_events.begin(), supported_events.end(), - bind1st(mem_fun(&sensor_base::register_supported_event), this)); - - physical_sensor::set_poller(accel_sensor::working, this); -} - -accel_sensor::~accel_sensor() -{ - INFO("accel_sensor is destroyed!\n"); -} - -bool accel_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ACCELEROMETER); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (m_sensor_hal->get_properties(properties) == false) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - m_raw_data_unit = properties.resolution / GRAVITY * G_TO_MG; - - INFO("m_raw_data_unit accel : [%f]\n", m_raw_data_unit); - - INFO("%s is created!\n", sensor_base::get_name()); - return true; -} - -void accel_sensor::get_types(vector &types) -{ - types.push_back(ACCELEROMETER_SENSOR); -} - -bool accel_sensor::working(void *inst) -{ - accel_sensor *sensor = (accel_sensor*)inst; - return sensor->process_event(); -} - -bool accel_sensor::process_event(void) -{ - sensor_event_t base_event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(base_event.data); - - AUTOLOCK(m_mutex); - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(ACCELEROMETER_UNPROCESSED_DATA_EVENT)) { - base_event.sensor_id = get_id(); - base_event.event_type = ACCELEROMETER_UNPROCESSED_DATA_EVENT; - push(base_event); - } - - if (get_client_cnt(ACCELEROMETER_RAW_DATA_EVENT)) { - base_event.sensor_id = get_id(); - base_event.event_type = ACCELEROMETER_RAW_DATA_EVENT; - raw_to_base(base_event.data); - push(base_event); - } - - return true; -} - -bool accel_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool accel_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool accel_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int accel_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - if (m_sensor_hal->get_sensor_data(data) < 0) { - ERR("Failed to get sensor data"); - return -1; - } - - if (type == ACCELEROMETER_RAW_DATA_EVENT) { - raw_to_base(data); - } else { - ERR("Does not support type: 0x%x", type); - return -1; - } - - return 0; -} - -bool accel_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - m_interval = interval; - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void accel_sensor::raw_to_base(sensor_data_t &data) -{ - data.value_count = 3; - data.values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[0] * m_raw_data_unit); - data.values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[1] * m_raw_data_unit); - data.values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data.values[2] * m_raw_data_unit); -} diff --git a/src/server/plugins/accel/accel_sensor.h b/src/server/plugins/accel/accel_sensor.h deleted file mode 100755 index a873538..0000000 --- a/src/server/plugins/accel/accel_sensor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _ACCEL_SENSOR_H_ -#define _ACCEL_SENSOR_H_ - -#include - -#include -#include - -class accel_sensor : public physical_sensor { -public: - accel_sensor(); - virtual ~accel_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - virtual bool set_interval(unsigned long interval); - virtual int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - -private: - sensor_hal *m_sensor_hal; - cmutex m_value_mutex; - - float m_raw_data_unit; - - unsigned long m_interval; - - virtual bool on_start(void); - virtual bool on_stop(void); - void raw_to_base(sensor_data_t &data); - bool process_event(void); -}; - -#endif diff --git a/src/server/plugins/bio_led_red/bio_led_red_sensor.cpp b/src/server/plugins/bio_led_red/bio_led_red_sensor.cpp deleted file mode 100755 index a302fbd..0000000 --- a/src/server/plugins/bio_led_red/bio_led_red_sensor.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include - -#include -#include -#include - -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define SENSOR_NAME "BIO_LED_RED_SENSOR" - -bio_led_red_sensor::bio_led_red_sensor() -: m_sensor_hal(NULL) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(BIO_LED_RED_RAW_DATA_EVENT); - - physical_sensor::set_poller(bio_led_red_sensor::working, this); -} - -bio_led_red_sensor::~bio_led_red_sensor() -{ - INFO("bio_led_red_sensor is destroyed!"); -} - -bool bio_led_red_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_BIO_LED_RED); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - INFO("%s is created!", sensor_base::get_name()); - - return true; -} - -void bio_led_red_sensor::get_types(vector &types) -{ - types.push_back(BIO_LED_RED_SENSOR); -} - -bool bio_led_red_sensor::working(void *inst) -{ - bio_led_red_sensor *sensor = (bio_led_red_sensor*)inst; - return sensor->process_event(); -} - -bool bio_led_red_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(BIO_LED_RED_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = BIO_LED_RED_RAW_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - return true; -} - -bool bio_led_red_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool bio_led_red_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool bio_led_red_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int bio_led_red_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int ret; - - ret = m_sensor_hal->get_sensor_data(data); - - if (ret < 0) - return -1; - - return -1; -} - -bool bio_led_red_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void bio_led_red_sensor::raw_to_base(sensor_data_t &data) -{ - -} diff --git a/src/server/plugins/bio_led_red/bio_led_red_sensor.h b/src/server/plugins/bio_led_red/bio_led_red_sensor.h deleted file mode 100755 index 78af52a..0000000 --- a/src/server/plugins/bio_led_red/bio_led_red_sensor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _HRM_RED_SENSOR_H_ -#define _HRM_RED_SENSOR_H_ - -#include - -#include -#include - -class bio_led_red_sensor : public physical_sensor { -public: - bio_led_red_sensor(); - virtual ~bio_led_red_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - virtual int get_sensor_data(unsigned int type, sensor_data_t &data); -private: - sensor_hal *m_sensor_hal; - - virtual bool on_start(void); - virtual bool on_stop(void); - bool process_event(void); - void raw_to_base(sensor_data_t &data); -}; - -#endif - diff --git a/src/server/plugins/geo/geo_sensor.cpp b/src/server/plugins/geo/geo_sensor.cpp deleted file mode 100755 index 0b86a0f..0000000 --- a/src/server/plugins/geo/geo_sensor.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include - -#include -#include - -using std::string; -using std::vector; - -#define SENSOR_NAME "GEOMAGNETIC_SENSOR" - -geo_sensor::geo_sensor() -: m_sensor_hal(NULL) -, m_resolution(0.0f) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(GEOMAGNETIC_RAW_DATA_EVENT); - register_supported_event(GEOMAGNETIC_UNPROCESSED_DATA_EVENT); - - physical_sensor::set_poller(geo_sensor::working, this); -} - -geo_sensor::~geo_sensor() -{ - INFO("geo_sensor is destroyed!\n"); -} - -bool geo_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GEOMAGNETIC); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (m_sensor_hal->get_properties(properties) == false) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - m_resolution = properties.resolution; - - INFO("%s is created!\n", sensor_base::get_name()); - - return true; -} - -void geo_sensor::get_types(vector &types) -{ - types.push_back(GEOMAGNETIC_SENSOR); -} - -bool geo_sensor::working(void *inst) -{ - geo_sensor *sensor = (geo_sensor*)inst; - return sensor->process_event(); -} - -bool geo_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - AUTOLOCK(m_mutex); - - if (get_client_cnt(GEOMAGNETIC_UNPROCESSED_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = GEOMAGNETIC_UNPROCESSED_DATA_EVENT; - push(event); - } - - if (get_client_cnt(GEOMAGNETIC_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = GEOMAGNETIC_RAW_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - return true; -} - -bool geo_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool geo_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool geo_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int geo_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int state; - - if (type != GEOMAGNETIC_RAW_DATA_EVENT) - return -1; - - state = m_sensor_hal->get_sensor_data(data); - raw_to_base(data); - - if (state < 0) { - ERR("m_sensor_hal get struct_data fail\n"); - return -1; - } - - return 0; -} - -bool geo_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void geo_sensor::raw_to_base(sensor_data_t &data) -{ - data.value_count = 3; - data.values[0] = data.values[0] * m_resolution; - data.values[1] = data.values[1] * m_resolution; - data.values[2] = data.values[2] * m_resolution; -} diff --git a/src/server/plugins/geo/geo_sensor.h b/src/server/plugins/geo/geo_sensor.h deleted file mode 100755 index df1e2c3..0000000 --- a/src/server/plugins/geo/geo_sensor.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _GEO_SENSOR_H_ -#define _GEO_SENSOR_H_ - -#include - -#include -#include - -class geo_sensor : public physical_sensor { -public: - geo_sensor(); - virtual ~geo_sensor(); - - virtual bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - virtual bool set_interval(unsigned long interval); - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); -private: - sensor_hal *m_sensor_hal; - - float m_resolution; - - virtual bool on_start(void); - virtual bool on_stop(void); - bool process_event(void); - void raw_to_base(sensor_data_t &data); -}; - -#endif - diff --git a/src/server/plugins/gyro/gyro_sensor.cpp b/src/server/plugins/gyro/gyro_sensor.cpp deleted file mode 100755 index 5fa0f68..0000000 --- a/src/server/plugins/gyro/gyro_sensor.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include - -#include -#include - -using std::string; -using std::vector; - -#define MS_TO_US 1000 -#define DPS_TO_MDPS 1000 -#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS)) - -#define SENSOR_NAME "GYROSCOPE_SENSOR" - -gyro_sensor::gyro_sensor() -: m_sensor_hal(NULL) -, m_resolution(0.0f) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(GYROSCOPE_RAW_DATA_EVENT); - register_supported_event(GYROSCOPE_UNPROCESSED_DATA_EVENT); - - physical_sensor::set_poller(gyro_sensor::working, this); -} - -gyro_sensor::~gyro_sensor() -{ - INFO("gyro_sensor is destroyed!\n"); -} - -bool gyro_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GYROSCOPE); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (m_sensor_hal->get_properties(properties) == false) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - m_resolution = properties.resolution; - - INFO("%s is created!\n", sensor_base::get_name()); - - return true; -} - -void gyro_sensor::get_types(vector &types) -{ - types.push_back(GYROSCOPE_SENSOR); -} - -bool gyro_sensor::working(void *inst) -{ - gyro_sensor *sensor = (gyro_sensor*)inst; - return sensor->process_event();; -} - -bool gyro_sensor::process_event(void) -{ - sensor_event_t event; - - if (m_sensor_hal->is_data_ready() == false) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(GYROSCOPE_UNPROCESSED_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = GYROSCOPE_UNPROCESSED_DATA_EVENT; - push(event); - } - - if (get_client_cnt(GYROSCOPE_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = GYROSCOPE_RAW_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - return true; -} - -bool gyro_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool gyro_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool gyro_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int gyro_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int state; - - if (type != GYROSCOPE_RAW_DATA_EVENT) - return -1; - - state = m_sensor_hal->get_sensor_data(data); - - if (state < 0) { - ERR("m_sensor_hal get struct_data fail\n"); - return -1; - } - - raw_to_base(data); - - return 0; -} - -bool gyro_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void gyro_sensor::raw_to_base(sensor_data_t &data) -{ - data.value_count = 3; - data.values[0] = data.values[0] * m_resolution; - data.values[1] = data.values[1] * m_resolution; - data.values[2] = data.values[2] * m_resolution; -} diff --git a/src/server/plugins/gyro/gyro_sensor.h b/src/server/plugins/gyro/gyro_sensor.h deleted file mode 100755 index 81bcb7b..0000000 --- a/src/server/plugins/gyro/gyro_sensor.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _GYRO_SENSOR_H_ -#define _GYRO_SENSOR_H_ - -#include - -#include -#include - -class gyro_sensor : public physical_sensor { -public: - gyro_sensor(); - virtual ~gyro_sensor(); - - virtual bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - virtual bool set_interval(unsigned long interval); - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); -private: - sensor_hal *m_sensor_hal; - float m_resolution; - - virtual bool on_start(void); - virtual bool on_stop(void); - void raw_to_base(sensor_data_t &data); - bool process_event(void); -}; - -#endif diff --git a/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.cpp b/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.cpp deleted file mode 100755 index cd1ff15..0000000 --- a/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 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. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using std::vector; -using std::string; - -#define SENSOR_NAME "GYROSCOPE_UNCAL_SENSOR" -#define SENSOR_TYPE_GYROSCOPE_UNCAL "GYROSCOPE_UNCAL" - -#define GYROSCOPE_ENABLED 0x01 -#define GYRO_BIAS_ENABLED 0x02 -#define GYROSCOPE_UNCAL_BIAS_ENABLED 3 - -#define INITIAL_VALUE -1 - -#define MS_TO_US 1000 -#define MIN_DELIVERY_DIFF_FACTOR 0.75f - -#define PI 3.141593 -#define AZIMUTH_OFFSET_DEGREES 360 -#define AZIMUTH_OFFSET_RADIANS (2 * PI) - -#define ELEMENT_NAME "NAME" -#define ELEMENT_VENDOR "VENDOR" -#define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" -#define ELEMENT_DEFAULT_SAMPLING_TIME "DEFAULT_SAMPLING_TIME" - -gyroscope_uncal_sensor::gyroscope_uncal_sensor() -: m_accel_sensor(NULL) -, m_magnetic_sensor(NULL) -, m_gyro_sensor(NULL) -, m_fusion_sensor(NULL) -, m_time(0) -{ - cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); - if (!fusion_sensor_hal) - m_hardware_fusion = false; - else - m_hardware_fusion = true; - - m_name = string(SENSOR_NAME); - register_supported_event(GYROSCOPE_UNCAL_RAW_DATA_EVENT); - - if (!config.get(SENSOR_TYPE_GYROSCOPE_UNCAL, ELEMENT_VENDOR, m_vendor)) { - ERR("[VENDOR] is empty\n"); - throw ENXIO; - } - - INFO("m_vendor = %s", m_vendor.c_str()); - - if (!config.get(SENSOR_TYPE_GYROSCOPE_UNCAL, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { - ERR("[RAW_DATA_UNIT] is empty\n"); - throw ENXIO; - } - - INFO("m_raw_data_unit = %s", m_raw_data_unit.c_str()); - - if (!config.get(SENSOR_TYPE_GYROSCOPE_UNCAL, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { - ERR("[DEFAULT_SAMPLING_TIME] is empty\n"); - throw ENXIO; - } - - INFO("m_default_sampling_time = %d", m_default_sampling_time); - - m_interval = m_default_sampling_time * MS_TO_US; -} - -gyroscope_uncal_sensor::~gyroscope_uncal_sensor() -{ - INFO("gyroscope_uncal_sensor is destroyed!\n"); -} - -bool gyroscope_uncal_sensor::init(void) -{ - m_accel_sensor = sensor_plugin_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_gyro_sensor = sensor_plugin_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); - m_magnetic_sensor = sensor_plugin_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - m_fusion_sensor = sensor_plugin_loader::get_instance().get_sensor(FUSION_SENSOR); - - if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor || !m_fusion_sensor) { - ERR("Failed to load sensors, accel: 0x%x, gyro: 0x%x, mag: 0x%x, fusion: 0x%x", - m_accel_sensor, m_gyro_sensor, m_magnetic_sensor, m_fusion_sensor); - return false; - } - - INFO("%s is created!\n", sensor_base::get_name()); - - return true; -} - -void gyroscope_uncal_sensor::get_types(vector &types) -{ - types.push_back(GYROSCOPE_UNCAL_SENSOR); -} - -bool gyroscope_uncal_sensor::on_start(void) -{ - AUTOLOCK(m_mutex); - - if (!m_hardware_fusion) { - m_accel_sensor->add_client(ACCELEROMETER_RAW_DATA_EVENT); - m_accel_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_accel_sensor->start(); - m_gyro_sensor->add_client(GYROSCOPE_RAW_DATA_EVENT); - m_gyro_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_gyro_sensor->start(); - m_magnetic_sensor->add_client(GEOMAGNETIC_RAW_DATA_EVENT); - m_magnetic_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_magnetic_sensor->start(); - } - - m_fusion_sensor->register_supported_event(FUSION_GYROSCOPE_UNCAL_EVENT); - m_fusion_sensor->register_supported_event(FUSION_GYROSCOPE_UNCAL_ENABLED); - m_fusion_sensor->add_client(FUSION_GYROSCOPE_UNCAL_EVENT); - m_fusion_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_fusion_sensor->start(); - - activate(); - return true; -} - -bool gyroscope_uncal_sensor::on_stop(void) -{ - AUTOLOCK(m_mutex); - - if (!m_hardware_fusion) { - m_accel_sensor->delete_client(ACCELEROMETER_RAW_DATA_EVENT); - m_accel_sensor->delete_interval((intptr_t)this, false); - m_accel_sensor->stop(); - m_gyro_sensor->delete_client(GYROSCOPE_RAW_DATA_EVENT); - m_gyro_sensor->delete_interval((intptr_t)this, false); - m_gyro_sensor->stop(); - m_magnetic_sensor->delete_client(GEOMAGNETIC_RAW_DATA_EVENT); - m_magnetic_sensor->delete_interval((intptr_t)this, false); - m_magnetic_sensor->stop(); - } - - m_fusion_sensor->delete_client(FUSION_GYROSCOPE_UNCAL_EVENT); - m_fusion_sensor->delete_interval((intptr_t)this, false); - m_fusion_sensor->unregister_supported_event(FUSION_GYROSCOPE_UNCAL_EVENT); - m_fusion_sensor->unregister_supported_event(FUSION_GYROSCOPE_UNCAL_ENABLED); - m_fusion_sensor->stop(); - - deactivate(); - return true; -} - -bool gyroscope_uncal_sensor::add_interval(int client_id, unsigned int interval) -{ - AUTOLOCK(m_mutex); - - if (!m_hardware_fusion) { - m_accel_sensor->add_interval(client_id, interval, false); - m_gyro_sensor->add_interval(client_id, interval, false); - m_magnetic_sensor->add_interval(client_id, interval, false); - } - - m_fusion_sensor->add_interval(client_id, interval, false); - - return sensor_base::add_interval(client_id, interval, false); -} - -bool gyroscope_uncal_sensor::delete_interval(int client_id) -{ - AUTOLOCK(m_mutex); - - if (!m_hardware_fusion) { - m_accel_sensor->delete_interval(client_id, false); - m_gyro_sensor->delete_interval(client_id, false); - m_magnetic_sensor->delete_interval(client_id, false); - } - - m_fusion_sensor->delete_interval(client_id, false); - - return sensor_base::delete_interval(client_id, false); -} - -void gyroscope_uncal_sensor::synthesize(const sensor_event_t &event, vector &outs) -{ - sensor_event_t gyroscope_uncal_event; - unsigned long long diff_time; - - if (event.event_type == GYROSCOPE_RAW_DATA_EVENT) { - diff_time = event.data.timestamp - m_time; - - if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) - return; - - m_gyro.m_data.m_vec[0] = event.data.values[0]; - m_gyro.m_data.m_vec[1] = event.data.values[1]; - m_gyro.m_data.m_vec[2] = event.data.values[2]; - - m_gyro.m_time_stamp = event.data.timestamp; - - m_enable_gyroscope_uncal |= GYROSCOPE_ENABLED; - } - - if (event.event_type == FUSION_GYROSCOPE_UNCAL_EVENT) { - diff_time = event.data.timestamp - m_time; - - if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) - return; - - m_fusion.m_data.m_vec[0] = event.data.values[0]; - m_fusion.m_data.m_vec[1] = event.data.values[1]; - m_fusion.m_data.m_vec[2] = event.data.values[2]; - - m_fusion.m_time_stamp = event.data.timestamp; - - m_enable_gyroscope_uncal |= GYRO_BIAS_ENABLED; - } - - if (m_enable_gyroscope_uncal == GYROSCOPE_UNCAL_BIAS_ENABLED) { - m_enable_gyroscope_uncal = 0; - - m_time = get_timestamp(); - gyroscope_uncal_event.sensor_id = get_id(); - gyroscope_uncal_event.event_type = GYROSCOPE_UNCAL_RAW_DATA_EVENT; - gyroscope_uncal_event.data.value_count = 6; - gyroscope_uncal_event.data.timestamp = m_time; - gyroscope_uncal_event.data.accuracy = SENSOR_ACCURACY_GOOD; - gyroscope_uncal_event.data.values[0] = m_gyro.m_data.m_vec[0]; - gyroscope_uncal_event.data.values[1] = m_gyro.m_data.m_vec[1]; - gyroscope_uncal_event.data.values[2] = m_gyro.m_data.m_vec[2]; - - gyroscope_uncal_event.data.values[3] = m_fusion.m_data.m_vec[0]; - gyroscope_uncal_event.data.values[4] = m_fusion.m_data.m_vec[1]; - gyroscope_uncal_event.data.values[5] = m_fusion.m_data.m_vec[2]; - - push(gyroscope_uncal_event); - } - - return; -} - -int gyroscope_uncal_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t &data) -{ - sensor_data_t fusion_data, gyro_data; - - if (event_type != GYROSCOPE_UNCAL_RAW_DATA_EVENT) - return -1; - - m_fusion_sensor->get_sensor_data(FUSION_GYROSCOPE_UNCAL_ENABLED, fusion_data); - m_gyro_sensor->get_sensor_data(GYROSCOPE_RAW_DATA_EVENT, gyro_data); - - data.accuracy = fusion_data.accuracy; - data.timestamp = get_timestamp(); - data.value_count = 6; - data.values[0] = gyro_data.values[0]; - data.values[1] = gyro_data.values[1]; - data.values[2] = gyro_data.values[2]; - data.values[3] = fusion_data.values[0]; - data.values[4] = fusion_data.values[1]; - data.values[5] = fusion_data.values[2]; - - return 0; -} - -bool gyroscope_uncal_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - properties.resolution = 0.000001; - properties.vendor = m_vendor; - properties.name = SENSOR_NAME; - properties.min_interval = 1; - properties.fifo_count = 0; - properties.max_batch_count = 0; - - return true; -} diff --git a/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.h b/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.h deleted file mode 100755 index 0edbde4..0000000 --- a/src/server/plugins/gyroscope_uncal/gyroscope_uncal_sensor.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 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 _GYROSCOPE_UNCAL_SENSOR_H_ -#define _GYROSCOPE_UNCAL_SENSOR_H_ - -#include -#include -#include - -class gyroscope_uncal_sensor : public virtual_sensor { -public: - gyroscope_uncal_sensor(); - virtual ~gyroscope_uncal_sensor(); - - bool init(void); - - void synthesize(const sensor_event_t &event, vector &outs); - - bool add_interval(int client_id, unsigned int interval); - bool delete_interval(int client_id); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - virtual void get_types(std::vector &types); - - int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - -private: - sensor_base *m_accel_sensor; - sensor_base *m_magnetic_sensor; - sensor_base *m_gyro_sensor; - sensor_base *m_fusion_sensor; - - sensor_data m_fusion; - sensor_data m_gyro; - - cmutex m_value_mutex; - - unsigned int m_enable_gyroscope_uncal; - - unsigned long long m_time; - unsigned int m_interval; - - std::string m_vendor; - std::string m_raw_data_unit; - int m_default_sampling_time; - float m_gyro_static_bias[3]; - int m_gyro_rotation_direction_compensation[3]; - float m_gyro_scale; - - bool on_start(void); - bool on_stop(void); -}; - -#endif /*_GYROSCOPE_UNCAL_SENSOR_H_*/ diff --git a/src/server/plugins/light/light_sensor.cpp b/src/server/plugins/light/light_sensor.cpp deleted file mode 100755 index b9e0dd0..0000000 --- a/src/server/plugins/light/light_sensor.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include -#include -#include -#include -#include - -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define SENSOR_NAME "LIGHT_SENSOR" - -#define INITIAL_VALUE -1 -const int light_sensor::m_light_level[] = {0, 1, 165, 288, 497, 869, 1532, 2692, 4692, 8280, 21428, 65535, 137852}; - -light_sensor::light_sensor() -: m_sensor_hal(NULL) -, m_level(INITIAL_VALUE) -{ - m_name = string(SENSOR_NAME); - - vector supported_events = { - LIGHT_CHANGE_LEVEL_EVENT, - LIGHT_LEVEL_DATA_EVENT, - LIGHT_LUX_DATA_EVENT, - }; - - for_each(supported_events.begin(), supported_events.end(), - bind1st(mem_fun(&sensor_base::register_supported_event), this)); - - physical_sensor::set_poller(light_sensor::working, this); -} - -light_sensor::~light_sensor() -{ - INFO("light_sensor is destroyed!"); -} - -bool light_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_LIGHT); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - INFO("%s is created!", sensor_base::get_name()); - - return true; -} - -void light_sensor::get_types(vector &types) -{ - types.push_back(LIGHT_SENSOR); -} - -bool light_sensor::working(void *inst) -{ - light_sensor *sensor = (light_sensor *)inst; - return sensor->process_event(); -} - -bool light_sensor::process_event(void) -{ - sensor_event_t event; - int level; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - level = (int) adc_to_light_level((int)event.data.values[0]); - - AUTOLOCK(m_client_info_mutex); - - event.sensor_id = get_id(); - if (get_client_cnt(LIGHT_LUX_DATA_EVENT)) { - event.event_type = LIGHT_LUX_DATA_EVENT; - push(event); - } - - if (get_client_cnt(LIGHT_LEVEL_DATA_EVENT)) { - event.event_type = LIGHT_LEVEL_DATA_EVENT; - raw_to_level(event.data); - push(event); - } - - if (m_level != level) { - m_level = level; - - if (get_client_cnt(LIGHT_CHANGE_LEVEL_EVENT)) { - event.event_type = LIGHT_CHANGE_LEVEL_EVENT; - raw_to_level(event.data); - push(event); - } - } - - return true; -} - -int light_sensor::adc_to_light_level(int adc) -{ - int level_cnt = sizeof(m_light_level) / sizeof(m_light_level[0]) - 1; - - for (int i = 0; i < level_cnt; ++i) { - if (adc >= m_light_level[i] && adc < m_light_level[i + 1]) - return i; - } - - return -1; -} - -bool light_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail"); - return false; - } - - return start_poll(); -} - -bool light_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail"); - return false; - } - - return stop_poll(); -} - -bool light_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - m_sensor_hal->get_properties(properties); - return true; -} - -int light_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int ret; - ret = m_sensor_hal->get_sensor_data(data); - - if (ret < 0) - return -1; - - if (type == LIGHT_LUX_DATA_EVENT) - return 0; - - if (type == LIGHT_LEVEL_DATA_EVENT) { - raw_to_level(data); - return 0; - } - - return -1; -} - -bool light_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void light_sensor::raw_to_level(sensor_data_t &data) -{ - data.values[0] = (int) adc_to_light_level((int)data.values[0]); - data.value_count = 1; -} diff --git a/src/server/plugins/light/light_sensor.h b/src/server/plugins/light/light_sensor.h deleted file mode 100755 index 1b6d0ca..0000000 --- a/src/server/plugins/light/light_sensor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _LIGHT_SENSOR_H_ -#define _LIGHT_SENSOR_H_ - -#include -#include -#include - -class light_sensor : public physical_sensor { -public: - light_sensor(); - virtual ~light_sensor(); - - virtual bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - virtual bool set_interval(unsigned long interval); - int get_sensor_data(const unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); -private: - static const int m_light_level[]; - - sensor_hal *m_sensor_hal; - int m_level; - - virtual bool on_start(void); - virtual bool on_stop(void); - - bool process_event(void); - int adc_to_light_level(int adc); - - void raw_to_level(sensor_data_t &data); - void raw_to_state(sensor_data_t &data); -}; -#endif /*_LIGHT_SENSOR_H_*/ diff --git a/src/server/plugins/pressure/pressure_sensor.cpp b/src/server/plugins/pressure/pressure_sensor.cpp deleted file mode 100755 index 533bb71..0000000 --- a/src/server/plugins/pressure/pressure_sensor.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include -#include -#include - -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define SENSOR_NAME "PRESSURE_SENSOR" -#define SENSOR_TYPE_PRESSURE "PRESSURE" -#define ELEMENT_NAME "NAME" -#define ELEMENT_VENDOR "VENDOR" -#define ATTR_VALUE "value" - -pressure_sensor::pressure_sensor() -: m_sensor_hal(NULL) -, m_pressure(0.0f) -, m_resolution(0.0f) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(PRESSURE_RAW_DATA_EVENT); - - physical_sensor::set_poller(pressure_sensor::working, this); -} - -pressure_sensor::~pressure_sensor() -{ - INFO("pressure_sensor is destroyed!"); -} - -bool pressure_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PRESSURE); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (!m_sensor_hal->get_properties(properties)) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - m_resolution = properties.resolution; - - string model_id = m_sensor_hal->get_model_id(); - - INFO("%s is created!", sensor_base::get_name()); - - return true; -} - -void pressure_sensor::get_types(vector &types) -{ - types.push_back(PRESSURE_SENSOR); -} - -bool pressure_sensor::working(void *inst) -{ - pressure_sensor *sensor = (pressure_sensor*)inst; - return sensor->process_event(); -} - -bool pressure_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(PRESSURE_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = PRESSURE_RAW_DATA_EVENT; - push(event); - } - - return true; -} - -bool pressure_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool pressure_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool pressure_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int pressure_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - return m_sensor_hal->get_sensor_data(data); -} - -bool pressure_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} diff --git a/src/server/plugins/pressure/pressure_sensor.h b/src/server/plugins/pressure/pressure_sensor.h deleted file mode 100755 index 9b7420f..0000000 --- a/src/server/plugins/pressure/pressure_sensor.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _PRESSURE_SENSOR_H_ -#define _PRESSURE_SENSOR_H_ - -#include - -#include -#include - -class pressure_sensor : public physical_sensor { -public: - pressure_sensor(); - virtual ~pressure_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - bool set_interval(unsigned long interval); - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - -private: - sensor_hal *m_sensor_hal; - float m_pressure; - float m_resolution; - - virtual bool on_start(void); - virtual bool on_stop(void); - bool process_event(void); - -}; - -#endif diff --git a/src/server/plugins/proxi/proxi_sensor.cpp b/src/server/plugins/proxi/proxi_sensor.cpp deleted file mode 100755 index edf82a2..0000000 --- a/src/server/plugins/proxi/proxi_sensor.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include -#include -#include - -using std::string; -using std::vector; - -#define SENSOR_NAME "PROXI_SENSOR" - -proxi_sensor::proxi_sensor() -: m_sensor_hal(NULL) -, m_state(PROXIMITY_STATE_FAR) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(PROXIMITY_CHANGE_STATE_EVENT); - register_supported_event(PROXIMITY_STATE_EVENT); - register_supported_event(PROXIMITY_DISTANCE_DATA_EVENT); - - physical_sensor::set_poller(proxi_sensor::working, this); -} - -proxi_sensor::~proxi_sensor() -{ - INFO("proxi_sensor is destroyed!\n"); -} - -bool proxi_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PROXIMITY); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - INFO("%s is created!\n", sensor_base::get_name()); - return true; -} - -void proxi_sensor::get_types(vector &types) -{ - types.push_back(PROXIMITY_SENSOR); -} - -bool proxi_sensor::working(void *inst) -{ - proxi_sensor *sensor = (proxi_sensor*)inst; - return sensor->process_event(); -} - -bool proxi_sensor::process_event(void) -{ - sensor_event_t event; - int state; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - AUTOLOCK(m_mutex); - - if (event.data.values[0] == PROXIMITY_NODE_STATE_FAR) { - INFO("PROXIMITY_STATE_FAR state occured\n"); - event.data.values[0] = PROXIMITY_STATE_FAR; - } else if (event.data.values[0] == PROXIMITY_NODE_STATE_NEAR) { - INFO("PROXIMITY_STATE_NEAR state occured\n"); - event.data.values[0] = PROXIMITY_STATE_NEAR; - } else { - ERR("PROXIMITY_STATE Unknown: %d\n",event.data.values[0]); - return false; - } - - event.sensor_id = get_id(); - if (get_client_cnt(PROXIMITY_DISTANCE_DATA_EVENT)) { - event.event_type = PROXIMITY_DISTANCE_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - state = event.data.values[0]; - - if (m_state != state) { - AUTOLOCK(m_value_mutex); - m_state = state; - - if (get_client_cnt(PROXIMITY_CHANGE_STATE_EVENT)) { - event.event_type = PROXIMITY_CHANGE_STATE_EVENT; - raw_to_base(event.data); - push(event); - } - } - - return true; -} - -bool proxi_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool proxi_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool proxi_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - m_sensor_hal->get_properties(properties); - - properties.min_range = properties.min_range * 5; - properties.max_range = properties.max_range * 5; - - return true; -} - -int proxi_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int state; - - if ((type != PROXIMITY_CHANGE_STATE_EVENT) && (type != PROXIMITY_STATE_EVENT)) - return -1; - - state = m_sensor_hal->get_sensor_data(data); - - if (state < 0) { - ERR("m_sensor_hal get struct_data fail\n"); - return -1; - } - - raw_to_base(data); - - return 0; -} - -void proxi_sensor::raw_to_base(sensor_data_t &data) -{ - data.values[0] = (float)(data.values[0] * 5); - data.value_count = 1; -} - diff --git a/src/server/plugins/proxi/proxi_sensor.h b/src/server/plugins/proxi/proxi_sensor.h deleted file mode 100755 index 97e5dba..0000000 --- a/src/server/plugins/proxi/proxi_sensor.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _PROXI_SENSOR_H_ -#define _PROXI_SENSOR_H_ - -#include -#include -#include - -class proxi_sensor : public physical_sensor { -public: - enum proxi_node_state_event_t { //changed as per Input Event Method definitions - PROXIMITY_NODE_STATE_NEAR = 0, - PROXIMITY_NODE_STATE_FAR = 1, - PROXIMITY_NODE_STATE_UNKNOWN = -1, - }; - -// In case of IIO input method, use the following definitions as the values returned by sensor are different. -// enum proxi_node_state_event_t { //changed as per IIO Method definitions -// PROXIMITY_NODE_STATE_NEAR = 1, -// PROXIMITY_NODE_STATE_FAR = 2, -// PROXIMITY_NODE_STATE_UNKNOWN = 0, -// }; - - proxi_sensor(); - virtual ~proxi_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); -private: - sensor_hal *m_sensor_hal; - - int m_state; - - cmutex m_value_mutex; - - - virtual bool on_start(void); - virtual bool on_stop(void); - - void raw_to_base(sensor_data_t &data); - void raw_to_state(sensor_data_t &data); - bool process_event(void); -}; - -#endif // _PROXI_SENSOR_H_ diff --git a/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp b/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp deleted file mode 100755 index e816baf..0000000 --- a/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include -#include -#include -#include - -using std::string; -using std::vector; - -#define SENSOR_NAME "RV_RAW_SENSOR" - -rv_raw_sensor::rv_raw_sensor() -: m_sensor_hal(NULL) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(RV_RAW_RAW_DATA_EVENT); - - physical_sensor::set_poller(rv_raw_sensor::working, this); -} - -rv_raw_sensor::~rv_raw_sensor() -{ - INFO("rv_raw_sensor is destroyed!\n"); -} - -bool rv_raw_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_RV_RAW); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (!m_sensor_hal->get_properties(properties)) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - set_privilege(SENSOR_PRIVILEGE_INTERNAL); - - INFO("%s is created!\n", sensor_base::get_name()); - - return true; -} - -void rv_raw_sensor::get_types(vector &types) -{ - types.push_back(RV_RAW_SENSOR); -} - -bool rv_raw_sensor::working(void *inst) -{ - rv_raw_sensor *sensor = (rv_raw_sensor*)inst; - return sensor->process_event();; -} - -bool rv_raw_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - AUTOLOCK(m_mutex); - - if (get_client_cnt(RV_RAW_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = RV_RAW_RAW_DATA_EVENT; - push(event); - } - - return true; -} - -bool rv_raw_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool rv_raw_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool rv_raw_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int rv_raw_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int state; - - if (type != RV_RAW_RAW_DATA_EVENT) - return -1; - - state = m_sensor_hal->get_sensor_data(data); - - if (state < 0) { - ERR("m_sensor_hal get struct_data fail\n"); - return -1; - } - - return 0; -} - -bool rv_raw_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} diff --git a/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.h b/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.h deleted file mode 100755 index f55d0a1..0000000 --- a/src/server/plugins/rotation_vector/rv_raw/rv_raw_sensor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _RV_RAW_SENSOR_H_ -#define _RV_RAW_SENSOR_H_ - -#include - -#include -#include - -class rv_raw_sensor : public physical_sensor { -public: - rv_raw_sensor(); - virtual ~rv_raw_sensor(); - - virtual bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - virtual bool set_interval(unsigned long interval); - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); -private: - sensor_hal *m_sensor_hal; - - virtual bool on_start(void); - virtual bool on_stop(void); - - bool process_event(void); -}; - -#endif /*_RV_RAW_SENSOR_H_*/ diff --git a/src/server/plugins/temperature/temperature_sensor.cpp b/src/server/plugins/temperature/temperature_sensor.cpp deleted file mode 100755 index 5b18a5b..0000000 --- a/src/server/plugins/temperature/temperature_sensor.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include -#include -#include - -using std::string; -using std::vector; - -#define SENSOR_NAME "TEMPERATURE_SENSOR" - -temperature_sensor::temperature_sensor() -: m_sensor_hal(NULL) -, m_temperature(0.0f) -, m_resolution(0.0f) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(TEMPERATURE_RAW_DATA_EVENT); - - physical_sensor::set_poller(temperature_sensor::working, this); -} - -temperature_sensor::~temperature_sensor() -{ - INFO("temperature_sensor is destroyed!"); -} - -bool temperature_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_TEMPERATURE); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (!m_sensor_hal->get_properties(properties)) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - m_resolution = properties.resolution; - - INFO("%s is created!", sensor_base::get_name()); - - return true; -} - -void temperature_sensor::get_types(vector &types) -{ - types.push_back(TEMPERATURE_SENSOR); -} - -bool temperature_sensor::working(void *inst) -{ - temperature_sensor *sensor = (temperature_sensor*)inst; - return sensor->process_event(); -} - -bool temperature_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(TEMPERATURE_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = TEMPERATURE_RAW_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - return true; -} - -bool temperature_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool temperature_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool temperature_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int temperature_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int ret; - - ret = m_sensor_hal->get_sensor_data(data); - - if (ret < 0) - return -1; - - if (type == TEMPERATURE_RAW_DATA_EVENT) { - raw_to_base(data); - return 0; - } - - return -1; -} - -bool temperature_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void temperature_sensor::raw_to_base(sensor_data_t &data) -{ - data.values[0] = data.values[0] * m_resolution; - data.value_count = 1; -} diff --git a/src/server/plugins/temperature/temperature_sensor.h b/src/server/plugins/temperature/temperature_sensor.h deleted file mode 100755 index 680862d..0000000 --- a/src/server/plugins/temperature/temperature_sensor.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _TEMPERATURE_SENSOR_H_ -#define _TEMPERATURE_SENSOR_H_ - -#include - -#include -#include - -class temperature_sensor : public physical_sensor { -public: - temperature_sensor(); - virtual ~temperature_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - - bool set_interval(unsigned long interval); - int get_sensor_data(unsigned int type, sensor_data_t &data); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - -private: - sensor_hal *m_sensor_hal; - float m_temperature; - float m_resolution; - - virtual bool on_start(void); - virtual bool on_stop(void); - bool process_event(void); - void raw_to_base(sensor_data_t &data); -}; - -#endif diff --git a/src/server/plugins/ultraviolet/ultraviolet_sensor.cpp b/src/server/plugins/ultraviolet/ultraviolet_sensor.cpp deleted file mode 100755 index 360eb95..0000000 --- a/src/server/plugins/ultraviolet/ultraviolet_sensor.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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. - * - */ - -#include -#include - -#include -#include -#include - -using std::bind1st; -using std::mem_fun; -using std::string; -using std::vector; - -#define SENSOR_NAME "ULTRAVIOLET_SENSOR" - -ultraviolet_sensor::ultraviolet_sensor() -: m_sensor_hal(NULL) -{ - m_name = string(SENSOR_NAME); - - register_supported_event(ULTRAVIOLET_RAW_DATA_EVENT); - - physical_sensor::set_poller(ultraviolet_sensor::working, this); -} - -ultraviolet_sensor::~ultraviolet_sensor() -{ - INFO("ultraviolet_sensor is destroyed!"); -} - -bool ultraviolet_sensor::init() -{ - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ULTRAVIOLET); - - if (!m_sensor_hal) { - ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); - return false; - } - - sensor_properties_s properties; - - if (m_sensor_hal->get_properties(properties) == false) { - ERR("sensor->get_properties() is failed!\n"); - return false; - } - - INFO("%s is created!", sensor_base::get_name()); - - return true; -} - -void ultraviolet_sensor::get_types(vector &types) -{ - types.push_back(ULTRAVIOLET_SENSOR); -} - -bool ultraviolet_sensor::working(void *inst) -{ - ultraviolet_sensor *sensor = (ultraviolet_sensor*)inst; - return sensor->process_event(); -} - -bool ultraviolet_sensor::process_event(void) -{ - sensor_event_t event; - - if (!m_sensor_hal->is_data_ready()) - return true; - - m_sensor_hal->get_sensor_data(event.data); - - - AUTOLOCK(m_client_info_mutex); - - if (get_client_cnt(ULTRAVIOLET_RAW_DATA_EVENT)) { - event.sensor_id = get_id(); - event.event_type = ULTRAVIOLET_RAW_DATA_EVENT; - raw_to_base(event.data); - push(event); - } - - return true; -} - -bool ultraviolet_sensor::on_start(void) -{ - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail\n"); - return false; - } - - return start_poll(); -} - -bool ultraviolet_sensor::on_stop(void) -{ - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail\n"); - return false; - } - - return stop_poll(); -} - -bool ultraviolet_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - return m_sensor_hal->get_properties(properties); -} - -int ultraviolet_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) -{ - int ret; - - ret = m_sensor_hal->get_sensor_data(data); - - if (ret < 0) - return -1; - - if (type == ULTRAVIOLET_RAW_DATA_EVENT) { - raw_to_base(data); - return 0; - } - - return -1; -} - -bool ultraviolet_sensor::set_interval(unsigned long interval) -{ - AUTOLOCK(m_mutex); - - INFO("Polling interval is set to %dms", interval); - - return m_sensor_hal->set_interval(interval); -} - -void ultraviolet_sensor::raw_to_base(sensor_data_t &data) -{ - -} diff --git a/src/server/plugins/ultraviolet/ultraviolet_sensor.h b/src/server/plugins/ultraviolet/ultraviolet_sensor.h deleted file mode 100755 index 3473db5..0000000 --- a/src/server/plugins/ultraviolet/ultraviolet_sensor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 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 _ULTRAVIOLET_SENSOR_H_ -#define _ULTRAVIOLET_SENSOR_H_ - -#include - -#include -#include - -class ultraviolet_sensor : public physical_sensor { -public: - ultraviolet_sensor(); - virtual ~ultraviolet_sensor(); - - bool init(); - virtual void get_types(std::vector &types); - - static bool working(void *inst); - virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - virtual int get_sensor_data(unsigned int type, sensor_data_t &data); -private: - sensor_hal *m_sensor_hal; - - virtual bool on_start(void); - virtual bool on_stop(void); - bool process_event(void); - void raw_to_base(sensor_data_t &data); -}; - -#endif - -- 2.7.4 From 5f3c5d3a3225ba31940f95224e459e947769061b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 14:22:13 +0900 Subject: [PATCH 14/16] sensord: disable auto_rotation sensor for refactoring sensor fw Change-Id: Ib4b92dc82b6fcec276b2fba17dc9666c72aa7cba Signed-off-by: kibak.yoon --- src/server/sensor_plugin_loader.cpp.in | 140 +-------------------------------- 1 file changed, 2 insertions(+), 138 deletions(-) diff --git a/src/server/sensor_plugin_loader.cpp.in b/src/server/sensor_plugin_loader.cpp.in index d370c14..86b45c1 100644 --- a/src/server/sensor_plugin_loader.cpp.in +++ b/src/server/sensor_plugin_loader.cpp.in @@ -28,17 +28,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +/* #ifdef ENABLE_AUTO_ROTATION #include #endif @@ -69,7 +59,7 @@ #ifdef ENABLE_GYROSCOPE_UNCAL #include #endif - +*/ using std::make_pair; using std::equal; @@ -236,47 +226,6 @@ bool sensor_plugin_loader::load_plugins(void) ); - sensor_hal *accel_hal = get_sensor_hal(SENSOR_HAL_TYPE_ACCELEROMETER); - if (accel_hal != NULL) { - enable_virtual_sensor |= ACCELEROMETER_ENABLED; - - accel_sensor* accel_sensor_ptr = NULL; - try { - accel_sensor_ptr = new(std::nothrow) accel_sensor; - } catch (int err) { - ERR("Failed to create accel_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (accel_sensor_ptr != NULL) - sensors.push_back(accel_sensor_ptr); - } - - sensor_hal *gyro_hal = get_sensor_hal(SENSOR_HAL_TYPE_GYROSCOPE); - if (gyro_hal != NULL) { - enable_virtual_sensor |= GYROSCOPE_ENABLED; - - gyro_sensor* gyro_sensor_ptr = NULL; - try { - gyro_sensor_ptr = new(std::nothrow) gyro_sensor; - } catch (int err) { - ERR("Failed to create gyro_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (gyro_sensor_ptr != NULL) - sensors.push_back(gyro_sensor_ptr); - } - - sensor_hal *geo_hal = get_sensor_hal(SENSOR_HAL_TYPE_GEOMAGNETIC); - if (geo_hal != NULL) { - enable_virtual_sensor |= GEOMAGNETIC_ENABLED; - - geo_sensor* geo_sensor_ptr = NULL; - try { - geo_sensor_ptr = new(std::nothrow) geo_sensor; - } catch (int err) { - ERR("Failed to create geo_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (geo_sensor_ptr != NULL) - sensors.push_back(geo_sensor_ptr); - } #ifdef ENABLE_SENSOR_FUSION fusion_sensor* fusion_sensor_ptr = NULL; try { @@ -393,90 +342,6 @@ bool sensor_plugin_loader::load_plugins(void) sensors.push_back(geomagnetic_rv_sensor_ptr); } #endif - sensor_hal *light_hal = get_sensor_hal(SENSOR_HAL_TYPE_LIGHT); - if (light_hal != NULL) { - light_sensor* light_sensor_ptr = NULL; - try { - light_sensor_ptr = new(std::nothrow) light_sensor; - } catch (int err) { - ERR("Failed to create light_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (light_sensor_ptr != NULL) - sensors.push_back(light_sensor_ptr); - } - - sensor_hal *proxi_hal = get_sensor_hal(SENSOR_HAL_TYPE_PROXIMITY); - if (proxi_hal != NULL) { - proxi_sensor* proxi_sensor_ptr = NULL; - try { - proxi_sensor_ptr = new(std::nothrow) proxi_sensor; - } catch (int err) { - ERR("Failed to create proxi_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (proxi_sensor_ptr != NULL) - sensors.push_back(proxi_sensor_ptr); - } - - sensor_hal *pressure_hal = get_sensor_hal(SENSOR_HAL_TYPE_PRESSURE); - if (pressure_hal != NULL) { - pressure_sensor* pressure_sensor_ptr = NULL; - try { - pressure_sensor_ptr = new(std::nothrow) pressure_sensor; - } catch (int err) { - ERR("Failed to create pressure_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (pressure_sensor_ptr != NULL) - sensors.push_back(pressure_sensor_ptr); - } - - sensor_hal *temp_hal = get_sensor_hal(SENSOR_HAL_TYPE_TEMPERATURE); - if (temp_hal != NULL) { - temperature_sensor* temp_sensor_ptr = NULL; - try { - temp_sensor_ptr = new(std::nothrow) temperature_sensor; - } catch (int err) { - ERR("Failed to create temperature_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (temp_sensor_ptr != NULL) - sensors.push_back(temp_sensor_ptr); - } - - sensor_hal *ultra_hal = get_sensor_hal(SENSOR_HAL_TYPE_ULTRAVIOLET); - if (ultra_hal != NULL) { - ultraviolet_sensor* ultra_sensor_ptr = NULL; - try { - ultra_sensor_ptr = new(std::nothrow) ultraviolet_sensor; - } catch (int err) { - ERR("Failed to create ultraviolet_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (ultra_sensor_ptr != NULL) - sensors.push_back(ultra_sensor_ptr); - } - - sensor_hal *bio_led_red_hal = get_sensor_hal(SENSOR_HAL_TYPE_BIO_LED_RED); - if (bio_led_red_hal != NULL) { - bio_led_red_sensor* bio_led_red_sensor_ptr = NULL; - try { - bio_led_red_sensor_ptr = new(std::nothrow) bio_led_red_sensor; - } catch (int err) { - ERR("Failed to create bio_led_red_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (bio_led_red_sensor_ptr != NULL) - sensors.push_back(bio_led_red_sensor_ptr); - } - - sensor_hal *rv_raw_hal = get_sensor_hal(SENSOR_HAL_TYPE_RV_RAW); - if (rv_raw_hal != NULL) { - rv_raw_sensor* rv_raw_sensor_ptr = NULL; - try { - rv_raw_sensor_ptr = new(std::nothrow) rv_raw_sensor; - } catch (int err) { - ERR("Failed to create rv_raw_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (rv_raw_sensor_ptr != NULL) - sensors.push_back(rv_raw_sensor_ptr); - } - shared_ptr sensor; for (unsigned int i = 0; i < sensors.size(); ++i) { @@ -629,4 +494,3 @@ vector sensor_plugin_loader::get_virtual_sensors(void) return virtual_list; } - -- 2.7.4 From a95bf7e0924df18a72b48bc8add71474dab8f218 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 14:50:44 +0900 Subject: [PATCH 15/16] sensord: move poller to share library for using it commonly Change-Id: I7d04ffc339a787c64feba08b5d1e66143fd66103 Signed-off-by: kibak.yoon --- src/client/CMakeLists.txt | 2 -- src/client/csensor_event_listener.cpp | 6 +++--- src/client/csensor_event_listener.h | 3 ++- src/shared/CMakeLists.txt | 2 ++ src/{client => shared}/poller.cpp | 40 +++++++++++++++++------------------ src/{client => shared}/poller.h | 13 +++++------- 6 files changed, 32 insertions(+), 34 deletions(-) rename src/{client => shared}/poller.cpp (85%) rename src/{client => shared}/poller.h (83%) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index e949a05..7653492 100755 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -34,7 +34,6 @@ add_library(${PROJECT_NAME} SHARED csensor_handle_info.cpp client_common.cpp command_channel.cpp - poller.cpp ) target_link_libraries(${PROJECT_NAME} ${lib_pkgs_LDFLAGS} "sensord-shared") @@ -43,7 +42,6 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) -install(FILES poller.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) install(FILES creg_event_info.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) install(FILES csensor_event_listener.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) install(FILES sensor_info_manager.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) diff --git a/src/client/csensor_event_listener.cpp b/src/client/csensor_event_listener.cpp index 17a1dbb..6595309 100644 --- a/src/client/csensor_event_listener.cpp +++ b/src/client/csensor_event_listener.cpp @@ -391,7 +391,7 @@ gboolean csensor_event_listener::callback_dispatcher(gpointer data) -bool csensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, int &event) +ssize_t csensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event) { ssize_t len; @@ -420,7 +420,7 @@ bool csensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, int void csensor_event_listener::listen_events(void) { - int event; + struct epoll_event event; ssize_t len = -1; do { @@ -468,7 +468,7 @@ void csensor_event_listener::listen_events(void) INFO("Event listener thread is terminated."); - if (m_client_info.has_client_id() && (event & EPOLLHUP)) { + if (m_client_info.has_client_id() && (event.events & EPOLLHUP)) { if (m_hup_observer) m_hup_observer(); } diff --git a/src/client/csensor_event_listener.h b/src/client/csensor_event_listener.h index 21f28cf..72dc7e7 100644 --- a/src/client/csensor_event_listener.h +++ b/src/client/csensor_event_listener.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -104,7 +105,7 @@ private: bool create_event_channel(void); void close_event_channel(void); - bool sensor_event_poll(void* buffer, int buffer_len, int &event); + ssize_t sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event); void listen_events(void); client_callback_info* handle_calibration_cb(csensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy); diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index cc46347..b648b2b 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -24,6 +24,7 @@ add_library(${PROJECT_NAME} SHARED csocket.cpp sensor_logs.cpp sensor_info.cpp + poller.cpp ) target_link_libraries(${PROJECT_NAME} ${shared_pkgs_LDFLAGS} "-lrt -ldl -pthread") @@ -35,6 +36,7 @@ install(FILES csocket.h cbase_lock.h sensor_info.h + poller.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ) diff --git a/src/client/poller.cpp b/src/shared/poller.cpp similarity index 85% rename from src/client/poller.cpp rename to src/shared/poller.cpp index e174caf..d2861ad 100755 --- a/src/client/poller.cpp +++ b/src/shared/poller.cpp @@ -20,16 +20,27 @@ #include #include +#define EPOLL_MAX 32 + +poller::poller() +{ + m_epfd = epoll_create(EPOLL_MAX); +} + poller::poller(int fd) -: m_epfd(-1) +: poller() { - create(fd); + add_fd(fd); } -bool poller::create(int fd) +poller::~poller() { - m_epfd = epoll_create(1); + if (m_epfd) + close(m_epfd); +} +bool poller::add_fd(int fd) +{ struct epoll_event event; event.data.fd = fd; @@ -43,7 +54,6 @@ bool poller::create(int fd) return true; } - bool poller::fill_event_queue(void) { const int EPOLL_MAX_EVENT = 1; @@ -52,9 +62,8 @@ bool poller::fill_event_queue(void) int nr_events = epoll_wait(m_epfd, event_items, EPOLL_MAX_EVENT, -1); if (nr_events < 0) { - if (errno == EINTR) { + if (errno == EINTR) return true; - } ERR("Epoll failed errrno : %d , errstr : %s", errno, strerror(errno)); return false; @@ -66,16 +75,14 @@ bool poller::fill_event_queue(void) } for (int i = 0; i < nr_events; i++) - m_event_queue.push(event_items[i].events); + m_event_queue.push(event_items[i]); return true; } -bool poller::poll(int &event) +bool poller::poll(struct epoll_event &event) { - event = 0; - while (true) { if (m_event_queue.empty()) { if (!fill_event_queue()) @@ -86,12 +93,12 @@ bool poller::poll(int &event) event = m_event_queue.front(); m_event_queue.pop(); - if (event & EPOLLERR) { + if (event.events & EPOLLERR) { ERR("Poll error!"); return false; } - if (event & EPOLLHUP) { + if (event.events & EPOLLHUP) { INFO("Poll: Connetion is closed from the other side"); return false; } @@ -100,10 +107,3 @@ bool poller::poll(int &event) } } } - -poller::~poller() -{ - if (m_epfd) - close(m_epfd); -} - diff --git a/src/client/poller.h b/src/shared/poller.h similarity index 83% rename from src/client/poller.h rename to src/shared/poller.h index eaf7d93..8e91b0d 100755 --- a/src/client/poller.h +++ b/src/shared/poller.h @@ -20,26 +20,23 @@ #ifndef _POLLER_H_ #define _POLLER_H_ -#include #include #include -#include #include -#include -#include #include class poller { public: + poller(); poller(int fd); - ~poller(); + virtual ~poller(); - bool poll(int &event); + bool add_fd(int fd); + bool poll(struct epoll_event &event); private: int m_epfd; - std::queue m_event_queue; + std::queue m_event_queue; - bool create(int fd); bool fill_event_queue(void); }; -- 2.7.4 From 3735c6778c2eebc6f0a251591aa61d3184bc86a4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 21 Jan 2016 14:58:55 +0900 Subject: [PATCH 16/16] sensord: modify HAL interface for support sensorhub * It doesn't need to support multi event types anymore, because a sensor has a only 1 event_type in new architecture. - removed interface of multi event types. - concept of "event type" is not removed completely still because of internal API. it will be removed later. * HAL interface supports multi sensor using get_sensor_list() API. * memory of sensor_event must be allocated in HAL. sensor fw will free this allocated memory. * refactoring and cleaning the code will be continue. * sensors will work when that sensor_event_poller patch is applied. Change-Id: I5c4282d9600a8b05f3b495d764dd28cf56ca356d Signed-off-by: kibak.yoon --- src/client/client.cpp | 11 +- src/server/command_worker.cpp | 45 +--- src/server/csensor_event_queue.cpp | 4 + src/server/csensor_event_queue.h | 19 +- src/server/physical_sensor.cpp | 123 +++++++++-- src/server/physical_sensor.h | 39 ++-- src/server/sensor_base.cpp | 364 ++++++++++++++++----------------- src/server/sensor_base.h | 108 +++++----- src/server/sensor_hal.h | 65 ------ src/server/sensor_plugin_loader.cpp.in | 321 +++++++---------------------- src/server/sensor_plugin_loader.h | 35 +--- src/server/virtual_sensor.cpp | 7 - src/server/virtual_sensor.h | 16 +- src/shared/sensor_hal.h | 128 +++++++++--- src/shared/sensor_info.cpp | 71 +++---- src/shared/sensor_info.h | 11 +- 16 files changed, 595 insertions(+), 772 deletions(-) delete mode 100644 src/server/sensor_hal.h diff --git a/src/client/client.cpp b/src/client/client.cpp index 035d907..dafe4db 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -579,14 +579,13 @@ API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count, false, "Invalid param: sensor (%p), event_types(%p), count(%)", sensor, event_types, count); - vector event_vec; - - info->get_supported_events(event_vec); - *event_types = (unsigned int *) malloc(sizeof(unsigned int) * event_vec.size()); + unsigned int event_type; + event_type = info->get_supported_event(); + *event_types = (unsigned int *) malloc(sizeof(unsigned int)); retvm_if(!*event_types, false, "Failed to allocate memory"); - copy(event_vec.begin(), event_vec.end(), *event_types); - *count = event_vec.size(); + (*event_types)[0] = event_type; + *count = 1; return true; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index dd8cab2..b72d7b6 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -152,20 +152,15 @@ void command_worker::make_sensor_raw_data_map(void) auto it_sensor = sensors.begin(); while (it_sensor != last) { + (*it_sensor)->get_sensor_info(info); + permission = (*it_sensor)->get_permission(); - vector types; - (*it_sensor)->get_types(types); + sensor_raw_data_map::iterator it_sensor_raw_data; + it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t())); - for (unsigned int i = 0; i < types.size(); ++i) { - (*it_sensor)->get_sensor_info(types[i], info); - permission = (*it_sensor)->get_permission(); + info.get_raw_data(it_sensor_raw_data->second); + info.clear(); - sensor_raw_data_map::iterator it_sensor_raw_data; - it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t())); - - info.get_raw_data(it_sensor_raw_data->second); - info.clear(); - } ++it_sensor; } } @@ -213,7 +208,6 @@ bool command_worker::working(void *ctx) bool command_worker::stopped(void *ctx) { string info; - event_type_vector event_vec; command_worker *inst = (command_worker *)ctx; inst->get_info(info); @@ -221,18 +215,6 @@ bool command_worker::stopped(void *ctx) if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) { - get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_sensor_id, event_vec); - - auto it_event = event_vec.begin(); - - while (it_event != event_vec.end()) { - WARN("Does not unregister event[0x%x] before connection broken for [%s]!!", *it_event, inst->m_module->get_name()); - if (!inst->m_module->delete_client(*it_event)) - ERR("Unregistering event[0x%x] failed", *it_event); - - ++it_event; - } - if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) { WARN("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name()); inst->m_module->delete_interval(inst->m_client_id, false); @@ -556,7 +538,6 @@ bool command_worker::cmd_register_event(void *payload) } insert_priority_list(cmd->event_type); - m_module->add_client(cmd->event_type); ret_value = OP_SUCCESS; DBG("Registering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id); @@ -589,13 +570,6 @@ bool command_worker::cmd_unregister_event(void *payload) goto out; } - if (!m_module->delete_client(cmd->event_type)) { - ERR("Failed to unregister event [0x%x] for client [%d]", - cmd->event_type, m_client_id); - ret_value = OP_ERROR; - goto out; - } - ret_value = OP_SUCCESS; DBG("Unregistering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id); @@ -777,7 +751,6 @@ out: bool command_worker::cmd_get_data(void *payload) { const unsigned int GET_DATA_MIN_INTERVAL = 10; - cmd_get_data_t *cmd; int state = OP_ERROR; bool adjusted = false; @@ -785,8 +758,6 @@ bool command_worker::cmd_get_data(void *payload) DBG("CMD_GET_VALUE Handler invoked\n"); - cmd = (cmd_get_data_t*)payload; - if (!is_permission_allowed()) { ERR("Permission denied to get data for client [%d], for sensor [0x%x]", m_client_id, m_sensor_id); @@ -794,7 +765,7 @@ bool command_worker::cmd_get_data(void *payload) goto out; } - state = m_module->get_sensor_data(cmd->type, data); + state = m_module->get_sensor_data(data); // In case of not getting sensor data, wait short time and retry again // 1. changing interval to be less than 10ms @@ -819,7 +790,7 @@ bool command_worker::cmd_get_data(void *payload) while (!state && !data.timestamp && (retry++ < RETRY_CNT)) { INFO("Wait sensor[0x%x] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME); - state = m_module->get_sensor_data(cmd->type, data); + state = m_module->get_sensor_data(data); } if (adjusted) diff --git a/src/server/csensor_event_queue.cpp b/src/server/csensor_event_queue.cpp index bc907e1..6902e8b 100644 --- a/src/server/csensor_event_queue.cpp +++ b/src/server/csensor_event_queue.cpp @@ -54,3 +54,7 @@ void* csensor_event_queue::pop(int *length) return event.first; } +void csensor_event_queue::push(sensor_event_t *event, int event_length) +{ + push_internal(event, event_length); +} diff --git a/src/server/csensor_event_queue.h b/src/server/csensor_event_queue.h index a72ca4a..4138cac 100644 --- a/src/server/csensor_event_queue.h +++ b/src/server/csensor_event_queue.h @@ -89,24 +89,9 @@ private: void push_internal(void *event, int length); public: static csensor_event_queue& get_instance(); - template void push(const T &event); - template void push(T *event); + + void push(sensor_event_t *event, int event_length); void* pop(int *length); }; -template -void csensor_event_queue::push(const T &event) -{ - void *new_event = malloc(sizeof(event)); - if (!new_event) - return; - memcpy(new_event, &event, sizeof(event)); - push_internal(new_event, sizeof(event)); -} - -template -void csensor_event_queue::push(T *event) -{ - push_internal(event, sizeof(event)); -} #endif diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 15d33a0..b25bc79 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -20,8 +20,10 @@ #include #include +#define UNKNOWN_NAME "UNKNOWN_SENSOR" physical_sensor::physical_sensor() +: m_sensor_hal(NULL) { } @@ -31,44 +33,127 @@ physical_sensor::~physical_sensor() } -bool physical_sensor::push(const sensor_event_t &event) +sensor_type_t physical_sensor::get_type(void) { - csensor_event_queue::get_instance().push(event); - return true; + return static_cast(m_handle.type); } -bool physical_sensor::push(sensor_event_t *event) +unsigned int physical_sensor::get_event_type(void) { - csensor_event_queue::get_instance().push(event); - return true; + return m_handle.event_type; } -bool physical_sensor::push(const sensorhub_event_t &event) +const char* physical_sensor::get_name() { - csensor_event_queue::get_instance().push(event); - return true; + if (m_handle.name.empty()) + return UNKNOWN_NAME; + + return m_handle.name.c_str(); +} + +void physical_sensor::set_sensor_handle(sensor_handle_t handle) +{ + m_handle.id = handle.id; + m_handle.name = handle.name; + m_handle.type = handle.type; + m_handle.event_type = handle.event_type; +} + +void physical_sensor::set_sensor_hal(sensor_hal *hal) +{ + m_sensor_hal = hal; +} + +int physical_sensor::get_poll_fd() +{ + AUTOLOCK(m_mutex); + + if (!m_sensor_hal) + return -1; + + return m_sensor_hal->get_poll_fd(); +} + +bool physical_sensor::on_start() +{ + AUTOLOCK(m_mutex); + + return m_sensor_hal->enable(m_handle.id); +} + +bool physical_sensor::on_stop() +{ + AUTOLOCK(m_mutex); + + return m_sensor_hal->disable(m_handle.id); +} + +long physical_sensor::set_command(unsigned int cmd, long value) +{ + AUTOLOCK(m_mutex); + + return m_sensor_hal->set_command(m_handle.id, std::to_string(cmd), std::to_string(value)); } -bool physical_sensor::push(sensorhub_event_t *event) +bool physical_sensor::set_interval(unsigned long interval) { - csensor_event_queue::get_instance().push(event); - return true; + AUTOLOCK(m_mutex); + + INFO("Polling interval is set to %dms", interval); + + return m_sensor_hal->set_interval(m_handle.id, interval); } -void physical_sensor::set_poller(working_func_t func, void *arg) +bool physical_sensor::set_batch(unsigned long latency) { - m_sensor_data_poller.set_context(arg); - m_sensor_data_poller.set_working(func); + AUTOLOCK(m_mutex); + + INFO("Polling interval is set to %dms", latency); + + return m_sensor_hal->set_batch_latency(m_handle.id, latency); } +bool physical_sensor::set_wakeup(int wakeup) +{ + return false; +} -bool physical_sensor::start_poll(void) +bool physical_sensor::is_data_ready(void) { - return m_sensor_data_poller.start(); + AUTOLOCK(m_mutex); + return m_sensor_hal->is_data_ready(); } -bool physical_sensor::stop_poll(void) +int physical_sensor::get_sensor_data(sensor_data_t &data) { - return m_sensor_data_poller.pause(); + AUTOLOCK(m_mutex); + + if (!m_sensor_hal->get_sensor_data(m_handle.id, data)) { + ERR("Failed to get sensor data"); + return -1; + } + + return 0; } + +int physical_sensor::get_sensor_event(sensor_event_t **event) +{ + AUTOLOCK(m_mutex); + + int event_length = -1; + event_length = m_sensor_hal->get_sensor_event(m_handle.id, event); + + if (event_length < 0) { + ERR("Failed to get sensor event"); + return -1; + } + + return event_length; +} + +bool physical_sensor::get_properties(sensor_properties_s &properties) +{ + return m_sensor_hal->get_properties(m_handle.id, properties); +} + diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index a4098b6..3fb5924 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -27,23 +27,36 @@ class physical_sensor : public sensor_base { public: - typedef worker_thread::trans_func_t working_func_t; - -private: - worker_thread m_sensor_data_poller; - -protected: physical_sensor(); virtual ~physical_sensor(); - bool push(const sensor_event_t &event); - bool push(sensor_event_t *event); - bool push(const sensorhub_event_t &event); - bool push(sensorhub_event_t *event); + /* setting module */ + void set_sensor_handle(sensor_handle_t handle); + void set_sensor_hal(sensor_hal *hal); + + /* module info */ + virtual sensor_type_t get_type(); + virtual unsigned int get_event_type(void); + virtual const char* get_name(void); - void set_poller(working_func_t func, void *arg); - bool start_poll(void); - bool stop_poll(void); + int get_poll_fd(); + + /* get data */ + bool is_data_ready(void); + virtual int get_sensor_data(sensor_data_t &data); + virtual int get_sensor_event(sensor_event_t **event); + +private: + sensor_handle_t m_handle; + sensor_hal *m_sensor_hal; + + virtual bool set_interval(unsigned long interval); + virtual bool set_wakeup(int wakeup); + virtual bool set_batch(unsigned long latency); + virtual bool on_start(); + virtual bool on_stop(); + virtual long set_command(unsigned int cmd, long value); + virtual bool get_properties(sensor_properties_s &properties); }; #endif diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 4a7ce4d..48b81cc 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -17,105 +17,37 @@ * */ +#include #include #include #include +#include +#include + using std::make_pair; using std::vector; -#define UNKNOWN_NAME "UNKNOWN_SENSOR" - sensor_base::sensor_base() -: m_privilege(SENSOR_PRIVILEGE_PUBLIC) +: m_unique_id(-1) +, m_privilege(SENSOR_PRIVILEGE_PUBLIC) , m_permission(SENSOR_PERMISSION_STANDARD) , m_client(0) , m_started(false) { - } sensor_base::~sensor_base() { - + INFO("%s is destroyed!\n", m_handle.name.c_str()); } -bool sensor_base::init() -{ - return true; -} - -bool sensor_base::is_virtual() -{ - return false; -} - -void sensor_base::add_id(sensor_id_t id) -{ - m_ids.insert(std::make_pair(static_cast (id & SENSOR_TYPE_MASK), id)); -} - -sensor_id_t sensor_base::get_id(void) +sensor_type_t sensor_base::get_type(void) { - auto it = m_ids.begin(); - - if (it != m_ids.end()) - return it->second; - - return UNKNOWN_SENSOR; -} - -sensor_id_t sensor_base::get_id(sensor_type_t sensor_type) -{ - - auto it = m_ids.find(sensor_type); - - if (it != m_ids.end()) - return it->second; - return UNKNOWN_SENSOR; } -sensor_privilege_t sensor_base::get_privilege(void) -{ - return m_privilege; -} - -int sensor_base::get_permission(void) -{ - return m_permission; -} - - -void sensor_base::set_privilege(sensor_privilege_t privilege) -{ - m_privilege = privilege; -} - -void sensor_base::set_permission(int permission) -{ - m_permission = permission; -} - -const char* sensor_base::get_name() -{ - if (m_name.empty()) - return UNKNOWN_NAME; - - return m_name.c_str(); -} - -bool sensor_base::on_start() -{ - return true; -} - -bool sensor_base::on_stop() -{ - return true; -} - bool sensor_base::start() { AUTOLOCK(m_mutex); @@ -158,48 +90,19 @@ bool sensor_base::stop(void) return true; } - -bool sensor_base::is_started(void) +bool sensor_base::on_start() { - AUTOLOCK(m_mutex); - AUTOLOCK(m_client_mutex); - - return m_started; + return false; } -bool sensor_base::add_client(unsigned int event_type) +bool sensor_base::on_stop() { - if (!is_supported(event_type)) { - ERR("Invaild event type: 0x%x", event_type); - return false; - } - - AUTOLOCK(m_client_info_mutex); - - ++(m_client_info[event_type]); - return true; + return false; } -bool sensor_base::delete_client(unsigned int event_type) +long sensor_base::set_command(unsigned int cmd, long value) { - if (!is_supported(event_type)) { - ERR("Invaild event type: 0x%x", event_type); - return false; - } - - AUTOLOCK(m_client_info_mutex); - - auto iter = m_client_info.find(event_type); - - if (iter == m_client_info.end()) - return false; - - if (iter->second == 0) - return false; - - --(iter->second); - - return true; + return -1; } bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_processor) @@ -220,6 +123,7 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro " by%sclient[%d] adding interval", get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); + set_interval(cur_min); } @@ -264,6 +168,62 @@ unsigned int sensor_base::get_interval(int client_id, bool is_processor) return m_plugin_info_list.get_interval(client_id, is_processor); } +bool sensor_base::add_batch(int client_id, unsigned int latency) +{ + unsigned int prev_max, cur_max; + + AUTOLOCK(m_plugin_info_list_mutex); + + prev_max = m_plugin_info_list.get_max_batch(); + + if (!m_plugin_info_list.add_batch(client_id, latency)) + return false; + + cur_max = m_plugin_info_list.get_max_batch(); + + if (cur_max != prev_max) { + INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency", + get_id(), prev_max, cur_max, client_id); + set_batch(cur_max); + } + + return true; +} + +bool sensor_base::delete_batch(int client_id) +{ + unsigned int prev_max, cur_max; + AUTOLOCK(m_plugin_info_list_mutex); + + prev_max = m_plugin_info_list.get_max_batch(); + + if (!m_plugin_info_list.delete_batch(client_id)) + return false; + + cur_max = m_plugin_info_list.get_max_batch(); + + if (!cur_max) { + INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms", + get_id(), client_id); + + set_batch(0); + } else if (cur_max != prev_max) { + INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency", + get_id(), prev_max, cur_max, client_id); + + set_batch(cur_max); + } + + return true; +} + +unsigned int sensor_base::get_batch(int client_id) +{ + AUTOLOCK(m_plugin_info_list_mutex); + + return m_plugin_info_list.get_batch(client_id); +} + bool sensor_base::add_wakeup(int client_id, int wakeup) { int prev_wakeup, cur_wakeup; @@ -280,7 +240,7 @@ bool sensor_base::add_wakeup(int client_id, int wakeup) if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) { INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] adding wakeup", get_id(), prev_wakeup, cur_wakeup, client_id); - set_wakeup(client_id, SENSOR_WAKEUP_ON); + set_wakeup(SENSOR_WAKEUP_ON); } return true; @@ -301,7 +261,7 @@ bool sensor_base::delete_wakeup(int client_id) if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) { INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] deleting wakeup", get_id(), prev_wakeup, cur_wakeup, client_id); - set_wakeup(client_id, SENSOR_WAKEUP_OFF); + set_wakeup(SENSOR_WAKEUP_OFF); } return true; @@ -314,71 +274,76 @@ int sensor_base::get_wakeup(int client_id) return m_plugin_info_list.is_wakeup_on(); } -bool sensor_base::add_batch(int client_id, unsigned int latency) +int sensor_base::get_sensor_data(sensor_data_t &data) { - unsigned int prev_max, cur_max; - - AUTOLOCK(m_plugin_info_list_mutex); - - prev_max = m_plugin_info_list.get_max_batch(); - - if (!m_plugin_info_list.add_batch(client_id, latency)) - return false; + return -1; +} - cur_max = m_plugin_info_list.get_max_batch(); +int sensor_base::get_sensor_event(sensor_event_t **event) +{ + return -1; +} - if (cur_max != prev_max) { - INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] adding latency", - get_id(), prev_max, cur_max, client_id); - set_batch(client_id, cur_max); - } +bool sensor_base::get_properties(sensor_properties_s &properties) +{ + return false; +} - return true; +const char* sensor_base::get_name() +{ + return NULL; } -bool sensor_base::delete_batch(int client_id) +void sensor_base::set_id(sensor_id_t id) { - unsigned int prev_max, cur_max; - AUTOLOCK(m_plugin_info_list_mutex); + m_unique_id = id; +} - prev_max = m_plugin_info_list.get_max_batch(); +sensor_id_t sensor_base::get_id(void) +{ + if (m_unique_id == -1) + return UNKNOWN_SENSOR; - if (!m_plugin_info_list.delete_batch(client_id)) - return false; + return m_unique_id; +} - cur_max = m_plugin_info_list.get_max_batch(); +unsigned int sensor_base::get_event_type(void) +{ + return -1; +} - if (!cur_max) { - INFO("No latency for sensor[0x%x] by client[%d] deleting latency, so set to default 0 ms", - get_id(), client_id); +sensor_privilege_t sensor_base::get_privilege(void) +{ + return m_privilege; +} - set_batch(client_id, 0); - } else if (cur_max != prev_max) { - INFO("Max latency for sensor[0x%x] is changed from %dms to %dms by client[%d] deleting latency", - get_id(), prev_max, cur_max, client_id); +int sensor_base::get_permission(void) +{ + return m_permission; +} - set_batch(client_id, cur_max); - } +bool sensor_base::is_started(void) +{ + AUTOLOCK(m_mutex); + AUTOLOCK(m_client_mutex); - return true; + return m_started; } -unsigned int sensor_base::get_batch(int client_id) +bool sensor_base::is_virtual() { - AUTOLOCK(m_plugin_info_list_mutex); - - return m_plugin_info_list.get_batch(client_id); + return false; } -void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info) +void sensor_base::get_sensor_info(sensor_info &info) { sensor_properties_s properties; properties.wakeup_supported = false; - get_properties(sensor_type, properties); + get_properties(properties); - info.set_type(sensor_type); - info.set_id(get_id(sensor_type)); + info.set_type(get_type()); + info.set_id(get_id()); info.set_privilege(m_privilege); info.set_name(properties.name.c_str()); info.set_vendor(properties.vendor.c_str()); @@ -388,53 +353,40 @@ void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info) info.set_min_interval(properties.min_interval); info.set_fifo_count(properties.fifo_count); info.set_max_batch_count(properties.max_batch_count); - - vector events; - - for (unsigned int i = 0; i < m_supported_event_info.size(); ++ i) { - if (m_supported_event_info[i] & (sensor_type << 16)) - events.push_back(m_supported_event_info[i]); - } - - info.set_supported_events(events); + info.set_supported_event(get_event_type()); info.set_wakeup_supported(properties.wakeup_supported); return; } -bool sensor_base::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) +bool sensor_base::is_wakeup_supported(void) { return false; } -bool sensor_base::is_supported(unsigned int event_type) +bool sensor_base::set_interval(unsigned long interval) { - auto iter = find(m_supported_event_info.begin(), m_supported_event_info.end(), event_type); - - if (iter == m_supported_event_info.end()) - return false; - - return true; + return false; } -bool sensor_base::is_wakeup_supported(void) +bool sensor_base::set_wakeup(int wakeup) { return false; } -long sensor_base::set_command(unsigned int cmd, long value) +bool sensor_base::set_batch(unsigned long latency) { - return -1; + return false; } -bool sensor_base::set_wakeup(int client_id, int wakeup) +void sensor_base::set_privilege(sensor_privilege_t privilege) { - return false; + m_privilege = privilege; } -bool sensor_base::set_batch(int client_id, unsigned int latency) +void sensor_base::set_permission(int permission) { - return false; + m_permission = permission; } int sensor_base::send_sensorhub_data(const char* data, int data_len) @@ -442,37 +394,62 @@ int sensor_base::send_sensorhub_data(const char* data, int data_len) return -1; } -int sensor_base::get_sensor_data(unsigned int type, sensor_data_t &data) +bool sensor_base::push(sensor_event_t *event, int event_length) { - return -1; + AUTOLOCK(m_client_mutex); + + if (m_client <= 0) + return false; + + csensor_event_queue::get_instance().push(event, event_length); + return true; } -void sensor_base::register_supported_event(unsigned int event_type) +/* +bool sensor_base::push(const sensor_event_t &event) { - m_supported_event_info.push_back(event_type); + AUTOLOCK(m_client_mutex); + + if (m_client <= 0) + return false; + + csensor_event_queue::get_instance().push(event); + return true; } -void sensor_base::unregister_supported_event(unsigned int event_type) +bool sensor_base::push(sensor_event_t *event) { - m_supported_event_info.erase(std::remove(m_supported_event_info.begin(), - m_supported_event_info.end(), event_type), m_supported_event_info.end()); + AUTOLOCK(m_client_mutex); + + if (m_client <= 0) + return false; + + csensor_event_queue::get_instance().push(event); + return true; } -unsigned int sensor_base::get_client_cnt(unsigned int event_type) -{ - AUTOLOCK(m_client_info_mutex); - auto iter = m_client_info.find(event_type); +bool sensor_base::push(const sensorhub_event_t &event) +{ + AUTOLOCK(m_client_mutex); - if (iter == m_client_info.end()) - return 0; + if (m_client <= 0) + return false; - return iter->second; + csensor_event_queue::get_instance().push(event); + return true; } -bool sensor_base::set_interval(unsigned long val) +bool sensor_base::push(sensorhub_event_t *event) { + AUTOLOCK(m_client_mutex); + + if (m_client <= 0) + return false; + + csensor_event_queue::get_instance().push(event); return true; } +*/ unsigned long long sensor_base::get_timestamp(void) { @@ -490,3 +467,4 @@ unsigned long long sensor_base::get_timestamp(timeval *t) return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec); } + diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 612547a..c3d19c3 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -36,96 +36,100 @@ #include #include #include +#include class sensor_base { -private: - typedef std::unordered_map client_info; - public: sensor_base(); virtual ~sensor_base(); - virtual bool init(void); - void add_id(sensor_id_t id); - sensor_id_t get_id(sensor_type_t sensor_type); - virtual void get_types(std::vector &types) {}; - - sensor_privilege_t get_privilege(void); - int get_permission(void); + /* module info */ + virtual sensor_type_t get_type(); + virtual unsigned int get_event_type(void); virtual const char* get_name(void); - virtual bool is_virtual(void); + /* start/stop */ bool start(void); bool stop(void); - bool is_started(void); - - virtual bool add_client(unsigned int event_type); - virtual bool delete_client(unsigned int event_type); - virtual bool add_interval(int client_id, unsigned int interval, bool is_processor); - virtual bool delete_interval(int client_id, bool is_processor); + /* interval / batch / wakeup */ + bool add_interval(int client_id, unsigned int interval, bool is_processor); + bool delete_interval(int client_id, bool is_processor); unsigned int get_interval(int client_id, bool is_processor); - virtual bool add_wakeup(int client_id, int wakeup); - virtual bool delete_wakeup(int client_id); + bool add_batch(int client_id, unsigned int latency); + bool delete_batch(int client_id); + unsigned int get_batch(int client_id); + + bool add_wakeup(int client_id, int wakeup); + bool delete_wakeup(int client_id); int get_wakeup(int client_id); + bool is_wakeup_supported(void); - virtual bool add_batch(int client_id, unsigned int latency); - virtual bool delete_batch(int client_id); - unsigned int get_batch(int client_id); + /* get data */ + virtual int get_sensor_data(sensor_data_t &data); + virtual int get_sensor_event(sensor_event_t **event); - void get_sensor_info(sensor_type_t sensor_type, sensor_info &info); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + /* id */ + void set_id(sensor_id_t id); + sensor_id_t get_id(void); - bool is_supported(unsigned int event_type); - bool is_wakeup_supported(void); + /* privilege */ + sensor_privilege_t get_privilege(void); + int get_permission(void); - virtual long set_command(unsigned int cmd, long value); - virtual bool set_wakeup(int client_id, int wakeup); - virtual bool set_batch(int client_id, unsigned int latency); - virtual int send_sensorhub_data(const char* data, int data_len); + bool is_started(void); + virtual bool is_virtual(void); + + /* sensor info */ + virtual void get_sensor_info(sensor_info &info); - virtual int get_sensor_data(unsigned int type, sensor_data_t &data); + /* push event to queue */ + bool push(sensor_event_t *event, int event_length); + /* + bool push(const sensor_event_t &event); + bool push(sensor_event_t *event); + bool push(const sensorhub_event_t &event); + bool push(sensorhub_event_t *event); + */ - void register_supported_event(unsigned int event_type); - void unregister_supported_event(unsigned int event_type); + /* for sensorhub */ + virtual long set_command(unsigned int cmd, long value); + virtual int send_sensorhub_data(const char* data, int data_len); protected: - typedef std::lock_guard lock; - typedef std::lock_guard rlock; - typedef std::unique_lock ulock; + cmutex m_mutex; + + void set_privilege(sensor_privilege_t privilege); + void set_permission(int permission); - std::map m_ids; +private: + sensor_id_t m_unique_id; + sensor_handle_t m_handle; sensor_privilege_t m_privilege; + int m_permission; cplugin_info_list m_plugin_info_list; cmutex m_plugin_info_list_mutex; - cmutex m_mutex; - unsigned int m_client; cmutex m_client_mutex; - client_info m_client_info; - cmutex m_client_info_mutex; - - std::vector m_supported_event_info; bool m_started; - std::string m_name; + virtual bool set_interval(unsigned long interval); + virtual bool set_batch(unsigned long latency); + virtual bool set_wakeup(int wakeup); - sensor_id_t get_id(void); - void set_privilege(sensor_privilege_t privilege); - void set_permission(int permission); - unsigned int get_client_cnt(unsigned int event_type); - virtual bool set_interval(unsigned long val); + /* get properties */ + virtual bool get_properties(sensor_properties_s &properties); - static unsigned long long get_timestamp(void); - static unsigned long long get_timestamp(timeval *t); -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 diff --git a/src/server/sensor_hal.h b/src/server/sensor_hal.h deleted file mode 100644 index 2da6406..0000000 --- a/src/server/sensor_hal.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2015 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_H_ -#define _SENSOR_HAL_H_ - -typedef enum { - SENSOR_HAL_TYPE_ACCELEROMETER, - SENSOR_HAL_TYPE_GEOMAGNETIC, - SENSOR_HAL_TYPE_LIGHT, - SENSOR_HAL_TYPE_PROXIMITY, - SENSOR_HAL_TYPE_GYROSCOPE, - SENSOR_HAL_TYPE_PRESSURE, - SENSOR_HAL_TYPE_CONTEXT, - SENSOR_HAL_TYPE_BIO, - SENSOR_HAL_TYPE_BIO_HRM, - SENSOR_HAL_TYPE_PIR, - SENSOR_HAL_TYPE_PIR_LONG, - SENSOR_HAL_TYPE_TEMPERATURE, - SENSOR_HAL_TYPE_HUMIDITY, - SENSOR_HAL_TYPE_ULTRAVIOLET, - SENSOR_HAL_TYPE_DUST, - SENSOR_HAL_TYPE_BIO_LED_IR, - SENSOR_HAL_TYPE_BIO_LED_RED, - SENSOR_HAL_TYPE_BIO_LED_GREEN, - SENSOR_HAL_TYPE_RV_RAW, - SENSOR_HAL_TYPE_GYROSCOPE_UNCAL, - SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL, - SENSOR_HAL_TYPE_FUSION, -} sensor_hal_type_t; - - - -class sensor_hal -{ -public: - sensor_hal(){}; - virtual ~sensor_hal(){}; - - virtual std::string get_model_id(void) = 0; - virtual sensor_hal_type_t get_type(void) = 0; - virtual bool enable(void) = 0; - virtual bool disable(void) = 0; - virtual bool is_data_ready(void) = 0; - virtual bool set_interval(unsigned long val) = 0; - virtual int get_sensor_data(sensor_data_t &data) = 0; - virtual bool get_properties(sensor_properties_s &properties) = 0; -}; -#endif /*_SENSOR_HAL_H_*/ diff --git a/src/server/sensor_plugin_loader.cpp.in b/src/server/sensor_plugin_loader.cpp.in index 86b45c1..d4b1f01 100644 --- a/src/server/sensor_plugin_loader.cpp.in +++ b/src/server/sensor_plugin_loader.cpp.in @@ -22,16 +22,17 @@ #include #include #include +#include #include #include #include #include #include -/* #ifdef ENABLE_AUTO_ROTATION #include #endif +/* #ifdef ENABLE_TILT #include #endif @@ -61,14 +62,9 @@ #endif */ -using std::make_pair; -using std::equal; using std::unordered_set; -using std::pair; using std::vector; using std::string; -using std::shared_ptr; -using std::static_pointer_cast; #define ROOT_ELEMENT "PLUGIN" #define TEXT_ELEMENT "text" @@ -76,19 +72,6 @@ using std::static_pointer_cast; #define HAL_ELEMENT "HAL" #define SENSOR_ELEMENT "SENSOR" -#define ACCELEROMETER_ENABLED 0x01 -#define GYROSCOPE_ENABLED 0x02 -#define GEOMAGNETIC_ENABLED 0x04 -#define TILT_ENABLED 1 -#define FUSION_ENABLED 1 -#define AUTO_ROTATION_ENABLED 1 -#define GAMING_RV_ENABLED 3 -#define GEOMAGNETIC_RV_ENABLED 5 -#define ORIENTATION_ENABLED 7 -#define GRAVITY_ENABLED 7 -#define LINEAR_ACCEL_ENABLED 7 -#define ORIENTATION_ENABLED 7 - #define HAL_PLUGINS_DIR_PATH "/usr/lib/sensor" #define SENSOR_INDEX_SHIFT 16 @@ -103,8 +86,10 @@ sensor_plugin_loader& sensor_plugin_loader::get_instance() return inst; } -bool sensor_plugin_loader::load_module(const string &path, vector &sensors, void* &handle) +bool sensor_plugin_loader::load_plugin(const string &path, vector &sensors, void* &handle) { + INFO("load HAL plugin [%s]", path.c_str()); + void *_handle = dlopen(path.c_str(), RTLD_NOW); if (!_handle) { @@ -114,84 +99,66 @@ bool sensor_plugin_loader::load_module(const string &path, vector &sensor dlerror(); - create_t create_module = (create_t) dlsym(_handle, "create"); + create_t create_plugin = (create_t) dlsym(_handle, "create"); - if (!create_module) { + if (!create_plugin) { ERR("Failed to find symbols in %s", path.c_str()); dlclose(_handle); return false; } - sensor_module *module = create_module(); + sensor_module *plugin = create_plugin(); - if (!module) { - ERR("Failed to create module, path is %s\n", path.c_str()); + if (!plugin) { + ERR("Failed to create plugin, path is %s\n", path.c_str()); dlclose(_handle); return false; } sensors.clear(); - sensors.swap(module->sensors); + sensors.swap(plugin->sensors); - delete module; + delete plugin; handle = _handle; return true; } -bool sensor_plugin_loader::insert_module(plugin_type type, const string &path) +bool sensor_plugin_loader::insert_plugins(std::vector hals) { - if (type == PLUGIN_TYPE_HAL) { - DBG("Insert HAL plugin [%s]", path.c_str()); - - std::vectorhals; - void *handle; - - if (!load_module(path, hals, handle)) - return false; + unsigned int i; + sensor_hal *hal; - shared_ptr hal; + for (i = 0; i < hals.size(); ++i) { + hal = static_cast(hals[i]); - for (unsigned int i = 0; i < hals.size(); ++i) { - hal.reset(static_cast (hals[i])); - sensor_hal_type_t sensor_hal_type = hal->get_type(); - m_sensor_hals.insert(make_pair(sensor_hal_type, hal)); - } - } else if (type == PLUGIN_TYPE_SENSOR) { - DBG("Insert Sensor plugin [%s]", path.c_str()); - - std::vector sensors; - void *handle; - - if (!load_module(path, sensors, handle)) - return false; + insert_sensors(hal); + } - shared_ptr sensor; + return true; +} - for (unsigned int i = 0; i < sensors.size(); ++i) { - sensor.reset(static_cast (sensors[i])); +bool sensor_plugin_loader::insert_sensors(sensor_hal *hal) +{ + unsigned int i; + vector sensors; + physical_sensor *phy_sensor; - if (!sensor->init()) { - ERR("Failed to init [%s] module\n", sensor->get_name()); - continue; - } + hal->get_sensors(sensors); - DBG("init [%s] module", sensor->get_name()); + for (i = 0; i < sensors.size(); ++i) { + int idx; + idx = m_sensors.count(sensors[i].type); - vector sensor_types; + phy_sensor = new physical_sensor(); + phy_sensor->set_id(idx << SENSOR_INDEX_SHIFT | sensors[i].type); + phy_sensor->set_sensor_handle(sensors[i]); + phy_sensor->set_sensor_hal(hal); - sensor->get_types(sensor_types); + std::shared_ptr sensor(phy_sensor); + m_sensors.insert(std::make_pair(sensors[i].type, sensor)); - for (unsigned int i = 0; i < sensor_types.size(); ++i) { - int idx; - idx = m_sensors.count(sensor_types[i]); - sensor->add_id(idx << SENSOR_INDEX_SHIFT | sensor_types[i]); - m_sensors.insert(make_pair(sensor_types[i], sensor)); - } - } - }else { - ERR("Not supported type: %d", type); - return false; + INFO("created [%s] sensor", sensor->get_name()); } return true; @@ -202,9 +169,6 @@ bool sensor_plugin_loader::load_plugins(void) vector hal_paths; vector unique_hal_paths; - int enable_virtual_sensor = 0; - vector sensors; - get_paths_from_dir(string(HAL_PLUGINS_DIR_PATH), hal_paths); unordered_set s; @@ -221,150 +185,31 @@ bool sensor_plugin_loader::load_plugins(void) for_each(unique_hal_paths.begin(), unique_hal_paths.end(), [&](const string &path) { - insert_module(PLUGIN_TYPE_HAL, path); + void *handle; + std::vector hals; + + load_plugin(path, hals, handle); + insert_plugins(hals); } ); - -#ifdef ENABLE_SENSOR_FUSION - fusion_sensor* fusion_sensor_ptr = NULL; +#ifdef ENABLE_AUTO_ROTATION + auto_rotation_sensor* auto_rot_sensor_ptr = NULL; try { - fusion_sensor_ptr = new(std::nothrow) fusion_sensor; + auto_rot_sensor_ptr = new(std::nothrow) auto_rotation_sensor; } catch (int err) { - ERR("Failed to create fusion_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (fusion_sensor_ptr != NULL) - sensors.push_back(fusion_sensor_ptr); -#endif -#ifdef ENABLE_TILT - if (enable_virtual_sensor & TILT_ENABLED == TILT_ENABLED) { - tilt_sensor* tilt_sensor_ptr = NULL; - try { - tilt_sensor_ptr = new(std::nothrow) tilt_sensor; - } catch (int err) { - ERR("Failed to create tilt_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (tilt_sensor_ptr != NULL) - sensors.push_back(tilt_sensor_ptr); + ERR("Failed to create auto_rotation_sensor module, err: %d, cause: %s", err, strerror(err)); } -#endif -#ifdef ENABLE_AUTO_ROTATION - if (enable_virtual_sensor & AUTO_ROTATION_ENABLED == AUTO_ROTATION_ENABLED) { - auto_rotation_sensor* auto_rot_sensor_ptr = NULL; - try { - auto_rot_sensor_ptr = new(std::nothrow) auto_rotation_sensor; - } catch (int err) { - ERR("Failed to create auto_rotation_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (auto_rot_sensor_ptr != NULL) - sensors.push_back(auto_rot_sensor_ptr); - } -#endif -#ifdef ENABLE_GRAVITY - if (enable_virtual_sensor & GRAVITY_ENABLED == GRAVITY_ENABLED) { - gravity_sensor* gravity_sensor_ptr = NULL; - try { - gravity_sensor_ptr = new(std::nothrow) gravity_sensor; - } catch (int err) { - ERR("Failed to create tilt_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (gravity_sensor_ptr != NULL) - sensors.push_back(gravity_sensor_ptr); - } -#endif -#ifdef ENABLE_LINEAR_ACCEL - if (enable_virtual_sensor & LINEAR_ACCEL_ENABLED == LINEAR_ACCEL_ENABLED) { - linear_accel_sensor* linear_accel_sensor_ptr = NULL; - try { - linear_accel_sensor_ptr = new(std::nothrow) linear_accel_sensor; - } catch (int err) { - ERR("Failed to create linear_accel_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (linear_accel_sensor_ptr != NULL) - sensors.push_back(linear_accel_sensor_ptr); - } -#endif + if (auto_rot_sensor_ptr != NULL) { + std::shared_ptr sensor(auto_rot_sensor_ptr); + sensor_hal_type type; - if (enable_virtual_sensor & ORIENTATION_ENABLED == ORIENTATION_ENABLED) { -#ifdef ENABLE_ORIENTATION - orientation_sensor* orientation_sensor_ptr = NULL; - try { - orientation_sensor_ptr = new(std::nothrow) orientation_sensor; - } catch (int err) { - ERR("Failed to create orientation_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (orientation_sensor_ptr != NULL) - sensors.push_back(orientation_sensor_ptr); -#endif -#ifdef ENABLE_RV - rv_sensor* rv_sensor_ptr = NULL; - try { - rv_sensor_ptr = new(std::nothrow) rv_sensor; - } catch (int err) { - ERR("Failed to create rv_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (rv_sensor_ptr != NULL) - sensors.push_back(rv_sensor_ptr); -#endif -#ifdef ENABLE_GYROSCOPE_UNCAL - gyroscope_uncal_sensor* gyroscope_uncal_sensor_ptr = NULL; - try { - gyroscope_uncal_sensor_ptr = new(std::nothrow) gyroscope_uncal_sensor; - } catch (int err) { - ERR("Failed to create gyroscope_uncal_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (gyroscope_uncal_sensor_ptr != NULL) - sensors.push_back(gyroscope_uncal_sensor_ptr); -#endif - } + type = static_cast(sensor->get_type()); + sensor->set_id(type); -#ifdef ENABLE_GAMING_RV - if (enable_virtual_sensor & GAMING_RV_ENABLED == GAMING_RV_ENABLED) { - gaming_rv_sensor* gaming_rv_sensor_ptr = NULL; - try { - gaming_rv_sensor_ptr = new(std::nothrow) gaming_rv_sensor; - } catch (int err) { - ERR("Failed to create gaming_rv_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (gaming_rv_sensor_ptr != NULL) - sensors.push_back(gaming_rv_sensor_ptr); - } -#endif -#ifdef ENABLE_GEOMAGNETIC_RV - if (enable_virtual_sensor & GEOMAGNETIC_RV_ENABLED == GEOMAGNETIC_RV_ENABLED) { - geomagnetic_rv_sensor* geomagnetic_rv_sensor_ptr = NULL; - try { - geomagnetic_rv_sensor_ptr = new(std::nothrow) geomagnetic_rv_sensor; - } catch (int err) { - ERR("Failed to create geomagnetic_rv_sensor module, err: %d, cause: %s", err, strerror(err)); - } - if (geomagnetic_rv_sensor_ptr != NULL) - sensors.push_back(geomagnetic_rv_sensor_ptr); + m_sensors.insert(std::make_pair(type, sensor)); } #endif - shared_ptr sensor; - - for (unsigned int i = 0; i < sensors.size(); ++i) { - sensor.reset(static_cast (sensors[i])); - - if (!sensor->init()) { - ERR("Failed to init [%s] module\n", sensor->get_name()); - continue; - } - - DBG("init [%s] module", sensor->get_name()); - - vector sensor_types; - - sensor->get_types(sensor_types); - - for (unsigned int i = 0; i < sensor_types.size(); ++i) { - int idx; - idx = m_sensors.count(sensor_types[i]); - sensor->add_id(idx << SENSOR_INDEX_SHIFT | sensor_types[i]); - m_sensors.insert(make_pair(sensor_types[i], sensor)); - } - } show_sensor_info(); return true; @@ -379,10 +224,10 @@ void sensor_plugin_loader::show_sensor_info(void) auto it = m_sensors.begin(); while (it != m_sensors.end()) { - shared_ptr sensor = it->second; + sensor_base *sensor = it->second.get(); sensor_info info; - sensor->get_sensor_info(it->first, info); + sensor->get_sensor_info(info); INFO("No:%d [%s]\n", ++index, sensor->get_name()); info.show(); it++; @@ -414,47 +259,40 @@ bool sensor_plugin_loader::get_paths_from_dir(const string &dir_path, vector(type)); - if (it_plugins == m_sensor_hals.end()) + if (it_plugins == m_sensors.end()) return NULL; return it_plugins->second.get(); } -vector sensor_plugin_loader::get_sensor_hals(sensor_hal_type_t type) +sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id) { - vector sensor_hal_list; - pair ret; - ret = m_sensor_hals.equal_range(type); - - for (auto it = ret.first; it != ret.second; ++it) - sensor_hal_list.push_back(it->second.get()); + vector sensors; - return sensor_hal_list; -} + sensor_type_t type = static_cast (id & SENSOR_TYPE_MASK); + unsigned int index = id >> SENSOR_INDEX_SHIFT; -sensor_base* sensor_plugin_loader::get_sensor(sensor_type_t type) -{ - auto it_plugins = m_sensors.find(type); + sensors = get_sensors(type); - if (it_plugins == m_sensors.end()) + if (sensors.size() <= index) return NULL; - return it_plugins->second.get(); + return sensors[index]; } vector sensor_plugin_loader::get_sensors(sensor_type_t type) { vector sensor_list; - pair ret; + std::pair ret; - if (type == ALL_SENSOR) + if ((int)(type) == (int)SENSOR_HAL_TYPE_ALL) ret = std::make_pair(m_sensors.begin(), m_sensors.end()); else - ret = m_sensors.equal_range(type); + ret = m_sensors.equal_range(static_cast(type)); for (auto it = ret.first; it != ret.second; ++it) sensor_list.push_back(it->second.get()); @@ -462,33 +300,16 @@ vector sensor_plugin_loader::get_sensors(sensor_type_t type) return sensor_list; } - -sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id) -{ - vector sensors; - - sensor_type_t type = (sensor_type_t) (id & SENSOR_TYPE_MASK); - unsigned int index = id >> SENSOR_INDEX_SHIFT; - - sensors = get_sensors(type); - - if (sensors.size() <= index) - return NULL; - - return sensors[index]; -} - - vector sensor_plugin_loader::get_virtual_sensors(void) { vector virtual_list; - sensor_base* module; + sensor_base* sensor; for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) { - module = sensor_it->second.get(); + sensor = sensor_it->second.get(); - if (module && module->is_virtual() == true) { - virtual_list.push_back(module); + if (sensor && sensor->is_virtual() == true) { + virtual_list.push_back(sensor); } } diff --git a/src/server/sensor_plugin_loader.h b/src/server/sensor_plugin_loader.h index 35a1fb5..bc0bb66 100755 --- a/src/server/sensor_plugin_loader.h +++ b/src/server/sensor_plugin_loader.h @@ -36,54 +36,29 @@ class sensor_hal; class sensor_base; -typedef std::multimap > sensor_hal_plugins; -/* -* a hal_plugins is a group of hal plugin -* -* ... -* -* -*/ - -typedef std::multimap > sensor_plugins; -/* -* a sensor_plugins is a group of sensor plugin -* -* ... -* -* -*/ +typedef std::multimap> sensor_plugins; class sensor_plugin_loader { private: - typedef enum plugin_type { - PLUGIN_TYPE_HAL, - PLUGIN_TYPE_SENSOR, - } plugin_type; - sensor_plugin_loader(); - bool load_module(const std::string &path, std::vector &sensors, void* &handle); - bool insert_module(plugin_type type, const std::string &path); + bool load_plugin(const std::string &path, std::vector &sensors, void* &handle); + bool insert_plugins(std::vector hals); + bool insert_sensors(sensor_hal *hal); void show_sensor_info(void); bool get_paths_from_dir(const std::string &dir_path, std::vector &hal_paths); - sensor_hal_plugins m_sensor_hals; sensor_plugins m_sensors; - public: static sensor_plugin_loader& get_instance(); bool load_plugins(void); - sensor_hal* get_sensor_hal(sensor_hal_type_t type); - std::vector get_sensor_hals(sensor_hal_type_t type); - sensor_base* get_sensor(sensor_type_t type); - std::vector get_sensors(sensor_type_t type); sensor_base* get_sensor(sensor_id_t id); + std::vector get_sensors(sensor_type_t type); std::vector get_virtual_sensors(void); }; #endif /* _SENSOR_PLUGIN_LOADER_CLASS_H_ */ diff --git a/src/server/virtual_sensor.cpp b/src/server/virtual_sensor.cpp index 9a9aabb..75c3bc0 100755 --- a/src/server/virtual_sensor.cpp +++ b/src/server/virtual_sensor.cpp @@ -47,10 +47,3 @@ bool virtual_sensor::deactivate(void) { return csensor_event_dispatcher::get_instance().delete_active_virtual_sensor(this); } - -bool virtual_sensor::push(sensor_event_t const &event) -{ - csensor_event_queue::get_instance().push(event); - return true; -} - diff --git a/src/server/virtual_sensor.h b/src/server/virtual_sensor.h index 780ba66..a695538 100755 --- a/src/server/virtual_sensor.h +++ b/src/server/virtual_sensor.h @@ -28,17 +28,19 @@ public: virtual_sensor(); virtual ~virtual_sensor(); - virtual void synthesize(const sensor_event_t& event, std::vector &outs) = 0; - virtual int get_sensor_data(const unsigned int event_type, sensor_data_t &data) = 0; - bool is_virtual(void); - bool m_hardware_fusion; + /* module info */ + virtual sensor_type_t get_type() = 0; + virtual unsigned int get_event_type(void) = 0; + virtual const char* get_name(void) = 0; + virtual void synthesize(const sensor_event_t& event, std::vector &outs) = 0; + virtual int get_sensor_data(sensor_data_t &data) = 0; + virtual bool is_virtual(void); protected: - bool activate(void); bool deactivate(void); - - bool push(sensor_event_t const &event); +private: + bool m_hardware_fusion; }; #endif diff --git a/src/shared/sensor_hal.h b/src/shared/sensor_hal.h index 8e14b22..7e062ef 100644 --- a/src/shared/sensor_hal.h +++ b/src/shared/sensor_hal.h @@ -19,49 +19,127 @@ #ifndef _SENSOR_HAL_H_ #define _SENSOR_HAL_H_ + +#include #include +#include +#include #include +#define SENSOR_HAL_VERSION(maj,min) \ + ((((maj) & 0xffff) << 24) | ((min) & 0xffff)) + +/* + * 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_HAL_TYPE_UNKNOWN = -2, + SENSOR_HAL_TYPE_ALL = -1, SENSOR_HAL_TYPE_ACCELEROMETER, + SENSOR_HAL_TYPE_GRAVITY, + SENSOR_HAL_TYPE_LINEAR_ACCELERATION, SENSOR_HAL_TYPE_GEOMAGNETIC, + SENSOR_HAL_TYPE_ROTATION_VECTOR, + SENSOR_HAL_TYPE_ORIENTATION, + SENSOR_HAL_TYPE_GYROSCOPE, SENSOR_HAL_TYPE_LIGHT, SENSOR_HAL_TYPE_PROXIMITY, - SENSOR_HAL_TYPE_GYROSCOPE, SENSOR_HAL_TYPE_PRESSURE, - SENSOR_HAL_TYPE_CONTEXT, - SENSOR_HAL_TYPE_BIO, - SENSOR_HAL_TYPE_BIO_HRM, - SENSOR_HAL_TYPE_PIR, - SENSOR_HAL_TYPE_PIR_LONG, + SENSOR_HAL_TYPE_ULTRAVIOLET, SENSOR_HAL_TYPE_TEMPERATURE, SENSOR_HAL_TYPE_HUMIDITY, - SENSOR_HAL_TYPE_ULTRAVIOLET, - SENSOR_HAL_TYPE_DUST, - SENSOR_HAL_TYPE_BIO_LED_IR, - SENSOR_HAL_TYPE_BIO_LED_RED, - SENSOR_HAL_TYPE_BIO_LED_GREEN, - SENSOR_HAL_TYPE_RV_RAW, + SENSOR_HAL_TYPE_HRM, + SENSOR_HAL_TYPE_HRM_LED_GREEN, + SENSOR_HAL_TYPE_HRM_LED_IR, + SENSOR_HAL_TYPE_HRM_LED_RED, SENSOR_HAL_TYPE_GYROSCOPE_UNCAL, SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL, - SENSOR_HAL_TYPE_FUSION, -} sensor_hal_type_t; + SENSOR_HAL_TYPE_GYROSCOPE_RV, + SENSOR_HAL_TYPE_GEOMAGNETIC_RV, + SENSOR_HAL_TYPE_ACTIVITY_STATIONARY = 0x100, + SENSOR_HAL_TYPE_ACTIVITY_WALK, + SENSOR_HAL_TYPE_ACTIVITY_RUN, + SENSOR_HAL_TYPE_ACTIVITY_IN_VEHICLE, + SENSOR_HAL_TYPE_ACTIVITY_ON_BICYCLE, + SENSOR_HAL_TYPE_GESTURE_MOVEMENT = 0x200, + SENSOR_HAL_TYPE_GESTURE_WRIST_UP, + SENSOR_HAL_TYPE_GESTURE_WRIST_DOWN, + SENSOR_HAL_TYPE_HUMAN_PEDOMETER = 0x300, + SENSOR_HAL_TYPE_HUMAN_SLEEP_MONITOR, + + SENSOR_HAL_TYPE_FUSION = 0x900, + SENSOR_HAL_TYPE_AUTO_ROTATION, + + SENSOR_HAL_TYPE_CONTEXT = 0x1000, + SENSOR_HAL_TYPE_MOTION, + SENSOR_HAL_TYPE_PIR, + SENSOR_HAL_TYPE_PIR_LONG, + SENSOR_HAL_TYPE_DUST, + SENSOR_HAL_TYPE_THERMOMETER, + SENSOR_HAL_TYPE_PEDOMETER, + SENSOR_HAL_TYPE_FLAT, + SENSOR_HAL_TYPE_HRM_RAW, + SENSOR_HAL_TYPE_TILT, + SENSOR_HAL_TYPE_ROTATION_VECTOR_RAW, +} sensor_hal_type; + +/* + * A platform sensor handler is generated based on this handle + * ID can be assigned from HAL developer. so it has to be unique in HAL. + */ +typedef struct sensor_handle_t { + uint32_t id; + std::string name; + sensor_hal_type type; + unsigned int event_type; // for Internal API +} sensor_handle_t; + +/* + * Sensor HAL interface + * 1 HAL must be abstracted from 1 device event node + */ class sensor_hal { public: - sensor_hal(); - virtual ~sensor_hal(); - - virtual std::string get_model_id(void) = 0; - virtual sensor_hal_type_t get_type(void) = 0; - virtual bool enable(void) = 0; - virtual bool disable(void) = 0; - virtual bool is_data_ready(void) = 0; - virtual bool set_interval(unsigned long val) = 0; - virtual int get_sensor_data(sensor_data_t &data) = 0; - virtual bool get_properties(sensor_properties_s &properties) = 0; + uint32_t get_hal_version(void) { + return SENSOR_HAL_VERSION(1, 0); + } + + virtual int get_poll_fd(void) = 0; + virtual bool get_sensors(std::vector &sensors) = 0; + + /* enable/disable sensor device */ + virtual bool enable(uint32_t id) = 0; + virtual bool disable(uint32_t id) = 0; + + /* set_command or set_option? */ + virtual bool set_command(uint32_t id, std::string command, std::string value) = 0; + + /* the belows can be merged to one */ + virtual bool set_interval(uint32_t id, unsigned long val) = 0; + virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0; + + /* sensor fw read the data when is_data_ready() is true */ + virtual bool is_data_ready() = 0; + virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0; + virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0; + + /* TODO: use get_sensors() instead of get_properties() */ + virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0; }; #endif /*_SENSOR_HAL_H_*/ diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index c25f366..030b2dc 100644 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -81,16 +81,14 @@ int sensor_info::get_max_batch_count(void) return m_max_batch_count; } -void sensor_info::get_supported_events(vector &events) +unsigned int sensor_info::get_supported_event() { - events = m_supported_events; + return m_supported_event; } bool sensor_info::is_supported_event(unsigned int event) { - auto iter = find(m_supported_events.begin(), m_supported_events.end(), event); - - if (iter == m_supported_events.end()) + if (event != m_supported_event) return false; return true; @@ -156,14 +154,9 @@ void sensor_info::set_max_batch_count(int max_batch_count) m_max_batch_count = max_batch_count; } -void sensor_info::register_supported_event(unsigned int event) +void sensor_info::set_supported_event(unsigned int event) { - m_supported_events.push_back(event); -} - -void sensor_info::set_supported_events(vector &events) -{ - copy(events.begin(), events.end(), back_inserter(m_supported_events)); + m_supported_event = event; } void sensor_info::set_wakeup_supported(bool supported) @@ -184,7 +177,7 @@ void sensor_info::get_raw_data(raw_data_t &data) put(data, m_min_interval); put(data, m_fifo_count); put(data, m_max_batch_count); - put(data, m_supported_events); + put(data, m_supported_event); put(data, m_wakeup_supported); } @@ -210,7 +203,7 @@ void sensor_info::set_raw_data(const char *data, int data_len) it_r_data = get(it_r_data, m_min_interval); it_r_data = get(it_r_data, m_fifo_count); it_r_data = get(it_r_data, m_max_batch_count); - it_r_data = get(it_r_data, m_supported_events); + it_r_data = get(it_r_data, m_supported_event); it_r_data = get(it_r_data, m_wakeup_supported); } @@ -227,9 +220,7 @@ void sensor_info::show(void) INFO("Min_interval = %d", m_min_interval); INFO("Fifo_count = %d", m_fifo_count); INFO("Max_batch_count = %d", m_max_batch_count); - - for (unsigned int i = 0; i < m_supported_events.size(); ++i) - INFO("supported_events[%u] = 0x%x", i, m_supported_events[i]); + INFO("supported_event = 0x%x", m_supported_event); INFO("Wakeup_supported = %d", m_wakeup_supported); } @@ -248,7 +239,7 @@ void sensor_info::clear(void) m_min_interval = 0; m_fifo_count = 0; m_max_batch_count = 0; - m_supported_events.clear(); + m_supported_event = 0; m_wakeup_supported = false; } @@ -263,33 +254,31 @@ void sensor_info::put(raw_data_t &data, int value) copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } -void sensor_info::put(raw_data_t &data, float value) +void sensor_info::put(raw_data_t &data, unsigned int value) { char buffer[sizeof(value)]; - float *temp = (float *) buffer; + unsigned int *temp = (unsigned int *) buffer; *temp = value; copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } -void sensor_info::put(raw_data_t &data, string &value) +void sensor_info::put(raw_data_t &data, float value) { - put(data, (int) value.size()); + char buffer[sizeof(value)]; - copy(value.begin(), value.end(), back_inserter(data)); + float *temp = (float *) buffer; + *temp = value; + + copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } -void sensor_info::put(raw_data_t &data, vector &value) +void sensor_info::put(raw_data_t &data, string &value) { put(data, (int) value.size()); - auto it = value.begin(); - - while (it != value.end()) { - put(data, (int) *it); - ++it; - } + copy(value.begin(), value.end(), back_inserter(data)); } void sensor_info::put(raw_data_t &data, bool value) @@ -309,37 +298,29 @@ raw_data_iterator sensor_info::get(raw_data_iterator it, int &value) return it + sizeof(value); } -raw_data_iterator sensor_info::get(raw_data_iterator it, float &value) +raw_data_iterator sensor_info::get(raw_data_iterator it, unsigned int &value) { copy(it, it + sizeof(value), (char*) &value); return it + sizeof(value); } -raw_data_iterator sensor_info::get(raw_data_iterator it, string &value) +raw_data_iterator sensor_info::get(raw_data_iterator it, float &value) { - int len; - - it = get(it, len); - - copy(it, it + len, back_inserter(value)); + copy(it, it + sizeof(value), (char*) &value); - return it + len; + return it + sizeof(value); } -raw_data_iterator sensor_info::get(raw_data_iterator it, vector &value) +raw_data_iterator sensor_info::get(raw_data_iterator it, string &value) { int len; it = get(it, len); - int ele; - for (int i = 0; i < len; ++i) { - it = get(it, ele); - value.push_back(ele); - } + copy(it, it + len, back_inserter(value)); - return it; + return it + len; } raw_data_iterator sensor_info::get(raw_data_iterator it, bool &value) diff --git a/src/shared/sensor_info.h b/src/shared/sensor_info.h index 28a35a2..732cc62 100644 --- a/src/shared/sensor_info.h +++ b/src/shared/sensor_info.h @@ -43,7 +43,7 @@ public: int get_min_interval(void); int get_fifo_count(void); int get_max_batch_count(void); - void get_supported_events(std::vector &events); + unsigned int get_supported_event(); bool is_supported_event(unsigned int event); bool is_wakeup_supported(void); @@ -58,8 +58,7 @@ public: void set_min_interval(int min_interval); void set_fifo_count(int fifo_count); void set_max_batch_count(int max_batch_count); - void register_supported_event(unsigned int event); - void set_supported_events(std::vector &events); + void set_supported_event(unsigned int event); void set_wakeup_supported(bool supported); void clear(void); @@ -79,19 +78,19 @@ private: int m_min_interval; int m_fifo_count; int m_max_batch_count; - std::vector m_supported_events; + unsigned int m_supported_event; bool m_wakeup_supported; void put(raw_data_t &data, int value); + void put(raw_data_t &data, unsigned int value); void put(raw_data_t &data, float value); void put(raw_data_t &data, std::string &value); - void put(raw_data_t &data, std::vector &value); void put(raw_data_t &data, bool value); raw_data_iterator get(raw_data_iterator it, int &value); + raw_data_iterator get(raw_data_iterator it, unsigned int &value); raw_data_iterator get(raw_data_iterator it, float &value); raw_data_iterator get(raw_data_iterator it, std::string &value); - raw_data_iterator get(raw_data_iterator it, std::vector &value); raw_data_iterator get(raw_data_iterator it, bool &value); }; -- 2.7.4