Integrate internal fixes 61/217361/1 submit/tizen/20200116.005934 submit/tizen_5.5/20191223.004350 submit/tizen_5.5/20191223.084045
authorBoram Bae <boram21.bae@samsung.com>
Thu, 7 Nov 2019 04:58:32 +0000 (13:58 +0900)
committerBoram Bae <boram21.bae@samsung.com>
Mon, 11 Nov 2019 00:53:13 +0000 (09:53 +0900)
Change-Id: Ib7d63ed61153ef5c8ce1ad357b8dace3ad8ca0f4
Signed-off-by: Boram Bae <boram21.bae@samsung.com>
277 files changed:
CMakeLists.txt
include/physical_sensor.h
include/sensor_hal_types.h
include/sensor_internal.h
include/sensor_types.h
packaging/sensord.service
packaging/sensord.socket
packaging/sensord.spec
sensor.conf [deleted file]
src/client/sensor_internal.cpp
src/client/sensor_listener.cpp
src/client/sensor_listener.h
src/client/sensor_manager.cpp
src/client/sensor_manager.h
src/client/sensor_provider.cpp
src/client/sensor_provider.h
src/client/sensor_provider_channel_handler.cpp
src/client/sensor_provider_channel_handler.h
src/client/sensor_reader.cpp [new file with mode: 0644]
src/client/sensor_reader.h [new file with mode: 0644]
src/fusion-sensor/CMakeLists.txt [moved from src/sensor/CMakeLists.txt with 90% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_alg.cpp [moved from src/sensor/auto_rotation/auto_rotation_alg.cpp with 100% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_alg.h [moved from src/sensor/auto_rotation/auto_rotation_alg.h with 100% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.cpp [moved from src/sensor/auto_rotation/auto_rotation_alg_emul.cpp with 100% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.h [moved from src/sensor/auto_rotation/auto_rotation_alg_emul.h with 100% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_sensor.cpp [moved from src/sensor/auto_rotation/auto_rotation_sensor.cpp with 98% similarity]
src/fusion-sensor/auto_rotation/auto_rotation_sensor.h [moved from src/sensor/auto_rotation/auto_rotation_sensor.h with 100% similarity]
src/fusion-sensor/create.cpp [moved from src/sensor/create.cpp with 89% similarity]
src/fusion-sensor/fusion_util.cpp [moved from src/sensor/fusion_util.cpp with 100% similarity]
src/fusion-sensor/fusion_util.h [moved from src/sensor/fusion_util.h with 100% similarity]
src/fusion-sensor/gesture/face_down_alg.h [moved from src/sensor/gesture/face_down_alg.h with 90% similarity]
src/fusion-sensor/gesture/face_down_alg_impl.cpp [moved from src/sensor/gesture/face_down_alg_impl.cpp with 80% similarity]
src/fusion-sensor/gesture/face_down_alg_impl.h [moved from src/sensor/gesture/face_down_alg_impl.h with 86% similarity]
src/fusion-sensor/gesture/face_down_sensor.cpp [new file with mode: 0644]
src/fusion-sensor/gesture/face_down_sensor.h [new file with mode: 0644]
src/fusion-sensor/gesture/pick_up_sensor.cpp [new file with mode: 0644]
src/fusion-sensor/gesture/pick_up_sensor.h [new file with mode: 0644]
src/fusion-sensor/gravity/gravity_comp_sensor.cpp [moved from src/sensor/gravity/gravity_comp_sensor.cpp with 100% similarity]
src/fusion-sensor/gravity/gravity_comp_sensor.h [moved from src/sensor/gravity/gravity_comp_sensor.h with 100% similarity]
src/fusion-sensor/gravity/gravity_lowpass_sensor.cpp [moved from src/sensor/gravity/gravity_lowpass_sensor.cpp with 100% similarity]
src/fusion-sensor/gravity/gravity_lowpass_sensor.h [moved from src/sensor/gravity/gravity_lowpass_sensor.h with 100% similarity]
src/fusion-sensor/linear_accel/linear_accel_sensor.cpp [moved from src/sensor/linear_accel/linear_accel_sensor.cpp with 100% similarity]
src/fusion-sensor/linear_accel/linear_accel_sensor.h [moved from src/sensor/linear_accel/linear_accel_sensor.h with 100% similarity]
src/fusion-sensor/orientation/orientation_sensor.cpp [moved from src/sensor/orientation/orientation_sensor.cpp with 99% similarity]
src/fusion-sensor/orientation/orientation_sensor.h [moved from src/sensor/orientation/orientation_sensor.h with 100% similarity]
src/fusion-sensor/pedometer/average_filter.cpp [moved from src/sensor/pedometer/average_filter.cpp with 100% similarity]
src/fusion-sensor/pedometer/average_filter.h [moved from src/sensor/pedometer/average_filter.h with 100% similarity]
src/fusion-sensor/pedometer/pedometer.cpp [moved from src/sensor/pedometer/pedometer.cpp with 100% similarity]
src/fusion-sensor/pedometer/pedometer.h [moved from src/sensor/pedometer/pedometer.h with 100% similarity]
src/fusion-sensor/pedometer/pedometer_info.h [moved from src/sensor/pedometer/pedometer_info.h with 100% similarity]
src/fusion-sensor/pedometer/pedometer_sensor.cpp [moved from src/sensor/pedometer/pedometer_sensor.cpp with 100% similarity]
src/fusion-sensor/pedometer/pedometer_sensor.h [moved from src/sensor/pedometer/pedometer_sensor.h with 100% similarity]
src/fusion-sensor/pedometer/pedometer_speed_filter.cpp [moved from src/sensor/pedometer/pedometer_speed_filter.cpp with 100% similarity]
src/fusion-sensor/pedometer/pedometer_speed_filter.h [moved from src/sensor/pedometer/pedometer_speed_filter.h with 100% similarity]
src/fusion-sensor/pedometer/savitzky_golay_filter15.cpp [moved from src/sensor/pedometer/savitzky_golay_filter15.cpp with 100% similarity]
src/fusion-sensor/pedometer/savitzky_golay_filter15.h [moved from src/sensor/pedometer/savitzky_golay_filter15.h with 100% similarity]
src/fusion-sensor/pedometer/sensor_frequency_compensator.cpp [moved from src/sensor/pedometer/sensor_frequency_compensator.cpp with 100% similarity]
src/fusion-sensor/pedometer/sensor_frequency_compensator.h [moved from src/sensor/pedometer/sensor_frequency_compensator.h with 100% similarity]
src/fusion-sensor/pedometer/step_detection.cpp [moved from src/sensor/pedometer/step_detection.cpp with 100% similarity]
src/fusion-sensor/pedometer/step_detection.h [moved from src/sensor/pedometer/step_detection.h with 100% similarity]
src/fusion-sensor/pedometer/step_event.h [moved from src/sensor/pedometer/step_event.h with 100% similarity]
src/fusion-sensor/pedometer/timestamp.h [moved from src/sensor/pedometer/timestamp.h with 100% similarity]
src/fusion-sensor/pedometer/zero_crossing_step_detection.cpp [moved from src/sensor/pedometer/zero_crossing_step_detection.cpp with 100% similarity]
src/fusion-sensor/pedometer/zero_crossing_step_detection.h [moved from src/sensor/pedometer/zero_crossing_step_detection.h with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt [moved from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/accel.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt [moved from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/gyro.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt [moved from src/sensor/rotation_vector/design/data/100ms/gravity/single_roll_throw/magnetic.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt [moved from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/accel.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt [moved from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/gyro.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt [moved from src/sensor/rotation_vector/design/data/100ms/linear_acceleration/move_x_y_z/magnetic.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt [moved from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/accel.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt [moved from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/gyro.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt [moved from src/sensor/rotation_vector/design/data/100ms/orientation/roll_pitch_yaw/magnetic.txt with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/In_hand/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Pant_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/Shirt_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_down/While_talking/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/In_hand/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Pant_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/Shirt_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Climb_stairs_up/While_talking/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/In_hand/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Pant_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/Shirt_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_fast/While_talking/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/In_hand/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Pant_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/Shirt_pocket/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/accel with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/gyro with 100% similarity]
src/fusion-sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic [moved from src/sensor/rotation_vector/design/data/25ms/pedo/Walk_slow/While_talking/magnetic with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png [moved from src/sensor/rotation_vector/design/documentation/diagram/block_diagram_gravity_and_linear_acceleration.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png [moved from src/sensor/rotation_vector/design/documentation/diagram/block_diagram_orientation_estimation.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/device_orientation.png [moved from src/sensor/rotation_vector/design/documentation/diagram/device_orientation.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png [moved from src/sensor/rotation_vector/design/documentation/diagram/kalman_filter_stages.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png [moved from src/sensor/rotation_vector/design/documentation/diagram/orientation_effect_on_gravity.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png [moved from src/sensor/rotation_vector/design/documentation/diagram/projection_diagram_gravity_computation.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_1.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_1.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_10.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_10.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_11.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_11.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_12.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_12.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_13.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_13_updated.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_13_updated.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_14.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_14.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_15.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_15.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_16.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_16.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_17.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_17.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_18.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_18.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_19.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_19.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_2.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_2.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_20.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_20.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_21.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_21.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_22.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_22.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_23.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_23.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_24.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_24.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_25.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_25.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_26.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_26.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_27.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_27.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_28.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_28.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_29.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_29.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_3.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_3.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_30.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_30.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_31.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_31.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_32.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_32.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_33.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_33.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_34.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_34.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_35.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_35.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_36.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_36.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_37.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_37.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_38.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_38.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_39.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_39.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_4.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_4.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_40.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_40.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_5.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_5.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_6.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_6.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_7.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_7.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_8.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_8.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/equation/equation_9.png [moved from src/sensor/rotation_vector/design/documentation/equation/equation_9.png with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html [moved from src/sensor/rotation_vector/design/documentation/hardware_fusion_sensor.html with 100% similarity]
src/fusion-sensor/rotation_vector/design/documentation/sensor_fusion.htm [moved from src/sensor/rotation_vector/design/documentation/sensor_fusion.htm with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/axis_rot2quat.m [moved from src/sensor/rotation_vector/design/lib/axis_rot2quat.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/estimate_gaming_rv.m [moved from src/sensor/rotation_vector/design/lib/estimate_gaming_rv.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m [moved from src/sensor/rotation_vector/design/lib/estimate_geomagnetic_rv.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/estimate_gravity.m [moved from src/sensor/rotation_vector/design/lib/estimate_gravity.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/estimate_linear_acceleration.m [moved from src/sensor/rotation_vector/design/lib/estimate_linear_acceleration.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/estimate_orientation.m [moved from src/sensor/rotation_vector/design/lib/estimate_orientation.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/euler2quat.m [moved from src/sensor/rotation_vector/design/lib/euler2quat.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/quat2euler.m [moved from src/sensor/rotation_vector/design/lib/quat2euler.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/quat2rot_mat.m [moved from src/sensor/rotation_vector/design/lib/quat2rot_mat.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/quat_prod.m [moved from src/sensor/rotation_vector/design/lib/quat_prod.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/rot_mat2quat.m [moved from src/sensor/rotation_vector/design/lib/rot_mat2quat.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/lib/sf_pedometer.m [moved from src/sensor/rotation_vector/design/lib/sf_pedometer.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/readme [moved from src/sensor/rotation_vector/design/readme with 100% similarity]
src/fusion-sensor/rotation_vector/design/sf_gaming_rv.m [moved from src/sensor/rotation_vector/design/sf_gaming_rv.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/sf_geomagnetic_rv.m [moved from src/sensor/rotation_vector/design/sf_geomagnetic_rv.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/sf_gravity.m [moved from src/sensor/rotation_vector/design/sf_gravity.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/sf_linear_acceleration.m [moved from src/sensor/rotation_vector/design/sf_linear_acceleration.m with 100% similarity]
src/fusion-sensor/rotation_vector/design/sf_orientation.m [moved from src/sensor/rotation_vector/design/sf_orientation.m with 100% similarity]
src/fusion-sensor/rotation_vector/fusion.h [moved from src/sensor/rotation_vector/fusion.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_base.cpp [moved from src/sensor/rotation_vector/fusion_base.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_base.h [moved from src/sensor/rotation_vector/fusion_base.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.cpp [moved from src/sensor/rotation_vector/fusion_utils/euler_angles.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/euler_angles.h [moved from src/sensor/rotation_vector/fusion_utils/euler_angles.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/matrix.cpp [moved from src/sensor/rotation_vector/fusion_utils/matrix.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/matrix.h [moved from src/sensor/rotation_vector/fusion_utils/matrix.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.cpp [moved from src/sensor/rotation_vector/fusion_utils/orientation_filter.cpp with 99% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/orientation_filter.h [moved from src/sensor/rotation_vector/fusion_utils/orientation_filter.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/quaternion.cpp [moved from src/sensor/rotation_vector/fusion_utils/quaternion.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/quaternion.h [moved from src/sensor/rotation_vector/fusion_utils/quaternion.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.cpp [moved from src/sensor/rotation_vector/fusion_utils/rotation_matrix.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/rotation_matrix.h [moved from src/sensor/rotation_vector/fusion_utils/rotation_matrix.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.cpp [moved from src/sensor/rotation_vector/fusion_utils/sensor_data.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/sensor_data.h [moved from src/sensor/rotation_vector/fusion_utils/sensor_data.h with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/vector.cpp [moved from src/sensor/rotation_vector/fusion_utils/vector.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/fusion_utils/vector.h [moved from src/sensor/rotation_vector/fusion_utils/vector.h with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_fusion.cpp [moved from src/sensor/rotation_vector/gyro_fusion.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_fusion.h [moved from src/sensor/rotation_vector/gyro_fusion.h with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.cpp [moved from src/sensor/rotation_vector/gyro_magnetic_fusion.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_magnetic_fusion.h [moved from src/sensor/rotation_vector/gyro_magnetic_fusion.h with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_rv_sensor.cpp [moved from src/sensor/rotation_vector/gyro_rv_sensor.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/gyro_rv_sensor.h [moved from src/sensor/rotation_vector/gyro_rv_sensor.h with 100% similarity]
src/fusion-sensor/rotation_vector/magnetic_fusion.cpp [moved from src/sensor/rotation_vector/magnetic_fusion.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/magnetic_fusion.h [moved from src/sensor/rotation_vector/magnetic_fusion.h with 100% similarity]
src/fusion-sensor/rotation_vector/magnetic_rv_sensor.cpp [moved from src/sensor/rotation_vector/magnetic_rv_sensor.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/magnetic_rv_sensor.h [moved from src/sensor/rotation_vector/magnetic_rv_sensor.h with 100% similarity]
src/fusion-sensor/rotation_vector/rv_sensor.cpp [moved from src/sensor/rotation_vector/rv_sensor.cpp with 100% similarity]
src/fusion-sensor/rotation_vector/rv_sensor.h [moved from src/sensor/rotation_vector/rv_sensor.h with 100% similarity]
src/fusion-sensor/tilt/tilt_sensor.cpp [moved from src/sensor/tilt/tilt_sensor.cpp with 100% similarity]
src/fusion-sensor/tilt/tilt_sensor.h [moved from src/sensor/tilt/tilt_sensor.h with 100% similarity]
src/physical-sensor/CMakeLists.txt [new file with mode: 0644]
src/physical-sensor/accel/accel_sensor.cpp [new file with mode: 0644]
src/physical-sensor/accel/accel_sensor.h [moved from src/sensor/sensorhub/pedometer_sensor.h with 51% similarity]
src/physical-sensor/create.cpp [new file with mode: 0644]
src/physical-sensor/macro.h [new file with mode: 0644]
src/sensor/accel/accel_sensor.cpp [deleted file]
src/sensor/gesture/face_down_sensor.cpp [deleted file]
src/sensor/gesture/face_down_sensor.h [deleted file]
src/sensor/hrm/hrm_sensor.cpp [deleted file]
src/sensor/sensorhub/pedometer_sensor.cpp [deleted file]
src/sensorctl/info.cpp
src/sensorctl/injector.h
src/sensorctl/sensor_adapter.cpp
src/sensorctl/sensor_manager.cpp
src/sensorctl/sensorctl.cpp
src/sensorctl/test_bench.h
src/sensorctl/testcase/sensor_listener.cpp
src/sensorctl/testcase/sensor_provider.cpp
src/server/CMakeLists.txt
src/server/application_sensor_handler.cpp
src/server/dbus_util.cpp [deleted file]
src/server/dbus_util.h [deleted file]
src/server/main.cpp
src/server/physical_sensor_handler.cpp
src/server/physical_sensor_handler.h
src/server/sensor_event_handler.cpp
src/server/sensor_event_handler.h
src/server/sensor_handler.cpp
src/server/sensor_handler.h
src/server/sensor_listener_proxy.cpp
src/server/sensor_listener_proxy.h
src/server/sensor_manager.cpp
src/server/sensor_manager.h
src/server/sensor_policy_listener.h [moved from src/sensor/hrm/hrm_sensor.h with 65% similarity]
src/server/sensor_policy_monitor.cpp [new file with mode: 0644]
src/server/sensor_policy_monitor.h [new file with mode: 0644]
src/server/sensor_publisher.h
src/server/server_channel_handler.cpp
src/shared/CMakeLists.txt
src/shared/cbase_lock.cpp [new file with mode: 0644]
src/shared/cbase_lock.h [new file with mode: 0644]
src/shared/channel.cpp
src/shared/channel.h
src/shared/channel_event_handler.cpp
src/shared/cmutex.cpp [new file with mode: 0644]
src/shared/cmutex.h [moved from src/sensor/accel/accel_sensor.h with 58% similarity]
src/shared/command_types.h
src/shared/event_loop.cpp
src/shared/event_loop.h
src/shared/ipc_client.cpp
src/shared/ipc_server.cpp
src/shared/macro.h
src/shared/message.cpp [changed mode: 0755->0644]
src/shared/message.h
src/shared/sensor_log.h
src/shared/sensor_types_private.h
src/shared/sensor_utils.cpp
src/shared/socket.cpp

index d8e4b05..047a1cc 100644 (file)
@@ -8,7 +8,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 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")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
-SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,--gc-sections -Wl,--print-gc-sections")
 SET(CMAKE_VERBOSE_MAKEFILE OFF)
 MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
 MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
@@ -22,13 +22,11 @@ ADD_SUBDIRECTORY(src/server)
 ADD_SUBDIRECTORY(src/client)
 ADD_SUBDIRECTORY(src/client-dummy)
 ADD_SUBDIRECTORY(src/sensorctl)
-ADD_SUBDIRECTORY(src/sensor)
+ADD_SUBDIRECTORY(src/physical-sensor)
+ADD_SUBDIRECTORY(src/fusion-sensor)
 
 INSTALL(
        DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor
        FILES_MATCHING PATTERN "*.h"
 )
-INSTALL( 
-       FILES sensor.conf DESTINATION /etc/dbus-1/system.d
-)
index 6009167..58c57da 100644 (file)
 #include <string>
 #include <sensor_types.h>
 
+#include "sensor_hal.h"
+
 #ifndef SENSOR_VERSION
 #define PHYSICAL_SENSOR_VERSION(maj, min) \
                ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
 #endif
 
 #ifndef OP_SUCCESS
-#define OP_SUCCESS 1
+#define OP_SUCCESS 0
 #endif
 #ifndef OP_ERROR
 #define OP_ERROR   -1
@@ -57,11 +59,22 @@ public:
 
        inline uint32_t get_version(void) { return PHYSICAL_SENSOR_VERSION(1, 0); }
 
-       /* TODO */
+       virtual std::string get_uri(void) { return ""; }
        virtual std::string get_privilege(void) { return ""; }
 
-       virtual int start(observer_h ob) = 0;
-       virtual int stop(observer_h ob) = 0;
+       virtual physical_sensor *clone(void) const = 0;
+       virtual void set_device(sensor_device *device) { return; }
+
+       virtual int start(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int stop(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+
        virtual int set_interval(observer_h ob, uint32_t interval)
        {
                return OP_DEFAULT;
index 6910e30..1dfe2d4 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <time.h>
 
 #define SENSOR_HAL_VERSION(maj, min) \
                ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
@@ -69,6 +70,8 @@ typedef enum {
        SENSOR_DEVICE_GYROSCOPE_RV,
        SENSOR_DEVICE_GEOMAGNETIC_RV,
 
+       SENSOR_DEVICE_SIGNIFICANT_MOTION = 0x100,
+
        SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
        SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
        SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR,
@@ -83,20 +86,29 @@ typedef enum {
        SENSOR_DEVICE_EXERCISE_ROWING,
        SENSOR_DEVICE_EXERCISE_STEPPER,
 
+       SENSOR_DEVICE_DATA_JOURNAL = 0x500,
+
        SENSOR_DEVICE_FUSION = 0x900,
        SENSOR_DEVICE_AUTO_ROTATION,
        SENSOR_DEVICE_AUTO_BRIGHTNESS,
+       SENSOR_DEVICE_MYOTEST,
 
        SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200,
        SENSOR_DEVICE_GESTURE_WRIST_UP,
        SENSOR_DEVICE_GESTURE_WRIST_DOWN,
        SENSOR_DEVICE_GESTURE_MOVEMENT_STATE,
+       SENSOR_DEVICE_GESTURE_PICK_UP,
+       SENSOR_DEVICE_GESTURE_FACE_DOWN,
 
        SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00,
        SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR,
        SENSOR_DEVICE_GPS_BATCH,
+       SENSOR_DEVICE_PPG_BATCH,
+       SENSOR_DEVICE_GPS_TIMESYNC,
 
        SENSOR_DEVICE_HRM_CTRL = 0x1A80,
+       SENSOR_DEVICE_REG_CTRL,
+       SENSOR_DEVICE_GPS_CTRL,
 
        SENSOR_DEVICE_WEAR_STATUS = 0x2000,
        SENSOR_DEVICE_WEAR_ON_MONITOR,
@@ -111,6 +123,16 @@ typedef enum {
        SENSOR_DEVICE_PRESSURE_INDICATOR,
        SENSOR_DEVICE_PRESSURE_ALERT,
        SENSOR_DEVICE_HR_CALORIE,
+       SENSOR_DEVICE_SWIMMING_TRACKER,
+       SENSOR_DEVICE_STRESS_TRACKER,
+       SENSOR_DEVICE_FAKE_MOTION,
+       SENSOR_DEVICE_GEOFENCE,
+       SENSOR_DEVICE_SWIMMING_OUTDOOR,
+       SENSOR_DEVICE_AUTO_SWIMMING,
+       SENSOR_DEVICE_INACTIVITY_DETECTOR,
+       SENSOR_DEVICE_HRM_BP,
+       SENSOR_DEVICE_ECG,
+       SENSOR_DEVICE_FALL_DETECTION,
 
        SENSOR_DEVICE_CONTEXT = 0x7000,
        SENSOR_DEVICE_MOTION,
@@ -126,6 +148,7 @@ typedef enum {
        SENSOR_DEVICE_GSR,
        SENSOR_DEVICE_SIMSENSE,
        SENSOR_DEVICE_PPG,
+
 } sensor_device_type;
 
 /*
@@ -228,6 +251,8 @@ enum sensor_attribute {
        SENSOR_ATTR_PEDOMETER_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1),
        SENSOR_ATTR_PEDOMETER_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2),
        SENSOR_ATTR_PEDOMETER_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3),
+       SENSOR_ATTR_PEDOMETER_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x4),
+       SENSOR_ATTR_PEDOMETER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2F),
 
        SENSOR_ATTR_STRESS_MONITOR_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1),
 
@@ -239,6 +264,9 @@ enum sensor_attribute {
        SENSOR_ATTR_CYCLE_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1),
        SENSOR_ATTR_CYCLE_HOLDING_POSITION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2),
        SENSOR_ATTR_CYCLE_VELOCITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3),
+       SENSOR_ATTR_CYCLE_GET_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x4),
+       SENSOR_ATTR_CYCLE_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x5),
+       SENSOR_ATTR_CYCLE_GPS_AGREEMENT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x6),
 
        SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1),
        SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2),
@@ -260,10 +288,17 @@ enum sensor_attribute {
        SENSOR_ATTR_RESTING_HR_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20),
        SENSOR_ATTR_RESTING_HR_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21),
 
+       SENSOR_ATTR_STEP_LEVEL_MONITOR_DW_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STEP_LEVEL_MONITOR, 0x1),
+
        SENSOR_ATTR_EXERCISE_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1),
        SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2),
        SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3),
        SENSOR_ATTR_EXERCISE_HR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4),
+       SENSOR_ATTR_EXERCISE_HR_ELEVATED_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x5),
+       SENSOR_ATTR_EXERCISE_HR_ELEVATED_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x6),
+       SENSOR_ATTR_EXERCISE_HR_BPM_RAW = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x7),
+       SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x8),
+       SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_THR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x9),
 
        SENSOR_ATTR_PRESSURE_INDICATOR_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1),
        SENSOR_ATTR_PRESSURE_INDICATOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2),
@@ -284,6 +319,77 @@ enum sensor_attribute {
        SENSOR_ATTR_HR_CALORIE_TARGET_CAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12),
        SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13),
        SENSOR_ATTR_HR_CALORIE_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20),
+
+       SENSOR_ATTR_SWIMMING_TRACKER_PLACE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x1),
+       SENSOR_ATTR_SWIMMING_TRACKER_DISTANCE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x2),
+       SENSOR_ATTR_SWIMMING_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x3),
+       SENSOR_ATTR_SWIMMING_TRACKER_BATCH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x4),
+       SENSOR_ATTR_SWIMMING_TRACKER_GOAL_CALORIES = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x5),
+       SENSOR_ATTR_SWIMMING_TRACKER_GOAL_LAPS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x6),
+       SENSOR_ATTR_SWIMMING_TRACKER_TIME_REST = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x7),
+       SENSOR_ATTR_SWIMMING_TRACKER_TIME_TURN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x8),
+
+       SENSOR_ATTR_SWIMMING_OUTDOOR_SET_BATCH_LAP_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x1),
+       SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_LENGTH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x2),
+       SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x3),
+       SENSOR_ATTR_SWIMMING_OUTDOOR_SET_GPS_PERMISSION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x4),
+       SENSOR_ATTR_SWIMMING_OUTDOOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x6),
+
+       SENSOR_ATTR_AUTO_SWIMMING_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_AUTO_SWIMMING, 0x1),
+
+       SENSOR_ATTR_INACTIVITY_DETECTOR_LEVEL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x1),
+       SENSOR_ATTR_INACTIVITY_DETECTOR_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x2),
+
+       SENSOR_ATTR_STRESS_TRACKER_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x1),
+       SENSOR_ATTR_STRESS_TRACKER_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x2),
+
+       SENSOR_ATTR_STRESS_MONITOR_BASE_HR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1),
+       SENSOR_ATTR_STRESS_MONITOR_HISTO_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x2),
+       SENSOR_ATTR_STRESS_MONITOR_HISTO_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x3),
+       SENSOR_ATTR_STRESS_MONITOR_TUNE_INDEX = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x4),
+       SENSOR_ATTR_STRESS_MONITOR_TUNE_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x5),
+       SENSOR_ATTR_STRESS_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x6),
+       SENSOR_ATTR_STRESS_MONITOR_OPERATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x7),
+
+       SENSOR_ATTR_SLEEP_MONITOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x1),
+       SENSOR_ATTR_SLEEP_MONITOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x2),
+
+       SENSOR_ATTR_SLEEP_DETECTOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x1),
+       SENSOR_ATTR_SLEEP_DETECTOR_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x2),
+
+       SENSOR_ATTR_DATA_JOURNAL_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x1),
+       SENSOR_ATTR_DATA_JOURNAL_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x2),
+
+       SENSOR_ATTR_GPS_BATCH_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_BATCH, 0x1),
+
+       SENSOR_ATTR_PPG_BATCH_POLLING_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x1),
+       SENSOR_ATTR_PPG_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x2),
+
+       SENSOR_ATTR_REG_CTRL_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x1),
+       SENSOR_ATTR_REG_CTRL_ADDRESS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x2),
+       SENSOR_ATTR_REG_CTRL_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x3),
+       SENSOR_ATTR_REG_CTRL_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x4),
+
+       SENSOR_ATTR_GPS_CTRL_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_CTRL, 0x1),
+
+       SENSOR_ATTR_FAKE_MOTION_EVENT_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x1),
+       SENSOR_ATTR_FAKE_MOTION_EVENT_COUNT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x2),
+       SENSOR_ATTR_FAKE_MOTION_PAUSE_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x3),
+
+       SENSOR_ATTR_GEOFENCE_ID = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x1),
+       SENSOR_ATTR_GEOFENCE_LAT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x2),
+       SENSOR_ATTR_GEOFENCE_LON = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x3),
+       SENSOR_ATTR_GEOFENCE_RADIUS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x4),
+       SENSOR_ATTR_GEOFENCE_PROVIDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x5),
+       SENSOR_ATTR_GEOFENCE_ACCURACY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x6),
+       SENSOR_ATTR_GEOFENCE_TIMESTAMP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x7),
+       SENSOR_ATTR_GEOFENCE_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x8),
+       SENSOR_ATTR_GEOFENCE_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x10),
+       SENSOR_ATTR_GEOFENCE_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x11),
+       SENSOR_ATTR_GEOFENCE_SET_LOCATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x12),
+       SENSOR_ATTR_GEOFENCE_BT_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x13),
+
+       SENSOR_ATTR_FALL_DETECTION_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_FALL_DETECTION, 0x1),
 };
 
 enum sensor_activity {
index ee3b375..d9f2b18 100644 (file)
@@ -423,6 +423,9 @@ int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_s
 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);
 
+typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
+int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
+
 int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
 
 /* Deprecated */
index 9c9426c..62aebbc 100644 (file)
@@ -92,6 +92,8 @@ typedef enum sensor_type_t {
        GYROSCOPE_RV_SENSOR,
        GEOMAGNETIC_RV_SENSOR,
 
+       SIGNIFICANT_MOTION_SENSOR = 0x100,
+
        HUMAN_PEDOMETER_SENSOR = 0x300,
        HUMAN_SLEEP_MONITOR_SENSOR,
        HUMAN_SLEEP_DETECTOR_SENSOR,
@@ -108,24 +110,32 @@ typedef enum sensor_type_t {
        EXERCISE_ROWING_SENSOR,
        EXERCISE_STEPPER_SENSOR,
 
+       DATA_JOURNAL_SENSOR = 0x500,
+
        EXTERNAL_EXERCISE_SENSOR = 0x800,
        EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR,
 
        FUSION_SENSOR = 0x900,
        AUTO_ROTATION_SENSOR,
        AUTO_BRIGHTNESS_SENSOR,
+       MYOTEST_SENSOR,
 
        GESTURE_MOVEMENT_SENSOR = 0x1200,
        GESTURE_WRIST_UP_SENSOR,
        GESTURE_WRIST_DOWN_SENSOR,
        GESTURE_MOVEMENT_STATE_SENSOR,
+       GESTURE_PICK_UP_SENSOR,
        GESTURE_FACE_DOWN_SENSOR,
 
        ACTIVITY_TRACKER_SENSOR = 0x1A00,
        ACTIVITY_LEVEL_MONITOR_SENSOR,
        GPS_BATCH_SENSOR,
+       PPG_BATCH_SENSOR,
+       GPS_TIMESYNC_SENSOR,
 
        HRM_CTRL_SENSOR = 0x1A80,
+       REG_CTRL_SENSOR,
+       GPS_CTRL_SENSOR,
 
        WEAR_STATUS_SENSOR = 0x2000,
        WEAR_ON_MONITOR_SENSOR,
@@ -142,6 +152,16 @@ typedef enum sensor_type_t {
        PRESSURE_INDICATOR_SENSOR,
        PRESSURE_ALERT_SENSOR,
        HR_CALORIE_SENSOR,
+       SWIMMING_TRACKER_SENSOR,
+       STRESS_TRACKER_SENSOR,
+       FAKE_MOTION_SENSOR,
+       GEOFENCE_SENSOR,
+       SWIMMING_OUTDOOR_SENSOR,
+       AUTO_SWIMMING_SENSOR,
+       INACTIVITY_DETECTOR_SENSOR,
+       HRM_BP_SENSOR,
+       ECG_SENSOR,
+       FALL_DETECTION_SENSOR,
 
        CONTEXT_SENSOR = 0x7000,
        MOTION_SENSOR,
index a8ea2ce..be67d1b 100644 (file)
@@ -8,6 +8,8 @@ Type=notify
 SmackProcessLabel=System
 ExecStart=/usr/bin/sensord
 MemoryLimit=20M
+Sockets=sensord.socket
+Nice=-5
 
 [Install]
 WantedBy=multi-user.target
index a64cd4b..31cff8d 100644 (file)
@@ -7,5 +7,7 @@ SocketGroup=input
 ListenStream=/run/.sensord.socket
 SocketMode=0777
 PassCredentials=yes
+Accept=false
 SmackLabelIPIn=*
 SmackLabelIPOut=@
+Service=sensord.service
index 5448001..9ea15c0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       sensord
 Summary:    Sensor daemon
-Version:    4.0.3
+Version:    4.0.54
 Release:    1
 Group:      System/Sensor Framework
 License:    Apache-2.0
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(libsystemd-daemon)
+BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(cynara-creds-socket)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
@@ -67,7 +68,6 @@ Group:      System/Testing
 %description -n sensor-test
 Sensor functional testing
 
-
 %prep
 %setup -q
 
@@ -106,11 +106,11 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall
 %{_libdir}/libsensor-genuine.so.*
 %{_libdir}/libsensord-shared.so
 %{_libdir}/sensor/fusion/libsensor-fusion.so
+%{_libdir}/sensor/physical/libsensor-physical.so
 %{_bindir}/sensord
 %{_unitdir}/sensord.service
 %{_unitdir}/sensord.socket
 %{_unitdir}/multi-user.target.wants/sensord.service
-%{_sysconfdir}/dbus-1/system.d/sensor.conf
 %{_unitdir}/sockets.target.wants/sensord.socket
 %license LICENSE.APLv2
 
diff --git a/sensor.conf b/sensor.conf
deleted file mode 100644 (file)
index efb4dcb..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-
-<policy user="root">
-<allow own="org.tizen.system.sensord"/>
-<allow send_destination="org.tizen.system.sensord"/>
-</policy>
-
-<policy group="sensor">
-<allow own="org.tizen.system.sensord"/>
-<allow send_destination="org.tizen.system.sensord"/>
-</policy>
-
-<policy context="default">
-<deny own="org.tizen.system.sensord"/>
-<deny send_destination="org.tizen.system.sensord"/>
-</policy>
-
-</busconfig>
-
index 5a9f042..a0f1e08 100644 (file)
 #include <sensor_log.h>
 #include <unordered_map>
 #include <regex>
+#include <thread>
+#include <cmutex.h>
+
+#include "sensor_reader.h"
 
 #define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
 #define MAX_LISTENER 100
 
 using namespace sensor;
 
+typedef struct {
+       int listener_id;
+       sensor_cb_t cb;
+       sensor_accuracy_changed_cb_t acc_cb;
+       sensor_info *sensor;
+       sensor_data_t *data;
+       void *user_data;
+} callback_info_s;
+
+static sensor::sensor_manager manager;
+static std::unordered_map<int, sensor::sensor_listener *> listeners;
+static cmutex lock;
+
+static gboolean callback_dispatcher(gpointer data)
+{
+       int event_type = 0;
+       callback_info_s *info = (callback_info_s *)data;
+
+       AUTOLOCK(lock);
+
+       if (info->sensor)
+               event_type = CONVERT_TYPE_EVENT(info->sensor->get_type());
+
+       if (info->cb && info->sensor && listeners.find(info->listener_id) != listeners.end())
+               info->cb(info->sensor, event_type, info->data, info->user_data);
+
+       delete [] info->data;
+       delete info;
+       return FALSE;
+}
+
+static gboolean accuracy_callback_dispatcher(gpointer data)
+{
+       callback_info_s *info = (callback_info_s *)data;
+
+       AUTOLOCK(lock);
+
+       if (info->acc_cb && info->sensor && listeners.find(info->listener_id) != listeners.end())
+               info->acc_cb(info->sensor, info->data->timestamp, info->data->accuracy, info->user_data);
+
+       delete [] info->data;
+       delete info;
+       return FALSE;
+}
+
 class sensor_event_handler : public ipc::channel_handler
 {
 public:
-       sensor_event_handler(sensor_t sensor, sensor_cb_t cb, void *user_data)
-       : m_sensor(reinterpret_cast<sensor_info *>(sensor))
+       sensor_event_handler(int id, sensor_t sensor, sensor_cb_t cb, void *user_data)
+       : m_listener_id(id)
+       , m_sensor(reinterpret_cast<sensor_info *>(sensor))
        , m_cb(cb)
        , m_user_data(user_data)
        {}
@@ -49,19 +99,26 @@ public:
        void disconnected(ipc::channel *ch) {}
        void read(ipc::channel *ch, ipc::message &msg)
        {
-               int event_type;
-               sensor_data_t *data;
+               callback_info_s *info;
+               sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()];
+
+               memcpy(data, msg.body(), msg.size());
 
-               data = reinterpret_cast<sensor_data_t *>(msg.body());
-               event_type = CONVERT_TYPE_EVENT(m_sensor->get_type());
+               info = new(std::nothrow) callback_info_s();
+               info->listener_id = m_listener_id;
+               info->cb = m_cb;
+               info->sensor = m_sensor;
+               info->data = data;
+               info->user_data = m_user_data;
 
-               m_cb(m_sensor, event_type, data, m_user_data);
+               g_idle_add(callback_dispatcher, info);
        }
 
        void read_complete(ipc::channel *ch) {}
        void error_caught(ipc::channel *ch, int error) {}
 
 private:
+       int m_listener_id;
        sensor_info *m_sensor;
        sensor_cb_t m_cb;
        void *m_user_data;
@@ -70,8 +127,9 @@ private:
 class sensor_accuracy_handler : public ipc::channel_handler
 {
 public:
-       sensor_accuracy_handler(sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data)
-       : m_sensor(reinterpret_cast<sensor_info *>(sensor))
+       sensor_accuracy_handler(int id, sensor_t sensor, sensor_accuracy_changed_cb_t cb, void *user_data)
+       : m_listener_id(id)
+       , m_sensor(reinterpret_cast<sensor_info *>(sensor))
        , m_cb(cb)
        , m_user_data(user_data)
        {}
@@ -80,24 +138,31 @@ public:
        void disconnected(ipc::channel *ch) {}
        void read(ipc::channel *ch, ipc::message &msg)
        {
-               sensor_data_t *data;
-               data = reinterpret_cast<sensor_data_t *>(msg.body());
+               callback_info_s *info;
+               sensor_data_t *data = (sensor_data_t *) new(std::nothrow) char[msg.size()];
+
+               memcpy(data, msg.body(), msg.size());
+
+               info = new(std::nothrow) callback_info_s();
+               info->listener_id = m_listener_id;
+               info->acc_cb = m_cb;
+               info->sensor = m_sensor;
+               info->data = data;
+               info->user_data = m_user_data;
 
-               m_cb(m_sensor, data->timestamp, data->accuracy, m_user_data);
+               g_idle_add(accuracy_callback_dispatcher, info);
        }
 
        void read_complete(ipc::channel *ch) {}
        void error_caught(ipc::channel *ch, int error) {}
 
 private:
+       int m_listener_id;
        sensor_info *m_sensor;
        sensor_accuracy_changed_cb_t m_cb;
        void *m_user_data;
 };
 
-static sensor::sensor_manager manager;
-static std::unordered_map<int, sensor::sensor_listener *> listeners;
-
 /*
  * TO-DO-LIST:
  * 1. power save option / lcd vconf : move to server
@@ -236,18 +301,23 @@ API bool sensord_is_wakeup_supported(sensor_t sensor)
 
 API int sensord_connect(sensor_t sensor)
 {
+       AUTOLOCK(lock);
+
        retvm_if(!manager.connect(), -EIO, "Failed to connect");
        retvm_if(!manager.is_supported(sensor), -EINVAL,
                        "Invalid sensor[%p]", sensor);
        retvm_if(listeners.size() > MAX_LISTENER, -EPERM, "Exceeded the maximum listener");
 
        sensor::sensor_listener *listener;
+       static sensor_reader reader;
 
-       listener = new(std::nothrow) sensor::sensor_listener(sensor);
+       listener = new(std::nothrow) sensor::sensor_listener(sensor, reader.get_event_loop());
        retvm_if(!listener, -ENOMEM, "Failed to allocate memory");
 
        listeners[listener->get_id()] = listener;
 
+       _D("Connect[%d]", listener->get_id());
+
        return listener->get_id();
 }
 
@@ -255,12 +325,16 @@ API bool sensord_disconnect(int handle)
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
        listener = it->second;
        retvm_if(!listener, false, "Invalid handle[%d]", handle);
 
+       _D("Disconnect[%d]", listener->get_id());
+
        delete listener;
        listeners.erase(handle);
 
@@ -275,6 +349,8 @@ API bool sensord_register_event(int handle, unsigned int event_type,
        int prev_max_batch_latency;
        sensor_event_handler *handler;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -294,7 +370,7 @@ API bool sensord_register_event(int handle, unsigned int event_type,
                return false;
        }
 
-       handler = new(std::nothrow) sensor_event_handler(listener->get_sensor(), cb, user_data);
+       handler = new(std::nothrow) sensor_event_handler(handle, listener->get_sensor(), cb, user_data);
        if (!handler) {
                listener->set_max_batch_latency(prev_max_batch_latency);
                listener->set_interval(prev_interval);
@@ -304,6 +380,8 @@ API bool sensord_register_event(int handle, unsigned int event_type,
 
        listener->set_event_handler(handler);
 
+       _D("Register event[%d]", listener->get_id());
+
        return true;
 }
 
@@ -311,6 +389,8 @@ API bool sensord_unregister_event(int handle, unsigned int event_type)
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -318,6 +398,8 @@ API bool sensord_unregister_event(int handle, unsigned int event_type)
 
        listener->unset_event_handler();
 
+       _D("Unregister event[%d]", listener->get_id());
+
        return true;
 }
 
@@ -326,12 +408,14 @@ API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t c
        sensor::sensor_listener *listener;
        sensor_accuracy_handler *handler;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
        listener = it->second;
 
-       handler = new(std::nothrow) sensor_accuracy_handler(listener->get_sensor(), cb, user_data);
+       handler = new(std::nothrow) sensor_accuracy_handler(handle, listener->get_sensor(), cb, user_data);
        retvm_if(!handler, false, "Failed to allocate memory");
 
        listener->set_accuracy_handler(handler);
@@ -343,6 +427,8 @@ API bool sensord_unregister_accuracy_cb(int handle)
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -358,6 +444,9 @@ API bool sensord_start(int handle, int option)
        sensor::sensor_listener *listener;
        int prev_pause;
        int pause;
+       int interval, batch_latency;
+
+       AUTOLOCK(lock);
 
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
@@ -378,6 +467,16 @@ API bool sensord_start(int handle, int option)
                return false;
        }
 
+       interval = listener->get_interval();
+       if (interval > 0)
+               listener->set_interval(interval);
+
+       batch_latency = listener->get_max_batch_latency();
+       listener->set_max_batch_latency(batch_latency);
+
+       _D("Start[%d] with the interval[%d] batch_latency[%d]",
+               listener->get_id(), interval, batch_latency);
+
        return true;
 }
 
@@ -386,6 +485,8 @@ API bool sensord_stop(int handle)
        int ret;
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -396,6 +497,8 @@ API bool sensord_stop(int handle)
        if (ret == -EAGAIN || ret == OP_SUCCESS)
                return true;
 
+       _D("Stop[%d]", listener->get_id());
+
        return false;
 }
 
@@ -403,6 +506,8 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -413,6 +518,8 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi
                return false;
        }
 
+       _D("Set interval[%d, %d]", listener->get_id(), interval);
+
        return true;
 }
 
@@ -420,6 +527,8 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -430,6 +539,8 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t
                return false;
        }
 
+       _D("Set max batch latency[%d, %u]", listener->get_id(), max_batch_latency);
+
        return true;
 }
 
@@ -438,6 +549,8 @@ API bool sensord_set_option(int handle, int option)
        sensor::sensor_listener *listener;
        int pause;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -450,6 +563,8 @@ API bool sensord_set_option(int handle, int option)
                return false;
        }
 
+       _D("Set pause option[%d, %d]", listener->get_id(), pause);
+
        return true;
 }
 
@@ -467,6 +582,8 @@ API int sensord_set_attribute_int(int handle, int attribute, int value)
                return -EIO;
        }
 
+       _D("Set attribute[%d, %d, %d]", listener->get_id(), attribute, value);
+
        return OP_SUCCESS;
 }
 
@@ -491,6 +608,8 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -508,6 +627,8 @@ API bool sensord_flush(int handle)
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -525,6 +646,8 @@ API bool sensord_set_passive_mode(int handle, bool passive)
 {
        sensor::sensor_listener *listener;
 
+       AUTOLOCK(lock);
+
        auto it = listeners.find(handle);
        retvm_if(it == listeners.end(), false, "Invalid handle[%d]", handle);
 
@@ -746,6 +869,18 @@ API int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, se
        return OP_SUCCESS;
 }
 
+API int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data)
+{
+       retvm_if(!provider, -EINVAL, "Invalid paramter");
+       retvm_if(!callback, -EINVAL, "Invalid paramter");
+
+       sensor_provider *p = static_cast<sensor_provider *>(provider);
+
+       p->set_attribute_str_cb(callback, user_data);
+
+       return OP_SUCCESS;
+}
+
 API int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data)
 {
        retvm_if(!provider, -EINVAL, "Invalid paramter");
@@ -822,6 +957,23 @@ API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
        return true;
 }
 
+static std::unordered_map<int, sensord_provider_h> external_providers;
+static int provider_id = 0;
+
+typedef struct external_cb_info_s {
+       int id;
+       sensor_external_command_cb_t cb;
+       void *user_data;
+} external_cb_info_s;
+
+static void external_attr_cb(sensord_provider_h provider, int attribute, const char *data, int cnt, void *user_data)
+{
+       external_cb_info_s *info = (external_cb_info_s *)user_data;
+
+       if (info->cb)
+               info->cb(info->id, data, cnt, info->user_data);
+}
+
 /* deprecated */
 API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
 {
index 96a7076..e08e179 100644 (file)
 #include <sensor_types.h>
 #include <command_types.h>
 #include <ipc_client.h>
+#include <cmutex.h>
 
 using namespace sensor;
 
+static cmutex lock;
+
 class listener_handler : public ipc::channel_handler
 {
 public:
@@ -36,7 +39,6 @@ public:
        void connected(ipc::channel *ch) {}
        void disconnected(ipc::channel *ch)
        {
-               _D("Disconnected");
                /* If channel->disconnect() is not explicitly called,
                 * listener will be restored */
                m_listener->restore();
@@ -78,6 +80,22 @@ sensor_listener::sensor_listener(sensor_t sensor)
        init();
 }
 
+sensor_listener::sensor_listener(sensor_t sensor, ipc::event_loop *loop)
+: m_id(0)
+, m_sensor(reinterpret_cast<sensor_info *>(sensor))
+, m_client(NULL)
+, m_cmd_channel(NULL)
+, m_evt_channel(NULL)
+, m_handler(NULL)
+, m_evt_handler(NULL)
+, m_acc_handler(NULL)
+, m_loop(loop)
+, m_connected(false)
+, m_started(false)
+{
+       init();
+}
+
 sensor_listener::~sensor_listener()
 {
        deinit();
@@ -107,6 +125,8 @@ bool sensor_listener::init(void)
 
 void sensor_listener::deinit(void)
 {
+       _D("Deinitializing..");
+       stop();
        disconnect();
 
        delete m_handler;
@@ -116,6 +136,7 @@ void sensor_listener::deinit(void)
        m_client = NULL;
 
        m_attributes.clear();
+       _D("Deinitialized..");
 }
 
 int sensor_listener::get_id(void)
@@ -133,6 +154,8 @@ void sensor_listener::restore(void)
        ret_if(!is_connected());
        retm_if(!connect(), "Failed to restore listener");
 
+       _D("Restoring sensor listener");
+
        /* Restore attributes/status */
        if (m_started.load())
                start();
@@ -153,7 +176,7 @@ bool sensor_listener::connect(void)
        m_cmd_channel = m_client->connect(NULL);
        retvm_if(!m_cmd_channel, false, "Failed to connect to server");
 
-       m_evt_channel = m_client->connect(m_handler, &m_loop, false);
+       m_evt_channel = m_client->connect(m_handler, m_loop, false);
        retvm_if(!m_evt_channel, false, "Failed to connect to server");
 
        ipc::message msg;
@@ -183,6 +206,8 @@ void sensor_listener::disconnect(void)
        ret_if(!is_connected());
        m_connected.store(false);
 
+       _D("Disconnecting..");
+
        m_evt_channel->disconnect();
        delete m_evt_channel;
        m_evt_channel = NULL;
@@ -201,16 +226,22 @@ bool sensor_listener::is_connected(void)
 
 ipc::channel_handler *sensor_listener::get_event_handler(void)
 {
+       AUTOLOCK(lock);
+
        return m_evt_handler;
 }
 
 void sensor_listener::set_event_handler(ipc::channel_handler *handler)
 {
+       AUTOLOCK(lock);
+
        m_evt_handler = handler;
 }
 
 void sensor_listener::unset_event_handler(void)
 {
+       AUTOLOCK(lock);
+
        delete m_evt_handler;
        m_evt_handler = NULL;
 }
@@ -275,7 +306,7 @@ int sensor_listener::stop(void)
        m_cmd_channel->read_sync(reply);
 
        if (reply.header()->err < 0) {
-               _E("Failed to stop listener[%d], sensor[%s]", get_id(), m_sensor->get_uri().c_str());
+               _E("Failed to stop listener[%d]", get_id());
                return reply.header()->err;
        }
 
@@ -332,6 +363,12 @@ int sensor_listener::set_interval(unsigned int interval)
 
        _I("Listener[%d] set interval[%u]", get_id(), _interval);
 
+       /* If it is not started, store the value only */
+       if (!m_started.load()) {
+               m_attributes[SENSORD_ATTRIBUTE_INTERVAL] = _interval;
+               return OP_SUCCESS;
+       }
+
        return set_attribute(SENSORD_ATTRIBUTE_INTERVAL, _interval);
 }
 
@@ -339,6 +376,12 @@ int sensor_listener::set_max_batch_latency(unsigned int max_batch_latency)
 {
        _I("Listener[%d] set max batch latency[%u]", get_id(), max_batch_latency);
 
+       /* If it is not started, store the value only */
+       if (!m_started.load()) {
+               m_attributes[SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY] = max_batch_latency;
+               return OP_SUCCESS;
+       }
+
        return set_attribute(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY, max_batch_latency);
 }
 
@@ -392,14 +435,14 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len)
 
        size = sizeof(cmd_listener_attr_str_t) + len;
 
-       buf = (cmd_listener_attr_str_t *) new(std::nothrow) char[size];
+       buf = (cmd_listener_attr_str_t *) malloc(sizeof(char) * size);
        retvm_if(!buf, -ENOMEM, "Failed to allocate memory");
 
        msg.set_type(CMD_LISTENER_ATTR_STR);
        buf->listener_id = m_id;
        buf->attribute = attribute;
 
-       memcpy(&buf->value, value, len);
+       memcpy(buf->value, value, len);
        buf->len = len;
 
        msg.enclose((char *)buf, size);
@@ -407,9 +450,13 @@ int sensor_listener::set_attribute(int attribute, const char *value, int len)
        m_cmd_channel->send_sync(&msg);
        m_cmd_channel->read_sync(reply);
 
-       delete [] buf;
+       /* Message memory is released automatically after sending message,
+          so it doesn't need to free memory */
 
-       return reply.header()->err;
+       if (reply.header()->err < 0)
+               return reply.header()->err;
+
+       return OP_SUCCESS;
 }
 
 int sensor_listener::get_sensor_data(sensor_data_t *data)
index f0a1f1b..be53ee5 100644 (file)
@@ -34,6 +34,7 @@ namespace sensor {
 class sensor_listener {
 public:
        sensor_listener(sensor_t sensor);
+       sensor_listener(sensor_t sensor, ipc::event_loop *loop);
        virtual ~sensor_listener();
 
        int get_id(void);
@@ -85,7 +86,7 @@ private:
        ipc::channel_handler *m_handler;
        ipc::channel_handler *m_evt_handler;
        ipc::channel_handler *m_acc_handler;
-       ipc::event_loop m_loop;
+       ipc::event_loop *m_loop;
        std::atomic<bool> m_connected;
        std::atomic<bool> m_started;
        std::map<int, int> m_attributes;
index 1c59634..f16601f 100644 (file)
@@ -54,7 +54,7 @@ int sensor_manager::get_sensor(const char *uri, sensor_t *sensor)
        }
 
        sensor_info *info = get_info(uri);
-       retv_if(!info, -EACCES);
+       retvm_if(!info, -EACCES, "There is no accessible sensor for uri[%s]", uri);
 
        *sensor = (sensor_t)info;
        return OP_SUCCESS;
@@ -69,7 +69,7 @@ int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count)
 
        infos = get_infos(uri);
        size = infos.size();
-       retv_if(size == 0, -EACCES);
+       retvm_if(size == 0, -EACCES, "There is no accessible sensors for uri[%s]", uri);
 
        *list = (sensor_t *)malloc(sizeof(sensor_info *) * size);
        retvm_if(!*list, -ENOMEM, "Failed to allocate memory");
@@ -134,8 +134,8 @@ int sensor_manager::remove_sensor(const char *uri)
 {
        for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
                if ((*it).get_uri() == uri) {
-                       _I("Removing sensor[%s]", (*it).get_uri().c_str());
-                       it = m_sensors.erase(it);
+                       m_sensors.erase(it);
+                       _I("Removed sensor[%s]", uri);
 
                        return OP_SUCCESS;
                }
@@ -254,7 +254,7 @@ void sensor_manager::restore(void)
        _D("Restored manager");
 }
 
-void sensor_manager::decode_sensors(const char *buf, std::vector<sensor_info> &infos)
+void sensor_manager::decode_sensors(const char *buf, std::list<sensor_info> &infos)
 {
        int count = 0;
        sensor_info info;
@@ -333,7 +333,7 @@ bool sensor_manager::has_privilege(std::string &uri)
 sensor_info *sensor_manager::get_info(const char *uri)
 {
        if (strncmp(uri, utils::get_uri(ALL_SENSOR), strlen(utils::get_uri(ALL_SENSOR))) == 0)
-               return &m_sensors[0];
+               return &m_sensors.front();
 
        for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
                if ((*it).get_uri() != uri)
index 350bb01..c335e0a 100644 (file)
@@ -24,7 +24,7 @@
 #include <sensor_info.h>
 #include <ipc_client.h>
 #include <event_loop.h>
-#include <vector>
+#include <list>
 #include <atomic>
 
 #include "sensor_internal.h"
@@ -68,7 +68,7 @@ private:
        bool connect_channel(void);
        bool is_connected(void);
 
-       void decode_sensors(const char *buf, std::vector<sensor_info> &infos);
+       void decode_sensors(const char *buf, std::list<sensor_info> &infos);
        bool get_sensors_internal(void);
 
        bool has_privilege(std::string &uri);
@@ -82,7 +82,7 @@ private:
        std::atomic<bool> m_connected;
        channel_handler *m_handler;
 
-       std::vector<sensor_info> m_sensors;
+       std::list<sensor_info> m_sensors;
 };
 
 }
index bd0b894..7afe921 100644 (file)
@@ -117,12 +117,12 @@ int sensor_provider::send_sensor_info(sensor_info *info)
        int size;
 
        size = serialize(info, &bytes);
-       retvm_if(size == -ENOMEM, -ENOMEM, "Failed to serialize");
+
        ipc::message msg((const char *)bytes, size);
        msg.set_type(CMD_PROVIDER_CONNECT);
 
        m_channel->send_sync(&msg);
-       delete []bytes;
+
        return OP_SUCCESS;
 }
 
@@ -170,14 +170,6 @@ void sensor_provider::restore(void)
 
 int sensor_provider::publish(sensor_data_t *data, int len)
 {
-       for (int i = 0; i < data->value_count; ++i) {
-               if (!(data->values[i] >= m_sensor.get_min_range() &&
-                     data->values[i] <= m_sensor.get_max_range())) {
-                       _E("Out of range");
-                       return OP_ERROR;
-               }
-       }
-
        ipc::message msg;
        msg.set_type(CMD_PROVIDER_PUBLISH);
        msg.enclose((const char *)data, len);
@@ -207,3 +199,8 @@ void sensor_provider::set_interval_cb(sensord_provider_interval_changed_cb cb, v
        m_handler->set_interval_cb(cb, user_data);
 }
 
+void sensor_provider::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data)
+{
+       m_handler->set_attribute_str_cb(cb, user_data);
+}
+
index 2191b60..7b26754 100644 (file)
@@ -47,6 +47,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_interval_changed_cb cb, void *user_data);
+       void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data);
 
        int publish(sensor_data_t *data, int len);
 
index ed3fd01..c939138 100644 (file)
@@ -30,9 +30,11 @@ sensor_provider::channel_handler::channel_handler(sensor_provider *provider)
 , m_start_cb(NULL)
 , m_stop_cb(NULL)
 , m_interval_changed_cb(NULL)
+, m_attribute_str_cb(NULL)
 , m_start_user_data(NULL)
 , m_stop_user_data(NULL)
 , m_interval_changed_user_data(NULL)
+, m_attribute_str_user_data(NULL)
 {
 }
 
@@ -65,6 +67,19 @@ void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg)
                if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_interval_changed_cb)
                        m_interval_changed_cb(m_provider, buf.value, m_interval_changed_user_data);
                break;
+       case CMD_PROVIDER_ATTR_STR:
+               cmd_provider_attr_str_t *attr;
+
+               attr = (cmd_provider_attr_str_t *) new(std::nothrow) char[msg.size()];
+               retm_if(!attr, "Failed to allocate memory");
+
+               msg.disclose((char *)attr);
+
+               if (m_attribute_str_cb)
+                       m_attribute_str_cb(m_provider, attr->attribute, attr->value, attr->len, m_attribute_str_user_data);
+
+               delete [] attr;
+               break;
        }
 }
 
@@ -93,3 +108,9 @@ void sensor_provider::channel_handler::set_interval_cb(sensord_provider_interval
        m_interval_changed_cb = cb;
        m_interval_changed_user_data = user_data;
 }
+
+void sensor_provider::channel_handler::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data)
+{
+       m_attribute_str_cb = cb;
+       m_attribute_str_user_data = user_data;
+}
index 877f9db..89a0e36 100644 (file)
@@ -41,6 +41,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_interval_changed_cb cb, void *user_data);
+       void set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data);
 
 private:
        sensor_provider *m_provider;
@@ -48,10 +49,12 @@ private:
        sensord_provider_start_cb m_start_cb;
        sensord_provider_stop_cb m_stop_cb;
        sensord_provider_interval_changed_cb m_interval_changed_cb;
+       sensord_provider_attribute_str_cb m_attribute_str_cb;
 
        void *m_start_user_data;
        void *m_stop_user_data;
        void *m_interval_changed_user_data;
+       void *m_attribute_str_user_data;
 };
 
 }
diff --git a/src/client/sensor_reader.cpp b/src/client/sensor_reader.cpp
new file mode 100644 (file)
index 0000000..cdbad28
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 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_reader.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+#include <chrono>
+
+using namespace sensor;
+
+sensor_reader::sensor_reader()
+: m_reader(NULL)
+, m_event_loop(NULL)
+, m_mutex()
+, m_cond()
+, m_loop(NULL)
+, m_running(false)
+{
+       m_event_loop = new(std::nothrow) ipc::event_loop();
+       m_reader = new(std::nothrow) std::thread(&sensor::sensor_reader::read_event, this);
+       m_reader->detach();
+
+       if (!m_running)
+               wait_for_preparation();
+
+       _I("Created");
+}
+
+sensor_reader::~sensor_reader()
+{
+       _I("Destroying..");
+       retm_if(!m_reader, "Invalid reader");
+
+       m_running = false;
+
+       m_event_loop->stop();
+
+       delete m_reader;
+       m_reader = NULL;
+
+       delete m_event_loop;
+       m_event_loop = NULL;
+
+       _I("Destroyed");
+}
+
+ipc::event_loop *sensor_reader::get_event_loop(void)
+{
+       retvm_if(!m_event_loop, NULL, "Invalid context");
+
+       return m_event_loop;
+}
+
+void sensor_reader::wait_for_preparation(void)
+{
+       std::unique_lock<std::mutex> lock(m_mutex);
+       m_cond.wait_for(lock, std::chrono::seconds(1));
+}
+
+void sensor_reader::read_event(void)
+{
+       _I("RUN");
+       m_loop = g_main_loop_new(g_main_context_new(), false);
+       m_event_loop->set_mainloop(m_loop);
+
+       m_cond.notify_one();
+       m_running = true;
+
+       if (!m_event_loop->run())
+               _E("Failed to run event loop");
+}
diff --git a/src/client/sensor_reader.h b/src/client/sensor_reader.h
new file mode 100644 (file)
index 0000000..010eb42
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_READER_H__
+#define __SENSOR_READER_H__
+
+#include <glib.h>
+#include <event_loop.h>
+
+#include <thread>
+#include <atomic>
+#include <condition_variable>
+
+namespace sensor {
+
+class sensor_reader {
+public:
+       sensor_reader();
+       ~sensor_reader();
+
+       ipc::event_loop *get_event_loop(void);
+
+private:
+       void wait_for_preparation(void);
+       void read_event(void);
+
+       std::thread *m_reader;
+       GMainLoop *m_loop;
+       ipc::event_loop *m_event_loop;
+       std::mutex m_mutex;
+       std::condition_variable m_cond;
+       std::atomic<bool> m_running;
+};
+
+}
+
+#endif /* __SENSOR_READER_H__ */
similarity index 90%
rename from src/sensor/CMakeLists.txt
rename to src/fusion-sensor/CMakeLists.txt
index 388cb3a..4ac9942 100644 (file)
@@ -65,7 +65,12 @@ FILE(GLOB_RECURSE SRCS ${SRCS} pedometer/*.cpp)
 ADD_DEFINITIONS(-DENABLE_PEDOMETER)
 ENDIF()
 
+IF("${GESTURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} gesture/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GESTURE)
+ENDIF()
+
 MESSAGE("Sources: ${SRCS}")
 ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared")
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/fusion)
@@ -72,7 +72,11 @@ bool auto_rotation_sensor::init(void)
 
 void auto_rotation_sensor::deinit(void)
 {
+       if (!m_alg)
+               return;
+
        delete m_alg;
+       m_alg = NULL;
 }
 
 int auto_rotation_sensor::get_sensor_info(const sensor_info2_t **info)
@@ -121,7 +125,7 @@ int auto_rotation_sensor::get_data(sensor_data_t **data, int *length)
        *data = sensor_data;
        *length = sizeof(sensor_data_t);
 
-       return 1;
+       return 0;
 }
 
 int auto_rotation_sensor::start(observer_h ob)
similarity index 89%
rename from src/sensor/create.cpp
rename to src/fusion-sensor/create.cpp
index 3c9b372..241a4cd 100644 (file)
 #ifdef ENABLE_PEDOMETER
 #include "pedometer/pedometer_sensor.h"
 #endif
+#ifdef ENABLE_GESTURE
+#include "gesture/face_down_sensor.h"
+#include "gesture/pick_up_sensor.h"
+#endif
 
 static std::vector<fusion_sensor_t> sensors;
 
@@ -63,7 +67,7 @@ void create_sensor(const char *name)
 extern "C" int create(fusion_sensor_t **fsensors)
 {
 #ifdef ENABLE_AUTO_ROTATION
-       create_sensor<auto_rotation_sensor>("Accelerometer");
+       create_sensor<auto_rotation_sensor>("Auto Rotation Sensor");
 #endif
 
 #ifdef ENABLE_GRAVITY
@@ -89,6 +93,10 @@ extern "C" int create(fusion_sensor_t **fsensors)
        create_sensor<pedometer_sensor>("Pedometer");
 #endif
 
+#ifdef ENABLE_GESTURE
+       create_sensor<face_down_sensor>("Face Down Sensor");
+       create_sensor<pick_up_sensor>("Pick Up Sensor");
+#endif
        *fsensors = &sensors[0];
        return sensors.size();
 }
similarity index 90%
rename from src/sensor/gesture/face_down_alg.h
rename to src/fusion-sensor/gesture/face_down_alg.h
index 16ab460..5c981b9 100644 (file)
 #ifndef __FACE_DOWN_ALG_H__
 #define __FACE_DOWN_ALG_H__
 
-#include <sensor_common.h>
+#include <sensor_types.h>
 
 class face_down_alg {
 public:
        virtual ~face_down_alg() {};
-       virtual void push_event(const sensor_event_t & event) = 0;
+       virtual void update(sensor_data_t *data) = 0;
        virtual bool get_face_down(void) = 0;
 };
 
similarity index 80%
rename from src/sensor/gesture/face_down_alg_impl.cpp
rename to src/fusion-sensor/gesture/face_down_alg_impl.cpp
index 611d539..e51a73a 100644 (file)
  * limitations under the License.
  *
  */
+#include "face_down_alg_impl.h"
+
+#include <sensor_log.h>
 #include <cmath>
 #include <climits>
-#include <sensor_log.h>
-#include <face_down_alg_impl.h>
 
 #define GRAVITY 9.80665
 #define TWENTY_DEGREES 0.349066
@@ -37,17 +38,16 @@ face_down_alg_impl::~face_down_alg_impl()
 {
 }
 
-void face_down_alg_impl::push_event(const sensor_event_t & event)
+void face_down_alg_impl::update(sensor_data_t *data)
 {
-       //_I("face_down_alg: %llu acc[2]: %f",event.data->timestamp,event.data->values[2]);
-       m_current_time = event.data->timestamp;
+       m_current_time = data->timestamp;
        remove_old_up_time();
 
-       if (event.data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES)))
-               m_latest_down_time = event.data->timestamp;
+       if (data->values[2] < (GRAVITY * cos(ONE_SIXTY_DEGREES)))
+               m_latest_down_time = data->timestamp;
 
-       if (event.data->values[2] > (GRAVITY * cos(TWENTY_DEGREES)))
-               m_oldest_up_time.push(event.data->timestamp);
+       if (data->values[2] > (GRAVITY * cos(TWENTY_DEGREES)))
+               m_oldest_up_time.push(data->timestamp);
 }
 
 void face_down_alg_impl::remove_old_up_time(void)
@@ -76,6 +76,7 @@ unsigned long long face_down_alg_impl::is_facing_down(void)
 {
        if (m_current_time - m_latest_down_time < WINDOW_SIZE)
                return m_latest_down_time;
+
        return 0;
 }
 
similarity index 86%
rename from src/sensor/gesture/face_down_alg_impl.h
rename to src/fusion-sensor/gesture/face_down_alg_impl.h
index 997719d..ff65ee7 100644 (file)
 #ifndef __FACE_DOWN_ALG_IMPL_H__
 #define __FACE_DOWN_ALG_IMPL_H__
 
-#include <sensor_common.h>
-#include <face_down_alg.h>
 #include <queue>
 
+#include "face_down_alg.h"
+
 class face_down_alg_impl : public virtual face_down_alg {
 public:
        face_down_alg_impl();
        ~face_down_alg_impl();
-       void push_event(const sensor_event_t & event);
+       void update(sensor_data_t *data);
        bool get_face_down(void);
+
 private:
+       void remove_old_up_time(void);
+       unsigned long long is_facing_down(void);
+       unsigned long long was_facing_up(void);
+
        unsigned long long m_current_time;
        unsigned long long m_last_event_time;
        unsigned long long m_latest_down_time;
        std::queue<unsigned long long> m_oldest_up_time;
-       void remove_old_up_time(void);
-       unsigned long long is_facing_down();
-       unsigned long long was_facing_up();
 };
 
 #endif /* __FACE_DOWN_ALG_IMPL_H__ */
diff --git a/src/fusion-sensor/gesture/face_down_sensor.cpp b/src/fusion-sensor/gesture/face_down_sensor.cpp
new file mode 100644 (file)
index 0000000..b3874c1
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * 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 "face_down_sensor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#include "face_down_alg_impl.h"
+
+#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_face_down/tizen_default"
+#define NAME_VENDOR "tizen.org"
+
+#define SRC_ID_GRAVITY 0x1
+#define SRC_URI_GRAVITY "http://tizen.org/sensor/general/gravity"
+
+static sensor_info2_t sensor_info = {
+       id: 0x1,
+       type: GESTURE_FACE_DOWN_SENSOR,
+       uri: NAME_SENSOR,
+       vendor: NAME_VENDOR,
+       min_range: 0,
+       max_range: 1,
+       resolution: 1,
+       min_interval: 50,
+       max_batch_count: 0,
+       wakeup_supported: false,
+       privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+       {SRC_ID_GRAVITY, SRC_URI_GRAVITY}
+};
+
+face_down_sensor::face_down_sensor()
+: m_state(0)
+, m_timestamp(0)
+, m_alg(NULL)
+{
+       if (!init())
+               throw OP_ERROR;
+}
+
+face_down_sensor::~face_down_sensor()
+{
+       deinit();
+}
+
+bool face_down_sensor::init(void)
+{
+       m_alg = get_alg();
+       retvm_if(!m_alg, false, "Not supported");
+       return true;
+}
+
+void face_down_sensor::deinit(void)
+{
+       if (!m_alg)
+               return;
+
+       delete m_alg;
+       m_alg = NULL;
+}
+
+int face_down_sensor::get_sensor_info(const sensor_info2_t **info)
+{
+       *info = &sensor_info;
+       return OP_SUCCESS;
+}
+
+int face_down_sensor::get_required_sensors(const required_sensor_s **sensors)
+{
+       *sensors = required_sensors;
+       return 1;
+}
+
+int face_down_sensor::update(uint32_t id, sensor_data_t *data, int len)
+{
+       int state;
+
+       m_alg->update(data);
+
+       state = m_alg->get_face_down();
+       retv_if(!state, OP_ERROR);
+
+       m_state = state;
+       m_timestamp = data->timestamp;
+
+       return OP_SUCCESS;
+}
+
+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_timestamp;
+       sensor_data->values[0] = m_state;
+       sensor_data->value_count = 1;
+
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return 0;
+}
+
+face_down_alg_impl *face_down_sensor::get_alg(void)
+{
+       face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl();
+       retvm_if(!alg, NULL, "Failed to allocate memory");
+
+       return alg;
+}
diff --git a/src/fusion-sensor/gesture/face_down_sensor.h b/src/fusion-sensor/gesture/face_down_sensor.h
new file mode 100644 (file)
index 0000000..56f1b3f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 __FACE_DOWN_SENSOR_H__
+#define __FACE_DOWN_SENSOR_H__
+
+#include <fusion_sensor.h>
+#include <sensor_types.h>
+
+#include "face_down_alg_impl.h"
+
+class face_down_sensor : public fusion_sensor {
+public:
+       face_down_sensor();
+       virtual ~face_down_sensor();
+
+       int get_sensor_info(const sensor_info2_t **info);
+       int get_required_sensors(const required_sensor_s **sensors);
+
+       int update(uint32_t id, sensor_data_t *data, int len);
+       int get_data(sensor_data_t **data, int *len);
+
+private:
+       bool init(void);
+       void deinit(void);
+
+       face_down_alg_impl *get_alg(void);
+
+       int m_state;
+       unsigned long long m_timestamp;
+
+       face_down_alg_impl *m_alg;
+};
+
+#endif /* __FACE_DOWN_SENSOR_H__ */
diff --git a/src/fusion-sensor/gesture/pick_up_sensor.cpp b/src/fusion-sensor/gesture/pick_up_sensor.cpp
new file mode 100644 (file)
index 0000000..11f51f6
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * sensord
+ *
+ * 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 "pick_up_sensor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#define NAME_SENSOR "http://tizen.org/sensor/general/gesture_pick_up/tizen_default"
+#define NAME_VENDOR "tizen.org"
+
+#define SRC_ID_MOVE 0x1
+#define SRC_URI_MOVE "http://tizen.org/sensor/general/gesture_movement/SENSOR_GESTURE_MOVEMENT"
+
+static sensor_info2_t sensor_info = {
+       id: 0x1,
+       type: GESTURE_PICK_UP_SENSOR,
+       uri: NAME_SENSOR,
+       vendor: NAME_VENDOR,
+       min_range: 0,
+       max_range: 1,
+       resolution: 1,
+       min_interval: 0,
+       max_batch_count: 0,
+       wakeup_supported: false,
+       privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+       {SRC_ID_MOVE, SRC_URI_MOVE}
+};
+
+pick_up_sensor::pick_up_sensor()
+: m_state(0)
+, m_timestamp(0)
+{
+}
+
+pick_up_sensor::~pick_up_sensor()
+{
+}
+
+int pick_up_sensor::get_sensor_info(const sensor_info2_t **info)
+{
+       *info = &sensor_info;
+       return OP_SUCCESS;
+}
+
+int pick_up_sensor::get_required_sensors(const required_sensor_s **sensors)
+{
+       *sensors = required_sensors;
+       return 1;
+}
+
+int pick_up_sensor::update(uint32_t id, sensor_data_t *data, int len)
+{
+       int state = data->values[0];
+
+       _D("State : %d", state);
+
+       m_state = state;
+       m_timestamp = data->timestamp;
+
+       return OP_SUCCESS;
+}
+
+int pick_up_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_timestamp;
+       sensor_data->values[0] = m_state;
+       sensor_data->value_count = 1;
+
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return 0;
+}
diff --git a/src/fusion-sensor/gesture/pick_up_sensor.h b/src/fusion-sensor/gesture/pick_up_sensor.h
new file mode 100644 (file)
index 0000000..0b43983
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * sensord
+ *
+ * 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.
+ *
+ */
+
+#ifndef __PICK_UP_SENSOR_H__
+#define __PICK_UP_SENSOR_H__
+
+#include <fusion_sensor.h>
+#include <sensor_types.h>
+
+class pick_up_sensor : public fusion_sensor {
+public:
+       pick_up_sensor();
+       virtual ~pick_up_sensor();
+
+       int get_sensor_info(const sensor_info2_t **info);
+       int get_required_sensors(const required_sensor_s **sensors);
+
+       int update(uint32_t id, sensor_data_t *data, int len);
+       int get_data(sensor_data_t **data, int *len);
+
+private:
+       int m_state;
+       unsigned long long m_timestamp;
+};
+
+#endif /* __PICK_UP_SENSOR_H__ */
@@ -108,5 +108,5 @@ int orientation_sensor::get_data(sensor_data_t **data, int *length)
        *data = sensor_data;
        *length = sizeof(sensor_data_t);
 
-       return 1;
+       return 0;
 }
@@ -65,7 +65,6 @@ orientation_filter<TYPE>::orientation_filter()
        m_var_azimuth = vec;
 
        m_gyro.m_time_stamp = 0;
-       m_gyro_dt = 0;
 }
 
 template <typename TYPE>
diff --git a/src/physical-sensor/CMakeLists.txt b/src/physical-sensor/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9ef4c4c
--- /dev/null
@@ -0,0 +1,41 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sensor-physical CXX)
+INCLUDE(GNUInstallDirs)
+
+SET(ACCEL "OFF")
+
+INCLUDE_DIRECTORIES(
+       ${CMAKE_SOURCE_DIR}/src/shared
+       ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+# 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")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections")
+MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
+MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
+
+# Internal Debugging Options
+#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED dlog glib-2.0 vconf libtzplatform-config)
+
+FOREACH(flag ${PLUGINS_PKGS_CFLAGS})
+       SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+
+FILE(GLOB SRCS *.cpp)
+
+IF("${ACCEL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} accel/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ACCEL)
+ENDIF()
+
+MESSAGE("Sources: ${SRCS}")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS} "sensord-shared")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/physical)
diff --git a/src/physical-sensor/accel/accel_sensor.cpp b/src/physical-sensor/accel/accel_sensor.cpp
new file mode 100644 (file)
index 0000000..6178e6d
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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 "accel_sensor.h"
+#include <sensor_log.h>
+
+#define URI_ACCEL "http://tizen.org/sensor/general/accelerometer"
+
+accel_sensor::accel_sensor()
+{
+       _I("accel_sensor is created : %#x", this);
+}
+
+accel_sensor::~accel_sensor()
+{
+       _I("accel_sensor is destroyed : %#x", this);
+}
+
+std::string accel_sensor::get_uri(void)
+{
+       return URI_ACCEL;
+}
+
+physical_sensor *accel_sensor::clone(void) const
+{
+       return new accel_sensor(*this);
+}
+
+int accel_sensor::start(observer_h ob)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::stop(observer_h ob)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::set_interval(observer_h ob, uint32_t interval)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::set_batch_latency(observer_h ob, uint32_t latency)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::set_attribute(observer_h ob, int32_t attr, int32_t value)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::set_attribute(observer_h ob, int32_t attr, const char *value, int len)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::flush(observer_h ob)
+{
+       return OP_DEFAULT;
+}
+
+int accel_sensor::on_event(sensor_data_t *data, int32_t len, int32_t remains)
+{
+       return OP_DEFAULT;
+}
similarity index 51%
rename from src/sensor/sensorhub/pedometer_sensor.h
rename to src/physical-sensor/accel/accel_sensor.h
index 16f1ac7..ea8b60f 100644 (file)
  *
  */
 
-#ifndef _PEDOMETER_SENSOR_H_
-#define _PEDOMETER_SENSOR_H_
+#ifndef __ACCEL_SENSOR_H__
+#define __ACCEL_SENSOR_H__
 
 #include <physical_sensor.h>
 
-class pedometer_sensor : public physical_sensor {
+class accel_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);
+       accel_sensor();
+       ~accel_sensor();
+
+       std::string get_uri(void);
+       physical_sensor *clone(void) const;
+
+       int start(observer_h ob);
+       int stop(observer_h ob);
+
+       int set_interval(observer_h ob, uint32_t interval);
+       int set_batch_latency(observer_h ob, uint32_t latency);
+       int set_attribute(observer_h ob, int32_t attr, int32_t value);
+       int set_attribute(observer_h ob, int32_t attr, const char *value, int len);
+       int flush(observer_h ob);
+       int on_event(sensor_data_t *data, int32_t len, int32_t remains);
 };
 
-#endif /* _PEDOMETER_SENSOR_H_ */
+#endif /* __ACCEL_SENSOR_H__ */
 
diff --git a/src/physical-sensor/create.cpp b/src/physical-sensor/create.cpp
new file mode 100644 (file)
index 0000000..dfaca85
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 <sensor_log.h>
+#include <physical_sensor.h>
+#include <vector>
+
+#ifdef ENABLE_ACCEL
+#include "accel/accel_sensor.h"
+#endif
+
+static std::vector<physical_sensor_t> sensors;
+
+template<typename _sensor>
+void create_sensor(const char *name)
+{
+       physical_sensor *instance = NULL;
+       try {
+               instance = new _sensor;
+       } catch (std::exception &e) {
+               _E("Failed to create %s sensor, exception: %s", name, e.what());
+               return;
+       } catch (int err) {
+               _ERRNO(err, _E, "Failed to create %s sensor device", name);
+               return;
+       }
+
+       sensors.push_back(instance);
+}
+
+extern "C" int create(physical_sensor_t **fsensors)
+{
+#ifdef ENABLE_ACCEL
+       create_sensor<accel_sensor>("Accelerometer");
+#endif
+       *fsensors = &sensors[0];
+       return sensors.size();
+}
diff --git a/src/physical-sensor/macro.h b/src/physical-sensor/macro.h
new file mode 100644 (file)
index 0000000..0ec7bcf
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#pragma once
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+static inline void __freep(void *p)
+{
+       free(*(void**) p);
+}
+
+static inline void __closep(int *fd)
+{
+       if (*fd >= 0)
+               close(*fd);
+}
+
+static inline void __fclosep(FILE **f)
+{
+       if (*f)
+               fclose(*f);
+}
+
+static inline void int_to_bytes(int value, int width, char data[])
+{
+       /* Big-endian */
+       for (int i = width - 1; i >= 0; i--) {
+               data[i] = (value & 0xff);
+               value = value >> 8;
+       }
+}
+
+static inline unsigned int bytes_to_uint(char data[], int &cursor, int width)
+{
+       unsigned int sum = 0;
+
+       /* Big-endian */
+       for (int i = 0; i < width; ++i)
+               sum = (sum << 8) + (unsigned char)data[cursor++];
+
+       return sum;
+}
+
+#define _cleanup_free_ _cleanup_(__freep)
+#define _cleanup_close_ _cleanup_(__closep)
+#define _cleanup_fclose_ _cleanup_(__fclosep)
+#define GET_BYTES(value, width, data) int_to_bytes(value, width, data)
+#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/src/sensor/accel/accel_sensor.cpp b/src/sensor/accel/accel_sensor.cpp
deleted file mode 100644 (file)
index 892ecb0..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 <sensor_common.h>
-#include <sensor_log.h>
-#include <accel_sensor.h>
-
-accel_sensor::accel_sensor()
-{
-       _I("accel_sensor is created : %#x", this);
-}
-
-accel_sensor::~accel_sensor()
-{
-}
-
-sensor_type_t accel_sensor::get_type(void)
-{
-       return ACCELEROMETER_SENSOR;
-}
diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp
deleted file mode 100644 (file)
index 98c1ccb..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
-#include <dlfcn.h>
-
-#include <sensor_log.h>
-#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <face_down_sensor.h>
-#include <sensor_loader.h>
-#include <fusion_util.h>
-#include <face_down_alg_impl.h>
-
-#define SENSOR_NAME "SENSOR_FACE_DOWN"
-
-#define SENSOR_FREQUENCY 50
-
-face_down_sensor::face_down_sensor()
-: m_gravity_sensor(NULL)
-, m_time(0)
-, m_state(false)
-{
-}
-
-face_down_sensor::~face_down_sensor()
-{
-       _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool face_down_sensor::init(void)
-{
-       m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR);
-
-       if (!m_gravity_sensor) {
-               _W("cannot load gravity sensor sensor[%s]", SENSOR_NAME);
-               return false;
-       }
-
-       m_alg = get_alg();
-       if (!m_alg)
-               return false;
-
-       _I("%s is created!", SENSOR_NAME);
-       return true;
-}
-
-sensor_type_t face_down_sensor::get_type(void)
-{
-       return GESTURE_FACE_DOWN_SENSOR;
-}
-
-unsigned int face_down_sensor::get_event_type(void)
-{
-       return CONVERT_TYPE_EVENT(GESTURE_FACE_DOWN_SENSOR);
-}
-
-const char *face_down_sensor::get_name(void)
-{
-       return SENSOR_NAME;
-}
-
-bool face_down_sensor::get_sensor_info(sensor_info & info)
-{
-       info.set_type(get_type());
-       info.set_id(get_id());
-       info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
-       info.set_name(get_name());
-       info.set_vendor("Samsung Electronics");
-       info.set_min_range(0);
-       info.set_max_range(1);
-       info.set_resolution(1);
-       info.set_min_interval(1);
-       info.set_fifo_count(0);
-       info.set_max_batch_count(0);
-       info.set_supported_event(get_event_type());
-       info.set_wakeup_supported(false);
-
-       return true;
-}
-
-void face_down_sensor::synthesize(const sensor_event_t & event)
-{
-       if (event.event_type != GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME)
-               return;
-
-       m_time = event.data->timestamp;
-       m_alg->push_event(event);
-       m_state = m_alg->get_face_down();
-       if (!m_state)
-               return;
-
-       sensor_event_t *face_down_event;
-       sensor_data_t *face_down_data;
-       int data_length;
-
-       face_down_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-       retm_if(!face_down_event, "Failed to allocate memory");
-
-       get_data(&face_down_data, &data_length);
-       face_down_event->sensor_id = get_id();
-       face_down_event->event_type = FACE_DOWN_RAW_DATA_EVENT;
-       face_down_event->data_length = data_length;
-       face_down_event->data = face_down_data;
-
-       push(face_down_event);
-
-       _I("[face_down_sensor] : True");
-}
-
-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;
-       sensor_data->value_count = 1;
-       sensor_data->values[0] = m_state;
-
-       *data = sensor_data;
-       *length = sizeof(sensor_data_t);
-
-       return 0;
-}
-
-bool face_down_sensor::set_interval(unsigned long interval)
-{
-       m_interval = interval;
-       return true;
-}
-
-bool face_down_sensor::set_batch_latency(unsigned long latency)
-{
-       return false;
-}
-
-bool face_down_sensor::on_start(void)
-{
-       if (m_gravity_sensor)
-               m_gravity_sensor->start();
-
-       m_time = 0;
-       m_state = false;
-       return activate();
-}
-
-bool face_down_sensor::on_stop(void)
-{
-       if (m_gravity_sensor)
-               m_gravity_sensor->stop();
-
-       m_time = 0;
-       m_state = false;
-
-       return deactivate();
-}
-
-bool face_down_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
-       m_gravity_sensor->add_interval(client_id, interval, true);
-       return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool face_down_sensor::delete_interval(int client_id, bool is_processor)
-{
-       m_gravity_sensor->delete_interval(client_id, true);
-       return sensor_base::delete_interval(client_id, is_processor);
-}
-
-face_down_alg_impl *face_down_sensor::get_alg(void)
-{
-       face_down_alg_impl *alg = new(std::nothrow) face_down_alg_impl();
-       retvm_if(!alg, NULL, "Failed to allocate memory");
-
-       return alg;
-}
diff --git a/src/sensor/gesture/face_down_sensor.h b/src/sensor/gesture/face_down_sensor.h
deleted file mode 100644 (file)
index 7bb0809..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 __FACE_DOWN_SENSOR_H__
-#define __FACE_DOWN_SENSOR_H__
-
-#include <virtual_sensor.h>
-#include <sensor_types.h>
-#include <face_down_alg_impl.h>
-
-class face_down_sensor : public virtual_sensor {
-public:
-       face_down_sensor();
-       ~face_down_sensor();
-
-       /* initialize sensor */
-       bool init(void);
-
-       /* sensor info */
-       sensor_type_t get_type(void);
-       unsigned int get_event_type(void);
-       const char *get_name(void);
-
-       bool get_sensor_info(sensor_info & info);
-
-       /* synthesize event */
-       void synthesize(const sensor_event_t & event);
-
-       bool add_interval(int client_id, unsigned int interval, bool is_processor);
-       bool delete_interval(int client_id, bool is_processor);
-
-       /* get data */
-       int get_data(sensor_data_t ** data, int *length);
-private:
-       sensor_base * m_gravity_sensor;
-       face_down_alg_impl *m_alg;
-
-       unsigned long long m_time;
-       bool m_state;
-       unsigned int m_interval;
-
-       bool set_interval(unsigned long interval);
-       bool set_batch_latency(unsigned long latency);
-
-       bool on_start(void);
-       bool on_stop(void);
-       face_down_alg_impl *get_alg(void);
-};
-
-#endif /* __FACE_DOWN_SENSOR_H__ */
diff --git a/src/sensor/hrm/hrm_sensor.cpp b/src/sensor/hrm/hrm_sensor.cpp
deleted file mode 100644 (file)
index d29ff49..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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 <sensor_common.h>
-#include <sensor_log.h>
-#include "hrm_sensor.h"
-
-hrm_sensor::hrm_sensor()
-{
-       set_permission(SENSOR_PERMISSION_BIO);
-
-       _I("hrm_sensor is created : %#x", this);
-}
-
-hrm_sensor::~hrm_sensor()
-{
-       _I("hrm_sensor is destroyed : %#x", this);
-}
diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp
deleted file mode 100644 (file)
index c825e41..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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 <sensor_common.h>
-#include <sensor_log.h>
-#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);
-
-       _I("pedometer_sensor is created : %#x", this);
-}
-
-pedometer_sensor::~pedometer_sensor()
-{
-}
-
-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;
-}
index 43b73f1..149b98c 100644 (file)
@@ -20,7 +20,6 @@
 #include "info.h"
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <glib.h>
 #include <sensor_internal.h>
 
@@ -45,10 +44,7 @@ bool info_manager::run(int argc, char *argv[])
        sensord_get_sensor_list(type, &sensors, &count);
        show_info(sensors, count);
 
-       if (sensors) {
-               free(sensors);
-               sensors = NULL;
-       }
+       delete sensors;
        return true;
 }
 
index 1742200..b487c91 100644 (file)
@@ -39,7 +39,7 @@ public:
        virtual bool teardown(void) { return true; }
 
        const std::string& name() const { return m_name; }
-       sensor_type_t type() { return m_type; }
+       const sensor_type_t type() const { return m_type; }
 
        virtual bool inject(int argc, char *argv[]) = 0;
 
index 2ba6f59..13bc4e5 100644 (file)
@@ -53,51 +53,39 @@ bool sensor_adapter::get_handle(sensor_info info, int &handle)
 {
        int err;
        int count;
-       sensor_t *sensors = NULL;
+       sensor_t *sensors;
 
        err = sensord_get_sensors(info.type, &sensors, &count);
        ASSERT_EQ(err, 0);
 
        handle = sensord_connect(sensors[info.index]);
-       ASSERT_FREE((handle < 0), sensors);
        ASSERT_GE(handle, 0);
 
-       free(sensors);
-       sensors = NULL;
-
        return true;
 }
 
 bool sensor_adapter::start(sensor_info info, int &handle)
 {
-       sensor_t *sensors = NULL;
+       sensor_t *sensors;
        int count;
        int err;
        bool ret;
 
        err = sensord_get_sensors(info.type, &sensors, &count);
        ASSERT_EQ(err, 0);
-
-       ASSERT_FREE((info.index >= count), sensors);
        ASSERT_LT(info.index, count);
-
-       ASSERT_FREE((info.index < 0), sensors);
        ASSERT_GE(info.index, 0);
 
        handle = sensord_connect(sensors[info.index]);
-       ASSERT_FREE((handle < 0), sensors);
        ASSERT_GE(handle, 0);
 
        ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL);
-       ASSERT_FREE((ret != true), sensors);
        ASSERT_TRUE(ret);
 
        ret = sensord_start(handle, info.powersave);
-       ASSERT_FREE((ret != true), sensors);
        ASSERT_TRUE(ret);
 
        free(sensors);
-       sensors = NULL;
 
        return true;
 }
index 694d34e..7504341 100644 (file)
@@ -70,6 +70,8 @@ static struct sensor_info sensor_infos[] = {
        {GESTURE_WRIST_UP_SENSOR,               "wristup"},
        {GESTURE_WRIST_DOWN_SENSOR,             "wristdown"},
        {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state"},
+       {GESTURE_PICK_UP_SENSOR,                "pickup"},
+       {GESTURE_FACE_DOWN_SENSOR,              "facedown"},
 
        {WEAR_STATUS_SENSOR,                    "wear_status"},
        {WEAR_ON_MONITOR_SENSOR,                "wear_on"},
index 415960f..a35e286 100644 (file)
@@ -47,11 +47,11 @@ static sensor_manager *create_manager(char *command)
 
        if (!strcmp(command, "test"))
                manager = new(std::nothrow) tester_manager;
-       else if (!strcmp(command, "inject"))
+       if (!strcmp(command, "inject"))
                manager = new(std::nothrow) injector_manager;
-       else if (!strcmp(command, "info"))
+       if (!strcmp(command, "info"))
                manager = new(std::nothrow) info_manager;
-       else if (!strcmp(command, "loopback"))
+       if (!strcmp(command, "loopback"))
                manager = new(std::nothrow) loopback_manager;
 
        if (!manager) {
index 9f51622..4e04b85 100644 (file)
@@ -67,9 +67,6 @@ do { \
        } \
 } while (0)
 
-#define ASSERT_FREE(expr, X) \
-       do { if (expr) { free (X); X = NULL; } } while (0)
-
 #define ASSERT_TRUE(condition) ASSERT(condition, ==, true)
 #define ASSERT_FALSE(condition) ASSERT(condition, ==, false)
 #define ASSERT_EQ(left, right) ASSERT(left, ==, right)
index cd1833c..ebff117 100644 (file)
@@ -59,7 +59,6 @@ TESTCASE(sensor_listener, get_sensors_p_1)
 
        err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count);
        ASSERT_EQ(err, 0);
-       ASSERT_FREE((count < 0), sensors);
        ASSERT_GT(count, 0);
 
        free(sensors);
@@ -91,8 +90,8 @@ TESTCASE(sensor_listener, all_api_p_1)
        bool ret;
        int handle;
        sensor_t sensor;
-       sensor_t *list = NULL;
-       int count = 0;
+       sensor_t *list;
+       int count;
 
        called = false;
 
@@ -103,37 +102,29 @@ TESTCASE(sensor_listener, all_api_p_1)
        ASSERT_EQ(err, 0);
 
        handle = sensord_connect(sensor);
-       ASSERT_FREE(((handle != 0) && list), list);
-       ASSERT_EQ(handle, 0);
+       ASSERT_EQ(err, 0);
 
        ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        ret = sensord_start(handle, 0);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        ret = sensord_change_event_interval(handle, 0, 100);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        ret = sensord_change_event_max_batch_latency(handle, 0, 100);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        mainloop::run();
 
        ret = sensord_stop(handle);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        ret = sensord_unregister_event(handle, 1);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        ret = sensord_disconnect(handle);
-       ASSERT_FREE(((ret != true) && list), list);
        ASSERT_TRUE(ret);
 
        free(list);
index a163325..9c76c21 100644 (file)
@@ -86,8 +86,8 @@ static void add_mysensor(void)
        sensord_provider_set_resolution(provider, 0.01f);
 
        sensord_add_provider(provider);
-       sensord_remove_provider(provider);
 
+       sensord_remove_provider(provider);
        sensord_destroy_provider(provider);
 }
 
index 6be6472..b11a84d 100644 (file)
@@ -1,7 +1,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(sensord CXX)
 
-SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session")
+SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session vconf")
 
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS})
index a5f9c0f..f2abadc 100644 (file)
@@ -140,6 +140,26 @@ int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr,
 
 int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len)
 {
+       ipc::message msg;
+       cmd_provider_attr_str_t *buf;
+       size_t size;
+
+       size = sizeof(cmd_provider_attr_str_t) + len;
+
+       buf = (cmd_provider_attr_str_t *) malloc(sizeof(char) * size);
+       retvm_if(!buf, -ENOMEM, "Failed to allocate memory");
+
+       msg.set_type(CMD_PROVIDER_ATTR_STR);
+       memcpy(buf->value, value, len);
+       buf->attribute = attr;
+       buf->len = len;
+
+       msg.enclose((char *)buf, size);
+
+       m_ch->send_sync(&msg);
+
+       _I("Set attribute[%d] to sensor[%s]", attr, m_info.get_uri().c_str());
+
        return OP_SUCCESS;
 }
 
diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp
deleted file mode 100644 (file)
index 0aa0b90..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include <dbus_util.h>
-#include <gio/gio.h>
-
-static int wrist_up_total_cnt;
-static int wrist_up_lcdon_cnt;
-static int wrist_up_algo;
-
-static GDBusNodeInfo *introspection_data = NULL;
-static guint owner_id;
-
-static const gchar introspection_xml[] =
-"<node>"
-"  <interface name='org.tizen.system.sensord'>"
-"       <method name='check_privilege'>"
-"         <arg type='i' name='response' direction='out'/>"
-"       </method>"
-"       <method name='wristup_lcdon_cnt'>"
-"         <arg type='i' name='response' direction='out'/>"
-"       </method>"
-"       <method name='wristup_total_cnt'>"
-"         <arg type='i' name='response' direction='out'/>"
-"       </method>"
-"       <method name='wristup_algo'>"
-"         <arg type='i' name='response' direction='out'/>"
-"       </method>"
-"  </interface>"
-"</node>";
-
-static void method_call_handler(GDBusConnection *conn,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *iface_name, const gchar *method_name,
-                               GVariant *parameters, GDBusMethodInvocation *invocation,
-                               gpointer user_data)
-{
-       int ret = DBUS_INIT;
-
-       if (g_strcmp0(method_name, "check_privilege") == 0) {
-               _D("check_privilege called");
-               ret = DBUS_SUCCESS;
-       } else if (g_strcmp0(method_name, "wristup_lcdon_cnt") == 0) {
-               _D("wristup_lcdon_cnt called, %d", wrist_up_lcdon_cnt);
-               ret = wrist_up_lcdon_cnt;
-       } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) {
-               _D("wristup_total_cnt called, %d", wrist_up_total_cnt);
-               ret = wrist_up_total_cnt;
-       } else if (g_strcmp0(method_name, "wristup_algo") == 0) {
-               _D("wristup_algo called, %d", wrist_up_algo);
-               ret = wrist_up_algo;
-       } else {
-               _D("No matched method call");
-               ret = DBUS_FAILED;
-       }
-
-       g_dbus_method_invocation_return_value(invocation,
-                                       g_variant_new("(i)", ret));
-}
-
-static const GDBusInterfaceVTable interface_vtable =
-{
-       method_call_handler,
-       NULL,
-       NULL
-};
-
-static void on_bus_acquired(GDBusConnection *connection,
-               const gchar *name,
-               gpointer user_data)
-{
-       guint registration_id;
-
-       if (!connection) {
-               _E("connection is null");
-               return;
-       }
-
-       registration_id = g_dbus_connection_register_object(connection,
-               SENSORD_OBJECT_PATH,
-               introspection_data->interfaces[0],
-               &interface_vtable,
-               NULL,  /* user_data */
-               NULL,  /* user_data_free_func */
-               NULL); /* GError** */
-
-       if (registration_id == 0)
-               _E("Failed to g_dbus_connection_register_object");
-
-       _I("Gdbus method call registrated");
-}
-
-static void on_name_acquired(GDBusConnection *conn,
-                               const gchar *name, gpointer user_data)
-{
-}
-
-static void on_name_lost(GDBusConnection *conn,
-                               const gchar *name, gpointer user_data)
-{
-       _E("Dbus name is lost!");
-}
-
-int get_lcdon_count(void)
-{
-       return wrist_up_lcdon_cnt;
-}
-
-void increase_lcdon_count(void)
-{
-       wrist_up_lcdon_cnt++;
-}
-
-void reset_lcdon_count(void)
-{
-       wrist_up_lcdon_cnt = 0;
-}
-
-int get_total_count(void)
-{
-       return wrist_up_total_cnt;
-}
-
-void increase_total_count(void)
-{
-       wrist_up_total_cnt++;
-}
-
-void reset_total_count(void)
-{
-       wrist_up_total_cnt = 0;
-}
-
-void set_wrist_up_algo(int mode)
-{
-       wrist_up_algo = mode;
-}
-
-void init_dbus(void)
-{
-#ifndef GLIB_VERSION_2_36
-       g_type_init();
-#endif
-
-       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
-       if (introspection_data == NULL) {
-               _E("Failed to init g_dbus_node_info_new_for_xml");
-               return;
-       }
-
-       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                                          SENSORD_BUS_NAME,
-                                                          (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
-                                                          | G_BUS_NAME_OWNER_FLAGS_REPLACE),
-                                                          on_bus_acquired,
-                                                          on_name_acquired,
-                                                          on_name_lost,
-                                                          NULL,
-                                                          NULL);
-       wrist_up_total_cnt = 0;
-       wrist_up_lcdon_cnt = 0;
-}
-
-void fini_dbus(void)
-{
-       if (owner_id != 0)
-               g_bus_unown_name(owner_id);
-
-       if (introspection_data)
-               g_dbus_node_info_unref(introspection_data);
-}
diff --git a/src/server/dbus_util.h b/src/server/dbus_util.h
deleted file mode 100644 (file)
index f729e3b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _DBUS_UTIL_H_
-#define _DBUS_UTIL_H_
-
-#define SENSORD_BUS_NAME              "org.tizen.system.sensord"
-#define SENSORD_OBJECT_PATH           "/Org/Tizen/System/SensorD"
-#define SENSORD_INTERFACE_NAME        SENSORD_BUS_NAME
-
-enum dbus_ret {
-       DBUS_INIT = -1,
-       DBUS_FAILED = 0,
-       DBUS_SUCCESS = 1
-};
-
-int get_lcdon_count(void);
-void increase_lcdon_count(void);
-void reset_lcdon_count(void);
-
-int get_total_count(void);
-void increase_total_count(void);
-void reset_total_count(void);
-void set_wrist_up_algo(int mode);
-
-void init_dbus(void);
-void fini_dbus(void);
-
-#endif /* SENSORD_GDBUS_H_ */
index 8bb6cf3..2f0357f 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <sensor_log.h>
-#include <dbus_util.h>
 #include <new>
 #include <csignal>
 
@@ -59,12 +58,8 @@ int main(int argc, char *argv[])
 
        std::set_new_handler(on_new_failed);
 
-       init_dbus();
-
        server::run();
 
-       fini_dbus();
-
        _I("Stopped");
 
        return 0;
index f73ee5d..1b44a87 100644 (file)
@@ -34,6 +34,7 @@ physical_sensor_handler::physical_sensor_handler(const sensor_info &info,
 , m_sensor(sensor)
 , m_hal_id(hal_id)
 , m_prev_interval(0)
+, m_prev_latency(0)
 {
 }
 
@@ -60,7 +61,6 @@ int physical_sensor_handler::get_poll_fd(void)
 
 int physical_sensor_handler::read_fd(std::vector<uint32_t> &ids)
 {
-       retv_if(observer_count() == 0, OP_ERROR);
        retv_if(!m_device, -EINVAL);
 
        int size;
@@ -90,15 +90,20 @@ int physical_sensor_handler::start(sensor_observer *ob)
 {
        retv_if(!m_device, -EINVAL);
 
+       bool ret;
        int policy = OP_DEFAULT;
 
+       ret = add_observer(ob);
+       retvm_if(!ret, OP_SUCCESS, "Listener is already added");
+
        if (m_sensor) {
                policy = m_sensor->start(ob);
-               retv_if(policy <= OP_ERROR, policy);
+               if (policy <= OP_ERROR) {
+                       remove_observer(ob);
+                       return policy;
+               }
        }
 
-       add_observer(ob);
-
        if (policy == OP_DEFAULT) {
                if (observer_count() > 1)
                        return OP_SUCCESS; /* already started */
@@ -187,11 +192,10 @@ int physical_sensor_handler::get_min_batch_latency(void)
        std::vector<int> temp;
 
        for (auto it = m_batch_latency_map.begin(); it != m_batch_latency_map.end(); ++it)
-               if (it->second > 0)
-                   temp.push_back(it->second);
+               temp.push_back(it->second);
 
        if (temp.empty())
-               return 0;
+               return -1;
 
        batch_latency = *std::min_element(temp.begin(), temp.end());
 
@@ -203,7 +207,7 @@ int physical_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t late
        retv_if(!m_device, -EINVAL);
 
        bool ret = false;
-       int _latency = latency;
+       int32_t cur_latency = latency;
        int policy = OP_DEFAULT;
 
        if (m_sensor) {
@@ -211,12 +215,36 @@ int physical_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t late
                retv_if(policy <= OP_ERROR, policy);
        }
 
-       m_batch_latency_map[ob] = _latency;
+       m_batch_latency_map[ob] = cur_latency;
+
+       if (policy == OP_DEFAULT)
+               cur_latency = get_min_batch_latency();
+
+       retv_if(m_prev_latency == cur_latency, OP_SUCCESS);
+
+       ret = m_device->set_batch_latency(m_hal_id, cur_latency);
+
+       m_prev_latency = cur_latency;
+
+       _I("Set batch latency[%d] to sensor[%s]", cur_latency, m_info.get_uri().c_str());
+
+       return (ret ? OP_SUCCESS : OP_ERROR);
+}
+
+int physical_sensor_handler::delete_batch_latency(sensor_observer *ob)
+{
+       bool ret = false;
+       int policy = OP_DEFAULT;
+       int32_t latency;
+
+       m_batch_latency_map.erase(ob);
+
+       latency = get_min_batch_latency();
+       retv_if(m_prev_latency == latency, OP_SUCCESS);
 
-       if (_latency <= latency)
-               return OP_SUCCESS;
+       ret = m_device->set_batch_latency(m_hal_id, latency);
 
-       ret = m_device->set_batch_latency(m_hal_id, _latency);
+       m_prev_latency = latency;
 
        return (ret ? OP_SUCCESS : OP_ERROR);
 }
index 31ab410..608f854 100644 (file)
@@ -50,6 +50,7 @@ public:
 
        int set_interval(sensor_observer *ob, int32_t interval);
        int set_batch_latency(sensor_observer *ob, int32_t latency);
+       int delete_batch_latency(sensor_observer *ob);
        int set_attribute(sensor_observer *ob, int32_t attr, int32_t value);
        int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len);
        int flush(sensor_observer *ob);
@@ -63,6 +64,7 @@ private:
        physical_sensor *m_sensor;
        uint32_t m_hal_id;
        int32_t m_prev_interval;
+       int32_t m_prev_latency;
 
        std::unordered_map<sensor_observer *, int> m_interval_map;
        std::unordered_map<sensor_observer *, int> m_batch_latency_map;
index a3422a7..2f7ddcf 100644 (file)
@@ -27,55 +27,73 @@ using namespace sensor;
 
 static std::vector<uint32_t> ids;
 
-sensor_event_handler::sensor_event_handler(physical_sensor_handler *sensor)
-: m_sensor(sensor)
+sensor_event_handler::sensor_event_handler()
 {
 }
 
+void sensor_event_handler::add_sensor(physical_sensor_handler *sensor)
+{
+       ret_if(!sensor);
+
+       m_sensors.insert(sensor);
+}
+
+void sensor_event_handler::remove_sensor(physical_sensor_handler *sensor)
+{
+       ret_if(!sensor);
+
+       m_sensors.erase(sensor);
+}
+
 bool sensor_event_handler::handle(int fd, ipc::event_condition condition)
 {
        sensor_info info;
-       sensor_data_t *data = NULL;
+       sensor_data_t *data;
+       physical_sensor_handler *sensor;
        int length = 0;
-       int remains = 1;
+       int remains;
 
-       if (m_sensor->read_fd(ids) < 0)
-               return true;
+       retv_if(m_sensors.empty(), false);
+
+       ids.clear();
 
-       auto result = std::find(std::begin(ids), std::end(ids), m_sensor->get_hal_id());
+       auto it = m_sensors.begin();
 
-       if (result == std::end(ids))
-       {
-               ids.clear();
+       /* sensors using the same fd share read_fd in common.
+        * so just call read_fd on the first sensor */
+       if ((*it)->read_fd(ids) < 0)
                return true;
-       }
 
-       while (remains > 0) {
-               remains = m_sensor->get_data(&data, &length);
-               if (remains < 0) {
-                       _E("Failed to get sensor data");
-                       break;
-               }
+       for (; it != m_sensors.end(); ++it) {
+               remains = 1;
+               sensor = *it;
 
-               if (m_sensor->on_event(data, length, remains) < 0) {
-                       free(data);
-                       data = NULL;
+               /* check whether the id of this sensor is in id list(parameter) or not */
+               auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id());
+               if (result == std::end(ids))
                        continue;
-               }
 
-               info = m_sensor->get_sensor_info();
+               while (remains > 0) {
+                       remains = sensor->get_data(&data, &length);
+                       if (remains < 0) {
+                               _E("Failed to get sensor data");
+                               break;
+                       }
+
+                       if (sensor->on_event(data, length, remains) < 0) {
+                               free(data);
+                               continue;
+                       }
+
+                       info = sensor->get_sensor_info();
 
-               //_I("[Data] allocate %p", data);
-               if (data) {
-                       if (m_sensor->notify(info.get_uri().c_str(), data, length) < 0) {
+                       //_I("[Data] allocate %p", data);
+                       if (sensor->notify(info.get_uri().c_str(), data, length) < 0) {
                                free(data);
-                               data = NULL;
                        }
+                       info.clear();
                }
-               info.clear();
        }
 
-       ids.clear();
-
        return true;
 }
index 53b5cd6..f956fdd 100644 (file)
@@ -21,6 +21,8 @@
 #define __SENSOR_EVENT_HANDLER__
 
 #include <event_handler.h>
+#include <set>
+
 #include "physical_sensor_handler.h"
 
 namespace sensor {
@@ -28,12 +30,15 @@ namespace sensor {
 class sensor_event_handler : public ipc::event_handler
 {
 public:
-       sensor_event_handler(physical_sensor_handler *sensor);
+       sensor_event_handler();
+
+       void add_sensor(physical_sensor_handler *sensor);
+       void remove_sensor(physical_sensor_handler *sensor);
 
        bool handle(int fd, ipc::event_condition condition);
 
 private:
-       physical_sensor_handler *m_sensor;
+       std::set<physical_sensor_handler *> m_sensors;
 };
 
 }
index b9cdfca..3939d04 100644 (file)
@@ -43,6 +43,9 @@ sensor_handler::sensor_handler(const sensor_info &info)
        case EXERCISE_STANDALONE_SENSOR:
                m_info.add_privilege(PRIVILEGE_LOCATION_URI);
                break;
+       case GPS_CTRL_SENSOR:
+               m_info.add_privilege(PRIVILEGE_PLATFORM_URI);
+               break;
        default:
                break;
        }
@@ -58,11 +61,12 @@ bool sensor_handler::has_observer(sensor_observer *ob)
        return false;
 }
 
-void sensor_handler::add_observer(sensor_observer *ob)
+bool sensor_handler::add_observer(sensor_observer *ob)
 {
-       ret_if(has_observer(ob));
+       retv_if(has_observer(ob), false);
 
        m_observers.push_back(ob);
+       return true;
 }
 
 void sensor_handler::remove_observer(sensor_observer *ob)
@@ -83,13 +87,11 @@ int sensor_handler::notify(const char *uri, sensor_data_t *data, int len)
        for (auto it = m_observers.begin(); it != m_observers.end(); ++it)
                (*it)->update(uri, msg);
 
-       if (msg->ref_count() == 0) {
-               delete msg;
-               msg = NULL;
-       }
-
        set_cache(data, len);
 
+       if (msg->ref_count() == 0)
+               msg->unref();
+
        return OP_SUCCESS;
 }
 
@@ -100,15 +102,12 @@ uint32_t sensor_handler::observer_count(void)
 
 void sensor_handler::set_cache(sensor_data_t *data, int size)
 {
-       retm_if(data == NULL, "Nothing to copy from as source is NULL");
-       retm_if(size <= 0, "data is of size 0");
-
-       if (m_last_data_size != size) {
-               m_last_data = (sensor_data_t*)realloc(m_last_data, size);
+       if (m_last_data == NULL) {
+               m_last_data = (sensor_data_t*)malloc(size);
                retm_if(m_last_data == NULL, "Memory allocation failed");
-               m_last_data_size = size;
        }
 
+       m_last_data_size = size;
        memcpy(m_last_data, data, size);
 }
 
@@ -124,3 +123,8 @@ int sensor_handler::get_cache(sensor_data_t **data, int *len)
 
        return 0;
 }
+
+int sensor_handler::delete_batch_latency(sensor_observer *ob)
+{
+       return 0;
+}
index db237e4..9f6e711 100644 (file)
@@ -35,7 +35,7 @@ public:
 
        /* publisher */
        bool has_observer(sensor_observer *ob);
-       void add_observer(sensor_observer *ob);
+       bool add_observer(sensor_observer *ob);
        void remove_observer(sensor_observer *ob);
        int notify(const char *type, sensor_data_t *data, int len);
        uint32_t observer_count(void);
@@ -47,6 +47,7 @@ public:
 
        virtual int set_interval(sensor_observer *ob, int32_t interval) = 0;
        virtual int set_batch_latency(sensor_observer *ob, int32_t latency) = 0;
+       virtual int delete_batch_latency(sensor_observer *ob);
        virtual int set_attribute(sensor_observer *ob, int32_t attr, int32_t value) = 0;
        virtual int set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len) = 0;
        virtual int flush(sensor_observer *ob) = 0;
index 8d3c3bc..77a2ff7 100644 (file)
@@ -26,6 +26,7 @@
 #include <sensor_types.h>
 
 #include "sensor_handler.h"
+#include "sensor_policy_monitor.h"
 
 using namespace sensor;
 
@@ -35,15 +36,18 @@ sensor_listener_proxy::sensor_listener_proxy(uint32_t id,
 , m_uri(uri)
 , m_manager(manager)
 , m_ch(ch)
+, m_started(false)
 , m_passive(false)
 , m_pause_policy(SENSORD_PAUSE_ALL)
 , m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED)
 , m_last_accuracy(SENSOR_ACCURACY_UNDEFINED)
 {
+       sensor_policy_monitor::get_instance().add_listener(this);
 }
 
 sensor_listener_proxy::~sensor_listener_proxy()
 {
+       sensor_policy_monitor::get_instance().remove_listener(this);
        stop();
 }
 
@@ -93,33 +97,48 @@ void sensor_listener_proxy::update_accuracy(ipc::message *msg)
        m_ch->send(acc_msg);
 }
 
-int sensor_listener_proxy::start(void)
+int sensor_listener_proxy::start(bool policy)
 {
+       int ret;
        sensor_handler *sensor = m_manager->get_sensor(m_uri);
        retv_if(!sensor, -EINVAL);
+       retvm_if(m_started && !policy, OP_SUCCESS, "Sensor is already started");
 
        _D("Listener[%d] try to start", get_id());
 
-       /* TODO: listen pause policy */
-       return sensor->start(this);
+       ret = sensor->start(this);
+       retv_if (ret < 0, OP_ERROR);
+
+       /* m_started is changed only when it is explicitly called by user,
+        * not automatically determined by any pause policy. */
+       if (policy)
+               return OP_SUCCESS;
+
+       m_started = true;
+       return OP_SUCCESS;
 }
 
-int sensor_listener_proxy::stop(void)
+int sensor_listener_proxy::stop(bool policy)
 {
        sensor_handler *sensor = m_manager->get_sensor(m_uri);
        retv_if(!sensor, -EINVAL);
-
-       /* TODO: listen pause policy */
+       retvm_if(!m_started && !policy, OP_SUCCESS, "Sensor is already stopped");
 
        _D("Listener[%d] try to stop", get_id());
 
        int ret = sensor->stop(this);
        retv_if(ret < 0, OP_ERROR);
 
+       /* attributes and m_started are changed only when it is explicitly called by user,
+        * not automatically determined by any policy. */
+       if (policy)
+               return OP_SUCCESS;
+
        /* unset attributes */
-       set_interval(POLL_1HZ_MS);
-       set_max_batch_latency(0);
+       set_interval(POLL_MAX_HZ_MS);
+       delete_batch_latency();
 
+       m_started = false;
        return OP_SUCCESS;
 }
 
@@ -143,6 +162,16 @@ int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency)
        return sensor->set_batch_latency(this, max_batch_latency);
 }
 
+int sensor_listener_proxy::delete_batch_latency(void)
+{
+       sensor_handler *sensor = m_manager->get_sensor(m_uri);
+       retv_if(!sensor, -EINVAL);
+
+       _I("Listener[%d] try to delete batch latency", get_id());
+
+       return sensor->delete_batch_latency(this);
+}
+
 int sensor_listener_proxy::set_passive_mode(bool passive)
 {
        /* TODO: passive mode */
@@ -163,6 +192,8 @@ int sensor_listener_proxy::set_attribute(int attribute, int value)
        } else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) {
                m_axis_orientation = value;
                return OP_SUCCESS;
+       } else if (attribute == SENSORD_ATTRIBUTE_FLUSH) {
+               return flush();
        }
 
        return sensor->set_attribute(this, attribute, value);
@@ -202,3 +233,18 @@ std::string sensor_listener_proxy::get_required_privileges(void)
        sensor_info info = sensor->get_sensor_info();
        return info.get_privilege();
 }
+
+void sensor_listener_proxy::on_policy_changed(int policy, int value)
+{
+       ret_if(m_started == false);
+       ret_if(policy != SENSORD_ATTRIBUTE_PAUSE_POLICY);
+       ret_if(m_pause_policy == SENSORD_PAUSE_NONE);
+
+       _D("power_save_state[%d], listener[%d] pause policy[%d]",
+                       value, get_id(), m_pause_policy);
+
+       if (value & m_pause_policy)
+               stop(true);
+       if (!(value & m_pause_policy))
+               start(true);
+}
index 30e3976..8258f63 100644 (file)
 
 #include "sensor_manager.h"
 #include "sensor_observer.h"
+#include "sensor_policy_listener.h"
 
 namespace sensor {
 
-class sensor_listener_proxy : public sensor_observer {
+class sensor_listener_proxy : public sensor_observer, sensor_policy_listener {
 public:
        sensor_listener_proxy(uint32_t id,
                        std::string uri, sensor_manager *manager, ipc::channel *ch);
@@ -39,11 +40,12 @@ public:
        /* sensor observer */
        int update(const char *uri, ipc::message *msg);
 
-       int start(void);
-       int stop(void);
+       int start(bool policy = false);
+       int stop(bool policy = false);
 
        int set_interval(unsigned int interval);
        int set_max_batch_latency(unsigned int max_batch_latency);
+       int delete_batch_latency(void);
        int set_passive_mode(bool passive);
        int set_attribute(int attribute, int value);
        int set_attribute(int attribute, const char *value, int len);
@@ -51,6 +53,9 @@ public:
        int get_data(sensor_data_t **data, int *len);
        std::string get_required_privileges(void);
 
+       /* sensor_policy_listener interface */
+       void on_policy_changed(int policy, int value);
+
 private:
        void update_event(ipc::message *msg);
        void update_accuracy(ipc::message *msg);
@@ -61,6 +66,7 @@ private:
        sensor_manager *m_manager;
        ipc::channel *m_ch;
 
+       bool m_started;
        bool m_passive;
        int m_pause_policy;
        int m_axis_orientation;
index 7ee0766..f6cc1f5 100644 (file)
@@ -138,13 +138,11 @@ void sensor_manager::send_added_msg(sensor_info *info)
        int size;
 
        size = serialize(info, &bytes);
-       retm_if(size == -ENOMEM, "Failed to serialize");
 
        ipc::message msg((const char *)bytes, size);
        msg.set_type(CMD_MANAGER_SENSOR_ADDED);
 
        send(msg);
-       delete []bytes;
 }
 
 void sensor_manager::send_removed_msg(const std::string &uri)
@@ -240,6 +238,18 @@ std::vector<sensor_handler *> sensor_manager::get_sensors(void)
        return sensors;
 }
 
+static physical_sensor *create_physical_sensor(std::string uri, physical_sensor_registry_t &psensors)
+{
+       for (auto it = psensors.begin(); it != psensors.end(); ++it) {
+               if (uri.find((*it)->get_uri()) != std::string::npos) {
+                       _D("%s, %s", uri.c_str(), (*it)->get_uri().c_str());
+                       return (*it)->clone();
+               }
+       }
+
+       return NULL;
+}
+
 void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices,
                physical_sensor_registry_t &psensors)
 {
@@ -250,13 +260,19 @@ void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices,
                int count = (*it)->get_sensors(&info);
 
                for (int i = 0; i < count; ++i) {
-                       /* TODO: psensors */
+                       physical_sensor *sensor = NULL;
+                       sensor_info pinfo(info[i]);
+                       std::string uri = pinfo.get_uri();
+
+                       sensor = create_physical_sensor(uri, psensors);
+                       if (sensor)
+                               sensor->set_device(it->get());
+
                        psensor = new(std::nothrow) physical_sensor_handler(
-                                       info[i], it->get(), info[i].id, NULL);
+                                       info[i], it->get(), info[i].id, sensor);
                        retm_if(!psensor, "Failed to allocate memory");
 
-                       sensor_info sinfo = psensor->get_sensor_info();
-                       m_sensors[sinfo.get_uri()] = psensor;
+                       m_sensors[uri] = psensor;
                }
        }
 }
@@ -376,12 +392,25 @@ void sensor_manager::init_sensors(void)
 
 void sensor_manager::register_handler(physical_sensor_handler *sensor)
 {
-       ret_if(sensor->get_poll_fd() < 0);
+       sensor_event_handler *handler = NULL;
+       int fd = sensor->get_poll_fd();
+
+       ret_if(fd < 0);
+
+       auto it = m_event_handlers.find(fd);
 
-       sensor_event_handler *handler = new(std::nothrow) sensor_event_handler(sensor);
+       if (it != m_event_handlers.end()) {
+               it->second->add_sensor(sensor);
+               return;
+       }
+
+       handler = new(std::nothrow) sensor_event_handler();
        retm_if(!handler, "Failed to allocate memory");
 
-       m_loop->add_event(sensor->get_poll_fd(),
+       handler->add_sensor(sensor);
+       m_event_handlers[fd] = handler;
+
+       m_loop->add_event(fd,
                        ipc::EVENT_IN | ipc::EVENT_HUP | ipc::EVENT_NVAL, handler);
 }
 
index 78692a8..aac7e93 100644 (file)
@@ -34,6 +34,7 @@
 #include "physical_sensor_handler.h"
 #include "fusion_sensor_handler.h"
 #include "external_sensor_handler.h"
+#include "sensor_event_handler.h"
 
 namespace sensor {
 
@@ -84,6 +85,7 @@ private:
        sensor_map_t m_sensors;
 
        std::vector<ipc::channel *> m_channels;
+       std::map<int, sensor_event_handler *> m_event_handlers;
 };
 
 }
similarity index 65%
rename from src/sensor/hrm/hrm_sensor.h
rename to src/server/sensor_policy_listener.h
index 1c64bc5..383aad4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * sensord
  *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
  *
  */
 
-#ifndef _HRM_SENSOR_H_
-#define _HRM_SENSOR_H_
+#ifndef __SENSOR_POLICY_LISTENER_H__
+#define __SENSOR_POLICY_LISTENER_H__
 
-#include <physical_sensor.h>
-
-class hrm_sensor : public physical_sensor {
+namespace sensor {
+class sensor_policy_listener {
 public:
-       hrm_sensor();
-       virtual ~hrm_sensor();
-};
+       virtual ~sensor_policy_listener() {}
 
-#endif /* _HRM_SENSOR_H_ */
+       virtual void on_policy_changed(int policy, int value) = 0;
+};
+}
 
+#endif /* __SENSOR_POLICY_LISTENER_H__ */
diff --git a/src/server/sensor_policy_monitor.cpp b/src/server/sensor_policy_monitor.cpp
new file mode 100644 (file)
index 0000000..9ab0f2b
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 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_policy_monitor.h"
+
+#include <sensor_log.h>
+#include <sensor_types.h>
+
+#ifndef VCONFKEY_SETAPPL_PSMODE
+#define VCONFKEY_SETAPPL_PSMODE "db/setting/psmode"
+#endif
+
+using namespace sensor;
+
+static int get_power_save_state(void)
+{
+       int ret;
+       int state = 0;
+       int pm_state, ps_state;
+
+       ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
+
+       if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF)
+               state |= SENSORD_PAUSE_ON_DISPLAY_OFF;
+
+       ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state);
+
+       if (!ret && ps_state != SETTING_PSMODE_NORMAL)
+               state |= SENSORD_PAUSE_ON_POWERSAVE_MODE;
+
+       return state;
+}
+
+static void power_save_state_cb(keynode_t *node, void *data)
+{
+       int power_save_state = get_power_save_state();
+
+       sensor_policy_monitor::get_instance().on_policy_changed(SENSORD_ATTRIBUTE_PAUSE_POLICY, power_save_state);
+}
+
+sensor_policy_monitor& sensor_policy_monitor::get_instance(void)
+{
+       static sensor_policy_monitor mon;
+       return mon;
+}
+
+sensor_policy_monitor::sensor_policy_monitor()
+{
+       vconf_notify_key_changed(VCONFKEY_PM_STATE, power_save_state_cb, NULL);
+       vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb, NULL);
+}
+
+sensor_policy_monitor::~sensor_policy_monitor()
+{
+       vconf_ignore_key_changed(VCONFKEY_PM_STATE, power_save_state_cb);
+       vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb);
+}
+
+void sensor_policy_monitor::add_listener(sensor_policy_listener *listener)
+{
+       ret_if(!listener);
+
+       m_listeners.insert(listener);
+}
+
+void sensor_policy_monitor::remove_listener(sensor_policy_listener *listener)
+{
+       ret_if(!listener);
+
+       m_listeners.erase(listener);
+}
+
+void sensor_policy_monitor::on_policy_changed(int policy, int value)
+{
+       auto it = m_listeners.begin();
+
+       while (it != m_listeners.end()) {
+               (*it)->on_policy_changed(policy, value);
+               ++it;
+       }
+}
diff --git a/src/server/sensor_policy_monitor.h b/src/server/sensor_policy_monitor.h
new file mode 100644 (file)
index 0000000..ba22199
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_POLICY_MONITOR_H__
+#define __SENSOR_POLICY_MONITOR_H__
+
+#include <channel.h>
+#include <message.h>
+#include <vconf.h>
+#include <set>
+
+#include "sensor_policy_listener.h"
+
+namespace sensor {
+
+class sensor_policy_monitor {
+public:
+       ~sensor_policy_monitor();
+
+       static sensor_policy_monitor& get_instance(void);
+
+       void add_listener(sensor_policy_listener *listener);
+       void remove_listener(sensor_policy_listener *listener);
+
+       void on_policy_changed(int policy, int value);
+
+private:
+       sensor_policy_monitor();
+
+       std::set<sensor_policy_listener *> m_listeners;
+};
+
+}
+
+#endif /* __SENSOR_POLICY_MONITOR_H__ */
index 58bb996..160237c 100644 (file)
@@ -31,7 +31,7 @@ public:
        virtual ~sensor_publisher() {}
 
        virtual bool has_observer(sensor_observer *ob) = 0;
-       virtual void add_observer(sensor_observer *ob) = 0;
+       virtual bool add_observer(sensor_observer *ob) = 0;
        virtual void remove_observer(sensor_observer *ob) = 0;
        virtual int notify(const char *type, sensor_data_t *data, int len) = 0;
 };
index a62b75b..780cc3d 100644 (file)
@@ -141,18 +141,13 @@ int server_channel_handler::listener_connect(channel *ch, message &msg)
 
        msg.disclose((char *)&buf);
 
-       sensor_listener_proxy *listener = NULL;
+       sensor_listener_proxy *listener;
        listener = new(std::nothrow) sensor_listener_proxy(listener_id,
                                buf.sensor, m_manager, ch);
        retvm_if(!listener, OP_ERROR, "Failed to allocate memory");
-
-       if (!has_privileges(ch->get_fd(), listener->get_required_privileges())) {
-               delete listener;
-               listener = NULL;
-               _E("Permission denied[%d, %s]", listener_id,
-                       m_listeners[listener_id]->get_required_privileges().c_str());
-               return -EACCES;
-       }
+       retvm_if(!has_privileges(ch->get_fd(), listener->get_required_privileges()),
+                       -EACCES, "Permission denied[%d, %s]",
+                       listener_id, m_listeners[listener_id]->get_required_privileges().c_str());
 
        buf.listener_id = listener_id;
 
@@ -160,10 +155,8 @@ int server_channel_handler::listener_connect(channel *ch, message &msg)
        reply.enclose((const char *)&buf, sizeof(buf));
        reply.header()->err = OP_SUCCESS;
 
-       if (!ch->send_sync(&reply)) {
-               delete listener;
+       if (!ch->send_sync(&reply))
                return OP_ERROR;
-       }
 
        _I("Connected sensor_listener[fd(%d) -> id(%u)]", ch->get_fd(), listener_id);
        m_listeners[listener_id] = listener;
@@ -237,7 +230,7 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg)
        }
        /* TODO : check return value */
        if (ret < 0)
-               _W("Return : %d", ret);
+               _D("Return : %d", ret);
 
        return send_reply(ch, OP_SUCCESS);
 }
@@ -265,7 +258,7 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg)
                return -EACCES;
        }
 
-       int ret = m_listeners[id]->set_attribute(buf->attribute, (char *)&buf->value, buf->len);
+       int ret = m_listeners[id]->set_attribute(buf->attribute, buf->value, buf->len);
        if (ret < 0) {
                delete [] buf;
                return ret;
index eb20325..11f605b 100644 (file)
@@ -1,7 +1,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(sensord-shared CXX)
 
-SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0")
+SET(DEPENDENTS "dlog libsystemd-daemon glib-2.0 gio-2.0 vconf libtzplatform-config")
 
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(SHARED_PKGS REQUIRED ${DEPENDENTS})
diff --git a/src/shared/cbase_lock.cpp b/src/shared/cbase_lock.cpp
new file mode 100644 (file)
index 0000000..38f2f84
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * 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 <pthread.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <cbase_lock.h>
+#include <sensor_log.h>
+
+cbase_lock::cbase_lock()
+{
+       m_history_mutex = PTHREAD_MUTEX_INITIALIZER;
+}
+
+cbase_lock::~cbase_lock()
+{
+       pthread_mutex_destroy(&m_history_mutex);
+}
+
+void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line)
+{
+       int ret = 0;
+       char m_curent_info[OWNER_INFO_LEN];
+       struct timeval sv;
+       unsigned long long lock_waiting_start_time = 0;
+       unsigned long long lock_acquired_time = 0;
+       unsigned long long waiting_time = 0;
+
+       snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line);
+
+       if (type == LOCK_TYPE_MUTEX)
+               ret = try_lock_impl();
+       else if (type == LOCK_TYPE_READ)
+               ret = try_read_lock_impl();
+       else if (type == LOCK_TYPE_WRITE)
+               ret = try_write_lock_impl();
+
+       if (ret == 0) {
+               pthread_mutex_lock(&m_history_mutex);
+               snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
+               pthread_mutex_unlock(&m_history_mutex);
+               return;
+       }
+
+       gettimeofday(&sv, NULL);
+       lock_waiting_start_time = MICROSECONDS(sv);
+
+       pthread_mutex_lock(&m_history_mutex);
+       _I("%s is waiting for getting %s(%#x) owned in %s",
+               m_curent_info, expr, this, m_owner_info);
+       pthread_mutex_unlock(&m_history_mutex);
+
+       if (type == LOCK_TYPE_MUTEX)
+               lock_impl();
+       else if (type == LOCK_TYPE_READ)
+               read_lock_impl();
+       else if (type == LOCK_TYPE_WRITE)
+               write_lock_impl();
+
+       gettimeofday(&sv, NULL);
+       lock_acquired_time = MICROSECONDS(sv);
+
+       waiting_time = lock_acquired_time - lock_waiting_start_time;
+
+       pthread_mutex_lock(&m_history_mutex);
+       _I("%s acquires lock after waiting %lluus, %s(%#x) was previously owned in %s",
+               m_curent_info, waiting_time, expr, this, m_owner_info);
+       snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
+       pthread_mutex_unlock(&m_history_mutex);
+}
+
+void cbase_lock::lock(lock_type type)
+{
+       if (type == LOCK_TYPE_MUTEX)
+               lock_impl();
+       else if (type == LOCK_TYPE_READ)
+               read_lock_impl();
+       else if (type == LOCK_TYPE_WRITE)
+               write_lock_impl();
+}
+
+void cbase_lock::unlock(void)
+{
+       unlock_impl();
+}
+
+int cbase_lock::lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::read_lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::write_lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::try_lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::try_read_lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::try_write_lock_impl(void)
+{
+       return 0;
+}
+
+int cbase_lock::unlock_impl(void)
+{
+       return 0;
+}
+
+Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line)
+: m_lock(m)
+{
+       m_lock.lock(type, expr, module, func, line);
+}
+
+Autolock::Autolock(cbase_lock &m, lock_type type)
+: m_lock(m)
+{
+       m_lock.lock(type);
+}
+
+Autolock::~Autolock()
+{
+       m_lock.unlock();
+}
diff --git a/src/shared/cbase_lock.h b/src/shared/cbase_lock.h
new file mode 100644 (file)
index 0000000..2de5c7e
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef _CBASE_LOCK_H_
+#define _CBASE_LOCK_H_
+
+#include <pthread.h>
+
+enum lock_type {
+       LOCK_TYPE_MUTEX,
+       LOCK_TYPE_READ,
+       LOCK_TYPE_WRITE,
+};
+
+#ifndef MICROSECONDS
+#define MICROSECONDS(tv)        ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+#endif
+
+#ifdef _LOCK_DEBUG
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ, #x,  __MODULE__, __func__, __LINE__)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
+#define LOCK(x)                (x).lock(#x, __MODULE__, __func__, __LINE__)
+#define LOCK_R(x)      (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
+#define LOCK_W(x)      (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
+#define UNLOCK(x)      (x).unlock()
+#else
+#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX)
+#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ)
+#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE)
+#define LOCK(x)                (x).lock()
+#define LOCK_R(x)      (x).lock(LOCK_TYPE_READ)
+#define LOCK_W(x)      (x).lock(LOCK_TYPE_WRITE)
+#define UNLOCK(x)      (x).unlock()
+#endif
+
+class cbase_lock {
+public:
+       cbase_lock();
+       virtual ~cbase_lock();
+
+       void lock(lock_type type, const char* expr, const char *module, const char *func, int line);
+       void lock(lock_type type);
+       void unlock(void);
+
+protected:
+       virtual int lock_impl(void);
+       virtual int read_lock_impl(void);
+       virtual int write_lock_impl(void);
+
+       virtual int try_lock_impl(void);
+       virtual int try_read_lock_impl(void);
+       virtual int try_write_lock_impl(void);
+
+       virtual int unlock_impl(void);
+private:
+       pthread_mutex_t m_history_mutex;
+       static const int OWNER_INFO_LEN = 256;
+       char m_owner_info[OWNER_INFO_LEN];
+};
+
+class Autolock {
+private:
+       cbase_lock& m_lock;
+public:
+       Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line);
+       Autolock(cbase_lock &m, lock_type type);
+       ~Autolock();
+};
+
+#endif /* _CBASE_LOCK_H_ */
index 639e9c1..f27e1d4 100644 (file)
@@ -26,7 +26,7 @@
 #include "sensor_log.h"
 #include "channel_event_handler.h"
 
-#define SYSTEMD_SOCK_BUF_SIZE 40000
+#define SYSTEMD_SOCK_BUF_SIZE (128*1024)
 
 using namespace ipc;
 
@@ -49,13 +49,8 @@ public:
                if (!m_ch->send_sync(m_msg))
                        return false;
 
-               if (m_msg) {
+               if (m_msg)
                        m_msg->unref();
-                       if(m_msg->ref_count() <= 0) {
-                               delete m_msg;
-                               m_msg = NULL;
-                       }
-               }
 
                return false;
        }
@@ -100,14 +95,27 @@ channel::channel(socket *sock)
 , m_loop(NULL)
 , m_connected(false)
 {
+       _D("Created");
 }
 
 channel::~channel()
 {
-       /* disconnect() should not be called here */
+       _D("Destroyed[%llu]", m_event_id);
+       disconnect();
 }
 
-void channel::bind(channel_handler *handler, event_loop *loop)
+uint64_t channel::bind(void)
+{
+       retv_if(!m_loop, 0);
+       m_event_id = m_loop->add_event(m_socket->get_fd(),
+                       (EVENT_IN | EVENT_HUP | EVENT_NVAL),
+                       dynamic_cast<channel_event_handler *>(m_handler));
+
+       _D("Bound[%llu]", m_event_id);
+       return m_event_id;
+}
+
+uint64_t channel::bind(channel_handler *handler, event_loop *loop, bool loop_bind)
 {
        m_handler = handler;
        m_loop = loop;
@@ -115,53 +123,71 @@ void channel::bind(channel_handler *handler, event_loop *loop)
 
        if (m_handler)
                m_handler->connected(this);
-}
 
-void channel::bind(void)
-{
-       ret_if(!m_loop);
-       m_event_id = m_loop->add_event(m_socket->get_fd(),
-                       (EVENT_IN | EVENT_HUP | EVENT_NVAL),
-                       dynamic_cast<channel_event_handler *>(m_handler));
+       if (loop_bind)
+               bind();
+
+       return m_event_id;
 }
 
-bool channel::connect(channel_handler *handler, event_loop *loop)
+uint64_t channel::connect(channel_handler *handler, event_loop *loop, bool loop_bind)
 {
        if (!m_socket->connect())
                return false;
 
-       bind(handler, loop);
-       return true;
+       bind(handler, loop, loop_bind);
+
+       _D("Connected[%llu]", m_event_id);
+       return m_event_id;
 }
 
 void channel::disconnect(void)
 {
-       ret_if(!is_connected());
+       if (!is_connected()) {
+               _D("Channel is not connected");
+               return;
+       }
+
        m_connected.store(false);
 
+       _D("Disconnecting..[%llu]", m_event_id);
+
        if (m_handler) {
                m_handler->disconnected(this);
                m_handler = NULL;
        }
 
        if (m_loop) {
+               _D("Remove event[%llu]", m_event_id);
                m_loop->remove_event(m_event_id, true);
                m_loop = NULL;
                m_event_id = 0;
        }
 
        if (m_socket) {
+               _D("Release socket[%d]", m_socket->get_fd());
                delete m_socket;
                m_socket = NULL;
        }
+
+       _D("Disconnected");
 }
 
 bool channel::send(message *msg)
 {
+       int retry_cnt = 0;
+       int cur_buffer_size = 0;
+
        retv_if(!m_loop, false);
 
-       int cur_buffer_size = m_socket->get_current_buffer_size();
-       retv_if(cur_buffer_size > SYSTEMD_SOCK_BUF_SIZE, false);
+       while (retry_cnt < 3) {
+               cur_buffer_size = m_socket->get_current_buffer_size();
+               if (cur_buffer_size <= SYSTEMD_SOCK_BUF_SIZE)
+                       break;
+               usleep(3000);
+               retry_cnt++;
+       }
+       retvm_if(retry_cnt >= 3, false, "Socket buffer[%d] is exceeded", cur_buffer_size);
 
        send_event_handler *handler = new(std::nothrow) send_event_handler(this, msg);
        retvm_if(!handler, false, "Failed to allocate memory");
@@ -176,20 +202,23 @@ bool channel::send(message *msg)
 
 bool channel::send_sync(message *msg)
 {
-       retv_if(!msg, false);
+       retvm_if(!msg, false, "Invalid message");
+       retvm_if(msg->size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg->size());
 
        ssize_t size = 0;
        char *buf = msg->body();
 
        /* header */
        size = m_socket->send(reinterpret_cast<void *>(msg->header()),
-                                  sizeof(message_header), true);
-       retv_if(size <= 0, false);
-       retv_if(msg->size() <= 0, true);
+           sizeof(message_header), true);
+       retvm_if(size <= 0, false, "Failed to send header");
+
+       /* if body size is zero, skip to send body message */
+       retv_if(msg->size() == 0, true);
 
        /* body */
        size = m_socket->send(buf, msg->size(), true);
-       retv_if(size <= 0, false);
+       retvm_if(size <= 0, false, "Failed to send body");
 
        return true;
 }
@@ -224,6 +253,11 @@ bool channel::read_sync(message &msg, bool select)
        }
 
        /* body */
+       if (header.length >= MAX_MSG_CAPACITY) {
+               _E("header.length error %u", header.length);
+               return false;
+       }
+
        if (header.length > 0) {
                size = m_socket->recv(&buf, header.length, select);
                retv_if(size <= 0, false);
@@ -284,8 +318,3 @@ int channel::get_fd(void) const
 {
        return m_fd;
 }
-
-void channel::set_event_id(uint64_t id)
-{
-       m_event_id = id;
-}
index f8c525c..efdc481 100644 (file)
@@ -38,11 +38,10 @@ public:
        channel(socket *sock);
        ~channel();
 
-       /* TODO */
-       void bind(void);
-       void bind(channel_handler *handler, event_loop *loop);
+       uint64_t bind(void);
+       uint64_t bind(channel_handler *handler, event_loop *loop, bool loop_bind);
 
-       bool connect(channel_handler *handler, event_loop *loop);
+       uint64_t connect(channel_handler *handler, event_loop *loop, bool loop_bind);
        void disconnect(void);
 
        bool is_connected(void);
@@ -57,7 +56,6 @@ public:
        bool set_option(int type, int value);
 
        int  get_fd(void) const;
-       void set_event_id(uint64_t id);
 
 private:
        int m_fd;
index 8a6b64b..9c48c0d 100644 (file)
@@ -45,12 +45,14 @@ bool channel_event_handler::handle(int fd, event_condition condition)
                return false;
 
        if (condition & (EVENT_HUP)) {
+               _D("The other proccess is dead");
                m_ch->disconnect();
+               m_ch = NULL;
                return false;
        }
 
        if (!m_ch->read_sync(msg, false)) {
-               m_ch->disconnect();
+               m_ch = NULL;
                return false;
        }
 
diff --git a/src/shared/cmutex.cpp b/src/shared/cmutex.cpp
new file mode 100644 (file)
index 0000000..6245b6e
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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 <cmutex.h>
+#include <sensor_log.h>
+
+cmutex::cmutex()
+{
+       pthread_mutexattr_t mutex_attr;
+       pthread_mutexattr_init(&mutex_attr);
+       pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
+       pthread_mutex_init(&m_mutex, &mutex_attr);
+       pthread_mutexattr_destroy(&mutex_attr);
+}
+
+cmutex::~cmutex()
+{
+       pthread_mutex_destroy(&m_mutex);
+}
+
+void cmutex::lock(void)
+{
+#ifdef _LOCK_DEBUG
+       cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__);
+#else
+       cbase_lock::lock(LOCK_TYPE_MUTEX);
+#endif
+}
+
+void cmutex::lock(const char* expr, const char *module, const char *func, int line)
+{
+       cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line);
+}
+
+int cmutex::lock_impl(void)
+{
+       return pthread_mutex_lock(&m_mutex);
+}
+
+int cmutex::try_lock_impl(void)
+{
+       return pthread_mutex_trylock(&m_mutex);
+}
+
+int cmutex::unlock_impl(void)
+{
+       return pthread_mutex_unlock(&m_mutex);
+}
similarity index 58%
rename from src/sensor/accel/accel_sensor.h
rename to src/shared/cmutex.h
index 309f91b..94aa2b6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * sensord
  *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * 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.
  *
  */
 
-#ifndef _ACCEL_SENSOR_H_
-#define _ACCEL_SENSOR_H_
+#ifndef _CMUTEX_H_
+#define _CMUTEX_H_
 
-#include <physical_sensor.h>
+#include "cbase_lock.h"
 
-class accel_sensor : public physical_sensor {
+class cmutex : public cbase_lock {
 public:
-       accel_sensor();
-       ~accel_sensor();
+       cmutex();
+       virtual ~cmutex();
 
-       sensor_type_t get_type(void);
-};
+       void lock(void);
+       void lock(const char* expr, const char *module, const char *func, int line);
+
+protected:
+       int lock_impl(void);
+       int try_lock_impl(void);
+       int unlock_impl(void);
 
-#endif /* _ACCEL_SENSOR_H_ */
+private:
+       pthread_mutex_t m_mutex;
+};
 
+#endif /* _CMUTEX_H_ */
index 34cb5fc..0bc2de5 100644 (file)
@@ -24,7 +24,7 @@
 #include "sensor_info.h"
 
 #define SENSOR_CHANNEL_PATH            "/run/.sensord.socket"
-#define MAX_BUF_SIZE 10240
+#define MAX_BUF_SIZE (16*1024)
 
 /* TODO: OOP - create serializer interface */
 enum cmd_type_e {
@@ -53,6 +53,7 @@ enum cmd_type_e {
        CMD_PROVIDER_STOP,
        CMD_PROVIDER_ATTR_INT,
        CMD_PROVIDER_PUBLISH,
+       CMD_PROVIDER_ATTR_STR,
 
        /* Etc */
        CMD_HAS_PRIVILEGE = 0x1000,
@@ -110,6 +111,12 @@ typedef struct  {
        int value;
 } cmd_provider_attr_int_t;
 
+typedef struct  {
+       int attribute;
+       int len;
+       char value[0];
+} cmd_provider_attr_str_t;
+
 typedef struct {
        char sensor[NAME_MAX];
 } cmd_has_privilege_t ;
index 881d39d..d923d78 100644 (file)
@@ -95,17 +95,19 @@ event_loop::event_loop(GMainLoop *mainloop)
 , m_sequence(1)
 , m_term_fd(-1)
 {
-       if (m_mainloop) {
-               g_main_loop_quit(m_mainloop);
-               g_main_loop_unref(m_mainloop);
-       }
-
        m_mainloop = mainloop;
 }
 
 event_loop::~event_loop()
 {
-       remove_all_events();
+       _D("Destoryed");
+}
+
+void event_loop::set_mainloop(GMainLoop *mainloop)
+{
+       retm_if(!mainloop, "Invalid mainloop");
+
+       m_mainloop = mainloop;
 }
 
 uint64_t event_loop::add_event(const int fd, const event_condition cond, event_handler *handler)
@@ -136,7 +138,7 @@ uint64_t event_loop::add_event(const int fd, const event_condition cond, event_h
 
        m_handlers[id] = info;
 
-       /* _D("Added[%llu](fd:%d)", id, fd); */
+       /* _D("Added event[%llu], fd[%d]", id, fd); */
        return id;
 }
 
@@ -144,16 +146,16 @@ uint64_t event_loop::add_idle_event(unsigned int priority, idle_handler *handler
 {
        GSource *src;
 
-       retvm_if(m_terminating.load(), false,
+       retvm_if(m_terminating.load(), 0,
                        "Failed to remove event, because event_loop is terminated");
 
        src = g_idle_source_new();
-       retvm_if(!src, false, "Failed to allocate memory");
+       retvm_if(!src, 0, "Failed to allocate memory");
 
        g_source_unref(src);
 
        /* Not Supported yet */
-       return false;
+       return 0;
 }
 
 bool event_loop::remove_event(uint64_t id, bool close_channel)
@@ -165,9 +167,9 @@ bool event_loop::remove_event(uint64_t id, bool close_channel)
                g_io_channel_shutdown(it->second->g_ch, TRUE, NULL);
 
        release_info(it->second);
-       m_handlers.erase(it);
+       m_handlers.erase(id);
 
-       /* _D("Removed[%llu]", id); */
+       /* _D("Removed event[%llu]", id); */
        return true;
 }
 
@@ -182,11 +184,11 @@ void event_loop::remove_all_events(void)
 
 void event_loop::release_info(handler_info *info)
 {
-       ret_if(!info->g_ch || info->id == 0);
+       retm_if(!info->g_ch || info->id == 0, "Invalid handler information");
+       /* _D("Releasing event..[%llu]", info->id); */
 
        g_source_destroy(info->g_src);
        g_source_unref(info->g_src);
-       info->g_src = NULL;
 
        g_io_channel_unref(info->g_ch);
        info->g_ch = NULL;
@@ -195,7 +197,8 @@ void event_loop::release_info(handler_info *info)
        info->handler = NULL;
 
        delete info;
-       info = NULL;
+
+       /* _D("Released event[%llu]", info->id); */
 }
 
 class terminator : public event_handler
@@ -218,7 +221,7 @@ private:
 bool event_loop::run(int timeout)
 {
        retvm_if(!m_mainloop, false, "Invalid GMainLoop");
-       retv_if(is_running(), false);
+       retvm_if(is_running(), false, "Already started");
 
        if (timeout > 0) {
                GSource *src = g_timeout_source_new(timeout);
index 870e6a3..f785c65 100644 (file)
@@ -46,7 +46,7 @@ class event_loop;
 
 class handler_info {
 public:
-       handler_info(int64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop)
+       handler_info(uint64_t _id, int _fd, GIOChannel *_ch, GSource *_src, event_handler *_handler, event_loop *_loop)
        : id(_id)
        , fd(_fd)
        , g_ch(_ch)
@@ -72,6 +72,8 @@ public:
        event_loop(GMainLoop *mainloop);
        ~event_loop();
 
+       void set_mainloop(GMainLoop *mainloop);
+
        uint64_t add_event(const int fd, const event_condition cond, event_handler *handler);
        uint64_t add_idle_event(unsigned int priority, idle_handler *handler);
 
index ea86baf..8c1dfa9 100644 (file)
@@ -55,9 +55,6 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi
        socket *sock = NULL;
        channel *ch = NULL;
        channel_event_handler *ev_handler = NULL;
-       bool ret = false;
-       retvm_if(access(m_path.c_str(), F_OK), NULL,
-                       "Failed to access to %s", m_path.c_str());
 
        sock = new(std::nothrow) stream_socket();
        retvm_if(!sock, NULL, "Failed to allocate memory");
@@ -78,25 +75,13 @@ channel *ipc_client::connect(channel_handler *handler, event_loop *loop, bool bi
        if (!ev_handler) {
                delete ch;
                delete sock;
-               _E("Faield to allocate memory");
+               _E("Failed to allocate memory");
                return NULL;
        }
 
-       ret = ch->connect(ev_handler, loop);
-       if(ret == false) {
-               delete ch;
-               delete sock;
-               delete ev_handler;
-               _E("Faield to connect");
-               return NULL;
-       }
+       uint64_t id = ch->connect(ev_handler, loop, bind);
 
-       if (loop && bind) {
-               uint64_t id = loop->add_event(sock->get_fd(),
-                               (EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);
-               ch->set_event_id(id);
-       }
+       _D("Connected[%llu]", id);
 
-       _I("Connected");
        return ch;
 }
index dba54f0..66431da 100644 (file)
@@ -57,7 +57,7 @@ void ipc_server::accept(ipc::socket &cli_sock)
 {
        m_accept_sock.accept(cli_sock);
 
-       _I("Accepted[%d]", cli_sock.get_fd());
+       _D("Accepted[%d]", cli_sock.get_fd());
 }
 
 bool ipc_server::bind(channel_handler *handler, event_loop *loop)
@@ -70,7 +70,7 @@ bool ipc_server::bind(channel_handler *handler, event_loop *loop)
 
        register_acceptor();
 
-       _I("Bound[%d]", m_accept_sock.get_fd());
+       _D("Bound[%d]", m_accept_sock.get_fd());
        return true;
 }
 
@@ -79,12 +79,12 @@ void ipc_server::register_channel(int fd, channel *ch)
        channel_event_handler *ev_handler = new(std::nothrow) channel_event_handler(ch, m_handler);
        retm_if(!ev_handler, "Failed to allocate memory");
 
-       ch->bind(ev_handler, m_event_loop);
-       uint64_t id = m_event_loop->add_event(fd,
-                       (event_condition)(EVENT_IN | EVENT_HUP | EVENT_NVAL), ev_handler);
+       uint64_t id = ch->bind(ev_handler, m_event_loop, true);
 
        if (id == 0)
                delete ev_handler;
+
+       _D("Registered event[%llu]", id);
 }
 
 void ipc_server::register_acceptor(void)
@@ -109,6 +109,5 @@ bool ipc_server::close(void)
 
        m_handler = NULL;
 
-       _I("Closed");
        return true;
 }
index 7a5f036..0ec7bcf 100644 (file)
@@ -42,7 +42,29 @@ static inline void __fclosep(FILE **f)
                fclose(*f);
 }
 
+static inline void int_to_bytes(int value, int width, char data[])
+{
+       /* Big-endian */
+       for (int i = width - 1; i >= 0; i--) {
+               data[i] = (value & 0xff);
+               value = value >> 8;
+       }
+}
+
+static inline unsigned int bytes_to_uint(char data[], int &cursor, int width)
+{
+       unsigned int sum = 0;
+
+       /* Big-endian */
+       for (int i = 0; i < width; ++i)
+               sum = (sum << 8) + (unsigned char)data[cursor++];
+
+       return sum;
+}
+
 #define _cleanup_free_ _cleanup_(__freep)
 #define _cleanup_close_ _cleanup_(__closep)
 #define _cleanup_fclose_ _cleanup_(__fclosep)
+#define GET_BYTES(value, width, data) int_to_bytes(value, width, data)
+#define GET_UINT(data, cursor, width) bytes_to_uint(data, cursor, width)
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
old mode 100755 (executable)
new mode 100644 (file)
index f53dd5e..d7455eb
@@ -21,8 +21,6 @@
 
 #include <sensor_log.h>
 #include <atomic>
-#include <memory>
-
 
 using namespace ipc;
 
@@ -33,37 +31,31 @@ static std::atomic<uint64_t> sequence(0);
 message::message(size_t capacity)
 : m_size(0)
 , m_capacity(capacity)
-, m_msg(new(std::nothrow) char[sizeof(char) * capacity])
+, m_msg((char *)malloc(sizeof(char) * capacity))
 , ref_cnt(0)
 {
        m_header.id = sequence++;
        m_header.type = UNDEFINED_TYPE;
        m_header.length = m_size;
        m_header.err = 0;
-
-       for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
-               m_header.ancillary[i] = NULL;
 }
 
 message::message(const void *msg, size_t sz)
 : m_size(sz)
 , m_capacity(sz)
-, m_msg(new(std::nothrow) char[sizeof(char) * sz])
+, m_msg((char *)msg)
 , ref_cnt(0)
 {
        m_header.id = sequence++;
        m_header.type = UNDEFINED_TYPE;
        m_header.length = m_size;
        m_header.err = 0;
-       ::memcpy(m_msg, msg, sz);
-       for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
-               m_header.ancillary[i] = NULL;
 }
 
 message::message(const message &msg)
 : m_size(msg.m_size)
 , m_capacity(msg.m_capacity)
-, m_msg(new(std::nothrow) char[(sizeof(char) * msg.m_capacity)])
+, m_msg((char *)malloc(sizeof(char) * msg.m_capacity))
 , ref_cnt(0)
 {
        ::memcpy(&m_header, &msg.m_header, sizeof(message_header));
@@ -80,15 +72,12 @@ message::message(int error)
        m_header.type = UNDEFINED_TYPE;
        m_header.length = 0;
        m_header.err = error;
-
-       for (int i = 0; i < MAX_HEADER_RESERVED; ++i)
-               m_header.ancillary[i] = NULL;
 }
 
 message::~message()
 {
-       if (m_msg) {
-               delete [] m_msg;
+       if (m_msg && ref_cnt == 0) {
+               free(m_msg);
                m_msg = NULL;
        }
 }
@@ -146,12 +135,12 @@ void message::unref(void)
 {
        ref_cnt--;
 
-       /*if (ref_cnt > 0 || !m_msg)
+       if (ref_cnt > 0 || !m_msg)
                return;
 
-       delete [] m_msg;
+       free(m_msg);
        m_msg = NULL;
-       delete this;*/
+       delete this;
 }
 
 int message::ref_count(void)
index 3b8fb67..118cf13 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h> /* size_t */
 #include <atomic>
 
-#define MAX_MSG_CAPACITY 10240
+#define MAX_MSG_CAPACITY (16*1024)
 #define MAX_HEADER_RESERVED 3
 
 namespace ipc {
index f2e0d49..46dcd32 100644 (file)
@@ -67,4 +67,9 @@
 #define LOG_DUMP(fp, fmt, arg...) \
        do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
 
+#define log_oom() ({ \
+       _E("Out of memory"); \
+       -ENOMEM;})
+
+
 #endif /* __SENSOR_LOG_H__ */
index d0ed9e2..b76a6fe 100644 (file)
@@ -34,6 +34,9 @@
 #define PRIVILEGE_LOCATION_STR "location"
 #define PRIVILEGE_LOCATION_URI "http://tizen.org/privilege/location"
 
+#define PRIVILEGE_PLATFORM_STR "platform"
+#define PRIVILEGE_PLATFORM_URI "http://tizen.org/privilege/internal/default/platform"
+
 #define URI_PRIV_INDEX 4
 #define URI_SENSOR_TYPE_INDEX 5
 
index 9bae0e6..b6e2eb2 100644 (file)
@@ -62,6 +62,8 @@ static std::map<sensor_type_t, const char *> types = {
        {GYROSCOPE_RV_SENSOR,            "http://tizen.org/sensor/general/gyroscope_rotation_vector"},
        {GEOMAGNETIC_RV_SENSOR,          "http://tizen.org/sensor/general/geomagnetic_rotation_vector"},
 
+       {SIGNIFICANT_MOTION_SENSOR,      "http://tizen.org/sensor/general/significant_motion"},
+
        {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"},
@@ -76,7 +78,6 @@ static std::map<sensor_type_t, const char *> types = {
        {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/healthinfo/external_exercise"},
 
        {FUSION_SENSOR,                  "http://tizen.org/sensor/general/fusion"},
        {AUTO_ROTATION_SENSOR,           "http://tizen.org/sensor/general/auto_rotation"},
@@ -86,13 +87,18 @@ static std::map<sensor_type_t, const char *> types = {
        {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_PICK_UP_SENSOR,         "http://tizen.org/sensor/general/gesture_pick_up"},
        {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/location/gps_batch"},
+       {PPG_BATCH_SENSOR,               "http://tizen.org/sensor/healthinfo/ppg_batch"},
+       {GPS_TIMESYNC_SENSOR,            "http://tizen.org/sensor/location/gps_timesync"},
 
        {HRM_CTRL_SENSOR,                "http://tizen.org/sensor/general/hrm_ctrl"},
+       {REG_CTRL_SENSOR,                "http://tizen.org/sensor/general/reg_ctrl"},
+       {GPS_CTRL_SENSOR,                "http://tizen.org/sensor/general/gps_ctrl"},
 
        {WEAR_STATUS_SENSOR,             "http://tizen.org/sensor/general/wear_status"},
        {WEAR_ON_MONITOR_SENSOR,         "http://tizen.org/sensor/general/wear_on_monitor"},
@@ -107,6 +113,17 @@ static std::map<sensor_type_t, const char *> types = {
        {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/healthinfo/hr_calorie"},
+       {SWIMMING_TRACKER_SENSOR,        "http://tizen.org/sensor/healthinfo/swimming_tracker"},
+       {SWIMMING_OUTDOOR_SENSOR,        "http://tizen.org/sensor/healthinfo/swimming_outdoor"},
+       {AUTO_SWIMMING_SENSOR,           "http://tizen.org/sensor/healthinfo/auto_swimming"},
+       {INACTIVITY_DETECTOR_SENSOR,     "http://tizen.org/sensor/general/inactivity_detector"},
+       {STRESS_TRACKER_SENSOR,          "http://tizen.org/sensor/healthinfo/stress_tracker"},
+       {FAKE_MOTION_SENSOR,             "http://tizen.org/sensor/general/fake_motion"},
+       {GEOFENCE_SENSOR,                "http://tizen.org/sensor/general/geofence"},
+       {INACTIVITY_DETECTOR_SENSOR,     "http://tizen.org/sensor/healthinfo/inactivity_detector"},
+       {HRM_BP_SENSOR,                  "http://tizen.org/sensor/healthinfo/hrm_bp"},
+       {ECG_SENSOR,                     "http://tizen.org/sensor/healthinfo/ecg"},
+       {FALL_DETECTION_SENSOR,          "http://tizen.org/sensor/general/fall_detection"},
 
        {CONTEXT_SENSOR,                 "http://tizen.org/sensor/general/context"},
        {MOTION_SENSOR,                  "http://tizen.org/sensor/general/motion"},
@@ -153,6 +170,8 @@ const char *sensor::utils::get_privilege(std::string uri)
                return PRIVILEGE_HEALTHINFO_URI;
        else if (uri.substr(start + 1, size) == PRIVILEGE_LOCATION_STR)
                return PRIVILEGE_LOCATION_URI;
+       else if (uri.substr(start + 1, size) == PRIVILEGE_PLATFORM_STR)
+               return PRIVILEGE_PLATFORM_URI;
 
        return "";
 }
index 8849181..6d11076 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "sensor_log.h"
 
-#define SOCK_TIMEOUT 3
+#define SOCK_TIMEOUT 10
 
 using namespace ipc;
 
@@ -169,8 +169,6 @@ bool socket::connect(void)
                return false;
        }
 
-       _D("Connected[%d]", m_sock_fd);
-
        return true;
 }
 
@@ -206,8 +204,6 @@ bool socket::bind(void)
                return false;
        }
 
-       _D("Bound to path[%d, %s]", m_sock_fd, m_path.c_str());
-
        return true;
 }
 
@@ -246,8 +242,6 @@ bool socket::accept(socket &client_sock)
        client_sock.set_fd(fd);
        /* TODO : socket type should be adjusted here */
 
-       _D("Accepted[%d, %d]", m_sock_fd, fd);
-
        return true;
 }
 
@@ -327,12 +321,10 @@ ssize_t socket::recv(void* buffer, size_t size, bool select) const
 bool socket::create_by_type(const std::string &path, int type)
 {
        m_sock_fd = ::create_systemd_socket(path, type);
-       if (m_sock_fd < 0) {
-               _D("Creating the UDS instead of systemd socket..");
+       if (m_sock_fd < 0)
                m_sock_fd = create_unix_socket(type);
-       } else {
+       else
                m_listening.store(true);
-       }
 
        retvm_if((m_sock_fd < 0), false, "Failed to create socket");
 
@@ -343,8 +335,6 @@ bool socket::create_by_type(const std::string &path, int type)
        /* TODO */
        /*retvm_if(!set_reuse_addr(), false, "Failed to reuse address"); */
 
-       _D("Created[%d]", m_sock_fd);
-
        m_path = path;
 
        return true;