From 44ddaba7e2869edbe46bb37f6b7e648ba0773253 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:07:39 +0900 Subject: [PATCH 01/16] sensord: add internal sensor types Change-Id: Ieacf15fdceb421dbc8e7912d137fcae52462a948 Signed-off-by: kibak.yoon --- src/client/client_common.cpp | 1 + src/shared/sensor_types.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index a0a7345..96ce4ff 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -72,6 +72,7 @@ unsigned int get_log_per_count(sensor_id_t id) case GESTURE_WRIST_DOWN_SENSOR: case GESTURE_MOVEMENT_SENSOR: case WEAR_STATUS_SENSOR: + case PRESSURE_SENSOR: return LOG_PER_COUNT_EVERY_EVENT; default: break; diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 18e40f4..dab36bc 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -66,6 +66,8 @@ extern "C" DEF_SENSOR(EXERCISE_ROWING_SENSOR) \ DEF_SENSOR(EXERCISE_STEPPER_SENSOR) \ \ + DEF_SENSOR_VALUE(EXTERNAL_EXERCISE_SENSOR, 0x800) \ + \ DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \ DEF_SENSOR(AUTO_ROTATION_SENSOR) \ DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \ @@ -92,6 +94,9 @@ extern "C" DEF_SENSOR(WORKOUT_SENSOR) \ DEF_SENSOR(CYCLE_MONITOR_SENSOR) \ DEF_SENSOR(STAIR_TRACKER_SENSOR) \ + DEF_SENSOR(PRESSURE_INDICATOR_SENSOR) \ + DEF_SENSOR(PRESSURE_ALERT_SENSOR) \ + DEF_SENSOR(HR_CALORIE_SENSOR) \ \ DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x7000) \ DEF_SENSOR(MOTION_SENSOR) \ @@ -104,6 +109,9 @@ extern "C" DEF_SENSOR(HRM_RAW_SENSOR) \ DEF_SENSOR(TILT_SENSOR) \ DEF_SENSOR(RV_RAW_SENSOR) \ + DEF_SENSOR(GSR_SENSOR) \ + DEF_SENSOR(SIMSENSE_SENSOR) \ + DEF_SENSOR(PPG_SENSOR) \ #define BIO_HRM_SENSOR HRM_SENSOR #define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR @@ -114,6 +122,7 @@ extern "C" #define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR #define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR #define EXERCISE_COACH_SENSOR EXERCISE_STANDALONE_SENSOR +#define EXERCISE_SENSOR EXTERNAL_EXERCISE_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From e358d052833d6af22ce1c1acf835a0b4443fa226 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 18:13:36 +0900 Subject: [PATCH 02/16] sensord: change file permission to remove execute permission Change-Id: I5cce417208269fdbae3899f643089ff1fbd990e5 Signed-off-by: kibak.yoon --- src/client/dbus_listener.cpp | 0 src/server/dbus_util.cpp | 0 src/server/server.cpp | 0 src/shared/macro.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/client/dbus_listener.cpp mode change 100755 => 100644 src/server/dbus_util.cpp mode change 100755 => 100644 src/server/server.cpp mode change 100755 => 100644 src/shared/macro.h diff --git a/src/client/dbus_listener.cpp b/src/client/dbus_listener.cpp old mode 100755 new mode 100644 diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp old mode 100755 new mode 100644 diff --git a/src/server/server.cpp b/src/server/server.cpp old mode 100755 new mode 100644 diff --git a/src/shared/macro.h b/src/shared/macro.h old mode 100755 new mode 100644 -- 2.7.4 From 530996c4a54010f2217862ac891207cb796ffd7f Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 30 Nov 2016 22:16:08 +0900 Subject: [PATCH 03/16] [BugFix] Reset Sensor Fusion Backend if it returns NaN because of inconsitent input and high error Change-Id: I29fe84898d32f710cb914748d3111edfb2da38b7 Signed-off-by: Akhil --- src/sensor/rotation_vector/fusion_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 51e45d3..89b5a44 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -100,5 +100,10 @@ void fusion_base::store_orientation(void) m_y = m_orientation_filter.m_quaternion.m_quat.m_vec[1]; m_z = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; m_w = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; + + if (std::isnan(m_x) || std::isnan(m_y) || std::isnan(m_z) || std::isnan(m_w)) { + m_timestamp = 0; + m_orientation_filter = orientation_filter(); + } clear(); } -- 2.7.4 From 98584eab2e8e7270af197d064ca5aba166c676ea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 2 Dec 2016 18:44:25 +0900 Subject: [PATCH 04/16] sensord: fix compiler warnings Change-Id: I6c702882e120c470ac69d6b0d510021d49ceb15c Signed-off-by: kibak.yoon --- src/sensorctl/injector_manager.cpp | 2 +- src/sensorctl/loopback_manager.cpp | 2 -- src/sensorctl/tester_manager.cpp | 2 +- src/sensorctl/tester_sensor.cpp | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp index 4f6b722..8aeebb0 100644 --- a/src/sensorctl/injector_manager.cpp +++ b/src/sensorctl/injector_manager.cpp @@ -103,7 +103,7 @@ bool injector_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } result = injector->inject(option_count, options); diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback_manager.cpp index 4b78007..b7908b6 100644 --- a/src/sensorctl/loopback_manager.cpp +++ b/src/sensorctl/loopback_manager.cpp @@ -42,8 +42,6 @@ static void int_to_bytes(int32_t value, int length, char cmd[]) bool loopback_manager::process(int argc, char *argv[]) { - sensor_type_t type; - if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { usage(); return false; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp index ffd9e57..c16140f 100644 --- a/src/sensorctl/tester_manager.cpp +++ b/src/sensorctl/tester_manager.cpp @@ -55,7 +55,7 @@ bool tester_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } tester->test(type, option_count, options); diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp index 5a75da6..7f324f6 100644 --- a/src/sensorctl/tester_sensor.cpp +++ b/src/sensorctl/tester_sensor.cpp @@ -36,8 +36,8 @@ static GMainLoop *mainloop; static int check_loop; static const char *result_str(bool result) { - if (result) return KGRN"[PASS]"RESET; - else return KRED"[FAIL]"RESET; + if (result) return KGRN "[PASS]" RESET; + else return KRED "[FAIL]" RESET; } bool tester_sensor::init(void) -- 2.7.4 From 0c9da3394ec379bd829a8d5e4712bcfb3198cb9a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 6 Dec 2016 10:43:02 +0900 Subject: [PATCH 05/16] sensord: install required header files instead of all header files Change-Id: Ib826fe1e3464a560f58e5868c64fd4e2cf9a8136 Signed-off-by: kibak.yoon --- src/client/CMakeLists.txt | 12 ++++++++---- src/client/sensor_internal.h | 2 +- src/client/sensor_internal_deprecated.h | 2 +- src/shared/CMakeLists.txt | 15 +++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 2f32b9c..f14b841 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -22,6 +22,11 @@ ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC") +SET (INSTALL_HEADERS + sensor_internal.h + sensor_internal_deprecated.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_SOURCE_DIR}/src/shared @@ -37,9 +42,8 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) 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( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" - ) +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index 47452d4..b7e9469 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -24,7 +24,7 @@ #define API __attribute__((visibility("default"))) #endif -#include "stdbool.h" +#include #include /*header for common sensor type*/ diff --git a/src/client/sensor_internal_deprecated.h b/src/client/sensor_internal_deprecated.h index a2b5b30..851ccbc 100644 --- a/src/client/sensor_internal_deprecated.h +++ b/src/client/sensor_internal_deprecated.h @@ -24,7 +24,7 @@ #define DEPRECATED __attribute__((deprecated)) #endif -#include "stdbool.h" +#include #include diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8b8416e..5d094ec 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -11,6 +11,13 @@ FOREACH(flag ${SHARED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +SET (INSTALL_HEADERS + sensor_types.h + sensor_common.h + sensor_deprecated.h + enum_factory.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_CURRENT_SOURCE_DIR} @@ -22,7 +29,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SHARED_PKGS_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) -INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" -) + +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() -- 2.7.4 From 77be7fb50f78d4858acd5c2aad3f32342cea0121 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Sat, 10 Dec 2016 14:57:24 +0900 Subject: [PATCH 06/16] sensord: add pre_start() that should be executed before starting regardless of clients Change-Id: I1cd8a70cdfcb5f838c94a1da7fced99835fbf872 Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 6 ++++++ src/sensor/auto_rotation/auto_rotation_sensor.h | 1 + src/server/sensor_base.cpp | 8 ++++++++ src/server/sensor_base.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index c3bd18e..71d10b4 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -194,6 +194,12 @@ bool auto_rotation_sensor::set_wakeup(int wakeup) return false; } +bool auto_rotation_sensor::pre_start(void) +{ + m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; + return true; +} + bool auto_rotation_sensor::on_start(void) { int length; diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.h b/src/sensor/auto_rotation/auto_rotation_sensor.h index ddd4e3c..d50f728 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.h +++ b/src/sensor/auto_rotation/auto_rotation_sensor.h @@ -56,6 +56,7 @@ private: virtual bool set_batch_latency(unsigned long latency); virtual bool set_wakeup(int wakeup); + virtual bool pre_start(void); virtual bool on_start(void); virtual bool on_stop(void); diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index a5a40bb..24e16a7 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -121,6 +121,9 @@ bool sensor_base::start(void) { AUTOLOCK(m_client_mutex); + if (!pre_start()) + return false; + ++m_client; if (m_client == 1) { @@ -348,6 +351,11 @@ bool sensor_base::set_batch_latency(unsigned long latency) return true; } +bool sensor_base::pre_start(void) +{ + return true; +} + bool sensor_base::on_start(void) { return true; diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 04883d8..89b88ed 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -103,6 +103,7 @@ private: virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); + virtual bool pre_start(void); virtual bool on_start(void); virtual bool on_stop(void); -- 2.7.4 From ef5f8297e1557197bab236094a4882c08b46e1c9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 16:47:53 +0900 Subject: [PATCH 07/16] sensor: fix return value from false to 0 Change-Id: Icb84d1ec8f8e20b29f02dc86807a4fe535c79455 Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 4a97a3c..ca9ec4f 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -324,15 +324,15 @@ ssize_t csocket::send(const void *buffer, size_t size) const if (ret == -1) { _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); - return false; + return 0; } else if (!ret) { _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); - return false; + return 0; } if (!FD_ISSET(m_sock_fd, &write_fds)) { _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); - return false; + return 0; } if (m_sock_type == SOCK_STREAM) -- 2.7.4 From 32032e4e333ebb3cfa5ee53320d0db858fd6f44e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 18:35:45 +0900 Subject: [PATCH 08/16] sensor: enable pedometer sensor - pedometer sensor needs healthinfo privilege Change-Id: I9ac4e2079fd0a6e640c92b63ce13f3c3f1c81ed0 Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 6 ++++++ src/sensor/sensorhub/pedometer_sensor.cpp | 34 +++++++++++++++++++++++++++++++ src/sensor/sensorhub/pedometer_sensor.h | 32 +++++++++++++++++++++++++++++ src/server/sensor_loader.cpp | 6 ++++++ 4 files changed, 78 insertions(+) create mode 100644 src/sensor/sensorhub/pedometer_sensor.cpp create mode 100644 src/sensor/sensorhub/pedometer_sensor.h diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 3ec60fd..272b547 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -10,6 +10,7 @@ SET(LINEAR_ACCEL "ON") SET(RV "ON") SET(ORIENTATION "ON") SET(FACE_DOWN "ON") +SET(SENSORHUB "ON") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared @@ -63,6 +64,11 @@ IF("${FACE_DOWN}" STREQUAL "ON") SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/gesture) SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_FACE_DOWN") ENDIF() +IF("${SENSORHUB}" STREQUAL "ON") + FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/sensorhub/*.cpp) + SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/sensorhub) + SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_SENSORHUB") +ENDIF() MESSAGE("${SENSOR_SRCS}") SET(SENSOR_SRCS ${SENSOR_SRCS} PARENT_SCOPE) diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp new file mode 100644 index 0000000..b9d5c23 --- /dev/null +++ b/src/sensor/sensorhub/pedometer_sensor.cpp @@ -0,0 +1,34 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include "pedometer_sensor.h" + +pedometer_sensor::pedometer_sensor() +{ + set_permission(SENSOR_PERMISSION_BIO); + + _I("pedometer_sensor is created : %#x", this); +} + +pedometer_sensor::~pedometer_sensor() +{ + _I("pedometer_sensor is destroyed : %#x", this); +} diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/sensor/sensorhub/pedometer_sensor.h new file mode 100644 index 0000000..5ae94c2 --- /dev/null +++ b/src/sensor/sensorhub/pedometer_sensor.h @@ -0,0 +1,32 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _PEDOMETER_SENSOR_H_ +#define _PEDOMETER_SENSOR_H_ + +#include + +class pedometer_sensor : public physical_sensor { +public: + pedometer_sensor(); + virtual ~pedometer_sensor(); +}; + +#endif /* _PEDOMETER_SENSOR_H_ */ + diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index c25d07a..614e057 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -53,6 +53,9 @@ #ifdef ENABLE_FACE_DOWN #include #endif +#ifdef ENABLE_SENSORHUB +#include +#endif using std::vector; using std::string; @@ -169,6 +172,9 @@ void sensor_loader::create_sensors(void) create_physical_sensors(HRM_LED_GREEN_SENSOR); create_physical_sensors(HRM_LED_IR_SENSOR); create_physical_sensors(HRM_LED_RED_SENSOR); +#ifdef ENABLE_SENSORHUB + create_physical_sensors(HUMAN_PEDOMETER_SENSOR); +#endif create_physical_sensors(UNKNOWN_SENSOR); -- 2.7.4 From 5abd1da78db60bc3a8674b75db3b38b7e8c2f78a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 19:50:03 +0900 Subject: [PATCH 09/16] sensord: fix incorrect return type - int to size_t Change-Id: Ia1d5b0308e2a9a546c1980d0bb1896a1e4a88204 Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 2 +- src/server/command_worker.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 8d57968..2436ab8 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -91,7 +91,7 @@ void command_worker::init_cmd_handlers(void) m_cmd_handlers[CMD_FLUSH] = &command_worker::cmd_flush; } -int command_worker::create_sensor_raw_list(int client_perms, std::vector &raw_list) +size_t command_worker::create_sensor_raw_list(int client_perms, std::vector &raw_list) { size_t total_raw_data_size = 0; vector sensors; diff --git a/src/server/command_worker.h b/src/server/command_worker.h index 3e1b62c..e6dff1d 100644 --- a/src/server/command_worker.h +++ b/src/server/command_worker.h @@ -45,7 +45,7 @@ private: static sensor_raw_data_map m_sensor_raw_data_map; static void init_cmd_handlers(void); - static int create_sensor_raw_list(int client_perms, std::vector &raw_list); + static size_t create_sensor_raw_list(int client_perms, std::vector &raw_list); static void get_sensor_list(int permissions, cpacket &sensor_list); static bool working(void *ctx); -- 2.7.4 From 4217c2abce8ac882f8f3384c1dca8d97f37d5baf Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 20:04:01 +0900 Subject: [PATCH 10/16] sensord: version up 2.0.9 Change-Id: I4d12ec6c0c12890c58407657dca42621cc128819 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 bb1cd3f..957ebcb 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.8 +Version: 2.0.9 Release: 0 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From e02c195ed699ebf0f0cf4869624a6734029dd762 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 28 Dec 2016 15:38:07 +0900 Subject: [PATCH 11/16] sensord: accumulate pedometer data - accumulated pedometer data should be provided to client Change-Id: Ib9a4bb5325867e1e55f1e8c9b9a32609915dbd08 Signed-off-by: kibak.yoon --- src/sensor/sensorhub/pedometer_sensor.cpp | 60 ++++++++++++++++++++++++++++++- src/sensor/sensorhub/pedometer_sensor.h | 15 ++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp index b9d5c23..c825e41 100644 --- a/src/sensor/sensorhub/pedometer_sensor.cpp +++ b/src/sensor/sensorhub/pedometer_sensor.cpp @@ -21,7 +21,32 @@ #include #include "pedometer_sensor.h" +enum value_index { + IDX_STEPS = 0, + IDX_WALK_STEPS, + IDX_RUN_STEPS, + IDX_DISTANCE, + IDX_CALORIES, + IDX_SPEED, + IDX_FREQUENCY, + IDX_STATE, + IDX_WALK_UP, + IDX_WALK_DOWN, + IDX_RUN_UP, + IDX_RUN_DOWN, + IDX_STATE_EX, +}; + pedometer_sensor::pedometer_sensor() +: m_steps(0) +, m_walk_steps(0) +, m_run_steps(0) +, m_walk_up_steps(0) +, m_walk_down_steps(0) +, m_run_up_steps(0) +, m_run_down_steps(0) +, m_distance(0) +, m_calories(0) { set_permission(SENSOR_PERMISSION_BIO); @@ -30,5 +55,38 @@ pedometer_sensor::pedometer_sensor() pedometer_sensor::~pedometer_sensor() { - _I("pedometer_sensor is destroyed : %#x", this); +} + +bool pedometer_sensor::on_event(const sensor_data_t *data, int data_len, int remains) +{ + if (data_len == sizeof(sensorhub_data_t)) + return false; + + accumulate((sensor_pedometer_data_t*)data); + return true; +} + +void pedometer_sensor::accumulate(sensor_pedometer_data_t *data) +{ + m_steps += data->values[IDX_STEPS]; + m_walk_steps += data->values[IDX_WALK_STEPS]; + m_run_steps += data->values[IDX_RUN_STEPS]; + m_distance += data->values[IDX_DISTANCE]; + m_calories += data->values[IDX_CALORIES]; + + m_walk_up_steps += data->values[IDX_WALK_UP]; + m_walk_down_steps += data->values[IDX_WALK_DOWN]; + m_run_up_steps += data->values[IDX_RUN_UP]; + m_run_down_steps += data->values[IDX_RUN_DOWN]; + + data->values[IDX_STEPS] = m_steps; + data->values[IDX_WALK_STEPS] = m_walk_steps; + data->values[IDX_RUN_STEPS] = m_run_steps; + data->values[IDX_DISTANCE] = m_distance; + data->values[IDX_CALORIES] = m_calories; + + data->values[IDX_WALK_UP] = m_walk_up_steps; + data->values[IDX_WALK_DOWN] = m_walk_down_steps; + data->values[IDX_RUN_UP] = m_run_up_steps; + data->values[IDX_RUN_DOWN] = m_run_down_steps; } diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/sensor/sensorhub/pedometer_sensor.h index 5ae94c2..16f1ac7 100644 --- a/src/sensor/sensorhub/pedometer_sensor.h +++ b/src/sensor/sensorhub/pedometer_sensor.h @@ -26,6 +26,21 @@ class pedometer_sensor : public physical_sensor { public: pedometer_sensor(); virtual ~pedometer_sensor(); + + bool on_event(const sensor_data_t *data, int data_len, int remains); + +private: + unsigned long long m_steps; + unsigned long long m_walk_steps; + unsigned long long m_run_steps; + unsigned long long m_walk_up_steps; + unsigned long long m_walk_down_steps; + unsigned long long m_run_up_steps; + unsigned long long m_run_down_steps; + double m_distance; + double m_calories; + + void accumulate(sensor_pedometer_data_t *data); }; #endif /* _PEDOMETER_SENSOR_H_ */ -- 2.7.4 From e970cca5105790b1c3c70194a23c4c5176bd06a1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 2 Jan 2017 14:39:03 +0900 Subject: [PATCH 12/16] sensord: add dummy api library for tv profile Change-Id: I610a6a2e43e475b20e96432d47b68aebe7785655 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 12 ++- src/client/CMakeLists.txt | 11 ++ src/client/client_dummy.cpp | 204 +++++++++++++++++++++++++++++++++++ src/client/external_client_dummy.cpp | 39 +++++++ 4 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 src/client/client_dummy.cpp create mode 100644 src/client/external_client_dummy.cpp diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 957ebcb..cfd30af 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -20,6 +20,8 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) Requires: libsensord = %{version}-%{release} +%define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}} + %description Sensor daemon @@ -56,9 +58,8 @@ Sensor functional testing %prep %setup -q MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` - cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} \ - -DMAJORVER=${MAJORVER} -DFULLVER=%{version} + -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{BUILD_PROFILE} %build make %{?jobs:-j%jobs} @@ -69,6 +70,7 @@ rm -rf %{buildroot} mkdir -p %{buildroot}%{_unitdir} +%if "%{?BUILD_PROFILE}" != "tv" install -m 0644 %SOURCE1 %{buildroot}%{_unitdir} install -m 0644 %SOURCE2 %{buildroot}%{_unitdir} install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} @@ -76,6 +78,7 @@ install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} %install_service multi-user.target.wants sensord.service %install_service sockets.target.wants sensord_event.socket %install_service sockets.target.wants sensord_command.socket +%endif %post systemctl daemon-reload @@ -93,13 +96,16 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files %manifest packaging/sensord.manifest %{_bindir}/sensord +%license LICENSE.APLv2 + +%if "%{?BUILD_PROFILE}" != "tv" %{_unitdir}/sensord.service %{_unitdir}/sensord_command.socket %{_unitdir}/sensord_event.socket %{_unitdir}/multi-user.target.wants/sensord.service %{_unitdir}/sockets.target.wants/sensord_command.socket %{_unitdir}/sockets.target.wants/sensord_event.socket -%license LICENSE.APLv2 +%endif %files -n libsensord %defattr(-,root,root,-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index f14b841..33ed7fa 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -34,6 +34,17 @@ INCLUDE_DIRECTORIES( ) FILE(GLOB_RECURSE SRCS *.cpp) + +IF("${PROFILE}" STREQUAL "tv") + LIST(REMOVE_ITEM SRCS + "${CMAKE_CURRENT_SOURCE_DIR}/client.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/external_client.cpp") +ELSE() + LIST(REMOVE_ITEM SRCS + "${CMAKE_CURRENT_SOURCE_DIR}/client_dummy.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/external_client_dummy.cpp") +ENDIF() + ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} "sensord-shared") diff --git a/src/client/client_dummy.cpp b/src/client/client_dummy.cpp new file mode 100644 index 0000000..c7732a6 --- /dev/null +++ b/src/client/client_dummy.cpp @@ -0,0 +1,204 @@ +/* + * sensord + * + * Copyright (c) 2013 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 "sensor_internal.h" +#include "sensor_internal_deprecated.h" + +API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count) +{ + return -ENODATA; +} + +API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor) +{ + return -ENODATA; +} + +API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count) +{ + return false; +} + +API sensor_t sensord_get_sensor(sensor_type_t type) +{ + return NULL; +} + +API bool sensord_get_type(sensor_t sensor, sensor_type_t *type) +{ + return false; +} + +API const char* sensord_get_name(sensor_t sensor) +{ + return NULL; +} + +API const char* sensord_get_vendor(sensor_t sensor) +{ + return NULL; +} + +API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege) +{ + return false; +} + +API bool sensord_get_min_range(sensor_t sensor, float *min_range) +{ + return false; +} + +API bool sensord_get_max_range(sensor_t sensor, float *max_range) +{ + return false; +} + +API bool sensord_get_resolution(sensor_t sensor, float *resolution) +{ + return false; +} + +API bool sensord_get_min_interval(sensor_t sensor, int *min_interval) +{ + return false; +} + +API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count) +{ + return false; +} + +API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count) +{ + return false; +} + +API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count) +{ + return false; +} + +API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported) +{ + return false; +} + +API bool sensord_is_wakeup_supported(sensor_t sensor) +{ + return false; +} + +API int sensord_connect(sensor_t sensor) +{ + return OP_ERROR; +} + +API bool sensord_disconnect(int handle) +{ + return false; +} + +API bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_event(int handle, unsigned int event_type) +{ + return false; +} + +API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_accuracy_cb(int handle) +{ + return false; +} + +API bool sensord_start(int handle, int option) +{ + return false; +} + +API bool sensord_stop(int handle) +{ + return false; +} + +API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval) +{ + return false; +} + +API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency) +{ + return false; +} + +API bool sensord_set_option(int handle, int option) +{ + return false; +} + +API int sensord_set_attribute_int(int handle, int attribute, int value) +{ + return OP_ERROR; +} + +API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) +{ + return OP_ERROR; +} + +API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len) +{ + return false; +} + +API bool sensord_send_command(int handle, const char *command, int command_len) +{ + return false; +} + +API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data) +{ + return false; +} + +API bool sensord_flush(int handle) +{ + return false; +} + +API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_set_passive_mode(int handle, bool passive) +{ + return false; +} diff --git a/src/client/external_client_dummy.cpp b/src/client/external_client_dummy.cpp new file mode 100644 index 0000000..8f359d0 --- /dev/null +++ b/src/client/external_client_dummy.cpp @@ -0,0 +1,39 @@ +/* + * sensord + * + * Copyright (c) 2013 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 "sensor_internal.h" +#include "sensor_internal_deprecated.h" + +API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data) +{ + return OP_ERROR; +} + +API bool sensord_external_disconnect(int handle) +{ + return false; +} + +API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt) +{ + return false; +} -- 2.7.4 From 8648c87faa7c03362fb23e01cf34c7556202dc6f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 2 Jan 2017 20:21:17 +0900 Subject: [PATCH 13/16] Remove profile build dependency Instead of the four packages, sensord, libsensord, libsensord-devel, and sensor-hal-devel, the following packages are produced: - sensord : dummy internal API library, which completely disable all sensor listener features - sensord-genuine : working internal API library and the sensor service daemon - sensord-devel : internal API headers and the pc file - sensor-hal-devel : API headers for Sensor HAL Change-Id: Ie3529d6e5eba0554fd86b4d7f95ea9726db00aa4 Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 12 ++- {src/shared => include}/enum_factory.h | 0 {src/shared => include}/sensor_common.h | 0 {src/shared => include}/sensor_deprecated.h | 0 {src/hal => include}/sensor_hal.h | 0 {src/hal => include}/sensor_hal_types.h | 0 {src/client => include}/sensor_internal.h | 0 .../sensor_internal_deprecated.h | 0 {src/shared => include}/sensor_types.h | 2 +- packaging/sensord.spec | 103 ++++++++++++--------- src/client-dummy/CMakeLists.txt | 39 ++++++++ src/client-dummy/client_deprecated.cpp | 84 +++++++++++++++++ src/{client => client-dummy}/client_dummy.cpp | 4 +- .../external_client_dummy.cpp | 4 +- src/{client => client-dummy}/sensor.pc.in | 0 src/client/CMakeLists.txt | 42 +-------- src/hal/CMakeLists.txt | 5 - src/sensorctl/CMakeLists.txt | 2 +- src/shared/CMakeLists.txt | 11 --- src/shared/sensor_types.cpp | 2 +- 20 files changed, 202 insertions(+), 108 deletions(-) rename {src/shared => include}/enum_factory.h (100%) rename {src/shared => include}/sensor_common.h (100%) rename {src/shared => include}/sensor_deprecated.h (100%) rename {src/hal => include}/sensor_hal.h (100%) rename {src/hal => include}/sensor_hal_types.h (100%) rename {src/client => include}/sensor_internal.h (100%) rename {src/client => include}/sensor_internal_deprecated.h (100%) rename {src/shared => include}/sensor_types.h (99%) create mode 100644 src/client-dummy/CMakeLists.txt create mode 100644 src/client-dummy/client_deprecated.cpp rename src/{client => client-dummy}/client_dummy.cpp (98%) rename src/{client => client-dummy}/external_client_dummy.cpp (93%) rename src/{client => client-dummy}/sensor.pc.in (100%) delete mode 100644 src/hal/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index bf31fa9..c5d9d08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensord-main CXX) INCLUDE(GNUInstallDirs) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + # Common Options SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections") @@ -13,8 +15,14 @@ MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") #add_definitions(-Wall -g -D_DEBUG) # Sub-directory +ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/server) ADD_SUBDIRECTORY(src/client) -ADD_SUBDIRECTORY(src/shared) -ADD_SUBDIRECTORY(src/hal) +ADD_SUBDIRECTORY(src/client-dummy) ADD_SUBDIRECTORY(src/sensorctl) + +INSTALL( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor + FILES_MATCHING PATTERN "*.h" +) diff --git a/src/shared/enum_factory.h b/include/enum_factory.h similarity index 100% rename from src/shared/enum_factory.h rename to include/enum_factory.h diff --git a/src/shared/sensor_common.h b/include/sensor_common.h similarity index 100% rename from src/shared/sensor_common.h rename to include/sensor_common.h diff --git a/src/shared/sensor_deprecated.h b/include/sensor_deprecated.h similarity index 100% rename from src/shared/sensor_deprecated.h rename to include/sensor_deprecated.h diff --git a/src/hal/sensor_hal.h b/include/sensor_hal.h similarity index 100% rename from src/hal/sensor_hal.h rename to include/sensor_hal.h diff --git a/src/hal/sensor_hal_types.h b/include/sensor_hal_types.h similarity index 100% rename from src/hal/sensor_hal_types.h rename to include/sensor_hal_types.h diff --git a/src/client/sensor_internal.h b/include/sensor_internal.h similarity index 100% rename from src/client/sensor_internal.h rename to include/sensor_internal.h diff --git a/src/client/sensor_internal_deprecated.h b/include/sensor_internal_deprecated.h similarity index 100% rename from src/client/sensor_internal_deprecated.h rename to include/sensor_internal_deprecated.h diff --git a/src/shared/sensor_types.h b/include/sensor_types.h similarity index 99% rename from src/shared/sensor_types.h rename to include/sensor_types.h index dab36bc..ac1f13a 100644 --- a/src/shared/sensor_types.h +++ b/include/sensor_types.h @@ -20,7 +20,7 @@ #ifndef _SENSOR_TYPES_H_ #define _SENSOR_TYPES_H_ -#include "enum_factory.h" +#include #ifdef __cplusplus extern "C" diff --git a/packaging/sensord.spec b/packaging/sensord.spec index cfd30af..e0e45ec 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,7 +1,7 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.9 -Release: 0 +Version: 2.0.10 +Release: 1 Group: System/Sensor Framework License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -18,28 +18,35 @@ BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) -Requires: libsensord = %{version}-%{release} -%define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}} +Provides: %{name}-profile_tv = %{version}-%{release} +# For backward compatibility +Provides: libsensord = %{version}-%{release} %description Sensor daemon -%package -n libsensord -Summary: Sensord library -Group: System/Libraries +%package genuine +Summary: Genuine Sensor Framework service daemon and shared library Requires: %{name} = %{version}-%{release} - -%description -n libsensord -Sensord library - -%package -n libsensord-devel -Summary: Sensord shared library +Provides: %{name}-profile_mobile = %{version}-%{release} +Provides: %{name}-profile_wearable = %{version}-%{release} +Provides: %{name}-profile_ivi = %{version}-%{release} +Provides: %{name}-profile_common = %{version}-%{release} + +%description genuine +Binary replacement for sensord. +This genuine sensord package contains actually working shared library +of the sensor internal APIs and the sensor service daemon. +If you want to keep using %{name} after uninstalling this, you need to reinstall %{name}. + +%package devel +Summary: Internal Sensor API (Development) Group: System/Development -Requires: libsensord = %{version}-%{release} +Requires: %{name} = %{version}-%{release} -%description -n libsensord-devel -Sensord shared library +%description devel +Internal Sensor API (Development) %package -n sensor-hal-devel Summary: Sensord HAL interface @@ -55,11 +62,20 @@ Group: System/Testing %description -n sensor-test Sensor functional testing +# This dummy package will be removed later. +%package -n libsensord-devel +Summary: Dummy package for backward compatibility +Requires: sensord-devel + +%description -n libsensord-devel +Some packages require libsensord-devel directly, and it causes local gbs build failures +with the old build snapshots. This is a temporal solution to handle such cases. + %prep %setup -q MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} \ - -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{BUILD_PROFILE} + -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %build make %{?jobs:-j%jobs} @@ -70,7 +86,6 @@ rm -rf %{buildroot} mkdir -p %{buildroot}%{_unitdir} -%if "%{?BUILD_PROFILE}" != "tv" install -m 0644 %SOURCE1 %{buildroot}%{_unitdir} install -m 0644 %SOURCE2 %{buildroot}%{_unitdir} install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} @@ -78,56 +93,52 @@ install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} %install_service multi-user.target.wants sensord.service %install_service sockets.target.wants sensord_event.socket %install_service sockets.target.wants sensord_command.socket -%endif + +ln -s libsensor.so.2 %{buildroot}%{_libdir}/libsensor.so.1 %post -systemctl daemon-reload +/sbin/ldconfig -%postun -systemctl daemon-reload +%files +%manifest packaging/sensord.manifest +%{_libdir}/libsensor.so.* +%license LICENSE.APLv2 -%post -n libsensord -ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 +%post genuine +pushd %{_libdir} +ln -sf libsensor-genuine.so.%{version} libsensor.so.%{version} +chsmack -a "_" libsensor.so.%{version} +popd /sbin/ldconfig -%postun -n libsensord -/sbin/ldconfig +%preun genuine +echo "You need to reinstall %{name}, if you need to keep using the APIs after uinstalling this." -%files +%files genuine %manifest packaging/sensord.manifest +%{_libdir}/libsensord-shared.so +%{_libdir}/libsensor-genuine.so.* %{_bindir}/sensord -%license LICENSE.APLv2 - -%if "%{?BUILD_PROFILE}" != "tv" %{_unitdir}/sensord.service %{_unitdir}/sensord_command.socket %{_unitdir}/sensord_event.socket %{_unitdir}/multi-user.target.wants/sensord.service %{_unitdir}/sockets.target.wants/sensord_command.socket %{_unitdir}/sockets.target.wants/sensord_event.socket -%endif - -%files -n libsensord -%defattr(-,root,root,-) -%manifest packaging/libsensord.manifest -%{_libdir}/libsensor.so.* -%{_libdir}/libsensord-shared.so -%license LICENSE.APLv2 -%files -n libsensord-devel -%defattr(-,root,root,-) +%files devel +%manifest packaging/sensord.manifest +%exclude %{_includedir}/sensor/sensor_hal.h %{_includedir}/sensor/*.h %{_libdir}/libsensor.so %{_libdir}/pkgconfig/sensor.pc -%license LICENSE.APLv2 %files -n sensor-hal-devel -%defattr(-,root,root,-) -%{_includedir}/sensor/sensor_hal.h -%{_includedir}/sensor/sensor_hal_types.h -%license LICENSE.APLv2 +%manifest packaging/sensord.manifest +%{_includedir}/sensor/sensor_hal*.h %files -n sensor-test -%defattr(-,root,root,-) %{_bindir}/sensorctl + +%files -n libsensord-devel %license LICENSE.APLv2 diff --git a/src/client-dummy/CMakeLists.txt b/src/client-dummy/CMakeLists.txt new file mode 100644 index 0000000..b0f48c2 --- /dev/null +++ b/src/client-dummy/CMakeLists.txt @@ -0,0 +1,39 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensor CXX) + +SET(DEPENDENTS "glib-2.0 dlog") +SET(VERSION ${FULLVER}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(PC_NAME ${PROJECT_NAME}) +SET(PC_DESCRIPTION "Sensor Client library") +SET(PC_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/sensor") +SET(PC_REQUIRES "${DEPENDENTS}") +SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +SET(PC_LDFLAGS "-l${PROJECT_NAME}") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(DUMMY_PKGS REQUIRED ${DEPENDENTS}) + +FOREACH(flag ${DUMMY_PKGS_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC") + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/src/shared + ${CMAKE_CURRENT_SOURCE_DIR} +) + +FILE(GLOB_RECURSE SRCS *.cpp) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${DUMMY_PKGS_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) + +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 ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/client-dummy/client_deprecated.cpp b/src/client-dummy/client_deprecated.cpp new file mode 100644 index 0000000..e721bed --- /dev/null +++ b/src/client-dummy/client_deprecated.cpp @@ -0,0 +1,84 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#ifndef API +#define API __attribute__((visibility("default"))) +#endif + +API int sf_connect(sensor_type_t sensor_type) +{ + return OP_ERROR; +} + +API int sf_disconnect(int handle) +{ + return OP_ERROR; +} + +API int sf_start(int handle, int option) +{ + return OP_ERROR; +} + +API int sf_stop(int handle) +{ + return OP_ERROR; +} + +API int sf_register_event(int handle, unsigned int event_type, event_condition_t *event_condition, sensor_callback_func_t cb, void *user_data) +{ + return OP_ERROR; +} + +API int sf_unregister_event(int handle, unsigned int event_type) +{ + return OP_ERROR; +} + +API int sf_change_event_condition(int handle, unsigned int event_type, event_condition_t *event_condition) +{ + return OP_ERROR; +} + +API int sf_change_sensor_option(int handle, int option) +{ + return OP_ERROR; +} + +API int sf_send_sensorhub_data(int handle, const char* data, int data_len) +{ + return OP_ERROR; +} + +API int sf_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data) +{ + return OP_ERROR; +} + +API int sf_check_rotation(unsigned long *rotation) +{ + return OP_ERROR; +} + +API int sf_is_sensor_event_available(sensor_type_t sensor_type, unsigned int event_type) +{ + return OP_ERROR; +} diff --git a/src/client/client_dummy.cpp b/src/client-dummy/client_dummy.cpp similarity index 98% rename from src/client/client_dummy.cpp rename to src/client-dummy/client_dummy.cpp index c7732a6..574079a 100644 --- a/src/client/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -20,8 +20,8 @@ #include #include -#include "sensor_internal.h" -#include "sensor_internal_deprecated.h" +#include +#include API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count) { diff --git a/src/client/external_client_dummy.cpp b/src/client-dummy/external_client_dummy.cpp similarity index 93% rename from src/client/external_client_dummy.cpp rename to src/client-dummy/external_client_dummy.cpp index 8f359d0..8eb9221 100644 --- a/src/client/external_client_dummy.cpp +++ b/src/client-dummy/external_client_dummy.cpp @@ -20,8 +20,8 @@ #include #include -#include "sensor_internal.h" -#include "sensor_internal_deprecated.h" +#include +#include API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data) { diff --git a/src/client/sensor.pc.in b/src/client-dummy/sensor.pc.in similarity index 100% rename from src/client/sensor.pc.in rename to src/client-dummy/sensor.pc.in diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 33ed7fa..9131d8d 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,60 +1,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(sensor CXX) +PROJECT(sensor-genuine CXX) SET(DEPENDENTS "vconf glib-2.0 gio-2.0 dlog") -SET(VERSION ${FULLVER}) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin") - -SET(PC_NAME ${PROJECT_NAME}) -SET(PC_DESCRIPTION "Sensor Client library") -SET(PC_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/sensor") -SET(PC_REQUIRES "${DEPENDENTS}") -SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -SET(PC_LDFLAGS "-l${PROJECT_NAME}") INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(PKGS REQUIRED ${DEPENDENTS}) +PKG_CHECK_MODULES(CLIENT_PKGS REQUIRED ${DEPENDENTS}) -FOREACH(flag ${PKGS_CFLAGS}) +FOREACH(flag ${CLIENT_PKGS_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC") -SET (INSTALL_HEADERS - sensor_internal.h - sensor_internal_deprecated.h -) - INCLUDE_DIRECTORIES( - ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_SOURCE_DIR}/src/shared ${CMAKE_CURRENT_SOURCE_DIR} ) FILE(GLOB_RECURSE SRCS *.cpp) -IF("${PROFILE}" STREQUAL "tv") - LIST(REMOVE_ITEM SRCS - "${CMAKE_CURRENT_SOURCE_DIR}/client.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/external_client.cpp") -ELSE() - LIST(REMOVE_ITEM SRCS - "${CMAKE_CURRENT_SOURCE_DIR}/client_dummy.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/external_client_dummy.cpp") -ENDIF() - ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} "sensord-shared") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CLIENT_PKGS_LDFLAGS} "sensord-shared") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) -FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) -ENDFOREACH() -INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) - +INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP) diff --git a/src/hal/CMakeLists.txt b/src/hal/CMakeLists.txt deleted file mode 100644 index 7119639..0000000 --- a/src/hal/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(sensor-hal CXX) - -INSTALL(FILES sensor_hal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) -INSTALL(FILES sensor_hal_types.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt index 1accf2a..2b9c675 100644 --- a/src/sensorctl/CMakeLists.txt +++ b/src/sensorctl/CMakeLists.txt @@ -25,4 +25,4 @@ FILE(GLOB_RECURSE SRCS *.cpp) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} sensor) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 5d094ec..69b88ed 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -11,13 +11,6 @@ FOREACH(flag ${SHARED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -SET (INSTALL_HEADERS - sensor_types.h - sensor_common.h - sensor_deprecated.h - enum_factory.h -) - INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_CURRENT_SOURCE_DIR} @@ -29,7 +22,3 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SHARED_PKGS_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) -ENDFOREACH() diff --git a/src/shared/sensor_types.cpp b/src/shared/sensor_types.cpp index 084e6b8..037ddc9 100644 --- a/src/shared/sensor_types.cpp +++ b/src/shared/sensor_types.cpp @@ -17,6 +17,6 @@ * */ -#include "sensor_types.h" +#include DECLARE_SENSOR_ENUM_UTIL(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From 12aa46db5eb55230e7bc2fc75817dd5984f14a1f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 3 Jan 2017 16:32:08 +0900 Subject: [PATCH 14/16] Add vconf & gio-2.0 to the package config This is for backward compatibility. A package uses vconf, which is indirectly required by sensord-devel. Change-Id: I45f04a02f72323637bb026f5449cf2afc147e30d Signed-off-by: Mu-Woong Lee --- src/client-dummy/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client-dummy/CMakeLists.txt b/src/client-dummy/CMakeLists.txt index b0f48c2..626d61e 100644 --- a/src/client-dummy/CMakeLists.txt +++ b/src/client-dummy/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensor CXX) -SET(DEPENDENTS "glib-2.0 dlog") +SET(DEPENDENTS "glib-2.0 gio-2.0 dlog vconf") SET(VERSION ${FULLVER}) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -- 2.7.4 From 0e23fe9a349204d683c182c8af87376fb40dee36 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 3 Jan 2017 18:42:50 +0900 Subject: [PATCH 15/16] Add dummy libsensord package to fix build unresolvable issues Change-Id: I33c0c0c4ce4cf739587ca7363970a376e360b4bf Signed-off-by: Mu-Woong Lee --- packaging/libsensord.manifest | 5 ----- packaging/sensord.spec | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) delete mode 100644 packaging/libsensord.manifest diff --git a/packaging/libsensord.manifest b/packaging/libsensord.manifest deleted file mode 100644 index 75b0fa5..0000000 --- a/packaging/libsensord.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/sensord.spec b/packaging/sensord.spec index e0e45ec..213cb52 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -21,7 +21,6 @@ BuildRequires: pkgconfig(cynara-session) Provides: %{name}-profile_tv = %{version}-%{release} # For backward compatibility -Provides: libsensord = %{version}-%{release} %description Sensor daemon @@ -62,7 +61,15 @@ Group: System/Testing %description -n sensor-test Sensor functional testing -# This dummy package will be removed later. +# These dummy packages will be removed later. +%package -n libsensord +Summary: Dummy package for backward compatibility +Requires: sensord + +%description -n libsensord +Without this dummy package, obs may reports several 'unresolvable' issues. +This is a temporal solution to handle such cases. + %package -n libsensord-devel Summary: Dummy package for backward compatibility Requires: sensord-devel @@ -140,5 +147,8 @@ echo "You need to reinstall %{name}, if you need to keep using the APIs after ui %files -n sensor-test %{_bindir}/sensorctl +%files -n libsensord +%license LICENSE.APLv2 + %files -n libsensord-devel %license LICENSE.APLv2 -- 2.7.4 From a10b751195b8114c7b5600240bb816df8438a0cf Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 19 Dec 2016 22:52:37 +0900 Subject: [PATCH 16/16] sensord: refactoring sensorctl for testing modules - To refactoring, there was the following changes. * add test_bench to create testcases easily * clean tester/injector/info/loopback files - testing command examples $ sensorctl test accelerometer /* test accelerometer sensor manually */ $ sensorctl test auto all /* test all testcases automatically with full-log */ $ sensorctl test auto socket 0 /* test socket module automatically without full-log */ $ sensorctl info all $ sensorctl inject Change-Id: Ie888c81f85d282eab77a8e1227d26710a85e9c61 Signed-off-by: kibak.yoon --- include/sensor_hal_types.h | 1 + src/sensorctl/CMakeLists.txt | 9 +- src/sensorctl/dbus_util.cpp | 12 +- src/sensorctl/dbus_util.h | 6 +- src/sensorctl/{info_manager.cpp => info.cpp} | 53 +++-- src/sensorctl/{info_manager.h => info.h} | 8 +- src/sensorctl/injector.cpp | 108 ++++++++++ src/sensorctl/injector.h | 51 ++++- src/sensorctl/injector_context_orientation.cpp | 37 ++-- src/sensorctl/injector_manager.cpp | 130 ------------ src/sensorctl/injector_manager.h | 58 ------ src/sensorctl/injector_wrist_up_conf.cpp | 59 ------ ...wrist_up_algo.cpp => injector_wristup_algo.cpp} | 45 ++-- src/sensorctl/injector_wristup_conf.cpp | 65 ++++++ src/sensorctl/log.h | 85 ++++++++ .../{loopback_manager.cpp => loopback.cpp} | 19 +- src/sensorctl/{loopback_manager.h => loopback.h} | 4 +- .../{injector_wrist_up_conf.h => macro.h} | 17 +- src/sensorctl/mainloop.cpp | 69 +++++++ .../{injector_context_orientation.h => mainloop.h} | 20 +- src/sensorctl/sensor_adapter.cpp | 160 +++++++++++++++ src/sensorctl/sensor_adapter.h | 62 ++++++ src/sensorctl/sensor_manager.cpp | 133 ++++++------ src/sensorctl/sensor_manager.h | 15 +- src/sensorctl/sensorctl.cpp | 78 +++---- src/sensorctl/sensorctl_log.h | 49 ----- src/sensorctl/test_bench.cpp | 226 +++++++++++++++++++++ src/sensorctl/test_bench.h | 201 ++++++++++++++++++ src/sensorctl/testcase/accelerometer.cpp | 170 ++++++++++++++++ src/sensorctl/testcase/sensor_basic.cpp | 168 +++++++++++++++ .../sensor_interval.cpp} | 21 +- src/sensorctl/tester.cpp | 188 +++++++++++++++++ src/sensorctl/tester.h | 25 ++- src/sensorctl/tester_manager.cpp | 79 ------- src/sensorctl/tester_sensor.cpp | 151 -------------- src/sensorctl/tester_sensor.h | 34 ---- src/sensorctl/util.cpp | 59 ++++++ src/sensorctl/{tester_manager.h => util.h} | 16 +- 38 files changed, 1885 insertions(+), 806 deletions(-) rename src/sensorctl/{info_manager.cpp => info.cpp} (63%) rename src/sensorctl/{info_manager.h => info.h} (81%) create mode 100644 src/sensorctl/injector.cpp delete mode 100644 src/sensorctl/injector_manager.cpp delete mode 100644 src/sensorctl/injector_manager.h delete mode 100644 src/sensorctl/injector_wrist_up_conf.cpp rename src/sensorctl/{injector_wrist_up_algo.cpp => injector_wristup_algo.cpp} (59%) create mode 100644 src/sensorctl/injector_wristup_conf.cpp create mode 100644 src/sensorctl/log.h rename src/sensorctl/{loopback_manager.cpp => loopback.cpp} (83%) rename src/sensorctl/{loopback_manager.h => loopback.h} (91%) rename src/sensorctl/{injector_wrist_up_conf.h => macro.h} (64%) create mode 100644 src/sensorctl/mainloop.cpp rename src/sensorctl/{injector_context_orientation.h => mainloop.h} (70%) create mode 100644 src/sensorctl/sensor_adapter.cpp create mode 100644 src/sensorctl/sensor_adapter.h delete mode 100644 src/sensorctl/sensorctl_log.h create mode 100644 src/sensorctl/test_bench.cpp create mode 100644 src/sensorctl/test_bench.h create mode 100644 src/sensorctl/testcase/accelerometer.cpp create mode 100644 src/sensorctl/testcase/sensor_basic.cpp rename src/sensorctl/{injector_wrist_up_algo.h => testcase/sensor_interval.cpp} (62%) create mode 100644 src/sensorctl/tester.cpp delete mode 100644 src/sensorctl/tester_manager.cpp delete mode 100644 src/sensorctl/tester_sensor.cpp delete mode 100644 src/sensorctl/tester_sensor.h create mode 100644 src/sensorctl/util.cpp rename src/sensorctl/{tester_manager.h => util.h} (67%) diff --git a/include/sensor_hal_types.h b/include/sensor_hal_types.h index 6beb935..6ad991d 100644 --- a/include/sensor_hal_types.h +++ b/include/sensor_hal_types.h @@ -223,6 +223,7 @@ typedef struct { #define CONVERT_TYPE_ATTR(type, index) ((type) << 8 | 0x80 | (index)) enum sensor_attribute { + SENSOR_ATTR_ACCELEROMETER_INJECTION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACCELEROMETER, 0xFF), SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), SENSOR_ATTR_PEDOMETER_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1), diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt index 2b9c675..7b44303 100644 --- a/src/sensorctl/CMakeLists.txt +++ b/src/sensorctl/CMakeLists.txt @@ -2,19 +2,20 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensorctl CXX) INCLUDE(GNUInstallDirs) -SET(DEPS glib-2.0 gio-2.0) +SET(DEPENDENTS glib-2.0 gio-2.0) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED ${DEPS}) +PKG_CHECK_MODULES(PKGS REQUIRED ${DEPENDENTS}) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src/ ${CMAKE_SOURCE_DIR}/src/hal/ ${CMAKE_SOURCE_DIR}/src/client/ ${CMAKE_SOURCE_DIR}/src/shared/ ) -FOREACH(flag ${pkgs_CFLAGS}) +FOREACH(flag ${PKGS_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") ENDFOREACH(flag) @@ -24,5 +25,5 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") FILE(GLOB_RECURSE SRCS *.cpp) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} sensor) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} sensor sensord-shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/sensorctl/dbus_util.cpp b/src/sensorctl/dbus_util.cpp index 886872e..a18d8c0 100644 --- a/src/sensorctl/dbus_util.cpp +++ b/src/sensorctl/dbus_util.cpp @@ -17,10 +17,13 @@ * */ +#include "dbus_util.h" + #include #include #include -#include + +#include "log.h" static GDBusConnection *connection; @@ -39,7 +42,7 @@ bool dbus_init(void) gaddr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!gaddr) { - PRINT("ERROR: Failed to get dbus address : %s", error->message); + _E("Failed to get dbus address : %s\n", error->message); g_error_free(error); error = NULL; return false; @@ -52,13 +55,13 @@ bool dbus_init(void) g_free(gaddr); if (!connection) { - PRINT("ERROR: Failed to get dbus connection : %s", error->message); + _E("Failed to get dbus connection : %s\n", error->message); g_error_free(error); error = NULL; return false; } - PRINT("G-DBUS connected[%s]\n", + _I("G-DBUS connected[%s]\n", g_dbus_connection_get_unique_name(connection)); return true; } @@ -104,4 +107,3 @@ GVariant *make_variant_int(int count, char *options[]) return NULL; } - diff --git a/src/sensorctl/dbus_util.h b/src/sensorctl/dbus_util.h index a51d903..e03166a 100644 --- a/src/sensorctl/dbus_util.h +++ b/src/sensorctl/dbus_util.h @@ -17,11 +17,15 @@ * */ -#pragma once // _DBUS_UTIL_H_ +#pragma once /* __DBUS_UTIL_H__ */ #include #include +#define SENSORD_BUS_NAME "org.tizen.system.sensord" +#define SENSORD_OBJ_PATH "/Org/Tizen/System/SensorD" +#define SENSORD_INTERFACE_NAME "org.tizen.system.sensord" + bool dbus_init(void); bool dbus_fini(void); bool dbus_emit_signal(gchar *dest_bus_name, gchar *object_path, diff --git a/src/sensorctl/info_manager.cpp b/src/sensorctl/info.cpp similarity index 63% rename from src/sensorctl/info_manager.cpp rename to src/sensorctl/info.cpp index 676bc40..6597230 100644 --- a/src/sensorctl/info_manager.cpp +++ b/src/sensorctl/info.cpp @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,37 +17,38 @@ * */ +#include "info.h" + #include -#include #include #include -#include -#include "info_manager.h" -bool info_manager::process(int argc, char *argv[]) +#include "log.h" + +#define INFO_ARGC 3 /* e.g. {sensorctl, info, accelerometer} */ + +bool info_manager::run(int argc, char *argv[]) { sensor_type_t type; + sensor_t *sensors; + int count; - if (argc == 2) { + if (argc < INFO_ARGC) { usage(); return false; } type = get_sensor_type(argv[2]); - if (type == UNKNOWN_SENSOR) - return false; - - sensor_t *sensors; - int count; + RETVM_IF(type == UNKNOWN_SENSOR, false, "Wrong argument : %s\n", argv[2]); sensord_get_sensor_list(type, &sensors, &count); - sensor_info(sensors, count); + show_info(sensors, count); - free(sensors); + delete sensors; return true; } -void info_manager::sensor_info(sensor_t *sensors, int count) +void info_manager::show_info(sensor_t *sensors, int count) { sensor_t sensor; char *vendor; @@ -71,24 +72,22 @@ void info_manager::sensor_info(sensor_t *sensors, int count) sensord_get_fifo_count(sensor, &fifo_count); sensord_get_max_batch_count(sensor, &max_batch_count); - PRINT("-------sensor[%d] information-------\n", i); - PRINT("vendor : %s\n", vendor); - PRINT("name : %s\n", name); - PRINT("min_range : %f\n", min_range); - PRINT("max_range : %f\n", max_range); - PRINT("resolution : %f\n", resolution); - PRINT("min_interval : %d\n", min_interval); - PRINT("fifo_count : %d\n", fifo_count); - PRINT("max_batch_count : %d\n", max_batch_count); - PRINT("--------------------------------\n"); + _N("-------sensor[%d] information-------\n", i); + _N("vendor : %s\n", vendor); + _N("name : %s\n", name); + _N("min_range : %f\n", min_range); + _N("max_range : %f\n", max_range); + _N("resolution : %f\n", resolution); + _N("min_interval : %d\n", min_interval); + _N("fifo_count : %d\n", fifo_count); + _N("max_batch_count : %d\n", max_batch_count); + _N("--------------------------------\n"); } } void info_manager::usage(void) { - PRINT("usage: sensorctl info \n"); - PRINT("\n"); + _N("usage: sensorctl info \n\n"); usage_sensors(); } - diff --git a/src/sensorctl/info_manager.h b/src/sensorctl/info.h similarity index 81% rename from src/sensorctl/info_manager.h rename to src/sensorctl/info.h index b71dfc0..b85b6ca 100644 --- a/src/sensorctl/info_manager.h +++ b/src/sensorctl/info.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,7 +17,7 @@ * */ -#pragma once // _INFO_MANAGER_H_ +#pragma once /* __INFO_MANAGER_H__ */ #include #include "sensor_manager.h" @@ -27,8 +27,8 @@ public: info_manager() {} virtual ~info_manager() {} - bool process(int argc, char *argv[]); + bool run(int argc, char *argv[]); private: - void sensor_info(sensor_t *sensors, int count); + void show_info(sensor_t *sensors, int count); void usage(void); }; diff --git a/src/sensorctl/injector.cpp b/src/sensorctl/injector.cpp new file mode 100644 index 0000000..a4e7b75 --- /dev/null +++ b/src/sensorctl/injector.cpp @@ -0,0 +1,108 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "injector.h" + +#include +#include +#include + +#include "log.h" +#include "dbus_util.h" + +std::vector injector_manager::injectors; + +injector::injector(sensor_type_t sensor_type, const char *event_name) +: m_type(sensor_type) +, m_name(event_name) +{ + injector_manager::register_injector(this); +} + +injector_manager::injector_manager() +{ + if (!dbus_init()) { + _E("Failed to init dbus"); + throw; + } +} + +injector_manager::~injector_manager() +{ + dbus_fini(); +} + +void injector_manager::register_injector(injector *inject) +{ + injectors.push_back(inject); +} + +bool injector_manager::run(int argc, char *argv[]) +{ + sensor_type_t type; + bool result; + + if (argc < INJECTOR_ARGC) { + usage(); + return false; + } + + /* 1. get sensor type */ + type = get_sensor_type(argv[2]); + RETVM_IF(type == UNKNOWN_SENSOR, false, "Invalid argument : %s\n", argv[2]); + + /* 2. set up injector */ + injector *_injector = get_injector(type, argv[3]); + RETVM_IF(!_injector, false, "Cannot find matched injector\n"); + + /* 3. set up injector */ + result = _injector->setup(); + RETVM_IF(!result, false, "Failed to init injector\n"); + + /* 4. inject event */ + result = _injector->inject(argc, argv); + RETVM_IF(!result, false, "Failed to run injector\n"); + + /* 5. tear down injector */ + result = _injector->teardown(); + RETVM_IF(!result, false, "Failed to tear down injector\n"); + + return true; +} + +injector *injector_manager::get_injector(sensor_type_t type, const char *name) +{ + int count; + + count = injectors.size(); + + for (int i = 0; i < count; ++i) { + if (type == injectors[i]->type() && + (injectors[i]->name() == name)) + return injectors[i]; + } + return NULL; +} + +void injector_manager::usage(void) +{ + _N("usage: sensorctl inject [] []\n\n"); + + usage_sensors(); +} diff --git a/src/sensorctl/injector.h b/src/sensorctl/injector.h index f9e8b40..ca942fc 100644 --- a/src/sensorctl/injector.h +++ b/src/sensorctl/injector.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,16 +17,51 @@ * */ -#pragma once // _INJECTOR_H_ +#pragma once /* __INJECTOR_H__ */ #include +#include +#include -#define SENSORD_BUS_NAME "org.tizen.system.sensord" -#define SENSORD_OBJ_PATH "/Org/Tizen/System/SensorD" -#define SENSORD_INTERFACE_NAME "org.tizen.system.sensord" +#include "sensor_manager.h" + +#define NAME_MAX_TEST 32 +#define INJECTOR_ARGC 4 /* e.g. {sensorctl, inject, wristup, conf} */ + +#define REGISTER_INJECTOR(sensor_type, event_name, injector_type) \ +static injector_type injector(sensor_type, event_name); + +class injector { +public: + injector(sensor_type_t sensor_type, const char *event_name); + virtual ~injector() {} + + virtual bool setup(void) { return true; } + virtual bool teardown(void) { return true; } + + const std::string& name() const { return m_name; } + const sensor_type_t type() const { return m_type; } + + virtual bool inject(int argc, char *argv[]) = 0; + +private: + sensor_type_t m_type; + std::string m_name; +}; + +class injector_manager : public sensor_manager { +public: + static void register_injector(injector *injector); -class injector_interface { public: - virtual bool init(void) { return true; } - virtual bool inject(int option_count, char *options[]) = 0; + injector_manager(); + virtual ~injector_manager(); + + bool run(int argc, char *argv[]); + +private: + static std::vector injectors; + + injector *get_injector(sensor_type_t type, const char *name); + void usage(void); }; diff --git a/src/sensorctl/injector_context_orientation.cpp b/src/sensorctl/injector_context_orientation.cpp index 863b901..7219ea9 100644 --- a/src/sensorctl/injector_context_orientation.cpp +++ b/src/sensorctl/injector_context_orientation.cpp @@ -20,26 +20,33 @@ #include #include #include -#include +#include "log.h" #include "dbus_util.h" -#include "injector_manager.h" -#include "injector_context_orientation.h" +#include "injector.h" #define CONTEXT_ORIENTATION_SIGNAL "orientation" -bool injector_context_orientation::inject(int option_count, char *options[]) +class injector_context_orientation : public injector { +public: + injector_context_orientation(sensor_type_t sensor_type, const char *event_name); + virtual ~injector_context_orientation() {} + + bool inject(int argc, char *argv[]); +}; + +injector_context_orientation::injector_context_orientation(sensor_type_t sensor_type, const char *event_name) +: injector(sensor_type, event_name) { - GVariant *variant; +} - if (option_count == 0) { - _E("ERROR: invalid argument\n"); - return false; - } +bool injector_context_orientation::inject(int argc, char *argv[]) +{ + GVariant *variant; - variant = make_variant_int(option_count, options); + RETVM_IF(argc <= INJECTOR_ARGC, false, "Invalid argument\n"); - if (variant == NULL) - return false; + variant = make_variant_int(argc - INJECTOR_ARGC, &argv[INJECTOR_ARGC]); + RETVM_IF(!variant, false, "Cannot make variant\n"); dbus_emit_signal(NULL, (gchar *)SENSORD_OBJ_PATH, @@ -48,9 +55,9 @@ bool injector_context_orientation::inject(int option_count, char *options[]) variant, NULL); - PRINT("set options to context: \n"); - for (int i = 0; i < option_count; ++i) - PRINT("option %d: %s\n", i, options[i]); + _I("Set up options to wristup:"); + for (int i = 0; i < argc - INJECTOR_ARGC; ++i) + _I("option %d: %s\n", i, argv[i]); return true; } diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp deleted file mode 100644 index 8aeebb0..0000000 --- a/src/sensorctl/injector_manager.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * sensorctl - * - * 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 "dbus_util.h" -#include "injector.h" -#include "injector_manager.h" - -#define NAME_MAX_TEST 32 -#define ARGC_BASE 4 /* e.g. {sensorctl, inject, wristup, conf} */ - -static std::vector injector_infos; - -injector_manager::injector_manager() -{ - if (!dbus_init()) { - _E("Failed to init dbus"); - throw; - } -} - -injector_manager::~injector_manager() -{ - dbus_fini(); -} - -bool injector_manager::register_injector(injector_info info) -{ - injector_infos.push_back(info); - return true; -} - -injector_interface *injector_manager::get_injector(sensor_type_t type, const char *name) -{ - int injector_count; - injector_count = injector_infos.size(); - - for (int i = 0; i < injector_count; ++i) { - if (type == injector_infos[i].type && - !strcmp(injector_infos[i].name, name)) - return injector_infos[i].injector; - } - return NULL; -} - -bool injector_manager::process(int argc, char *argv[]) -{ - int option_count; - char *options[8]; - bool result; - sensor_type_t type; - char *event_name; - int i; - - if (argc < 4) { - usage(); - return false; - } - - /* 1. get sensor type */ - type = get_sensor_type(argv[2]); - if (type == UNKNOWN_SENSOR) { - _E("ERROR : failed to process injector\n"); - return false; - } - - /* 2. set up injector */ - event_name = argv[3]; - - injector_interface *injector = get_injector(type, event_name); - if (injector == NULL) { - _E("ERROR: cannot find matched injector\n"); - return false; - } - - /* 3. init injector */ - result = injector->init(); - if (!result) { - _E("ERROR: failed to init injector\n"); - return false; - } - - /* 4. inject event with options */ - option_count = argc - ARGC_BASE; - for (i = 0; i < option_count; ++i) { - options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); - } - - result = injector->inject(option_count, options); - if (!result) { - _E("ERROR : failed to process injector\n"); - for (i = 0; i < option_count; ++i) - delete [] options[i]; - - return false; - } - - for (i = 0; i < option_count; ++i) - delete [] options[i]; - - return true; -} - -void injector_manager::usage(void) -{ - PRINT("usage: sensorctl inject [] []\n\n"); - - usage_sensors(); -} - diff --git a/src/sensorctl/injector_manager.h b/src/sensorctl/injector_manager.h deleted file mode 100644 index 380c486..0000000 --- a/src/sensorctl/injector_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * sensorctl - * - * 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. - * - */ - -#pragma once // _INJECT_MANAGER_H_ - -#include -#include -#include "injector.h" -#include "sensor_manager.h" - -#define REGISTER_INJECTOR(sensor_type, sensor_name, injector_type) \ -static void __attribute__((constructor)) reg_injector(void) \ -{ \ - struct injector_info info; \ - info.type = (sensor_type); \ - info.name = (sensor_name); \ - info.injector = new(std::nothrow) (injector_type)(); \ - if (!info.injector) { \ - _E("ERROR: Failed to allocate memory(%s)", #injector_type); \ - return; \ - } \ - injector_manager::register_injector(info); \ -} - -struct injector_info { - sensor_type_t type; - const char *name; - injector_interface *injector; -}; - -class injector_manager : public sensor_manager { -public: - injector_manager(); - virtual ~injector_manager(); - - bool process(int argc, char *argv[]); - - static bool register_injector(injector_info info); -private: - injector_interface *get_injector(sensor_type_t type, const char *name); - void usage(void); -}; diff --git a/src/sensorctl/injector_wrist_up_conf.cpp b/src/sensorctl/injector_wrist_up_conf.cpp deleted file mode 100644 index 11e7a2f..0000000 --- a/src/sensorctl/injector_wrist_up_conf.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * sensorctl - * - * 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 "dbus_util.h" -#include "injector_manager.h" -#include "injector_wrist_up_conf.h" - -#define WRIST_UP_CONF_SIGNAL "conf" - -bool injector_wrist_up_conf::inject(int option_count, char *options[]) -{ - GVariant *variant; - - if (option_count == 0) { - _E("ERROR: invalid argument\n"); - return false; - } - - variant = make_variant_int(option_count, options); - - if (variant == NULL) - return false; - - dbus_emit_signal(NULL, - (gchar *)SENSORD_OBJ_PATH, - (gchar *)SENSORD_INTERFACE_NAME, - (gchar *)WRIST_UP_CONF_SIGNAL, - variant, - NULL); - - PRINT("set options to wristup: \n"); - for (int i = 0; i < option_count; ++i) - PRINT("option %d: %s\n", i, options[i]); - - return true; -} - -REGISTER_INJECTOR(MOTION_SENSOR, "conf", injector_wrist_up_conf) - diff --git a/src/sensorctl/injector_wrist_up_algo.cpp b/src/sensorctl/injector_wristup_algo.cpp similarity index 59% rename from src/sensorctl/injector_wrist_up_algo.cpp rename to src/sensorctl/injector_wristup_algo.cpp index 766e6ec..2585bd8 100644 --- a/src/sensorctl/injector_wrist_up_algo.cpp +++ b/src/sensorctl/injector_wristup_algo.cpp @@ -23,18 +23,32 @@ #include #include #include -#include + +#include "log.h" #include "dbus_util.h" -#include "injector_manager.h" -#include "injector_wrist_up_algo.h" +#include "injector.h" -#define WRIST_UP_ALGO_SIGNAL "algo" +#define WRISTUP_ALGO_SIGNAL "algo" #define OPTION_INDEX 0 typedef std::map option_map_t; static option_map_t option_map; -bool injector_wrist_up_algo::init(void) +class injector_wristup_algo : public injector { +public: + injector_wristup_algo(sensor_type_t sensor_type, const char *event_name); + virtual ~injector_wristup_algo() {} + + bool setup(void); + bool inject(int argc, char *argv[]); +}; + +injector_wristup_algo::injector_wristup_algo(sensor_type_t sensor_type, const char *event_name) +: injector(sensor_type, event_name) +{ +} + +bool injector_wristup_algo::setup(void) { option_map.insert(option_map_t::value_type("auto", 0)); option_map.insert(option_map_t::value_type("green", 1)); @@ -44,34 +58,27 @@ bool injector_wrist_up_algo::init(void) return true; } -bool injector_wrist_up_algo::inject(int option_count, char *options[]) +bool injector_wristup_algo::inject(int argc, char *argv[]) { int option; - if (option_count == 0) { - _E("ERROR: invalid argument\n"); - return false; - } + RETVM_IF(argc == 0, false, "Invalid argument\n"); option_map_t::iterator it; - it = option_map.find(options[OPTION_INDEX]); - - if (it == option_map.end()) { - _E("ERROR: no matched-option: %s\n", options[OPTION_INDEX]); - return false; - } + it = option_map.find(argv[INJECTOR_ARGC]); + RETVM_IF(it == option_map.end(), false, "No matched option: %s\n", argv[INJECTOR_ARGC]); option = it->second; dbus_emit_signal(NULL, (gchar *)SENSORD_OBJ_PATH, (gchar *)SENSORD_INTERFACE_NAME, - (gchar *)WRIST_UP_ALGO_SIGNAL, + (gchar *)WRISTUP_ALGO_SIGNAL, g_variant_new("(i)", option), NULL); - _I("set [%s] mode to wristup (%d)", options[OPTION_INDEX], option); + _I("Set up [%s] mode to wristup (%d)\n", argv[INJECTOR_ARGC], option); return true; } -REGISTER_INJECTOR(MOTION_SENSOR, "algo", injector_wrist_up_algo) +REGISTER_INJECTOR(GESTURE_WRIST_UP_SENSOR, WRISTUP_ALGO_SIGNAL, injector_wristup_algo) diff --git a/src/sensorctl/injector_wristup_conf.cpp b/src/sensorctl/injector_wristup_conf.cpp new file mode 100644 index 0000000..5d356c5 --- /dev/null +++ b/src/sensorctl/injector_wristup_conf.cpp @@ -0,0 +1,65 @@ +/* + * sensorctl + * + * 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 "log.h" +#include "dbus_util.h" +#include "injector.h" + +#define WRISTUP_CONF_SIGNAL "conf" + +class injector_wristup_conf : public injector { +public: + injector_wristup_conf(sensor_type_t sensor_type, const char *event_name); + virtual ~injector_wristup_conf() {} + + bool inject(int argc, char *argv[]); +}; + +injector_wristup_conf::injector_wristup_conf(sensor_type_t sensor_type, const char *event_name) +: injector(sensor_type, event_name) +{ +} + +bool injector_wristup_conf::inject(int argc, char *argv[]) +{ + GVariant *variant; + + RETVM_IF(argc <= INJECTOR_ARGC, false, "Invalid argument\n"); + + variant = make_variant_int(argc - INJECTOR_ARGC, &argv[INJECTOR_ARGC]); + RETVM_IF(!variant, false, "Cannot make variant\n"); + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)WRISTUP_CONF_SIGNAL, + variant, + NULL); + + _I("Set up options to wristup:"); + for (int i = 0; i < argc - INJECTOR_ARGC; ++i) + _I("option %d: %s\n", i, argv[i]); + + return true; +} + +REGISTER_INJECTOR(GESTURE_WRIST_UP_SENSOR, WRISTUP_CONF_SIGNAL, injector_wristup_conf) diff --git a/src/sensorctl/log.h b/src/sensorctl/log.h new file mode 100644 index 0000000..00cefbd --- /dev/null +++ b/src/sensorctl/log.h @@ -0,0 +1,85 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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. + * + */ + +#pragma once /* __LOG_H__ */ + +#include +#include + +#define _NRM "\x1B[0m" +#define _RED "\x1B[31m" +#define _GRN "\x1B[32m" +#define _YEL "\x1B[33m" +#define _BLU "\x1B[34m" +#define _MAG "\x1B[35m" +#define _CYN "\x1B[36m" +#define _WHT "\x1B[37m" +#define _RST "\033[0m" + +#define _N(fmt, args...) \ +do { \ + g_print(fmt, ##args); \ +} while (0) + +#define _E(fmt, args...) \ +do { \ + g_print("\x1B[31m" fmt "\033[0m", ##args); \ +} while (0) + +#define _I(fmt, args...) \ +do { \ + g_print("\x1B[32m" fmt "\033[0m", ##args); \ +} while (0) + +#define WARN_IF(expr, fmt, arg...) \ +do { \ + if(expr) { \ + _E(fmt, ##arg); \ + } \ +} while (0) + +#define RET_IF(expr) \ +do { \ + if(expr) { \ + return; \ + } \ +} while (0) + +#define RETV_IF(expr, val) \ +do { \ + if(expr) { \ + return (val); \ + } \ +} while (0) + +#define RETM_IF(expr, fmt, arg...) \ +do { \ + if(expr) { \ + _E(fmt, ##arg); \ + return; \ + } \ +} while (0) + +#define RETVM_IF(expr, val, fmt, arg...) \ +do { \ + if(expr) { \ + _E(fmt, ##arg); \ + return (val); \ + } \ +} while (0) diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback.cpp similarity index 83% rename from src/sensorctl/loopback_manager.cpp rename to src/sensorctl/loopback.cpp index b7908b6..ee177b8 100644 --- a/src/sensorctl/loopback_manager.cpp +++ b/src/sensorctl/loopback.cpp @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -21,8 +21,9 @@ #include #include #include -#include -#include "loopback_manager.h" + +#include "log.h" +#include "loopback.h" #define SHUB_INST_LIB_ADD ((char)-79) #define SHUB_INST_LIB_REMOVE ((char)-78) @@ -40,7 +41,7 @@ static void int_to_bytes(int32_t value, int length, char cmd[]) } } -bool loopback_manager::process(int argc, char *argv[]) +bool loopback_manager::run(int argc, char *argv[]) { if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { usage(); @@ -88,10 +89,10 @@ bool loopback_manager::process(int argc, char *argv[]) void loopback_manager::usage(void) { - PRINT("usage: sensorctl loopback [start/stop] [14byte sensor char data]\n"); - PRINT("ex: sensorctl loopback start 15000 1 1 19 1 (after 15000ms, wrist up event)\n"); - PRINT("ex: sensorctl loopback stop\n"); - PRINT(" * if not enought 14byte, remain bytes are filled with 0\n"); - PRINT("\n"); + _N("usage: sensorctl loopback [start/stop] [14byte sensor char data]\n"); + _N("ex: sensorctl loopback start 15000 1 1 19 1 (after 15000ms, wrist up event)\n"); + _N("ex: sensorctl loopback stop\n"); + _N(" * if not enought 14byte, remain bytes are filled with 0\n"); + _N("\n"); } diff --git a/src/sensorctl/loopback_manager.h b/src/sensorctl/loopback.h similarity index 91% rename from src/sensorctl/loopback_manager.h rename to src/sensorctl/loopback.h index 2aa3297..3117e27 100644 --- a/src/sensorctl/loopback_manager.h +++ b/src/sensorctl/loopback.h @@ -17,7 +17,7 @@ * */ -#pragma once // _LOOPBACK_MANAGER_H_ +#pragma once /* __LOOPBACK_MANAGER_H__ */ #include #include "sensor_manager.h" @@ -27,7 +27,7 @@ public: loopback_manager() {} virtual ~loopback_manager() {} - bool process(int argc, char *argv[]); + bool run(int argc, char *argv[]); private: void usage(void); }; diff --git a/src/sensorctl/injector_wrist_up_conf.h b/src/sensorctl/macro.h similarity index 64% rename from src/sensorctl/injector_wrist_up_conf.h rename to src/sensorctl/macro.h index 93b75f4..4e624a5 100644 --- a/src/sensorctl/injector_wrist_up_conf.h +++ b/src/sensorctl/macro.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,18 +17,7 @@ * */ -#pragma once // _WRISTUP_INJECTOR_H_ - -#include -#include -#include "injector.h" +#pragma once /* __MACRO_H__ */ #define NAME_MAX_TEST 32 - -class injector_wrist_up_conf: public injector_interface { -public: - injector_wrist_up_conf() {} - virtual ~injector_wrist_up_conf() {} - - bool inject(int option_count, char *options[]); -}; +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/src/sensorctl/mainloop.cpp b/src/sensorctl/mainloop.cpp new file mode 100644 index 0000000..8ea1d4a --- /dev/null +++ b/src/sensorctl/mainloop.cpp @@ -0,0 +1,69 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "mainloop.h" + +void mainloop::run(void) +{ + instance().start_loop(); +} + +void mainloop::stop(void) +{ + instance().stop_loop(); +} + +bool mainloop::is_running(void) +{ + return instance().is_loop_running(); +} + +mainloop& mainloop::instance(void) +{ + static mainloop loop; + return loop; +} + +void mainloop::start_loop(void) +{ + if (is_loop_running()) + return; + + m_mainloop = g_main_loop_new(NULL, false); + m_running = true; + + g_main_loop_run(m_mainloop); +} + +void mainloop::stop_loop(void) +{ + if (!is_loop_running()) + return; + + g_main_loop_quit(m_mainloop); + g_main_loop_unref(m_mainloop); + m_mainloop = NULL; + m_running = false; +} + +bool mainloop::is_loop_running(void) +{ + return m_running; +} + diff --git a/src/sensorctl/injector_context_orientation.h b/src/sensorctl/mainloop.h similarity index 70% rename from src/sensorctl/injector_context_orientation.h rename to src/sensorctl/mainloop.h index 01d2d18..70e3e53 100644 --- a/src/sensorctl/injector_context_orientation.h +++ b/src/sensorctl/mainloop.h @@ -17,16 +17,24 @@ * */ -#pragma once // _CONTEXT_INJECTOR_H_ +#pragma once /* __MAINLOOP_H__ */ #include #include -#include "injector.h" -class injector_context_orientation: public injector_interface { +class mainloop { public: - injector_context_orientation() {} - virtual ~injector_context_orientation() {} + static void run(void); + static void stop(void); + static bool is_running(void); - bool inject(int option_count, char *options[]); +private: + static mainloop& instance(); + + void start_loop(void); + void stop_loop(void); + bool is_loop_running(void); + + GMainLoop *m_mainloop; + bool m_running; }; diff --git a/src/sensorctl/sensor_adapter.cpp b/src/sensorctl/sensor_adapter.cpp new file mode 100644 index 0000000..056b5a6 --- /dev/null +++ b/src/sensorctl/sensor_adapter.cpp @@ -0,0 +1,160 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "sensor_adapter.h" + +#include + +#include "log.h" +#include "mainloop.h" +#include "test_bench.h" + +#define SENSOR_EVENT(type) ((type) << 16 | 0x1) + +bool sensor_adapter::is_supported(sensor_type_t type) +{ + sensor_t sensor; + int ret; + + ret = sensord_get_default_sensor(type, &sensor); + ASSERT_TRUE(ret); + + return true; +} + +int sensor_adapter::get_count(sensor_type_t type) +{ + sensor_t *sensors; + int count = 0; + + if (sensord_get_sensors(type, &sensors, &count) == 0) + free(sensors); + + return count; +} + +bool sensor_adapter::get_handle(sensor_info info, int &handle) +{ + int err; + int count; + sensor_t *sensors; + + err = sensord_get_sensors(info.type, &sensors, &count); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensors[info.index]); + ASSERT_GE(handle, 0); + + return true; +} + +bool sensor_adapter::start(sensor_info info, int &handle) +{ + sensor_t *sensors; + int count; + int err; + bool ret; + + err = sensord_get_sensors(info.type, &sensors, &count); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensors[info.index]); + ASSERT_GE(handle, 0); + + ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL); + ASSERT_TRUE(ret); + + ret = sensord_start(handle, info.powersave); + ASSERT_TRUE(ret); + + free(sensors); + + return true; +} + +bool sensor_adapter::stop(sensor_info info, int handle) +{ + bool ret; + + ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type)); + EXPECT_TRUE(ret); + + ret = sensord_stop(handle); + EXPECT_TRUE(ret); + + ret = sensord_disconnect(handle); + EXPECT_TRUE(ret); + + return true; +} + +bool sensor_adapter::change_interval(int handle, int interval) +{ + return true; +} + +bool sensor_adapter::change_batch_latency(int handle, int batch_latency) +{ + return true; +} + +bool sensor_adapter::change_powersave(int handle, int powersave) +{ + return true; +} + +bool sensor_adapter::set_attribute(int handle, int attribute, int value) +{ + bool ret; + + ret = sensord_set_attribute_int(handle, attribute, value); + ASSERT_TRUE(ret); + + return true; +} + +bool sensor_adapter::set_attribute(int handle, int attribute, char *value, int size) +{ + int ret; + + ret = sensord_set_attribute_str(handle, attribute, value, size); + + return ((ret == 0) ? true : false); +} + +bool sensor_adapter::get_data(int handle, sensor_type_t type, sensor_data_t &data) +{ + bool ret; + + ret = sensord_get_data(handle, SENSOR_EVENT(type), &data); + ASSERT_TRUE(ret); + + return true; +} + +bool sensor_adapter::flush(int handle) +{ + bool ret; + + ret = sensord_flush(handle); + ASSERT_TRUE(ret); + + return true; +} + diff --git a/src/sensorctl/sensor_adapter.h b/src/sensorctl/sensor_adapter.h new file mode 100644 index 0000000..631c4e5 --- /dev/null +++ b/src/sensorctl/sensor_adapter.h @@ -0,0 +1,62 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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. + * + */ + +#pragma once /* __SENSOR_ADAPTER_H__ */ + +#include + +class sensor_info { +public: + sensor_info(sensor_type_t _type, int _index, int _interval, int _batch_latency, int _powersave, sensor_cb_t _cb, void *_user_data) + : type(_type) + , index(_index) + , interval(_interval) + , batch_latency(_batch_latency) + , powersave(_powersave) + , cb(_cb) + , user_data(_user_data) + { } + + sensor_type_t type; + int index; + int interval; + int batch_latency; + int powersave; + sensor_cb_t cb; + void *user_data; +}; + +class sensor_adapter { +public: + static bool is_supported(sensor_type_t type); + static int get_count(sensor_type_t type); + static bool get_handle(sensor_info info, int &handle); + + static bool start(sensor_info info, int &handle); + static bool stop(sensor_info info, int handle); + + static bool change_interval(int handle, int interval); + static bool change_batch_latency(int handle, int batch_latency); + static bool change_powersave(int handle, int powersave); + static bool set_attribute(int handle, int attribute, int value); + static bool set_attribute(int handle, int attribute, char *value, int size); + + static bool get_data(int handle, sensor_type_t type, sensor_data_t &data); + static bool flush(int handle); +}; diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp index ce2e4ef..25ff923 100644 --- a/src/sensorctl/sensor_manager.cpp +++ b/src/sensorctl/sensor_manager.cpp @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,12 +17,14 @@ * */ -#include -#include -#include #include "sensor_manager.h" -#define NAME_MAX_TEST 32 +#include +#include + +#include "log.h" +#include "util.h" +#include "macro.h" struct sensor_info { sensor_type_t type; @@ -30,86 +32,97 @@ struct sensor_info { }; static struct sensor_info sensor_infos[] = { - {ALL_SENSOR, "all"}, + {ALL_SENSOR, "all"}, // General Sensors - {ACCELEROMETER_SENSOR, "accelerometer"}, - {GEOMAGNETIC_SENSOR, "magnetic"}, - {LIGHT_SENSOR, "light"}, - {PROXIMITY_SENSOR, "proximity"}, - {GYROSCOPE_SENSOR, "gyroscope"}, - {PRESSURE_SENSOR, "pressure"}, - {BIO_SENSOR, "bio"}, - {BIO_HRM_SENSOR, "hrm"}, - {AUTO_ROTATION_SENSOR, "auto_rotation"}, - {GRAVITY_SENSOR, "gravity"}, - {LINEAR_ACCEL_SENSOR, "linear_accel"}, - {ROTATION_VECTOR_SENSOR, "rotation_vector"}, - {ORIENTATION_SENSOR, "orientation"}, - {TEMPERATURE_SENSOR, "temperature"}, - {HUMIDITY_SENSOR, "humidity"}, - {ULTRAVIOLET_SENSOR, "ultraviolet"}, - {BIO_LED_GREEN_SENSOR, "hrm_led_green"}, - {BIO_LED_IR_SENSOR, "hrm_led_ir"}, - {BIO_LED_RED_SENSOR, "hrm_led_red"}, - {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal"}, - {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal"}, - {GYROSCOPE_RV_SENSOR, "gyro_rv"}, - {GEOMAGNETIC_RV_SENSOR, "mag_rv"}, - /* If WRIST_UP_SENSOR is created, it has to be changed to WRIST_UP_SENSOR */ - {MOTION_SENSOR, "motion"}, - {CONTEXT_SENSOR, "context"}, - {EXERCISE_SENSOR, "exercise"}, - {GESTURE_WRIST_UP_SENSOR, "wristup"}, + {ACCELEROMETER_SENSOR, "accelerometer"}, + {GRAVITY_SENSOR, "gravity"}, + {LINEAR_ACCEL_SENSOR, "linear_accel"}, + {GEOMAGNETIC_SENSOR, "magnetic"}, + {ROTATION_VECTOR_SENSOR, "rotation_vector"}, + {ORIENTATION_SENSOR, "orientation"}, + {GYROSCOPE_SENSOR, "gyroscope"}, + {LIGHT_SENSOR, "light"}, + {PROXIMITY_SENSOR, "proximity"}, + {PRESSURE_SENSOR, "pressure"}, + {ULTRAVIOLET_SENSOR, "uv"}, + {TEMPERATURE_SENSOR, "temperature"}, + {HUMIDITY_SENSOR, "humidity"}, + {HRM_SENSOR, "hrm"}, + {HRM_RAW_SENSOR, "hrm_raw"}, + {HRM_LED_GREEN_SENSOR, "hrm_led_green"}, + {HRM_LED_IR_SENSOR, "hrm_led_ir"}, + {HRM_LED_RED_SENSOR, "hrm_led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal"}, + {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal"}, + {GYROSCOPE_RV_SENSOR, "gyro_rv"}, + {GEOMAGNETIC_RV_SENSOR, "mag_rv"}, + + {HUMAN_PEDOMETER_SENSOR, "pedo"}, + {HUMAN_SLEEP_MONITOR_SENSOR, "sleep_monitor"}, + + {AUTO_ROTATION_SENSOR, "auto_rotation"}, + //{AUTO_BRIGHTENESS_SENSOR, "auto_brighteness"}, + {MOTION_SENSOR, "motion"}, + {CONTEXT_SENSOR, "context"}, + + {GESTURE_MOVEMENT_SENSOR, "movement"}, + {GESTURE_WRIST_UP_SENSOR, "wristup"}, + {GESTURE_WRIST_DOWN_SENSOR, "wristdown"}, + {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state"}, + + {WEAR_STATUS_SENSOR, "wear_status"}, + {WEAR_ON_MONITOR_SENSOR, "wear_on"}, + {GPS_BATCH_SENSOR, "gps"}, + {ACTIVITY_TRACKER_SENSOR, "activity"}, + {SLEEP_DETECTOR_SENSOR, "sleep_detector"}, }; -bool sensor_manager::process(int argc, char *argv[]) +sensor_manager::~sensor_manager() { - return false; } -void sensor_manager::usage_sensors(void) +bool sensor_manager::run(int argc, char *argv[]) { - PRINT("The sensor types are:\n"); - int sensor_count = ARRAY_SIZE(sensor_infos); + return true; +} - for (int i = 0; i < sensor_count; ++i) - PRINT(" %d: %s(%d)\n", i, sensor_infos[i].name, sensor_infos[i].type); - PRINT("\n"); +void sensor_manager::stop(void) +{ } -sensor_type_t sensor_manager::get_sensor_type(char *name) +sensor_type_t sensor_manager::get_sensor_type(const char *name) { int index; - int sensor_count = ARRAY_SIZE(sensor_infos); + int count; + + if (util::is_hex(name)) + return (sensor_type_t) (strtol(name, NULL, 16)); + + if (util::is_number(name)) + return (sensor_type_t) (atoi(name)); - for (index = 0; index < sensor_count; ++index) { + count = ARRAY_SIZE(sensor_infos); + + for (index = 0; index < count; ++index) { if (!strcmp(sensor_infos[index].name, name)) break; } - if (index == sensor_count) { - _E("ERROR: sensor name is wrong\n"); + if (index == count) { + _E("Invaild sensor name\n"); usage_sensors(); return UNKNOWN_SENSOR; } return sensor_infos[index].type; } -const char *sensor_manager::get_sensor_name(sensor_type_t type) +void sensor_manager::usage_sensors(void) { - int index; + _N("The sensor types are:\n"); int sensor_count = ARRAY_SIZE(sensor_infos); - for (index = 0; index < sensor_count; ++index) { - if (sensor_infos[index].type == type) - break; - } - - if (index == sensor_count) { - _E("ERROR: sensor name is wrong\n"); - usage_sensors(); - return "UNKNOWN SENSOR"; - } - return sensor_infos[index].name; + for (int i = 0; i < sensor_count; ++i) + _N("%3d: %s(%#x)\n", i, sensor_infos[i].name, sensor_infos[i].type); + _N("\n"); } diff --git a/src/sensorctl/sensor_manager.h b/src/sensorctl/sensor_manager.h index 9fd3476..152abcd 100644 --- a/src/sensorctl/sensor_manager.h +++ b/src/sensorctl/sensor_manager.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,16 +17,19 @@ * */ -#pragma once // _SENSOR_MANAGER_H_ +#pragma once /* __SENSOR_MANAGER_H__ */ #include class sensor_manager { public: - virtual bool process(int argc, char *argv[]); + virtual ~sensor_manager(); + + virtual bool run(int argc, char *argv[]); + virtual void stop(void); + protected: - void usage_sensors(void); + sensor_type_t get_sensor_type(const char *name); - sensor_type_t get_sensor_type(char *name); - const char * get_sensor_name(sensor_type_t type); + void usage_sensors(void); }; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp index aa4543e..a35e286 100644 --- a/src/sensorctl/sensorctl.cpp +++ b/src/sensorctl/sensorctl.cpp @@ -22,79 +22,85 @@ #include #include -#include +#include "log.h" #include "sensor_manager.h" -#include "tester_manager.h" -#include "injector_manager.h" -#include "info_manager.h" -#include "loopback_manager.h" +#include "tester.h" +#include "injector.h" +#include "info.h" +#include "loopback.h" -static void good_bye(void) -{ -} - -static void signal_handler(int signo) -{ - _E("\nReceived SIGNAL(%d)\n", signo); - exit(EXIT_SUCCESS); - - return; -} +static sensor_manager *manager; -void usage(void) +static void usage(void) { - PRINT("usage: sensorctl []\n"); + _N("usage: sensorctl []\n"); - PRINT("The sensorctl commands are:\n"); - PRINT(" test: test sensor(s)\n"); - PRINT(" inject: inject the event to sensor\n"); - PRINT(" info: show sensor infos\n"); - PRINT(" loopback: sensor loopback test\n"); + _N("The sensorctl commands are:\n"); + _N(" test: test sensor(s)\n"); + _N(" inject: inject the event to sensor\n"); + _N(" info: show sensor infos\n"); } -sensor_manager *create_manager(int argc, char *argv[2]) +static sensor_manager *create_manager(char *command) { sensor_manager *manager = NULL; - if (!strcmp(argv[1], "test")) + if (!strcmp(command, "test")) manager = new(std::nothrow) tester_manager; - if (!strcmp(argv[1], "inject")) + if (!strcmp(command, "inject")) manager = new(std::nothrow) injector_manager; - if (!strcmp(argv[1], "info")) + if (!strcmp(command, "info")) manager = new(std::nothrow) info_manager; - if (!strcmp(argv[1], "loopback")) + if (!strcmp(command, "loopback")) manager = new(std::nothrow) loopback_manager; if (!manager) { - _E("failed to allocate memory for manager"); + _E("failed to allocate memory for manager\n"); return NULL; } return manager; } -int main(int argc, char *argv[]) +static void destroy_manager(sensor_manager *manager) +{ + if (!manager) + return; + + delete manager; + manager = NULL; +} + +static void signal_handler(int signo) { - atexit(good_bye); + _E("\nReceived SIGNAL(%d)\n", signo); + manager->stop(); +} + +int main(int argc, char *argv[]) +{ signal(SIGINT, signal_handler); signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); signal(SIGQUIT, signal_handler); signal(SIGABRT, signal_handler); + signal(SIGTSTP, signal_handler); if (argc < 2) { usage(); - return 0; + return EXIT_SUCCESS; } - sensor_manager *manager = create_manager(argc, argv); + manager = create_manager(argv[1]); if (!manager) { usage(); - return 0; + return EXIT_SUCCESS; } - manager->process(argc, argv); + manager->run(argc, argv); + + destroy_manager(manager); - return 0; + return EXIT_SUCCESS; } diff --git a/src/sensorctl/sensorctl_log.h b/src/sensorctl/sensorctl_log.h deleted file mode 100644 index f5f8f25..0000000 --- a/src/sensorctl/sensorctl_log.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * sensorctl - * - * 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. - * - */ - -#pragma once // _SENSORCTL_LOG_H_ - -#include -#include - -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KYEL "\x1B[33m" -#define KBLU "\x1B[34m" -#define KMAG "\x1B[35m" -#define KCYN "\x1B[36m" -#define KWHT "\x1B[37m" -#define RESET "\033[0m" - -#define PRINT(fmt, args...) \ - do { \ - g_print(fmt, ##args); \ - } while (0) - -#define _E(fmt, args...) \ - do { \ - g_print("\x1B[31m" fmt "\033[0m", ##args); \ - } while (0) - -#define _I(fmt, args...) \ - do { \ - g_print("\x1B[32m" fmt "\033[0m", ##args); \ - } while (0) - diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp new file mode 100644 index 0000000..f675133 --- /dev/null +++ b/src/sensorctl/test_bench.cpp @@ -0,0 +1,226 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "log.h" +#include "test_bench.h" + +/* + * Implementation of test_option + */ +bool test_option::full_log = false; +std::string test_option::group = ""; + +void test_option::show_full_log(bool show) +{ + full_log = show; +} + +void test_option::set_group(const char *gname) +{ + group = gname; +} + +void test_option::set_options(int argc, char *argv[]) +{ + /* TODO: use getopt() */ + if (argc > 3) + set_group(argv[3]); + if (argc > 4) + show_full_log(atoi(argv[4])); +} + +/* + * Implementation of test_case + */ +test_case::test_case(const std::string &group, const std::string &name) +: m_group(group) +, m_name(name) +{ + test_bench::register_testcase(group, this); +} + +void test_case::started(void) +{ + _I("[----------]\n"); + _I("[ RUN ] "); + _N("%s.%s\n", m_group.c_str(), m_name.c_str()); +} + +void test_case::stopped(void) +{ + _I("[ OK ] "); + _N("%s.%s\n", m_group.c_str(), m_name.c_str()); + _I("[----------]\n"); +} + +void test_case::show(bool result) +{ + if (result) + _I("[ PASSED ] "); + else + _E("[ FAILED ] "); + _N("%s.%s\n", m_group.c_str(), m_name.c_str()); +} + +void test_case::run_testcase(void) +{ + bool result; + + started(); + result = (this->*m_func)(); + stopped(); + show(result); +} + +void test_case::register_func(test_func func) +{ + m_func = func; +} + +/* + * Implementation of test_bench + */ +test_bench& test_bench::instance() +{ + static test_bench bench; + return bench; +} + +void test_bench::register_testcase(const std::string &group, test_case *testcase) +{ + instance().add_testcase(group, testcase); +} + +void test_bench::push_failure(const std::string &function, long line, const std::string &msg) +{ + instance().add_failure(function, line, msg); +} + +void test_bench::run_all_testcase(void) +{ + instance().run(); +} + +void test_bench::stop_all_testcase(void) +{ + instance().stop(); +} + +void test_bench::add_testcase(const std::string &group, test_case *testcase) +{ + if (!testcase) + return; + + testcases.insert(std::pair(group, testcase)); +} + +void test_bench::add_failure(const std::string &function, long line, const std::string &msg) +{ + test_result fail(function, line, msg); + + results.push_back(fail); + m_failure_count++; +} + +void test_bench::started(void) +{ + _I("[==========] "); + _N("Running %d testcases\n", count(test_option::group)); +} + +void test_bench::stopped(void) +{ + _I("[==========] "); + _N("%d testcases ran\n", count(test_option::group)); +} + +void test_bench::show_failures(void) +{ + _N("================================\n"); + + if (m_failure_count == 0) { + _N("there was no fail case\n"); + return; + } + + _N("%d case(s) are failed, listed below:\n", m_failure_count); + + for (unsigned int i = 0; i < results.size(); ++i) { + _E("[ FAILED ] "); + _N("%s(%ld) -> %s\n", + results[i].function.c_str(), + results[i].line, + results[i].msg.c_str()); + } +} + +void test_bench::run(void) +{ + std::size_t found; + m_failure_count = 0; + + started(); + + for (auto it = testcases.begin(); it != testcases.end(); ++it) { + if (m_stop) + break; + + found = it->first.find("skip"); + + if (test_option::group.empty() && found != std::string::npos) + continue; + + found = it->first.find(test_option::group); + + if (!test_option::group.empty() && found == std::string::npos) + continue; + + it->second->run_testcase(); + } + + stopped(); + show_failures(); +} + +void test_bench::stop(void) +{ + m_stop = true; +} + +unsigned int test_bench::count(std::string &group) +{ + if (group.empty()) + return testcases.size() - count_by_key("skip"); + + return count_by_key(group.c_str()); +} + +unsigned int test_bench::count_by_key(const char *key) +{ + int count = 0; + + for (auto it = testcases.begin(); it != testcases.end(); ++it) { + std::size_t found = it->first.find(key); + + if (found != std::string::npos) + count++; + } + + return count; +} diff --git a/src/sensorctl/test_bench.h b/src/sensorctl/test_bench.h new file mode 100644 index 0000000..8525e39 --- /dev/null +++ b/src/sensorctl/test_bench.h @@ -0,0 +1,201 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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. + * + */ + +#pragma once /* __TEST_BENCH_H__ */ + +#include +#include +#include +#include +#include + +#define FAIL(left, comp, right) \ +do { \ + _E("[ FAIL ] "); \ + std::ostringstream os; \ + os << __FUNCTION__ << "(" << __LINE__ << ") : " \ + << #left << "(" << left << ") " \ + << #comp << " " << #right << "(" << right << ")"; \ + std::cout << os.str() << std::endl; \ + test_bench::push_failure(__FUNCTION__, __LINE__, os.str()); \ +} while (0) + +#define PASS(left, comp, right) \ +do { \ + if (test_option::full_log) { \ + _I("[ PASS ] "); \ + std::ostringstream os; \ + os << __FUNCTION__ << "(" << __LINE__ << ") : " \ + << #left << "(" << left << ") " \ + << #comp << " " << #right << "(" << right << ")"; \ + std::cout << os.str() << std::endl; \ + } \ +} while (0) + +#define ASSERT(left, comp, right) \ +do { \ + if (!((left) comp (right))) { \ + FAIL(left, comp, right); \ + return false; \ + } \ + PASS(left, comp, right); \ +} while (0) + + +#define EXPECT(left, comp, right) \ +do { \ + if (!((left) comp (right))) { \ + FAIL(left, comp, right); \ + } else { \ + PASS(left, comp, right); \ + } \ +} while (0) + +#define ASSERT_TRUE(condition) ASSERT(condition, ==, true) +#define ASSERT_FALSE(condition) ASSERT(condition, ==, false) +#define ASSERT_EQ(left, right) ASSERT(left, ==, right) +#define ASSERT_NE(left, right) ASSERT(left, !=, right) +#define ASSERT_LT(left, right) ASSERT(left, <, right) +#define ASSERT_LE(left, right) ASSERT(left, <=, right) +#define ASSERT_GT(left, right) ASSERT(left, >, right) +#define ASSERT_GE(left, right) ASSERT(left, >=, right) +#define ASSERT_NEAR(left, right, err) \ +do { \ + ASSERT(left, >=, (right - (err))); \ + ASSERT(left, <=, (right + (err))); \ +} while (0) + +#define EXPECT_TRUE(condition) EXPECT(condition, ==, true) +#define EXPECT_FALSE(condition) EXPECT(condition, ==, false) +#define EXPECT_EQ(left, right) EXPECT(left, ==, right) +#define EXPECT_NE(left, right) EXPECT(left, !=, right) +#define EXPECT_LT(left, right) EXPECT(left, <, right) +#define EXPECT_LE(left, right) EXPECT(left, <=, right) +#define EXPECT_GT(left, right) EXPECT(left, >, right) +#define EXPECT_GE(left, right) EXPECT(left, >=, right) +#define EXPECT_NEAR(left, right, err) \ +do { \ + EXPECT(left, >=, (right - (err))); \ + EXPECT(left, <=, (right + (err))); \ +} while (0) + +#define TESTCASE(group, name) \ +class test_case_##group_##name : public test_case { \ +public: \ + test_case_##group_##name() \ + : test_case(#group, #name) \ + { \ + register_func(static_cast(&test_case_##group_##name::test)); \ + } \ + bool test(void); \ +} test_case_##group_##name##_instance; \ +bool test_case_##group_##name::test(void) + +/* + * Declaration of test_option + */ +class test_option { +public: + static bool full_log; + static std::string group; + + static void show_full_log(bool show); + static void set_group(const char *gname); + static void set_options(int argc, char *argv[]); +}; + +/* + * Decloaration of test_result + */ +class test_result { +public: + test_result(const std::string &_function, long _line, const std::string &_msg) + : function(_function) + , line(_line) + , msg(_msg) { } + + std::string function; + long line; + std::string msg; +}; + +/* + * Declaration of test_case + */ +class test_case { +public: + test_case(const std::string &group, const std::string &name); + + void run_testcase(void); + + const std::string& group() const { return m_group; } + const std::string& name() const { return m_name; } + +protected: + typedef bool (test_case::*test_func)(); + + void started(void); + void stopped(void); + void show(bool result); + void register_func(test_func func); + +private: + const std::string m_group; + const std::string m_name; + test_func m_func; +}; + +/* + * Declaration of test_bench + */ +class test_bench { +public: + test_bench() + : m_failure_count(0) + , m_stop(false) + {} + + static void register_testcase(const std::string &group, test_case *testcase); + + static void run_all_testcase(void); + static void stop_all_testcase(void); + + static void push_failure(const std::string &function, long line, const std::string &msg); + +private: + static test_bench& instance(); + + void add_failure(const std::string &function, long line, const std::string &msg); + + void started(void); + void stopped(void); + void show_failures(void); + + void add_testcase(const std::string &group, test_case *testcase); + void run(void); + void stop(void); + + unsigned int count(std::string &group); + unsigned int count_by_key(const char *key); + + std::multimap testcases; + std::vector results; + int m_failure_count; + bool m_stop; +}; diff --git a/src/sensorctl/testcase/accelerometer.cpp b/src/sensorctl/testcase/accelerometer.cpp new file mode 100644 index 0000000..ed526c3 --- /dev/null +++ b/src/sensorctl/testcase/accelerometer.cpp @@ -0,0 +1,170 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "log.h" +#include "mainloop.h" +#include "test_bench.h" +#include "sensor_adapter.h" + +static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + EXPECT_GT(data->timestamp, 0); + EXPECT_NEAR(data->values[0], 0, 19.6); + EXPECT_NEAR(data->values[1], 0, 19.6); + EXPECT_NEAR(data->values[2], 0, 19.6); + + mainloop::stop(); +} + +TESTCASE(accelerometer_basic, start_stop_p) +{ + bool ret; + int handle; + + sensor_info info(ACCELEROMETER_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +static void get_data_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + mainloop::stop(); +} + +TESTCASE(accelerometer_basic, get_data_p) +{ + bool ret; + int handle; + sensor_data_t data; + + sensor_info info(ACCELEROMETER_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, get_data_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::get_data(handle, info.type, data); + ASSERT_TRUE(ret); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +static unsigned long long prev_prev_ts; +static unsigned long long prev_ts; +static int event_count; + +static void accel_regular_interval_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + int prev_gap; + int current_gap; + if (prev_prev_ts == 0) { + prev_prev_ts = data->timestamp; + return; + } + + if (prev_ts == 0) { + prev_ts = data->timestamp; + return; + } + + prev_gap = prev_ts - prev_prev_ts; + current_gap = data->timestamp - prev_ts; + + EXPECT_NEAR(current_gap, prev_gap, 10000); + prev_prev_ts = prev_ts; + prev_ts = data->timestamp; + + if (event_count++ > 3) + mainloop::stop(); +} + +TESTCASE(accelerometer_interval, regular_interval_p) +{ + bool ret; + int handle; + prev_prev_ts = 0; + prev_ts = 0; + event_count = 0; + + sensor_info info(ACCELEROMETER_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_regular_interval_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +static void accel_interval_100ms_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + if (prev_ts == 0) { + prev_ts = data->timestamp; + return; + } + + /* 100ms + 20ms(error) */ + EXPECT_LE(data->timestamp - prev_ts, 120000); + prev_ts = data->timestamp; + + if (event_count++ > 3) + mainloop::stop(); +} + +TESTCASE(accelerometer_interval, 100ms_interval_p) +{ + bool ret; + int handle; + + prev_ts = 0; + event_count = 0; + + sensor_info info(ACCELEROMETER_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_interval_100ms_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} diff --git a/src/sensorctl/testcase/sensor_basic.cpp b/src/sensorctl/testcase/sensor_basic.cpp new file mode 100644 index 0000000..466b80a --- /dev/null +++ b/src/sensorctl/testcase/sensor_basic.cpp @@ -0,0 +1,168 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "log.h" +#include "mainloop.h" +#include "test_bench.h" +#include "sensor_adapter.h" + +static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + EXPECT_GT(data->timestamp, 0); + //_N("[ DATA ] %f\n", data->values[0]); + mainloop::stop(); +} + +TESTCASE(all_sensor_test, scenario_basic_p) +{ + int err; + bool ret; + int count; + int handle; + sensor_t *sensors; + sensor_type_t type; + + err = sensord_get_sensors(ALL_SENSOR, &sensors, &count); + ASSERT_EQ(err, 0); + + for (int i = 0; i < count; ++i) { + sensord_get_type(sensors[i], &type); + /* TODO */ + _N("[ TYPE ] %s\n", "UNKNOWN_SENSOR"); + + sensor_info info(type, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + + ret = sensor_adapter::start(info, handle); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + EXPECT_TRUE(ret); + } + + free(sensors); + + return true; +} + +typedef bool (*process_func_t)(const char *msg, int size, int count); + +static pid_t run_process(process_func_t func, const char *msg, int size, int count) +{ + pid_t pid = fork(); + if (pid < 0) + return -1; + + if (pid == 0) { + if (!func(msg, size, count)) + _E("Failed to run process\n"); + exit(0); + } + + return pid; +} + +static bool run_echo_command_test(const char *str, int size, int cout) +{ + bool ret = true; + int handle; + char buf[4096] = {'1', '1', '1', }; + + sensor_info info(ACCELEROMETER_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + sensor_adapter::get_handle(info, handle); + + usleep(10000); + for (int i = 0; i < 1024; ++i) + ret &= sensor_adapter::set_attribute(handle, SENSOR_ATTR_ACCELEROMETER_INJECTION, buf, 4096); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(echo_command_test, echo_command_p) +{ + pid_t pid; + + usleep(100000); + + for (int i = 0; i < 100; ++i) { + pid = run_process(run_echo_command_test, NULL, 0, 0); + EXPECT_GE(pid, 0); + } + + pid = run_process(run_echo_command_test, NULL, 0, 0); + EXPECT_GE(pid, 0); + + ASSERT_TRUE(true); + usleep(100000); + + return true; +} + +#if 0 +TESTCASE(gyroscope_value_p) +{ + scenario_basic_p(GYROSCOPE_SENSOR); +} + +TESTCASE(gravitye_value_p) +{ + scenario_basic_p(GRAVITY_SENSOR); +} + +TESTCASE(linear_accel_value_p) +{ + scenario_basic_p(LINEAR_ACCEL_SENSOR); +} + +TESTCASE(proximity_value_p) +{ + scenario_basic_p(PROXIMITY_SENSOR); +} + +TESTCASE(pressure_value_p) +{ + scenario_basic_p(PRESSURE_SENSOR); +} + +TESTCASE(hrm_value_p) +{ + scenario_basic_p(HRM_SENSOR); +} + +TESTCASE(hrm_raw_value_p) +{ + scenario_basic_p(HRM_RAW_SENSOR); +} + +TESTCASE(hrm_led_green_value_p) +{ + scenario_basic_p(HRM_LED_GREEN_SENSOR); +} + +TESTCASE(wrist_up_value_p) +{ + scenario_basic_p(GESTURE_WRIST_UP_SENSOR); +} +#endif diff --git a/src/sensorctl/injector_wrist_up_algo.h b/src/sensorctl/testcase/sensor_interval.cpp similarity index 62% rename from src/sensorctl/injector_wrist_up_algo.h rename to src/sensorctl/testcase/sensor_interval.cpp index a5bd6fe..8318fd5 100644 --- a/src/sensorctl/injector_wrist_up_algo.h +++ b/src/sensorctl/testcase/sensor_interval.cpp @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,17 +17,10 @@ * */ -#pragma once // _WRISTUP_INJECTOR_H_ +#include "test_bench.h" -#include -#include -#include "injector.h" - -class injector_wrist_up_algo: public injector_interface { -public: - injector_wrist_up_algo() {} - virtual ~injector_wrist_up_algo() {} - - bool init(void); - bool inject(int option_count, char *options[]); -}; +TESTCASE(sensor_interval, all_sensor_interval_10ms_p) +{ + /* TODO: test 10ms interval */ + return true; +} diff --git a/src/sensorctl/tester.cpp b/src/sensorctl/tester.cpp new file mode 100644 index 0000000..c164a57 --- /dev/null +++ b/src/sensorctl/tester.cpp @@ -0,0 +1,188 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "tester.h" + +#include +#include +#include +#include + +#include "log.h" +#include "macro.h" +#include "mainloop.h" +#include "test_bench.h" +#include "sensor_adapter.h" + +#define TESTER_ARGC 3 /* e.g. {sensorctl, test, accelerometer} */ + +#define MAX_COUNT 999999 +#define DEFAULT_INTERVAL 100 +#define DEFAULT_LATENCY 0 +#define DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON + +static sensor_type_t type; +static int interval; +static int latency; +static int powersave; +static int repeat; + +static int event_count = 0; + +tester_manager::tester_manager() +{ +} + +tester_manager::~tester_manager() +{ +} + +bool tester_manager::run(int argc, char *argv[]) +{ + if (argc < TESTER_ARGC) { + usage(); + return false; + } + + if (!setup(argc, argv)) { + usage(); + return false; + } + + test_bench::run_all_testcase(); + + return true; +} + +bool tester_manager::setup(int argc, char *argv[]) +{ + if (strncmp(argv[2], "auto", 4) == 0) + return setup_auto(argc, argv); + + return setup_manual(argc, argv); +} + +bool tester_manager::setup_auto(int argc, char *argv[]) +{ + if (argc > 5) + repeat = atoi(argv[5]); + + test_option::show_full_log(true); + test_option::set_options(argc, argv); + + return true; +} + +bool tester_manager::setup_manual(int argc, char *argv[]) +{ + type = get_sensor_type(argv[2]); + RETVM_IF(type == UNKNOWN_SENSOR, false, "Invalid argument\n"); + + interval = DEFAULT_INTERVAL; + latency = DEFAULT_LATENCY; + powersave = DEFAULT_POWERSAVE_OPTION; + event_count = 0; + + if (argc >= TESTER_ARGC + 1) + interval = atoi(argv[TESTER_ARGC]); + if (argc >= TESTER_ARGC + 2) + latency = atoi(argv[TESTER_ARGC + 1]); + if (argc >= TESTER_ARGC + 3) + powersave = atoi(argv[TESTER_ARGC + 2]); + + test_option::show_full_log(true); + test_option::set_group("skip_manual"); + /* test_option::set_options(argc, argv); */ + + return true; +} + +void tester_manager::stop(void) +{ + if (mainloop::is_running()) + mainloop::stop(); +} + +void tester_manager::usage(void) +{ + _N("usage: sensorctl test auto [group] [log]\n"); + _N("usage: sensorctl test [interval] [batch_latency] [event_count] [test_count]\n"); + + usage_sensors(); + + _N("auto:\n"); + _N(" test sensors automatically.\n"); + _N("group:\n"); + _N(" a group name(or a specific word contained in the group name).\n"); + _N("log:\n"); + _N(" enable(1) or disable(0). default value is 1.\n"); + _N("sensor_type: specific sensor\n"); + _N(" test specific sensor manually.\n"); + _N("interval_ms:\n"); + _N(" interval. default value is 100ms.\n"); + _N("batch_latency_ms:\n"); + _N(" batch_latency. default value is 1000ms.\n"); + _N("event count(n):\n"); + _N(" test sensor until it gets n event. default is 999999(infinitly).\n"); + _N("test count(n):\n"); + _N(" test sensor in n times repetitively, default is 1.\n\n"); +} + +/* manual test case */ +static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + if (event_count >= MAX_COUNT) { + mainloop::stop(); + return; + } + + _N("%llu ", data->timestamp); + for (int i = 0; i < data->value_count; ++i) + _N(" %10f", data->values[i]); + _N("\n"); +} + +TESTCASE(skip_manual, sensor_test) +{ + int handle; + bool ret; + int index = 0; + sensor_data_t data; + + if (sensor_adapter::get_count(type) > 1) { + _N("There are more than 2 sensors. please enter the index : "); + scanf("%d", &index); + } + + sensor_info info(type, index, interval, latency, powersave, test_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + ret = sensor_adapter::get_data(handle, type, data); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + diff --git a/src/sensorctl/tester.h b/src/sensorctl/tester.h index 2d912c9..148a402 100644 --- a/src/sensorctl/tester.h +++ b/src/sensorctl/tester.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,27 @@ * */ -#pragma once // _TESTER_H_ +#pragma once /* __TESTER_H__ */ #include +#include +#include -class tester_interface { +#include "sensor_manager.h" + +class tester_manager : public sensor_manager { public: - virtual bool init(void) = 0; - virtual bool test(sensor_type_t type, int option_count, char *options[]) = 0; + tester_manager(); + virtual ~tester_manager(); + + bool run(int argc, char *argv[]); + void stop(void); + +private: + bool setup(int argc, char *argv[]); + bool setup_auto(int argc, char *argv[]); + bool setup_manual(int argc, char *argv[]); + + void usage(void); }; + diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp deleted file mode 100644 index c16140f..0000000 --- a/src/sensorctl/tester_manager.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * sensorctl - * - * 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 "tester.h" -#include "tester_manager.h" -#include "tester_sensor.h" - -#define NAME_MAX_TEST 32 -#define ARGC_BASE 3 /* e.g. {sensorctl, test, accelerometer} */ - -bool tester_manager::process(int argc, char *argv[]) -{ - int option_count; - char *options[8]; - sensor_type_t type; - int i; - - if (argc == 2) { - usage(); - return false; - } - - /* 1. get sensor type */ - type = get_sensor_type(argv[2]); - if (type == UNKNOWN_SENSOR) { - _E("ERROR : failed to process injector\n"); - return false; - } - - /* 2. set up injector */ - tester_interface *tester = new tester_sensor(); - tester->init(); - - /* 3. test sensor with options */ - option_count = argc - ARGC_BASE; - for (i = 0; i < option_count; ++i) { - options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); - } - - tester->test(type, option_count, options); - - return true; -} - -void tester_manager::usage(void) -{ - PRINT("usage: sensorctl test [interval] [event_count] [test_count]\n\n"); - - usage_sensors(); - - PRINT("interval_ms:\n"); - PRINT(" interval. default value is 100ms.\n"); - PRINT("event count(n):\n"); - PRINT(" test sensor until it gets n event. default is 999999(infinitly).\n"); - PRINT("test count(n):\n"); - PRINT(" test sensor in n times repetitively, default is 1.\n\n"); -} - diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp deleted file mode 100644 index 7f324f6..0000000 --- a/src/sensorctl/tester_sensor.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * sensorctl - * - * 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 "tester_sensor.h" - -#define DEFAULT_INTERVAL 100 -#define DEFAULT_LATENCY 0 -#define DEFAULT_TEST_COUNT 1 -#define DEFAULT_EVENT_COUNT 9999 - -#define SENSOR_SHIFT_TYPE 16 - -static GMainLoop *mainloop; -static int check_loop; - -static const char *result_str(bool result) { - if (result) return KGRN "[PASS]" RESET; - else return KRED "[FAIL]" RESET; -} - -bool tester_sensor::init(void) -{ - return true; -} - -void tester_sensor::test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t type; - int *cnt_event; - - sensord_get_type(sensor, &type); - - cnt_event = (int *)user_data; - - if (check_loop++ >= *cnt_event) { - if (!mainloop) - return; - - g_main_loop_quit(mainloop); - g_main_loop_unref(mainloop); - mainloop = NULL; - return; - } - - PRINT("[%llu] %s:", data->timestamp, sensord_get_name(sensor)); - - if (type == GESTURE_WRIST_UP_SENSOR) { - PRINT("[%d]\n", ((sensorhub_data_t *)data)->hub_data[0]); - return; - } - - for (int i = 0; i < data->value_count; ++i) - PRINT(" [%f]", data->values[i]); - PRINT("\n"); -} - -void tester_sensor::test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event) -{ - bool result; - sensor_t sensor; - unsigned int event_id; - sensor_data_t data; - int handle; - int count = 0; - - event_id = type << SENSOR_SHIFT_TYPE | 0x1; - - while (count++ < cnt_test) { - mainloop = g_main_loop_new(NULL, FALSE); - check_loop = 0; - - PRINT("=======================================\n"); - PRINT("TEST(%d/%d)\n", count, cnt_test); - PRINT("=======================================\n"); - - sensor = sensord_get_sensor(type); - PRINT("%s sensord_get_sensor: sensor(%p)\n", result_str((sensor == NULL)? 0 : 1), sensor); - - handle = sensord_connect(sensor); - PRINT("%s sensord_connect: handle(%d)\n", result_str((handle >= 0)), handle); - - result = sensord_register_event(handle, event_id, interval, latency, test_cb, (void *)&cnt_event); - PRINT("%s sensord_register_event\n", result_str(result)); - - result = sensord_start(handle, 3); - PRINT("%s sensord_start\n", result_str(result)); - - result = sensord_get_data(handle, event_id, &data); - PRINT("%s sensord_get_data\n", result_str(result)); - - result = sensord_flush(handle); - PRINT("%s sensord_flush\n", result_str(result)); - - if (result) { - for (int i = 0; i < data.value_count; ++i) - PRINT("[%f] ", data.values[i]); - PRINT("\n"); - } - - g_main_loop_run(mainloop); - - result = sensord_unregister_event(handle, event_id); - PRINT("%s sensord_unregister_event: handle(%d)\n", result_str(result), handle); - result = sensord_stop(handle); - PRINT("%s sensord_stop: handle(%d)\n", result_str(result), handle); - result = sensord_disconnect(handle); - PRINT("%s sensord_disconnect: handle(%d)\n", result_str(result), handle); - } -} - -bool tester_sensor::test(sensor_type_t type, int option_count, char *options[]) -{ - int interval = DEFAULT_INTERVAL; - int latency = DEFAULT_LATENCY; - int cnt_test = DEFAULT_TEST_COUNT; - int cnt_event = DEFAULT_EVENT_COUNT; - - sensor_type_t sensor_type = type; - - if (option_count >= 1) - interval = atoi(options[0]); - if (option_count >= 2) - cnt_event = atoi(options[1]); - if (option_count >= 3) - cnt_test = atoi(options[2]); - - test_sensor(sensor_type, interval, latency, cnt_test, cnt_event); - return true; -} diff --git a/src/sensorctl/tester_sensor.h b/src/sensorctl/tester_sensor.h deleted file mode 100644 index 68b76b4..0000000 --- a/src/sensorctl/tester_sensor.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * sensorctl - * - * 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. - * - */ - -#pragma once // _SENSOR_TESTER_H_ - -#include "tester.h" - -class tester_sensor : public tester_interface { -public: - tester_sensor() {} - virtual ~tester_sensor() {} - - virtual bool init(void); - virtual bool test(sensor_type_t type, int option_count, char *options[]); -private: - void test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event); - static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); -}; diff --git a/src/sensorctl/util.cpp b/src/sensorctl/util.cpp new file mode 100644 index 0000000..9b2016f --- /dev/null +++ b/src/sensorctl/util.cpp @@ -0,0 +1,59 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include "util.h" + +bool util::is_number(const char *value) +{ + if (value == NULL || *value == 0) + return false; + + while (*value) { + if (*value < '0' || *value > '9') + return false; + value++; + } + + return true; +} + +bool util::is_hex(const char *value) +{ + if (value == NULL || *value == 0) + return false; + + if (value[0] != '0') + return false; + + if (value[1] != 'x' && value[1] != 'X') + return false; + + value += 2; + + while (*value) { + if ((*value < '0' || *value > '9') && + (*value < 'a' || *value > 'f') && + (*value < 'A' || *value > 'F')) + return false; + value++; + } + + return true; +} diff --git a/src/sensorctl/tester_manager.h b/src/sensorctl/util.h similarity index 67% rename from src/sensorctl/tester_manager.h rename to src/sensorctl/util.h index 16f4b16..b2dcbc8 100644 --- a/src/sensorctl/tester_manager.h +++ b/src/sensorctl/util.h @@ -1,7 +1,7 @@ /* * sensorctl * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -17,16 +17,10 @@ * */ -#pragma once // _TEST_MANAGER_H_ +#pragma once /* __UTIL_H__ */ -#include "sensor_manager.h" - -class tester_manager : public sensor_manager { +class util { public: - tester_manager() {} - virtual ~tester_manager() {} - - bool process(int argc, char *argv[]); -private: - void usage(void); + static bool is_number(const char *value); + static bool is_hex(const char *value); }; -- 2.7.4