From c9d34f004ecc08816e99259e4b0948497e3cda2e Mon Sep 17 00:00:00 2001 From: "Hongkuk, Son" Date: Sun, 18 Oct 2015 14:06:03 +0900 Subject: [PATCH] sensord: sync with SPIN tizen_2.4 Signed-off-by: Hongkuk, Son Change-Id: I6c2150a15109a0ab80c3e642828a2786f137690f --- src/accel/accel_sensor.cpp | 10 +- src/accel/accel_sensor.h | 6 +- src/accel/accel_sensor_hal.cpp | 5 +- src/accel/accel_sensor_hal.h | 19 ++- src/auto_rotation/auto_rotation_sensor.cpp | 8 +- src/auto_rotation/auto_rotation_sensor.h | 11 +- src/bio_led_red/bio_led_red_sensor.cpp | 10 +- src/bio_led_red/bio_led_red_sensor.h | 4 +- src/bio_led_red/bio_led_red_sensor_hal.cpp | 5 +- src/bio_led_red/bio_led_red_sensor_hal.h | 19 ++- src/fusion/fusion_sensor.cpp | 9 +- src/fusion/fusion_sensor.h | 8 +- src/fusion/hardware_fusion_sensor.html | 4 +- src/geo/geo_sensor.cpp | 13 +- src/geo/geo_sensor.h | 4 +- src/geo/geo_sensor_hal.cpp | 6 +- src/geo/geo_sensor_hal.h | 19 ++- src/gravity/gravity_sensor.cpp | 11 +- src/gravity/gravity_sensor.h | 12 +- src/gyro/gyro_sensor.cpp | 11 +- src/gyro/gyro_sensor.h | 4 +- src/gyro/gyro_sensor_hal.cpp | 5 +- src/gyro/gyro_sensor_hal.h | 19 ++- src/libsensord/client.cpp | 96 ++++++++++----- src/libsensord/client_common.cpp | 2 - src/libsensord/command_channel.cpp | 36 +++--- src/libsensord/command_channel.h | 7 +- src/libsensord/creg_event_info.h | 2 + src/libsensord/csensor_event_listener.cpp | 61 +++++---- src/libsensord/csensor_event_listener.h | 35 ++---- src/libsensord/csensor_handle_info.cpp | 32 +++-- src/libsensord/csensor_handle_info.h | 11 +- src/libsensord/poller.h | 4 +- src/libsensord/sensor_info_manager.cpp | 2 + src/libsensord/sensor_info_manager.h | 12 +- src/libsensord/sensor_internal.h | 7 +- src/libsensord/sensor_proxi.h | 2 +- src/light/light_sensor.cpp | 12 +- src/light/light_sensor.h | 5 +- src/light/light_sensor_hal.cpp | 5 +- src/light/light_sensor_hal.h | 19 ++- src/linear_accel/linear_accel_sensor.cpp | 13 +- src/linear_accel/linear_accel_sensor.h | 12 +- src/orientation/orientation_sensor.cpp | 11 +- src/orientation/orientation_sensor.h | 10 +- src/pressure/pressure_sensor.cpp | 10 +- src/pressure/pressure_sensor.h | 4 +- src/pressure/pressure_sensor_hal.cpp | 5 +- src/pressure/pressure_sensor_hal.h | 19 ++- src/proxi/proxi_sensor.cpp | 11 +- src/proxi/proxi_sensor.h | 4 +- src/proxi/proxi_sensor_hal.cpp | 5 +- src/proxi/proxi_sensor_hal.h | 17 ++- src/rotation_vector/gaming_rv/gaming_rv_sensor.cpp | 11 +- src/rotation_vector/gaming_rv/gaming_rv_sensor.h | 10 +- .../geomagnetic_rv/geomagnetic_rv_sensor.cpp | 11 +- .../geomagnetic_rv/geomagnetic_rv_sensor.h | 10 +- src/rotation_vector/rv/rv_sensor.cpp | 11 +- src/rotation_vector/rv/rv_sensor.h | 10 +- src/rotation_vector/rv_raw/rv_raw_sensor.cpp | 11 +- src/rotation_vector/rv_raw/rv_raw_sensor.h | 4 +- src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp | 5 +- src/rotation_vector/rv_raw/rv_raw_sensor_hal.h | 19 ++- src/server/command_worker.cpp | 137 ++++++++++++--------- src/server/command_worker.h | 11 +- src/server/main.cpp | 5 +- src/server/permission_checker.cpp | 2 +- src/shared/CMakeLists.txt | 2 + src/shared/batch_info_list.cpp | 90 ++++++++++++++ src/shared/batch_info_list.h | 45 +++++++ src/shared/cclient_info_manager.cpp | 37 +++--- src/shared/cclient_info_manager.h | 12 +- src/shared/cclient_sensor_record.cpp | 48 ++++---- src/shared/cclient_sensor_record.h | 13 +- src/shared/cconfig.cpp | 3 + src/shared/cconfig.h | 8 +- src/shared/cinterval_info_list.h | 5 +- src/shared/common.cpp | 17 +++ src/shared/csensor_config.cpp | 3 + src/shared/csensor_config.h | 24 ++-- src/shared/csensor_event_dispatcher.cpp | 3 + src/shared/csensor_event_dispatcher.h | 6 +- src/shared/csensor_event_queue.cpp | 20 +-- src/shared/csensor_event_queue.h | 37 +++--- src/shared/csensor_usage.cpp | 1 + src/shared/csensor_usage.h | 4 +- src/shared/csocket.cpp | 10 +- src/shared/csocket.h | 8 +- src/shared/cvirtual_sensor_config.h | 24 ++-- src/shared/iio_common.h | 8 +- src/shared/physical_sensor.cpp | 16 ++- src/shared/physical_sensor.h | 6 +- src/shared/sensor_base.cpp | 58 ++++++--- src/shared/sensor_base.h | 38 +++--- src/shared/sensor_hal.cpp | 8 +- src/shared/sensor_hal.h | 78 ++++++++---- src/shared/sensor_info.cpp | 5 + src/shared/sensor_info.h | 23 ++-- src/shared/sensor_plugin_loader.cpp | 81 +++++------- src/shared/sensor_plugin_loader.h | 32 ++--- src/shared/sf_common.h | 21 ++-- src/shared/virtual_sensor.h | 2 +- src/shared/worker_thread.h | 13 +- src/temperature/temperature_sensor.cpp | 11 +- src/temperature/temperature_sensor.h | 4 +- src/temperature/temperature_sensor_hal.cpp | 6 +- src/temperature/temperature_sensor_hal.h | 19 ++- src/tilt/tilt_sensor.cpp | 9 +- src/tilt/tilt_sensor.h | 11 +- src/ultraviolet/ultraviolet_sensor.cpp | 10 +- src/ultraviolet/ultraviolet_sensor.h | 4 +- src/ultraviolet/ultraviolet_sensor_hal.cpp | 5 +- src/ultraviolet/ultraviolet_sensor_hal.h | 19 ++- src/uncal_gyro/uncal_gyro_sensor.cpp | 11 +- src/uncal_gyro/uncal_gyro_sensor.h | 8 +- systemd/sensord.socket | 2 +- test/src/api-test.c | 20 +++ test/src/check-sensor.c | 2 + test/src/fusion-data-collection.c | 2 +- test/src/multi-process-performance-test.c | 3 +- test/src/sensor-test.c | 1 + 121 files changed, 1095 insertions(+), 811 deletions(-) mode change 100644 => 100755 src/fusion/hardware_fusion_sensor.html mode change 100755 => 100644 src/libsensord/client.cpp mode change 100755 => 100644 src/libsensord/command_channel.cpp mode change 100755 => 100644 src/libsensord/command_channel.h mode change 100755 => 100644 src/libsensord/creg_event_info.h mode change 100755 => 100644 src/libsensord/csensor_event_listener.cpp mode change 100755 => 100644 src/libsensord/csensor_event_listener.h mode change 100755 => 100644 src/libsensord/csensor_handle_info.cpp mode change 100755 => 100644 src/libsensord/csensor_handle_info.h mode change 100755 => 100644 src/libsensord/sensor_internal.h mode change 100755 => 100644 src/server/command_worker.cpp mode change 100755 => 100644 src/server/command_worker.h mode change 100755 => 100644 src/shared/CMakeLists.txt create mode 100644 src/shared/batch_info_list.cpp create mode 100644 src/shared/batch_info_list.h mode change 100755 => 100644 src/shared/cclient_info_manager.cpp mode change 100755 => 100644 src/shared/cclient_info_manager.h mode change 100755 => 100644 src/shared/cclient_sensor_record.cpp mode change 100755 => 100644 src/shared/cclient_sensor_record.h mode change 100755 => 100644 src/shared/common.cpp mode change 100755 => 100644 src/shared/csensor_event_queue.cpp mode change 100755 => 100644 src/shared/csensor_event_queue.h mode change 100755 => 100644 src/shared/csensor_usage.cpp mode change 100755 => 100644 src/shared/csensor_usage.h mode change 100755 => 100644 src/shared/csocket.cpp mode change 100755 => 100644 src/shared/csocket.h mode change 100755 => 100644 src/shared/physical_sensor.cpp mode change 100755 => 100644 src/shared/physical_sensor.h mode change 100755 => 100644 src/shared/sf_common.h mode change 100644 => 100755 src/uncal_gyro/uncal_gyro_sensor.cpp mode change 100644 => 100755 src/uncal_gyro/uncal_gyro_sensor.h mode change 100644 => 100755 systemd/sensord.socket mode change 100644 => 100755 test/src/api-test.c mode change 100644 => 100755 test/src/check-sensor.c mode change 100644 => 100755 test/src/fusion-data-collection.c mode change 100644 => 100755 test/src/multi-process-performance-test.c mode change 100644 => 100755 test/src/sensor-test.c diff --git a/src/accel/accel_sensor.cpp b/src/accel/accel_sensor.cpp index 1dc28ff..0db4c12 100755 --- a/src/accel/accel_sensor.cpp +++ b/src/accel/accel_sensor.cpp @@ -26,6 +26,8 @@ using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define GRAVITY 9.80665 #define G_TO_MG 1000 @@ -59,7 +61,7 @@ accel_sensor::~accel_sensor() bool accel_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(ACCELEROMETER_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ACCELEROMETER); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -81,9 +83,9 @@ bool accel_sensor::init() return true; } -sensor_type_t accel_sensor::get_type(void) +void accel_sensor::get_types(vector &types) { - return ACCELEROMETER_SENSOR; + types.push_back(ACCELEROMETER_SENSOR); } bool accel_sensor::working(void *inst) @@ -140,7 +142,7 @@ bool accel_sensor::on_stop(void) return stop_poll(); } -bool accel_sensor::get_properties(sensor_properties_s &properties) +bool accel_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/accel/accel_sensor.h b/src/accel/accel_sensor.h index fec8d69..a873538 100755 --- a/src/accel/accel_sensor.h +++ b/src/accel/accel_sensor.h @@ -31,12 +31,13 @@ public: virtual ~accel_sensor(); bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); virtual int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + private: sensor_hal *m_sensor_hal; cmutex m_value_mutex; @@ -47,7 +48,6 @@ private: virtual bool on_start(void); virtual bool on_stop(void); - void raw_to_base(sensor_data_t &data); bool process_event(void); }; diff --git a/src/accel/accel_sensor_hal.cpp b/src/accel/accel_sensor_hal.cpp index 3f4bfba..ac709a5 100755 --- a/src/accel/accel_sensor_hal.cpp +++ b/src/accel/accel_sensor_hal.cpp @@ -24,6 +24,7 @@ #include using std::ifstream; +using std::string; #define GRAVITY 9.80665 #define G_TO_MG 1000 @@ -157,9 +158,9 @@ string accel_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t accel_sensor_hal::get_type(void) +sensor_hal_type_t accel_sensor_hal::get_type(void) { - return ACCELEROMETER_SENSOR; + return SENSOR_HAL_TYPE_ACCELEROMETER; } bool accel_sensor_hal::enable(void) diff --git a/src/accel/accel_sensor_hal.h b/src/accel/accel_sensor_hal.h index 5782368..f16d94c 100755 --- a/src/accel/accel_sensor_hal.h +++ b/src/accel/accel_sensor_hal.h @@ -21,18 +21,15 @@ #define _ACCEL_SENSOR_HAL_H_ #include -#include #include -using std::string; - class accel_sensor_hal : public sensor_hal { public: accel_sensor_hal(); virtual ~accel_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -48,17 +45,17 @@ private: unsigned long m_polling_interval; unsigned long long m_fired_time; - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; int m_resolution; float m_raw_data_unit; int m_method; - string m_data_node; - string m_enable_node; - string m_interval_node; + std::string m_data_node; + std::string m_enable_node; + std::string m_interval_node; std::function update_value; diff --git a/src/auto_rotation/auto_rotation_sensor.cpp b/src/auto_rotation/auto_rotation_sensor.cpp index 9c0e367..5601fae 100755 --- a/src/auto_rotation/auto_rotation_sensor.cpp +++ b/src/auto_rotation/auto_rotation_sensor.cpp @@ -38,6 +38,8 @@ using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define SENSOR_NAME "AUTO_ROTATION_SENSOR" #define SENSOR_TYPE_AUTO_ROTATION "AUTO_ROTATION" @@ -133,9 +135,9 @@ bool auto_rotation_sensor::init() return true; } -sensor_type_t auto_rotation_sensor::get_type(void) +void auto_rotation_sensor::get_types(vector &types) { - return AUTO_ROTATION_SENSOR; + types.push_back(AUTO_ROTATION_SENSOR); } bool auto_rotation_sensor::on_start(void) @@ -208,7 +210,7 @@ int auto_rotation_sensor::get_sensor_data(const unsigned int event_type, sensor_ return 0; } -bool auto_rotation_sensor::get_properties(sensor_properties_s &properties) +bool auto_rotation_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.name = "Auto Rotation Sensor"; properties.vendor = "Samsung Electronics"; diff --git a/src/auto_rotation/auto_rotation_sensor.h b/src/auto_rotation/auto_rotation_sensor.h index 863d419..d2d1998 100755 --- a/src/auto_rotation/auto_rotation_sensor.h +++ b/src/auto_rotation/auto_rotation_sensor.h @@ -21,7 +21,6 @@ #define _AUTO_ROTATION_SENSOR_H_ #include -#include #include class auto_rotation_sensor : public virtual_sensor { @@ -30,14 +29,14 @@ public: virtual ~auto_rotation_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); - void synthesize(const sensor_event_t& event, vector &outs); + void synthesize(const sensor_event_t& event, std::vector &outs); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - virtual bool get_properties(sensor_properties_s &properties); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_base *m_accel_sensor; cmutex m_value_mutex; @@ -47,8 +46,8 @@ private: unsigned long long m_rotation_time; auto_rotation_alg *m_alg; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; auto_rotation_alg *get_alg(); diff --git a/src/bio_led_red/bio_led_red_sensor.cpp b/src/bio_led_red/bio_led_red_sensor.cpp index 17d228f..07006c7 100755 --- a/src/bio_led_red/bio_led_red_sensor.cpp +++ b/src/bio_led_red/bio_led_red_sensor.cpp @@ -26,6 +26,8 @@ using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define SENSOR_NAME "BIO_LED_RED_SENSOR" @@ -46,7 +48,7 @@ bio_led_red_sensor::~bio_led_red_sensor() bool bio_led_red_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(BIO_LED_RED_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_BIO_LED_RED); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -58,9 +60,9 @@ bool bio_led_red_sensor::init() return true; } -sensor_type_t bio_led_red_sensor::get_type(void) +void bio_led_red_sensor::get_types(vector &types) { - return BIO_LED_RED_SENSOR; + types.push_back(BIO_LED_RED_SENSOR); } bool bio_led_red_sensor::working(void *inst) @@ -110,7 +112,7 @@ bool bio_led_red_sensor::on_stop(void) return stop_poll(); } -bool bio_led_red_sensor::get_properties(sensor_properties_s &properties) +bool bio_led_red_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/bio_led_red/bio_led_red_sensor.h b/src/bio_led_red/bio_led_red_sensor.h index f14b4af..78af52a 100755 --- a/src/bio_led_red/bio_led_red_sensor.h +++ b/src/bio_led_red/bio_led_red_sensor.h @@ -31,11 +31,11 @@ public: virtual ~bio_led_red_sensor(); bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); virtual int get_sensor_data(unsigned int type, sensor_data_t &data); private: sensor_hal *m_sensor_hal; diff --git a/src/bio_led_red/bio_led_red_sensor_hal.cpp b/src/bio_led_red/bio_led_red_sensor_hal.cpp index 38ee2bb..59fea6a 100755 --- a/src/bio_led_red/bio_led_red_sensor_hal.cpp +++ b/src/bio_led_red/bio_led_red_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_BIO_LED_RED "BIO_LED_RED" #define ELEMENT_NAME "NAME" @@ -112,9 +113,9 @@ string bio_led_red_sensor_hal::get_model_id(void) } -sensor_type_t bio_led_red_sensor_hal::get_type(void) +sensor_hal_type_t bio_led_red_sensor_hal::get_type(void) { - return BIO_LED_RED_SENSOR; + return SENSOR_HAL_TYPE_BIO_LED_RED; } bool bio_led_red_sensor_hal::enable(void) diff --git a/src/bio_led_red/bio_led_red_sensor_hal.h b/src/bio_led_red/bio_led_red_sensor_hal.h index d94c470..bd9059b 100755 --- a/src/bio_led_red/bio_led_red_sensor_hal.h +++ b/src/bio_led_red/bio_led_red_sensor_hal.h @@ -21,17 +21,14 @@ #define _BIO_LED_RED_SENSOR_HAL_H_ #include -#include - -using std::string; class bio_led_red_sensor_hal : public sensor_hal { public: bio_led_red_sensor_hal(); virtual ~bio_led_red_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -40,9 +37,9 @@ public: bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; unsigned long m_polling_interval; @@ -51,9 +48,9 @@ private: unsigned long long m_fired_time; int m_node_handle; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/fusion/fusion_sensor.cpp b/src/fusion/fusion_sensor.cpp index 38e02e4..bb04436 100755 --- a/src/fusion/fusion_sensor.cpp +++ b/src/fusion/fusion_sensor.cpp @@ -33,6 +33,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "FUSION_SENSOR" #define SENSOR_TYPE_FUSION "FUSION" @@ -212,9 +215,9 @@ bool fusion_sensor::init(void) return true; } -sensor_type_t fusion_sensor::get_type(void) +void fusion_sensor::get_types(vector &types) { - return FUSION_SENSOR; + types.push_back(FUSION_SENSOR); } bool fusion_sensor::on_start(void) @@ -458,7 +461,7 @@ int fusion_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t return 0; } -bool fusion_sensor::get_properties(sensor_properties_s &properties) +bool fusion_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.min_range = 0; properties.max_range = 0; diff --git a/src/fusion/fusion_sensor.h b/src/fusion/fusion_sensor.h index 8b4013f..e057ff0 100755 --- a/src/fusion/fusion_sensor.h +++ b/src/fusion/fusion_sensor.h @@ -35,8 +35,8 @@ public: bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int data_id, sensor_data_t &data); @@ -63,8 +63,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; float m_accel_static_bias[3]; float m_gyro_static_bias[3]; diff --git a/src/fusion/hardware_fusion_sensor.html b/src/fusion/hardware_fusion_sensor.html old mode 100644 new mode 100755 index aae6fea..2c81202 --- a/src/fusion/hardware_fusion_sensor.html +++ b/src/fusion/hardware_fusion_sensor.html @@ -91,7 +91,7 @@ software sensor fusion,

->In the constructor use sensor_plugin_loader to check if the hal sensor fusion is present or not:

-

sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR)

+

sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION)


->If @@ -103,7 +103,7 @@ this result in virtual_sensor::m_hardware_fusion

