From 4279e3e2ae97d7730e4f865d6ec27355571a91e6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 10 May 2017 17:55:21 +0900 Subject: [PATCH 01/16] sensord: add privilege part to URI format - http:///sensor/// Change-Id: I10601f8f95fdb693dd02d047e2228c59e81e5dcd Signed-off-by: kibak.yoon --- src/client/sensor_provider.cpp | 4 + src/sensor/auto_rotation/auto_rotation_sensor.cpp | 4 +- src/sensor/gravity/gravity_comp_sensor.cpp | 6 +- src/sensor/gravity/gravity_lowpass_sensor.cpp | 4 +- src/sensor/linear_accel/linear_accel_sensor.cpp | 6 +- src/sensor/orientation/orientation_sensor.cpp | 4 +- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 6 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 6 +- src/sensor/rotation_vector/rv_sensor.cpp | 8 +- src/server/sensor_handler.cpp | 3 + src/shared/sensor_types_private.h | 9 +- src/shared/sensor_utils.cpp | 193 ++++++++++++---------- src/shared/sensor_utils.h | 1 + 13 files changed, 147 insertions(+), 107 deletions(-) diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index 5d0b1c9..94036e0 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,9 @@ bool sensor_provider::init(const char *uri) m_sensor.set_min_range(0); m_sensor.set_max_range(1); m_sensor.set_resolution(1); + /* TODO: temporary walkaround */ + const char *priv = sensor::utils::get_privilege(uri); + m_sensor.set_privilege(priv); return true; } diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 33f1fda..e02cad3 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -24,11 +24,11 @@ #include "auto_rotation_alg_emul.h" -#define NAME_SENSOR "http://tizen.org/sensor/auto_rotation/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/auto_rotation/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" static sensor_info2_t sensor_info = { id: 0x1, diff --git a/src/sensor/gravity/gravity_comp_sensor.cpp b/src/sensor/gravity/gravity_comp_sensor.cpp index 9552e74..36b2171 100644 --- a/src/sensor/gravity/gravity_comp_sensor.cpp +++ b/src/sensor/gravity/gravity_comp_sensor.cpp @@ -24,14 +24,14 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gravity/tizen_complementary" +#define NAME_SENSOR "http://tizen.org/sensor/general/gravity/tizen_complementary" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define SRC_ID_GYRO 0x2 -#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" +#define SRC_STR_GYRO "http://tizen.org/sensor/general/gyroscope" #define GRAVITY 9.80665 diff --git a/src/sensor/gravity/gravity_lowpass_sensor.cpp b/src/sensor/gravity/gravity_lowpass_sensor.cpp index bc31ce2..5401934 100644 --- a/src/sensor/gravity/gravity_lowpass_sensor.cpp +++ b/src/sensor/gravity/gravity_lowpass_sensor.cpp @@ -24,11 +24,11 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gravity/tizen_lowpass" +#define NAME_SENSOR "http://tizen.org/sensor/general/gravity/tizen_lowpass" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define GRAVITY 9.80665 #define US_PER_SEC 1000000 diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 00e0bb7..2dac280 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -23,14 +23,14 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/linear_acceleration/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/linear_acceleration/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define SRC_ID_GRAVITY 0x2 -#define SRC_STR_GRAVITY "http://tizen.org/sensor/gravity" +#define SRC_STR_GRAVITY "http://tizen.org/sensor/general/gravity" #define GRAVITY 9.80665 diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index 551c73f..acdf12b 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -23,11 +23,11 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/orientation/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/orientation/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_RV 0x1 -#define SRC_STR_RV "http://tizen.org/sensor/rotation_vector" +#define SRC_STR_RV "http://tizen.org/sensor/general/rotation_vector" static sensor_info2_t sensor_info = { id: 0x1, diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 74e0e27..478e2ee 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -23,14 +23,14 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/gyroscope_rotation_vector/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/gyroscope_rotation_vector/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define SRC_ID_GYRO 0x2 -#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" +#define SRC_STR_GYRO "http://tizen.org/sensor/general/gyroscope" static sensor_info2_t sensor_info = { id: 0x1, diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 2e4b255..ef438ad 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -23,14 +23,14 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/geomagnetic_rotation_vector/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/geomagnetic_rotation_vector/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define SRC_ID_MAG 0x3 -#define SRC_STR_MAG "http://tizen.org/sensor/magnetic" +#define SRC_STR_MAG "http://tizen.org/sensor/general/magnetic" static sensor_info2_t sensor_info = { id: 0x1, diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index e88a004..cb37f42 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -23,17 +23,17 @@ #include #include -#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/tizen_default" +#define NAME_SENSOR "http://tizen.org/sensor/general/rotation_vector/tizen_default" #define NAME_VENDOR "tizen.org" #define SRC_ID_ACC 0x1 -#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" +#define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" #define SRC_ID_GYRO 0x2 -#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" +#define SRC_STR_GYRO "http://tizen.org/sensor/general/gyroscope" #define SRC_ID_MAG 0x3 -#define SRC_STR_MAG "http://tizen.org/sensor/magnetic" +#define SRC_STR_MAG "http://tizen.org/sensor/general/magnetic" static sensor_info2_t sensor_info = { id: 0x1, diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index 95701cc..4f16244 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -21,12 +21,15 @@ #include #include +#include using namespace sensor; sensor_handler::sensor_handler(const sensor_info &info) : m_info(info) { + const char *priv = sensor::utils::get_privilege(m_info.get_uri()); + m_info.set_privilege(priv); } bool sensor_handler::has_observer(sensor_observer *ob) diff --git a/src/shared/sensor_types_private.h b/src/shared/sensor_types_private.h index 17fcd02..b1c49f3 100644 --- a/src/shared/sensor_types_private.h +++ b/src/shared/sensor_types_private.h @@ -20,9 +20,16 @@ #ifndef __SENSOR_TYPES_PRIVATE__ #define __SENSOR_TYPES_PRIVATE__ -#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)$)~" +#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/(general|healthinfo)\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)$)~" #define SENSOR_URI_REGEX URI_REGEX("sensor") #define PREDEFINED_TYPE_URI "http://tizen.org/sensor/" +#define URI_DELIMITER "/" +#define PRIVILEGE_HEALTHINFO_STR "healthinfo" +#define PRIVILEGE_HEALTHINFO_URI "http://tizen.org/privilege/healthinfo" + +#define URI_PRIV_INDEX 4 +#define URI_SENSOR_TYPE_INDEX 5 + #endif /* __SENSOR_TYPES_PRIVATE__ */ diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 8313c4d..1f09e4b 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -28,7 +28,9 @@ #include #include +#include #include +#include #ifndef PATH_MAX #define PATH_MAX 256 @@ -36,90 +38,90 @@ /* TODO: move and define string type to sensor_type.h */ static std::map types = { - {UNKNOWN_SENSOR, "http://tizen.org/sensor/unknown"}, - {ALL_SENSOR, "http://tizen.org/sensor/all"}, - {ACCELEROMETER_SENSOR, "http://tizen.org/sensor/accelerometer"}, - {GRAVITY_SENSOR, "http://tizen.org/sensor/gravity"}, - {LINEAR_ACCEL_SENSOR, "http://tizen.org/sensor/linear_acceleration"}, - {GEOMAGNETIC_SENSOR, "http://tizen.org/sensor/magnetic"}, - {ROTATION_VECTOR_SENSOR, "http://tizen.org/sensor/rotation_vector"}, - {ORIENTATION_SENSOR, "http://tizen.org/sensor/orientation"}, - {GYROSCOPE_SENSOR, "http://tizen.org/sensor/gyroscope"}, - {LIGHT_SENSOR, "http://tizen.org/sensor/light"}, - {PROXIMITY_SENSOR, "http://tizen.org/sensor/proximity"}, - {PRESSURE_SENSOR, "http://tizen.org/sensor/pressure"}, - {ULTRAVIOLET_SENSOR, "http://tizen.org/sensor/ultraviolet"}, - {TEMPERATURE_SENSOR, "http://tizen.org/sensor/temperature"}, - {HUMIDITY_SENSOR, "http://tizen.org/sensor/humidity"}, - {HRM_SENSOR, "http://tizen.org/sensor/heart_rate_monitor"}, - {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/heart_rate_monitor.led_green"}, - {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/heart_rate_monitor.led_ir"}, - {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/heart_rate_monitor.led_red"}, - {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/gyroscope.uncalibrated"}, - {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/geomagnetic.uncalibrated"}, - {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/gyroscope_rotation_vector"}, - {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/geomagnetic_rotation_vector"}, - - {HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/human_pedometer"}, - {HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/human_sleep_monitor"}, - {HUMAN_SLEEP_DETECTOR_SENSOR, "http://tizen.org/sensor/human_sleep_detector"}, - {HUMAN_STRESS_MONITOR_SENSOR, "http://tizen.org/sensor/human_stress_monitor"}, - - {EXERCISE_WALKING_SENSOR, "http://tizen.org/sensor/exercise.walking"}, - {EXERCISE_RUNNING_SENSOR, "http://tizen.org/sensor/exercise.running"}, - {EXERCISE_HIKING_SENSOR, "http://tizen.org/sensor/exercise.hiking"}, - {EXERCISE_CYCLING_SENSOR, "http://tizen.org/sensor/exercise.cycling"}, - {EXERCISE_ELLIPTICAL_SENSOR, "http://tizen.org/sensor/exercise.elliptical"}, - {EXERCISE_INDOOR_CYCLING_SENSOR, "http://tizen.org/sensor/exercise.indoor_cycling"}, - {EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/exercise.rowing"}, - {EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/exercise.stepper"}, - - {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/external_exercise"}, - - {FUSION_SENSOR, "http://tizen.org/sensor/fusion"}, - {AUTO_ROTATION_SENSOR, "http://tizen.org/sensor/auto_rotation"}, - {AUTO_BRIGHTNESS_SENSOR, "http://tizen.org/sensor/auto_brightness"}, - - {GESTURE_MOVEMENT_SENSOR, "http://tizen.org/sensor/gesture_movement"}, - {GESTURE_WRIST_UP_SENSOR, "http://tizen.org/sensor/gesture_wrist_up"}, - {GESTURE_WRIST_DOWN_SENSOR, "http://tizen.org/sensor/gesture_wrist_down"}, - {GESTURE_MOVEMENT_STATE_SENSOR, "http://tizen.org/sensor/gesture_movement_state"}, - {GESTURE_FACE_DOWN_SENSOR, "http://tizen.org/sensor/gesture_face_down"}, - - {ACTIVITY_TRACKER_SENSOR, "http://tizen.org/sensor/activity_tracker"}, - {ACTIVITY_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/activity_level_monitor"}, - {GPS_BATCH_SENSOR, "http://tizen.org/sensor/gps_batch"}, - - {HRM_CTRL_SENSOR, "http://tizen.org/sensor/hrm_ctrl"}, - - {WEAR_STATUS_SENSOR, "http://tizen.org/sensor/wear_status"}, - {WEAR_ON_MONITOR_SENSOR, "http://tizen.org/sensor/wear_on_monitor"}, - {NO_MOVE_DETECTOR_SENSOR, "http://tizen.org/sensor/no_move_detector"}, - {RESTING_HR_SENSOR, "http://tizen.org/sensor/resting_hr"}, - {STEP_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/step_level_monitor"}, - {EXERCISE_STANDALONE_SENSOR, "http://tizen.org/sensor/exercise_standalone"}, - {EXERCISE_HR_SENSOR, "http://tizen.org/sensor/exercise_hr"}, - {WORKOUT_SENSOR, "http://tizen.org/sensor/workout"}, - {CYCLE_MONITOR_SENSOR, "http://tizen.org/sensor/cycle_monitor"}, - {STAIR_TRACKER_SENSOR, "http://tizen.org/sensor/stair_tracker"}, - {PRESSURE_INDICATOR_SENSOR, "http://tizen.org/sensor/pressure_indicator"}, - {PRESSURE_ALERT_SENSOR, "http://tizen.org/sensor/pressure_alert"}, - {HR_CALORIE_SENSOR, "http://tizen.org/sensor/hr_calorie"}, - - {CONTEXT_SENSOR, "http://tizen.org/sensor/context"}, - {MOTION_SENSOR, "http://tizen.org/sensor/motion"}, - {PIR_SENSOR, "http://tizen.org/sensor/pir"}, - {PIR_LONG_SENSOR, "http://tizen.org/sensor/pir_long"}, - {DUST_SENSOR, "http://tizen.org/sensor/dust"}, - {THERMOMETER_SENSOR, "http://tizen.org/sensor/thermometer"}, - {PEDOMETER_SENSOR, "http://tizen.org/sensor/pedometer"}, - {FLAT_SENSOR, "http://tizen.org/sensor/flat"}, - {HRM_RAW_SENSOR, "http://tizen.org/sensor/hrm_raw"}, - {TILT_SENSOR, "http://tizen.org/sensor/tilt"}, - {RV_RAW_SENSOR, "http://tizen.org/sensor/rv_raw"}, - {GSR_SENSOR, "http://tizen.org/sensor/gsr"}, - {SIMSENSE_SENSOR, "http://tizen.org/sensor/simsense"}, - {PPG_SENSOR, "http://tizen.org/sensor/ppg"}, + {UNKNOWN_SENSOR, "http://tizen.org/sensor/general/unknown"}, + {ALL_SENSOR, "http://tizen.org/sensor/general/all"}, + {ACCELEROMETER_SENSOR, "http://tizen.org/sensor/general/accelerometer"}, + {GRAVITY_SENSOR, "http://tizen.org/sensor/general/gravity"}, + {LINEAR_ACCEL_SENSOR, "http://tizen.org/sensor/general/linear_acceleration"}, + {GEOMAGNETIC_SENSOR, "http://tizen.org/sensor/general/magnetic"}, + {ROTATION_VECTOR_SENSOR, "http://tizen.org/sensor/general/rotation_vector"}, + {ORIENTATION_SENSOR, "http://tizen.org/sensor/general/orientation"}, + {GYROSCOPE_SENSOR, "http://tizen.org/sensor/general/gyroscope"}, + {LIGHT_SENSOR, "http://tizen.org/sensor/general/light"}, + {PROXIMITY_SENSOR, "http://tizen.org/sensor/general/proximity"}, + {PRESSURE_SENSOR, "http://tizen.org/sensor/general/pressure"}, + {ULTRAVIOLET_SENSOR, "http://tizen.org/sensor/general/ultraviolet"}, + {TEMPERATURE_SENSOR, "http://tizen.org/sensor/general/temperature"}, + {HUMIDITY_SENSOR, "http://tizen.org/sensor/general/humidity"}, + {HRM_SENSOR, "http://tizen.org/sensor/healthinfo/heart_rate_monitor"}, + {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/healthinfo/heart_rate_monitor.led_green"}, + {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/healthinfo/heart_rate_monitor.led_ir"}, + {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/healthinfo/heart_rate_monitor.led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/general/gyroscope.uncalibrated"}, + {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/general/geomagnetic.uncalibrated"}, + {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/general/gyroscope_rotation_vector"}, + {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/general/geomagnetic_rotation_vector"}, + + {HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/human_pedometer"}, + {HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_monitor"}, + {HUMAN_SLEEP_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_detector"}, + {HUMAN_STRESS_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_stress_monitor"}, + + {EXERCISE_WALKING_SENSOR, "http://tizen.org/sensor/general/exercise.walking"}, + {EXERCISE_RUNNING_SENSOR, "http://tizen.org/sensor/general/exercise.running"}, + {EXERCISE_HIKING_SENSOR, "http://tizen.org/sensor/general/exercise.hiking"}, + {EXERCISE_CYCLING_SENSOR, "http://tizen.org/sensor/general/exercise.cycling"}, + {EXERCISE_ELLIPTICAL_SENSOR, "http://tizen.org/sensor/general/exercise.elliptical"}, + {EXERCISE_INDOOR_CYCLING_SENSOR, "http://tizen.org/sensor/general/exercise.indoor_cycling"}, + {EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/general/exercise.rowing"}, + {EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/general/exercise.stepper"}, + + {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/general/external_exercise"}, + + {FUSION_SENSOR, "http://tizen.org/sensor/general/fusion"}, + {AUTO_ROTATION_SENSOR, "http://tizen.org/sensor/general/auto_rotation"}, + {AUTO_BRIGHTNESS_SENSOR, "http://tizen.org/sensor/general/auto_brightness"}, + + {GESTURE_MOVEMENT_SENSOR, "http://tizen.org/sensor/general/gesture_movement"}, + {GESTURE_WRIST_UP_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_up"}, + {GESTURE_WRIST_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_wrist_down"}, + {GESTURE_MOVEMENT_STATE_SENSOR, "http://tizen.org/sensor/general/gesture_movement_state"}, + {GESTURE_FACE_DOWN_SENSOR, "http://tizen.org/sensor/general/gesture_face_down"}, + + {ACTIVITY_TRACKER_SENSOR, "http://tizen.org/sensor/general/activity_tracker"}, + {ACTIVITY_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/activity_level_monitor"}, + {GPS_BATCH_SENSOR, "http://tizen.org/sensor/general/gps_batch"}, + + {HRM_CTRL_SENSOR, "http://tizen.org/sensor/general/hrm_ctrl"}, + + {WEAR_STATUS_SENSOR, "http://tizen.org/sensor/general/wear_status"}, + {WEAR_ON_MONITOR_SENSOR, "http://tizen.org/sensor/general/wear_on_monitor"}, + {NO_MOVE_DETECTOR_SENSOR, "http://tizen.org/sensor/general/no_move_detector"}, + {RESTING_HR_SENSOR, "http://tizen.org/sensor/general/resting_hr"}, + {STEP_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/step_level_monitor"}, + {EXERCISE_STANDALONE_SENSOR, "http://tizen.org/sensor/general/exercise_standalone"}, + {EXERCISE_HR_SENSOR, "http://tizen.org/sensor/healthinfo/general/exercise_hr"}, + {WORKOUT_SENSOR, "http://tizen.org/sensor/general/workout"}, + {CYCLE_MONITOR_SENSOR, "http://tizen.org/sensor/general/cycle_monitor"}, + {STAIR_TRACKER_SENSOR, "http://tizen.org/sensor/general/stair_tracker"}, + {PRESSURE_INDICATOR_SENSOR, "http://tizen.org/sensor/general/pressure_indicator"}, + {PRESSURE_ALERT_SENSOR, "http://tizen.org/sensor/general/pressure_alert"}, + {HR_CALORIE_SENSOR, "http://tizen.org/sensor/general/hr_calorie"}, + + {CONTEXT_SENSOR, "http://tizen.org/sensor/general/context"}, + {MOTION_SENSOR, "http://tizen.org/sensor/general/motion"}, + {PIR_SENSOR, "http://tizen.org/sensor/general/pir"}, + {PIR_LONG_SENSOR, "http://tizen.org/sensor/general/pir_long"}, + {DUST_SENSOR, "http://tizen.org/sensor/general/dust"}, + {THERMOMETER_SENSOR, "http://tizen.org/sensor/general/thermometer"}, + {PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/general/pedometer"}, + {FLAT_SENSOR, "http://tizen.org/sensor/general/flat"}, + {HRM_RAW_SENSOR, "http://tizen.org/sensor/healthinfo/general/hrm_raw"}, + {TILT_SENSOR, "http://tizen.org/sensor/general/tilt"}, + {RV_RAW_SENSOR, "http://tizen.org/sensor/general/rv_raw"}, + {GSR_SENSOR, "http://tizen.org/sensor/healthinfo/general/gsr"}, + {SIMSENSE_SENSOR, "http://tizen.org/sensor/general/simsense"}, + {PPG_SENSOR, "http://tizen.org/sensor/healthinfo/general/ppg"}, }; const char *sensor::utils::get_uri(sensor_type_t type) @@ -130,6 +132,29 @@ const char *sensor::utils::get_uri(sensor_type_t type) return it->second; } +const char *sensor::utils::get_privilege(std::string uri) +{ + std::size_t start = 0; + std::size_t end = uri.length(); + std::size_t size = uri.size(); + + for (int i = 0; i < URI_PRIV_INDEX; ++i) { + retv_if(start >= uri.length(), ""); + start = uri.find(URI_DELIMITER, start + 1); + retv_if(start == std::string::npos, ""); + } + + end = uri.find(URI_DELIMITER, start + 1); + retv_if(end == std::string::npos, ""); + + size = end - (start + 1); + + if (uri.substr(start + 1, size) == PRIVILEGE_HEALTHINFO_STR) + return PRIVILEGE_HEALTHINFO_URI; + + return ""; +} + unsigned long long sensor::utils::get_timestamp(void) { struct timespec t; diff --git a/src/shared/sensor_utils.h b/src/shared/sensor_utils.h index 7e31f6d..8e80f27 100644 --- a/src/shared/sensor_utils.h +++ b/src/shared/sensor_utils.h @@ -29,6 +29,7 @@ namespace sensor { namespace utils { const char *get_uri(sensor_type_t type); + const char *get_privilege(std::string uri); unsigned long long get_timestamp(void); unsigned long long get_timestamp(timeval *t); -- 2.7.4 From 76f2b516c0e00d60f6933b1c408c330b1865a65a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 10 May 2017 18:12:40 +0900 Subject: [PATCH 02/16] sensord: specify the appropriate sensor type based on URI Change-Id: I4facc8b3b31ff2f2e19d9ebdefc0bdeea8ae2f8b Signed-off-by: kibak.yoon --- src/server/sensor_handler.cpp | 3 +++ src/shared/sensor_utils.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/shared/sensor_utils.h | 1 + 3 files changed, 43 insertions(+) diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index 4f16244..d72cfb8 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -30,6 +30,9 @@ sensor_handler::sensor_handler(const sensor_info &info) { const char *priv = sensor::utils::get_privilege(m_info.get_uri()); m_info.set_privilege(priv); + + sensor_type_t type = sensor::utils::get_type(m_info.get_uri()); + m_info.set_type(type); } bool sensor_handler::has_observer(sensor_observer *ob) diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 1f09e4b..729c53b 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -155,6 +155,45 @@ const char *sensor::utils::get_privilege(std::string uri) return ""; } +static void init_types(std::map &sensor_types) +{ + ret_if(!sensor_types.empty()); + + for (auto it = types.begin(); it != types.end(); ++it) { + std::string uri(it->second); + std::size_t found = uri.find_last_of("/"); + std::size_t len = uri.length() - (found + 1); + + sensor_types.emplace(uri.substr(found + 1, len), it->first); + } +} + +sensor_type_t sensor::utils::get_type(std::string uri) +{ + static std::map sensor_types; + init_types(sensor_types); + + std::size_t start = 0; + std::size_t end = uri.length(); + std::size_t size = uri.size(); + + for (int i = 0; i < URI_SENSOR_TYPE_INDEX; ++i) { + retv_if(start >= uri.length(), UNKNOWN_SENSOR); + start = uri.find(URI_DELIMITER, start + 1); + retv_if(start == std::string::npos, UNKNOWN_SENSOR); + } + + end = uri.find(URI_DELIMITER, start + 1); + retv_if(end == std::string::npos, UNKNOWN_SENSOR); + + size = end - (start + 1); + + auto it = sensor_types.find(uri.substr(start + 1, size)); + retv_if(it == sensor_types.end(), UNKNOWN_SENSOR); + + return it->second; +} + unsigned long long sensor::utils::get_timestamp(void) { struct timespec t; diff --git a/src/shared/sensor_utils.h b/src/shared/sensor_utils.h index 8e80f27..3497dc7 100644 --- a/src/shared/sensor_utils.h +++ b/src/shared/sensor_utils.h @@ -30,6 +30,7 @@ namespace sensor { namespace utils { const char *get_uri(sensor_type_t type); const char *get_privilege(std::string uri); + sensor_type_t get_type(std::string uri); unsigned long long get_timestamp(void); unsigned long long get_timestamp(timeval *t); -- 2.7.4 From 786f460a8409ea0fd17d1b8a597c833f57ffcbe4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 10 May 2017 20:51:25 +0900 Subject: [PATCH 03/16] sensord: fix typo errors about sensor URI - fix url of serveral healthinfo sensors Change-Id: I26339da8056abb8526393b9e1dfe31eeea6a8e98 Signed-off-by: kibak.yoon --- src/shared/sensor_utils.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 729c53b..21e13ea 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -67,16 +67,16 @@ static std::map types = { {HUMAN_SLEEP_DETECTOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_sleep_detector"}, {HUMAN_STRESS_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/human_stress_monitor"}, - {EXERCISE_WALKING_SENSOR, "http://tizen.org/sensor/general/exercise.walking"}, - {EXERCISE_RUNNING_SENSOR, "http://tizen.org/sensor/general/exercise.running"}, - {EXERCISE_HIKING_SENSOR, "http://tizen.org/sensor/general/exercise.hiking"}, - {EXERCISE_CYCLING_SENSOR, "http://tizen.org/sensor/general/exercise.cycling"}, - {EXERCISE_ELLIPTICAL_SENSOR, "http://tizen.org/sensor/general/exercise.elliptical"}, - {EXERCISE_INDOOR_CYCLING_SENSOR, "http://tizen.org/sensor/general/exercise.indoor_cycling"}, - {EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/general/exercise.rowing"}, - {EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/general/exercise.stepper"}, + {EXERCISE_WALKING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.walking"}, + {EXERCISE_RUNNING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.running"}, + {EXERCISE_HIKING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.hiking"}, + {EXERCISE_CYCLING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.cycling"}, + {EXERCISE_ELLIPTICAL_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.elliptical"}, + {EXERCISE_INDOOR_CYCLING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.indoor_cycling"}, + {EXERCISE_ROWING_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.rowing"}, + {EXERCISE_STEPPER_SENSOR, "http://tizen.org/sensor/healthinfo/exercise.stepper"}, - {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/general/external_exercise"}, + {EXTERNAL_EXERCISE_SENSOR, "http://tizen.org/sensor/healthinfo/external_exercise"}, {FUSION_SENSOR, "http://tizen.org/sensor/general/fusion"}, {AUTO_ROTATION_SENSOR, "http://tizen.org/sensor/general/auto_rotation"}, @@ -97,16 +97,16 @@ static std::map types = { {WEAR_STATUS_SENSOR, "http://tizen.org/sensor/general/wear_status"}, {WEAR_ON_MONITOR_SENSOR, "http://tizen.org/sensor/general/wear_on_monitor"}, {NO_MOVE_DETECTOR_SENSOR, "http://tizen.org/sensor/general/no_move_detector"}, - {RESTING_HR_SENSOR, "http://tizen.org/sensor/general/resting_hr"}, - {STEP_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/step_level_monitor"}, - {EXERCISE_STANDALONE_SENSOR, "http://tizen.org/sensor/general/exercise_standalone"}, - {EXERCISE_HR_SENSOR, "http://tizen.org/sensor/healthinfo/general/exercise_hr"}, - {WORKOUT_SENSOR, "http://tizen.org/sensor/general/workout"}, - {CYCLE_MONITOR_SENSOR, "http://tizen.org/sensor/general/cycle_monitor"}, - {STAIR_TRACKER_SENSOR, "http://tizen.org/sensor/general/stair_tracker"}, + {RESTING_HR_SENSOR, "http://tizen.org/sensor/healthinfo/resting_hr"}, + {STEP_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/step_level_monitor"}, + {EXERCISE_STANDALONE_SENSOR, "http://tizen.org/sensor/healthinfo/exercise_standalone"}, + {EXERCISE_HR_SENSOR, "http://tizen.org/sensor/healthinfo/exercise_hr"}, + {WORKOUT_SENSOR, "http://tizen.org/sensor/healthinfo/workout"}, + {CYCLE_MONITOR_SENSOR, "http://tizen.org/sensor/healthinfo/cycle_monitor"}, + {STAIR_TRACKER_SENSOR, "http://tizen.org/sensor/healthinfo/stair_tracker"}, {PRESSURE_INDICATOR_SENSOR, "http://tizen.org/sensor/general/pressure_indicator"}, {PRESSURE_ALERT_SENSOR, "http://tizen.org/sensor/general/pressure_alert"}, - {HR_CALORIE_SENSOR, "http://tizen.org/sensor/general/hr_calorie"}, + {HR_CALORIE_SENSOR, "http://tizen.org/sensor/healthinfo/hr_calorie"}, {CONTEXT_SENSOR, "http://tizen.org/sensor/general/context"}, {MOTION_SENSOR, "http://tizen.org/sensor/general/motion"}, @@ -114,14 +114,14 @@ static std::map types = { {PIR_LONG_SENSOR, "http://tizen.org/sensor/general/pir_long"}, {DUST_SENSOR, "http://tizen.org/sensor/general/dust"}, {THERMOMETER_SENSOR, "http://tizen.org/sensor/general/thermometer"}, - {PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/general/pedometer"}, + {PEDOMETER_SENSOR, "http://tizen.org/sensor/healthinfo/pedometer"}, {FLAT_SENSOR, "http://tizen.org/sensor/general/flat"}, - {HRM_RAW_SENSOR, "http://tizen.org/sensor/healthinfo/general/hrm_raw"}, + {HRM_RAW_SENSOR, "http://tizen.org/sensor/healthinfo/hrm_raw"}, {TILT_SENSOR, "http://tizen.org/sensor/general/tilt"}, {RV_RAW_SENSOR, "http://tizen.org/sensor/general/rv_raw"}, - {GSR_SENSOR, "http://tizen.org/sensor/healthinfo/general/gsr"}, - {SIMSENSE_SENSOR, "http://tizen.org/sensor/general/simsense"}, - {PPG_SENSOR, "http://tizen.org/sensor/healthinfo/general/ppg"}, + {GSR_SENSOR, "http://tizen.org/sensor/healthinfo/gsr"}, + {SIMSENSE_SENSOR, "http://tizen.org/sensor/healthinfo/simsense"}, + {PPG_SENSOR, "http://tizen.org/sensor/healthinfo/ppg"}, }; const char *sensor::utils::get_uri(sensor_type_t type) -- 2.7.4 From 22bab7c34dded30f03f921c22b62a7215f85d912 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 10 May 2017 22:20:27 +0900 Subject: [PATCH 04/16] sensord: add location privilege to location-related sensors Change-Id: Ib931902c518fd67e62fb7e7dc2d8cd6340d792b3 Signed-off-by: kibak.yoon --- src/server/sensor_handler.cpp | 11 +++++++++++ src/server/server_channel_handler.cpp | 5 ++--- src/shared/sensor_info.cpp | 8 ++++++++ src/shared/sensor_info.h | 1 + src/shared/sensor_types_private.h | 5 +++++ src/shared/sensor_utils.cpp | 4 +++- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/server/sensor_handler.cpp b/src/server/sensor_handler.cpp index d72cfb8..2a2eb6a 100644 --- a/src/server/sensor_handler.cpp +++ b/src/server/sensor_handler.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace sensor; @@ -33,6 +34,16 @@ sensor_handler::sensor_handler(const sensor_info &info) sensor_type_t type = sensor::utils::get_type(m_info.get_uri()); m_info.set_type(type); + + /* TODO: temporary walkaround for sensors that require multiple privileges */ + switch (m_info.get_type()) { + case EXTERNAL_EXERCISE_SENSOR: + case EXERCISE_STANDALONE_SENSOR: + m_info.add_privilege(PRIVILEGE_LOCATION_URI); + break; + default: + break; + } } bool sensor_handler::has_observer(sensor_observer *ob) diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index 88c48e4..f20008c 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -23,13 +23,12 @@ #include #include #include +#include #include #include "permission_checker.h" #include "application_sensor_handler.h" -#define PRIV_DELIMINATOR ";" - using namespace sensor; using namespace ipc; @@ -397,7 +396,7 @@ bool server_channel_handler::has_privilege(int fd, std::string &priv) bool server_channel_handler::has_privileges(int fd, std::string priv) { std::vector privileges; - privileges = utils::tokenize(priv, PRIV_DELIMINATOR); + privileges = utils::tokenize(priv, PRIV_DELIMITER); for (auto it = privileges.begin(); it != privileges.end(); ++it) { if (!has_privilege(fd, *it)) diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index c2d95c3..e56be7e 100644 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -20,6 +20,7 @@ #include "sensor_info.h" #include +#include #include #include #include @@ -207,6 +208,13 @@ void sensor_info::set_privilege(const char *privilege) m_privilege = privilege; } +void sensor_info::add_privilege(const char *privilege) +{ + if (!m_privilege.empty()) + m_privilege.append(PRIV_DELIMITER); + m_privilege.append(privilege); +} + void sensor_info::serialize(raw_data_t &data) { put(data, m_type); diff --git a/src/shared/sensor_info.h b/src/shared/sensor_info.h index 91b6ba8..d07b5b8 100644 --- a/src/shared/sensor_info.h +++ b/src/shared/sensor_info.h @@ -63,6 +63,7 @@ public: void set_max_batch_count(int max_batch_count); void set_wakeup_supported(bool supported); void set_privilege(const char *privilege); + void add_privilege(const char *privilege); void clear(void); diff --git a/src/shared/sensor_types_private.h b/src/shared/sensor_types_private.h index b1c49f3..d0ed9e2 100644 --- a/src/shared/sensor_types_private.h +++ b/src/shared/sensor_types_private.h @@ -25,10 +25,15 @@ #define PREDEFINED_TYPE_URI "http://tizen.org/sensor/" +#define PRIV_DELIMITER ";" #define URI_DELIMITER "/" + #define PRIVILEGE_HEALTHINFO_STR "healthinfo" #define PRIVILEGE_HEALTHINFO_URI "http://tizen.org/privilege/healthinfo" +#define PRIVILEGE_LOCATION_STR "location" +#define PRIVILEGE_LOCATION_URI "http://tizen.org/privilege/location" + #define URI_PRIV_INDEX 4 #define URI_SENSOR_TYPE_INDEX 5 diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 21e13ea..16341cc 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -90,7 +90,7 @@ static std::map types = { {ACTIVITY_TRACKER_SENSOR, "http://tizen.org/sensor/general/activity_tracker"}, {ACTIVITY_LEVEL_MONITOR_SENSOR, "http://tizen.org/sensor/general/activity_level_monitor"}, - {GPS_BATCH_SENSOR, "http://tizen.org/sensor/general/gps_batch"}, + {GPS_BATCH_SENSOR, "http://tizen.org/sensor/location/gps_batch"}, {HRM_CTRL_SENSOR, "http://tizen.org/sensor/general/hrm_ctrl"}, @@ -151,6 +151,8 @@ const char *sensor::utils::get_privilege(std::string uri) if (uri.substr(start + 1, size) == PRIVILEGE_HEALTHINFO_STR) return PRIVILEGE_HEALTHINFO_URI; + else if (uri.substr(start + 1, size) == PRIVILEGE_LOCATION_STR) + return PRIVILEGE_LOCATION_URI; return ""; } -- 2.7.4 From aa59628dbd970bf16627146de04e1eb82d3d2505 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 16 May 2017 14:16:09 +0900 Subject: [PATCH 05/16] sensord: rename set_interval_cb to interval_changed_cb Change-Id: I9f7dd165b8b4a2aa3f244c4f5061f1b96d0cec84 Signed-off-by: kibak.yoon --- include/sensor_internal.h | 4 ++-- src/client-dummy/client_dummy.cpp | 2 +- src/client/sensor_internal.cpp | 2 +- src/client/sensor_provider.cpp | 2 +- src/client/sensor_provider.h | 2 +- src/client/sensor_provider_channel_handler.cpp | 14 +++++++------- src/client/sensor_provider_channel_handler.h | 6 +++--- src/sensorctl/testcase/unit_provider.cpp | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/sensor_internal.h b/include/sensor_internal.h index 49609b6..ee3b375 100644 --- a/include/sensor_internal.h +++ b/include/sensor_internal.h @@ -420,8 +420,8 @@ int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_ typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data); int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data); -typedef void (*sensord_provider_set_interval_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data); -int sensord_provider_set_set_interval_cb(sensord_provider_h provider, sensord_provider_set_interval_cb callback, void *user_data); +typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data); +int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data); int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data); diff --git a/src/client-dummy/client_dummy.cpp b/src/client-dummy/client_dummy.cpp index 63ae2ea..ee8cde3 100644 --- a/src/client-dummy/client_dummy.cpp +++ b/src/client-dummy/client_dummy.cpp @@ -290,7 +290,7 @@ API int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provid return OP_ERROR; } -API int sensord_provider_set_set_interval_cb(sensord_provider_h provider, sensord_provider_set_interval_cb callback, void *user_data) +API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data) { return OP_ERROR; } diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index dcd497a..fe3e554 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -732,7 +732,7 @@ API int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provid return OP_SUCCESS; } -API int sensord_provider_set_set_interval_cb(sensord_provider_h provider, sensord_provider_set_interval_cb callback, void *user_data) +API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data) { retvm_if(!provider, -EINVAL, "Invalid paramter"); retvm_if(!callback, -EINVAL, "Invalid paramter"); diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index 94036e0..f2eae8b 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -199,7 +199,7 @@ void sensor_provider::set_stop_cb(sensord_provider_stop_cb cb, void *user_data) m_handler->set_stop_cb(cb, user_data); } -void sensor_provider::set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data) +void sensor_provider::set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data) { m_handler->set_interval_cb(cb, user_data); } diff --git a/src/client/sensor_provider.h b/src/client/sensor_provider.h index b499995..2191b60 100644 --- a/src/client/sensor_provider.h +++ b/src/client/sensor_provider.h @@ -46,7 +46,7 @@ public: void set_start_cb(sensord_provider_start_cb cb, void *user_data); void set_stop_cb(sensord_provider_stop_cb cb, void *user_data); - void set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data); + void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data); int publish(sensor_data_t *data, int len); diff --git a/src/client/sensor_provider_channel_handler.cpp b/src/client/sensor_provider_channel_handler.cpp index 52cc6bf..ed3fd01 100644 --- a/src/client/sensor_provider_channel_handler.cpp +++ b/src/client/sensor_provider_channel_handler.cpp @@ -29,10 +29,10 @@ sensor_provider::channel_handler::channel_handler(sensor_provider *provider) : m_provider(provider) , m_start_cb(NULL) , m_stop_cb(NULL) -, m_set_interval_cb(NULL) +, m_interval_changed_cb(NULL) , m_start_user_data(NULL) , m_stop_user_data(NULL) -, m_set_interval_user_data(NULL) +, m_interval_changed_user_data(NULL) { } @@ -62,8 +62,8 @@ void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg) cmd_provider_attr_int_t buf; msg.disclose((char *)&buf); - if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_set_interval_cb) - m_set_interval_cb(m_provider, buf.value, m_set_interval_user_data); + if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_interval_changed_cb) + m_interval_changed_cb(m_provider, buf.value, m_interval_changed_user_data); break; } } @@ -88,8 +88,8 @@ void sensor_provider::channel_handler::set_stop_cb(sensord_provider_stop_cb cb, m_stop_user_data = user_data; } -void sensor_provider::channel_handler::set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data) +void sensor_provider::channel_handler::set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data) { - m_set_interval_cb = cb; - m_set_interval_user_data = user_data; + m_interval_changed_cb = cb; + m_interval_changed_user_data = user_data; } diff --git a/src/client/sensor_provider_channel_handler.h b/src/client/sensor_provider_channel_handler.h index efe5ce5..877f9db 100644 --- a/src/client/sensor_provider_channel_handler.h +++ b/src/client/sensor_provider_channel_handler.h @@ -40,18 +40,18 @@ public: void set_start_cb(sensord_provider_start_cb cb, void *user_data); void set_stop_cb(sensord_provider_stop_cb cb, void *user_data); - void set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data); + void set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data); private: sensor_provider *m_provider; sensord_provider_start_cb m_start_cb; sensord_provider_stop_cb m_stop_cb; - sensord_provider_set_interval_cb m_set_interval_cb; + sensord_provider_interval_changed_cb m_interval_changed_cb; void *m_start_user_data; void *m_stop_user_data; - void *m_set_interval_user_data; + void *m_interval_changed_user_data; }; } diff --git a/src/sensorctl/testcase/unit_provider.cpp b/src/sensorctl/testcase/unit_provider.cpp index 89ae9e3..0c61862 100644 --- a/src/sensorctl/testcase/unit_provider.cpp +++ b/src/sensorctl/testcase/unit_provider.cpp @@ -164,7 +164,7 @@ TESTCASE(sensor_api_provider_mysensor, provider_p_1) ASSERT_EQ(err, 0); err = sensord_provider_set_stop_cb(provider, stop_cb, NULL); ASSERT_EQ(err, 0); - err = sensord_provider_set_set_interval_cb(provider, interval_cb, NULL); + err = sensord_provider_set_interval_changed_cb(provider, interval_cb, NULL); ASSERT_EQ(err, 0); err = sensord_get_default_sensor_by_uri(MYSENSOR_URI, &sensor); -- 2.7.4 From 17d34a8dfba5522383ecfa0f21c2190750b75d76 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 15 May 2017 18:45:39 +0900 Subject: [PATCH 06/16] Temporary fix for build errors from Tizen 3.0 snapshots This patch enables to build other packages requiring pkgconfig(sensor), when you need to build & install the latest sensord for Tizen 3.0 devices. Change-Id: Ib70d2236d8b1beaf8d0a7040af5540df502de547 Signed-off-by: Mu-Woong Lee --- packaging/sensord.spec | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 45901e6..cd7496c 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -46,7 +46,7 @@ Summary: Internal Sensor API (Development) Group: System/Development Requires: %{name}-dummy = %{version}-%{release} # To support old-snapshot-based package builds -Provides: libsensord-devel +#Provides: libsensord-devel %description devel Internal Sensor API (Development) @@ -138,3 +138,28 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall %files -n sensor-test %{_bindir}/sensorctl + + +# Dummy packages for Tizen 3.0. +# When building other packages on Tizen 3.0, after building sensord first, +# some dependency conflicts may occur. These dummy packages may fix such +# dependency issues. +%package -n libsensord +Summary: Dummy libsensord +Requires: sensord-dummy +Group: System/Sensor Framework + +%description -n libsensord +Dummy libsensord + +%files -n libsensord + +%package -n libsensord-devel +Summary: Dummy libsensord-devel +Requires: sensord-devel +Group: System/Sensor Framework + +%description -n libsensord-devel +Dummy libsensord-devel + +%files -n libsensord-devel -- 2.7.4 From 74e889e2b43586b60dce12fbd6ceba49df219a04 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 18 May 2017 15:37:34 +0900 Subject: [PATCH 07/16] sensord: remove command when manager/listener/provider are disconnected - if channel is disconnected(), server releases their resources automatically. - so it is not neccessary to release resource by sending command. Change-Id: Ifd4ed14b20429def377f10d5a6d5dd3da18efc86 Signed-off-by: kibak.yoon --- src/client/sensor_listener.cpp | 8 ------- src/client/sensor_manager.cpp | 11 +-------- src/client/sensor_provider.cpp | 9 ------- src/server/server_channel_handler.cpp | 44 ----------------------------------- src/shared/command_types.h | 10 -------- 5 files changed, 1 insertion(+), 81 deletions(-) diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index 0e66ef7..9eedd6d 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -182,15 +182,7 @@ void sensor_listener::disconnect(void) ret_if(!is_connected()); m_connected.store(false); - ipc::message msg; - ipc::message reply; - - msg.set_type(CMD_LISTENER_DISCONNECT); - m_evt_channel->send_sync(&msg); - - m_evt_channel->read_sync(reply); m_evt_channel->disconnect(); - delete m_evt_channel; m_evt_channel = NULL; diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 43fcb41..760a90b 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -222,17 +222,9 @@ bool sensor_manager::connect(void) void sensor_manager::disconnect(void) { ret_if(!is_connected()); - - ipc::message msg; - ipc::message reply; - msg.set_type(CMD_MANAGER_DISCONNECT); - - m_mon_channel->send_sync(&msg); - m_mon_channel->read_sync(reply); - retm_if(reply.header()->err < 0, "Failed to disconnect"); + m_connected.store(false); m_mon_channel->disconnect(); - delete m_mon_channel; m_mon_channel = NULL; @@ -240,7 +232,6 @@ void sensor_manager::disconnect(void) delete m_cmd_channel; m_cmd_channel = NULL; - m_connected.store(false); _D("Disconnected"); } diff --git a/src/client/sensor_provider.cpp b/src/client/sensor_provider.cpp index f2eae8b..50772d5 100644 --- a/src/client/sensor_provider.cpp +++ b/src/client/sensor_provider.cpp @@ -147,16 +147,7 @@ bool sensor_provider::disconnect(void) retv_if(!is_connected(), false); m_connected.store(false); - ipc::message msg(OP_SUCCESS); - ipc::message reply; - - msg.set_type(CMD_PROVIDER_DISCONNECT); - - m_channel->send_sync(&msg); - m_channel->read_sync(reply); - m_channel->disconnect(); - delete m_channel; m_channel = NULL; diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index f20008c..fbcb6cb 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -81,14 +81,10 @@ void server_channel_handler::read(channel *ch, message &msg) switch (msg.type()) { case CMD_MANAGER_CONNECT: err = manager_connect(ch, msg); break; - case CMD_MANAGER_DISCONNECT: - err = manager_disconnect(ch, msg); break; case CMD_MANAGER_SENSOR_LIST: err = manager_get_sensor_list(ch, msg); break; case CMD_LISTENER_CONNECT: err = listener_connect(ch, msg); break; - case CMD_LISTENER_DISCONNECT: - err = listener_disconnect(ch, msg); break; case CMD_LISTENER_START: err = listener_start(ch, msg); break; case CMD_LISTENER_STOP: @@ -101,8 +97,6 @@ void server_channel_handler::read(channel *ch, message &msg) err = listener_get_data(ch, msg); break; case CMD_PROVIDER_CONNECT: err = provider_connect(ch, msg); break; - case CMD_PROVIDER_DISCONNECT: - err = provider_disconnect(ch, msg); break; case CMD_PROVIDER_PUBLISH: err = provider_publish(ch, msg); break; case CMD_HAS_PRIVILEGE: @@ -122,12 +116,6 @@ int server_channel_handler::manager_connect(channel *ch, message &msg) return OP_SUCCESS; } -int server_channel_handler::manager_disconnect(channel *ch, message &msg) -{ - m_manager->deregister_channel(ch); - return send_reply(ch, OP_SUCCESS); -} - int server_channel_handler::manager_get_sensor_list(channel *ch, message &msg) { ipc::message reply; @@ -177,25 +165,6 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) return OP_SUCCESS; } -int server_channel_handler::listener_disconnect(channel *ch, message &msg) -{ - auto it = m_listener_ids.find(ch); - retv_if(it == m_listener_ids.end(), -EINVAL); - - uint32_t id = it->second; - - retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); - - delete m_listeners[id]; - m_listeners.erase(id); - m_listener_ids.erase(ch); - - _D("Disconnected sensor_listener[%u]", id); - - return send_reply(ch, OP_SUCCESS); -} - int server_channel_handler::listener_start(channel *ch, message &msg) { cmd_listener_start_t buf; @@ -335,19 +304,6 @@ int server_channel_handler::provider_connect(channel *ch, message &msg) return send_reply(ch, OP_SUCCESS); } -int server_channel_handler::provider_disconnect(channel *ch, message &msg) -{ - auto it = m_app_sensors.find(ch); - retv_if(it == m_app_sensors.end(), -EINVAL); - - sensor_info info = it->second->get_sensor_info(); - - m_manager->deregister_sensor(info.get_uri()); - m_app_sensors.erase(ch); - - return send_reply(ch, OP_SUCCESS); -} - int server_channel_handler::provider_publish(channel *ch, message &msg) { auto it = m_app_sensors.find(ch); diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 6ea1523..a994f29 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -33,7 +33,6 @@ enum cmd_type_e { /* Manager */ CMD_MANAGER_CONNECT = 0x100, - CMD_MANAGER_DISCONNECT, CMD_MANAGER_SENSOR_LIST, CMD_MANAGER_SENSOR_ADDED, CMD_MANAGER_SENSOR_REMOVED, @@ -42,7 +41,6 @@ enum cmd_type_e { CMD_LISTENER_EVENT = 0x200, CMD_LISTENER_ACC_EVENT, CMD_LISTENER_CONNECT, - CMD_LISTENER_DISCONNECT, CMD_LISTENER_START, CMD_LISTENER_STOP, CMD_LISTENER_ATTR_INT, @@ -51,7 +49,6 @@ enum cmd_type_e { /* Provider */ CMD_PROVIDER_CONNECT = 0x300, - CMD_PROVIDER_DISCONNECT, CMD_PROVIDER_START, CMD_PROVIDER_STOP, CMD_PROVIDER_ATTR_INT, @@ -75,10 +72,6 @@ typedef struct { typedef struct { int listener_id; -} cmd_listener_disconnect_t; - -typedef struct { - int listener_id; } cmd_listener_start_t; typedef struct { @@ -109,9 +102,6 @@ typedef struct { } cmd_provider_connect_t; typedef struct { -} cmd_provider_disconnect_t; - -typedef struct { sensor_data_t data; } cmd_provider_publish_t; -- 2.7.4 From f550470b75ef2a7d34ce5ca5e797c0902dd9aea3 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 5 Jun 2017 10:57:30 +0900 Subject: [PATCH 08/16] sensord: fix bug to enable external sensor on rpi3 Change-Id: I9013a23afefc2e8fbcbb861a6afa74b499641884 Signed-off-by: kibak.yoon --- src/server/external_sensor_handler.cpp | 3 +++ src/server/sensor_manager.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/external_sensor_handler.cpp b/src/server/external_sensor_handler.cpp index 53381b9..7b3e7da 100644 --- a/src/server/external_sensor_handler.cpp +++ b/src/server/external_sensor_handler.cpp @@ -59,6 +59,7 @@ int external_sensor_notifier::notify(void) external_sensor_handler::external_sensor_handler(const sensor_info &info, external_sensor *sensor) : sensor_handler(info) +, m_sensor(sensor) , m_notifier(NULL) , m_policy(OP_DEFAULT) { @@ -97,6 +98,8 @@ int external_sensor_handler::start(sensor_observer *ob) int policy = m_sensor->start(ob); retv_if(policy <= OP_ERROR, policy); + add_observer(ob); + return OP_SUCCESS; } diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index 601c5ef..dc602ff 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -65,7 +65,7 @@ bool sensor_manager::init(void) m_loader.load_fusion_sensor(VIRTUAL_SENSOR_DIR_PATH, fusion_sensors); m_loader.load_external_sensor(EXTERNAL_SENSOR_DIR_PATH, external_sensors); - retvm_if(devices.empty(), false, "There is no sensors"); + retvm_if(devices.empty() && external_sensors.empty(), false, "There is no sensors"); /* TODO: support dynamic sensor */ create_physical_sensors(devices, physical_sensors); -- 2.7.4 From 2b07ad19db3cbf77800bc18d7195a88434b5738c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 7 Jun 2017 17:38:06 +0900 Subject: [PATCH 09/16] sensord: add select() before read a data to check whether it is ready or not Change-Id: Id39cffc0107771dcdec0f7d23da6b36f39af0fbe Signed-off-by: kibak.yoon --- src/shared/channel.cpp | 8 ++++---- src/shared/channel.h | 2 +- src/shared/channel_event_handler.cpp | 2 +- src/shared/socket.cpp | 13 ++++++++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index 8549f1e..e407aee 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -77,7 +77,7 @@ public: if (condition & (EVENT_OUT | EVENT_HUP)) return false; - if (!m_ch->read_sync(msg)) + if (!m_ch->read_sync(msg, false)) return false; return false; @@ -202,14 +202,14 @@ bool channel::read(void) return true; } -bool channel::read_sync(message &msg) +bool channel::read_sync(message &msg, bool select) { message_header header; ssize_t size = 0; char buf[MAX_MSG_CAPACITY]; /* header */ - size = m_socket->recv(&header, sizeof(message_header), true); + size = m_socket->recv(&header, sizeof(message_header), select); retv_if(size <= 0, false); /* check error from header */ @@ -221,7 +221,7 @@ bool channel::read_sync(message &msg) /* body */ if (header.length > 0) { - size = m_socket->recv(&buf, header.length, true); + size = m_socket->recv(&buf, header.length, select); retv_if(size <= 0, false); } diff --git a/src/shared/channel.h b/src/shared/channel.h index db709b6..f8c525c 100644 --- a/src/shared/channel.h +++ b/src/shared/channel.h @@ -51,7 +51,7 @@ public: bool send_sync(message *msg); bool read(void); - bool read_sync(message &msg); + bool read_sync(message &msg, bool select = true); bool get_option(int type, int &value) const; bool set_option(int type, int value); diff --git a/src/shared/channel_event_handler.cpp b/src/shared/channel_event_handler.cpp index 9045a88..6ca1e25 100644 --- a/src/shared/channel_event_handler.cpp +++ b/src/shared/channel_event_handler.cpp @@ -51,7 +51,7 @@ bool channel_event_handler::handle(int fd, event_condition condition) return false; } - if (!m_ch->read_sync(msg)) { + if (!m_ch->read_sync(msg, false)) { m_ch->disconnect(); delete m_ch; m_ch = NULL; diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp index 871031f..f053dbc 100644 --- a/src/shared/socket.cpp +++ b/src/shared/socket.cpp @@ -310,7 +310,18 @@ ssize_t socket::send(const void *buffer, size_t size, bool select) const ssize_t socket::recv(void* buffer, size_t size, bool select) const { - /* WARNING: if select() is called here, it affects performance */ + if (select) { + const int TIMEOUT = 1; + fd_set read_fds; + FD_ZERO(&read_fds); + FD_SET(m_sock_fd, &read_fds); + + if (!select_fds(m_sock_fd, &read_fds, NULL, TIMEOUT)) { + _E("Failed to receive message(timeout)"); + return 0; + } + } + return on_recv(buffer, size); } -- 2.7.4 From 9d2e31e0585ec0873113fbdcae662808f0f83745 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Jun 2017 13:05:13 +0900 Subject: [PATCH 10/16] sensord: remove redundant blank lines at the end of a code block Change-Id: I90276bc03a6ddd2fb73fa5eb78ab16aa386c8ad0 Signed-off-by: kibak.yoon --- include/sensor_hal_types.h | 1 - src/server/sensor_manager.cpp | 1 - src/shared/seqpacket_socket.h | 1 - 3 files changed, 3 deletions(-) diff --git a/include/sensor_hal_types.h b/include/sensor_hal_types.h index 6ad991d..6910e30 100644 --- a/include/sensor_hal_types.h +++ b/include/sensor_hal_types.h @@ -126,7 +126,6 @@ typedef enum { SENSOR_DEVICE_GSR, SENSOR_DEVICE_SIMSENSE, SENSOR_DEVICE_PPG, - } sensor_device_type; /* diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index dc602ff..3af7ca9 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -257,7 +257,6 @@ void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices, m_sensors[sinfo.get_uri()] = psensor; } } - } void sensor_manager::create_fusion_sensors(fusion_sensor_registry_t &fsensors) diff --git a/src/shared/seqpacket_socket.h b/src/shared/seqpacket_socket.h index 5614903..05c25d8 100644 --- a/src/shared/seqpacket_socket.h +++ b/src/shared/seqpacket_socket.h @@ -34,7 +34,6 @@ public: private: ssize_t on_send(const void *buffer, size_t size) const; ssize_t on_recv(void *buffer, size_t size) const; - }; } -- 2.7.4 From eba8cbb954d7b717c491b19977b9195e1f6a8819 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 14 Jun 2017 19:13:14 +0900 Subject: [PATCH 11/16] sensord: send accuracy changed event to listeners Change-Id: Idfcf4217ef2694578857c032e60ad55950198452 Signed-off-by: kibak.yoon --- src/server/sensor_listener_proxy.cpp | 31 ++++++++++++++++++++++++++++++- src/server/sensor_listener_proxy.h | 4 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 7c20c90..51b38a9 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -38,6 +38,7 @@ sensor_listener_proxy::sensor_listener_proxy(uint32_t id, , m_passive(false) , m_pause_policy(SENSORD_PAUSE_ALL) , m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED) +, m_last_accuracy(SENSOR_ACCURACY_UNDEFINED) { } @@ -55,13 +56,41 @@ int sensor_listener_proxy::update(const char *uri, ipc::message *msg) { retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE); + update_event(msg); + update_accuracy(msg); + + return OP_CONTINUE; +} + +void sensor_listener_proxy::update_event(ipc::message *msg) +{ /* TODO: check axis orientation */ msg->header()->type = CMD_LISTENER_EVENT; msg->header()->err = OP_SUCCESS; m_ch->send(msg); +} - return OP_CONTINUE; +void sensor_listener_proxy::update_accuracy(ipc::message *msg) +{ + sensor_data_t *data = reinterpret_cast(msg->body()); + + if (data->accuracy == m_last_accuracy) + return; + + m_last_accuracy = data->accuracy; + + sensor_data_t acc_data; + acc_data.accuracy = m_last_accuracy; + + ipc::message *acc_msg = new(std::nothrow) ipc::message(); + retm_if(!acc_msg, "Failed to allocate memory"); + + acc_msg->header()->type = CMD_LISTENER_ACC_EVENT; + acc_msg->header()->err = OP_SUCCESS; + acc_msg->enclose(&acc_data, sizeof(acc_data)); + + m_ch->send(acc_msg); } int sensor_listener_proxy::start(void) diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index 05bc453..30e3976 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -52,6 +52,9 @@ public: std::string get_required_privileges(void); private: + void update_event(ipc::message *msg); + void update_accuracy(ipc::message *msg); + uint32_t m_id; std::string m_uri; @@ -61,6 +64,7 @@ private: bool m_passive; int m_pause_policy; int m_axis_orientation; + int m_last_accuracy; }; } -- 2.7.4 From 866a049c502fc49ec750e02048cecb2e3fbe57ea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 14 Jun 2017 20:17:15 +0900 Subject: [PATCH 12/16] sensord: rv: fix bug that the accuracy value is not changed Change-Id: I9a3020ae8e748e09dbb79e0e2f13cc8c3208d65d Signed-off-by: kibak.yoon --- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 6 ++---- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 4 +--- src/sensor/rotation_vector/rv_sensor.cpp | 4 +--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 478e2ee..850118f 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -87,16 +87,14 @@ int gyro_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) else if (id == SRC_ID_GYRO) m_fusion.push_gyro(*data); - if (m_accuracy > data->accuracy) - m_accuracy = data->accuracy; - if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) return OP_ERROR; - if(timestamp == m_time) + if (timestamp == m_time) return OP_ERROR; m_time = timestamp; + m_accuracy = data->accuracy; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); return OP_SUCCESS; diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index ef438ad..5e4cd74 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -87,9 +87,6 @@ int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) else if (id == SRC_ID_MAG) m_fusion.push_mag(*data); - if (m_accuracy > data->accuracy) - m_accuracy = data->accuracy; - if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) return OP_ERROR; @@ -97,6 +94,7 @@ int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) return OP_ERROR; m_time = timestamp; + m_accuracy = data->accuracy; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); return OP_SUCCESS; diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index cb37f42..c69cb6b 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -93,9 +93,6 @@ int rv_sensor::update(uint32_t id, sensor_data_t *data, int len) else if (id == SRC_ID_GYRO) m_fusion.push_gyro(*data); - if (m_accuracy > data->accuracy) - m_accuracy = data->accuracy; - if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) return OP_ERROR; @@ -103,6 +100,7 @@ int rv_sensor::update(uint32_t id, sensor_data_t *data, int len) return OP_ERROR; m_time = timestamp; + m_accuracy = data->accuracy; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); return OP_SUCCESS; -- 2.7.4 From 225da6f36fc7e6d75b888283d6710cb259e60d99 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 15 Jun 2017 16:58:32 +0900 Subject: [PATCH 13/16] sensord: fix bugs with using invalid format in logs Change-Id: Ide24272d63a24611aba81a5fe0114e62cebeb1fe Signed-off-by: kibak.yoon --- src/client/sensor_internal.cpp | 38 +++++++++++++++++++------------------- src/client/sensor_manager.cpp | 2 +- src/shared/seqpacket_socket.cpp | 6 +++--- src/shared/socket.cpp | 2 +- src/shared/stream_socket.cpp | 6 +++--- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index fe3e554..22d8840 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -115,10 +115,10 @@ API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor) API bool sensord_get_type(sensor_t sensor, sensor_type_t *type) { - retvm_if(!type, false, "Invalid parameter[%#x]", type); + retvm_if(!type, false, "Invalid type"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *type = static_cast(sensor)->get_type(); @@ -129,7 +129,7 @@ API const char* sensord_get_uri(sensor_t sensor) { retvm_if(!manager.connect(), NULL, "Failed to connect"); retvm_if(!manager.is_supported(sensor), NULL, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); return static_cast(sensor)->get_uri().c_str(); } @@ -138,7 +138,7 @@ API const char* sensord_get_name(sensor_t sensor) { retvm_if(!manager.connect(), NULL, "Failed to connect"); retvm_if(!manager.is_supported(sensor), NULL, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); return static_cast(sensor)->get_model().c_str(); } @@ -147,17 +147,17 @@ API const char* sensord_get_vendor(sensor_t sensor) { retvm_if(!manager.connect(), NULL, "Failed to connect"); retvm_if(!manager.is_supported(sensor), NULL, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); return static_cast(sensor)->get_vendor().c_str(); } API bool sensord_get_min_range(sensor_t sensor, float *min_range) { - retvm_if(!min_range, false, "Invalid parameter[%#x]", min_range); + retvm_if(!min_range, false, "Invalid paramter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *min_range = static_cast(sensor)->get_min_range(); @@ -166,10 +166,10 @@ API bool sensord_get_min_range(sensor_t sensor, float *min_range) API bool sensord_get_max_range(sensor_t sensor, float *max_range) { - retvm_if(!max_range, false, "Invalid parameter[%#x]", max_range); + retvm_if(!max_range, false, "Invalid parameter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *max_range = static_cast(sensor)->get_max_range(); @@ -178,10 +178,10 @@ API bool sensord_get_max_range(sensor_t sensor, float *max_range) API bool sensord_get_resolution(sensor_t sensor, float *resolution) { - retvm_if(!resolution, false, "Invalid parameter[%#x]", resolution); + retvm_if(!resolution, false, "Invalid parameter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *resolution = static_cast(sensor)->get_resolution(); @@ -190,10 +190,10 @@ API bool sensord_get_resolution(sensor_t sensor, float *resolution) API bool sensord_get_min_interval(sensor_t sensor, int *min_interval) { - retvm_if(!min_interval, false, "Invalid parameter[%#x]", min_interval); + retvm_if(!min_interval, false, "Invalid parameter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *min_interval = static_cast(sensor)->get_min_interval(); @@ -202,10 +202,10 @@ API bool sensord_get_min_interval(sensor_t sensor, int *min_interval) API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count) { - retvm_if(!fifo_count, false, "Invalid parameter[%#x]", fifo_count); + retvm_if(!fifo_count, false, "Invalid parameter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *fifo_count = 0; @@ -214,10 +214,10 @@ API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count) API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count) { - retvm_if(!max_batch_count, false, "Invalid parameter[%#x]", max_batch_count); + retvm_if(!max_batch_count, false, "Invalid parameter"); retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); *max_batch_count = static_cast(sensor)->get_max_batch_count(); @@ -228,7 +228,7 @@ API bool sensord_is_wakeup_supported(sensor_t sensor) { retvm_if(!manager.connect(), false, "Failed to connect"); retvm_if(!manager.is_supported(sensor), false, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); return static_cast(sensor)->is_wakeup_supported(); } @@ -237,7 +237,7 @@ API int sensord_connect(sensor_t sensor) { retvm_if(!manager.connect(), -EIO, "Failed to connect"); retvm_if(!manager.is_supported(sensor), -EINVAL, - "Invalid sensor[%#x]", sensor); + "Invalid sensor[%p]", sensor); sensor::sensor_listener *listener; diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 760a90b..101b833 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -83,7 +83,7 @@ int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count) bool sensor_manager::is_supported(sensor_t sensor) { - retvm_if(!sensor, false, "Invalid parameter[%#x]", sensor); + retvm_if(!sensor, false, "Invalid sensor"); for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { if (&*it == sensor) diff --git a/src/shared/seqpacket_socket.cpp b/src/shared/seqpacket_socket.cpp index ef6e01b..ad27394 100644 --- a/src/shared/seqpacket_socket.cpp +++ b/src/shared/seqpacket_socket.cpp @@ -54,7 +54,7 @@ ssize_t seqpacket_socket::on_send(const void *buffer, size_t size) const } while (err == EINTR); if (err) { - _ERRNO(errno, _E, "Failed to send(%d, %#x, %d) = %d", + _ERRNO(errno, _E, "Failed to send(%d, %p, %u) = %d", socket::get_fd(), buffer, size, len); } @@ -74,7 +74,7 @@ ssize_t seqpacket_socket::on_recv(void *buffer, size_t size) const if (len > 0) { err = 0; } else if (len == 0) { - _E("Failed to recv(%d, %#p , %d) = %d, because the peer performed shutdown!", + _E("Failed to recv(%d, %p , %u) = %d, because the peer performed shutdown!", socket::get_fd(), buffer, size, len); err = 1; } else { @@ -86,7 +86,7 @@ ssize_t seqpacket_socket::on_recv(void *buffer, size_t size) const return 0; if (err) { - _ERRNO(errno, _E, "Failed to recv(%d, %#x, %d) = %d", + _ERRNO(errno, _E, "Failed to recv(%d, %p, %u) = %d", socket::get_fd(), buffer, size, len); } diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp index f053dbc..aed28df 100644 --- a/src/shared/socket.cpp +++ b/src/shared/socket.cpp @@ -422,7 +422,7 @@ bool socket::has_connected(void) } if (so_error) { - _E("Failed to connect[%d]: %d", so_error); + _E("Failed to connect[%d] : %d", m_sock_fd, so_error); return false; } diff --git a/src/shared/stream_socket.cpp b/src/shared/stream_socket.cpp index 8ec9f7c..e583f26 100644 --- a/src/shared/stream_socket.cpp +++ b/src/shared/stream_socket.cpp @@ -58,7 +58,7 @@ ssize_t stream_socket::on_send(const void *buffer, size_t size) const continue; } - _ERRNO(errno, _E, "Failed to send(%d, %#p, %x, %d) = %d", + _ERRNO(errno, _E, "Failed to send(%d, %p, %u, %u) = %d", get_fd(), buffer, total_size, size - total_size, len); return -errno; } @@ -81,7 +81,7 @@ ssize_t stream_socket::on_recv(void *buffer, size_t size) const socket::get_mode()); if (len == 0) { - _E("Failed to recv(%d, %#p + %x, %d) = %d, because the peer performed shutdown", + _E("Failed to recv(%d, %p + %x, %u) = %d, because the peer performed shutdown", get_fd(), buffer, total_size, size - total_size, len); return -1; } @@ -92,7 +92,7 @@ ssize_t stream_socket::on_recv(void *buffer, size_t size) const continue; } - _ERRNO(errno, _E, "Failed to recv(%d, %#p, %x, %d) = %d", + _ERRNO(errno, _E, "Failed to recv(%d, %p, %u, %u) = %d", get_fd(), buffer, total_size, size - total_size, len); return -errno; } -- 2.7.4 From 7497cf8b59310b0eb1414d8a9a2af44d4e76efe1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 23 Jun 2017 14:44:27 +0900 Subject: [PATCH 14/16] sensord: remove termination routine when there is no sensor - serveral frameworks try to connect sensor continuously, so the sensor daemon runs every time they try. it's a overhead work. Change-Id: Ib203c69e4e53767256e71ca9aaa5f58c6d97a622 Signed-off-by: kibak.yoon --- src/server/server.cpp | 20 -------------------- src/server/server.h | 1 - 2 files changed, 21 deletions(-) diff --git a/src/server/server.cpp b/src/server/server.cpp index a7a2f03..22b3987 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -33,7 +33,6 @@ #define SET_CAL 1 //#define CAL_NODE_PATH "/sys/class/sensors/ssp_sensor/set_cal_data" -#define TIMEOUT_TERM 10 #define MAX_CONNECTION 1000 using namespace sensor; @@ -87,7 +86,6 @@ bool server::init(void) init_calibration(); init_server(); - init_termination(); is_running.store(true); sd_notify(0, "READY=1"); @@ -148,21 +146,3 @@ void server::init_server(void) m_server->set_option(SO_TYPE, SOCK_STREAM); m_server->bind(m_handler, &m_loop); } - -static gboolean terminate(gpointer data) -{ - sensor_manager *mgr = reinterpret_cast(data); - std::vector sensors = mgr->get_sensors(); - - if (sensors.size() <= 0) { - _I("Terminating.. because there is no sensors"); - server::stop(); - } - - return FALSE; -} - -void server::init_termination(void) -{ - g_timeout_add_seconds(TIMEOUT_TERM, terminate, m_manager); -} diff --git a/src/server/server.h b/src/server/server.h index 99856a1..e8a5771 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -46,7 +46,6 @@ private: void init_calibration(void); void init_server(void); - void init_termination(void); ipc::ipc_server *m_server; sensor_manager *m_manager; -- 2.7.4 From 2eeda580cd75630b43b53ca9e8f27762c1d2bbe4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 17 Jul 2017 11:54:52 +0900 Subject: [PATCH 15/16] sensor: fix the type casting issue about integer division - the result of integer division converted into floating point Change-Id: I40d59f2976c1d65cd4c4c20ddb027edcbc70ab5b Signed-off-by: kibak.yoon --- src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp b/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp index be41328..e352f5b 100644 --- a/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp +++ b/src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp @@ -40,7 +40,7 @@ #define ZIGMA_W (0.05 * DEG2RAD) #define TAU_W 1000 #define QWB_CONST ((2 * (ZIGMA_W * ZIGMA_W)) / TAU_W) -#define F_CONST (-1 / TAU_W) +#define F_CONST (-1.0 / TAU_W) #define SQUARE(T) (T * T) #define NEGLIGIBLE_VAL 0.0000001 -- 2.7.4 From 06207864e19a4f25f8ffb06a08261b953ab9c8d8 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 17 Jul 2017 11:59:39 +0900 Subject: [PATCH 16/16] sensor: check NULL if memory allocation is failed Change-Id: I1a85c8d036143f93f344be1e8eb2b5a5f7983470 Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 1 + src/sensor/gesture/face_down_sensor.cpp | 6 ++---- src/sensor/gravity/gravity_comp_sensor.cpp | 1 + src/sensor/gravity/gravity_lowpass_sensor.cpp | 1 + src/sensor/linear_accel/linear_accel_sensor.cpp | 1 + src/sensor/orientation/orientation_sensor.cpp | 1 + src/sensor/rotation_vector/gyro_rv_sensor.cpp | 1 + src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 1 + src/sensor/rotation_vector/rv_sensor.cpp | 1 + 9 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index e02cad3..7fb6587 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -111,6 +111,7 @@ int auto_rotation_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = SENSOR_ACCURACY_GOOD; sensor_data->timestamp = m_rotation_time; diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp index 03ddf7c..98c1ccb 100644 --- a/src/sensor/gesture/face_down_sensor.cpp +++ b/src/sensor/gesture/face_down_sensor.cpp @@ -119,10 +119,7 @@ void face_down_sensor::synthesize(const sensor_event_t & event) int data_length; face_down_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!face_down_event) { - _E("Failed to allocate memory"); - return; - } + retm_if(!face_down_event, "Failed to allocate memory"); get_data(&face_down_data, &data_length); face_down_event->sensor_id = get_id(); @@ -139,6 +136,7 @@ int face_down_sensor::get_data(sensor_data_t ** data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = SENSOR_ACCURACY_GOOD; sensor_data->timestamp = m_time; diff --git a/src/sensor/gravity/gravity_comp_sensor.cpp b/src/sensor/gravity/gravity_comp_sensor.cpp index 36b2171..1fbf747 100644 --- a/src/sensor/gravity/gravity_comp_sensor.cpp +++ b/src/sensor/gravity/gravity_comp_sensor.cpp @@ -229,6 +229,7 @@ int gravity_comp_sensor::get_data(sensor_data_t **data, int *len) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; diff --git a/src/sensor/gravity/gravity_lowpass_sensor.cpp b/src/sensor/gravity/gravity_lowpass_sensor.cpp index 5401934..eb3a48f 100644 --- a/src/sensor/gravity/gravity_lowpass_sensor.cpp +++ b/src/sensor/gravity/gravity_lowpass_sensor.cpp @@ -116,6 +116,7 @@ int gravity_lowpass_sensor::get_data(sensor_data_t **data, int *len) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 2dac280..99b7b1e 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -104,6 +104,7 @@ int linear_accel_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = SENSOR_ACCURACY_GOOD; sensor_data->timestamp = m_time; diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index acdf12b..7cec3f2 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -96,6 +96,7 @@ int orientation_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 850118f..1a0aaaa 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -104,6 +104,7 @@ int gyro_rv_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 5e4cd74..8a40705 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -104,6 +104,7 @@ int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index c69cb6b..20b0226 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -110,6 +110,7 @@ int rv_sensor::get_data(sensor_data_t **data, int *length) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; -- 2.7.4