From b026f61b5a21f776be5e561f548c760a455929a1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 3 Nov 2016 17:48:16 +0900 Subject: [PATCH 01/16] sensord: fix the bug that handles are pushed to a list regardless of return value Change-Id: Ibf13b5262ae66274b758b065822c634959f5bbbb Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 89d678b..f606d29 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -105,8 +105,8 @@ bool sensor_loader::load(void) for_each(unique_device_hal_paths.begin(), unique_device_hal_paths.end(), [&](const string &path) { void *handle; - load_sensor_devices(path, handle); - m_handles.push_back(handle); + if (load_sensor_devices(path, handle)) + m_handles.push_back(handle); } ); -- 2.7.4 From b596e1f1297a7fe6d3e14c43ac81e827fa84c5fd Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 9 Nov 2016 17:41:46 +0900 Subject: [PATCH 02/16] sensord: change log level from error to warning for the warning case - when applications access not-supported sensors, it doesn't need to print error level logs. Change-Id: I1d98d0ebd85bf3d12a673e320a39d2942d53cc9a Signed-off-by: kibak.yoon --- src/client/client.cpp | 6 +-- src/client/command_channel.cpp | 2 +- src/client/sensor_client_info.cpp | 46 +++++++++++------------ src/sensor/auto_rotation/auto_rotation_sensor.cpp | 2 +- src/sensor/gesture/face_down_sensor.cpp | 2 +- src/sensor/gravity/gravity_sensor.cpp | 4 +- src/sensor/linear_accel/linear_accel_sensor.cpp | 4 +- src/sensor/orientation/orientation_sensor.cpp | 2 +- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 2 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 2 +- src/sensor/rotation_vector/rv_sensor.cpp | 2 +- src/sensor/tilt/tilt_sensor.cpp | 12 +++--- src/server/command_worker.cpp | 8 +++- src/server/sensor_loader.cpp | 2 +- src/server/server.cpp | 5 ++- src/server/worker_thread.cpp | 2 +- src/shared/csocket.cpp | 38 +++++-------------- 17 files changed, 65 insertions(+), 76 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 0f69a1d..7d22d9f 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -612,9 +612,7 @@ API int sensord_connect(sensor_t sensor) bool first_connection = false; sensor_info* info = sensor_to_sensor_info(sensor); - - retvm_if(!sensor_info_manager::get_instance().is_valid(info), - OP_ERROR, "Invalid param: sensor (%p)", sensor); + retv_if(!sensor_info_manager::get_instance().is_valid(info), OP_ERROR); sensor_id_t sensor_id = info->get_id(); @@ -783,7 +781,7 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int AUTOLOCK(lock); if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) { - _E("client %s failed to get handle information", get_client_name()); + _W("client %s failed to get handle information", get_client_name()); return false; } diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index 319c960..683c017 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -212,7 +212,7 @@ bool command_channel::cmd_hello(sensor_id_t sensor) } if (cmd_done->value < 0) { - _E("client %s got error[%d] from server with sensor [%s]", + _W("client %s got value[%d] from server with sensor [%s]", get_client_name(), cmd_done->value, get_sensor_name(sensor)); delete[] (char *)cmd_done; diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index d027d8a..743cd29 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -53,7 +53,7 @@ int sensor_client_info::create_handle(sensor_id_t sensor) handle++; if (handle == MAX_HANDLE) { - _E("Handles of client %s are full", get_client_name()); + _W("Handles of client %s are full", get_client_name()); return MAX_HANDLE_REACHED; } @@ -77,7 +77,7 @@ bool sensor_client_info::delete_handle(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -100,7 +100,7 @@ bool sensor_client_info::register_event(int handle, unsigned int event_type, auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -117,7 +117,7 @@ bool sensor_client_info::unregister_event(int handle, unsigned int event_type) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -134,7 +134,7 @@ bool sensor_client_info::register_accuracy_cb(int handle, sensor_accuracy_change auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -152,7 +152,7 @@ bool sensor_client_info::unregister_accuracy_cb(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -170,7 +170,7 @@ bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int pau auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -187,7 +187,7 @@ bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &p auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -204,7 +204,7 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -220,7 +220,7 @@ bool sensor_client_info::get_passive_mode(int handle) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -234,7 +234,7 @@ bool sensor_client_info::set_passive_mode(int handle, bool passive) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -250,7 +250,7 @@ bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -266,7 +266,7 @@ bool sensor_client_info::set_event_batch(int handle, unsigned int event_type, un auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -283,7 +283,7 @@ bool sensor_client_info::set_accuracy(int handle, int accuracy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -299,7 +299,7 @@ bool sensor_client_info::set_bad_accuracy(int handle, int bad_accuracy) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -315,7 +315,7 @@ bool sensor_client_info::get_event_info(int handle, unsigned int event_type, uns auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -367,7 +367,7 @@ bool sensor_client_info::add_command_channel(sensor_id_t sensor, command_channel auto it_channel = m_command_channels.find(sensor); if (it_channel != m_command_channels.end()) { - _E("%s alreay has command_channel for %s", get_client_name(), get_sensor_name(sensor)); + _W("%s alreay has command_channel for %s", get_client_name(), get_sensor_name(sensor)); return false; } @@ -381,7 +381,7 @@ bool sensor_client_info::get_command_channel(sensor_id_t sensor, command_channel auto it_channel = m_command_channels.find(sensor); if (it_channel == m_command_channels.end()) { - _E("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor)); + _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor)); return false; } @@ -409,7 +409,7 @@ bool sensor_client_info::close_command_channel(sensor_id_t sensor_id) auto it_channel = m_command_channels.find(sensor_id); if (it_channel == m_command_channels.end()) { - _E("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor_id)); + _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor_id)); return false; } @@ -501,7 +501,7 @@ bool sensor_client_info::get_sensor_id(int handle, sensor_id_t &sensor) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -517,7 +517,7 @@ bool sensor_client_info::get_sensor_state(int handle, int &sensor_state) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -673,7 +673,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, int value) auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } @@ -689,7 +689,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, const char *va auto it_handle = m_sensor_handle_infos.find(handle); if (it_handle == m_sensor_handle_infos.end()) { - _E("Handle[%d] is not found for client %s", handle, get_client_name()); + _W("Handle[%d] is not found for client %s", handle, get_client_name()); return false; } diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 470d5d8..c3bd18e 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -59,7 +59,7 @@ bool auto_rotation_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accel sensor_hal from %s", get_name()); + _W("cannot load accel sensor_hal from %s", get_name()); return false; } diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp index 9aca0f4..03ddf7c 100644 --- a/src/sensor/gesture/face_down_sensor.cpp +++ b/src/sensor/gesture/face_down_sensor.cpp @@ -57,7 +57,7 @@ bool face_down_sensor::init(void) m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); if (!m_gravity_sensor) { - _E("cannot load gravity sensor sensor[%s]", SENSOR_NAME); + _W("cannot load gravity sensor sensor[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index 931940a..d4c74ce 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -77,7 +77,7 @@ bool gravity_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accelerometer sensor_hal[%s]", get_name()); + _W("cannot load accelerometer sensor_hal[%s]", get_name()); return false; } @@ -150,7 +150,7 @@ void gravity_sensor::synthesize_rv(const sensor_event_t& event) int accuracy; if (!m_fusion->get_rotation_vector(x, y, z, w, heading_accuracy, accuracy)) { - _E("Failed to get rotation vector"); + _W("Failed to get rotation vector"); return; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index f5ad037..56af7b6 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -63,14 +63,14 @@ bool linear_accel_sensor::init(void) m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); if (!m_accel_sensor) { - _E("cannot load accelerometer sensor_hal[%s]", get_name()); + _W("cannot load accelerometer sensor_hal[%s]", get_name()); return false; } m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); if (!m_gravity_sensor) { - _E("cannot load gravity sensor_hal[%s]", get_name()); + _W("cannot load gravity sensor_hal[%s]", get_name()); return false; } diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index 8f4bd79..c9cad8b 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -57,7 +57,7 @@ bool orientation_sensor::init(void) m_rotation_vector_sensor = sensor_loader::get_instance().get_sensor(ROTATION_VECTOR_SENSOR); if (!m_rotation_vector_sensor) { - _E("cannot load sensor[%s]", SENSOR_NAME); + _W("cannot load sensor[%s]", SENSOR_NAME); return false; } _I("%s is created!", SENSOR_NAME); diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 1af3da1..7c7c9b3 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -60,7 +60,7 @@ bool gyro_rv_sensor::init(void) m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); if (!m_accel_sensor || !m_gyro_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 6700230..61001c1 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -60,7 +60,7 @@ bool magnetic_rv_sensor::init(void) m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); if (!m_accel_sensor || !m_mag_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 0e9db8e..9fb42c7 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -63,7 +63,7 @@ bool rv_sensor::init(void) m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); if (!m_accel_sensor || !m_gyro_sensor|| !m_mag_sensor) { - _E("cannot load sensors[%s]", SENSOR_NAME); + _W("cannot load sensors[%s]", SENSOR_NAME); return false; } diff --git a/src/sensor/tilt/tilt_sensor.cpp b/src/sensor/tilt/tilt_sensor.cpp index b60f337..6691978 100644 --- a/src/sensor/tilt/tilt_sensor.cpp +++ b/src/sensor/tilt/tilt_sensor.cpp @@ -61,35 +61,35 @@ tilt_sensor::tilt_sensor() register_supported_event(TILT_RAW_DATA_EVENT); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_VENDOR, m_vendor)) { - _E("[VENDOR] is empty\n"); + _W("[VENDOR] is empty\n"); throw ENXIO; } _I("m_vendor = %s", m_vendor.c_str()); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { - _E("[RAW_DATA_UNIT] is empty\n"); + _W("[RAW_DATA_UNIT] is empty\n"); throw ENXIO; } _I("m_raw_data_unit = %s", m_raw_data_unit.c_str()); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { - _E("[DEFAULT_SAMPLING_TIME] is empty\n"); + _W("[DEFAULT_SAMPLING_TIME] is empty\n"); throw ENXIO; } _I("m_default_sampling_time = %d", m_default_sampling_time); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_PITCH_ROTATION_COMPENSATION, &m_pitch_rotation_compensation)) { - _E("[PITCH_ROTATION_COMPENSATION] is empty\n"); + _W("[PITCH_ROTATION_COMPENSATION] is empty\n"); throw ENXIO; } _I("m_pitch_rotation_compensation = %d", m_pitch_rotation_compensation); if (!config.get(SENSOR_TYPE_TILT, ELEMENT_ROLL_ROTATION_COMPENSATION, &m_roll_rotation_compensation)) { - _E("[ROLL_ROTATION_COMPENSATION] is empty\n"); + _W("[ROLL_ROTATION_COMPENSATION] is empty\n"); throw ENXIO; } @@ -109,7 +109,7 @@ bool tilt_sensor::init(void) m_fusion_sensor = sensor_loader::get_instance().get_sensor(FUSION_SENSOR); if (!m_accel_sensor || !m_fusion_sensor) { - _E("Failed to load sensors, accel: %#x, fusion: %#x", + _W("Failed to load sensors, accel: %#x, fusion: %#x", m_accel_sensor, m_fusion_sensor); return false; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index d978481..8d57968 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -336,6 +336,12 @@ bool command_worker::send_cmd_get_sensor_list_done(void) return false; } + /* + * TODO: get_sensor_list() command is processed on one-time connection in the current architecture. + * but it doesn't need to use one-time connection. + */ + m_socket.close(); + return true; } @@ -397,7 +403,7 @@ bool command_worker::cmd_hello(void *payload) m_module = (sensor_base *)sensor_loader::get_instance().get_sensor(cmd->sensor); if (!m_module) { - _E("Sensor type[%d] is not supported", cmd->sensor); + _W("Sensor type[%d] is not supported", cmd->sensor); if (!get_client_info_manager().has_sensor_record(m_client_id)) get_client_info_manager().remove_client_record(m_client_id); diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index f606d29..c25d07a 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -251,7 +251,7 @@ void sensor_loader::create_virtual_sensors(const char *name) } if (!instance->init()) { - _E("Failed to init %s", name); + _W("Failed to init %s", name); delete instance; return; } diff --git a/src/server/server.cpp b/src/server/server.cpp index 14e24fe..3e30174 100755 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -342,7 +342,8 @@ void server::run(void) void server::stop(void) { - _I("Sensord server stopped"); + if (!m_running) + return; m_running = false; @@ -351,6 +352,8 @@ void server::stop(void) g_main_loop_unref(m_mainloop); m_mainloop = NULL; } + + _I("Sensord server stopped"); } server& server::get_instance(void) diff --git a/src/server/worker_thread.cpp b/src/server/worker_thread.cpp index 9f88a24..9108016 100644 --- a/src/server/worker_thread.cpp +++ b/src/server/worker_thread.cpp @@ -41,7 +41,7 @@ bool worker_thread::transition_function(trans_func_index index) { if (m_trans_func[index] != NULL) { if (!m_trans_func[index](m_context)) { - _E("Transition[%d] function returning false", index); + _W("Transition[%d] function returning false", index); return false; } } diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 3b55107..46033ea 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -83,10 +83,8 @@ bool csocket::bind(const char *sock_path) int length; mode_t socket_mode; - if (!is_valid()) { - _E("%s's socket is invalid", get_client_name()); + if (!is_valid()) return false; - } if (!access(sock_path, F_OK)) { unlink(sock_path); @@ -116,10 +114,8 @@ bool csocket::bind(const char *sock_path) bool csocket::listen(const int max_connections) { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (::listen(m_sock_fd, max_connections) < 0) { _ERRNO(errno, _E, "Failed to listen for socket[%d]", m_sock_fd); @@ -309,10 +305,8 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t csocket::send(const void *buffer, size_t size) const { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return -EINVAL; - } if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); @@ -322,10 +316,8 @@ ssize_t csocket::send(const void *buffer, size_t size) const ssize_t csocket::recv(void* buffer, size_t size) const { - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return -EINVAL; - } if (m_sock_type == SOCK_STREAM) return recv_for_stream(buffer, size); @@ -341,10 +333,8 @@ bool csocket::connect(const char *sock_path) int addr_len; bool prev_blocking_mode; - if (!is_valid()) { - _E("%s's socket is invalid", get_client_name()); + if (!is_valid()) return false; - } prev_blocking_mode = is_blocking_mode(); @@ -413,10 +403,8 @@ bool csocket::set_blocking_mode(bool blocking) { int flags; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } flags = fcntl(m_sock_fd, F_GETFL); @@ -444,10 +432,8 @@ bool csocket::set_sock_type(void) opt_len = sizeof(sock_type); - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (getsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &sock_type, &opt_len) < 0) { _ERRNO(errno, _E, "getsockopt(SOL_SOCKET, SO_TYPE) failed for %s, m_sock_fd: %d", @@ -469,10 +455,8 @@ bool csocket::set_connection_mode(void) tv.tv_sec = TIMEOUT; tv.tv_usec = 0; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { _ERRNO(errno, _E, "Set SO_RCVTIMEO failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd); @@ -500,10 +484,8 @@ bool csocket::is_blocking_mode(void) { int flags; - if (!is_valid()) { - _E("Socket(%d) is invalid", m_sock_fd); + if (!is_valid()) return false; - } flags = fcntl(m_sock_fd, F_GETFL); @@ -529,7 +511,7 @@ bool csocket::close(void) { if (m_sock_fd >= 0) { if (::close(m_sock_fd) < 0) { - _ERRNO(errno, _E, "Failed to close socket[%d]", m_sock_fd); + _ERRNO(errno, _W, "Failed to close socket[%d]", m_sock_fd); return false; } m_sock_fd = -1; -- 2.7.4 From ecdee543f108afb9755df378fa188b5bc9db1818 Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Mon, 12 Sep 2016 21:54:55 +0900 Subject: [PATCH 03/16] sensord: create file for macros Change-Id: I44a8199875c059ac11e772afe1e6b47c5a0a8b65 Signed-off-by: minsoo kim --- src/shared/macro.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 src/shared/macro.h diff --git a/src/shared/macro.h b/src/shared/macro.h new file mode 100755 index 0000000..7a5f036 --- /dev/null +++ b/src/shared/macro.h @@ -0,0 +1,48 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once + +#include +#include +#include + +#define _cleanup_(x) __attribute__((cleanup(x))) + +static inline void __freep(void *p) +{ + free(*(void**) p); +} + +static inline void __closep(int *fd) +{ + if (*fd >= 0) + close(*fd); +} + +static inline void __fclosep(FILE **f) +{ + if (*f) + fclose(*f); +} + +#define _cleanup_free_ _cleanup_(__freep) +#define _cleanup_close_ _cleanup_(__closep) +#define _cleanup_fclose_ _cleanup_(__fclosep) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -- 2.7.4 From 66e67ca071a6b328503340bbef97cc018c191b9b Mon Sep 17 00:00:00 2001 From: "hs81.go" Date: Tue, 4 Oct 2016 10:46:41 +0900 Subject: [PATCH 04/16] sensord: remove an useless event suffix name Change-Id: Ia16741513429196bdbb1063e9a7dcdce62f8a41b Signed-off-by: hs81.go --- src/client/client_common.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index ec17a1f..a0a7345 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -42,9 +42,8 @@ const char* get_sensor_name(sensor_id_t id) const char* get_event_name(unsigned int event_type) { sensor_type_t type = (sensor_type_t) (event_type >> SENSOR_EVENT_SHIFT); - std::string name(util_sensor_type_t::get_string(type)); - return name.append("_EVENT").c_str(); + return util_sensor_type_t::get_string(type); } unsigned int get_calibration_event_type(unsigned int event_type) -- 2.7.4 From dc6c4ea719820bae22a51f1df5f9d217c29a4f51 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 18:21:34 +0900 Subject: [PATCH 05/16] sensord: add attributes and types to hal_types.h Change-Id: I0e9be365468a59ea948f6cdea1356fe46ae75979 Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index 6c30f47..6beb935 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -108,6 +108,9 @@ typedef enum { SENSOR_DEVICE_WORKOUT, SENSOR_DEVICE_CYCLE_MONITOR, SENSOR_DEVICE_STAIR_TRACKER, + SENSOR_DEVICE_PRESSURE_INDICATOR, + SENSOR_DEVICE_PRESSURE_ALERT, + SENSOR_DEVICE_HR_CALORIE, SENSOR_DEVICE_CONTEXT = 0x7000, SENSOR_DEVICE_MOTION, @@ -221,6 +224,66 @@ typedef struct { enum sensor_attribute { SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), + + SENSOR_ATTR_PEDOMETER_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1), + SENSOR_ATTR_PEDOMETER_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2), + SENSOR_ATTR_PEDOMETER_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3), + + SENSOR_ATTR_STRESS_MONITOR_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), + + SENSOR_ATTR_EXERCISE_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x1), + SENSOR_ATTR_EXERCISE_GPS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x2), + SENSOR_ATTR_EXERCISE_BATCH_INTERVAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x3), + SENSOR_ATTR_EXERCISE_PSERVICE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x4), + + SENSOR_ATTR_CYCLE_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1), + SENSOR_ATTR_CYCLE_HOLDING_POSITION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2), + SENSOR_ATTR_CYCLE_VELOCITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3), + + SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1), + SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2), + + SENSOR_ATTR_RESTING_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x1), + SENSOR_ATTR_RESTING_HR_MAX_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x2), + SENSOR_ATTR_RESTING_HR_MIN_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x3), + SENSOR_ATTR_RESTING_HR_AVG_RHR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x4), + SENSOR_ATTR_RESTING_HR_HOUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x5), + SENSOR_ATTR_RESTING_HR_MIN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x6), + SENSOR_ATTR_RESTING_HR_SEC = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x7), + SENSOR_ATTR_RESTING_HR_PROPERTY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x10), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x11), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x12), + SENSOR_ATTR_RESTING_HR_PROPERTY_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x13), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x14), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x15), + SENSOR_ATTR_RESTING_HR_PROPERTY_CONT_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x16), + SENSOR_ATTR_RESTING_HR_DATA_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20), + SENSOR_ATTR_RESTING_HR_DATA_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21), + + SENSOR_ATTR_EXERCISE_HR_OPR_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1), + SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2), + SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3), + SENSOR_ATTR_EXERCISE_HR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4), + + SENSOR_ATTR_PRESSURE_INDICATOR_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1), + SENSOR_ATTR_PRESSURE_INDICATOR_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2), + SENSOR_ATTR_PRESSURE_INDICATOR_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x3), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x4), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x5), + SENSOR_ATTR_PRESSURE_INDICATOR_CURRENT_TIME = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x6), + + SENSOR_ATTR_PRESSURE_ALERT_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x1), + SENSOR_ATTR_PRESSURE_ALERT_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x2), + + SENSOR_ATTR_HR_CALORIE_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x1), + SENSOR_ATTR_HR_CALORIE_HEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x2), + SENSOR_ATTR_HR_CALORIE_WEIGHT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x3), + SENSOR_ATTR_HR_CALORIE_GENDER = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x4), + SENSOR_ATTR_HR_CALORIE_INST = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x10), + SENSOR_ATTR_HR_CALORIE_EXERCISE_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x11), + SENSOR_ATTR_HR_CALORIE_TARGET_CAL = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12), + SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13), + SENSOR_ATTR_HR_CALORIE_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20), }; enum sensor_activity { -- 2.7.4 From 7b82ada72d9325ba5192621a9366d915668793b8 Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Thu, 6 Oct 2016 16:09:30 +0900 Subject: [PATCH 06/16] sensord: add get wristup dbus interface SENSORD_BUS_NAME : "org.tizen.system.sensord" SENSORD_OBJECT_PATH : "/Org/Tizen/System/SensorD" SENSORD_INTERFACE_NAME : SENSORD_BUS_NAME WRISTUP_ALGO_METHOD : "wristup_algo" Change-Id: Ic7992b874b2456da2ede823de6bb7ffeb579f1a0 Signed-off-by: minsoo kim --- src/server/dbus_util.cpp | 12 ++++++++++++ src/server/dbus_util.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp index c29b61d..0aa0b90 100755 --- a/src/server/dbus_util.cpp +++ b/src/server/dbus_util.cpp @@ -23,6 +23,7 @@ static int wrist_up_total_cnt; static int wrist_up_lcdon_cnt; +static int wrist_up_algo; static GDBusNodeInfo *introspection_data = NULL; static guint owner_id; @@ -39,6 +40,9 @@ static const gchar introspection_xml[] = " " " " " " +" " +" " +" " " " ""; @@ -59,6 +63,9 @@ static void method_call_handler(GDBusConnection *conn, } else if (g_strcmp0(method_name, "wristup_total_cnt") == 0) { _D("wristup_total_cnt called, %d", wrist_up_total_cnt); ret = wrist_up_total_cnt; + } else if (g_strcmp0(method_name, "wristup_algo") == 0) { + _D("wristup_algo called, %d", wrist_up_algo); + ret = wrist_up_algo; } else { _D("No matched method call"); ret = DBUS_FAILED; @@ -141,6 +148,11 @@ void reset_total_count(void) wrist_up_total_cnt = 0; } +void set_wrist_up_algo(int mode) +{ + wrist_up_algo = mode; +} + void init_dbus(void) { #ifndef GLIB_VERSION_2_36 diff --git a/src/server/dbus_util.h b/src/server/dbus_util.h index ce4ad54..f729e3b 100644 --- a/src/server/dbus_util.h +++ b/src/server/dbus_util.h @@ -37,6 +37,7 @@ void reset_lcdon_count(void); int get_total_count(void); void increase_total_count(void); void reset_total_count(void); +void set_wrist_up_algo(int mode); void init_dbus(void); void fini_dbus(void); -- 2.7.4 From 0145bede6b0f34857422de4297038b905f64ecea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 28 Oct 2016 00:26:34 +0900 Subject: [PATCH 07/16] sensord: change socket type from stream to seqpacket Change-Id: I3ecc7f26e9917b29dfeaf4a9164012bf3df2c8f2 Signed-off-by: kibak.yoon --- src/client/sensor_event_listener.cpp | 15 +++++++++++++-- src/shared/csocket.cpp | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index dc40271..fd11d4f 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -240,13 +240,13 @@ ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, s len = m_event_socket.recv(buffer, buffer_len); if (!len) { - _I("%s failed to read after poll!", get_client_name()); + _E("%s failed to read after poll!", get_client_name()); return -1; } } if (len < 0) { - _I("%s failed to recv event from event socket", get_client_name()); + _E("%s failed to recv event from event socket", get_client_name()); return -1; } @@ -277,6 +277,10 @@ void sensor_event_listener::listen_events(void) sensor_event_t *sensor_event = reinterpret_cast(buffer); data_len = sensor_event->data_length; + + if (data_len == 0) + continue; + buffer_data = malloc(data_len); len = sensor_event_poll(buffer_data, data_len, event); @@ -291,6 +295,13 @@ void sensor_event_listener::listen_events(void) handle_events((void *)buffer); } while (true); + if (m_poller) { + delete m_poller; + m_poller = NULL; + } + + close_event_channel(); + { /* the scope for the lock */ lock l(m_thread_mutex); m_thread_state = THREAD_STATE_TERMINATE; diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 46033ea..25a7076 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -25,7 +25,7 @@ csocket::csocket() : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { @@ -34,7 +34,7 @@ csocket::csocket() csocket::csocket(int sock_fd) : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { @@ -45,7 +45,7 @@ csocket::csocket(int sock_fd) csocket::csocket(const csocket &sock) : m_sock_fd(-1) -, m_sock_type(SOCK_STREAM) +, m_sock_type(SOCK_SEQPACKET) , m_send_flags(MSG_NOSIGNAL) , m_recv_flags(MSG_NOSIGNAL) { -- 2.7.4 From d75157fd9acfe3000acdf6c036c2e2b559a3d14c Mon Sep 17 00:00:00 2001 From: minsoo kim Date: Mon, 7 Nov 2016 20:04:12 +0900 Subject: [PATCH 08/16] sensord: set socket_type when connection of client is accepted Currently, stream socket is used for command and sequence packet socket is used for sensor event. but when server accepts any connection of client server creates socket object with default socket type. so client socket which is accepted by server must set proper socket type, not default. Change-Id: I789ff247a37a8048e9e4657997ac55a603b484e9 Signed-off-by: minsoo kim --- src/shared/csocket.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 25a7076..c500def 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -170,6 +170,7 @@ bool csocket::accept(csocket& client_socket) const do { client_socket.m_sock_fd = ::accept(m_sock_fd, (sockaddr *)&m_addr, (socklen_t *)&addr_length); + client_socket.set_sock_type(); if (!client_socket.is_valid()) err = errno; } while (err == EINTR); -- 2.7.4 From a3178338a7857eb929280ef05f526c215cd482b2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 17 Nov 2016 00:04:29 +0900 Subject: [PATCH 09/16] sensord: add select before sending the event because check client fd is writable or not, select() is added. Change-Id: I3189b314ec574fa8201dc79e33b91ad2e7f82deb Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index c500def..4a97a3c 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -306,9 +306,35 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t csocket::send(const void *buffer, size_t size) const { + const int TIMEOUT = 5; + fd_set write_fds; + struct timeval tv; + if (!is_valid()) return -EINVAL; + FD_ZERO(&write_fds); + FD_SET(m_sock_fd, &write_fds); + tv.tv_sec = TIMEOUT; + tv.tv_usec = 0; + + int ret; + + ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv); + + if (ret == -1) { + _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); + return false; + } else if (!ret) { + _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); + return false; + } + + if (!FD_ISSET(m_sock_fd, &write_fds)) { + _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); + return false; + } + if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); -- 2.7.4 From d482ea6afbf0c2ed942a5636e99b5ba468e251d7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:00:14 +0900 Subject: [PATCH 10/16] sensord: change variable name of attribute-related functions - change name from value_len to len - change name from attribute to attr Change-Id: I7a2513f207c34fd564100b6bdd1d4f2798845ca8 Signed-off-by: kibak.yoon --- src/client/client.cpp | 12 ++++++------ src/client/sensor_client_info.cpp | 10 +++++----- src/client/sensor_client_info.h | 2 +- src/client/sensor_handle_info.cpp | 12 +++++++----- src/client/sensor_handle_info.h | 2 +- src/server/external_sensor_worker.cpp | 1 - 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 7d22d9f..7fd43f5 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1135,7 +1135,7 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return change_attribute_int(handle, attribute, value); } -API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len) +API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) { sensor_id_t sensor_id; command_channel *cmd_channel; @@ -1154,22 +1154,22 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, return -EPERM; } - retvm_if((value_len < 0) || (value == NULL), -EINVAL, + retvm_if((len < 0) || (value == NULL), -EINVAL, "Invalid value_len: %d, value: %#x, handle: %d, %s, %s", - value_len, value, handle, get_sensor_name(sensor_id), get_client_name()); + len, value, handle, get_sensor_name(sensor_id), get_client_name()); client_id = sensor_client_info::get_instance().get_client_id(); retvm_if((client_id < 0), -EPERM, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name()); - if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { + if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) { _E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s", - client_id, value_len, value, get_client_name()); + client_id, len, value, get_client_name()); return -EPERM; } - sensor_client_info::get_instance().set_attribute(handle, attribute, value, value_len); + sensor_client_info::get_instance().set_attribute(handle, attribute, value, len); return OP_SUCCESS; } diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 743cd29..2a755aa 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -682,7 +682,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, int value) return true; } -bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int value_len) +bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int len) { AUTOLOCK(m_handle_info_lock); @@ -693,17 +693,17 @@ bool sensor_client_info::set_attribute(int handle, int attribute, const char *va return false; } - auto it_attribute = it_handle->second.attributes_str.find(attribute); + auto it_attr = it_handle->second.attributes_str.find(attribute); - if (it_attribute != it_handle->second.attributes_str.end()) { - it_attribute->second->set(value, value_len); + if (it_attr != it_handle->second.attributes_str.end()) { + it_attr->second->set(value, len); return true; } attribute_info *info = new(std::nothrow) attribute_info(); retvm_if(!info, false, "Failed to allocate memory"); - info->set(value, value_len); + info->set(value, len); it_handle->second.attributes_str[attribute] = info; return true; diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 905d682..15f2677 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -66,7 +66,7 @@ public: bool set_passive_mode(int handle, bool passive); bool set_attribute(int handle, int attribute, int value); - bool set_attribute(int handle, int attribute, const char *value, int value_len); + bool set_attribute(int handle, int attribute, const char *value, int len); bool set_sensor_pause_policy(int handle, int pause_policy); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 9f2d562..5f10930 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -40,15 +40,17 @@ attribute_info::~attribute_info() m_len = 0; } -bool attribute_info::set(const char *value, unsigned int len) +bool attribute_info::set(const char *value, int len) { + retvm_if(len < 0, false, "Invalid length"); + if (m_attr) delete m_attr; m_attr = new(std::nothrow) char[len]; retvm_if(!m_attr, false, "Failed to allocate memory"); - memcpy(m_attr, value, len); + memcpy(m_attr, value, (unsigned int)len); m_len = len; return true; @@ -142,10 +144,10 @@ bool sensor_handle_info::delete_reg_event_info(unsigned int event_type) void sensor_handle_info::clear(void) { - sensor_attribute_str_map::iterator it_attribute; + sensor_attribute_str_map::iterator it_attr; - for (it_attribute = attributes_str.begin(); it_attribute != attributes_str.end(); ++it_attribute) - delete it_attribute->second; + for (it_attr = attributes_str.begin(); it_attr != attributes_str.end(); ++it_attr) + delete it_attr->second; attributes_int.clear(); attributes_str.clear(); diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index 70cf5c9..6ede304 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -34,7 +34,7 @@ public: ~attribute_info(); char *get(void); - bool set(const char *value, unsigned int len); + bool set(const char *value, int len); unsigned int size(void); diff --git a/src/server/external_sensor_worker.cpp b/src/server/external_sensor_worker.cpp index 67bb4d7..f62dc28 100644 --- a/src/server/external_sensor_worker.cpp +++ b/src/server/external_sensor_worker.cpp @@ -95,7 +95,6 @@ bool external_sensor_worker::working(void *ctx) ret = inst->dispatch_command(header.cmd, payload); delete[] payload; - return ret; } -- 2.7.4 From 6539d695b404d2ed28ef98de06bbce13039e0f26 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:03:25 +0900 Subject: [PATCH 11/16] sensord: add sensorctl instead of original sensor-test - this sensorctl is an initial version for the sync, it will be updated to the latest version as soon as possible. Change-Id: Ie532efaecf73fc742810c9b6ce53085ac8e75817 Signed-off-by: kibak.yoon --- CMakeLists.txt | 2 +- packaging/sensord.spec | 6 +- src/sensorctl/CMakeLists.txt | 28 +++ src/sensorctl/dbus_util.cpp | 107 ++++++++ src/sensorctl/dbus_util.h | 30 +++ src/sensorctl/info_manager.cpp | 94 +++++++ src/sensorctl/info_manager.h | 34 +++ src/sensorctl/injector.h | 32 +++ src/sensorctl/injector_context_orientation.cpp | 58 +++++ src/sensorctl/injector_context_orientation.h | 32 +++ src/sensorctl/injector_manager.cpp | 130 ++++++++++ src/sensorctl/injector_manager.h | 58 +++++ src/sensorctl/injector_wrist_up_algo.cpp | 77 ++++++ src/sensorctl/injector_wrist_up_algo.h | 33 +++ src/sensorctl/injector_wrist_up_conf.cpp | 59 +++++ src/sensorctl/injector_wrist_up_conf.h | 34 +++ src/sensorctl/loopback_manager.cpp | 99 ++++++++ src/sensorctl/loopback_manager.h | 33 +++ src/sensorctl/sensor_manager.cpp | 115 +++++++++ src/sensorctl/sensor_manager.h | 32 +++ src/sensorctl/sensorctl.cpp | 100 ++++++++ src/sensorctl/sensorctl_log.h | 49 ++++ src/sensorctl/tester.h | 28 +++ src/sensorctl/tester_manager.cpp | 79 ++++++ src/sensorctl/tester_manager.h | 32 +++ src/sensorctl/tester_sensor.cpp | 151 +++++++++++ src/sensorctl/tester_sensor.h | 34 +++ src/test/CMakeLists.txt | 49 ---- src/test/src/api-test.c | 271 -------------------- src/test/src/check-sensor.c | 333 ------------------------- src/test/src/check-sensor.h | 38 --- src/test/src/fusion-data-collection.c | 129 ---------- src/test/src/multi-process-performance-test.c | 117 --------- src/test/src/multi-thread-performance-test.c | 114 --------- src/test/src/sensor-test.c | 230 ----------------- 35 files changed, 1560 insertions(+), 1287 deletions(-) create mode 100644 src/sensorctl/CMakeLists.txt create mode 100644 src/sensorctl/dbus_util.cpp create mode 100644 src/sensorctl/dbus_util.h create mode 100644 src/sensorctl/info_manager.cpp create mode 100644 src/sensorctl/info_manager.h create mode 100644 src/sensorctl/injector.h create mode 100644 src/sensorctl/injector_context_orientation.cpp create mode 100644 src/sensorctl/injector_context_orientation.h create mode 100644 src/sensorctl/injector_manager.cpp create mode 100644 src/sensorctl/injector_manager.h create mode 100644 src/sensorctl/injector_wrist_up_algo.cpp create mode 100644 src/sensorctl/injector_wrist_up_algo.h create mode 100644 src/sensorctl/injector_wrist_up_conf.cpp create mode 100644 src/sensorctl/injector_wrist_up_conf.h create mode 100644 src/sensorctl/loopback_manager.cpp create mode 100644 src/sensorctl/loopback_manager.h create mode 100644 src/sensorctl/sensor_manager.cpp create mode 100644 src/sensorctl/sensor_manager.h create mode 100644 src/sensorctl/sensorctl.cpp create mode 100644 src/sensorctl/sensorctl_log.h create mode 100644 src/sensorctl/tester.h create mode 100644 src/sensorctl/tester_manager.cpp create mode 100644 src/sensorctl/tester_manager.h create mode 100644 src/sensorctl/tester_sensor.cpp create mode 100644 src/sensorctl/tester_sensor.h delete mode 100644 src/test/CMakeLists.txt delete mode 100644 src/test/src/api-test.c delete mode 100644 src/test/src/check-sensor.c delete mode 100644 src/test/src/check-sensor.h delete mode 100644 src/test/src/fusion-data-collection.c delete mode 100644 src/test/src/multi-process-performance-test.c delete mode 100644 src/test/src/multi-thread-performance-test.c delete mode 100644 src/test/src/sensor-test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 591edb4..bf31fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,4 @@ ADD_SUBDIRECTORY(src/server) ADD_SUBDIRECTORY(src/client) ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/hal) -ADD_SUBDIRECTORY(src/test) +ADD_SUBDIRECTORY(src/sensorctl) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index b1439b8..bb1cd3f 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -123,9 +123,5 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files -n sensor-test %defattr(-,root,root,-) -%{_bindir}/api-test -%{_bindir}/sensor-test -%{_bindir}/multi-thread-performance-test -%{_bindir}/multi-process-performance-test -%{_bindir}/fusion-data-collection +%{_bindir}/sensorctl %license LICENSE.APLv2 diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt new file mode 100644 index 0000000..1accf2a --- /dev/null +++ b/src/sensorctl/CMakeLists.txt @@ -0,0 +1,28 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensorctl CXX) +INCLUDE(GNUInstallDirs) + +SET(DEPS glib-2.0 gio-2.0) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${DEPS}) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src/hal/ + ${CMAKE_SOURCE_DIR}/src/client/ + ${CMAKE_SOURCE_DIR}/src/shared/ +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +# Installing files +FILE(GLOB_RECURSE SRCS *.cpp) +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} sensor) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/src/sensorctl/dbus_util.cpp b/src/sensorctl/dbus_util.cpp new file mode 100644 index 0000000..886872e --- /dev/null +++ b/src/sensorctl/dbus_util.cpp @@ -0,0 +1,107 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +static GDBusConnection *connection; + +bool dbus_init(void) +{ + GError *error = NULL; + gchar *gaddr; + + if (connection) + return true; + +#ifndef GLIB_VERSION_2_36 + g_type_init(); +#endif + + gaddr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (!gaddr) { + PRINT("ERROR: Failed to get dbus address : %s", error->message); + g_error_free(error); + error = NULL; + return false; + } + + connection = g_dbus_connection_new_for_address_sync(gaddr, + (GDBusConnectionFlags)(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT + | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), + NULL, NULL, &error); + g_free(gaddr); + + if (!connection) { + PRINT("ERROR: Failed to get dbus connection : %s", error->message); + g_error_free(error); + error = NULL; + return false; + } + + PRINT("G-DBUS connected[%s]\n", + g_dbus_connection_get_unique_name(connection)); + return true; +} + +bool dbus_fini(void) +{ + if (!connection) + return true; + + g_dbus_connection_close_sync(connection, NULL, NULL); + g_object_unref(connection); + connection = NULL; + + return true; +} + +bool dbus_emit_signal(gchar *dest_bus_name, gchar *object_path, + gchar *interface_name, gchar *signal_name, + GVariant *variant, GError **error) +{ + g_dbus_connection_emit_signal(connection, + dest_bus_name, + object_path, + interface_name, + signal_name, + variant, + error); + return true; +} + +GVariant *make_variant_int(int count, char *options[]) +{ + switch (count) { + case 1: + return g_variant_new("(i)", atoi(options[0])); + case 2: + return g_variant_new("(ii)", atoi(options[0]), atoi(options[1])); + case 3: + return g_variant_new("(iii)", atoi(options[0]), atoi(options[1]), atoi(options[2])); + default: + break; + } + + return NULL; +} + diff --git a/src/sensorctl/dbus_util.h b/src/sensorctl/dbus_util.h new file mode 100644 index 0000000..a51d903 --- /dev/null +++ b/src/sensorctl/dbus_util.h @@ -0,0 +1,30 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _DBUS_UTIL_H_ + +#include +#include + +bool dbus_init(void); +bool dbus_fini(void); +bool dbus_emit_signal(gchar *dest_bus_name, gchar *object_path, + gchar *interface_name, gchar *signal_name, + GVariant *variant, GError **error); +GVariant *make_variant_int(int count, char *options[]); diff --git a/src/sensorctl/info_manager.cpp b/src/sensorctl/info_manager.cpp new file mode 100644 index 0000000..676bc40 --- /dev/null +++ b/src/sensorctl/info_manager.cpp @@ -0,0 +1,94 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include "info_manager.h" + +bool info_manager::process(int argc, char *argv[]) +{ + sensor_type_t type; + + if (argc == 2) { + usage(); + return false; + } + + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) + return false; + + sensor_t *sensors; + int count; + + sensord_get_sensor_list(type, &sensors, &count); + sensor_info(sensors, count); + + free(sensors); + return true; +} + +void info_manager::sensor_info(sensor_t *sensors, int count) +{ + sensor_t sensor; + char *vendor; + char *name; + float min_range; + float max_range; + float resolution; + int min_interval; + int fifo_count; + int max_batch_count; + + for (int i = 0; i < count; ++i) { + sensor = sensors[i]; + + name = const_cast(sensord_get_name(sensor)); + vendor = const_cast(sensord_get_vendor(sensor)); + sensord_get_max_range(sensor, &max_range); + sensord_get_min_range(sensor, &min_range); + sensord_get_resolution(sensor, &resolution); + sensord_get_min_interval(sensor, &min_interval); + sensord_get_fifo_count(sensor, &fifo_count); + sensord_get_max_batch_count(sensor, &max_batch_count); + + PRINT("-------sensor[%d] information-------\n", i); + PRINT("vendor : %s\n", vendor); + PRINT("name : %s\n", name); + PRINT("min_range : %f\n", min_range); + PRINT("max_range : %f\n", max_range); + PRINT("resolution : %f\n", resolution); + PRINT("min_interval : %d\n", min_interval); + PRINT("fifo_count : %d\n", fifo_count); + PRINT("max_batch_count : %d\n", max_batch_count); + PRINT("--------------------------------\n"); + } +} + +void info_manager::usage(void) +{ + PRINT("usage: sensorctl info \n"); + PRINT("\n"); + + usage_sensors(); +} + diff --git a/src/sensorctl/info_manager.h b/src/sensorctl/info_manager.h new file mode 100644 index 0000000..b71dfc0 --- /dev/null +++ b/src/sensorctl/info_manager.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INFO_MANAGER_H_ + +#include +#include "sensor_manager.h" + +class info_manager : public sensor_manager { +public: + info_manager() {} + virtual ~info_manager() {} + + bool process(int argc, char *argv[]); +private: + void sensor_info(sensor_t *sensors, int count); + void usage(void); +}; diff --git a/src/sensorctl/injector.h b/src/sensorctl/injector.h new file mode 100644 index 0000000..f9e8b40 --- /dev/null +++ b/src/sensorctl/injector.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INJECTOR_H_ + +#include + +#define SENSORD_BUS_NAME "org.tizen.system.sensord" +#define SENSORD_OBJ_PATH "/Org/Tizen/System/SensorD" +#define SENSORD_INTERFACE_NAME "org.tizen.system.sensord" + +class injector_interface { +public: + virtual bool init(void) { return true; } + virtual bool inject(int option_count, char *options[]) = 0; +}; diff --git a/src/sensorctl/injector_context_orientation.cpp b/src/sensorctl/injector_context_orientation.cpp new file mode 100644 index 0000000..863b901 --- /dev/null +++ b/src/sensorctl/injector_context_orientation.cpp @@ -0,0 +1,58 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_context_orientation.h" + +#define CONTEXT_ORIENTATION_SIGNAL "orientation" + +bool injector_context_orientation::inject(int option_count, char *options[]) +{ + GVariant *variant; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + variant = make_variant_int(option_count, options); + + if (variant == NULL) + return false; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)CONTEXT_ORIENTATION_SIGNAL, + variant, + NULL); + + PRINT("set options to context: \n"); + for (int i = 0; i < option_count; ++i) + PRINT("option %d: %s\n", i, options[i]); + + return true; +} + +REGISTER_INJECTOR(CONTEXT_SENSOR, CONTEXT_ORIENTATION_SIGNAL, injector_context_orientation) diff --git a/src/sensorctl/injector_context_orientation.h b/src/sensorctl/injector_context_orientation.h new file mode 100644 index 0000000..01d2d18 --- /dev/null +++ b/src/sensorctl/injector_context_orientation.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _CONTEXT_INJECTOR_H_ + +#include +#include +#include "injector.h" + +class injector_context_orientation: public injector_interface { +public: + injector_context_orientation() {} + virtual ~injector_context_orientation() {} + + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp new file mode 100644 index 0000000..4f6b722 --- /dev/null +++ b/src/sensorctl/injector_manager.cpp @@ -0,0 +1,130 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector.h" +#include "injector_manager.h" + +#define NAME_MAX_TEST 32 +#define ARGC_BASE 4 /* e.g. {sensorctl, inject, wristup, conf} */ + +static std::vector injector_infos; + +injector_manager::injector_manager() +{ + if (!dbus_init()) { + _E("Failed to init dbus"); + throw; + } +} + +injector_manager::~injector_manager() +{ + dbus_fini(); +} + +bool injector_manager::register_injector(injector_info info) +{ + injector_infos.push_back(info); + return true; +} + +injector_interface *injector_manager::get_injector(sensor_type_t type, const char *name) +{ + int injector_count; + injector_count = injector_infos.size(); + + for (int i = 0; i < injector_count; ++i) { + if (type == injector_infos[i].type && + !strcmp(injector_infos[i].name, name)) + return injector_infos[i].injector; + } + return NULL; +} + +bool injector_manager::process(int argc, char *argv[]) +{ + int option_count; + char *options[8]; + bool result; + sensor_type_t type; + char *event_name; + int i; + + if (argc < 4) { + usage(); + return false; + } + + /* 1. get sensor type */ + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) { + _E("ERROR : failed to process injector\n"); + return false; + } + + /* 2. set up injector */ + event_name = argv[3]; + + injector_interface *injector = get_injector(type, event_name); + if (injector == NULL) { + _E("ERROR: cannot find matched injector\n"); + return false; + } + + /* 3. init injector */ + result = injector->init(); + if (!result) { + _E("ERROR: failed to init injector\n"); + return false; + } + + /* 4. inject event with options */ + option_count = argc - ARGC_BASE; + for (i = 0; i < option_count; ++i) { + options[i] = new char[NAME_MAX_TEST]; + strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + } + + result = injector->inject(option_count, options); + if (!result) { + _E("ERROR : failed to process injector\n"); + for (i = 0; i < option_count; ++i) + delete [] options[i]; + + return false; + } + + for (i = 0; i < option_count; ++i) + delete [] options[i]; + + return true; +} + +void injector_manager::usage(void) +{ + PRINT("usage: sensorctl inject [] []\n\n"); + + usage_sensors(); +} + diff --git a/src/sensorctl/injector_manager.h b/src/sensorctl/injector_manager.h new file mode 100644 index 0000000..380c486 --- /dev/null +++ b/src/sensorctl/injector_manager.h @@ -0,0 +1,58 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INJECT_MANAGER_H_ + +#include +#include +#include "injector.h" +#include "sensor_manager.h" + +#define REGISTER_INJECTOR(sensor_type, sensor_name, injector_type) \ +static void __attribute__((constructor)) reg_injector(void) \ +{ \ + struct injector_info info; \ + info.type = (sensor_type); \ + info.name = (sensor_name); \ + info.injector = new(std::nothrow) (injector_type)(); \ + if (!info.injector) { \ + _E("ERROR: Failed to allocate memory(%s)", #injector_type); \ + return; \ + } \ + injector_manager::register_injector(info); \ +} + +struct injector_info { + sensor_type_t type; + const char *name; + injector_interface *injector; +}; + +class injector_manager : public sensor_manager { +public: + injector_manager(); + virtual ~injector_manager(); + + bool process(int argc, char *argv[]); + + static bool register_injector(injector_info info); +private: + injector_interface *get_injector(sensor_type_t type, const char *name); + void usage(void); +}; diff --git a/src/sensorctl/injector_wrist_up_algo.cpp b/src/sensorctl/injector_wrist_up_algo.cpp new file mode 100644 index 0000000..766e6ec --- /dev/null +++ b/src/sensorctl/injector_wrist_up_algo.cpp @@ -0,0 +1,77 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_wrist_up_algo.h" + +#define WRIST_UP_ALGO_SIGNAL "algo" +#define OPTION_INDEX 0 + +typedef std::map option_map_t; +static option_map_t option_map; + +bool injector_wrist_up_algo::init(void) +{ + option_map.insert(option_map_t::value_type("auto", 0)); + option_map.insert(option_map_t::value_type("green", 1)); + option_map.insert(option_map_t::value_type("purple", 2)); + option_map.insert(option_map_t::value_type("red", 3)); + + return true; +} + +bool injector_wrist_up_algo::inject(int option_count, char *options[]) +{ + int option; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + option_map_t::iterator it; + it = option_map.find(options[OPTION_INDEX]); + + if (it == option_map.end()) { + _E("ERROR: no matched-option: %s\n", options[OPTION_INDEX]); + return false; + } + + option = it->second; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)WRIST_UP_ALGO_SIGNAL, + g_variant_new("(i)", option), + NULL); + + _I("set [%s] mode to wristup (%d)", options[OPTION_INDEX], option); + return true; +} + +REGISTER_INJECTOR(MOTION_SENSOR, "algo", injector_wrist_up_algo) diff --git a/src/sensorctl/injector_wrist_up_algo.h b/src/sensorctl/injector_wrist_up_algo.h new file mode 100644 index 0000000..a5bd6fe --- /dev/null +++ b/src/sensorctl/injector_wrist_up_algo.h @@ -0,0 +1,33 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _WRISTUP_INJECTOR_H_ + +#include +#include +#include "injector.h" + +class injector_wrist_up_algo: public injector_interface { +public: + injector_wrist_up_algo() {} + virtual ~injector_wrist_up_algo() {} + + bool init(void); + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/injector_wrist_up_conf.cpp b/src/sensorctl/injector_wrist_up_conf.cpp new file mode 100644 index 0000000..11e7a2f --- /dev/null +++ b/src/sensorctl/injector_wrist_up_conf.cpp @@ -0,0 +1,59 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_wrist_up_conf.h" + +#define WRIST_UP_CONF_SIGNAL "conf" + +bool injector_wrist_up_conf::inject(int option_count, char *options[]) +{ + GVariant *variant; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + variant = make_variant_int(option_count, options); + + if (variant == NULL) + return false; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)WRIST_UP_CONF_SIGNAL, + variant, + NULL); + + PRINT("set options to wristup: \n"); + for (int i = 0; i < option_count; ++i) + PRINT("option %d: %s\n", i, options[i]); + + return true; +} + +REGISTER_INJECTOR(MOTION_SENSOR, "conf", injector_wrist_up_conf) + diff --git a/src/sensorctl/injector_wrist_up_conf.h b/src/sensorctl/injector_wrist_up_conf.h new file mode 100644 index 0000000..93b75f4 --- /dev/null +++ b/src/sensorctl/injector_wrist_up_conf.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _WRISTUP_INJECTOR_H_ + +#include +#include +#include "injector.h" + +#define NAME_MAX_TEST 32 + +class injector_wrist_up_conf: public injector_interface { +public: + injector_wrist_up_conf() {} + virtual ~injector_wrist_up_conf() {} + + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback_manager.cpp new file mode 100644 index 0000000..4b78007 --- /dev/null +++ b/src/sensorctl/loopback_manager.cpp @@ -0,0 +1,99 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include "loopback_manager.h" + +#define SHUB_INST_LIB_ADD ((char)-79) +#define SHUB_INST_LIB_REMOVE ((char)-78) +#define SHUB_LOOP_BACK_LIB 12 +#define DEFAULT_COMMAND_SIZE 3 +#define MAX_COMMAND_SIZE 82 +#define MAX_DATA_SIZE 84 /* -79, 12, 4byte Delaytime + 78 bytes data */ + +static void int_to_bytes(int32_t value, int length, char cmd[]) +{ + /* Convert to Big-endian */ + for (int i = length - 1; i >= 0; i--) { + cmd[i] = (value & 0xff); + value = value >> 8; + } +} + +bool loopback_manager::process(int argc, char *argv[]) +{ + sensor_type_t type; + + if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { + usage(); + return false; + } + + if (!strcmp(argv[2], "start")) { + int handle; + sensor_t sensor; + sensor = sensord_get_sensor(CONTEXT_SENSOR); + handle = sensord_connect(sensor); + + /* + * sensorhub (bytes) command [0~1] delaytime [2~5] data[6~83] + * shell (argv) command [0~2] delaytime [3] data[4~81] + */ + char test_data[MAX_DATA_SIZE] = {SHUB_INST_LIB_ADD, SHUB_LOOP_BACK_LIB,}; + int_to_bytes(atoi(argv[3]), sizeof(int), &(test_data[2])); + + for (int i = 4; i < argc; i++) + test_data[i+2] = atoi(argv[i]); + + sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data)); + sensord_disconnect(handle); + return true; + } + + if (!strcmp(argv[2], "stop")) { + int handle; + sensor_t sensor; + sensor = sensord_get_sensor(CONTEXT_SENSOR); + handle = sensord_connect(sensor); + + char test_data[4] = {SHUB_INST_LIB_REMOVE, SHUB_LOOP_BACK_LIB,}; + + sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data)); + sensord_disconnect(handle); + return true; + } + + usage(); + + return false; +} + +void loopback_manager::usage(void) +{ + PRINT("usage: sensorctl loopback [start/stop] [14byte sensor char data]\n"); + PRINT("ex: sensorctl loopback start 15000 1 1 19 1 (after 15000ms, wrist up event)\n"); + PRINT("ex: sensorctl loopback stop\n"); + PRINT(" * if not enought 14byte, remain bytes are filled with 0\n"); + PRINT("\n"); +} + diff --git a/src/sensorctl/loopback_manager.h b/src/sensorctl/loopback_manager.h new file mode 100644 index 0000000..2aa3297 --- /dev/null +++ b/src/sensorctl/loopback_manager.h @@ -0,0 +1,33 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _LOOPBACK_MANAGER_H_ + +#include +#include "sensor_manager.h" + +class loopback_manager : public sensor_manager { +public: + loopback_manager() {} + virtual ~loopback_manager() {} + + bool process(int argc, char *argv[]); +private: + void usage(void); +}; diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp new file mode 100644 index 0000000..ce2e4ef --- /dev/null +++ b/src/sensorctl/sensor_manager.cpp @@ -0,0 +1,115 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include "sensor_manager.h" + +#define NAME_MAX_TEST 32 + +struct sensor_info { + sensor_type_t type; + char name[NAME_MAX_TEST]; +}; + +static struct sensor_info sensor_infos[] = { + {ALL_SENSOR, "all"}, + + // General Sensors + {ACCELEROMETER_SENSOR, "accelerometer"}, + {GEOMAGNETIC_SENSOR, "magnetic"}, + {LIGHT_SENSOR, "light"}, + {PROXIMITY_SENSOR, "proximity"}, + {GYROSCOPE_SENSOR, "gyroscope"}, + {PRESSURE_SENSOR, "pressure"}, + {BIO_SENSOR, "bio"}, + {BIO_HRM_SENSOR, "hrm"}, + {AUTO_ROTATION_SENSOR, "auto_rotation"}, + {GRAVITY_SENSOR, "gravity"}, + {LINEAR_ACCEL_SENSOR, "linear_accel"}, + {ROTATION_VECTOR_SENSOR, "rotation_vector"}, + {ORIENTATION_SENSOR, "orientation"}, + {TEMPERATURE_SENSOR, "temperature"}, + {HUMIDITY_SENSOR, "humidity"}, + {ULTRAVIOLET_SENSOR, "ultraviolet"}, + {BIO_LED_GREEN_SENSOR, "hrm_led_green"}, + {BIO_LED_IR_SENSOR, "hrm_led_ir"}, + {BIO_LED_RED_SENSOR, "hrm_led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal"}, + {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal"}, + {GYROSCOPE_RV_SENSOR, "gyro_rv"}, + {GEOMAGNETIC_RV_SENSOR, "mag_rv"}, + /* If WRIST_UP_SENSOR is created, it has to be changed to WRIST_UP_SENSOR */ + {MOTION_SENSOR, "motion"}, + {CONTEXT_SENSOR, "context"}, + {EXERCISE_SENSOR, "exercise"}, + {GESTURE_WRIST_UP_SENSOR, "wristup"}, +}; + +bool sensor_manager::process(int argc, char *argv[]) +{ + return false; +} + +void sensor_manager::usage_sensors(void) +{ + PRINT("The sensor types are:\n"); + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (int i = 0; i < sensor_count; ++i) + PRINT(" %d: %s(%d)\n", i, sensor_infos[i].name, sensor_infos[i].type); + PRINT("\n"); +} + +sensor_type_t sensor_manager::get_sensor_type(char *name) +{ + int index; + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (index = 0; index < sensor_count; ++index) { + if (!strcmp(sensor_infos[index].name, name)) + break; + } + + if (index == sensor_count) { + _E("ERROR: sensor name is wrong\n"); + usage_sensors(); + return UNKNOWN_SENSOR; + } + return sensor_infos[index].type; +} + +const char *sensor_manager::get_sensor_name(sensor_type_t type) +{ + int index; + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (index = 0; index < sensor_count; ++index) { + if (sensor_infos[index].type == type) + break; + } + + if (index == sensor_count) { + _E("ERROR: sensor name is wrong\n"); + usage_sensors(); + return "UNKNOWN SENSOR"; + } + return sensor_infos[index].name; +} diff --git a/src/sensorctl/sensor_manager.h b/src/sensorctl/sensor_manager.h new file mode 100644 index 0000000..9fd3476 --- /dev/null +++ b/src/sensorctl/sensor_manager.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSOR_MANAGER_H_ + +#include + +class sensor_manager { +public: + virtual bool process(int argc, char *argv[]); +protected: + void usage_sensors(void); + + sensor_type_t get_sensor_type(char *name); + const char * get_sensor_name(sensor_type_t type); +}; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp new file mode 100644 index 0000000..aa4543e --- /dev/null +++ b/src/sensorctl/sensorctl.cpp @@ -0,0 +1,100 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +#include +#include "sensor_manager.h" +#include "tester_manager.h" +#include "injector_manager.h" +#include "info_manager.h" +#include "loopback_manager.h" + +static void good_bye(void) +{ +} + +static void signal_handler(int signo) +{ + _E("\nReceived SIGNAL(%d)\n", signo); + exit(EXIT_SUCCESS); + + return; +} + +void usage(void) +{ + PRINT("usage: sensorctl []\n"); + + PRINT("The sensorctl commands are:\n"); + PRINT(" test: test sensor(s)\n"); + PRINT(" inject: inject the event to sensor\n"); + PRINT(" info: show sensor infos\n"); + PRINT(" loopback: sensor loopback test\n"); +} + +sensor_manager *create_manager(int argc, char *argv[2]) +{ + sensor_manager *manager = NULL; + + if (!strcmp(argv[1], "test")) + manager = new(std::nothrow) tester_manager; + if (!strcmp(argv[1], "inject")) + manager = new(std::nothrow) injector_manager; + if (!strcmp(argv[1], "info")) + manager = new(std::nothrow) info_manager; + if (!strcmp(argv[1], "loopback")) + manager = new(std::nothrow) loopback_manager; + + if (!manager) { + _E("failed to allocate memory for manager"); + return NULL; + } + + return manager; +} + +int main(int argc, char *argv[]) +{ + atexit(good_bye); + + signal(SIGINT, signal_handler); + signal(SIGHUP, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGABRT, signal_handler); + + if (argc < 2) { + usage(); + return 0; + } + + sensor_manager *manager = create_manager(argc, argv); + if (!manager) { + usage(); + return 0; + } + + manager->process(argc, argv); + + return 0; +} diff --git a/src/sensorctl/sensorctl_log.h b/src/sensorctl/sensorctl_log.h new file mode 100644 index 0000000..f5f8f25 --- /dev/null +++ b/src/sensorctl/sensorctl_log.h @@ -0,0 +1,49 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSORCTL_LOG_H_ + +#include +#include + +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define KYEL "\x1B[33m" +#define KBLU "\x1B[34m" +#define KMAG "\x1B[35m" +#define KCYN "\x1B[36m" +#define KWHT "\x1B[37m" +#define RESET "\033[0m" + +#define PRINT(fmt, args...) \ + do { \ + g_print(fmt, ##args); \ + } while (0) + +#define _E(fmt, args...) \ + do { \ + g_print("\x1B[31m" fmt "\033[0m", ##args); \ + } while (0) + +#define _I(fmt, args...) \ + do { \ + g_print("\x1B[32m" fmt "\033[0m", ##args); \ + } while (0) + diff --git a/src/sensorctl/tester.h b/src/sensorctl/tester.h new file mode 100644 index 0000000..2d912c9 --- /dev/null +++ b/src/sensorctl/tester.h @@ -0,0 +1,28 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _TESTER_H_ + +#include + +class tester_interface { +public: + virtual bool init(void) = 0; + virtual bool test(sensor_type_t type, int option_count, char *options[]) = 0; +}; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp new file mode 100644 index 0000000..ffd9e57 --- /dev/null +++ b/src/sensorctl/tester_manager.cpp @@ -0,0 +1,79 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "tester.h" +#include "tester_manager.h" +#include "tester_sensor.h" + +#define NAME_MAX_TEST 32 +#define ARGC_BASE 3 /* e.g. {sensorctl, test, accelerometer} */ + +bool tester_manager::process(int argc, char *argv[]) +{ + int option_count; + char *options[8]; + sensor_type_t type; + int i; + + if (argc == 2) { + usage(); + return false; + } + + /* 1. get sensor type */ + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) { + _E("ERROR : failed to process injector\n"); + return false; + } + + /* 2. set up injector */ + tester_interface *tester = new tester_sensor(); + tester->init(); + + /* 3. test sensor with options */ + option_count = argc - ARGC_BASE; + for (i = 0; i < option_count; ++i) { + options[i] = new char[NAME_MAX_TEST]; + strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + } + + tester->test(type, option_count, options); + + return true; +} + +void tester_manager::usage(void) +{ + PRINT("usage: sensorctl test [interval] [event_count] [test_count]\n\n"); + + usage_sensors(); + + PRINT("interval_ms:\n"); + PRINT(" interval. default value is 100ms.\n"); + PRINT("event count(n):\n"); + PRINT(" test sensor until it gets n event. default is 999999(infinitly).\n"); + PRINT("test count(n):\n"); + PRINT(" test sensor in n times repetitively, default is 1.\n\n"); +} + diff --git a/src/sensorctl/tester_manager.h b/src/sensorctl/tester_manager.h new file mode 100644 index 0000000..16f4b16 --- /dev/null +++ b/src/sensorctl/tester_manager.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _TEST_MANAGER_H_ + +#include "sensor_manager.h" + +class tester_manager : public sensor_manager { +public: + tester_manager() {} + virtual ~tester_manager() {} + + bool process(int argc, char *argv[]); +private: + void usage(void); +}; diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp new file mode 100644 index 0000000..5a75da6 --- /dev/null +++ b/src/sensorctl/tester_sensor.cpp @@ -0,0 +1,151 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include "tester_sensor.h" + +#define DEFAULT_INTERVAL 100 +#define DEFAULT_LATENCY 0 +#define DEFAULT_TEST_COUNT 1 +#define DEFAULT_EVENT_COUNT 9999 + +#define SENSOR_SHIFT_TYPE 16 + +static GMainLoop *mainloop; +static int check_loop; + +static const char *result_str(bool result) { + if (result) return KGRN"[PASS]"RESET; + else return KRED"[FAIL]"RESET; +} + +bool tester_sensor::init(void) +{ + return true; +} + +void tester_sensor::test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + sensor_type_t type; + int *cnt_event; + + sensord_get_type(sensor, &type); + + cnt_event = (int *)user_data; + + if (check_loop++ >= *cnt_event) { + if (!mainloop) + return; + + g_main_loop_quit(mainloop); + g_main_loop_unref(mainloop); + mainloop = NULL; + return; + } + + PRINT("[%llu] %s:", data->timestamp, sensord_get_name(sensor)); + + if (type == GESTURE_WRIST_UP_SENSOR) { + PRINT("[%d]\n", ((sensorhub_data_t *)data)->hub_data[0]); + return; + } + + for (int i = 0; i < data->value_count; ++i) + PRINT(" [%f]", data->values[i]); + PRINT("\n"); +} + +void tester_sensor::test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event) +{ + bool result; + sensor_t sensor; + unsigned int event_id; + sensor_data_t data; + int handle; + int count = 0; + + event_id = type << SENSOR_SHIFT_TYPE | 0x1; + + while (count++ < cnt_test) { + mainloop = g_main_loop_new(NULL, FALSE); + check_loop = 0; + + PRINT("=======================================\n"); + PRINT("TEST(%d/%d)\n", count, cnt_test); + PRINT("=======================================\n"); + + sensor = sensord_get_sensor(type); + PRINT("%s sensord_get_sensor: sensor(%p)\n", result_str((sensor == NULL)? 0 : 1), sensor); + + handle = sensord_connect(sensor); + PRINT("%s sensord_connect: handle(%d)\n", result_str((handle >= 0)), handle); + + result = sensord_register_event(handle, event_id, interval, latency, test_cb, (void *)&cnt_event); + PRINT("%s sensord_register_event\n", result_str(result)); + + result = sensord_start(handle, 3); + PRINT("%s sensord_start\n", result_str(result)); + + result = sensord_get_data(handle, event_id, &data); + PRINT("%s sensord_get_data\n", result_str(result)); + + result = sensord_flush(handle); + PRINT("%s sensord_flush\n", result_str(result)); + + if (result) { + for (int i = 0; i < data.value_count; ++i) + PRINT("[%f] ", data.values[i]); + PRINT("\n"); + } + + g_main_loop_run(mainloop); + + result = sensord_unregister_event(handle, event_id); + PRINT("%s sensord_unregister_event: handle(%d)\n", result_str(result), handle); + result = sensord_stop(handle); + PRINT("%s sensord_stop: handle(%d)\n", result_str(result), handle); + result = sensord_disconnect(handle); + PRINT("%s sensord_disconnect: handle(%d)\n", result_str(result), handle); + } +} + +bool tester_sensor::test(sensor_type_t type, int option_count, char *options[]) +{ + int interval = DEFAULT_INTERVAL; + int latency = DEFAULT_LATENCY; + int cnt_test = DEFAULT_TEST_COUNT; + int cnt_event = DEFAULT_EVENT_COUNT; + + sensor_type_t sensor_type = type; + + if (option_count >= 1) + interval = atoi(options[0]); + if (option_count >= 2) + cnt_event = atoi(options[1]); + if (option_count >= 3) + cnt_test = atoi(options[2]); + + test_sensor(sensor_type, interval, latency, cnt_test, cnt_event); + return true; +} diff --git a/src/sensorctl/tester_sensor.h b/src/sensorctl/tester_sensor.h new file mode 100644 index 0000000..68b76b4 --- /dev/null +++ b/src/sensorctl/tester_sensor.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSOR_TESTER_H_ + +#include "tester.h" + +class tester_sensor : public tester_interface { +public: + tester_sensor() {} + virtual ~tester_sensor() {} + + virtual bool init(void); + virtual bool test(sensor_type_t type, int option_count, char *options[]); +private: + void test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event); + static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); +}; diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt deleted file mode 100644 index d9e3ec9..0000000 --- a/src/test/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -project(sensor-tc C) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") -SET(VERSION 1.0) - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0) - -add_definitions(${rpkgs_CFLAGS}) -add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}") - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/src/client) -include_directories(${CMAKE_SOURCE_DIR}/src/shared) -include_directories(${CMAKE_SOURCE_DIR}/src/hal) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -link_directories(${CMAKE_SOURCE_DIR}/src/client/) - -add_executable(api-test src/api-test.c) -add_executable(sensor-test src/sensor-test.c src/check-sensor.c) -add_executable(multi-process-performance-test src/multi-process-performance-test.c src/check-sensor.c) -add_executable(fusion-data-collection src/fusion-data-collection.c) -add_executable(multi-thread-performance-test src/multi-thread-performance-test.c src/check-sensor.c) - -SET_TARGET_PROPERTIES(api-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(sensor-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(multi-process-performance-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(fusion-data-collection PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(multi-thread-performance-test PROPERTIES LINKER_LANGUAGE C) - -target_link_libraries(api-test glib-2.0 dlog sensor) -target_link_libraries(sensor-test glib-2.0 dlog sensor) -target_link_libraries(multi-process-performance-test glib-2.0 dlog sensor pthread) -target_link_libraries(fusion-data-collection glib-2.0 dlog sensor) -target_link_libraries(multi-thread-performance-test glib-2.0 dlog sensor pthread) - -INSTALL(TARGETS api-test DESTINATION /usr/bin/) -INSTALL(TARGETS sensor-test DESTINATION /usr/bin/) -INSTALL(TARGETS multi-process-performance-test DESTINATION /usr/bin/) -INSTALL(TARGETS fusion-data-collection DESTINATION /usr/bin/) -INSTALL(TARGETS multi-thread-performance-test DESTINATION /usr/bin/) diff --git a/src/test/src/api-test.c b/src/test/src/api-test.c deleted file mode 100644 index 2a1ff11..0000000 --- a/src/test/src/api-test.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_EVENT_INTERVAL 100 - -static GMainLoop *mainloop; -FILE *fp; - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - g_main_loop_quit(mainloop); -} - -bool check_sensor_api(unsigned int event_type, int cond_value) -{ - int handle; - - mainloop = g_main_loop_new(NULL, FALSE); - - sensor_type_t sensor_type = event_type >> 16; - sensor_t sensor = sensord_get_sensor(sensor_type); - - handle = sensord_connect(sensor); - - if (handle < 0) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_connect\n", sensor_type, event_type); - return false; - } - - bool is_supported; - bool result_boolean = sensord_is_supported_event_type(sensor, event_type, &is_supported); - if (!result_boolean && !is_supported) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_is_supported_event\n", sensor_type, event_type); - return false; - } - - int output; - result_boolean = sensord_get_min_interval(sensor, &output); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_interval\n", sensor_type, event_type); - return false; - } - - float output3; - result_boolean = sensord_get_resolution(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_resolution\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_get_max_range(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_max_range\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_get_min_range(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_range\n", sensor_type, event_type); - return false; - } - - sensor_privilege_t output4; - result_boolean = sensord_get_privilege(sensor, &output4); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_privilege\n", sensor_type, event_type); - return false; - } - - const char* result_char = sensord_get_vendor(sensor); - if (!result_char) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_vendor\n", sensor_type, event_type); - return false; - } - - result_char = sensord_get_name(sensor); - if (!result_char) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_name\n", sensor_type, event_type); - return false; - } - - sensor_type_t output_type; - result_boolean = sensord_get_type(sensor, &output_type); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_type\n", sensor_type, event_type); - return false; - } - - unsigned int *output2; - result_boolean = sensord_get_supported_event_types(sensor, &output2, &output); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_supported_event_types\n", sensor_type, event_type); - return false; - } - - 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; - } - - result_boolean = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_start(handle, 1); - 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; - } - - sensor_data_t data; - result_boolean = sensord_get_data(handle, event_type, &data); - 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; - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - 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; - } - - 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; - } - - 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; - } - - 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; -} - -int main(int argc, char **argv) -{ - bool result; - - int interval = DEFAULT_EVENT_INTERVAL; - if (argc == 2) - interval = atof(argv[1]); - - fp = fopen("auto_test.output", "w+"); - - result = check_sensor_api(ACCELEROMETER_RAW_DATA_EVENT, interval); - fprintf(fp, "Accelerometer - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GEOMAGNETIC_RAW_DATA_EVENT, interval); - fprintf(fp, "Geomagnetic - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GRAVITY_RAW_DATA_EVENT, interval); - fprintf(fp, "Gravity - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GYROSCOPE_RAW_DATA_EVENT, interval); - fprintf(fp, "Gyroscope - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(LIGHT_LUX_DATA_EVENT, interval); - fprintf(fp, "Light - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(LINEAR_ACCEL_RAW_DATA_EVENT, interval); - fprintf(fp, "Linear Accel - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ORIENTATION_RAW_DATA_EVENT, interval); - fprintf(fp, "Orientation - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(TILT_RAW_DATA_EVENT, interval); - fprintf(fp, "Tilt - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(PRESSURE_RAW_DATA_EVENT, interval); - fprintf(fp, "Pressure - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ROTATION_VECTOR_RAW_DATA_EVENT, interval); - fprintf(fp, "Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GEOMAGNETIC_RV_RAW_DATA_EVENT, interval); - fprintf(fp, "Geomagnetic Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GAMING_RV_RAW_DATA_EVENT, interval); - fprintf(fp, "Gaming Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GYROSCOPE_UNCAL_SENSOR, interval); - fprintf(fp, "Gyroscope Uncal Sensor - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(TEMPERATURE_RAW_DATA_EVENT, interval); - fprintf(fp, "Temperature - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ULTRAVIOLET_RAW_DATA_EVENT, interval); - fprintf(fp, "ULTRAVIOLET - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(BIO_LED_RED_RAW_DATA_EVENT, interval); - fprintf(fp, "BIO_LED_RED - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(FACE_DOWN_RAW_DATA_EVENT, interval); - fprintf(fp, "Face Down - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - printf("Logs printed in ./auto_test.output\n"); - fclose(fp); - return 0; -} diff --git a/src/test/src/check-sensor.c b/src/test/src/check-sensor.c deleted file mode 100644 index 04ea726..0000000 --- a/src/test/src/check-sensor.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "check-sensor.h" - -void printpollinglogs(sensor_type_t type,sensor_data_t data) -{ - switch(type) { - case(ACCELEROMETER_SENSOR): - printf("Accelerometer [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(AUTO_ROTATION_SENSOR): - printf("Auto Rotation [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(GYROSCOPE_SENSOR): - printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(PRESSURE_SENSOR): - printf("Pressure [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(GEOMAGNETIC_SENSOR): - printf("Geomagnetic [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(LIGHT_SENSOR): - printf("Light [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(TEMPERATURE_SENSOR): - printf("Temperature [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(PROXIMITY_SENSOR): - printf("Proximity [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(ULTRAVIOLET_SENSOR): - printf("Ultraviolet [%lld] [%6.6f]\n", data.timestamp, data.values[0]); - break; - case(BIO_LED_RED_SENSOR): - printf("Bio_LED_Red [%lld] [%6.6f]\n", data.timestamp, data.values[0]); - break; - case(ORIENTATION_SENSOR): - printf("Orientation [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(TILT_SENSOR): - printf("Tilt [%lld] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1]); - break; - case(GRAVITY_SENSOR): - printf("Gravity [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(LINEAR_ACCEL_SENSOR): - printf("Linear Acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(ROTATION_VECTOR_SENSOR): - printf("Rotation Vector [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GEOMAGNETIC_RV_SENSOR): - printf("Geomagnetic Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GYROSCOPE_RV_SENSOR): - printf("Gaming Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GYROSCOPE_UNCAL_SENSOR): - printf("Gyroscope Uncal [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3], data.values[4], data.values[5]); - break; - case(GESTURE_FACE_DOWN_SENSOR): - printf("Face Down [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - default: - return; - } -} - -int get_event(sensor_type_t sensor_type, char str[]) -{ - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ACCELEROMETER_RAW_DATA_EVENT; - break; - case AUTO_ROTATION_SENSOR: - if (strcmp(str, "CHANGE_STATE_EVENT") == 0) - return AUTO_ROTATION_CHANGE_STATE_EVENT; - break; - case GYROSCOPE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GYROSCOPE_RAW_DATA_EVENT; - break; - case PRESSURE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return PRESSURE_RAW_DATA_EVENT; - break; - case GEOMAGNETIC_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GEOMAGNETIC_RAW_DATA_EVENT; - break; - case LIGHT_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return LIGHT_LUX_DATA_EVENT; - break; - case TEMPERATURE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return TEMPERATURE_RAW_DATA_EVENT; - break; - case PROXIMITY_SENSOR: - if (strcmp(str, "CHANGE_STATE_EVENT") == 0) - return PROXIMITY_CHANGE_STATE_EVENT; - break; - case ULTRAVIOLET_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ULTRAVIOLET_RAW_DATA_EVENT; - break; - case BIO_LED_RED_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return BIO_LED_RED_RAW_DATA_EVENT; - break; - case ORIENTATION_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ORIENTATION_RAW_DATA_EVENT; - break; - case TILT_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return TILT_RAW_DATA_EVENT; - break; - case GRAVITY_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GRAVITY_RAW_DATA_EVENT; - break; - case LINEAR_ACCEL_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return LINEAR_ACCEL_RAW_DATA_EVENT; - break; - case ROTATION_VECTOR_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ROTATION_VECTOR_RAW_DATA_EVENT; - break; - case GEOMAGNETIC_RV_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GEOMAGNETIC_RV_RAW_DATA_EVENT; - break; - case GYROSCOPE_RV_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GAMING_RV_RAW_DATA_EVENT; - break; - case GYROSCOPE_UNCAL_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GYROSCOPE_UNCAL_RAW_DATA_EVENT; - break; - case GESTURE_FACE_DOWN_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return FACE_DOWN_RAW_DATA_EVENT; - break; - - default: - return -1; - } - return -1; -} - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t sensor_type = event_type >> 16; - - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - printf("Accelerometer [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case AUTO_ROTATION_SENSOR: - printf("Auto Rotation [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case GYROSCOPE_SENSOR: - printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case PRESSURE_SENSOR: - printf("Pressure [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case GEOMAGNETIC_SENSOR: - printf("Geomagnetic [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case LIGHT_SENSOR: - printf("Light [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case TEMPERATURE_SENSOR : - printf("Temperature [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case PROXIMITY_SENSOR: - printf("Proximity [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case ULTRAVIOLET_SENSOR: - printf("Ultraviolet [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case BIO_LED_RED_SENSOR: - printf("Bio_LED_Red [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case ORIENTATION_SENSOR : - printf("Orientation [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case TILT_SENSOR : - printf("Tilt [%lld] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1]); - break; - case GRAVITY_SENSOR: - printf("Gravity [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case LINEAR_ACCEL_SENSOR: - printf("Linear acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case ROTATION_VECTOR_SENSOR: - printf("Rotation vector [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GEOMAGNETIC_RV_SENSOR: - printf("Geomagnetic RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GYROSCOPE_RV_SENSOR: - printf("Gaming RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GYROSCOPE_UNCAL_SENSOR: - printf("Gyroscope Uncal [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3], data->values[4], data->values[5]); - break; - case GESTURE_FACE_DOWN_SENSOR: - printf("Face Down [%lld] [%6.6f] \n", data->timestamp, data->values[0]); - break; - - default: - return; - } -} - -void *check_sensor(void *arg) -{ - struct pthread_arguments * argu = (struct pthread_arguments *) arg; - - GMainLoop *mainloop; - int handle; - bool result, start_handle, stop_handle; - - mainloop = g_main_loop_new(NULL, FALSE); - - sensor_t sensor = sensord_get_sensor(argu -> sensor_type); - handle = sensord_connect(sensor); - - result = sensord_register_event(handle, argu->event, argu->interval, 0, callback, NULL); - - if (!result) { - printf("Can't register sensor\n"); - return NULL; - } - - start_handle = sensord_start(handle, 0); - - if (!start_handle) { - printf("Error\n\n\n\n"); - sensord_unregister_event(handle, argu->event); - sensord_disconnect(handle); - return NULL; - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - result = sensord_unregister_event(handle, argu->event); - - if (!result) { - printf("Error\n\n"); - return NULL; - } - - stop_handle = sensord_stop(handle); - - if (!stop_handle) { - printf("Error\n\n"); - return NULL; - } - - sensord_disconnect(handle); - return NULL; -} - -int polling_sensor(sensor_type_t sensor_type, unsigned int event) -{ - bool result; - int handle; - - printf("Polling based\n"); - sensor_t sensor; - sensor = sensord_get_sensor(sensor_type); - handle = sensord_connect(sensor); - result = sensord_start(handle, 1); - - if (!result) { - printf("Can't start the sensor\n"); - printf("Error\n\n\n\n"); - return -1; - } - - sensor_data_t data; - - while (1) { - result = sensord_get_data(handle, event, &data); - printpollinglogs(sensor_type, data); - usleep(100000); - } - - result = sensord_disconnect(handle); - - if (!result) { - printf("Can't disconnect sensor\n"); - printf("Error\n\n\n\n"); - return -1; - } - - return 0; -} diff --git a/src/test/src/check-sensor.h b/src/test/src/check-sensor.h deleted file mode 100644 index 042dc87..0000000 --- a/src/test/src/check-sensor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 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 CHECK_SENSOR_H -#define CHECK_SENSOR_H - -#include - -#define DEFAULT_EVENT_INTERVAL 100 - -int get_event(sensor_type_t sensor_type, char str[]); -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); -void *check_sensor(void *arg); -void printpollinglogs(sensor_type_t type, sensor_data_t data); -int polling_sensor(sensor_type_t sensor_type, unsigned int event); - -struct pthread_arguments -{ - sensor_type_t sensor_type; - unsigned int event; - int interval; -}; -#endif diff --git a/src/test/src/fusion-data-collection.c b/src/test/src/fusion-data-collection.c deleted file mode 100644 index 6abd6f5..0000000 --- a/src/test/src/fusion-data-collection.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAXSIZE 4 - -static GMainLoop *mainloop; -FILE* file_output[MAXSIZE]; - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t sensor_type = event_type >> 16; - - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - fprintf(file_output[0], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[0]); - break; - case GEOMAGNETIC_SENSOR: - fprintf(file_output[1], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[1]); - break; - case GYROSCOPE_SENSOR: - fprintf(file_output[2], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[2]); - break; - case PROXIMITY_SENSOR: - fprintf(file_output[MAXSIZE-1], "%6.6f %lld\n", data->values[0], data->timestamp); - fflush(file_output[MAXSIZE-1]); - break; - default: - return; - } -} - -void usage() -{ - printf("Usage : ./fusion-data-collection \n\n"); - - printf("interval:\n"); - printf("The sampling interval in ms.\n"); - exit(-1); -} - -int main(int argc, char **argv) -{ - int interval; - - if (argc == 2) { - interval = atoi(argv[1]); - if (interval <= 0) - usage(); - } - else - usage(); - - int i; - - int handle[MAXSIZE]; - bool result[MAXSIZE], start_handle[MAXSIZE]; - unsigned int event[MAXSIZE]; - int sensors[MAXSIZE]; - - sensors[0] = ACCELEROMETER_SENSOR; - sensors[1] = GEOMAGNETIC_SENSOR; - sensors[2] = GYROSCOPE_SENSOR; - sensors[MAXSIZE-1] = PROXIMITY_SENSOR; - - mainloop = g_main_loop_new(NULL, FALSE); - - char file_name[50]; - - for (i = 0; i < MAXSIZE; i++) { - snprintf(file_name, sizeof(file_name), "output_%d", sensors[i]); - file_output[i] = fopen(file_name, "w+"); - sensor_t sensor = sensord_get_sensor(sensors[i]); - handle[i] = sensord_connect(sensor); - event[i] = (sensors[i] << 16) | 0x0001; - result[i] = sensord_register_event(handle[i], event[i], interval, 0, callback, NULL); - - if (!result[i]) { - printf("error: unable to register sensor\n"); - return -1; - } - start_handle[i] = sensord_start(handle[i], 1); - - if (!start_handle[i]) { - printf("error: unable to start handle\n"); - sensord_unregister_event(handle[i], event[i]); - sensord_disconnect(handle[i]); - return -1; - } - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - for (i = 0; i < MAXSIZE; i++) { - sensord_unregister_event(handle[i], event[i]); - sensord_stop(handle[i]); - sensord_disconnect(handle[i]); - } - - return 0; -} diff --git a/src/test/src/multi-process-performance-test.c b/src/test/src/multi-process-performance-test.c deleted file mode 100644 index c9b02ec..0000000 --- a/src/test/src/multi-process-performance-test.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include - -#include "check-sensor.h" - -void usage() -{ - printf("Usage : ./performance-test (optional)\n\n"); - - printf("TIMEOUT:\n"); - printf("time for which the parallel sensor test cases should run\n"); - - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.\n"); - printf("If no value for sensor is entered default value by the driver will be used.\n"); -} - -int main(int argc, char** argv) -{ - pid_t b = 1; - - int i = 0; - int interval = DEFAULT_EVENT_INTERVAL; - int TIMEOUT = 10; //in seconds for which all the sensor tests should run - - if(argc < 2) { - usage(); - return -1; - } - else if(argc == 2){ - TIMEOUT = atoi(argv[1]); - if (TIMEOUT == 0) { - usage(); - return -1; - } - } - else { - TIMEOUT = atoi(argv[1]); - interval = atoi(argv[2]); - if (TIMEOUT == 0 || interval == 0) { - usage(); - return -1; - } - } - - //make an array of size MAX and fill it with all the sensors needed to run - int MAX = 6; - pid_t pids[MAX]; - sensor_type_t sensor[MAX]; - - //Update the value of MAX and add more sensors here to test more sensors in parallel - sensor[0] = ACCELEROMETER_SENSOR; - sensor[1] = GYROSCOPE_SENSOR; - sensor[2] = GEOMAGNETIC_SENSOR; - sensor[3] = PRESSURE_SENSOR; - sensor[4] = PROXIMITY_SENSOR; - sensor[MAX-1] = LIGHT_SENSOR; - - while (i < MAX) { - if (b > 0) { - b = fork(); - if (b == -1) perror("Fork failed\n"); - else if (b == 0) { - break; - } - pids[i] = b; - i++; - } - } - - if (i < MAX) { - // call the sensord test tc-common for a sensor. - int event = (sensor[i] << 16) | 0x0001; - struct pthread_arguments arg; - arg.sensor_type = sensor[i]; - arg.event = event; - arg.interval = interval; - - check_sensor((void*)&arg); - } - else { - // Main Parent Child. Waits for TIMEOUT and then kills all child processes. - sleep (TIMEOUT); - int j = 0; - - for (j = 0; j < MAX; j++) { - char command[100]; - snprintf(command, sizeof(command), "kill %d", pids[j]); - if (system(command) == -1) - return -1; - } - } - - return 0; -} diff --git a/src/test/src/multi-thread-performance-test.c b/src/test/src/multi-thread-performance-test.c deleted file mode 100644 index 588c0e7..0000000 --- a/src/test/src/multi-thread-performance-test.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "check-sensor.h" - -void usage() -{ - printf("Usage : ./multi-sensor (optional)\n\n"); - printf("TIMEOUT:\n"); - printf("time for which the parallel sensor test cases should run\n"); - - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.\n"); - printf("If no value for sensor is entered default value by the driver will be used.\n"); - printf("arg[i].sensor_type: "); - printf("[accelerometer] "); - printf("[auto_rotation]\n"); - printf("[gyroscope] "); - printf("[pressure] "); - printf("[temperature] "); - printf("[geomagnetic] "); - printf("[orientation] "); - printf("[tilt] "); - printf("[gravity] "); - printf("[linear_accel] "); - printf("[rotation_vector] "); - printf("[geomagnetic_rv] "); - printf("[gaming_rv] "); - printf("[ultraviolet] "); - printf("[light]\n"); - printf("[gyro_uncal]"); - printf("[face_down]"); - -} - -int main(int argc, char **argv) -{ - - int i = 0; - int interval = DEFAULT_EVENT_INTERVAL; - int TIMEOUT = 10; //in seconds for which all the sensor tests should run - - if(argc < 2) { - usage(); - return -1; - } - else if(argc == 2){ - TIMEOUT = atoi(argv[1]); - if (TIMEOUT == 0) { - usage(); - return -1; - } - } - else { - TIMEOUT = atoi(argv[1]); - interval = atoi(argv[2]); - if (TIMEOUT == 0 || interval == 0) { - usage(); - return -1; - } - } - - int MAX = 6, j = 0, k = 0; - struct pthread_arguments arg[MAX]; - int t = 0; - - arg[0].sensor_type = ACCELEROMETER_SENSOR; - arg[0].event = ACCELEROMETER_RAW_DATA_EVENT; - arg[1].sensor_type = GYROSCOPE_SENSOR; - arg[1].event = GYROSCOPE_RAW_DATA_EVENT; - arg[2].sensor_type = GEOMAGNETIC_RV_SENSOR; - arg[2].event = GEOMAGNETIC_RV_RAW_DATA_EVENT; - arg[3].sensor_type = PRESSURE_SENSOR; - arg[3].event = PRESSURE_RAW_DATA_EVENT; - arg[4].sensor_type = PROXIMITY_SENSOR; - arg[4].event = PROXIMITY_CHANGE_STATE_EVENT; - arg[5].sensor_type = LIGHT_SENSOR; - arg[5].event = LIGHT_LUX_DATA_EVENT; - - for (t = 0; t < MAX; t++) - arg[t].interval = interval; - - pthread_t thread_id[MAX]; - - for (j = 0; j < MAX; j++) - pthread_create(&thread_id[j], NULL, check_sensor, (void*)&arg[j]); - - sleep(TIMEOUT); - return 0; -} diff --git a/src/test/src/sensor-test.c b/src/test/src/sensor-test.c deleted file mode 100644 index ff2b005..0000000 --- a/src/test/src/sensor-test.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "check-sensor.h" - -void usage() -{ - printf("Usage : ./sensor-test -p(optional) (optional) (optional)\n\n"); - - printf("Sensor_type: "); - printf("[accelerometer] "); - printf("[auto_rotation]\n"); - printf("[gyroscope] "); - printf("[pressure] "); - printf("[temperature] "); - printf("[geomagnetic] "); - printf("[orientation] "); - printf("[tilt] "); - printf("[gravity] "); - printf("[linear_accel] "); - printf("[rotation_vector] "); - printf("[geomagnetic_rv] "); - printf("[gaming_rv] "); - printf("[ultraviolet] "); - printf("[bio_led_red] "); - printf("[light]\n"); - printf("[gyroscope_uncal]"); - printf("[face_down]"); - printf("event:"); - printf("[RAW_DATA_EVENT]\n"); - printf("-p: [polling]\n"); - printf("Sensor_type: "); - printf("[proximity]\n"); - printf("event:"); - printf("[CHANGE_STATE_EVENT]\n"); - printf("-p: [polling]\n"); - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n"); -} - -int main(int argc, char **argv) -{ - int interval; - unsigned int event; - sensor_type_t sensor_type; - bool is_polling; - - char *end1; - - if (argc < 2 || argc > 5) { - printf("Wrong number of arguments\n"); - usage(); - return -1; - } - - if (strcmp(argv[1], "accelerometer") == 0) { - sensor_type = ACCELEROMETER_SENSOR; - event = ACCELEROMETER_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "auto_rotation") == 0) { - sensor_type = AUTO_ROTATION_SENSOR; - event = AUTO_ROTATION_CHANGE_STATE_EVENT; - } - else if (strcmp(argv[1], "gyroscope") == 0) { - sensor_type = GYROSCOPE_SENSOR; - event = GYROSCOPE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "pressure") == 0) { - sensor_type = PRESSURE_SENSOR; - event = PRESSURE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "temperature") == 0) { - sensor_type = TEMPERATURE_SENSOR; - event = TEMPERATURE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "geomagnetic") == 0) { - sensor_type = GEOMAGNETIC_SENSOR; - event = GEOMAGNETIC_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "orientation") == 0) { - sensor_type = ORIENTATION_SENSOR; - event = ORIENTATION_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "tilt") == 0) { - sensor_type = TILT_SENSOR; - event = TILT_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gravity") == 0) { - sensor_type = GRAVITY_SENSOR; - event = GRAVITY_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "linear_accel") == 0) { - sensor_type = LINEAR_ACCEL_SENSOR; - event = LINEAR_ACCEL_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "rotation_vector") == 0) { - sensor_type = ROTATION_VECTOR_SENSOR; - event = ROTATION_VECTOR_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "geomagnetic_rv") == 0) { - sensor_type = GEOMAGNETIC_RV_SENSOR; - event = GEOMAGNETIC_RV_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gaming_rv") == 0) { - sensor_type = GYROSCOPE_RV_SENSOR; - event = GAMING_RV_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "light") == 0) { - sensor_type = LIGHT_SENSOR; - event = LIGHT_LUX_DATA_EVENT; - } - else if (strcmp(argv[1], "proximity") == 0) { - sensor_type = PROXIMITY_SENSOR; - event = PROXIMITY_CHANGE_STATE_EVENT; - } - else if (strcmp(argv[1], "ultraviolet") == 0) { - sensor_type = ULTRAVIOLET_SENSOR; - event = ULTRAVIOLET_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gyroscope_uncal") == 0) { - sensor_type = GYROSCOPE_UNCAL_SENSOR; - event = GYROSCOPE_UNCAL_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "bio_led_red") == 0) { - sensor_type = BIO_LED_RED_SENSOR; - event = BIO_LED_RED_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "face_down") == 0) { - sensor_type = GESTURE_FACE_DOWN_SENSOR; - event = FACE_DOWN_RAW_DATA_EVENT; - } - else { - usage(); - return -1; - } - - interval = DEFAULT_EVENT_INTERVAL; - - is_polling = FALSE; - - if(argc >= 3 && strcmp(argv[2], "-p") == 0) { - is_polling = TRUE; - } - - if (is_polling) { - if (argc == 4) { - int temp_event = get_event(sensor_type, argv[3]); - if (temp_event == -1) { - interval = atoi(argv[3]); - if (interval == 0){ - usage(); - return -1; - } - } - else { - event = temp_event; - } - } - else if (argc == 5) { - event = get_event(sensor_type, argv[3]); - interval = strtol(argv[4], &end1, 10); - - if (*end1) { - printf("Conversion error, non-convertible part: %s\n", end1); - return -1; - } - } - return polling_sensor(sensor_type, event); - } - else { - if (argc == 3) { - int temp_event = get_event(sensor_type, argv[2]); - - if (temp_event == -1) { - interval = atoi(argv[2]); - if (interval == 0){ - usage(); - return -1; - } - } - else { - event = temp_event; - } - } - else if (argc == 4) { - event = get_event(sensor_type, argv[2]); - interval = strtol(argv[3], &end1, 10); - - if (*end1) { - printf("Conversion error, non-convertible part: %s\n", end1); - return -1; - } - } - struct pthread_arguments arg; - arg.sensor_type = sensor_type; - arg.event = event; - arg.interval = interval; - - void *result = check_sensor((void*)&arg); - - if (!result) - return -1; - - return 0; - } -} -- 2.7.4 From 44ddaba7e2869edbe46bb37f6b7e648ba0773253 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:07:39 +0900 Subject: [PATCH 12/16] sensord: add internal sensor types Change-Id: Ieacf15fdceb421dbc8e7912d137fcae52462a948 Signed-off-by: kibak.yoon --- src/client/client_common.cpp | 1 + src/shared/sensor_types.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index a0a7345..96ce4ff 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -72,6 +72,7 @@ unsigned int get_log_per_count(sensor_id_t id) case GESTURE_WRIST_DOWN_SENSOR: case GESTURE_MOVEMENT_SENSOR: case WEAR_STATUS_SENSOR: + case PRESSURE_SENSOR: return LOG_PER_COUNT_EVERY_EVENT; default: break; diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 18e40f4..dab36bc 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -66,6 +66,8 @@ extern "C" DEF_SENSOR(EXERCISE_ROWING_SENSOR) \ DEF_SENSOR(EXERCISE_STEPPER_SENSOR) \ \ + DEF_SENSOR_VALUE(EXTERNAL_EXERCISE_SENSOR, 0x800) \ + \ DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \ DEF_SENSOR(AUTO_ROTATION_SENSOR) \ DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \ @@ -92,6 +94,9 @@ extern "C" DEF_SENSOR(WORKOUT_SENSOR) \ DEF_SENSOR(CYCLE_MONITOR_SENSOR) \ DEF_SENSOR(STAIR_TRACKER_SENSOR) \ + DEF_SENSOR(PRESSURE_INDICATOR_SENSOR) \ + DEF_SENSOR(PRESSURE_ALERT_SENSOR) \ + DEF_SENSOR(HR_CALORIE_SENSOR) \ \ DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x7000) \ DEF_SENSOR(MOTION_SENSOR) \ @@ -104,6 +109,9 @@ extern "C" DEF_SENSOR(HRM_RAW_SENSOR) \ DEF_SENSOR(TILT_SENSOR) \ DEF_SENSOR(RV_RAW_SENSOR) \ + DEF_SENSOR(GSR_SENSOR) \ + DEF_SENSOR(SIMSENSE_SENSOR) \ + DEF_SENSOR(PPG_SENSOR) \ #define BIO_HRM_SENSOR HRM_SENSOR #define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR @@ -114,6 +122,7 @@ extern "C" #define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR #define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR #define EXERCISE_COACH_SENSOR EXERCISE_STANDALONE_SENSOR +#define EXERCISE_SENSOR EXTERNAL_EXERCISE_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From e358d052833d6af22ce1c1acf835a0b4443fa226 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 18:13:36 +0900 Subject: [PATCH 13/16] sensord: change file permission to remove execute permission Change-Id: I5cce417208269fdbae3899f643089ff1fbd990e5 Signed-off-by: kibak.yoon --- src/client/dbus_listener.cpp | 0 src/server/dbus_util.cpp | 0 src/server/server.cpp | 0 src/shared/macro.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/client/dbus_listener.cpp mode change 100755 => 100644 src/server/dbus_util.cpp mode change 100755 => 100644 src/server/server.cpp mode change 100755 => 100644 src/shared/macro.h diff --git a/src/client/dbus_listener.cpp b/src/client/dbus_listener.cpp old mode 100755 new mode 100644 diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp old mode 100755 new mode 100644 diff --git a/src/server/server.cpp b/src/server/server.cpp old mode 100755 new mode 100644 diff --git a/src/shared/macro.h b/src/shared/macro.h old mode 100755 new mode 100644 -- 2.7.4 From 530996c4a54010f2217862ac891207cb796ffd7f Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 30 Nov 2016 22:16:08 +0900 Subject: [PATCH 14/16] [BugFix] Reset Sensor Fusion Backend if it returns NaN because of inconsitent input and high error Change-Id: I29fe84898d32f710cb914748d3111edfb2da38b7 Signed-off-by: Akhil --- src/sensor/rotation_vector/fusion_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 51e45d3..89b5a44 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -100,5 +100,10 @@ void fusion_base::store_orientation(void) m_y = m_orientation_filter.m_quaternion.m_quat.m_vec[1]; m_z = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; m_w = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; + + if (std::isnan(m_x) || std::isnan(m_y) || std::isnan(m_z) || std::isnan(m_w)) { + m_timestamp = 0; + m_orientation_filter = orientation_filter(); + } clear(); } -- 2.7.4 From 98584eab2e8e7270af197d064ca5aba166c676ea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 2 Dec 2016 18:44:25 +0900 Subject: [PATCH 15/16] sensord: fix compiler warnings Change-Id: I6c702882e120c470ac69d6b0d510021d49ceb15c Signed-off-by: kibak.yoon --- src/sensorctl/injector_manager.cpp | 2 +- src/sensorctl/loopback_manager.cpp | 2 -- src/sensorctl/tester_manager.cpp | 2 +- src/sensorctl/tester_sensor.cpp | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp index 4f6b722..8aeebb0 100644 --- a/src/sensorctl/injector_manager.cpp +++ b/src/sensorctl/injector_manager.cpp @@ -103,7 +103,7 @@ bool injector_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } result = injector->inject(option_count, options); diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback_manager.cpp index 4b78007..b7908b6 100644 --- a/src/sensorctl/loopback_manager.cpp +++ b/src/sensorctl/loopback_manager.cpp @@ -42,8 +42,6 @@ static void int_to_bytes(int32_t value, int length, char cmd[]) bool loopback_manager::process(int argc, char *argv[]) { - sensor_type_t type; - if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { usage(); return false; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp index ffd9e57..c16140f 100644 --- a/src/sensorctl/tester_manager.cpp +++ b/src/sensorctl/tester_manager.cpp @@ -55,7 +55,7 @@ bool tester_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } tester->test(type, option_count, options); diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp index 5a75da6..7f324f6 100644 --- a/src/sensorctl/tester_sensor.cpp +++ b/src/sensorctl/tester_sensor.cpp @@ -36,8 +36,8 @@ static GMainLoop *mainloop; static int check_loop; static const char *result_str(bool result) { - if (result) return KGRN"[PASS]"RESET; - else return KRED"[FAIL]"RESET; + if (result) return KGRN "[PASS]" RESET; + else return KRED "[FAIL]" RESET; } bool tester_sensor::init(void) -- 2.7.4 From 0c9da3394ec379bd829a8d5e4712bcfb3198cb9a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 6 Dec 2016 10:43:02 +0900 Subject: [PATCH 16/16] sensord: install required header files instead of all header files Change-Id: Ib826fe1e3464a560f58e5868c64fd4e2cf9a8136 Signed-off-by: kibak.yoon --- src/client/CMakeLists.txt | 12 ++++++++---- src/client/sensor_internal.h | 2 +- src/client/sensor_internal_deprecated.h | 2 +- src/shared/CMakeLists.txt | 15 +++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 2f32b9c..f14b841 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -22,6 +22,11 @@ ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC") +SET (INSTALL_HEADERS + sensor_internal.h + sensor_internal_deprecated.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_SOURCE_DIR}/src/shared @@ -37,9 +42,8 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) -INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" - ) +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index 47452d4..b7e9469 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -24,7 +24,7 @@ #define API __attribute__((visibility("default"))) #endif -#include "stdbool.h" +#include #include /*header for common sensor type*/ diff --git a/src/client/sensor_internal_deprecated.h b/src/client/sensor_internal_deprecated.h index a2b5b30..851ccbc 100644 --- a/src/client/sensor_internal_deprecated.h +++ b/src/client/sensor_internal_deprecated.h @@ -24,7 +24,7 @@ #define DEPRECATED __attribute__((deprecated)) #endif -#include "stdbool.h" +#include #include diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8b8416e..5d094ec 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -11,6 +11,13 @@ FOREACH(flag ${SHARED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +SET (INSTALL_HEADERS + sensor_types.h + sensor_common.h + sensor_deprecated.h + enum_factory.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_CURRENT_SOURCE_DIR} @@ -22,7 +29,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SHARED_PKGS_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) -INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" -) + +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() -- 2.7.4