sensor_hal *fusion_sensor_hal = -sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR);

+sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);

if (!fusion_sensor_hal)

  m_hardware_fusion diff --git a/src/geo/geo_sensor.cpp b/src/geo/geo_sensor.cpp index 02609ca..6d9c170 100755 --- a/src/geo/geo_sensor.cpp +++ b/src/geo/geo_sensor.cpp @@ -23,6 +23,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "GEOMAGNETIC_SENSOR" geo_sensor::geo_sensor() @@ -45,7 +48,7 @@ geo_sensor::~geo_sensor() bool geo_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(GEOMAGNETIC_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GEOMAGNETIC); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -66,15 +69,15 @@ bool geo_sensor::init() return true; } -sensor_type_t geo_sensor::get_type(void) +void geo_sensor::get_types(vector &types) { - return GEOMAGNETIC_SENSOR; + types.push_back(GEOMAGNETIC_SENSOR); } bool geo_sensor::working(void *inst) { geo_sensor *sensor = (geo_sensor*)inst; - return sensor->process_event();; + return sensor->process_event(); } bool geo_sensor::process_event(void) @@ -125,7 +128,7 @@ bool geo_sensor::on_stop(void) return stop_poll(); } -bool geo_sensor::get_properties(sensor_properties_s &properties) +bool geo_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/geo/geo_sensor.h b/src/geo/geo_sensor.h index d864ec1..df1e2c3 100755 --- a/src/geo/geo_sensor.h +++ b/src/geo/geo_sensor.h @@ -31,13 +31,13 @@ public: virtual ~geo_sensor(); virtual bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; diff --git a/src/geo/geo_sensor_hal.cpp b/src/geo/geo_sensor_hal.cpp index 0480752..9b23ea5 100755 --- a/src/geo/geo_sensor_hal.cpp +++ b/src/geo/geo_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_MAGNETIC "MAGNETIC" #define ELEMENT_NAME "NAME" @@ -147,9 +148,9 @@ string geo_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t geo_sensor_hal::get_type(void) +sensor_hal_type_t geo_sensor_hal::get_type(void) { - return GEOMAGNETIC_SENSOR; + return SENSOR_HAL_TYPE_GEOMAGNETIC; } bool geo_sensor_hal::enable(void) @@ -190,7 +191,6 @@ bool geo_sensor_hal::set_interval(unsigned long val) INFO("Interval is changed from %dms to %dms]", m_polling_interval, val); m_polling_interval = val; return true; - } bool geo_sensor_hal::update_value(bool wait) diff --git a/src/geo/geo_sensor_hal.h b/src/geo/geo_sensor_hal.h index 44afebb..0af57e8 100755 --- a/src/geo/geo_sensor_hal.h +++ b/src/geo/geo_sensor_hal.h @@ -21,17 +21,14 @@ #define _GEO_SENSOR_HAL_H_ #include -#include - -using std::string; class geo_sensor_hal : public sensor_hal { public: geo_sensor_hal(); virtual ~geo_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -39,9 +36,9 @@ public: virtual int get_sensor_data(sensor_data_t &data); bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; float m_min_range; float m_max_range; @@ -57,9 +54,9 @@ private: int m_node_handle; unsigned long m_polling_interval; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/gravity/gravity_sensor.cpp b/src/gravity/gravity_sensor.cpp index aa23a5e..dfe3ae7 100755 --- a/src/gravity/gravity_sensor.cpp +++ b/src/gravity/gravity_sensor.cpp @@ -31,6 +31,9 @@ #include #include +using std::string; +using std::vector; + #define INITIAL_VALUE -1 #define GRAVITY 9.80665 @@ -66,7 +69,7 @@ gravity_sensor::gravity_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -157,9 +160,9 @@ bool gravity_sensor::init() return true; } -sensor_type_t gravity_sensor::get_type(void) +void gravity_sensor::get_types(vector &types) { - return GRAVITY_SENSOR; + types.push_back(GRAVITY_SENSOR); } bool gravity_sensor::on_start(void) @@ -374,7 +377,7 @@ int gravity_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t return 0; } -bool gravity_sensor::get_properties(sensor_properties_s &properties) +bool gravity_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.min_range = -GRAVITY; properties.max_range = GRAVITY; diff --git a/src/gravity/gravity_sensor.h b/src/gravity/gravity_sensor.h index cd15b79..b5114ee 100755 --- a/src/gravity/gravity_sensor.h +++ b/src/gravity/gravity_sensor.h @@ -30,15 +30,15 @@ public: virtual ~gravity_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t& event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - bool get_properties(sensor_properties_s &properties); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_base *m_accel_sensor; sensor_base *m_gyro_sensor; @@ -55,9 +55,9 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; - string m_orientation_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; + std::string m_orientation_data_unit; int m_default_sampling_time; int m_gravity_sign_compensation[3]; int m_azimuth_rotation_compensation; diff --git a/src/gyro/gyro_sensor.cpp b/src/gyro/gyro_sensor.cpp index c7b0001..2cb2859 100755 --- a/src/gyro/gyro_sensor.cpp +++ b/src/gyro/gyro_sensor.cpp @@ -23,6 +23,9 @@ #include #include +using std::string; +using std::vector; + #define MS_TO_US 1000 #define DPS_TO_MDPS 1000 #define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS)) @@ -48,7 +51,7 @@ gyro_sensor::~gyro_sensor() bool gyro_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(GYROSCOPE_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_GYROSCOPE); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -69,9 +72,9 @@ bool gyro_sensor::init() return true; } -sensor_type_t gyro_sensor::get_type(void) +void gyro_sensor::get_types(vector &types) { - return GYROSCOPE_SENSOR; + types.push_back(GYROSCOPE_SENSOR); } bool gyro_sensor::working(void *inst) @@ -127,7 +130,7 @@ bool gyro_sensor::on_stop(void) return stop_poll(); } -bool gyro_sensor::get_properties(sensor_properties_s &properties) +bool gyro_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/gyro/gyro_sensor.h b/src/gyro/gyro_sensor.h index a56ca2f..81bcb7b 100755 --- a/src/gyro/gyro_sensor.h +++ b/src/gyro/gyro_sensor.h @@ -31,13 +31,13 @@ public: virtual ~gyro_sensor(); virtual bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; float m_resolution; diff --git a/src/gyro/gyro_sensor_hal.cpp b/src/gyro/gyro_sensor_hal.cpp index 52b55fb..97a6903 100755 --- a/src/gyro/gyro_sensor_hal.cpp +++ b/src/gyro/gyro_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define DPS_TO_MDPS 1000 #define MIN_RANGE(RES) (-((1 << (RES))/2)) @@ -137,9 +138,9 @@ string gyro_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t gyro_sensor_hal::get_type(void) +sensor_hal_type_t gyro_sensor_hal::get_type(void) { - return GYROSCOPE_SENSOR; + return SENSOR_HAL_TYPE_GYROSCOPE; } bool gyro_sensor_hal::enable(void) diff --git a/src/gyro/gyro_sensor_hal.h b/src/gyro/gyro_sensor_hal.h index 6204399..dde408e 100755 --- a/src/gyro/gyro_sensor_hal.h +++ b/src/gyro/gyro_sensor_hal.h @@ -21,17 +21,14 @@ #define _GYRO_SENSOR_HAL_H_ #include -#include - -using std::string; class gyro_sensor_hal : public sensor_hal { public: gyro_sensor_hal(); virtual ~gyro_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long ms_interval); @@ -47,18 +44,18 @@ private: unsigned long m_polling_interval; unsigned long long m_fired_time; - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; float m_min_range; float m_max_range; int m_resolution; float m_raw_data_unit; - string m_data_node; - string m_enable_node; - string m_interval_node; + std::string m_data_node; + std::string m_enable_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/libsensord/client.cpp b/src/libsensord/client.cpp old mode 100755 new mode 100644 index 710bdcf..943e5a9 --- a/src/libsensord/client.cpp +++ b/src/libsensord/client.cpp @@ -27,11 +27,17 @@ #include #include #include +#include +#include + +using std::vector; #ifndef API #define API __attribute__((visibility("default"))) #endif +#define MIN_INTERVAL 10 + static const int OP_SUCCESS = 0; static const int OP_ERROR = -1; @@ -260,16 +266,9 @@ static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, senso } } - if (prev_rep.interval != cur_rep.interval) { - unsigned int min_interval; - - if (cur_rep.interval == 0) - min_interval= POLL_MAX_HZ_MS; - else - min_interval = cur_rep.interval; - - if (!cmd_channel->cmd_set_interval(min_interval)) { - ERR("Sending cmd_set_interval(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), min_interval, get_client_name()); + if ( (prev_rep.interval != cur_rep.interval) || (prev_rep.latency != cur_rep.latency)) { + if (!cmd_channel->cmd_set_batch(cur_rep.interval, cur_rep.latency)) { + ERR("Sending cmd_set_batch(%d, %s, %d, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.interval, cur_rep.latency, get_client_name()); return false; } } @@ -297,7 +296,7 @@ static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, senso return false; } } else { - if (!cmd_channel->cmd_unset_interval()) { + if (!cmd_channel->cmd_unset_batch()) { ERR("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name()); return false; } @@ -616,14 +615,14 @@ API int sensord_connect(sensor_t sensor) retvm_if (!sensor_info_manager::get_instance().is_valid(info), OP_ERROR, "Invalid param: sensor (%p)", sensor); - sensor_id_t sensor_id = info->get_id(); + sensor_id_t sensor_id = info->get_id(); AUTOLOCK(lock); sensor_registered = event_listener.is_sensor_registered(sensor_id); handle = event_listener.create_handle(sensor_id); - if (handle == MAX_HANDLE) { + if (handle == MAX_HANDLE_REACHED) { ERR("Maximum number of handles reached, sensor: %s in client %s", get_sensor_name(sensor_id), get_client_name()); return OP_ERROR; } @@ -758,14 +757,15 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int return false; } - if (interval == 0) - interval = 1; + if (interval < MIN_INTERVAL) + interval = MIN_INTERVAL; - INFO("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, cb: 0x%x, user_data: 0x%x", get_client_name(), get_event_name(event_type), - event_type, get_sensor_name(sensor_id), handle, interval, cb, user_data); + INFO("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, latency: %d, cb: 0x%x, user_data: 0x%x", + get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), + handle, interval, max_batch_latency, cb, user_data); event_listener.get_sensor_rep(sensor_id, prev_rep); - event_listener.register_event(handle, event_type, interval, cb_type, cb, user_data); + event_listener.register_event(handle, event_type, interval, max_batch_latency, cb_type, cb, user_data); event_listener.get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); @@ -791,7 +791,7 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; bool ret; - unsigned int prev_interval; + unsigned int prev_interval, prev_latency; int prev_cb_type; void *prev_cb; void *prev_user_data; @@ -807,7 +807,7 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) event_type, get_sensor_name(sensor_id), handle); event_listener.get_sensor_rep(sensor_id, prev_rep); - event_listener.get_event_info(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data); + event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); if (!event_listener.unregister_event(handle, event_type)) { ERR("%s try to unregister non registered event %s[0x%x] for sensor %s[%d]", @@ -819,7 +819,7 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - event_listener.register_event(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data); + event_listener.register_event(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); return ret; @@ -945,12 +945,12 @@ API bool sensord_stop(int handle) } -API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval) +static bool change_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency) { sensor_id_t sensor_id; sensor_rep prev_rep, cur_rep; bool ret; - unsigned int prev_interval; + unsigned int prev_interval, prev_latency; int prev_cb_type; void *prev_cb; void *prev_user_data; @@ -962,14 +962,20 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi return false; } - INFO("%s changes interval of event %s[0x%x] for %s[%d] to interval %d", get_client_name(), get_event_name(event_type), - event_type, get_sensor_name(sensor_id), handle, interval); + if (interval == 0) + interval = 1; + + INFO("%s changes batch of event %s[0x%x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type), + event_type, get_sensor_name(sensor_id), handle, interval, latency); event_listener.get_sensor_rep(sensor_id, prev_rep); - event_listener.get_event_info(handle, event_type, prev_interval, prev_cb_type, prev_cb, prev_user_data); + event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); + + if (interval < MIN_INTERVAL) + interval = MIN_INTERVAL; - if (!event_listener.set_event_interval(handle, event_type, interval)) + if (!event_listener.set_event_batch(handle, event_type, interval, latency)) return false; event_listener.get_sensor_rep(sensor_id, cur_rep); @@ -977,17 +983,45 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); if (!ret) - event_listener.set_event_interval(handle, event_type, prev_interval); + event_listener.set_event_batch(handle, event_type, prev_interval, prev_latency); return ret; - } -API bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency) +API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval) { - return false; + unsigned int prev_interval, prev_latency; + int prev_cb_type; + void *prev_cb; + void *prev_user_data; + + AUTOLOCK(lock); + + if (!event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { + ERR("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type); + return false; + } + + INFO("handle = %d, event_type = 0x%x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency); + return change_event_batch(handle, event_type, interval, prev_latency); } +API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency) +{ + unsigned int prev_interval, prev_latency; + int prev_cb_type; + void *prev_cb; + void *prev_user_data; + + AUTOLOCK(lock); + + if (!event_listener.get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { + ERR("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type); + return false; + } + + return change_event_batch(handle, event_type, prev_interval, max_batch_latency); +} API bool sensord_set_option(int handle, int option) { diff --git a/src/libsensord/client_common.cpp b/src/libsensord/client_common.cpp index 40f99b1..9efccee 100755 --- a/src/libsensord/client_common.cpp +++ b/src/libsensord/client_common.cpp @@ -123,8 +123,6 @@ const char* get_log_element_name(log_id id, unsigned int type) const char* get_sensor_name(sensor_id_t sensor_id) { - const int SENSOR_TYPE_MASK = 0x0000FFFF; - sensor_type_t sensor_type = (sensor_type_t) (sensor_id & SENSOR_TYPE_MASK); return get_log_element_name(LOG_ID_SENSOR_TYPE, sensor_type); diff --git a/src/libsensord/command_channel.cpp b/src/libsensord/command_channel.cpp old mode 100755 new mode 100644 index 21238a2..c46a1a1 --- a/src/libsensord/command_channel.cpp +++ b/src/libsensord/command_channel.cpp @@ -108,7 +108,8 @@ bool command_channel::cmd_get_id(int &client_id) packet->set_cmd(CMD_GET_ID); cmd_get_id = (cmd_get_id_t *)packet->data(); - cmd_get_id->pid = getpid(); + + get_proc_name(getpid(), cmd_get_id->name); INFO("%s send cmd_get_id()", get_client_name()); @@ -480,33 +481,34 @@ bool command_channel::cmd_unregister_events(event_type_vector &event_vec) return true; } -bool command_channel::cmd_set_interval(unsigned int interval) +bool command_channel::cmd_set_batch(unsigned int interval, unsigned int latency) { cpacket *packet; - cmd_set_interval_t *cmd_set_interval; + cmd_set_batch_t *cmd_set_batch; cmd_done_t *cmd_done; - packet = new(std::nothrow) cpacket(sizeof(cmd_set_interval_t)); + packet = new(std::nothrow) cpacket(sizeof(cmd_set_batch_t)); retvm_if(!packet, false, "Failed to allocate memory"); - packet->set_cmd(CMD_SET_INTERVAL); + packet->set_cmd(CMD_SET_BATCH); - cmd_set_interval = (cmd_set_interval_t*)packet->data(); - cmd_set_interval->interval = interval; + cmd_set_batch = (cmd_set_batch_t*)packet->data(); + cmd_set_batch->interval = interval; + cmd_set_batch->latency = latency; - INFO("%s send cmd_set_interval(client_id=%d, %s, interval=%d)", - get_client_name(), m_client_id, get_sensor_name(m_sensor_id), interval); + INFO("%s send cmd_set_batch(client_id=%d, %s, interval=%d, latency = %d)", + get_client_name(), m_client_id, get_sensor_name(m_sensor_id), interval, latency); if (!command_handler(packet, (void **)&cmd_done)) { - ERR("%s failed to send/receive command for sensor[%s] with client_id [%d], interval[%d]", - get_client_name(), get_sensor_name(m_sensor_id), m_client_id, interval); + ERR("%s failed to send/receive command for sensor[%s] with client_id [%d], interval[%d], latency[%d]", + get_client_name(), get_sensor_name(m_sensor_id), m_client_id, interval, latency); delete packet; return false; } if (cmd_done->value < 0) { - ERR("%s got error[%d] from server for sensor[%s] with client_id [%d], interval[%d]", - get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, interval); + ERR("%s got error[%d] from server for sensor[%s] with client_id [%d], interval[%d], latency[%d]", + get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, interval, latency); delete[] (char *)cmd_done; delete packet; @@ -519,17 +521,17 @@ bool command_channel::cmd_set_interval(unsigned int interval) return true; } -bool command_channel::cmd_unset_interval(void) +bool command_channel::cmd_unset_batch(void) { cpacket *packet; cmd_done_t *cmd_done; - packet = new(std::nothrow) cpacket(sizeof(cmd_unset_interval_t)); + packet = new(std::nothrow) cpacket(sizeof(cmd_unset_batch_t)); retvm_if(!packet, false, "Failed to allocate memory"); - packet->set_cmd(CMD_UNSET_INTERVAL); + packet->set_cmd(CMD_UNSET_BATCH); - INFO("%s send cmd_unset_interval(client_id=%d, %s)", + INFO("%s send cmd_unset_batch(client_id=%d, %s)", get_client_name(), m_client_id, get_sensor_name(m_sensor_id)); if (!command_handler(packet, (void **)&cmd_done)) { diff --git a/src/libsensord/command_channel.h b/src/libsensord/command_channel.h old mode 100755 new mode 100644 index 2688c15..ae1ba6a --- a/src/libsensord/command_channel.h +++ b/src/libsensord/command_channel.h @@ -23,9 +23,6 @@ #include #include #include -#include - -using std::vector; class command_channel { @@ -48,8 +45,8 @@ public: bool cmd_register_events(event_type_vector &event_vec); bool cmd_unregister_event(unsigned int event_type); bool cmd_unregister_events(event_type_vector &event_vec); - bool cmd_set_interval(unsigned int interval); - bool cmd_unset_interval(void); + bool cmd_set_batch(unsigned int interval, unsigned int latency); + bool cmd_unset_batch(void); bool cmd_set_command(unsigned int cmd, long value); bool cmd_get_data(unsigned int type, sensor_data_t* values); bool cmd_send_sensorhub_data(const char* buffer, int data_len); diff --git a/src/libsensord/creg_event_info.h b/src/libsensord/creg_event_info.h old mode 100755 new mode 100644 index 82f23bd..a270d79 --- a/src/libsensord/creg_event_info.h +++ b/src/libsensord/creg_event_info.h @@ -35,6 +35,7 @@ public: int m_handle; unsigned int type; unsigned int m_interval; + unsigned int m_latency; int m_cb_type; void *m_cb; void *m_user_data; @@ -43,6 +44,7 @@ public: creg_event_info():m_id(0), m_handle(-1), type(0), m_interval(POLL_1HZ_MS), + m_latency(0), m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL), m_previous_event_time(0), m_fired(false){} diff --git a/src/libsensord/csensor_event_listener.cpp b/src/libsensord/csensor_event_listener.cpp old mode 100755 new mode 100644 index 7dbebc3..dea77e0 --- a/src/libsensord/csensor_event_listener.cpp +++ b/src/libsensord/csensor_event_listener.cpp @@ -24,12 +24,14 @@ #include #include +#include #define MS_TO_US 1000 #define MIN_DELIVERY_DIFF_FACTOR 0.75f using std::thread; using std::pair; +using std::vector; csensor_event_listener::csensor_event_listener() : m_client_id(CLIENT_ID_INVALID) @@ -114,7 +116,7 @@ bool csensor_event_listener::stop_handle(int handle) } bool csensor_event_listener::register_event(int handle, unsigned int event_type, - unsigned int interval, int cb_type, void *cb, void* user_data) + unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data) { AUTOLOCK(m_handle_info_lock); @@ -125,7 +127,7 @@ bool csensor_event_listener::register_event(int handle, unsigned int event_type, return false; } - if (!it_handle->second.add_reg_event_info(event_type, interval, cb_type, cb, user_data)) + if (!it_handle->second.add_reg_event_info(event_type, interval, latency, cb_type, cb, user_data)) return false; return true; @@ -148,24 +150,6 @@ bool csensor_event_listener::unregister_event(int handle, unsigned int event_typ return true; } -bool csensor_event_listener::change_event_interval(int handle, unsigned int event_type, - unsigned int interval) -{ - AUTOLOCK(m_handle_info_lock); - - auto it_handle = m_sensor_handle_infos.find(handle); - - if (it_handle == m_sensor_handle_infos.end()) { - ERR("Handle[%d] is not found for client %s", handle, get_client_name()); - return false; - } - - if (!it_handle->second.change_reg_event_interval(event_type, interval)) - return false; - - return true; -} - bool csensor_event_listener::register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data) { AUTOLOCK(m_handle_info_lock); @@ -268,7 +252,7 @@ bool csensor_event_listener::set_sensor_option(int handle, int sensor_option) return true; } -bool csensor_event_listener::set_event_interval(int handle, unsigned int event_type, unsigned int interval) +bool csensor_event_listener::set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency) { AUTOLOCK(m_handle_info_lock); @@ -279,14 +263,14 @@ bool csensor_event_listener::set_event_interval(int handle, unsigned int event_t return false; } - if (!it_handle->second.change_reg_event_interval(event_type, interval)) + if (!it_handle->second.change_reg_event_batch(event_type, interval, latency)) return false; return true; } -bool csensor_event_listener::get_event_info(int handle, unsigned int event_type, unsigned int &interval, int &cb_type, void* &cb, void* &user_data) +bool csensor_event_listener::get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data) { AUTOLOCK(m_handle_info_lock); @@ -304,8 +288,8 @@ bool csensor_event_listener::get_event_info(int handle, unsigned int event_type, if (!event_info) return NULL; - interval = event_info->m_interval; + latency = event_info->m_latency; cb_type = event_info->m_cb_type; cb = event_info->m_cb; user_data = event_info->m_user_data; @@ -332,13 +316,18 @@ void csensor_event_listener::get_listening_sensors(sensor_id_vector &sensors) void csensor_event_listener::get_sensor_rep(sensor_id_t sensor, sensor_rep& rep) { + const unsigned int INVALID_BATCH_VALUE = std::numeric_limits::max(); + AUTOLOCK(m_handle_info_lock); rep.active = is_sensor_active(sensor); rep.option = get_active_option(sensor); - rep.interval = get_active_min_interval(sensor); - get_active_event_types(sensor, rep.event_types); + if (!get_active_batch(sensor, rep.interval, rep.latency)) { + rep.interval = INVALID_BATCH_VALUE; + rep.latency = INVALID_BATCH_VALUE; + } + get_active_event_types(sensor, rep.event_types); } void csensor_event_listener::operate_sensor(sensor_id_t sensor, int power_save_state) @@ -443,11 +432,14 @@ void csensor_event_listener::set_client_id(int client_id) m_client_id = client_id; } -unsigned int csensor_event_listener::get_active_min_interval(sensor_id_t sensor) +bool csensor_event_listener::get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency) { unsigned int min_interval = POLL_MAX_HZ_MS; + unsigned int min_latency = std::numeric_limits::max(); + bool active_sensor_found = false; - unsigned int interval; + unsigned int _interval; + unsigned int _latency; AUTOLOCK(m_handle_info_lock); @@ -457,18 +449,23 @@ unsigned int csensor_event_listener::get_active_min_interval(sensor_id_t sensor) if ((it_handle->second.m_sensor_id == sensor) && (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED)) { active_sensor_found = true; - interval = it_handle->second.get_min_interval(); - min_interval = (interval < min_interval) ? interval : min_interval; + it_handle->second.get_batch(_interval, _latency); + min_interval = (_interval < min_interval) ? _interval : min_interval; + min_latency = (_latency < min_latency) ? _latency : min_latency; } ++it_handle; } - if (!active_sensor_found) + if (!active_sensor_found) { DBG("Active sensor[0x%x] is not found for client %s", sensor, get_client_name()); + return false; + } - return (active_sensor_found) ? min_interval : 0; + interval = min_interval; + latency = min_latency; + return true; } unsigned int csensor_event_listener::get_active_option(sensor_id_t sensor) diff --git a/src/libsensord/csensor_event_listener.h b/src/libsensord/csensor_event_listener.h old mode 100755 new mode 100644 index 0f7ac49..2986273 --- a/src/libsensord/csensor_event_listener.h +++ b/src/libsensord/csensor_event_listener.h @@ -38,19 +38,10 @@ #include #include -using std::unordered_map; -using std::vector; -using std::string; -using std::queue; -using std::mutex; -using std::lock_guard; -using std::unique_lock; -using std::condition_variable; - -typedef vector handle_vector; -typedef vector sensor_id_vector; -typedef unordered_map sensor_handle_info_map; -typedef unordered_map sensor_command_channel_map; +typedef std::vector handle_vector; +typedef std::vector sensor_id_vector; +typedef std::unordered_map sensor_handle_info_map; +typedef std::unordered_map sensor_command_channel_map; typedef struct { unsigned long long event_id; @@ -72,6 +63,7 @@ typedef struct sensor_rep bool active; int option; unsigned int interval; + unsigned int latency; event_type_vector event_types; } sensor_rep; @@ -84,9 +76,8 @@ public: bool delete_handle(int handle); bool start_handle(int handle); bool stop_handle(int handle); - bool register_event(int handle, unsigned int event_type, unsigned int interval, int cb_type, void *cb, void* user_data); + bool register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb, void* user_data); bool unregister_event(int handle, unsigned int event_type); - bool change_event_interval(int handle, unsigned int event_type, unsigned int interval); bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data); bool unregister_accuracy_cb(int handle); @@ -95,12 +86,12 @@ public: bool get_sensor_params(int handle, int &sensor_state, int &sensor_option); bool set_sensor_state(int handle, int sensor_state); bool set_sensor_option(int handle, int sensor_option); - bool set_event_interval(int handle, unsigned int event_type, unsigned int interval); - bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, int &cb_type, void* &cb, void* &user_data); + bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); + bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, int &cb_type, void* &cb, void* &user_data); void operate_sensor(sensor_id_t sensor, int power_save_state); void get_listening_sensors(sensor_id_vector &sensors); - unsigned int get_active_min_interval(sensor_id_t sensor_id); + bool get_active_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency); unsigned int get_active_option(sensor_id_t sensor_id); void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types); @@ -135,8 +126,8 @@ private: THREAD_STATE_STOP, THREAD_STATE_TERMINATE, }; - typedef lock_guard lock; - typedef unique_lock ulock; + typedef std::lock_guard lock; + typedef std::unique_lock ulock; sensor_handle_info_map m_sensor_handle_infos; sensor_command_channel_map m_command_channels; @@ -149,8 +140,8 @@ private: cmutex m_handle_info_lock; thread_state m_thread_state; - mutex m_thread_mutex; - condition_variable m_thread_cond; + std::mutex m_thread_mutex; + std::condition_variable m_thread_cond; hup_observer_t m_hup_observer; diff --git a/src/libsensord/csensor_handle_info.cpp b/src/libsensord/csensor_handle_info.cpp old mode 100755 new mode 100644 index d1c8dbb..3aa173f --- a/src/libsensord/csensor_handle_info.cpp +++ b/src/libsensord/csensor_handle_info.cpp @@ -19,6 +19,7 @@ #include #include +#include using std::pair; @@ -64,7 +65,7 @@ void csensor_handle_info::get_reg_event_types(event_type_vector &event_types) } } -bool csensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, int cb_type, void *cb, void *user_data) +bool csensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb, void *user_data) { creg_event_info event_info; @@ -79,6 +80,7 @@ bool csensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned i event_info.m_handle = m_handle; event_info.type = event_type; event_info.m_interval = interval; + event_info.m_latency = latency; event_info.m_cb_type = cb_type; event_info.m_cb = cb; event_info.m_user_data = user_data; @@ -113,7 +115,7 @@ unsigned long long csensor_handle_info::renew_event_id(void) return m_event_id++; } -bool csensor_handle_info::change_reg_event_interval(unsigned int event_type, unsigned int interval) +bool csensor_handle_info::change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency) { auto it_event = m_reg_event_infos.find(event_type); @@ -124,29 +126,39 @@ bool csensor_handle_info::change_reg_event_interval(unsigned int event_type, uns it_event->second.m_id = renew_event_id(); it_event->second.m_interval = interval; + it_event->second.m_latency = latency; return true; } -unsigned int csensor_handle_info::get_min_interval(void) +void csensor_handle_info::get_batch(unsigned int &interval, unsigned int &latency) { - unsigned int min_interval = POLL_MAX_HZ_MS; - unsigned int interval; - if (m_reg_event_infos.empty()) { DBG("No events are registered for client %s", get_client_name()); - return min_interval; + interval = POLL_MAX_HZ_MS; + latency = 0; + return; } + unsigned int min_interval = POLL_MAX_HZ_MS; + unsigned int min_latency = std::numeric_limits::max(); + + unsigned int _interval; + unsigned int _latency; + auto it_event = m_reg_event_infos.begin(); while (it_event != m_reg_event_infos.end()) { - interval = it_event->second.m_interval; - min_interval = (interval < min_interval) ? interval : min_interval; + _interval = it_event->second.m_interval; + _latency = it_event->second.m_latency; + + min_interval = (_interval < min_interval) ? _interval : min_interval; + min_latency = (_latency < min_latency) ? _latency : min_latency; ++it_event; } - return min_interval; + interval = min_interval; + latency = min_latency; } unsigned int csensor_handle_info::get_reg_event_count(void) diff --git a/src/libsensord/csensor_handle_info.h b/src/libsensord/csensor_handle_info.h old mode 100755 new mode 100644 index b6eca9b..3330dbe --- a/src/libsensord/csensor_handle_info.h +++ b/src/libsensord/csensor_handle_info.h @@ -25,11 +25,8 @@ #include #include #include -#include -using std::unordered_map; -using std::vector; -typedef unordered_map event_info_map; +typedef std::unordered_map event_info_map; class csensor_handle_info { public: @@ -45,14 +42,14 @@ public: csensor_handle_info(); ~csensor_handle_info(); - bool add_reg_event_info(unsigned int event_type, unsigned int interval, int cb_type, void *cb,void *user_data); + bool add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, int cb_type, void *cb,void *user_data); bool delete_reg_event_info(unsigned int event_type); - bool change_reg_event_interval(unsigned int event_type, unsigned int interval); + bool change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency); creg_event_info* get_reg_event_info(const unsigned int event_type); void get_reg_event_types(event_type_vector &event_types); - unsigned int get_min_interval(void); + void get_batch(unsigned int &interval, unsigned int &latency); unsigned int get_reg_event_count(void); void clear_all_events(void); diff --git a/src/libsensord/poller.h b/src/libsensord/poller.h index 5650518..eaf7d93 100755 --- a/src/libsensord/poller.h +++ b/src/libsensord/poller.h @@ -29,8 +29,6 @@ #include #include -using std::queue; - class poller { public: poller(int fd); @@ -39,7 +37,7 @@ public: bool poll(int &event); private: int m_epfd; - queue m_event_queue; + std::queue m_event_queue; bool create(int fd); bool fill_event_queue(void); diff --git a/src/libsensord/sensor_info_manager.cpp b/src/libsensord/sensor_info_manager.cpp index f4c6fe1..4a427f2 100755 --- a/src/libsensord/sensor_info_manager.cpp +++ b/src/libsensord/sensor_info_manager.cpp @@ -19,9 +19,11 @@ #include #include +#include using std::pair; using std::make_pair; +using std::vector; sensor_info_manager::sensor_info_manager() { diff --git a/src/libsensord/sensor_info_manager.h b/src/libsensord/sensor_info_manager.h index 512905f..084b5a3 100755 --- a/src/libsensord/sensor_info_manager.h +++ b/src/libsensord/sensor_info_manager.h @@ -26,23 +26,19 @@ #include #include -using std::multimap; -using std::unordered_map; -using std::unordered_set; - class sensor_info_manager { public: static sensor_info_manager& get_instance(void); const sensor_info* get_info(sensor_type_t type); - vector get_infos(sensor_type_t type); + std::vector get_infos(sensor_type_t type); const sensor_info* get_info(sensor_id_t id); bool is_valid(sensor_info* info); void add_info(sensor_info* info); private: - typedef multimap sensor_infos; - typedef unordered_map id_to_info_map; - typedef unordered_set info_set; + typedef std::multimap sensor_infos; + typedef std::unordered_map id_to_info_map; + typedef std::unordered_set info_set; sensor_info_manager(); ~sensor_info_manager(); diff --git a/src/libsensord/sensor_internal.h b/src/libsensord/sensor_internal.h old mode 100755 new mode 100644 index 49c74dc..ff107cb --- a/src/libsensord/sensor_internal.h +++ b/src/libsensord/sensor_internal.h @@ -24,6 +24,10 @@ #define DEPRECATED __attribute__((deprecated)) #endif +#ifndef API +#define API __attribute__((visibility("default"))) +#endif + #include "stdbool.h" #ifdef __cplusplus @@ -298,10 +302,11 @@ bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned * @brief Change the max batch latency of a specifed event type in a connected sensor. * * @param[in] handle a handle represensting a connected sensor. + * @param[in] event_type an event type to change max batch latency * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled. * @return true on success, otherwise false. */ -bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency); +bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency); /** * @brief Change the option of a connected sensor. diff --git a/src/libsensord/sensor_proxi.h b/src/libsensord/sensor_proxi.h index 22939d9..1c99fa4 100755 --- a/src/libsensord/sensor_proxi.h +++ b/src/libsensord/sensor_proxi.h @@ -40,7 +40,7 @@ enum proxi_event_type { }; enum proxi_change_state { - PROXIMITY_STATE_FAR = 0, + PROXIMITY_STATE_FAR = 0, PROXIMITY_STATE_NEAR = 1, }; diff --git a/src/light/light_sensor.cpp b/src/light/light_sensor.cpp index 73e45cc..e0a61f1 100755 --- a/src/light/light_sensor.cpp +++ b/src/light/light_sensor.cpp @@ -22,9 +22,12 @@ #include #include #include +#include using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define SENSOR_NAME "LIGHT_SENSOR" @@ -56,7 +59,7 @@ light_sensor::~light_sensor() bool light_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(LIGHT_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_LIGHT); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -64,12 +67,13 @@ bool light_sensor::init() } INFO("%s is created!", sensor_base::get_name()); + return true; } -sensor_type_t light_sensor::get_type(void) +void light_sensor::get_types(vector &types) { - return LIGHT_SENSOR; + types.push_back(LIGHT_SENSOR); } bool light_sensor::working(void *inst) @@ -148,7 +152,7 @@ bool light_sensor::on_stop(void) return stop_poll(); } -bool light_sensor::get_properties(sensor_properties_s &properties) +bool light_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { m_sensor_hal->get_properties(properties); return true; diff --git a/src/light/light_sensor.h b/src/light/light_sensor.h index cdc8e50..1b6d0ca 100755 --- a/src/light/light_sensor.h +++ b/src/light/light_sensor.h @@ -30,14 +30,13 @@ public: virtual ~light_sensor(); virtual bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(const unsigned int type, sensor_data_t &data); - + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: static const int m_light_level[]; diff --git a/src/light/light_sensor_hal.cpp b/src/light/light_sensor_hal.cpp index 835a096..bf3a613 100755 --- a/src/light/light_sensor_hal.cpp +++ b/src/light/light_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_LIGHT "LIGHT" #define ELEMENT_NAME "NAME" @@ -114,9 +115,9 @@ string light_sensor_hal::get_model_id(void) } -sensor_type_t light_sensor_hal::get_type(void) +sensor_hal_type_t light_sensor_hal::get_type(void) { - return LIGHT_SENSOR; + return SENSOR_HAL_TYPE_LIGHT; } bool light_sensor_hal::enable(void) diff --git a/src/light/light_sensor_hal.h b/src/light/light_sensor_hal.h index 89a88f1..560cb87 100755 --- a/src/light/light_sensor_hal.h +++ b/src/light/light_sensor_hal.h @@ -21,17 +21,14 @@ #define _LIGHT_SENSOR_HAL_H_ #include -#include - -using std::string; class light_sensor_hal : public sensor_hal { public: light_sensor_hal(); virtual ~light_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -39,9 +36,9 @@ public: virtual int get_sensor_data(sensor_data_t &data); bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; unsigned long m_polling_interval; @@ -50,9 +47,9 @@ private: unsigned long long m_fired_time; int m_node_handle; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/linear_accel/linear_accel_sensor.cpp b/src/linear_accel/linear_accel_sensor.cpp index 6e21ab2..fc2a1bb 100755 --- a/src/linear_accel/linear_accel_sensor.cpp +++ b/src/linear_accel/linear_accel_sensor.cpp @@ -31,6 +31,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "LINEAR_ACCEL_SENSOR" #define SENSOR_TYPE_LINEAR_ACCEL "LINEAR_ACCEL" #define SENSOR_TYPE_GRAVITY "GRAVITY" @@ -78,7 +81,7 @@ linear_accel_sensor::linear_accel_sensor() m_enable_linear_accel = 0; register_supported_event(LINEAR_ACCEL_RAW_DATA_EVENT); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -195,9 +198,9 @@ bool linear_accel_sensor::init() return true; } -sensor_type_t linear_accel_sensor::get_type(void) +void linear_accel_sensor::get_types(vector &types) { - return LINEAR_ACCEL_SENSOR; + types.push_back(LINEAR_ACCEL_SENSOR); } bool linear_accel_sensor::on_start(void) @@ -416,9 +419,9 @@ int linear_accel_sensor::get_sensor_data(const unsigned int event_type, sensor_d return 0; } -bool linear_accel_sensor::get_properties(sensor_properties_s &properties) +bool linear_accel_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { - m_accel_sensor->get_properties(properties); + m_accel_sensor->get_properties(ACCELEROMETER_SENSOR, properties); properties.name = "Linear Acceleration Sensor"; properties.vendor = m_vendor; properties.resolution = 0.000001; diff --git a/src/linear_accel/linear_accel_sensor.h b/src/linear_accel/linear_accel_sensor.h index e8f8395..e201b93 100755 --- a/src/linear_accel/linear_accel_sensor.h +++ b/src/linear_accel/linear_accel_sensor.h @@ -30,15 +30,15 @@ public: virtual ~linear_accel_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t& event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - bool get_properties(sensor_properties_s &properties); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_base *m_accel_sensor; sensor_base *m_gyro_sensor; @@ -56,9 +56,9 @@ private: unsigned int m_enable_linear_accel; - string m_vendor; - string m_raw_data_unit; - string m_orientation_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; + std::string m_orientation_data_unit; int m_default_sampling_time; float m_accel_static_bias[3]; int m_accel_rotation_direction_compensation[3]; diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index 44d44bd..e560007 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "ORIENTATION_SENSOR" #define SENSOR_TYPE_ORIENTATION "ORIENTATION" @@ -61,7 +64,7 @@ orientation_sensor::orientation_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -139,9 +142,9 @@ bool orientation_sensor::init(void) return true; } -sensor_type_t orientation_sensor::get_type(void) +void orientation_sensor::get_types(vector &types) { - return ORIENTATION_SENSOR; + types.push_back(ORIENTATION_SENSOR); } bool orientation_sensor::on_start(void) @@ -314,7 +317,7 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da return 0; } -bool orientation_sensor::get_properties(sensor_properties_s &properties) +bool orientation_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { if(m_raw_data_unit == "DEGREES") { properties.min_range = -180; diff --git a/src/orientation/orientation_sensor.h b/src/orientation/orientation_sensor.h index 86c39f9..070a21b 100755 --- a/src/orientation/orientation_sensor.h +++ b/src/orientation/orientation_sensor.h @@ -31,12 +31,12 @@ public: bool init(void); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t& event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); @@ -55,8 +55,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; int m_azimuth_rotation_compensation; int m_pitch_rotation_compensation; diff --git a/src/pressure/pressure_sensor.cpp b/src/pressure/pressure_sensor.cpp index 407c6f9..0559021 100755 --- a/src/pressure/pressure_sensor.cpp +++ b/src/pressure/pressure_sensor.cpp @@ -26,6 +26,8 @@ using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define SENSOR_NAME "PRESSURE_SENSOR" #define SENSOR_TYPE_PRESSURE "PRESSURE" @@ -55,7 +57,7 @@ pressure_sensor::~pressure_sensor() bool pressure_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PRESSURE_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PRESSURE); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -100,9 +102,9 @@ bool pressure_sensor::init() return true; } -sensor_type_t pressure_sensor::get_type(void) +void pressure_sensor::get_types(vector &types) { - return PRESSURE_SENSOR; + types.push_back(PRESSURE_SENSOR); } bool pressure_sensor::working(void *inst) @@ -152,7 +154,7 @@ bool pressure_sensor::on_stop(void) return stop_poll(); } -bool pressure_sensor::get_properties(sensor_properties_s &properties) +bool pressure_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/pressure/pressure_sensor.h b/src/pressure/pressure_sensor.h index 3430dfb..e17f587 100755 --- a/src/pressure/pressure_sensor.h +++ b/src/pressure/pressure_sensor.h @@ -31,13 +31,13 @@ public: virtual ~pressure_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp index 33aa181..544240f 100755 --- a/src/pressure/pressure_sensor_hal.cpp +++ b/src/pressure/pressure_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_PRESSURE "PRESSURE" #define ELEMENT_NAME "NAME" @@ -151,9 +152,9 @@ string pressure_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t pressure_sensor_hal::get_type(void) +sensor_hal_type_t pressure_sensor_hal::get_type(void) { - return PRESSURE_SENSOR; + return SENSOR_HAL_TYPE_PRESSURE; } bool pressure_sensor_hal::enable(void) diff --git a/src/pressure/pressure_sensor_hal.h b/src/pressure/pressure_sensor_hal.h index 04412fc..07e8e1b 100755 --- a/src/pressure/pressure_sensor_hal.h +++ b/src/pressure/pressure_sensor_hal.h @@ -21,17 +21,14 @@ #define _PRESSURE_SENSOR_HAL_H_ #include -#include - -using std::string; class pressure_sensor_hal : public sensor_hal { public: pressure_sensor_hal(); virtual ~pressure_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); @@ -40,9 +37,9 @@ public: virtual int get_sensor_data(sensor_data_t &data); virtual bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; float m_pressure; float m_sea_level_pressure; @@ -60,9 +57,9 @@ private: unsigned long long m_fired_time; int m_node_handle; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/proxi/proxi_sensor.cpp b/src/proxi/proxi_sensor.cpp index 65809b9..05352d1 100755 --- a/src/proxi/proxi_sensor.cpp +++ b/src/proxi/proxi_sensor.cpp @@ -22,6 +22,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "PROXI_SENSOR" proxi_sensor::proxi_sensor() @@ -44,7 +47,7 @@ proxi_sensor::~proxi_sensor() bool proxi_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PROXIMITY_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_PROXIMITY); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -55,9 +58,9 @@ bool proxi_sensor::init() return true; } -sensor_type_t proxi_sensor::get_type(void) +void proxi_sensor::get_types(vector &types) { - return PROXIMITY_SENSOR; + types.push_back(PROXIMITY_SENSOR); } bool proxi_sensor::working(void *inst) @@ -122,7 +125,7 @@ bool proxi_sensor::on_stop(void) return stop_poll(); } -bool proxi_sensor::get_properties(sensor_properties_s &properties) +bool proxi_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { m_sensor_hal->get_properties(properties); diff --git a/src/proxi/proxi_sensor.h b/src/proxi/proxi_sensor.h index 8584f2d..9c3a009 100755 --- a/src/proxi/proxi_sensor.h +++ b/src/proxi/proxi_sensor.h @@ -30,12 +30,12 @@ public: virtual ~proxi_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; diff --git a/src/proxi/proxi_sensor_hal.cpp b/src/proxi/proxi_sensor_hal.cpp index aee3f7a..7358b08 100755 --- a/src/proxi/proxi_sensor_hal.cpp +++ b/src/proxi/proxi_sensor_hal.cpp @@ -25,6 +25,7 @@ #include #include +using std::string; using std::ifstream; #define SENSOR_TYPE_PROXI "PROXI" @@ -107,9 +108,9 @@ string proxi_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t proxi_sensor_hal::get_type(void) +sensor_hal_type_t proxi_sensor_hal::get_type(void) { - return PROXIMITY_SENSOR; + return SENSOR_HAL_TYPE_PROXIMITY; } bool proxi_sensor_hal::enable(void) diff --git a/src/proxi/proxi_sensor_hal.h b/src/proxi/proxi_sensor_hal.h index 3b96b04..a1cd3a1 100755 --- a/src/proxi/proxi_sensor_hal.h +++ b/src/proxi/proxi_sensor_hal.h @@ -21,9 +21,6 @@ #define _PROXI_SENSOR_HAL_H_ #include -#include - -using std::string; class proxi_sensor_hal : public sensor_hal { @@ -43,20 +40,20 @@ public: proxi_sensor_hal(); virtual ~proxi_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool is_data_ready(bool wait); virtual int get_sensor_data(sensor_data_t &data); virtual bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; - string m_enable_node; - string m_data_node; + std::string m_enable_node; + std::string m_data_node; unsigned int m_state; diff --git a/src/rotation_vector/gaming_rv/gaming_rv_sensor.cpp b/src/rotation_vector/gaming_rv/gaming_rv_sensor.cpp index fa359a0..f491038 100755 --- a/src/rotation_vector/gaming_rv/gaming_rv_sensor.cpp +++ b/src/rotation_vector/gaming_rv/gaming_rv_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "GAMING_RV_SENSOR" #define SENSOR_TYPE_GAMING_RV "GAMING_ROTATION_VECTOR" @@ -69,7 +72,7 @@ gaming_rv_sensor::gaming_rv_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -161,9 +164,9 @@ bool gaming_rv_sensor::init() return true; } -sensor_type_t gaming_rv_sensor::get_type(void) +void gaming_rv_sensor::get_types(vector &types) { - return GAMING_RV_SENSOR; + types.push_back(GAMING_RV_SENSOR); } bool gaming_rv_sensor::on_start(void) @@ -316,7 +319,7 @@ int gaming_rv_sensor::get_sensor_data(unsigned int event_type, sensor_data_t &da return 0; } -bool gaming_rv_sensor::get_properties(sensor_properties_s &properties) +bool gaming_rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.vendor = m_vendor; properties.name = SENSOR_NAME; diff --git a/src/rotation_vector/gaming_rv/gaming_rv_sensor.h b/src/rotation_vector/gaming_rv/gaming_rv_sensor.h index db9dd47..1b748b1 100755 --- a/src/rotation_vector/gaming_rv/gaming_rv_sensor.h +++ b/src/rotation_vector/gaming_rv/gaming_rv_sensor.h @@ -31,12 +31,12 @@ public: bool init(void); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t &event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); @@ -58,8 +58,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; float m_accel_static_bias[3]; diff --git a/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp b/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp index c3e8a26..f4aafe8 100755 --- a/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp +++ b/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "GEOMAGNETIC_RV_SENSOR" #define SENSOR_TYPE_GEOMAGNETIC_RV "GEOMAGNETIC_ROTATION_VECTOR" @@ -50,7 +53,7 @@ geomagnetic_rv_sensor::geomagnetic_rv_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -99,9 +102,9 @@ bool geomagnetic_rv_sensor::init() return true; } -sensor_type_t geomagnetic_rv_sensor::get_type(void) +void geomagnetic_rv_sensor::get_types(vector &types) { - return GEOMAGNETIC_RV_SENSOR; + types.push_back(GEOMAGNETIC_RV_SENSOR); } bool geomagnetic_rv_sensor::on_start(void) @@ -227,7 +230,7 @@ int geomagnetic_rv_sensor::get_sensor_data(unsigned int event_type, sensor_data_ return 0; } -bool geomagnetic_rv_sensor::get_properties(sensor_properties_s &properties) +bool geomagnetic_rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.vendor = m_vendor; properties.name = SENSOR_NAME; diff --git a/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.h b/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.h index c87d252..f5ad4b7 100755 --- a/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.h +++ b/src/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.h @@ -31,12 +31,12 @@ public: bool init(void); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t &event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); @@ -53,8 +53,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; bool on_start(void); diff --git a/src/rotation_vector/rv/rv_sensor.cpp b/src/rotation_vector/rv/rv_sensor.cpp index bcf20e2..e42716b 100755 --- a/src/rotation_vector/rv/rv_sensor.cpp +++ b/src/rotation_vector/rv/rv_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "RV_SENSOR" #define SENSOR_TYPE_RV "ROTATION_VECTOR" @@ -63,7 +66,7 @@ rv_sensor::rv_sensor() cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); // Will check if fusion_sensor is in the list of hal sensors. - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -114,9 +117,9 @@ bool rv_sensor::init() return true; } -sensor_type_t rv_sensor::get_type(void) +void rv_sensor::get_types(vector &types) { - return ROTATION_VECTOR_SENSOR; + types.push_back(ROTATION_VECTOR_SENSOR); } bool rv_sensor::on_start(void) @@ -249,7 +252,7 @@ int rv_sensor::get_sensor_data(unsigned int event_type, sensor_data_t &data) return 0; } -bool rv_sensor::get_properties(sensor_properties_s &properties) +bool rv_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.vendor = m_vendor; properties.name = SENSOR_NAME; diff --git a/src/rotation_vector/rv/rv_sensor.h b/src/rotation_vector/rv/rv_sensor.h index 3e5de3d..00f9761 100755 --- a/src/rotation_vector/rv/rv_sensor.h +++ b/src/rotation_vector/rv/rv_sensor.h @@ -31,12 +31,12 @@ public: bool init(void); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t &event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); @@ -60,8 +60,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; bool on_start(void); diff --git a/src/rotation_vector/rv_raw/rv_raw_sensor.cpp b/src/rotation_vector/rv_raw/rv_raw_sensor.cpp index 3e017ce..f1b3a2b 100755 --- a/src/rotation_vector/rv_raw/rv_raw_sensor.cpp +++ b/src/rotation_vector/rv_raw/rv_raw_sensor.cpp @@ -23,6 +23,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "RV_RAW_SENSOR" rv_raw_sensor::rv_raw_sensor() @@ -43,7 +46,7 @@ rv_raw_sensor::~rv_raw_sensor() bool rv_raw_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(RV_RAW_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_RV_RAW); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -64,9 +67,9 @@ bool rv_raw_sensor::init() return true; } -sensor_type_t rv_raw_sensor::get_type(void) +void rv_raw_sensor::get_types(vector &types) { - return RV_RAW_SENSOR; + types.push_back(RV_RAW_SENSOR); } bool rv_raw_sensor::working(void *inst) @@ -116,7 +119,7 @@ bool rv_raw_sensor::on_stop(void) return stop_poll(); } -bool rv_raw_sensor::get_properties(sensor_properties_t &properties) +bool rv_raw_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/rotation_vector/rv_raw/rv_raw_sensor.h b/src/rotation_vector/rv_raw/rv_raw_sensor.h index 4d04a4b..f55d0a1 100755 --- a/src/rotation_vector/rv_raw/rv_raw_sensor.h +++ b/src/rotation_vector/rv_raw/rv_raw_sensor.h @@ -31,13 +31,13 @@ public: virtual ~rv_raw_sensor(); virtual bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_t &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; diff --git a/src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp index 261a81e..11eb5c4 100755 --- a/src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp +++ b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_RV_RAW "ROTATION_VECTOR" #define ELEMENT_NAME "NAME" @@ -108,9 +109,9 @@ string rv_raw_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t rv_raw_sensor_hal::get_type(void) +sensor_hal_type_t rv_raw_sensor_hal::get_type(void) { - return RV_RAW_SENSOR; + return SENSOR_HAL_TYPE_RV_RAW; } bool rv_raw_sensor_hal::enable(void) diff --git a/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h index 565b509..382f454 100755 --- a/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h +++ b/src/rotation_vector/rv_raw/rv_raw_sensor_hal.h @@ -21,17 +21,14 @@ #define _RV_RAW_SENSOR_HAL_H_ #include -#include - -using std::string; class rv_raw_sensor_hal : public sensor_hal { public: rv_raw_sensor_hal(); virtual ~rv_raw_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -39,9 +36,9 @@ public: virtual int get_sensor_data(sensor_data_t &data); virtual bool get_properties(sensor_properties_t &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; unsigned long m_polling_interval; @@ -54,9 +51,9 @@ private: unsigned long long m_fired_time; int m_node_handle; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp old mode 100755 new mode 100644 index 09e633f..e88c897 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -28,11 +28,13 @@ #include #include #include +#include #include #include #include using std::string; +using std::vector; using std::make_pair; using std::set; @@ -47,6 +49,7 @@ command_worker::command_worker(const csocket& socket) , m_permission(SENSOR_PERMISSION_NONE) , m_socket(socket) , m_module(NULL) +, m_sensor_id(UNKNOWN_SENSOR) { static bool init = false; @@ -84,8 +87,8 @@ void command_worker::init_cmd_handlers(void) m_cmd_handlers[CMD_REG] = &command_worker::cmd_register_event; m_cmd_handlers[CMD_UNREG] = &command_worker::cmd_unregister_event; m_cmd_handlers[CMD_SET_OPTION] = &command_worker::cmd_set_option; - m_cmd_handlers[CMD_SET_INTERVAL] = &command_worker::cmd_set_interval; - m_cmd_handlers[CMD_UNSET_INTERVAL] = &command_worker::cmd_unset_interval; + m_cmd_handlers[CMD_SET_BATCH] = &command_worker::cmd_set_batch; + m_cmd_handlers[CMD_UNSET_BATCH] = &command_worker::cmd_unset_batch; m_cmd_handlers[CMD_SET_COMMAND] = &command_worker::cmd_set_command; m_cmd_handlers[CMD_GET_DATA] = &command_worker::cmd_get_data; m_cmd_handlers[CMD_SEND_SENSORHUB_DATA] = &command_worker::cmd_send_sensorhub_data; @@ -147,17 +150,26 @@ void command_worker::make_sensor_raw_data_map(void) sensors = sensor_plugin_loader::get_instance().get_sensors(ALL_SENSOR); + std::sort(sensors.begin(), sensors.end()); + auto last = std::unique(sensors.begin(), sensors.end()); + auto it_sensor = sensors.begin(); - while (it_sensor != sensors.end()) { - (*it_sensor)->get_sensor_info(info); - permission = (*it_sensor)->get_permission(); + while (it_sensor != last) { + + vector types; + (*it_sensor)->get_types(types); - sensor_raw_data_map::iterator it_sensor_raw_data; - it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t())); + for (unsigned int i = 0; i < types.size(); ++i) { + (*it_sensor)->get_sensor_info(types[i], info); + permission = (*it_sensor)->get_permission(); - info.get_raw_data(it_sensor_raw_data->second); - info.clear(); + sensor_raw_data_map::iterator it_sensor_raw_data; + it_sensor_raw_data = m_sensor_raw_data_map.insert(std::make_pair(permission, raw_data_t())); + + info.get_raw_data(it_sensor_raw_data->second); + info.clear(); + } ++it_sensor; } } @@ -213,7 +225,7 @@ bool command_worker::stopped(void *ctx) if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) { - get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_module->get_id(), event_vec); + get_client_info_manager().get_registered_events(inst->m_client_id, inst->m_sensor_id, event_vec); auto it_event = event_vec.begin(); @@ -225,16 +237,16 @@ bool command_worker::stopped(void *ctx) ++it_event; } - if (get_client_info_manager().is_started(inst->m_client_id, inst->m_module->get_id())) { + if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) { WARN("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name()); inst->m_module->delete_interval(inst->m_client_id, false); inst->m_module->stop(); } - if (inst->m_module->get_id()) { - if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_module->get_id())) { - INFO("Removing sensor[0x%x] record for client_id[%d]", inst->m_module->get_id(), inst->m_client_id); - get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_module->get_id()); + if (inst->m_sensor_id) { + if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) { + INFO("Removing sensor[0x%x] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); + get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id); } } } @@ -356,12 +368,20 @@ bool command_worker::cmd_get_id(void *payload) { cmd_get_id_t *cmd; int client_id; + struct ucred cr; + socklen_t opt_len = sizeof(cr); DBG("CMD_GET_ID Handler invoked\n"); cmd = (cmd_get_id_t*)payload; + if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) { + ERR("Failed to get socket option with SO_PEERCRED"); + return false; + } + client_id = get_client_info_manager().create_client_record(); - get_client_info_manager().set_client_info(client_id, cmd->pid); + + get_client_info_manager().set_client_info(client_id, cr.pid, cmd->name); m_permission = get_permission(); get_client_info_manager().set_permission(client_id, m_permission); @@ -393,6 +413,7 @@ bool command_worker::cmd_hello(void *payload) DBG("CMD_HELLO Handler invoked\n"); cmd = (cmd_hello_t*)payload; + m_sensor_id = cmd->sensor; m_client_id = cmd->client_id; if (m_permission == SENSOR_PERMISSION_NONE) @@ -410,14 +431,14 @@ bool command_worker::cmd_hello(void *payload) } if (!is_permission_allowed()) { - ERR("Permission denied to connect sensor[0x%x] for client [%d]", m_module->get_id(), m_client_id); + ERR("Permission denied to connect sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("Hello sensor [0x%x], client id [%d]", m_module->get_id(), m_client_id); - get_client_info_manager().create_sensor_record(m_client_id, m_module->get_id()); - INFO("New sensor record created for sensor [0x%x], sensor name [%s] on client id [%d]\n", m_module->get_id(), m_module->get_name(), m_client_id); + DBG("Hello sensor [0x%x], client id [%d]", m_sensor_id, m_client_id); + get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id); + INFO("New sensor record created for sensor [0x%x], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id); ret_value = OP_SUCCESS; out: if (!send_cmd_done(ret_value)) @@ -431,14 +452,14 @@ bool command_worker::cmd_byebye(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id); + ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("CMD_BYEBYE for client [%d], sensor [0x%x]", m_client_id, m_module->get_id()); + DBG("CMD_BYEBYE for client [%d], sensor [0x%x]", m_client_id, m_sensor_id); - if (!get_client_info_manager().remove_sensor_record(m_client_id, m_module->get_id())) { + if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) { ERR("Error removing sensor_record for client [%d]", m_client_id); ret_value = OP_ERROR; goto out; @@ -462,24 +483,24 @@ bool command_worker::cmd_start(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to start sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id); + ERR("Permission denied to start sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("START Sensor [0x%x], called from client [%d]", m_module->get_id(), m_client_id); + DBG("START Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id); if (m_module->start()) { - get_client_info_manager().set_start(m_client_id, m_module->get_id(), true); + get_client_info_manager().set_start(m_client_id, m_sensor_id, true); /* * Rotation could be changed even LCD is off by pop sync rotation * and a client listening rotation event with always-on option. * To reflect the last rotation state, request it to event dispatcher. */ - get_event_dispathcher().request_last_event(m_client_id, m_module->get_id()); + get_event_dispathcher().request_last_event(m_client_id, m_sensor_id); ret_value = OP_SUCCESS; } else { - ERR("Failed to start sensor [0x%x] for client [%d]", m_module->get_id(), m_client_id); + ERR("Failed to start sensor [0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -495,18 +516,18 @@ bool command_worker::cmd_stop(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_module? m_module->get_id() : -1, m_client_id); + ERR("Permission denied to stop sensor[0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - DBG("STOP Sensor [0x%x], called from client [%d]", m_module->get_id(), m_client_id); + DBG("STOP Sensor [0x%x], called from client [%d]", m_sensor_id, m_client_id); if (m_module->stop()) { - get_client_info_manager().set_start(m_client_id, m_module->get_id(), false); + get_client_info_manager().set_start(m_client_id, m_sensor_id, false); ret_value = OP_SUCCESS; } else { - ERR("Failed to stop sensor [0x%x] for client [%d]", m_module->get_id(), m_client_id); + ERR("Failed to stop sensor [0x%x] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -531,7 +552,7 @@ bool command_worker::cmd_register_event(void *payload) goto out; } - if (!get_client_info_manager().register_event(m_client_id, m_module? m_module->get_id() : -1, cmd->event_type)) { + if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) { INFO("Failed to register event [0x%x] for client [%d] to client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; @@ -565,7 +586,7 @@ bool command_worker::cmd_unregister_event(void *payload) goto out; } - if (!get_client_info_manager().unregister_event(m_client_id, m_module->get_id(), cmd->event_type)) { + if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) { ERR("Failed to unregister event [0x%x] for client [%d] from client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; @@ -590,30 +611,30 @@ out: return true; } -bool command_worker::cmd_set_interval(void *payload) +bool command_worker::cmd_set_batch(void *payload) { - cmd_set_interval_t *cmd; + cmd_set_batch_t *cmd; long ret_value = OP_ERROR; - cmd = (cmd_set_interval_t*)payload; + cmd = (cmd_set_batch_t*)payload; if (!is_permission_allowed()) { - ERR("Permission denied to register interval for client [%d], for sensor [0x%x] with interval [%d] to client info manager", - m_client_id, m_module? m_module->get_id() : -1, cmd->interval); + ERR("Permission denied to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager", + m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } - if (!get_client_info_manager().set_interval(m_client_id, m_module->get_id(), cmd->interval)) { - ERR("Failed to register interval for client [%d], for sensor [0x%x] with interval [%d] to client info manager", - m_client_id, m_module->get_id(), cmd->interval); + if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) { + ERR("Failed to set batch for client [%d], for sensor [0x%x] with batch [%d, %d] to client info manager", + m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } if (!m_module->add_interval(m_client_id, cmd->interval, false)) { ERR("Failed to set interval for client [%d], for sensor [0x%x] with interval [%d]", - m_client_id, m_module->get_id(), cmd->interval); + m_client_id, m_sensor_id, cmd->interval); ret_value = OP_ERROR; goto out; } @@ -627,20 +648,20 @@ out: return true; } -bool command_worker::cmd_unset_interval(void *payload) +bool command_worker::cmd_unset_batch(void *payload) { long ret_value = OP_ERROR; if (!is_permission_allowed()) { - ERR("Permission denied to unregister interval for client [%d], for sensor [0x%x] to client info manager", - m_client_id, m_module? m_module->get_id() : -1); + ERR("Permission denied to unset batch for client [%d], for sensor [0x%x] to client info manager", + m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; } - if (!get_client_info_manager().set_interval(m_client_id, m_module->get_id(), 0)) { - ERR("Failed to unregister interval for client [%d], for sensor [0x%x] to client info manager", - m_client_id, m_module->get_id()); + if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) { + ERR("Failed to unset batch for client [%d], for sensor [0x%x] to client info manager", + m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; } @@ -669,14 +690,14 @@ bool command_worker::cmd_set_option(void *payload) if (!is_permission_allowed()) { ERR("Permission denied to set interval for client [%d], for sensor [0x%x] with option [%d] to client info manager", - m_client_id, m_module? m_module->get_id() : -1, cmd->option); + m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; } - if (!get_client_info_manager().set_option(m_client_id, m_module->get_id(), cmd->option)) { + if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) { ERR("Failed to set option for client [%d], for sensor [0x%x] with option [%d] to client info manager", - m_client_id, m_module->get_id(), cmd->option); + m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; } @@ -700,7 +721,7 @@ bool command_worker::cmd_set_command(void *payload) if (!is_permission_allowed()) { ERR("Permission denied to set command for client [%d], for sensor [0x%x] with cmd [%d]", - m_client_id, m_module? m_module->get_id() : -1, cmd->cmd); + m_client_id, m_sensor_id, cmd->cmd); ret_value = OP_ERROR; goto out; } @@ -729,7 +750,7 @@ bool command_worker::cmd_get_data(void *payload) if (!is_permission_allowed()) { ERR("Permission denied to get data for client [%d], for sensor [0x%x]", - m_client_id, m_module? m_module->get_id() : -1); + m_client_id, m_sensor_id); state = OP_ERROR; goto out; } @@ -744,7 +765,7 @@ bool command_worker::cmd_get_data(void *payload) // 5. repeat 2 ~ 4 operations RETRY_CNT times // 6. reverting back to original interval if (!state && !data.timestamp) { - const int RETRY_CNT = 3; + const int RETRY_CNT = 5; const unsigned long long INIT_WAIT_TIME = 20000; //20ms const unsigned long WAIT_TIME = 100000; //100ms int retry = 0; @@ -757,7 +778,7 @@ bool command_worker::cmd_get_data(void *payload) } while (!state && !data.timestamp && (retry++ < RETRY_CNT)) { - INFO("Wait sensor[0x%x] data updated for client [%d] #%d", m_module->get_id(), m_client_id, retry); + INFO("Wait sensor[0x%x] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep((retry == 1) ? INIT_WAIT_TIME : WAIT_TIME); state = m_module->get_sensor_data(cmd->type, data); } @@ -771,7 +792,7 @@ bool command_worker::cmd_get_data(void *payload) if (state) { ERR("Failed to get data for client [%d], for sensor [0x%x]", - m_client_id, m_module->get_id()); + m_client_id, m_sensor_id); } out: @@ -791,7 +812,7 @@ bool command_worker::cmd_send_sensorhub_data(void *payload) if (!is_permission_allowed()) { ERR("Permission denied to send sensorhub_data for client [%d], for sensor [0x%x]", - m_client_id, m_module? m_module->get_id() : -1); + m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; } diff --git a/src/server/command_worker.h b/src/server/command_worker.h old mode 100755 new mode 100644 index 33f1b0a..89796f5 --- a/src/server/command_worker.h +++ b/src/server/command_worker.h @@ -26,9 +26,7 @@ #include #include -using std::multimap; - -typedef multimap sensor_raw_data_map; +typedef std::multimap sensor_raw_data_map; void insert_priority_list(unsigned int); class command_worker { @@ -43,6 +41,7 @@ private: csocket m_socket; worker_thread m_worker; sensor_base *m_module; + sensor_id_t m_sensor_id; static cmd_handler_t m_cmd_handlers[CMD_CNT]; static cpacket m_sensor_list; static sensor_raw_data_map m_sensor_raw_data_map; @@ -70,14 +69,14 @@ private: bool cmd_stop(void *payload); bool cmd_register_event(void *payload); bool cmd_unregister_event(void *payload); - bool cmd_set_interval(void *payload); - bool cmd_unset_interval(void *payload); + bool cmd_set_batch(void *payload); + bool cmd_unset_batch(void *payload); bool cmd_set_option(void *payload); bool cmd_set_command(void *payload); bool cmd_get_data(void *payload); bool cmd_send_sensorhub_data(void *payload); - void get_info(string &info); + void get_info(std::string &info); int get_permission(void); bool is_permission_allowed(void); diff --git a/src/server/main.cpp b/src/server/main.cpp index c9be4e0..91c8674 100755 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -22,6 +22,9 @@ #include #include #include +#include + +using std::string; static void sig_term_handler(int signo, siginfo_t *info, void *data) { @@ -60,8 +63,6 @@ int main(int argc, char *argv[]) server::get_instance().stop(); - sensor_plugin_loader::get_instance().destroy(); - INFO("Sensord terminated"); return 0; } diff --git a/src/server/permission_checker.cpp b/src/server/permission_checker.cpp index f4fff18..dea1763 100755 --- a/src/server/permission_checker.cpp +++ b/src/server/permission_checker.cpp @@ -81,7 +81,7 @@ void permission_checker::init() m_permission_infos.push_back(std::make_shared (SENSOR_PERMISSION_STANDARD, false, "")); m_permission_infos.push_back(std::make_shared (SENSOR_PERMISSION_BIO, true, "http://tizen.org/privilege/healthinfo")); - vector sensors; + std::vector sensors; sensors = sensor_plugin_loader::get_instance().get_sensors(ALL_SENSOR); for (unsigned int i = 0; i < sensors.size(); ++i) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt old mode 100755 new mode 100644 index 2cadc1a..cdc35ee --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -29,6 +29,7 @@ add_library(sensord-server SHARED cclient_info_manager.cpp cclient_sensor_record.cpp cinterval_info_list.cpp + batch_info_list.cpp sensor_plugin_loader.cpp sensor_hal.cpp sensor_base.cpp @@ -63,6 +64,7 @@ install(FILES cvirtual_sensor_config.h csensor_event_queue.h cinterval_info_list.h + batch_info_list.h sensor_plugin_loader.h sensor_hal.h sensor_base.h diff --git a/src/shared/batch_info_list.cpp b/src/shared/batch_info_list.cpp new file mode 100644 index 0000000..0fd84b1 --- /dev/null +++ b/src/shared/batch_info_list.cpp @@ -0,0 +1,90 @@ +/* + * libsensord-share + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +using std::pair; +using std::shared_ptr; + +batch_info::batch_info(unsigned int interval, unsigned int latency) +{ + this->interval = interval; + this->latency = latency; +} + +bool batch_info_list::add_batch(int id, unsigned int interval, unsigned int latency) +{ + auto it_batch_info = m_batch_infos.find(id); + + if (it_batch_info != m_batch_infos.end()) { + it_batch_info->second->interval = interval; + it_batch_info->second->latency = latency; + return true; + } + + m_batch_infos.insert(pair> (id, std::make_shared (interval, latency))); + return true; +} + +bool batch_info_list::delete_batch(int id) +{ + auto it_batch_info = m_batch_infos.find(id); + + if (it_batch_info == m_batch_infos.end()) + return false; + + m_batch_infos.erase(it_batch_info); + return true; +} + +bool batch_info_list::get_batch(int id, unsigned int &interval, unsigned int &latency) +{ + auto it_batch_info = m_batch_infos.find(id); + + if (it_batch_info == m_batch_infos.end()) + return false; + + interval = it_batch_info->second->interval; + latency = it_batch_info->second->latency; + + return true; +} + +bool batch_info_list::get_best_batch(unsigned int &interval, unsigned int &latency) +{ + if (m_batch_infos.empty()) + return false; + + auto get_min_interval = [](pair> &a, pair> &b){ + return (a.second->interval < b.second->interval); + }; + + auto get_min_latency = [](pair> &a, pair> &b){ + return (a.second->latency < b.second->latency); + }; + + auto it_interval_min = std::min_element(m_batch_infos.begin(), m_batch_infos.end(), get_min_interval); + auto it_latency_min = std::min_element(m_batch_infos.begin(), m_batch_infos.end(), get_min_latency); + + interval = it_interval_min->second->interval; + latency = it_latency_min->second->latency; + + return true; +} diff --git a/src/shared/batch_info_list.h b/src/shared/batch_info_list.h new file mode 100644 index 0000000..d6c22f0 --- /dev/null +++ b/src/shared/batch_info_list.h @@ -0,0 +1,45 @@ +/* + * libsensord-share + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _BATCH_INFO_LIST_CLASS_H_ +#define _BATCH_INFO_LIST_CLASS_H_ + +#include +#include + +class batch_info +{ +public: + batch_info(unsigned int interval, unsigned int latency); + unsigned int interval; + unsigned int latency; +}; + +class batch_info_list +{ +private: + std::unordered_map> m_batch_infos; + +public: + bool add_batch(int id, unsigned int interval, unsigned int latency); + bool delete_batch(int id); + bool get_batch(int id, unsigned int &interval, unsigned int &latency); + bool get_best_batch(unsigned int &interval, unsigned int &latency); +}; +#endif diff --git a/src/shared/cclient_info_manager.cpp b/src/shared/cclient_info_manager.cpp old mode 100755 new mode 100644 index 3302167..1a142de --- a/src/shared/cclient_info_manager.cpp +++ b/src/shared/cclient_info_manager.cpp @@ -22,6 +22,7 @@ #include using std::pair; +using std::string; cclient_info_manager::cclient_info_manager() { @@ -37,21 +38,6 @@ cclient_info_manager& cclient_info_manager::get_instance() return inst; } - -unsigned int cclient_info_manager::get_interval(int client_id, sensor_id_t sensor_id) -{ - AUTOLOCK(m_mutex); - - auto it_record = m_clients.find(client_id); - - if (it_record == m_clients.end()) { - ERR("Client[%d] is not found", client_id); - return 0; - } - - return it_record->second.get_interval(sensor_id); -} - bool cclient_info_manager::get_registered_events(int client_id, sensor_id_t sensor_id, event_type_vector &event_vec) { AUTOLOCK(m_mutex); @@ -104,7 +90,7 @@ bool cclient_info_manager::unregister_event(int client_id, sensor_id_t sensor_id return true; } -bool cclient_info_manager::set_interval(int client_id, sensor_id_t sensor_id, unsigned int interval) +bool cclient_info_manager::set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned latency) { AUTOLOCK(m_mutex); @@ -115,10 +101,21 @@ bool cclient_info_manager::set_interval(int client_id, sensor_id_t sensor_id, un return false; } - if(!it_record->second.set_interval(sensor_id, interval)) + return it_record->second.set_batch(sensor_id, interval, latency); +} + +bool cclient_info_manager::get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency) +{ + AUTOLOCK(m_mutex); + + auto it_record = m_clients.find(client_id); + + if (it_record == m_clients.end()) { + ERR("Client[%d] is not found", client_id); return false; + } - return true; + return it_record->second.get_batch(sensor_id, interval, latency); } bool cclient_info_manager::set_option(int client_id, sensor_id_t sensor_id, int option) @@ -224,7 +221,7 @@ bool cclient_info_manager::has_client_record(int client_id) } -void cclient_info_manager::set_client_info(int client_id, pid_t pid) +void cclient_info_manager::set_client_info(int client_id, pid_t pid, const string &name) { AUTOLOCK(m_mutex); @@ -235,7 +232,7 @@ void cclient_info_manager::set_client_info(int client_id, pid_t pid) return; } - it_record->second.set_client_info(pid); + it_record->second.set_client_info(pid, name); return; } diff --git a/src/shared/cclient_info_manager.h b/src/shared/cclient_info_manager.h old mode 100755 new mode 100644 index ccf67ae..e36c2fb --- a/src/shared/cclient_info_manager.h +++ b/src/shared/cclient_info_manager.h @@ -24,10 +24,10 @@ #include #include #include -using std::unordered_map; +#include -typedef unordered_map client_id_sensor_record_map; -typedef vector client_id_vec; +typedef std::unordered_map client_id_sensor_record_map; +typedef std::vector client_id_vec; class cclient_info_manager { @@ -37,7 +37,7 @@ public: bool remove_client_record(int client_id); bool has_client_record(int client_id); - void set_client_info(int client_id, pid_t pid); + void set_client_info(int client_id, pid_t pid, const std::string &name); const char* get_client_info(int client_id); bool set_permission(int client_id, int permission); @@ -51,8 +51,8 @@ public: bool register_event(int client_id, sensor_id_t sensor_id, unsigned int event_type); bool unregister_event(int client_id, sensor_id_t sensor_id, unsigned int event_type); - bool set_interval(int client_id, sensor_id_t sensor_id, unsigned int interval); - unsigned int get_interval(int client_id, sensor_id_t sensor_id); + bool set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned int latency); + bool get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency); bool set_option(int client_id, sensor_id_t sensor_id, int option); bool set_start(int client_id, sensor_id_t sensor_id, bool start); diff --git a/src/shared/cclient_sensor_record.cpp b/src/shared/cclient_sensor_record.cpp old mode 100755 new mode 100644 index a302e4c..6995862 --- a/src/shared/cclient_sensor_record.cpp +++ b/src/shared/cclient_sensor_record.cpp @@ -21,6 +21,7 @@ #include using std::pair; +using std::string; cclient_sensor_record::cclient_sensor_record() : m_client_id(0) @@ -72,21 +73,6 @@ bool cclient_sensor_record::unregister_event(sensor_id_t sensor_id, unsigned int return true; } -bool cclient_sensor_record::set_interval(sensor_id_t sensor_id, unsigned int interval) -{ - auto it_usage = m_sensor_usages.find(sensor_id); - - if (it_usage == m_sensor_usages.end()) { - csensor_usage usage; - usage.m_interval = interval; - m_sensor_usages.insert(pair(sensor_id, usage)); - } else { - it_usage->second.m_interval = interval; - } - - return true; -} - bool cclient_sensor_record::set_option(sensor_id_t sensor_id, int option) { auto it_usage = m_sensor_usages.find(sensor_id); @@ -128,18 +114,36 @@ bool cclient_sensor_record::is_started(sensor_id_t sensor_id) return it_usage->second.m_start; } +bool cclient_sensor_record::set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency) +{ + auto it_usage = m_sensor_usages.find(sensor_id); + if (it_usage == m_sensor_usages.end()) { + csensor_usage usage; + usage.m_interval = interval; + usage.m_latency = latency; + m_sensor_usages.insert(pair(sensor_id, usage)); + } else { + it_usage->second.m_interval = interval; + it_usage->second.m_latency = latency; + } -unsigned int cclient_sensor_record::get_interval(sensor_id_t sensor_id) + return true; +} + +bool cclient_sensor_record::get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency) { auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { ERR("Sensor[0x%x] is not found", sensor_id); - return 0; + return false; } - return it_usage->second.m_interval; + interval = it_usage->second.m_interval; + latency = it_usage->second.m_latency; + + return true; } bool cclient_sensor_record::is_listening_event(sensor_id_t sensor_id, unsigned int event_type) @@ -223,17 +227,13 @@ void cclient_sensor_record::set_client_id(int client_id) m_client_id = client_id; } -void cclient_sensor_record::set_client_info(pid_t pid) +void cclient_sensor_record::set_client_info(pid_t pid, const string &name) { char client_info[NAME_MAX + 32]; - char proc_name[NAME_MAX]; - m_pid = pid; - get_proc_name(pid, proc_name); - snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", proc_name, m_pid, m_client_id); + snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", name.c_str(), m_pid, m_client_id); m_client_info.assign(client_info); - } const char* cclient_sensor_record::get_client_info(void) diff --git a/src/shared/cclient_sensor_record.h b/src/shared/cclient_sensor_record.h old mode 100755 new mode 100644 index c2d9ef7..d42093e --- a/src/shared/cclient_sensor_record.h +++ b/src/shared/cclient_sensor_record.h @@ -25,10 +25,9 @@ #include #include #include +#include -using std::unordered_map; - -typedef unordered_map sensor_usage_map; +typedef std::unordered_map sensor_usage_map; class cclient_sensor_record { public: @@ -37,7 +36,7 @@ public: void set_client_id(int client_id); - void set_client_info(pid_t pid); + void set_client_info(pid_t pid, const std::string &name); const char* get_client_info(void); void set_permission(int permission); @@ -46,8 +45,8 @@ public: bool register_event(sensor_id_t sensor_id, unsigned int event_type); bool unregister_event(sensor_id_t sensor_id, unsigned int event_type); - bool set_interval(sensor_id_t sensor_id, unsigned int interval); - unsigned int get_interval(sensor_id_t sensor_id); + bool set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency); + bool get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency); bool set_option(sensor_id_t sensor_id, int option); bool set_start(sensor_id_t sensor_id, bool start); @@ -70,7 +69,7 @@ private: int m_client_id; pid_t m_pid; int m_permission; - string m_client_info; + std::string m_client_info; csocket m_event_socket; sensor_usage_map m_sensor_usages; }; diff --git a/src/shared/cconfig.cpp b/src/shared/cconfig.cpp index 23d11a5..14c7f01 100755 --- a/src/shared/cconfig.cpp +++ b/src/shared/cconfig.cpp @@ -19,8 +19,11 @@ #include #include +#include using std::ifstream; +using std::string; +using std::istringstream; cconfig::cconfig(void) { diff --git a/src/shared/cconfig.h b/src/shared/cconfig.h index aa92fdd..dd23b11 100755 --- a/src/shared/cconfig.h +++ b/src/shared/cconfig.h @@ -24,16 +24,12 @@ #include #include -using std::unordered_map; -using std::string; -using std::istringstream; - class cconfig { protected: - virtual bool load_config(const string& config_path) = 0; + virtual bool load_config(const std::string& config_path) = 0; - string m_device_id; + std::string m_device_id; public: cconfig(); virtual ~cconfig(); diff --git a/src/shared/cinterval_info_list.h b/src/shared/cinterval_info_list.h index 340cba6..3c28c95 100755 --- a/src/shared/cinterval_info_list.h +++ b/src/shared/cinterval_info_list.h @@ -21,7 +21,6 @@ #define _CINTERVAL_INFO_LIST_CLASS_H_ #include -using std::list; class cinterval_info { @@ -32,7 +31,7 @@ public: unsigned int interval; }; -typedef list::iterator cinterval_info_iterator; +typedef std::list::iterator cinterval_info_iterator; class cinterval_info_list { @@ -40,7 +39,7 @@ private: static bool comp_interval_info(cinterval_info a, cinterval_info b); cinterval_info_iterator find_if(int client_id, bool is_processor); - list m_list; + std::list m_list; public: bool add_interval(int client_id, unsigned int interval, bool is_processor); diff --git a/src/shared/common.cpp b/src/shared/common.cpp old mode 100755 new mode 100644 index 884bbf3..7196266 --- a/src/shared/common.cpp +++ b/src/shared/common.cpp @@ -113,6 +113,7 @@ EXTAPI void sf_log(int type , int priority , const char *tag , const char *fmt , va_end(ap); } +#if defined(_DEBUG) bool get_proc_name(pid_t pid, char *process_name) { FILE *fp; @@ -131,10 +132,26 @@ bool get_proc_name(pid_t pid, char *process_name) } strncpy(process_name, buf, NAME_MAX-1); + process_name[NAME_MAX-1] = '\0'; fclose(fp); return true; } +#else +bool get_proc_name(pid_t pid, char *process_name) +{ + char buf[NAME_MAX]; + + if (sprintf(buf, "%d process", pid) < 1) { + return false; + } + + strncpy(process_name, buf, NAME_MAX-1); + process_name[NAME_MAX-1] = '\0'; + + return true; +} +#endif const char* get_client_name(void) { diff --git a/src/shared/csensor_config.cpp b/src/shared/csensor_config.cpp index 1f193a7..f36c818 100755 --- a/src/shared/csensor_config.cpp +++ b/src/shared/csensor_config.cpp @@ -24,8 +24,11 @@ #include #include #include +#include using std::ifstream; +using std::string; +using std::istringstream; #define ROOT_ELEMENT "SENSOR" #define TEXT_ELEMENT "text" diff --git a/src/shared/csensor_config.h b/src/shared/csensor_config.h index d4c69a5..5ce6c74 100755 --- a/src/shared/csensor_config.h +++ b/src/shared/csensor_config.h @@ -24,7 +24,7 @@ #define SENSOR_CONFIG_FILE_PATH "/usr/etc/sensors.xml" -typedef unordered_map Element; +typedef std::unordered_map Element; /* * an Element is a group of attributes * @@ -33,7 +33,7 @@ typedef unordered_map Element; * */ -typedef unordered_map Model; +typedef std::unordered_map Model; /* * a Model is a group of elements to consist of specific vendor's one sensor configuration * @@ -45,7 +45,7 @@ typedef unordered_map Model; * */ -typedef unordered_map Model_list; +typedef std::unordered_map Model_list; /* * a Model_list is a group of Model * @@ -57,7 +57,7 @@ typedef unordered_map Model_list; * */ -typedef unordered_map Sensor_config; +typedef std::unordered_map Sensor_config; /* * a SensorConfig represents sensors.xml * @@ -75,21 +75,21 @@ private: csensor_config(csensor_config const&) {}; csensor_config& operator=(csensor_config const&); - bool load_config(const string& config_path); + bool load_config(const std::string& config_path); Sensor_config m_sensor_config; public: static csensor_config& get_instance(void); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, std::string& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, double& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, const std::string& attr, long& value); - bool get(const string& sensor_type, const string& model_id, const string& element, string& value); - bool get(const string& sensor_type, const string& model_id, const string& element, double& value); - bool get(const string& sensor_type, const string& model_id, const string& element, long& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, std::string& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, double& value); + bool get(const std::string& sensor_type, const std::string& model_id, const std::string& element, long& value); - bool is_supported(const string &sensor_type, const string &model_id); + bool is_supported(const std::string &sensor_type, const std::string &model_id); }; #endif diff --git a/src/shared/csensor_event_dispatcher.cpp b/src/shared/csensor_event_dispatcher.cpp index 6906ee2..1fc79e0 100755 --- a/src/shared/csensor_event_dispatcher.cpp +++ b/src/shared/csensor_event_dispatcher.cpp @@ -22,7 +22,10 @@ #include #include #include +#include + using std::thread; +using std::vector; #define MAX_PENDING_CONNECTION 32 diff --git a/src/shared/csensor_event_dispatcher.h b/src/shared/csensor_event_dispatcher.h index fe9eba1..27131c2 100755 --- a/src/shared/csensor_event_dispatcher.h +++ b/src/shared/csensor_event_dispatcher.h @@ -25,9 +25,11 @@ #include #include #include +#include +#include -typedef unordered_map event_type_last_event_map; -typedef list virtual_sensors; +typedef std::unordered_map event_type_last_event_map; +typedef std::list virtual_sensors; class csensor_event_dispatcher { diff --git a/src/shared/csensor_event_queue.cpp b/src/shared/csensor_event_queue.cpp old mode 100755 new mode 100644 index d3aa0dc..ed95497 --- a/src/shared/csensor_event_queue.cpp +++ b/src/shared/csensor_event_queue.cpp @@ -20,18 +20,13 @@ #include #include "common.h" -csensor_event_queue::csensor_event_queue() -{ -} - csensor_event_queue& csensor_event_queue::get_instance() { static csensor_event_queue inst; return inst; } - -void csensor_event_queue::push(sensor_event_t const &event) +void csensor_event_queue::push(const sensor_event_t &event) { sensor_event_t *new_event = new(std::nothrow) sensor_event_t; retm_if(!new_event, "Failed to allocate memory"); @@ -40,7 +35,12 @@ void csensor_event_queue::push(sensor_event_t const &event) push_internal(new_event); } -void csensor_event_queue::push(sensorhub_event_t const &event) +void csensor_event_queue::push(sensor_event_t *event) +{ + push_internal(event); +} + +void csensor_event_queue::push(const sensorhub_event_t &event) { sensorhub_event_t *new_event = new(std::nothrow) sensorhub_event_t; retm_if(!new_event, "Failed to allocate memory"); @@ -49,6 +49,11 @@ void csensor_event_queue::push(sensorhub_event_t const &event) push_internal(new_event); } +void csensor_event_queue::push(sensorhub_event_t *event) +{ + push_internal(event); +} + void csensor_event_queue::push_internal(void *event) { lock l(m_mutex); @@ -63,7 +68,6 @@ void csensor_event_queue::push_internal(void *event) delete (sensorhub_event_t *)event; else delete (sensor_event_t *)event; - } else m_queue.push(event); diff --git a/src/shared/csensor_event_queue.h b/src/shared/csensor_event_queue.h old mode 100755 new mode 100644 index 4c554d9..8ae00d2 --- a/src/shared/csensor_event_queue.h +++ b/src/shared/csensor_event_queue.h @@ -25,15 +25,7 @@ #include #include -using namespace std; -using std::queue; -using std::mutex; -using std::lock_guard; -using std::unique_lock; -using std::condition_variable; -using std::set; - -extern set priority_list; +extern std::set priority_list; class csensor_event_queue { @@ -51,8 +43,8 @@ private: if (priority_list.empty()) return (e2->data.timestamp < e1->data.timestamp); - set::iterator iter_e1 = priority_list.find(e1->event_type); - set::iterator iter_e2 = priority_list.find(e2->event_type); + std::set::iterator iter_e1 = priority_list.find(e1->event_type); + std::set::iterator iter_e2 = priority_list.find(e2->event_type); if (iter_e1 == priority_list.end()) prioritize_e1 = false; @@ -82,21 +74,24 @@ private: std::priority_queue, compare> m_queue; - mutex m_mutex; - condition_variable m_cond_var; + std::mutex m_mutex; + std::condition_variable m_cond_var; - typedef lock_guard lock; - typedef unique_lock ulock; + typedef std::lock_guard lock; + typedef std::unique_lock ulock; - csensor_event_queue(); - csensor_event_queue(csensor_event_queue const&) {}; - csensor_event_queue& operator=(csensor_event_queue const&); + csensor_event_queue() {}; + ~csensor_event_queue() {}; + csensor_event_queue(const csensor_event_queue &) {}; + csensor_event_queue& operator=(const csensor_event_queue &); void push_internal(void *event); - public: static csensor_event_queue& get_instance(); - void push(sensor_event_t const &event); - void push(sensorhub_event_t const &event); + void push(const sensor_event_t &event); + void push(sensor_event_t *event); + void push(const sensorhub_event_t &event); + void push(sensorhub_event_t *event); + void* pop(void); }; diff --git a/src/shared/csensor_usage.cpp b/src/shared/csensor_usage.cpp old mode 100755 new mode 100644 index f270a36..345c014 --- a/src/shared/csensor_usage.cpp +++ b/src/shared/csensor_usage.cpp @@ -23,6 +23,7 @@ csensor_usage::csensor_usage() : m_interval(POLL_MAX_HZ_MS) +, m_latency(0) , m_option(SENSOR_OPTION_DEFAULT) , m_start(false) { diff --git a/src/shared/csensor_usage.h b/src/shared/csensor_usage.h old mode 100755 new mode 100644 index 3535962..3c71dcd --- a/src/shared/csensor_usage.h +++ b/src/shared/csensor_usage.h @@ -23,13 +23,13 @@ #include #include #include -using std::vector; -typedef vector reg_event_vector; +typedef std::vector reg_event_vector; class csensor_usage { public: unsigned int m_interval; + unsigned int m_latency; int m_option; reg_event_vector m_reg_events; bool m_start; diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp old mode 100755 new mode 100644 index 96ff1d5..9845b5f --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -20,7 +20,7 @@ #include #include #include - +#include csocket::csocket() : m_sock_fd(-1) @@ -160,7 +160,7 @@ bool csocket::accept(csocket& client_socket) const return true; } -ssize_t csocket::send_for_seqpacket(void const* buffer, size_t size) const +ssize_t csocket::send_for_seqpacket(const void *buffer, size_t size) const { ssize_t err, len; @@ -210,14 +210,14 @@ ssize_t csocket::recv_for_seqpacket(void* buffer, size_t size) const } -ssize_t csocket::send_for_stream(void const* buffer, size_t size) const +ssize_t csocket::send_for_stream(const void *buffer, size_t size) const { ssize_t len; ssize_t err = 0; size_t total_sent_size = 0; do { - len = ::send(m_sock_fd, (void const*)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags); + len = ::send(m_sock_fd, (const void *)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags); if (len >= 0) { total_sent_size += len; @@ -269,7 +269,7 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const } -ssize_t csocket::send(void const* buffer, size_t size) const +ssize_t csocket::send(const void *buffer, size_t size) const { if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); diff --git a/src/shared/csocket.h b/src/shared/csocket.h old mode 100755 new mode 100644 index b6e8990..c7f719f --- a/src/shared/csocket.h +++ b/src/shared/csocket.h @@ -27,8 +27,6 @@ #include #include #include "common.h" -#include -using std::string; class csocket { public: @@ -47,7 +45,7 @@ public: bool connect(const char *sock_path); //Data Transfer - ssize_t send(void const* buffer, size_t size) const; + ssize_t send(const void *buffer, size_t size) const; ssize_t recv(void* buffer, size_t size) const; bool set_connection_mode(void); @@ -66,8 +64,8 @@ private: bool set_blocking_mode(bool blocking); bool set_sock_type(void); - ssize_t send_for_seqpacket(void const* buffer, size_t size) const; - ssize_t send_for_stream(void const* buffer, size_t size) const; + ssize_t send_for_seqpacket(const void *buffer, size_t size) const; + ssize_t send_for_stream(const void *buffer, size_t size) const; ssize_t recv_for_seqpacket(void* buffer, size_t size) const; ssize_t recv_for_stream(void* buffer, size_t size) const; diff --git a/src/shared/cvirtual_sensor_config.h b/src/shared/cvirtual_sensor_config.h index b3c5f7d..a9af957 100755 --- a/src/shared/cvirtual_sensor_config.h +++ b/src/shared/cvirtual_sensor_config.h @@ -24,14 +24,14 @@ #define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml" -typedef unordered_map Element; +typedef std::unordered_map Element; /* * an Element is a group of attributes * * */ -typedef unordered_map Virtual_sensor; +typedef std::unordered_map Virtual_sensor; /* * a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration * @@ -40,7 +40,7 @@ typedef unordered_map Virtual_sensor; * ... */ -typedef unordered_map virtual_sensor_config; +typedef std::unordered_map virtual_sensor_config; /* * a Virtual_sensor_config represents virtual_sensors.xml * @@ -49,7 +49,7 @@ typedef unordered_map virtual_sensor_config; * */ -typedef unordered_map virtual_sensor_device_config; +typedef std::unordered_map virtual_sensor_device_config; /* * a virtual_sensor_device_config represents virtual_sensors.xml * @@ -64,22 +64,22 @@ private: cvirtual_sensor_config(cvirtual_sensor_config const&) {}; cvirtual_sensor_config& operator=(cvirtual_sensor_config const&); - bool load_config(const string& config_path); + bool load_config(const std::string& config_path); virtual_sensor_device_config m_virtual_sensor_config; public: static cvirtual_sensor_config& get_instance(void); - bool get(const string& sensor_type, const string& element, const string& attr, string& value); - bool get(const string& sensor_type, const string& element, const string& attr, float *value); - bool get(const string& sensor_type, const string& element, const string& attr, int *value); + bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, std::string& value); + bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, float *value); + bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, int *value); - bool get(const string& sensor_type, const string& element, string& value); - bool get(const string& sensor_type, const string& element, float *value, int count =1); - bool get(const string& sensor_type, const string& element, int *value, int count = 1); + bool get(const std::string& sensor_type, const std::string& element, std::string& value); + bool get(const std::string& sensor_type, const std::string& element, float *value, int count =1); + bool get(const std::string& sensor_type, const std::string& element, int *value, int count = 1); - bool is_supported(const string &sensor_type); + bool is_supported(const std::string &sensor_type); }; #endif diff --git a/src/shared/iio_common.h b/src/shared/iio_common.h index ecda683..80f1f34 100755 --- a/src/shared/iio_common.h +++ b/src/shared/iio_common.h @@ -25,10 +25,6 @@ #include #include -using std::string; -using std::ifstream; - - #define NO_OF_ULL_BYTES 8 #define NO_OF_SHORT_VAL 4 #define CH0_INDEX 0 @@ -85,9 +81,9 @@ int update_sysfs_string(const char *filepath, const char *val); int convert_bytes_to_int(int input, struct channel_parameters *info); template -bool read_node_value(string node_path, value_t &value) +bool read_node_value(std::string node_path, value_t &value) { - ifstream handle; + std::ifstream handle; handle.open(node_path.c_str()); if (!handle) { diff --git a/src/shared/physical_sensor.cpp b/src/shared/physical_sensor.cpp old mode 100755 new mode 100644 index 4f9ee3c..15d33a0 --- a/src/shared/physical_sensor.cpp +++ b/src/shared/physical_sensor.cpp @@ -31,13 +31,25 @@ physical_sensor::~physical_sensor() } -bool physical_sensor::push(sensor_event_t const &event) +bool physical_sensor::push(const sensor_event_t &event) { csensor_event_queue::get_instance().push(event); return true; } -bool physical_sensor::push(sensorhub_event_t const &event) +bool physical_sensor::push(sensor_event_t *event) +{ + csensor_event_queue::get_instance().push(event); + return true; +} + +bool physical_sensor::push(const sensorhub_event_t &event) +{ + csensor_event_queue::get_instance().push(event); + return true; +} + +bool physical_sensor::push(sensorhub_event_t *event) { csensor_event_queue::get_instance().push(event); return true; diff --git a/src/shared/physical_sensor.h b/src/shared/physical_sensor.h old mode 100755 new mode 100644 index 4118ae3..a4098b6 --- a/src/shared/physical_sensor.h +++ b/src/shared/physical_sensor.h @@ -36,8 +36,10 @@ protected: physical_sensor(); virtual ~physical_sensor(); - bool push(sensor_event_t const &event); - bool push(sensorhub_event_t const &event); + bool push(const sensor_event_t &event); + bool push(sensor_event_t *event); + bool push(const sensorhub_event_t &event); + bool push(sensorhub_event_t *event); void set_poller(working_func_t func, void *arg); bool start_poll(void); diff --git a/src/shared/sensor_base.cpp b/src/shared/sensor_base.cpp index 60c1b2f..056e065 100755 --- a/src/shared/sensor_base.cpp +++ b/src/shared/sensor_base.cpp @@ -20,6 +20,10 @@ #include #include +#include + +using std::make_pair; +using std::vector; #define UNKNOWN_NAME "UNKNOWN_SENSOR" @@ -47,14 +51,30 @@ bool sensor_base::is_virtual() return false; } -void sensor_base::set_id(sensor_id_t id) +void sensor_base::add_id(sensor_id_t id) { - m_id = id; + m_ids.insert(std::make_pair(static_cast (id & SENSOR_TYPE_MASK), id)); } sensor_id_t sensor_base::get_id(void) { - return m_id; + auto it = m_ids.begin(); + + if (it != m_ids.end()) + return it->second; + + return UNKNOWN_SENSOR; +} + +sensor_id_t sensor_base::get_id(sensor_type_t sensor_type) +{ + + auto it = m_ids.find(sensor_type); + + if (it != m_ids.end()) + return it->second; + + return UNKNOWN_SENSOR; } sensor_privilege_t sensor_base::get_privilege(void) @@ -78,12 +98,6 @@ void sensor_base::set_permission(int permission) m_permission = permission; } - -sensor_type_t sensor_base::get_type() -{ - return UNKNOWN_SENSOR; -} - const char* sensor_base::get_name() { if (m_name.empty()) @@ -204,7 +218,7 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro if (cur_min != prev_min) { INFO("Min interval for sensor[0x%x] is changed from %dms to %dms" " by%sclient[%d] adding interval", - get_type(), prev_min, cur_min, + get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); set_interval(cur_min); } @@ -227,14 +241,14 @@ bool sensor_base::delete_interval(int client_id, bool is_processor) if (!cur_min) { INFO("No interval for sensor[0x%x] by%sclient[%d] deleting interval, " "so set to default %dms", - get_type(), is_processor ? " processor " : " ", + get_id(), is_processor ? " processor " : " ", client_id, POLL_1HZ_MS); set_interval(POLL_1HZ_MS); } else if (cur_min != prev_min) { INFO("Min interval for sensor[0x%x] is changed from %dms to %dms" " by%sclient[%d] deleting interval", - get_type(), prev_min, cur_min, + get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); set_interval(cur_min); @@ -250,13 +264,13 @@ unsigned int sensor_base::get_interval(int client_id, bool is_processor) return m_interval_info_list.get_interval(client_id, is_processor); } -void sensor_base::get_sensor_info(sensor_info &info) +void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info) { sensor_properties_s properties; - get_properties(properties); + get_properties(sensor_type, properties); - info.set_type(get_type()); - info.set_id(get_id()); + info.set_type(sensor_type); + info.set_id(get_id(sensor_type)); info.set_privilege(m_privilege); info.set_name(properties.name.c_str()); info.set_vendor(properties.vendor.c_str()); @@ -266,12 +280,20 @@ void sensor_base::get_sensor_info(sensor_info &info) info.set_min_interval(properties.min_interval); info.set_fifo_count(properties.fifo_count); info.set_max_batch_count(properties.max_batch_count); - info.set_supported_events(m_supported_event_info); + + vector events; + + for (unsigned int i = 0; i < m_supported_event_info.size(); ++ i) { + if (m_supported_event_info[i] & (sensor_type << 16)) + events.push_back(m_supported_event_info[i]); + } + + info.set_supported_events(events); return; } -bool sensor_base::get_properties(sensor_properties_s &properties) +bool sensor_base::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return false; } diff --git a/src/shared/sensor_base.h b/src/shared/sensor_base.h index 0206201..353cee2 100755 --- a/src/shared/sensor_base.h +++ b/src/shared/sensor_base.h @@ -21,6 +21,7 @@ #define _SENSOR_BASE_H_ #include +#include #include #include #include @@ -35,29 +36,20 @@ #include #include -using std::string; -using std::mutex; -using std::recursive_mutex; -using std::lock_guard; -using std::list; -using std::unordered_map; -using std::vector; -using std::unique_lock; -using std::condition_variable; - class sensor_base { private: - typedef unordered_map client_info; + typedef std::unordered_map client_info; public: sensor_base(); virtual ~sensor_base(); virtual bool init(void); - void set_id(sensor_id_t id); - sensor_id_t get_id(void); - virtual sensor_type_t get_type(void); + void add_id(sensor_id_t id); + sensor_id_t get_id(sensor_type_t sensor_type); + virtual void get_types(std::vector &types) {}; + sensor_privilege_t get_privilege(void); int get_permission(void); virtual const char* get_name(void); @@ -74,9 +66,9 @@ public: virtual bool delete_interval(int client_id, bool is_processor); unsigned int get_interval(int client_id, bool is_processor); + void get_sensor_info(sensor_type_t sensor_type, sensor_info &info); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - void get_sensor_info(sensor_info &info); - virtual bool get_properties(sensor_properties_s &properties); bool is_supported(unsigned int event_type); virtual long set_command(unsigned int cmd, long value); @@ -87,11 +79,11 @@ public: void register_supported_event(unsigned int event_type); void unregister_supported_event(unsigned int event_type); protected: - typedef lock_guard lock; - typedef lock_guard rlock; - typedef unique_lock ulock; + typedef std::lock_guard lock; + typedef std::lock_guard rlock; + typedef std::unique_lock ulock; - sensor_id_t m_id; + std::map m_ids; sensor_privilege_t m_privilege; int m_permission; @@ -106,12 +98,12 @@ protected: client_info m_client_info; cmutex m_client_info_mutex; - vector m_supported_event_info; - + std::vector m_supported_event_info; bool m_started; - string m_name; + std::string m_name; + sensor_id_t get_id(void); void set_privilege(sensor_privilege_t privilege); void set_permission(int permission); unsigned int get_client_cnt(unsigned int event_type); diff --git a/src/shared/sensor_hal.cpp b/src/shared/sensor_hal.cpp index a0bfd84..f5a315d 100755 --- a/src/shared/sensor_hal.cpp +++ b/src/shared/sensor_hal.cpp @@ -24,7 +24,9 @@ #include using std::ifstream; +using std::ofstream; using std::fstream; +using std::string; cmutex sensor_hal::m_shared_mutex; @@ -200,7 +202,7 @@ bool sensor_hal::get_sensorhub_input_event_node_info(const string &interval_node bool sensor_hal::set_node_value(const string &node_path, int value) { - fstream node(node_path, fstream::out); + ofstream node(node_path, ofstream::binary); if (!node) return false; @@ -212,7 +214,7 @@ bool sensor_hal::set_node_value(const string &node_path, int value) bool sensor_hal::set_node_value(const string &node_path, unsigned long long value) { - fstream node(node_path, fstream::out); + ofstream node(node_path, ofstream::binary); if (!node) return false; @@ -225,7 +227,7 @@ bool sensor_hal::set_node_value(const string &node_path, unsigned long long valu bool sensor_hal::get_node_value(const string &node_path, int &value) { - fstream node(node_path, fstream::in); + ifstream node(node_path, ifstream::binary); if (!node) return false; diff --git a/src/shared/sensor_hal.h b/src/shared/sensor_hal.h index fdb8299..09762a4 100755 --- a/src/shared/sensor_hal.h +++ b/src/shared/sensor_hal.h @@ -26,8 +26,6 @@ #include #include -using std::string; - /* * As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock * Current kernel-headers package doesn't have it so we should define it here. @@ -37,22 +35,47 @@ using std::string; #define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */ #endif +typedef enum { + SENSOR_HAL_TYPE_ACCELEROMETER, + SENSOR_HAL_TYPE_GEOMAGNETIC, + SENSOR_HAL_TYPE_LIGHT, + SENSOR_HAL_TYPE_PROXIMITY, + SENSOR_HAL_TYPE_GYROSCOPE, + SENSOR_HAL_TYPE_PRESSURE, + SENSOR_HAL_TYPE_CONTEXT, + SENSOR_HAL_TYPE_BIO, + SENSOR_HAL_TYPE_BIO_HRM, + SENSOR_HAL_TYPE_PIR, + SENSOR_HAL_TYPE_PIR_LONG, + SENSOR_HAL_TYPE_TEMPERATURE, + SENSOR_HAL_TYPE_HUMIDITY, + SENSOR_HAL_TYPE_ULTRAVIOLET, + SENSOR_HAL_TYPE_DUST, + SENSOR_HAL_TYPE_BIO_LED_IR, + SENSOR_HAL_TYPE_BIO_LED_RED, + SENSOR_HAL_TYPE_BIO_LED_GREEN, + SENSOR_HAL_TYPE_RV_RAW, + SENSOR_HAL_TYPE_GYROSCOPE_UNCAL, + SENSOR_HAL_TYPE_GEOMAGNETIC_UNCAL, + SENSOR_HAL_TYPE_FUSION, +} sensor_hal_type_t; + typedef struct { int method; - string data_node_path; - string enable_node_path; - string interval_node_path; - string buffer_enable_node_path; - string buffer_length_node_path; - string trigger_node_path; + std::string data_node_path; + std::string enable_node_path; + std::string interval_node_path; + std::string buffer_enable_node_path; + std::string buffer_length_node_path; + std::string trigger_node_path; } node_info; typedef struct { bool sensorhub_controlled; - string sensor_type; - string key; - string iio_enable_node_name; - string sensorhub_interval_node_name; + std::string sensor_type; + std::string key; + std::string iio_enable_node_name; + std::string sensorhub_interval_node_name; } node_info_query; enum input_method { @@ -75,13 +98,14 @@ public: virtual ~sensor_hal(); virtual bool init(void *data = NULL); - virtual string get_model_id(void) = 0; - virtual sensor_type_t get_type(void) = 0; + virtual std::string get_model_id(void) = 0; + virtual sensor_hal_type_t get_type(void) = 0; virtual bool enable(void) = 0; virtual bool disable(void) = 0; virtual bool set_interval(unsigned long val); virtual bool is_data_ready(bool wait) = 0; - virtual bool get_properties(sensor_properties_s &properties) = 0; + virtual bool get_properties(sensor_properties_s &properties) {return false;}; + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) {return false;}; virtual int get_sensor_data(sensor_data_t &data); virtual int get_sensor_data(sensorhub_data_t &data); virtual long set_command(unsigned int cmd, long val); @@ -91,24 +115,24 @@ protected: cmutex m_mutex; static cmutex m_shared_mutex; - virtual bool set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0); + virtual bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0); static unsigned long long get_timestamp(void); static unsigned long long get_timestamp(timeval *t); - static bool find_model_id(const string &sensor_type, string &model_id); - static bool is_sensorhub_controlled(const string &key); + static bool find_model_id(const std::string &sensor_type, std::string &model_id); + static bool is_sensorhub_controlled(const std::string &key); static bool get_node_info(const node_info_query &query, node_info &info); static void show_node_info(node_info &info); - static bool set_node_value(const string &node_path, int value); - static bool set_node_value(const string &node_path, unsigned long long value); - static bool get_node_value(const string &node_path, int &value); + static bool set_node_value(const std::string &node_path, int value); + static bool set_node_value(const std::string &node_path, unsigned long long value); + static bool get_node_value(const std::string &node_path, int &value); private: - static bool get_event_num(const string &node_path, string &event_num); - static bool get_input_method(const string &key, int &method, string &device_num); + static bool get_event_num(const std::string &node_path, std::string &event_num); + static bool get_input_method(const std::string &key, int &method, std::string &device_num); - static bool get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info); - static bool get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info); - static bool get_input_event_node_info(const string& device_num, node_info &info); - static bool get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info); + static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info); + static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info); + static bool get_input_event_node_info(const std::string& device_num, node_info &info); + static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info); }; #endif /*_SENSOR_HAL_CLASS_H_*/ diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index fe8303c..bed247e 100755 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -20,6 +20,11 @@ #include #include #include +#include +#include + +using std::vector; +using std::string; sensor_type_t sensor_info::get_type(void) { diff --git a/src/shared/sensor_info.h b/src/shared/sensor_info.h index 6a8a09e..185d249 100755 --- a/src/shared/sensor_info.h +++ b/src/shared/sensor_info.h @@ -25,10 +25,7 @@ #include #include -using std::string; -using std::vector; - -typedef vector raw_data_t; +typedef std::vector raw_data_t; typedef raw_data_t::iterator raw_data_iterator; class sensor_info @@ -45,7 +42,7 @@ public: int get_min_interval(void); int get_fifo_count(void); int get_max_batch_count(void); - void get_supported_events(vector &events); + void get_supported_events(std::vector &events); bool is_supported_event(unsigned int event); void set_type(sensor_type_t type); @@ -60,7 +57,7 @@ public: void set_fifo_count(int fifo_count); void set_max_batch_count(int max_batch_count); void register_supported_event(unsigned int event); - void set_supported_events(vector &events); + void set_supported_events(std::vector &events); void clear(void); @@ -71,25 +68,25 @@ private: sensor_type_t m_type; sensor_id_t m_id; sensor_privilege_t m_privilege; - string m_name; - string m_vendor; + std::string m_name; + std::string m_vendor; float m_min_range; float m_max_range; float m_resolution; int m_min_interval; int m_fifo_count; int m_max_batch_count; - vector m_supported_events; + std::vector m_supported_events; void put(raw_data_t &data, int value); void put(raw_data_t &data, float value); - void put(raw_data_t &data, string &value); - void put(raw_data_t &data, vector &value); + void put(raw_data_t &data, std::string &value); + void put(raw_data_t &data, std::vector &value); raw_data_iterator get(raw_data_iterator it, int &value); raw_data_iterator get(raw_data_iterator it, float &value); - raw_data_iterator get(raw_data_iterator it, string &value); - raw_data_iterator get(raw_data_iterator it, vector &value); + raw_data_iterator get(raw_data_iterator it, std::string &value); + raw_data_iterator get(raw_data_iterator it, std::vector &value); }; #endif /* _SENSOR_INFO_H_ */ diff --git a/src/shared/sensor_plugin_loader.cpp b/src/shared/sensor_plugin_loader.cpp index 17772c9..3b5831c 100755 --- a/src/shared/sensor_plugin_loader.cpp +++ b/src/shared/sensor_plugin_loader.cpp @@ -31,6 +31,11 @@ using std::make_pair; using std::equal; using std::unordered_set; +using std::pair; +using std::vector; +using std::string; +using std::shared_ptr; +using std::static_pointer_cast; #define ROOT_ELEMENT "PLUGIN" #define TEXT_ELEMENT "text" @@ -100,12 +105,12 @@ bool sensor_plugin_loader::insert_module(plugin_type type, const string &path) if (!load_module(path, hals, handle)) return false; - sensor_hal* hal; + shared_ptr hal; for (unsigned int i = 0; i < hals.size(); ++i) { - hal = static_cast (hals[i]); - sensor_type_t sensor_type = hal->get_type(); - m_sensor_hals.insert(make_pair(sensor_type, hal)); + hal.reset(static_cast (hals[i])); + sensor_hal_type_t sensor_hal_type = hal->get_type(); + m_sensor_hals.insert(make_pair(sensor_hal_type, hal)); } } else if (type == PLUGIN_TYPE_SENSOR) { DBG("Insert Sensor plugin [%s]", path.c_str()); @@ -116,25 +121,28 @@ bool sensor_plugin_loader::insert_module(plugin_type type, const string &path) if (!load_module(path, sensors, handle)) return false; - sensor_base* sensor; + shared_ptr sensor; for (unsigned int i = 0; i < sensors.size(); ++i) { - sensor = static_cast (sensors[i]); + sensor.reset(static_cast (sensors[i])); if (!sensor->init()) { ERR("Failed to init [%s] module\n", sensor->get_name()); - delete sensor; continue; } DBG("init [%s] module", sensor->get_name()); - sensor_type_t sensor_type = sensor->get_type(); + vector sensor_types; - int idx; - idx = m_sensors.count(sensor_type); - sensor->set_id(idx << SENSOR_INDEX_SHIFT | sensor_type); - m_sensors.insert(make_pair(sensor_type, sensor)); + sensor->get_types(sensor_types); + + for (unsigned int i = 0; i < sensor_types.size(); ++i) { + int idx; + idx = m_sensors.count(sensor_types[i]); + sensor->add_id(idx << SENSOR_INDEX_SHIFT | sensor_types[i]); + m_sensors.insert(make_pair(sensor_types[i], sensor)); + } } }else { ERR("Not supported type: %d", type); @@ -201,10 +209,10 @@ void sensor_plugin_loader::show_sensor_info(void) auto it = m_sensors.begin(); while (it != m_sensors.end()) { - sensor_base* sensor = it->second; + shared_ptr sensor = it->second; sensor_info info; - sensor->get_sensor_info(info); + sensor->get_sensor_info(it->first, info); INFO("No:%d [%s]\n", ++index, sensor->get_name()); info.show(); it++; @@ -322,24 +330,24 @@ bool sensor_plugin_loader::get_paths_from_config(const string &config_path, vect } -sensor_hal* sensor_plugin_loader::get_sensor_hal(sensor_type_t type) +sensor_hal* sensor_plugin_loader::get_sensor_hal(sensor_hal_type_t type) { auto it_plugins = m_sensor_hals.find(type); if (it_plugins == m_sensor_hals.end()) return NULL; - return it_plugins->second; + return it_plugins->second.get(); } -vector sensor_plugin_loader::get_sensor_hals(sensor_type_t type) +vector sensor_plugin_loader::get_sensor_hals(sensor_hal_type_t type) { vector sensor_hal_list; pair ret; ret = m_sensor_hals.equal_range(type); for (auto it = ret.first; it != ret.second; ++it) - sensor_hal_list.push_back(it->second); + sensor_hal_list.push_back(it->second.get()); return sensor_hal_list; } @@ -351,7 +359,7 @@ sensor_base* sensor_plugin_loader::get_sensor(sensor_type_t type) if (it_plugins == m_sensors.end()) return NULL; - return it_plugins->second; + return it_plugins->second.get(); } vector sensor_plugin_loader::get_sensors(sensor_type_t type) @@ -365,7 +373,7 @@ vector sensor_plugin_loader::get_sensors(sensor_type_t type) ret = m_sensors.equal_range(type); for (auto it = ret.first; it != ret.second; ++it) - sensor_list.push_back(it->second); + sensor_list.push_back(it->second.get()); return sensor_list; } @@ -373,7 +381,6 @@ vector sensor_plugin_loader::get_sensors(sensor_type_t type) sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id) { - const int SENSOR_TYPE_MASK = 0x0000FFFF; vector sensors; sensor_type_t type = (sensor_type_t) (id & SENSOR_TYPE_MASK); @@ -394,7 +401,7 @@ vector sensor_plugin_loader::get_virtual_sensors(void) sensor_base* module; for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) { - module = sensor_it->second; + module = sensor_it->second.get(); if (module && module->is_virtual() == true) { virtual_list.push_back(module); @@ -404,33 +411,3 @@ vector sensor_plugin_loader::get_virtual_sensors(void) return virtual_list; } -bool sensor_plugin_loader::destroy() -{ - sensor_base* sensor; - - for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) { - sensor = sensor_it->second; - - //need to dlclose - //unregister_module(module); - - delete sensor; - } - - sensor_hal* sensor_hal; - - for (auto sensor_hal_it = m_sensor_hals.begin(); sensor_hal_it != m_sensor_hals.end(); ++sensor_hal_it) { - sensor_hal = sensor_hal_it->second; - - // need to dlclose - //unregister_module(module); - - delete sensor_hal; - } - - m_sensors.clear(); - m_sensor_hals.clear(); - - return true; -} - diff --git a/src/shared/sensor_plugin_loader.h b/src/shared/sensor_plugin_loader.h index 6903024..8e71dcb 100755 --- a/src/shared/sensor_plugin_loader.h +++ b/src/shared/sensor_plugin_loader.h @@ -21,6 +21,7 @@ #define _SENSOR_PLUGIN_LOADER_CLASS_H_ #include +#include #include #include @@ -29,19 +30,12 @@ #include #include #include - +#include class sensor_hal; class sensor_base; -using std::pair; -using std::vector; -using std::multimap; -using std::set; -using std::string; -using std::istringstream; - -typedef multimap sensor_hal_plugins; +typedef std::multimap > sensor_hal_plugins; /* * a hal_plugins is a group of hal plugin * @@ -50,7 +44,7 @@ typedef multimap sensor_hal_plugins; * */ -typedef multimap sensor_plugins; +typedef std::multimap > sensor_plugins; /* * a sensor_plugins is a group of sensor plugin * @@ -69,11 +63,11 @@ private: sensor_plugin_loader(); - bool load_module(const string &path, vector &sensors, void* &handle); - bool insert_module(plugin_type type, const string &path); + bool load_module(const std::string &path, std::vector &sensors, void* &handle); + bool insert_module(plugin_type type, const std::string &path); void show_sensor_info(void); - bool get_paths_from_dir(const string &dir_path, vector &hal_paths, vector &sensor_paths); - bool get_paths_from_config(const string &config_path, vector &hal_paths, vector &sensor_paths); + bool get_paths_from_dir(const std::string &dir_path, std::vector &hal_paths, std::vector &sensor_paths); + bool get_paths_from_config(const std::string &config_path, std::vector &hal_paths, std::vector &sensor_paths); sensor_hal_plugins m_sensor_hals; sensor_plugins m_sensors; @@ -82,15 +76,13 @@ public: static sensor_plugin_loader& get_instance(); bool load_plugins(void); - sensor_hal* get_sensor_hal(sensor_type_t type); - vector get_sensor_hals(sensor_type_t type); + sensor_hal* get_sensor_hal(sensor_hal_type_t type); + std::vector get_sensor_hals(sensor_hal_type_t type); sensor_base* get_sensor(sensor_type_t type); - vector get_sensors(sensor_type_t type); + std::vector get_sensors(sensor_type_t type); sensor_base* get_sensor(sensor_id_t id); - vector get_virtual_sensors(void); - - bool destroy(); + std::vector get_virtual_sensors(void); }; #endif /* _SENSOR_PLUGIN_LOADER_CLASS_H_ */ diff --git a/src/shared/sf_common.h b/src/shared/sf_common.h old mode 100755 new mode 100644 index 6481095..777421b --- a/src/shared/sf_common.h +++ b/src/shared/sf_common.h @@ -17,6 +17,8 @@ * */ +#include + #if !defined(_SF_COMMON_H_) #define _SF_COMMON_H_ #include @@ -26,14 +28,16 @@ #include #include -#define COMMAND_CHANNEL_PATH "/tmp/sf_command_socket" -#define EVENT_CHANNEL_PATH "/tmp/sf_event_socket" +#define COMMAND_CHANNEL_PATH "/tmp/sensord_command_socket" +#define EVENT_CHANNEL_PATH "/tmp/sensord_event_socket" -#define MAX_HANDLE 64 +#define MAX_HANDLE 256 #define MAX_HANDLE_REACHED -2 #define CLIENT_ID_INVALID -1 +#define SENSOR_TYPE_MASK 0xFFFF + enum packet_type_t { CMD_NONE = 0, CMD_GET_ID, @@ -46,8 +50,8 @@ enum packet_type_t { CMD_REG, CMD_UNREG, CMD_SET_OPTION, - CMD_SET_INTERVAL, - CMD_UNSET_INTERVAL, + CMD_SET_BATCH, + CMD_UNSET_BATCH, CMD_SET_COMMAND, CMD_GET_DATA, CMD_SEND_SENSORHUB_DATA, @@ -73,7 +77,7 @@ enum poll_interval_t { }; typedef struct { - pid_t pid; + char name[NAME_MAX]; } cmd_get_id_t; typedef struct { @@ -127,10 +131,11 @@ typedef struct { typedef struct { unsigned int interval; -} cmd_set_interval_t; + unsigned int latency; +} cmd_set_batch_t; typedef struct { -} cmd_unset_interval_t; +} cmd_unset_batch_t; typedef struct { int option; diff --git a/src/shared/virtual_sensor.h b/src/shared/virtual_sensor.h index d6414e3..780ba66 100755 --- a/src/shared/virtual_sensor.h +++ b/src/shared/virtual_sensor.h @@ -28,7 +28,7 @@ public: virtual_sensor(); virtual ~virtual_sensor(); - virtual void synthesize(const sensor_event_t &event, vector &outs) = 0; + virtual void synthesize(const sensor_event_t& event, std::vector &outs) = 0; virtual int get_sensor_data(const unsigned int event_type, sensor_data_t &data) = 0; bool is_virtual(void); bool m_hardware_fusion; diff --git a/src/shared/worker_thread.h b/src/shared/worker_thread.h index 67b5f10..6459b3f 100755 --- a/src/shared/worker_thread.h +++ b/src/shared/worker_thread.h @@ -24,11 +24,6 @@ #include #include -using std::mutex; -using std::lock_guard; -using std::unique_lock; -using std::condition_variable; - class worker_thread { public: @@ -50,13 +45,13 @@ private: TRANS_FUNC_CNT, }; - typedef lock_guard lock; - typedef unique_lock ulock; + typedef std::lock_guard lock; + typedef std::unique_lock ulock; worker_state_t m_state; void *m_context; - mutex m_mutex; - condition_variable m_cond_working; + std::mutex m_mutex; + std::condition_variable m_cond_working; bool m_thread_created; trans_func_t m_trans_func[TRANS_FUNC_CNT]; diff --git a/src/temperature/temperature_sensor.cpp b/src/temperature/temperature_sensor.cpp index 20d9955..5b09eb1 100755 --- a/src/temperature/temperature_sensor.cpp +++ b/src/temperature/temperature_sensor.cpp @@ -22,6 +22,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "TEMPERATURE_SENSOR" temperature_sensor::temperature_sensor() @@ -42,7 +45,7 @@ temperature_sensor::~temperature_sensor() bool temperature_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(TEMPERATURE_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_TEMPERATURE); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -63,9 +66,9 @@ bool temperature_sensor::init() return true; } -sensor_type_t temperature_sensor::get_type(void) +void temperature_sensor::get_types(vector &types) { - return TEMPERATURE_SENSOR; + types.push_back(TEMPERATURE_SENSOR); } bool temperature_sensor::working(void *inst) @@ -115,7 +118,7 @@ bool temperature_sensor::on_stop(void) return stop_poll(); } -bool temperature_sensor::get_properties(sensor_properties_s &properties) +bool temperature_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/temperature/temperature_sensor.h b/src/temperature/temperature_sensor.h index 9bb881a..680862d 100755 --- a/src/temperature/temperature_sensor.h +++ b/src/temperature/temperature_sensor.h @@ -31,13 +31,13 @@ public: virtual ~temperature_sensor(); bool init(); - sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); int get_sensor_data(unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_hal *m_sensor_hal; diff --git a/src/temperature/temperature_sensor_hal.cpp b/src/temperature/temperature_sensor_hal.cpp index 64bb254..d8952ff 100755 --- a/src/temperature/temperature_sensor_hal.cpp +++ b/src/temperature/temperature_sensor_hal.cpp @@ -23,6 +23,8 @@ #include #include +using std::string; + #define SENSOR_TYPE_TEMPERATURE "TEMPERATURE" #define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" @@ -115,9 +117,9 @@ string temperature_sensor_hal::get_model_id(void) return m_model_id; } -sensor_type_t temperature_sensor_hal::get_type(void) +sensor_hal_type_t temperature_sensor_hal::get_type(void) { - return TEMPERATURE_SENSOR; + return SENSOR_HAL_TYPE_TEMPERATURE; } bool temperature_sensor_hal::enable(void) diff --git a/src/temperature/temperature_sensor_hal.h b/src/temperature/temperature_sensor_hal.h index 334a74d..1151afc 100755 --- a/src/temperature/temperature_sensor_hal.h +++ b/src/temperature/temperature_sensor_hal.h @@ -21,17 +21,14 @@ #define _TEMPERATURE_SENSOR_HAL_H_ #include -#include - -using std::string; class temperature_sensor_hal : public sensor_hal { public: temperature_sensor_hal(); virtual ~temperature_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -44,15 +41,15 @@ private: unsigned long m_polling_interval; unsigned long long m_fired_time; - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; float m_raw_data_unit; - string m_data_node; - string m_enable_node; - string m_interval_node; + std::string m_data_node; + std::string m_enable_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/tilt/tilt_sensor.cpp b/src/tilt/tilt_sensor.cpp index 58cbb4e..a898dea 100755 --- a/src/tilt/tilt_sensor.cpp +++ b/src/tilt/tilt_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::string; +using std::vector; + #define SENSOR_NAME "TILT_SENSOR" #define SENSOR_TYPE_TILT "TILT" @@ -120,9 +123,9 @@ bool tilt_sensor::init(void) return true; } -sensor_type_t tilt_sensor::get_type(void) +void tilt_sensor::get_types(vector &types) { - return TILT_SENSOR; + types.push_back(TILT_SENSOR); } bool tilt_sensor::on_start(void) @@ -250,7 +253,7 @@ int tilt_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t &d return 0; } -bool tilt_sensor::get_properties(sensor_properties_s &properties) +bool tilt_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { if(m_raw_data_unit == "DEGREES") { properties.min_range = -180; diff --git a/src/tilt/tilt_sensor.h b/src/tilt/tilt_sensor.h index 8ac6c62..a6a4bd5 100755 --- a/src/tilt/tilt_sensor.h +++ b/src/tilt/tilt_sensor.h @@ -30,16 +30,15 @@ public: virtual ~tilt_sensor(); bool init(void); + virtual void get_types(std::vector &types); - void synthesize(const sensor_event_t &event, vector &outs); + void synthesize(const sensor_event_t &event, std::vector &outs); bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); private: sensor_base *m_accel_sensor; sensor_base *m_fusion_sensor; @@ -51,8 +50,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; int m_pitch_rotation_compensation; int m_roll_rotation_compensation; diff --git a/src/ultraviolet/ultraviolet_sensor.cpp b/src/ultraviolet/ultraviolet_sensor.cpp index e393c22..e47dc9d 100755 --- a/src/ultraviolet/ultraviolet_sensor.cpp +++ b/src/ultraviolet/ultraviolet_sensor.cpp @@ -26,6 +26,8 @@ using std::bind1st; using std::mem_fun; +using std::string; +using std::vector; #define SENSOR_NAME "ULTRAVIOLET_SENSOR" @@ -46,7 +48,7 @@ ultraviolet_sensor::~ultraviolet_sensor() bool ultraviolet_sensor::init() { - m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(ULTRAVIOLET_SENSOR); + m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_ULTRAVIOLET); if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); @@ -65,9 +67,9 @@ bool ultraviolet_sensor::init() return true; } -sensor_type_t ultraviolet_sensor::get_type(void) +void ultraviolet_sensor::get_types(vector &types) { - return ULTRAVIOLET_SENSOR; + types.push_back(ULTRAVIOLET_SENSOR); } bool ultraviolet_sensor::working(void *inst) @@ -118,7 +120,7 @@ bool ultraviolet_sensor::on_stop(void) return stop_poll(); } -bool ultraviolet_sensor::get_properties(sensor_properties_s &properties) +bool ultraviolet_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { return m_sensor_hal->get_properties(properties); } diff --git a/src/ultraviolet/ultraviolet_sensor.h b/src/ultraviolet/ultraviolet_sensor.h index 62f7835..3473db5 100755 --- a/src/ultraviolet/ultraviolet_sensor.h +++ b/src/ultraviolet/ultraviolet_sensor.h @@ -31,11 +31,11 @@ public: virtual ~ultraviolet_sensor(); bool init(); - virtual sensor_type_t get_type(void); + virtual void get_types(std::vector &types); static bool working(void *inst); virtual bool set_interval(unsigned long interval); - virtual bool get_properties(sensor_properties_s &properties); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); virtual int get_sensor_data(unsigned int type, sensor_data_t &data); private: sensor_hal *m_sensor_hal; diff --git a/src/ultraviolet/ultraviolet_sensor_hal.cpp b/src/ultraviolet/ultraviolet_sensor_hal.cpp index 634fd9f..ab6f210 100755 --- a/src/ultraviolet/ultraviolet_sensor_hal.cpp +++ b/src/ultraviolet/ultraviolet_sensor_hal.cpp @@ -26,6 +26,7 @@ #include using std::ifstream; +using std::string; #define SENSOR_TYPE_ULTRAVIOLET "ULTRAVIOLET" #define ELEMENT_NAME "NAME" @@ -143,9 +144,9 @@ string ultraviolet_sensor_hal::get_model_id(void) } -sensor_type_t ultraviolet_sensor_hal::get_type(void) +sensor_hal_type_t ultraviolet_sensor_hal::get_type(void) { - return ULTRAVIOLET_SENSOR; + return SENSOR_HAL_TYPE_ULTRAVIOLET; } bool ultraviolet_sensor_hal::enable(void) diff --git a/src/ultraviolet/ultraviolet_sensor_hal.h b/src/ultraviolet/ultraviolet_sensor_hal.h index 1925b7a..5af37ca 100755 --- a/src/ultraviolet/ultraviolet_sensor_hal.h +++ b/src/ultraviolet/ultraviolet_sensor_hal.h @@ -21,17 +21,14 @@ #define _ULTRAVIOLET_SENSOR_HAL_H_ #include -#include - -using std::string; class ultraviolet_sensor_hal : public sensor_hal { public: ultraviolet_sensor_hal(); virtual ~ultraviolet_sensor_hal(); - string get_model_id(void); - sensor_type_t get_type(void); + std::string get_model_id(void); + sensor_hal_type_t get_type(void); bool enable(void); bool disable(void); bool set_interval(unsigned long val); @@ -40,9 +37,9 @@ public: bool get_properties(sensor_properties_s &properties); private: - string m_model_id; - string m_vendor; - string m_chip_name; + std::string m_model_id; + std::string m_vendor; + std::string m_chip_name; float m_min_range; float m_max_range; @@ -55,9 +52,9 @@ private: unsigned long long m_fired_time; int m_node_handle; - string m_enable_node; - string m_data_node; - string m_interval_node; + std::string m_enable_node; + std::string m_data_node; + std::string m_interval_node; bool m_sensorhub_controlled; diff --git a/src/uncal_gyro/uncal_gyro_sensor.cpp b/src/uncal_gyro/uncal_gyro_sensor.cpp old mode 100644 new mode 100755 index d152be7..831b6fe --- a/src/uncal_gyro/uncal_gyro_sensor.cpp +++ b/src/uncal_gyro/uncal_gyro_sensor.cpp @@ -32,6 +32,9 @@ #include #include +using std::vector; +using std::string; + #define SENSOR_NAME "UNCAL_GYROSCOPE_SENSOR" #define SENSOR_TYPE_UNCAL_GYRO "UNCAL_GYROSCOPE" @@ -62,7 +65,7 @@ uncal_gyro_sensor::uncal_gyro_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); - sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION); if (!fusion_sensor_hal) m_hardware_fusion = false; else @@ -119,9 +122,9 @@ bool uncal_gyro_sensor::init(void) return true; } -sensor_type_t uncal_gyro_sensor::get_type(void) +void uncal_gyro_sensor::get_types(vector &types) { - return UNCAL_GYROSCOPE_SENSOR; + types.push_back(UNCAL_GYROSCOPE_SENSOR); } bool uncal_gyro_sensor::on_start(void) @@ -287,7 +290,7 @@ int uncal_gyro_sensor::get_sensor_data(const unsigned int event_type, sensor_dat return 0; } -bool uncal_gyro_sensor::get_properties(sensor_properties_s &properties) +bool uncal_gyro_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) { properties.resolution = 0.000001; properties.vendor = m_vendor; diff --git a/src/uncal_gyro/uncal_gyro_sensor.h b/src/uncal_gyro/uncal_gyro_sensor.h old mode 100644 new mode 100755 index dccb6f0..f4c6b8c --- a/src/uncal_gyro/uncal_gyro_sensor.h +++ b/src/uncal_gyro/uncal_gyro_sensor.h @@ -35,8 +35,8 @@ public: bool add_interval(int client_id, unsigned int interval); bool delete_interval(int client_id); - bool get_properties(sensor_properties_s &properties); - sensor_type_t get_type(void); + virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); + virtual void get_types(std::vector &types); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); @@ -56,8 +56,8 @@ private: unsigned long long m_time; unsigned int m_interval; - string m_vendor; - string m_raw_data_unit; + std::string m_vendor; + std::string m_raw_data_unit; int m_default_sampling_time; float m_gyro_static_bias[3]; int m_gyro_rotation_direction_compensation[3]; diff --git a/systemd/sensord.socket b/systemd/sensord.socket old mode 100644 new mode 100755 index 5357ca5..b8bd460 --- a/systemd/sensord.socket +++ b/systemd/sensord.socket @@ -2,7 +2,7 @@ Description=Sensor daemon socket [Socket] -ListenStream=/tmp/sf_command_socket +ListenStream=/tmp/sensord_command_socket SocketMode=0777 PassCredentials=yes Accept=false diff --git a/test/src/api-test.c b/test/src/api-test.c old mode 100644 new mode 100755 index fb772c6..6ab4dd0 --- a/test/src/api-test.c +++ b/test/src/api-test.c @@ -121,6 +121,7 @@ bool check_sensor_api(unsigned int event_type, int cond_value) sensor_t *output_list; result_boolean = sensord_get_sensor_list(sensor_type, &output_list, &output); if (!result_boolean) { + free(output2); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_sensor_list\n", sensor_type, event_type); return false; } @@ -128,6 +129,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) result = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL); if (result < 0) { + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type); return false; } @@ -137,6 +140,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) if (!result_boolean) { sensord_unregister_event(handle, event_type); sensord_disconnect(handle); + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_start\n", sensor_type, event_type); return false; } @@ -146,6 +151,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) if (!result_boolean) { sensord_unregister_event(handle, event_type); sensord_disconnect(handle); + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_data\n", sensor_type, event_type); return false; } @@ -155,12 +162,16 @@ bool check_sensor_api(unsigned int event_type, int cond_value) result_boolean = sensord_change_event_interval(handle, event_type, 101); if (!result_boolean) { + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_event_interval\n", sensor_type, event_type); return false; } result_boolean = sensord_set_option(handle, SENSOR_OPTION_ON_IN_SCREEN_OFF); if (!result_boolean){ + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_sensor_option\n", sensor_type, event_type); return false; } @@ -168,6 +179,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) result_boolean = sensord_unregister_event(handle, event_type); if (!result_boolean) { + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_unregister_event\n", sensor_type, event_type); return false; } @@ -175,6 +188,8 @@ bool check_sensor_api(unsigned int event_type, int cond_value) result_boolean = sensord_stop(handle); if (!result_boolean) { + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_stop\n", sensor_type, event_type); return false; } @@ -182,10 +197,15 @@ bool check_sensor_api(unsigned int event_type, int cond_value) result_boolean = sensord_disconnect(handle); if (!result_boolean) { + free(output2); + free(output_list); fprintf(fp, "Sensor - %d, event - %d, failed at sensord_disconnect\n", sensor_type, event_type); return false; } + free(output2); + free(output_list); + return true; } diff --git a/test/src/check-sensor.c b/test/src/check-sensor.c old mode 100644 new mode 100755 index 5fcff08..b231650 --- a/test/src/check-sensor.c +++ b/test/src/check-sensor.c @@ -168,6 +168,8 @@ int get_event(sensor_type_t sensor_type, char str[]) return UNCAL_GYRO_RAW_DATA_EVENT; break; + default: + return -1; } return -1; } diff --git a/test/src/fusion-data-collection.c b/test/src/fusion-data-collection.c old mode 100644 new mode 100755 index 8c4c771..86e9a0f --- a/test/src/fusion-data-collection.c +++ b/test/src/fusion-data-collection.c @@ -81,7 +81,7 @@ int main(int argc, char **argv) int i; int handle[MAXSIZE]; - int result[MAXSIZE], start_handle[MAXSIZE], stop_handle[MAXSIZE]; + int result[MAXSIZE], start_handle[MAXSIZE]; unsigned int event[MAXSIZE]; int sensors[MAXSIZE]; diff --git a/test/src/multi-process-performance-test.c b/test/src/multi-process-performance-test.c old mode 100644 new mode 100755 index 82fc74f..20d8ea2 --- a/test/src/multi-process-performance-test.c +++ b/test/src/multi-process-performance-test.c @@ -107,7 +107,8 @@ int main(int argc, char** argv) for (j = 0; j < MAX; j++) { char command[100]; sprintf(command, "kill %d", pids[j]); - system(command); + if (system(command) == -1) + return -1; } } diff --git a/test/src/sensor-test.c b/test/src/sensor-test.c old mode 100644 new mode 100755 index d9ddcff..281d8ac --- a/test/src/sensor-test.c +++ b/test/src/sensor-test.c @@ -150,6 +150,7 @@ int main(int argc, char **argv) } else { usage(); + return -1; } interval = DEFAULT_EVENT_INTERVAL; -- 2.7.4