From 850a6d5fc8313b94f4a46eb7b18b20e982879d74 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 22 Mar 2016 23:08:12 +0900 Subject: [PATCH 01/16] sensord: check whether the data is valid or not Change-Id: Ia456be16c90f949b1d32bbdc53579b41d58a477d Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 3 +++ src/server/sensor_event_poller.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index b10071f..83e5bce 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -712,6 +712,9 @@ bool command_worker::cmd_get_data(void *payload) remain_count = m_module->get_data(&data, &length); + if (remain_count < 0) + state = OP_ERROR; + // In case of not getting sensor data, wait short time and retry again // 1. changing interval to be less than 10ms // 2. In case of first time, wait for INIT_WAIT_TIME diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index 6058eed..082d689 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -51,6 +51,9 @@ void sensor_event_poller::init_sensor_map() fd = sensor->get_poll_fd(); + if (fd < 0) + continue; + m_fd_sensors.insert(std::make_pair(fd, sensor)); } } -- 2.7.4 From 21430f54e9199542d00346cf735a3966d4ef92d7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 22 Mar 2016 23:09:30 +0900 Subject: [PATCH 02/16] sensord: add the comments for logic Change-Id: I68bf587381b3a9371512d3d2c74cb5091c496b94 Signed-off-by: kibak.yoon --- src/server/sensor_event_poller.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index 082d689..b6d46ca 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -117,6 +117,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids physical_sensor *sensor; std::pair ret; + /* find sensors which is based on same device(fd) */ ret = m_fd_sensors.equal_range(fd); for (auto it_sensor = ret.first; it_sensor != ret.second; ++it_sensor) { @@ -127,6 +128,7 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids sensor = it_sensor->second; + /* check whether the id of this sensor is in id list(parameter) or not */ auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id()); if (result == std::end(ids)) -- 2.7.4 From 5b8f49878ceeae939ee782a5b0b326eb39e64be2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 23 Mar 2016 12:20:52 +0900 Subject: [PATCH 03/16] sensord: hal: splite sensor_hal.h into sensor_hal interface and hal types Change-Id: If9ec7348721581839faecf022e29c88134debe68 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 1 + src/hal/CMakeLists.txt | 1 + src/hal/sensor_hal.h | 165 +------------------------------ src/hal/sensor_hal_types.h | 228 +++++++++++++++++++++++++++++++++++++++++++ src/server/physical_sensor.h | 1 + src/server/sensor_base.cpp | 2 +- src/server/sensor_base.h | 2 +- src/shared/sensor_common.h | 2 +- 8 files changed, 235 insertions(+), 167 deletions(-) create mode 100644 src/hal/sensor_hal_types.h diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 801cec4..5bc4a2b 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -141,6 +141,7 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files -n sensor-hal-devel %defattr(-,root,root,-) %{_includedir}/sensor/sensor_hal.h +%{_includedir}/sensor/sensor_hal_types.h %license LICENSE.APLv2 %if %{build_test_suite} == "ON" diff --git a/src/hal/CMakeLists.txt b/src/hal/CMakeLists.txt index ee01da1..7119639 100644 --- a/src/hal/CMakeLists.txt +++ b/src/hal/CMakeLists.txt @@ -2,3 +2,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensor-hal CXX) INSTALL(FILES sensor_hal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) +INSTALL(FILES sensor_hal_types.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor/) diff --git a/src/hal/sensor_hal.h b/src/hal/sensor_hal.h index c52f25d..21eb205 100644 --- a/src/hal/sensor_hal.h +++ b/src/hal/sensor_hal.h @@ -20,164 +20,7 @@ #include #include - -#define SENSOR_HAL_VERSION(maj, min) \ - ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/* - * Sensor Types - * These types are used to controll the sensors - * - * - base unit - * acceleration values : meter per second^2 (m/s^2) - * magnetic values : micro-Tesla (uT) - * orientation values : degrees - * gyroscope values : degree/s - * temperature values : degrees centigrade - * proximity valeus : distance - * light values : lux - * pressure values : hectopascal (hPa) - * humidity : relative humidity (%) - */ -typedef enum { - SENSOR_DEVICE_UNKNOWN = -2, - SENSOR_DEVICE_ALL = -1, - SENSOR_DEVICE_ACCELEROMETER, - SENSOR_DEVICE_GRAVITY, - SENSOR_DEVICE_LINEAR_ACCELERATION, - SENSOR_DEVICE_GEOMAGNETIC, - SENSOR_DEVICE_ROTATION_VECTOR, - SENSOR_DEVICE_ORIENTATION, - SENSOR_DEVICE_GYROSCOPE, - SENSOR_DEVICE_LIGHT, - SENSOR_DEVICE_PROXIMITY, - SENSOR_DEVICE_PRESSURE, - SENSOR_DEVICE_ULTRAVIOLET, - SENSOR_DEVICE_TEMPERATURE, - SENSOR_DEVICE_HUMIDITY, - SENSOR_DEVICE_HRM, - SENSOR_DEVICE_HRM_LED_GREEN, - SENSOR_DEVICE_HRM_LED_IR, - SENSOR_DEVICE_HRM_LED_RED, - SENSOR_DEVICE_GYROSCOPE_UNCAL, - SENSOR_DEVICE_GEOMAGNETIC_UNCAL, - SENSOR_DEVICE_GYROSCOPE_RV, - SENSOR_DEVICE_GEOMAGNETIC_RV, - - SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, - SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, - - SENSOR_DEVICE_FUSION = 0x900, - SENSOR_DEVICE_AUTO_ROTATION, - SENSOR_DEVICE_AUTO_BRIGHTNESS, - - SENSOR_DEVICE_CONTEXT = 0x1000, - SENSOR_DEVICE_MOTION, - SENSOR_DEVICE_PIR, - SENSOR_DEVICE_PIR_LONG, - SENSOR_DEVICE_DUST, - SENSOR_DEVICE_THERMOMETER, - SENSOR_DEVICE_PEDOMETER, - SENSOR_DEVICE_FLAT, - SENSOR_DEVICE_HRM_RAW, - SENSOR_DEVICE_TILT, - SENSOR_DEVICE_ROTATION_VECTOR_RAW, - SENSOR_DEVICE_EXERCISE, - SENSOR_DEVICE_GSR, - SENSOR_DEVICE_SIMSENSE, - SENSOR_DEVICE_PPG, - - SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, - SENSOR_DEVICE_GESTURE_WRIST_UP, - SENSOR_DEVICE_GESTURE_WRIST_DOWN, - SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, - - SENSOR_DEVICE_WEAR_STATUS = 0x1A00, - SENSOR_DEVICE_WEAR_ON_MONITOR, - SENSOR_DEVICE_GPS_BATCH, - SENSOR_DEVICE_ACTIVITY_TRACKER, - SENSOR_DEVICE_SLEEP_DETECTOR, - SENSOR_DEVICE_NO_MOVE_DETECTOR = 0x1A80, - SENSOR_DEVICE_HRM_CTRL, - SENSOR_DEVICE_EXERCISE_COACH, - SENSOR_DEVICE_EXERCISE_HR, - SENSOR_DEVICE_RESTING_HR, - SENSOR_DEVICE_STEP_LEVEL_MONITOR, - SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, - SENSOR_DEVICE_CYCLE_MONITOR, - SENSOR_DEVICE_STRESS_MONITOR, - SENSOR_DEVICE_AUTOSESSION_EXERCISE, - SENSOR_DEVICE_STAIR_TRACKER, - -} sensor_device_type; - -/* - * A platform sensor handler is generated based on this handle - * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device. - */ -typedef struct sensor_info_t { - uint32_t id; - const char *name; - sensor_device_type type; - unsigned int event_type; // for Internal API - const char *model_name; - const char *vendor; - float min_range; - float max_range; - float resolution; - int min_interval; - int max_batch_count; - bool wakeup_supported; -} sensor_info_t; - -enum sensor_accuracy_t { - SENSOR_ACCURACY_UNDEFINED = -1, - SENSOR_ACCURACY_BAD = 0, - SENSOR_ACCURACY_NORMAL =1, - SENSOR_ACCURACY_GOOD = 2, - SENSOR_ACCURACY_VERYGOOD = 3 -}; - -#define SENSOR_DATA_VALUE_SIZE 16 - -/* sensor_data_t */ -typedef struct sensor_data_t { - int accuracy; - unsigned long long timestamp; - int value_count; - float values[SENSOR_DATA_VALUE_SIZE]; -} sensor_data_t; - -#define SENSORHUB_DATA_VALUE_SIZE 4096 - -/* sensorhub_data_t */ -typedef struct sensorhub_data_t { - int accuracy; - unsigned long long timestamp; - - /* - * Use "value_count" instead of "hub_data_size" - * which is going to be removed soon - */ - union { - int value_count; - int hub_data_size; /* deprecated */ - }; - - /* - * Use "values" instead of "hub_data" - * which is going to be removed soon - */ - union { - char values[SENSORHUB_DATA_VALUE_SIZE]; - char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ - }; -} sensorhub_data_t; +#include "sensor_hal_types.h" /* * Create devices @@ -185,11 +28,6 @@ typedef struct sensorhub_data_t { typedef void *sensor_device_t; typedef int (*create_t)(sensor_device_t **devices); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#ifdef __cplusplus /* * Sensor device interface * 1 device must be abstracted from 1 device event node @@ -233,6 +71,5 @@ public: return false; } }; -#endif /* __cplusplus */ #endif /* _SENSOR_HAL_H_ */ diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h new file mode 100644 index 0000000..9a4032b --- /dev/null +++ b/src/hal/sensor_hal_types.h @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _SENSOR_HAL_TYPES_H_ +#define _SENSOR_HAL_TYPES_H_ + +#include +#include + +#define SENSOR_HAL_VERSION(maj, min) \ + ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF)) + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/* + * Sensor Types + * These types are used to controll the sensors + * + * - base unit + * acceleration values : meter per second^2 (m/s^2) + * magnetic values : micro-Tesla (uT) + * orientation values : degrees + * gyroscope values : degree/s + * temperature values : degrees centigrade + * proximity valeus : distance + * light values : lux + * pressure values : hectopascal (hPa) + * humidity : relative humidity (%) + */ +typedef enum { + SENSOR_DEVICE_UNKNOWN = -2, + SENSOR_DEVICE_ALL = -1, + SENSOR_DEVICE_ACCELEROMETER, + SENSOR_DEVICE_GRAVITY, + SENSOR_DEVICE_LINEAR_ACCELERATION, + SENSOR_DEVICE_GEOMAGNETIC, + SENSOR_DEVICE_ROTATION_VECTOR, + SENSOR_DEVICE_ORIENTATION, + SENSOR_DEVICE_GYROSCOPE, + SENSOR_DEVICE_LIGHT, + SENSOR_DEVICE_PROXIMITY, + SENSOR_DEVICE_PRESSURE, + SENSOR_DEVICE_ULTRAVIOLET, + SENSOR_DEVICE_TEMPERATURE, + SENSOR_DEVICE_HUMIDITY, + SENSOR_DEVICE_HRM, + SENSOR_DEVICE_HRM_LED_GREEN, + SENSOR_DEVICE_HRM_LED_IR, + SENSOR_DEVICE_HRM_LED_RED, + SENSOR_DEVICE_GYROSCOPE_UNCAL, + SENSOR_DEVICE_GEOMAGNETIC_UNCAL, + SENSOR_DEVICE_GYROSCOPE_RV, + SENSOR_DEVICE_GEOMAGNETIC_RV, + + SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, + SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, + + SENSOR_DEVICE_FUSION = 0x900, + SENSOR_DEVICE_AUTO_ROTATION, + SENSOR_DEVICE_AUTO_BRIGHTNESS, + + SENSOR_DEVICE_CONTEXT = 0x1000, + SENSOR_DEVICE_MOTION, + SENSOR_DEVICE_PIR, + SENSOR_DEVICE_PIR_LONG, + SENSOR_DEVICE_DUST, + SENSOR_DEVICE_THERMOMETER, + SENSOR_DEVICE_PEDOMETER, + SENSOR_DEVICE_FLAT, + SENSOR_DEVICE_HRM_RAW, + SENSOR_DEVICE_TILT, + SENSOR_DEVICE_ROTATION_VECTOR_RAW, + SENSOR_DEVICE_EXERCISE, + SENSOR_DEVICE_GSR, + SENSOR_DEVICE_SIMSENSE, + SENSOR_DEVICE_PPG, + + SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, + SENSOR_DEVICE_GESTURE_WRIST_UP, + SENSOR_DEVICE_GESTURE_WRIST_DOWN, + SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, + + SENSOR_DEVICE_WEAR_STATUS = 0x1A00, + SENSOR_DEVICE_WEAR_ON_MONITOR, + SENSOR_DEVICE_GPS_BATCH, + SENSOR_DEVICE_ACTIVITY_TRACKER, + SENSOR_DEVICE_SLEEP_DETECTOR, + SENSOR_DEVICE_NO_MOVE_DETECTOR = 0x1A80, + SENSOR_DEVICE_HRM_CTRL, + SENSOR_DEVICE_EXERCISE_COACH, + SENSOR_DEVICE_EXERCISE_HR, + SENSOR_DEVICE_RESTING_HR, + SENSOR_DEVICE_STEP_LEVEL_MONITOR, + SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, + SENSOR_DEVICE_CYCLE_MONITOR, + SENSOR_DEVICE_STRESS_MONITOR, + SENSOR_DEVICE_AUTOSESSION_EXERCISE, + SENSOR_DEVICE_STAIR_TRACKER, + +} sensor_device_type; + +/* + * A platform sensor handler is generated based on this handle + * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device. + */ +typedef struct sensor_info_t { + uint32_t id; + const char *name; + sensor_device_type type; + unsigned int event_type; // for Internal API + const char *model_name; + const char *vendor; + float min_range; + float max_range; + float resolution; + int min_interval; + int max_batch_count; + bool wakeup_supported; +} sensor_info_t; + +enum sensor_accuracy_t { + SENSOR_ACCURACY_UNDEFINED = -1, + SENSOR_ACCURACY_BAD = 0, + SENSOR_ACCURACY_NORMAL =1, + SENSOR_ACCURACY_GOOD = 2, + SENSOR_ACCURACY_VERYGOOD = 3 +}; + +#define SENSOR_DATA_VALUE_SIZE 16 + +/* sensor_data_t */ +typedef struct sensor_data_t { + int accuracy; + unsigned long long timestamp; + int value_count; + float values[SENSOR_DATA_VALUE_SIZE]; +} sensor_data_t; + +#define SENSORHUB_DATA_VALUE_SIZE 4096 + +/* sensorhub_data_t */ +typedef struct sensorhub_data_t { + int accuracy; + unsigned long long timestamp; + + /* + * Use "value_count" instead of "hub_data_size" + * which is going to be removed soon + */ + union { + int value_count; + int hub_data_size; /* deprecated */ + }; + + /* + * Use "values" instead of "hub_data" + * which is going to be removed soon + */ + union { + char values[SENSORHUB_DATA_VALUE_SIZE]; + char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ + }; +} sensorhub_data_t; + +#define SENSOR_PEDOMETER_DATA_DIFFS_SIZE 20 + +typedef struct { + int accuracy; + unsigned long long timestamp; + int value_count; /* value_count == 8 */ + float values[SENSOR_DATA_VALUE_SIZE]; + /* values = {step count, walk step count, run step count, + moving distance, calorie burned, last speed, + last stepping frequency (steps per sec), + last step status (walking, running, ...)} */ + /* Additional data attributes (not in sensor_data_t)*/ + int diffs_count; + struct differences { + int timestamp; + int steps; + int walk_steps; + int run_steps; + float distance; + float calories; + float speed; + } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; + unsigned long long accumulated_steps; + unsigned long long accumulated_walk_steps; + unsigned long long accumulated_run_steps; + double accumulated_distance; + double accumulated_calories; +} sensor_pedometer_data_t; + +enum sensor_attribute { + SENSOR_ATTR_ACTIVITY = 0x100, +}; + +enum sensor_activity { + SENSOR_ACTIVITY_UNKNOWN = 1, + SENSOR_ACTIVITY_STILL = 2, + SENSOR_ACTIVITY_WALKING = 4, + SENSOR_ACTIVITY_RUNNING = 8, + SENSOR_ACTIVITY_IN_VEHICLE = 16, + SENSOR_ACTIVITY_ON_BICYCLE = 32, +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _SENSOR_HAL_TYPES_H_ */ diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index d8628c1..cbcbc9a 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -22,6 +22,7 @@ #include #include +#include class physical_sensor : public sensor_base { public: diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 0936815..a08be8c 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index b69ca8e..5bc1c10 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include class sensor_base { diff --git a/src/shared/sensor_common.h b/src/shared/sensor_common.h index 40b95b8..e3d83ff 100644 --- a/src/shared/sensor_common.h +++ b/src/shared/sensor_common.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #define OP_ERROR -1 -- 2.7.4 From 6cc3752c971015128d8c5677f97ee88238020e32 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 10:43:55 +0900 Subject: [PATCH 04/16] sensord: skip the get_data process when there are some problems * after initializing data pointer, skip the get_data process Change-Id: Ie4fc53f7d3f529821542875ff97f6839dce0dfee Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 83e5bce..3583223 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -309,7 +309,8 @@ bool command_worker::send_cmd_get_data_done(int state, sensor_data_t *data) cmd_get_data_done = (cmd_get_data_done_t*)ret_packet->data(); cmd_get_data_done->state = state; - memcpy(&cmd_get_data_done->base_data , data, sizeof(sensor_data_t)); + if (data) + memcpy(&cmd_get_data_done->base_data, data, sizeof(sensor_data_t)); if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) { _E("Failed to send a cmd_get_data_done"); @@ -707,13 +708,17 @@ bool command_worker::cmd_get_data(void *payload) _E("Permission denied to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); state = OP_ERROR; + data = NULL; goto out; } remain_count = m_module->get_data(&data, &length); - if (remain_count < 0) + if (remain_count < 0) { state = OP_ERROR; + data = NULL; + goto out; + } // In case of not getting sensor data, wait short time and retry again // 1. changing interval to be less than 10ms -- 2.7.4 From f3df2191b4595f6f4db18579452135738cd05953 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 21 Mar 2016 18:48:08 +0900 Subject: [PATCH 05/16] sensord: in similar with the interval, sensor attributes are separately maintained for each client. Change-Id: If3ced3df21fd9cc84ae55d9d113487efa3d95895 Signed-off-by: Mu-Woong Lee --- src/server/command_worker.cpp | 5 +++-- src/server/sensor_base.cpp | 17 ++++++++++++++++- src/server/sensor_base.h | 8 ++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 3583223..48a3cb4 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -504,6 +504,7 @@ bool command_worker::cmd_stop(void *payload) if (m_module->stop()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, false); + m_module->delete_attribute(m_client_id); ret_value = OP_SUCCESS; } else { _E("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); @@ -778,7 +779,7 @@ bool command_worker::cmd_set_attribute_int(void *payload) goto out; } - ret_value = m_module->set_attribute(cmd->attribute, cmd->value); + ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value); out: if (!send_cmd_done(ret_value)) @@ -803,7 +804,7 @@ bool command_worker::cmd_set_attribute_str(void *payload) goto out; } - ret_value = m_module->set_attribute(cmd->attribute, cmd->value, cmd->value_len); + ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value, cmd->value_len); out: if (!send_cmd_done(ret_value)) diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index a08be8c..ad9ef95 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -90,7 +90,22 @@ bool sensor_base::flush(void) return true; } -int sensor_base::set_attribute(int32_t cmd, int32_t value) +int sensor_base::add_attribute(int client_id, int32_t attribute, int32_t value) +{ + return set_attribute(attribute, value); +} + +int sensor_base::add_attribute(int client_id, int32_t attribute, char *value, int value_size) +{ + return set_attribute(attribute, value, value_size); +} + +bool sensor_base::delete_attribute(int client_id) +{ + return true; +} + +int sensor_base::set_attribute(int32_t attribute, int32_t value) { return OP_ERROR; } diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 5bc1c10..0e013d1 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -52,8 +52,9 @@ public: virtual int get_data(sensor_data_t **data, int *length); virtual bool flush(void); - virtual int set_attribute(int32_t attribute, int32_t value); - virtual int set_attribute(int32_t attribute, char *value, int value_size); + virtual int add_attribute(int client_id, int32_t attribute, int32_t value); + virtual int add_attribute(int client_id, int32_t attribute, char *value, int value_size); + virtual bool delete_attribute(int client_id); /* start/stop */ bool start(void); @@ -91,6 +92,9 @@ private: unsigned int m_client; cmutex m_client_mutex; + virtual int set_attribute(int32_t attribute, int32_t value); + virtual int set_attribute(int32_t attribute, char *value, int value_size); + virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); -- 2.7.4 From ce4f6a793d5f3c70f834b8338464d079cbecb1e4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 31 Mar 2016 19:19:13 +0900 Subject: [PATCH 06/16] sensord: use memcpy instead of copying values * if value_count is over 16(max value count), it makes a problem when values is copied in loop. Change-Id: I8f07fe76909fe995027a604ac18bb9cdb6fbf827 Signed-off-by: kibak.yoon --- src/client/command_channel.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index ca6b025..da07846 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -589,15 +589,7 @@ bool command_channel::cmd_get_data(unsigned int type, sensor_data_t* sensor_data return false; } - sensor_data_t *base_data; - base_data = &cmd_get_data_done->base_data; - - sensor_data->timestamp = base_data->timestamp; - sensor_data->accuracy = base_data->accuracy; - sensor_data->value_count = base_data->value_count; - - memcpy(sensor_data->values, base_data->values, - sizeof(sensor_data->values[0]) * base_data->value_count); + memcpy(sensor_data, &cmd_get_data_done->base_data, sizeof(sensor_data_t)); delete[] (char *)cmd_get_data_done; delete packet; -- 2.7.4 From b9eb12d6aed2c693514982e383de98963f4b4f11 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 31 Mar 2016 19:32:23 +0900 Subject: [PATCH 07/16] sensor_base: add sensor event data caching for sync-read support With this patch, sync-read requests from clients do not need to call get_data() functions of HALs anymore. Change-Id: I00560691f23fe15a0d785f7597b78b75b939a930 Signed-off-by: Mu-Woong Lee --- src/server/command_worker.cpp | 27 ++++++++------------------- src/server/sensor_base.cpp | 32 ++++++++++++++++++++++++++++++++ src/server/sensor_base.h | 6 ++++++ 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 48a3cb4..d088078 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -696,30 +696,22 @@ out: bool command_worker::cmd_get_data(void *payload) { const unsigned int GET_DATA_MIN_INTERVAL = 10; - int state = OP_ERROR; - int remain_count; + int state; bool adjusted = false; int length; - sensor_data_t *data; + sensor_data_t *data = NULL; _D("CMD_GET_VALUE Handler invoked\n"); if (!is_permission_allowed()) { _E("Permission denied to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); - state = OP_ERROR; - data = NULL; + state = -EACCES; goto out; } - remain_count = m_module->get_data(&data, &length); - - if (remain_count < 0) { - state = OP_ERROR; - data = NULL; - goto out; - } + state = m_module->get_cache(&data); // In case of not getting sensor data, wait short time and retry again // 1. changing interval to be less than 10ms @@ -728,7 +720,7 @@ bool command_worker::cmd_get_data(void *payload) // 4. retrying to get data // 5. repeat 2 ~ 4 operations RETRY_CNT times // 6. reverting back to original interval - if ((remain_count >= 0) && !data->timestamp) { + if (state == -ENODATA) { const int RETRY_CNT = 10; int retry = 0; @@ -739,26 +731,23 @@ bool command_worker::cmd_get_data(void *payload) adjusted = true; } - while ((remain_count >= 0) && !data->timestamp && (retry++ < RETRY_CNT)) { + while ((state == -ENODATA) && (retry++ < RETRY_CNT)) { _I("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep(WAIT_TIME(retry)); - remain_count = m_module->get_data(&data, &length); + state = m_module->get_cache(&data); } if (adjusted) m_module->add_interval(m_client_id, interval, false); } - if (data->timestamp) - state = OP_SUCCESS; - if (state < 0) { _E("Failed to get data for client [%d], for sensor [0x%llx]", m_client_id, m_sensor_id); } out: - send_cmd_get_data_done(state, data); + send_cmd_get_data_done(state < 0 ? OP_ERROR : OP_SUCCESS, data); return true; } diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index ad9ef95..6398cd6 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -35,6 +35,7 @@ sensor_base::sensor_base() , m_permission(SENSOR_PERMISSION_STANDARD) , m_started(false) , m_client(0) +, m_last_data(NULL) { } @@ -148,6 +149,9 @@ bool sensor_base::stop(void) } m_started = false; + + free(m_last_data); + m_last_data = NULL; } _I("[%s] sensor stopped, #client = %d", get_name(), m_client); @@ -293,6 +297,8 @@ void sensor_base::set_permission(int permission) bool sensor_base::push(sensor_event_t *event) { + set_cache(event->data); + AUTOLOCK(m_client_mutex); if (m_client <= 0) @@ -302,6 +308,32 @@ bool sensor_base::push(sensor_event_t *event) return true; } +void sensor_base::set_cache(sensor_data_t *data) +{ + AUTOLOCK(m_data_cache_mutex); + + /* Caching the last known data for sync-read support */ + if (m_last_data == NULL) { + m_last_data = (sensor_data_t*)malloc(sizeof(sensor_data_t)); + retm_if(m_last_data == NULL, "Memory allocation failed"); + } + + memcpy(m_last_data, data, sizeof(sensor_data_t)); +} + +int sensor_base::get_cache(sensor_data_t **data) +{ + retv_if(m_last_data == NULL, -ENODATA); + + *data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(*data == NULL, -ENOMEM, "Memory allocation failed"); + + AUTOLOCK(m_data_cache_mutex); + + memcpy(*data, m_last_data, sizeof(sensor_data_t)); + return 0; +} + bool sensor_base::set_interval(unsigned long interval) { return true; diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 0e013d1..adbabc2 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -50,6 +50,7 @@ public: /* set/get data */ virtual int get_data(sensor_data_t **data, int *length); + int get_cache(sensor_data_t **data); virtual bool flush(void); virtual int add_attribute(int client_id, int32_t attribute, int32_t value); @@ -92,6 +93,9 @@ private: unsigned int m_client; cmutex m_client_mutex; + sensor_data_t *m_last_data; + cmutex m_data_cache_mutex; + virtual int set_attribute(int32_t attribute, int32_t value); virtual int set_attribute(int32_t attribute, char *value, int value_size); @@ -100,6 +104,8 @@ private: virtual bool on_start(void); virtual bool on_stop(void); + + void set_cache(sensor_data_t *data); }; #endif /* _SENSOR_BASE_H_ */ -- 2.7.4 From 94b72107b73db96727e7dd96ac6fa37d2613f941 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 21:15:06 +0900 Subject: [PATCH 08/16] sensord: remove unused variable - remove compliler warning. Change-Id: I47f2788ca8d09902d1f2d6342c77fd258b91412e Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index d088078..b9f5853 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -698,7 +698,6 @@ bool command_worker::cmd_get_data(void *payload) const unsigned int GET_DATA_MIN_INTERVAL = 10; int state; bool adjusted = false; - int length; sensor_data_t *data = NULL; -- 2.7.4 From 6727cdb51fe467afc1c14cc45bafc53f62e14d4c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 29 Mar 2016 00:39:13 +0900 Subject: [PATCH 09/16] sensord: fix the memory leak when get_data is failed - problem: if sensor->get_data() is failed, event memory is not freed. so there is memory-leak problem. - solution: the allocation code of the event meory is moved when it is needed. Change-Id: If42ab454c269ceab2ed64a13a9915cab23a2822e Signed-off-by: kibak.yoon --- src/server/sensor_event_poller.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp index b6d46ca..1327b44 100644 --- a/src/server/sensor_event_poller.cpp +++ b/src/server/sensor_event_poller.cpp @@ -135,7 +135,6 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids continue; while (remains > 0) { - event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); remains = sensor->get_data(&data, &data_length); if (remains < 0) { _E("Failed to get sensor data"); @@ -143,11 +142,16 @@ bool sensor_event_poller::process_event(int fd, const std::vector &ids } if (!sensor->on_event(data, data_length, remains)) { - free(event); free(data); continue; } + event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); + if (!event) { + _E("Memory allocation failed"); + break; + } + event->sensor_id = sensor->get_id(); event->event_type = sensor->get_event_type(); event->data_length = data_length; -- 2.7.4 From 6a4db3a803f927ab0561c7c3bc1ac1e651ebacb4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 22:49:00 +0900 Subject: [PATCH 10/16] sensord: set calibration at booting time if cal_node is existed * calibration is needed on tw1 device Change-Id: Ie84d5c391269352b701d882b9c163b90f76c1307 Signed-off-by: kibak.yoon --- src/server/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/server/main.cpp b/src/server/main.cpp index 504beb7..2ef0bfa 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -23,7 +23,8 @@ #include #include -using std::string; +#define CAL_NODE_PATH "/sys/class/sensors/ssp_sensor/set_cal_data" +#define SET_CAL 1 static void sig_term_handler(int signo, siginfo_t *info, void *data) { @@ -52,12 +53,31 @@ static void signal_init(void) sigaction(SIGTERM, &sig_act, NULL); } +static void set_cal_data(void) +{ + FILE *fp = fopen(CAL_NODE_PATH, "w"); + + if (!fp) { + _I("Not support calibration_node"); + return; + } + + fprintf(fp, "%d", SET_CAL); + fclose(fp); + + _I("Succeeded to set calibration data"); + + return; +} + int main(int argc, char *argv[]) { _I("Sensord started"); signal_init(); + set_cal_data(); + sensor_loader::get_instance().load(); server::get_instance().run(); -- 2.7.4 From 4fb76e4154475964d02000ce615ae93042e515c6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 1 Apr 2016 22:49:32 +0900 Subject: [PATCH 11/16] sensor-hal: sync with the latest HAL interface Change-Id: I7b718bbfd14ff39f39c6adb9b16fe7935ae339d0 Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index 9a4032b..0e73602 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -197,15 +197,14 @@ typedef struct { int steps; int walk_steps; int run_steps; + int walk_up_steps; + int walk_down_steps; + int run_up_steps; + int run_down_steps; float distance; float calories; float speed; } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; - unsigned long long accumulated_steps; - unsigned long long accumulated_walk_steps; - unsigned long long accumulated_run_steps; - double accumulated_distance; - double accumulated_calories; } sensor_pedometer_data_t; enum sensor_attribute { -- 2.7.4 From 70f41b4da9711d45a2b606d9b7ba576543ac5c16 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 4 Apr 2016 10:33:57 +0900 Subject: [PATCH 12/16] sensord: change static function to member function about get_timestamp() * there is no reason for get_timestamp() function to be static. Change-Id: Ie8531a2bcde5523f6219ffb16aa11dd25b3034fc Signed-off-by: kibak.yoon --- src/server/sensor_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index adbabc2..e5e07c7 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -79,8 +79,8 @@ public: protected: void set_permission(int permission); - static unsigned long long get_timestamp(void); - static unsigned long long get_timestamp(timeval *t); + unsigned long long get_timestamp(void); + unsigned long long get_timestamp(timeval *t); private: sensor_id_t m_id; -- 2.7.4 From 5a9bf8b8f10cb36bf458dada73df87fc2d6d0d00 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 4 Apr 2016 17:38:58 +0900 Subject: [PATCH 13/16] sensord: replace 0x% with %# - %# adds "0x" prefix according to data type Change-Id: I7d20614603c18d14e4710b04c59aaa7f10a8e7f3 Signed-off-by: kibak.yoon --- src/client/client.cpp | 22 ++++---- src/client/client_common.cpp | 4 +- src/client/command_channel.cpp | 8 +-- src/client/sensor_client_info.cpp | 4 +- src/client/sensor_event_listener.cpp | 4 +- src/client/sensor_handle_info.cpp | 6 +- src/sensor/accel/accel_sensor.cpp | 2 +- src/sensor/fusion/fusion_sensor.cpp | 6 +- src/sensor/hrm/hrm_sensor.cpp | 2 +- src/sensor/orientation/orientation_sensor.cpp | 2 +- .../rotation_vector/gaming_rv/gaming_rv_sensor.cpp | 2 +- .../geomagnetic_rv/geomagnetic_rv_sensor.cpp | 2 +- src/sensor/rotation_vector/rv/rv_sensor.cpp | 2 +- src/sensor/tilt/tilt_sensor.cpp | 2 +- src/server/client_sensor_record.cpp | 16 +++--- src/server/command_worker.cpp | 66 +++++++++++----------- src/server/sensor_base.cpp | 12 ++-- src/server/sensor_event_dispatcher.cpp | 8 +-- src/server/sensor_usage.cpp | 6 +- src/server/worker_thread.cpp | 10 ++-- src/shared/cbase_lock.cpp | 4 +- src/shared/csocket.cpp | 14 ++--- src/shared/sensor_info.cpp | 4 +- 23 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 4a8854f..79a759c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -716,7 +716,7 @@ static bool register_event(int handle, unsigned int event_type, unsigned int int if (interval == 0) interval = DEFAULT_INTERVAL; - _I("%s registers event %s[0x%x] for sensor %s[%d] with interval: %d, latency: %d, cb: 0x%x, user_data: 0x%x", + _I("%s registers event %s[%#x] for sensor %s[%d] with interval: %d, latency: %d, cb: %#x, user_data: %#x", get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle, interval, max_batch_latency, cb, user_data); @@ -759,14 +759,14 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) return false; } - _I("%s unregisters event %s[0x%x] for sensor %s[%d]", get_client_name(), get_event_name(event_type), + _I("%s unregisters event %s[%#x] for sensor %s[%d]", get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle); sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data); if (!sensor_client_info::get_instance().unregister_event(handle, event_type)) { - _E("%s try to unregister non registered event %s[0x%x] for sensor %s[%d]", + _E("%s try to unregister non registered event %s[%#x] for sensor %s[%d]", get_client_name(),get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle); return false; } @@ -796,7 +796,7 @@ API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t c } - _I("%s registers accuracy_changed_cb for sensor %s[%d] with cb: 0x%x, user_data: 0x%x", + _I("%s registers accuracy_changed_cb for sensor %s[%d] with cb: %#x, user_data: %#x", get_client_name(), get_sensor_name(sensor_id), handle, cb, user_data); sensor_client_info::get_instance().register_accuracy_cb(handle, cb , user_data); @@ -921,7 +921,7 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int if (interval == 0) interval = DEFAULT_INTERVAL; - _I("%s changes batch of event %s[0x%x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type), + _I("%s changes batch of event %s[%#x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle, interval, latency); sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep); @@ -951,11 +951,11 @@ API bool sensord_change_event_interval(int handle, unsigned int event_type, unsi AUTOLOCK(lock); if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { - _E("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type); + _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type); return false; } - _I("handle = %d, event_type = 0x%x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency); + _I("handle = %d, event_type = %#x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency); return change_event_batch(handle, event_type, interval, prev_latency); } @@ -969,7 +969,7 @@ API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_t AUTOLOCK(lock); if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data)) { - _E("Failed to get event info with handle = %d, event_type = 0x%x", handle, event_type); + _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type); return false; } @@ -1069,7 +1069,7 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, } retvm_if((value_len < 0) || (value == NULL), -EINVAL, - "Invalid value_len: %d, value: 0x%x, handle: %d, %s, %s", + "Invalid value_len: %d, value: %#x, handle: %d, %s, %s", value_len, value, handle, get_sensor_name(sensor_id), get_client_name()); client_id = sensor_client_info::get_instance().get_client_id(); @@ -1078,7 +1078,7 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, client_id, handle, get_sensor_name(sensor_id), get_client_name()); if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { - _E("Sending cmd_set_attribute_str(%d, %d, 0x%x) failed for %s", + _E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s", client_id, value_len, value, get_client_name()); return -EPERM; } @@ -1127,7 +1127,7 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso } if (!cmd_channel->cmd_get_data(data_id, sensor_data)) { - _E("cmd_get_data(%d, %d, 0x%x) failed for %s", client_id, data_id, sensor_data, get_client_name()); + _E("cmd_get_data(%d, %d, %#x) failed for %s", client_id, data_id, sensor_data, get_client_name()); return false; } diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index ae7479c..95af36e 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -60,7 +60,7 @@ const char* get_sensor_name(sensor_id_t sensor_id) auto iter = g_log_maps.find(sensor_type); if (iter == g_log_maps.end()) { - _I("Unknown type value: 0x%x", sensor_type); + _I("Unknown type value: %#x", sensor_type); return p_unknown; } @@ -75,7 +75,7 @@ const char* get_event_name(unsigned int event_type) auto iter = g_log_maps.find(sensor_type); if (iter == g_log_maps.end()) { - _I("Unknown type value: 0x%x", sensor_type); + _I("Unknown type value: %#x", sensor_type); return p_unknown; } diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp index da07846..7724278 100644 --- a/src/client/command_channel.cpp +++ b/src/client/command_channel.cpp @@ -612,18 +612,18 @@ bool command_channel::cmd_set_attribute_int(int attribute, int value) cmd_set_attribute_int->attribute = attribute; cmd_set_attribute_int->value = value; - _I("%s send cmd_set_attribute_int(client_id=%d, %s, 0x%x, %d)", + _I("%s send cmd_set_attribute_int(client_id=%d, %s, %#x, %d)", get_client_name(), m_client_id, get_sensor_name(m_sensor_id), attribute, value); if (!command_handler(packet, (void **)&cmd_done)) { - _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], attribute[0x%x], value[%d]", + _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], attribute[%#x], value[%d]", get_client_name(), get_sensor_name(m_sensor_id), m_client_id, attribute, value); delete packet; return false; } if (cmd_done->value < 0) { - _E("Client %s got error[%d] from server for sensor[%s] with attribute[0x%x], value[%d]", + _E("Client %s got error[%d] from server for sensor[%s] with attribute[%#x], value[%d]", get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), attribute, value); delete[] (char *)cmd_done; @@ -653,7 +653,7 @@ bool command_channel::cmd_set_attribute_str(int attribute, const char* value, in cmd_set_attribute_str->value_len = value_len; memcpy(cmd_set_attribute_str->value, value, value_len); - _I("%s send cmd_set_attribute_str(client_id=%d, attribute = 0x%x, value_len = %d, value = 0x%x)", + _I("%s send cmd_set_attribute_str(client_id=%d, attribute = %#x, value_len = %d, value = %#x)", get_client_name(), m_client_id, attribute, value_len, value); if (!command_handler(packet, (void **)&cmd_done)) { diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index d6133c3..e4485af 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -438,7 +438,7 @@ bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &inte } if (!active_sensor_found) { - _D("Active sensor[0x%llx] is not found for client %s", sensor, get_client_name()); + _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name()); return false; } @@ -470,7 +470,7 @@ unsigned int sensor_client_info::get_active_option(sensor_id_t sensor) } if (!active_sensor_found) - _D("Active sensor[0x%llx] is not found for client %s", sensor, get_client_name()); + _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name()); return active_option; } diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 273d0d1..56e877a 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -285,7 +285,7 @@ gboolean sensor_event_listener::callback_dispatcher(gpointer data) else if (cb_info->cb_type == SENSOR_LEGACY_CB) ((sensor_legacy_cb_t) cb_info->cb)(cb_info->event_type, (sensor_event_data_t *) cb_info->sensor_data, cb_info->user_data); } else { - _W("Discard invalid callback cb(0x%x)(%s, 0x%x, 0x%x) with id: %llu", + _W("Discard invalid callback cb(%#x)(%s, %#x, %#x) with id: %llu", cb_info->cb, get_event_name(cb_info->event_type), cb_info->sensor_data, cb_info->user_data, cb_info->event_id); } @@ -423,7 +423,7 @@ bool sensor_event_listener::create_event_channel(void) } if ((event_channel_ready.magic != CHANNEL_MAGIC_NUM) || (event_channel_ready.client_id != client_id)) { - _E("Event_channel_ready packet is wrong, magic = 0x%x, client id = %d", + _E("Event_channel_ready packet is wrong, magic = %#x, client id = %d", event_channel_ready.magic, event_channel_ready.client_id); return false; } diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index f24b74a..2263ee0 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -70,7 +70,7 @@ bool sensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned in auto it_event = m_reg_event_infos.find(event_type); if (it_event != m_reg_event_infos.end()) { - _E("Event %s[0x%x] is already registered for client %s", get_event_name(event_type), event_type, get_client_name()); + _E("Event %s[%#x] is already registered for client %s", get_event_name(event_type), event_type, get_client_name()); return false; } @@ -93,7 +93,7 @@ bool sensor_handle_info::delete_reg_event_info(unsigned int event_type) auto it_event = m_reg_event_infos.find(event_type); if (it_event == m_reg_event_infos.end()) { - _E("Event %s[0x%x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); + _E("Event %s[%#x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); return false; } @@ -118,7 +118,7 @@ bool sensor_handle_info::change_reg_event_batch(unsigned int event_type, unsigne auto it_event = m_reg_event_infos.find(event_type); if (it_event == m_reg_event_infos.end()) { - _E("Event %s[0x%x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); + _E("Event %s[%#x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name()); return false; } diff --git a/src/sensor/accel/accel_sensor.cpp b/src/sensor/accel/accel_sensor.cpp index 4fe9f5b..90fd8bd 100644 --- a/src/sensor/accel/accel_sensor.cpp +++ b/src/sensor/accel/accel_sensor.cpp @@ -23,7 +23,7 @@ accel_sensor::accel_sensor() { - _E("accel_sensor is created : 0x%x", this); + _E("accel_sensor is created : %#x", this); } accel_sensor::~accel_sensor() diff --git a/src/sensor/fusion/fusion_sensor.cpp b/src/sensor/fusion/fusion_sensor.cpp index 5766a04..0a90e58 100644 --- a/src/sensor/fusion/fusion_sensor.cpp +++ b/src/sensor/fusion/fusion_sensor.cpp @@ -169,15 +169,15 @@ bool fusion_sensor::init(void) m_magnetic_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); if (!m_accel_sensor) { - _E("Failed to load accel sensor: 0x%x", m_accel_sensor); + _E("Failed to load accel sensor: %#x", m_accel_sensor); return false; } if (!m_gyro_sensor) - _I("Failed to load gyro sensor: 0x%x", m_gyro_sensor); + _I("Failed to load gyro sensor: %#x", m_gyro_sensor); if (!m_magnetic_sensor) - _I("Failed to load geomagnetic sensor: 0x%x", m_magnetic_sensor); + _I("Failed to load geomagnetic sensor: %#x", m_magnetic_sensor); _I("%s is created!", sensor_base::get_name()); return true; diff --git a/src/sensor/hrm/hrm_sensor.cpp b/src/sensor/hrm/hrm_sensor.cpp index 908f1b5..0425226 100644 --- a/src/sensor/hrm/hrm_sensor.cpp +++ b/src/sensor/hrm/hrm_sensor.cpp @@ -25,7 +25,7 @@ hrm_sensor::hrm_sensor() { set_permission(SENSOR_PERMISSION_BIO); - _I("hrm_sensor is created : 0x%x", this); + _I("hrm_sensor is created : %#x", this); } hrm_sensor::~hrm_sensor() diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index 7ace6ee..091cb12 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -131,7 +131,7 @@ bool orientation_sensor::init(void) m_fusion_sensor = sensor_loader::get_instance().get_sensor(FUSION_SENSOR); if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor || !m_fusion_sensor) { - _E("Failed to load sensors, accel: 0x%x, gyro: 0x%x, mag: 0x%x, fusion: 0x%x", + _E("Failed to load sensors, accel: %#x, gyro: %#x, mag: %#x, fusion: %#x", m_accel_sensor, m_gyro_sensor, m_magnetic_sensor, m_fusion_sensor); return false; } diff --git a/src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.cpp b/src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.cpp index 3fd0268..b2d4e99 100644 --- a/src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.cpp @@ -132,7 +132,7 @@ bool gaming_rv_sensor::init() m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); if (!m_accel_sensor || !m_gyro_sensor) { - _E("Failed to load sensors, accel: 0x%x, gyro: 0x%x", + _E("Failed to load sensors, accel: %#x, gyro: %#x", m_accel_sensor, m_gyro_sensor); return false; } diff --git a/src/sensor/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp b/src/sensor/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp index e7cbfb3..a97b949 100644 --- a/src/sensor/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/geomagnetic_rv/geomagnetic_rv_sensor.cpp @@ -91,7 +91,7 @@ bool geomagnetic_rv_sensor::init() m_fusion_sensor = sensor_loader::get_instance().get_sensor(FUSION_SENSOR); if (!m_accel_sensor || !m_magnetic_sensor || !m_fusion_sensor) { - _E("Failed to load sensors, accel: 0x%x, mag: 0x%x, fusion: 0x%x", + _E("Failed to load sensors, accel: %#x, mag: %#x, fusion: %#x", m_accel_sensor, m_magnetic_sensor, m_fusion_sensor); return false; } diff --git a/src/sensor/rotation_vector/rv/rv_sensor.cpp b/src/sensor/rotation_vector/rv/rv_sensor.cpp index 79b5cc5..1008ed3 100644 --- a/src/sensor/rotation_vector/rv/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv/rv_sensor.cpp @@ -99,7 +99,7 @@ bool rv_sensor::init() m_fusion_sensor = sensor_loader::get_instance().get_sensor(FUSION_SENSOR); if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor || !m_fusion_sensor) { - _E("Failed to load sensors, accel: 0x%x, gyro: 0x%x, mag: 0x%x, fusion: 0x%x", + _E("Failed to load sensors, accel: %#x, gyro: %#x, mag: %#x, fusion: %#x", m_accel_sensor, m_gyro_sensor, m_magnetic_sensor, m_fusion_sensor); return false; } diff --git a/src/sensor/tilt/tilt_sensor.cpp b/src/sensor/tilt/tilt_sensor.cpp index e37a448..d236350 100644 --- a/src/sensor/tilt/tilt_sensor.cpp +++ b/src/sensor/tilt/tilt_sensor.cpp @@ -112,7 +112,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: 0x%x, fusion: 0x%x", + _E("Failed to load sensors, accel: %#x, fusion: %#x", m_accel_sensor, m_fusion_sensor); return false; } diff --git a/src/server/client_sensor_record.cpp b/src/server/client_sensor_record.cpp index 58fde54..95001bb 100644 --- a/src/server/client_sensor_record.cpp +++ b/src/server/client_sensor_record.cpp @@ -49,7 +49,7 @@ bool client_sensor_record::register_event(sensor_id_t sensor_id, unsigned int ev } if (!it_usage->second.register_event(event_type)) { - _E("Event[0x%x] is already registered", event_type); + _E("Event[%#x] is already registered", event_type); return false; } @@ -61,12 +61,12 @@ bool client_sensor_record::unregister_event(sensor_id_t sensor_id, unsigned int auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { - _E("Sensor[0x%x] is not registered", sensor_id); + _E("Sensor[%#x] is not registered", sensor_id); return false; } if (!it_usage->second.unregister_event(event_type)) { - _E("Event[0x%x] is already registered", event_type); + _E("Event[%#x] is already registered", event_type); return false; } @@ -136,7 +136,7 @@ bool client_sensor_record::get_batch(sensor_id_t sensor_id, unsigned int &interv auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { - _E("Sensor[0x%x] is not found", sensor_id); + _E("Sensor[%#x] is not found", sensor_id); return false; } @@ -164,7 +164,7 @@ bool client_sensor_record::add_sensor_usage(sensor_id_t sensor_id) auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage != m_sensor_usages.end()) { - _E("Sensor[0x%x] is already registered", sensor_id); + _E("Sensor[%#x] is already registered", sensor_id); return false; } @@ -178,7 +178,7 @@ bool client_sensor_record::remove_sensor_usage(sensor_id_t sensor_id) auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { - _E("Sensor[0x%x] is not found", sensor_id); + _E("Sensor[%#x] is not found", sensor_id); return false; } m_sensor_usages.erase(it_usage); @@ -199,7 +199,7 @@ bool client_sensor_record::has_sensor_usage(sensor_id_t sensor_id) auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { - _D("Sensor[0x%x] is not found", sensor_id); + _D("Sensor[%#x] is not found", sensor_id); return false; } @@ -212,7 +212,7 @@ bool client_sensor_record::get_registered_events(sensor_id_t sensor_id, event_ty auto it_usage = m_sensor_usages.find(sensor_id); if (it_usage == m_sensor_usages.end()) { - _D("Sensor[0x%x] is not found", sensor_id); + _D("Sensor[%#x] is not found", sensor_id); return false; } diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index b9f5853..83c3f8b 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -222,7 +222,7 @@ bool command_worker::stopped(void *ctx) if (inst->m_sensor_id > UNKNOWN_SENSOR) { if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) { - _I("Removing sensor[0x%llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); + _I("Removing sensor[%#llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id); get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id); } } @@ -331,7 +331,7 @@ bool command_worker::send_cmd_get_sensor_list_done(void) int permission = get_permission(); - _I("permission = 0x%x", permission); + _I("permission = %#x", permission); get_sensor_list(permission, sensor_list); @@ -410,14 +410,14 @@ bool command_worker::cmd_hello(void *payload) } if (!is_permission_allowed()) { - _E("Permission denied to connect sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Permission denied to connect sensor[%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - _D("Hello sensor [0x%llx], client id [%d]", m_sensor_id, m_client_id); + _D("Hello sensor [%#llx], client id [%d]", m_sensor_id, m_client_id); get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id); - _I("New sensor record created for sensor [0x%llx], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id); + _I("New sensor record created for sensor [%#llx], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id); ret_value = OP_SUCCESS; out: if (!send_cmd_done(ret_value)) @@ -431,12 +431,12 @@ bool command_worker::cmd_byebye(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - _E("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Permission denied to stop sensor[%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - _D("CMD_BYEBYE for client [%d], sensor [0x%llx]", m_client_id, m_sensor_id); + _D("CMD_BYEBYE for client [%d], sensor [%#llx]", m_client_id, m_sensor_id); if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) { _E("Error removing sensor_record for client [%d]", m_client_id); @@ -462,12 +462,12 @@ bool command_worker::cmd_start(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - _E("Permission denied to start sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Permission denied to start sensor[%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - _D("START Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id); + _D("START Sensor [%#llx], called from client [%d]", m_sensor_id, m_client_id); if (m_module->start()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, true); @@ -479,7 +479,7 @@ bool command_worker::cmd_start(void *payload) get_event_dispathcher().request_last_event(m_client_id, m_sensor_id); ret_value = OP_SUCCESS; } else { - _E("Failed to start sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Failed to start sensor [%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -495,19 +495,19 @@ bool command_worker::cmd_stop(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - _E("Permission denied to stop sensor[0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Permission denied to stop sensor[%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; goto out; } - _D("STOP Sensor [0x%llx], called from client [%d]", m_sensor_id, m_client_id); + _D("STOP Sensor [%#llx], called from client [%d]", m_sensor_id, m_client_id); if (m_module->stop()) { get_client_info_manager().set_start(m_client_id, m_sensor_id, false); m_module->delete_attribute(m_client_id); ret_value = OP_SUCCESS; } else { - _E("Failed to stop sensor [0x%llx] for client [%d]", m_sensor_id, m_client_id); + _E("Failed to stop sensor [%#llx] for client [%d]", m_sensor_id, m_client_id); ret_value = OP_ERROR; } @@ -526,21 +526,21 @@ bool command_worker::cmd_register_event(void *payload) cmd = (cmd_reg_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to register event [0x%x] for client [%d] to client info manager", + _E("Permission denied to register event [%#x] for client [%d] to client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) { - _I("Failed to register event [0x%x] for client [%d] to client info manager", + _I("Failed to register event [%#x] for client [%d] to client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; goto out; } ret_value = OP_SUCCESS; - _D("Registering Event [0x%x] is done for client [%d]", cmd->event_type, m_client_id); + _D("Registering Event [%#x] is done for client [%d]", cmd->event_type, m_client_id); out: if (!send_cmd_done(ret_value)) @@ -557,21 +557,21 @@ bool command_worker::cmd_unregister_event(void *payload) cmd = (cmd_unreg_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to unregister event [0x%x] for client [%d] to client info manager", + _E("Permission denied to unregister event [%#x] for client [%d] to client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) { - _E("Failed to unregister event [0x%x] for client [%d] from client info manager", + _E("Failed to unregister event [%#x] for client [%d] from client info manager", cmd->event_type, m_client_id); ret_value = OP_ERROR; goto out; } ret_value = OP_SUCCESS; - _D("Unregistering Event [0x%x] is done for client [%d]", + _D("Unregistering Event [%#x] is done for client [%d]", cmd->event_type, m_client_id); out: @@ -589,28 +589,28 @@ bool command_worker::cmd_set_batch(void *payload) cmd = (cmd_set_batch_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager", + _E("Permission denied to set batch for client [%d], for sensor [%#llx] with batch [%d, %d] to client info manager", m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) { - _E("Failed to set batch for client [%d], for sensor [0x%llx] with batch [%d, %d] to client info manager", + _E("Failed to set batch for client [%d], for sensor [%#llx] with batch [%d, %d] to client info manager", m_client_id, m_sensor_id, cmd->interval, cmd->latency); ret_value = OP_ERROR; goto out; } if (!m_module->add_interval(m_client_id, cmd->interval, false)) { - _E("Failed to set interval for client [%d], for sensor [0x%llx] with interval [%d]", + _E("Failed to set interval for client [%d], for sensor [%#llx] with interval [%d]", m_client_id, m_sensor_id, cmd->interval); ret_value = OP_ERROR; goto out; } if (!m_module->add_batch(m_client_id, cmd->latency)) { - _E("Failed to set latency for client [%d], for sensor [0x%llx] with latency [%d]", + _E("Failed to set latency for client [%d], for sensor [%#llx] with latency [%d]", m_client_id, m_sensor_id, cmd->latency); ret_value = OP_ERROR; goto out; @@ -630,14 +630,14 @@ bool command_worker::cmd_unset_batch(void *payload) long ret_value = OP_ERROR; if (!is_permission_allowed()) { - _E("Permission denied to unset batch for client [%d], for sensor [0x%llx] to client info manager", + _E("Permission denied to unset batch for client [%d], for sensor [%#llx] to client info manager", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) { - _E("Failed to unset batch for client [%d], for sensor [0x%llx] to client info manager", + _E("Failed to unset batch for client [%d], for sensor [%#llx] to client info manager", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; @@ -672,14 +672,14 @@ bool command_worker::cmd_set_option(void *payload) cmd = (cmd_set_option_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to set interval for client [%d], for sensor [0x%llx] with option [%d] to client info manager", + _E("Permission denied to set interval for client [%d], for sensor [%#llx] with option [%d] to client info manager", m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; } if (!get_client_info_manager().set_option(m_client_id, m_sensor_id, cmd->option)) { - _E("Failed to set option for client [%d], for sensor [0x%llx] with option [%d] to client info manager", + _E("Failed to set option for client [%d], for sensor [%#llx] with option [%d] to client info manager", m_client_id, m_sensor_id, cmd->option); ret_value = OP_ERROR; goto out; @@ -704,7 +704,7 @@ bool command_worker::cmd_get_data(void *payload) _D("CMD_GET_VALUE Handler invoked\n"); if (!is_permission_allowed()) { - _E("Permission denied to get data for client [%d], for sensor [0x%llx]", + _E("Permission denied to get data for client [%d], for sensor [%#llx]", m_client_id, m_sensor_id); state = -EACCES; goto out; @@ -731,7 +731,7 @@ bool command_worker::cmd_get_data(void *payload) } while ((state == -ENODATA) && (retry++ < RETRY_CNT)) { - _I("Wait sensor[0x%llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); + _I("Wait sensor[%#llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry); usleep(WAIT_TIME(retry)); state = m_module->get_cache(&data); } @@ -741,7 +741,7 @@ bool command_worker::cmd_get_data(void *payload) } if (state < 0) { - _E("Failed to get data for client [%d], for sensor [0x%llx]", + _E("Failed to get data for client [%d], for sensor [%#llx]", m_client_id, m_sensor_id); } @@ -761,7 +761,7 @@ bool command_worker::cmd_set_attribute_int(void *payload) cmd = (cmd_set_attribute_int_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to set attribute for client [%d], for sensor [0x%llx] with attribute [%d]", + _E("Permission denied to set attribute for client [%d], for sensor [%#llx] with attribute [%d]", m_client_id, m_sensor_id, cmd->attribute); ret_value = OP_ERROR; goto out; @@ -786,7 +786,7 @@ bool command_worker::cmd_set_attribute_str(void *payload) cmd = (cmd_set_attribute_str_t*)payload; if (!is_permission_allowed()) { - _E("Permission denied to set attribute for client [%d], for sensor [0x%llx]", + _E("Permission denied to set attribute for client [%d], for sensor [%#llx]", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; @@ -808,7 +808,7 @@ bool command_worker::cmd_flush(void *payload) _D("CMD_FLUSH Handler invoked"); if (!is_permission_allowed()) { - _E("Permission denied to flush sensor data for client [%d], for sensor [0x%llx]", + _E("Permission denied to flush sensor data for client [%d], for sensor [%#llx]", m_client_id, m_sensor_id); ret_value = OP_ERROR; goto out; diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 6398cd6..0af356d 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -180,7 +180,7 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro cur_min = m_sensor_info_list.get_min_interval(); if (cur_min != prev_min) { - _I("Min interval for sensor[0x%llx] is changed from %dms to %dms" + _I("Min interval for sensor[%#llx] is changed from %dms to %dms" " by%sclient[%d] adding interval", get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); @@ -204,14 +204,14 @@ bool sensor_base::delete_interval(int client_id, bool is_processor) cur_min = m_sensor_info_list.get_min_interval(); if (!cur_min) { - _I("No interval for sensor[0x%llx] by%sclient[%d] deleting interval, " + _I("No interval for sensor[%#llx] by%sclient[%d] deleting interval, " "so set to default %dms", get_id(), is_processor ? " processor " : " ", client_id, POLL_1HZ_MS); set_interval(POLL_1HZ_MS); } else if (cur_min != prev_min) { - _I("Min interval for sensor[0x%llx] is changed from %dms to %dms" + _I("Min interval for sensor[%#llx] is changed from %dms to %dms" " by%sclient[%d] deleting interval", get_id(), prev_min, cur_min, is_processor ? " processor " : " ", client_id); @@ -243,7 +243,7 @@ bool sensor_base::add_batch(int client_id, unsigned int latency) cur_max = m_sensor_info_list.get_max_batch(); if (cur_max != prev_max) { - _I("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] adding latency", + _I("Max latency for sensor[%#llx] is changed from %dms to %dms by client[%d] adding latency", get_id(), prev_max, cur_max, client_id); set_batch_latency(cur_max); } @@ -264,12 +264,12 @@ bool sensor_base::delete_batch(int client_id) cur_max = m_sensor_info_list.get_max_batch(); if (!cur_max) { - _I("No latency for sensor[0x%llx] by client[%d] deleting latency, so set to default 0 ms", + _I("No latency for sensor[%#llx] by client[%d] deleting latency, so set to default 0 ms", get_id(), client_id); set_batch_latency(0); } else if (cur_max != prev_max) { - _I("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] deleting latency", + _I("Max latency for sensor[%#llx] is changed from %dms to %dms by client[%d] deleting latency", get_id(), prev_max, cur_max, client_id); set_batch_latency(cur_max); diff --git a/src/server/sensor_event_dispatcher.cpp b/src/server/sensor_event_dispatcher.cpp index 977a657..c1c401a 100644 --- a/src/server/sensor_event_dispatcher.cpp +++ b/src/server/sensor_event_dispatcher.cpp @@ -169,9 +169,9 @@ void sensor_event_dispatcher::send_sensor_events(vector &events) ret = (ret & (client_socket.send(sensor_event->data, sensor_event->data_length) > 0)); if (ret) - _D("Event[0x%x] sent to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); + _D("Event[%#x] sent to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); else - _E("Failed to send event[0x%x] to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); + _E("Failed to send event[%#x] to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd()); ++it_client_id; } @@ -261,10 +261,10 @@ void sensor_event_dispatcher::request_last_event(int client_id, sensor_id_t sens sensor_event_t event; if (is_record_event(*it_event) && get_last_event(*it_event, event)) { if (client_socket.send(&event, sizeof(event)) > 0) - _I("Send the last event[0x%x] to %s on socket[%d]", event.event_type, + _I("Send the last event[%#x] to %s on socket[%d]", event.event_type, client_info_manager.get_client_info(client_id), client_socket.get_socket_fd()); else - _E("Failed to send event[0x%x] to %s on socket[%d]", event.event_type, + _E("Failed to send event[%#x] to %s on socket[%d]", event.event_type, client_info_manager.get_client_info(client_id), client_socket.get_socket_fd()); } ++it_event; diff --git a/src/server/sensor_usage.cpp b/src/server/sensor_usage.cpp index 83ead8d..77d2cce 100644 --- a/src/server/sensor_usage.cpp +++ b/src/server/sensor_usage.cpp @@ -40,7 +40,7 @@ bool sensor_usage::register_event(unsigned int event_type) auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type); if (it_event != m_reg_events.end()) { - _E("Event[0x%x] is already registered", event_type); + _E("Event[%#x] is already registered", event_type); return false; } @@ -53,7 +53,7 @@ bool sensor_usage::unregister_event(unsigned int event_type) auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type); if (it_event == m_reg_events.end()) { - _E("Event[0x%x] is not found",event_type); + _E("Event[%#x] is not found",event_type); return false; } @@ -67,7 +67,7 @@ bool sensor_usage::is_event_registered(unsigned int event_type) auto it_event = find (m_reg_events.begin(), m_reg_events.end(), event_type); if (it_event == m_reg_events.end()){ - _D("Event[0x%x] is not registered",event_type); + _D("Event[%#x] is not registered",event_type); return false; } diff --git a/src/server/worker_thread.cpp b/src/server/worker_thread.cpp index afd188c..bf3320c 100644 --- a/src/server/worker_thread.cpp +++ b/src/server/worker_thread.cpp @@ -153,7 +153,7 @@ bool worker_thread::resume(void) void worker_thread::main(void) { - _D("Worker thread(0x%x) is created", std::this_thread::get_id()); + _D("Worker thread(%#x) is created", std::this_thread::get_id()); transition_function(STARTED); @@ -164,7 +164,7 @@ void worker_thread::main(void) if (state == WORKER_STATE_WORKING) { if (!transition_function(WORKING)) { m_state = WORKER_STATE_STOPPED; - _D("Worker thread(0x%x) exits from working state", std::this_thread::get_id()); + _D("Worker thread(%#x) exits from working state", std::this_thread::get_id()); m_thread_created = false; transition_function(STOPPED); break; @@ -177,12 +177,12 @@ void worker_thread::main(void) if (m_state == WORKER_STATE_PAUSED) { transition_function(PAUSED); - _D("Worker thread(0x%x) is paused", std::this_thread::get_id()); + _D("Worker thread(%#x) is paused", std::this_thread::get_id()); m_cond_working.wait(u); if (m_state == WORKER_STATE_WORKING) { transition_function(RESUMED); - _D("Worker thread(0x%x) is resumed", std::this_thread::get_id()); + _D("Worker thread(%#x) is resumed", std::this_thread::get_id()); } else if (m_state == WORKER_STATE_STOPPED) { m_thread_created = false; transition_function(STOPPED); @@ -194,7 +194,7 @@ void worker_thread::main(void) break; } } - _I("Worker thread(0x%x)'s main is terminated", std::this_thread::get_id()); + _I("Worker thread(%#x)'s main is terminated", std::this_thread::get_id()); } void worker_thread::set_started(trans_func_t func) diff --git a/src/shared/cbase_lock.cpp b/src/shared/cbase_lock.cpp index f30ce18..e7bcc95 100644 --- a/src/shared/cbase_lock.cpp +++ b/src/shared/cbase_lock.cpp @@ -64,7 +64,7 @@ void cbase_lock::lock(lock_type type, const char* expr, const char *module, cons lock_waiting_start_time = MICROSECONDS(sv); pthread_mutex_lock(&m_history_mutex); - _I("%s is waiting for getting %s(0x%x) owned in %s", + _I("%s is waiting for getting %s(%#x) owned in %s", m_curent_info, expr, this, m_owner_info); pthread_mutex_unlock(&m_history_mutex); @@ -82,7 +82,7 @@ void cbase_lock::lock(lock_type type, const char* expr, const char *module, cons waiting_time = lock_acquired_time - lock_waiting_start_time; pthread_mutex_lock(&m_history_mutex); - _I("%s acquires lock after waiting %lluus, %s(0x%x) was previously owned in %s", + _I("%s acquires lock after waiting %lluus, %s(%#x) was previously owned in %s", m_curent_info, waiting_time, expr, this, m_owner_info); snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info); pthread_mutex_unlock(&m_history_mutex); diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 23bcdd4..199a722 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -159,7 +159,7 @@ ssize_t csocket::send_for_seqpacket(const void *buffer, size_t size) const } while (err == EINTR); if (err) { - _ERRNO(errno, _E, "Failed to send(%d, 0x%x, %d, 0x%x) = %d", + _ERRNO(errno, _E, "Failed to send(%d, %#x, %d, %#x) = %d", m_sock_fd, buffer, size, m_send_flags, len); } @@ -176,7 +176,7 @@ ssize_t csocket::recv_for_seqpacket(void* buffer, size_t size) const if (len > 0) { err = 0; } else if (len == 0) { - _E("recv(%d, 0x%p , %d) = %d, because the peer performed shutdown!", + _E("recv(%d, %#p , %d) = %d, because the peer performed shutdown!", m_sock_fd, buffer, size, len); err = 1; } else { @@ -185,13 +185,13 @@ ssize_t csocket::recv_for_seqpacket(void* buffer, size_t size) const } while (err == EINTR); if ((err == EAGAIN) || (err == EWOULDBLOCK)) { - _ERRNO(err, _D, "Failed to recv(%d, 0x%x, %d, 0x%x) = %d", + _ERRNO(err, _D, "Failed to recv(%d, %#x, %d, %#x) = %d", m_socket_fd, buffer, size, m_recv_flags, len); return 0; } if (err) { - _ERRNO(err, _E, "Failed to recv(%d, 0x%x, %d, 0x%x) = %d", + _ERRNO(err, _E, "Failed to recv(%d, %#x, %d, %#x) = %d", m_sock_fd, buffer, size, m_recv_flags, len); } @@ -212,7 +212,7 @@ ssize_t csocket::send_for_stream(const void *buffer, size_t size) const total_sent_size += len; err = 0; } else { - _ERRNO(errno, _E, "Failed to send(%d, 0x%p + %d, %d - %d) = %d for %s", + _ERRNO(errno, _E, "Failed to send(%d, %#p + %d, %d - %d) = %d for %s", m_sock_fd, buffer, total_sent_size, size, total_sent_size, len, get_client_name()); @@ -238,12 +238,12 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const if (len > 0) { total_recv_size += len; } else if (len == 0) { - _E("recv(%d, 0x%p + %d, %d - %d) = %d, because the peer of %s performed shutdown!", + _E("recv(%d, %#p + %d, %d - %d) = %d, because the peer of %s performed shutdown!", m_sock_fd, buffer, total_recv_size, size, total_recv_size, len, get_client_name()); err = 1; break; } else { - _ERRNO(errno, _E, "Failed to recv(%d, 0x%p + %d, %d - %d) = %d for %s", + _ERRNO(errno, _E, "Failed to recv(%d, %#p + %d, %d - %d) = %d for %s", m_sock_fd, buffer, total_recv_size, size, total_recv_size, len, get_client_name()); diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index eae3bde..f7c241a 100644 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -211,7 +211,7 @@ void sensor_info::set_raw_data(const char *data, int data_len) void sensor_info::show(void) { _I("Type = %d", m_type); - _I("ID = 0x%llx", (int64_t)m_id); + _I("ID = %#llx", (int64_t)m_id); _I("Privilege = %d", (int)m_privilege); _I("Name = %s", m_name.c_str()); _I("Vendor = %s", m_vendor.c_str()); @@ -221,7 +221,7 @@ void sensor_info::show(void) _I("Min_interval = %d", m_min_interval); _I("Fifo_count = %d", m_fifo_count); _I("Max_batch_count = %d", m_max_batch_count); - _I("Supported_event = 0x%x", m_supported_event); + _I("Supported_event = %#x", m_supported_event); _I("Wakeup_supported = %d", m_wakeup_supported); } -- 2.7.4 From 2f18f5a17af85c0b0c70d77c7a800f9ee14d6cef Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 4 Apr 2016 22:30:33 +0900 Subject: [PATCH 14/16] sensorctl test Change-Id: Ibec35d870f89260eaeeaa39a98dfcc488d536373 Signed-off-by: kibak.yoon --- CMakeLists.txt | 1 + packaging/sensord.spec | 1 + src/sensorctl/CMakeLists.txt | 28 ++++ src/sensorctl/dbus_util.cpp | 107 +++++++++++++++ src/sensorctl/dbus_util.h | 30 +++++ src/sensorctl/info_manager.cpp | 93 +++++++++++++ src/sensorctl/info_manager.h | 34 +++++ src/sensorctl/injector.h | 32 +++++ src/sensorctl/injector_context_orientation.cpp | 60 +++++++++ src/sensorctl/injector_context_orientation.h | 32 +++++ src/sensorctl/injector_manager.cpp | 130 +++++++++++++++++++ src/sensorctl/injector_manager.h | 58 +++++++++ src/sensorctl/injector_wristup_algo.cpp | 77 +++++++++++ src/sensorctl/injector_wristup_algo.h | 33 +++++ src/sensorctl/injector_wristup_conf.cpp | 59 +++++++++ src/sensorctl/injector_wristup_conf.h | 34 +++++ src/sensorctl/macro.h | 22 ++++ src/sensorctl/sensor_manager.cpp | 172 +++++++++++++++++++++++++ src/sensorctl/sensor_manager.h | 34 +++++ src/sensorctl/sensorctl.cpp | 96 ++++++++++++++ src/sensorctl/sensorctl_log.h | 52 ++++++++ src/sensorctl/tester.h | 28 ++++ src/sensorctl/tester_auto.cpp | 83 ++++++++++++ src/sensorctl/tester_auto.h | 36 ++++++ src/sensorctl/tester_manager.cpp | 79 ++++++++++++ src/sensorctl/tester_manager.h | 32 +++++ src/sensorctl/tester_sensor.cpp | 152 ++++++++++++++++++++++ src/sensorctl/tester_sensor.h | 34 +++++ 28 files changed, 1629 insertions(+) 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_wristup_algo.cpp create mode 100644 src/sensorctl/injector_wristup_algo.h create mode 100644 src/sensorctl/injector_wristup_conf.cpp create mode 100644 src/sensorctl/injector_wristup_conf.h create mode 100644 src/sensorctl/macro.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_auto.cpp create mode 100644 src/sensorctl/tester_auto.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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 591edb4..7dc8b5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,3 +18,4 @@ 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 5bc4a2b..722db6b 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -149,6 +149,7 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %defattr(-,root,root,-) %{_bindir}/api-test %{_bindir}/sensor-test +%{_bindir}/sensorctl %{_bindir}/multi-thread-performance-test %{_bindir}/multi-process-performance-test %{_bindir}/fusion-data-collection diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt new file mode 100644 index 0000000..28ee9d2 --- /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} -fPIE") + +# 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..b35ce8c --- /dev/null +++ b/src/sensorctl/info_manager.cpp @@ -0,0 +1,93 @@ +/* + * 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 "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); + + delete 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..799e07a --- /dev/null +++ b/src/sensorctl/injector_context_orientation.cpp @@ -0,0 +1,60 @@ +/* + * 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 +#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..9757013 --- /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]; + strcpy(options[i], 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_wristup_algo.cpp b/src/sensorctl/injector_wristup_algo.cpp new file mode 100644 index 0000000..db7b272 --- /dev/null +++ b/src/sensorctl/injector_wristup_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_wristup_algo.h" + +#define WRISTUP_ALGO_SIGNAL "algo" +#define OPTION_INDEX 0 + +typedef std::map option_map_t; +static option_map_t option_map; + +bool injector_wristup_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_wristup_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 *)WRISTUP_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_wristup_algo) diff --git a/src/sensorctl/injector_wristup_algo.h b/src/sensorctl/injector_wristup_algo.h new file mode 100644 index 0000000..dcf3c0c --- /dev/null +++ b/src/sensorctl/injector_wristup_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_wristup_algo: public injector_interface { +public: + injector_wristup_algo() {} + virtual ~injector_wristup_algo() {} + + bool init(void); + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/injector_wristup_conf.cpp b/src/sensorctl/injector_wristup_conf.cpp new file mode 100644 index 0000000..7c55b40 --- /dev/null +++ b/src/sensorctl/injector_wristup_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_wristup_conf.h" + +#define WRISTUP_CONF_SIGNAL "conf" + +bool injector_wristup_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 *)WRISTUP_CONF_SIGNAL, + variant, + NULL); + + PRINT("set options to wristup: \n"); + for(int i=0; i +#include +#include "injector.h" + +#define NAME_MAX_TEST 32 + +class injector_wristup_conf: public injector_interface { +public: + injector_wristup_conf() {} + virtual ~injector_wristup_conf() {} + + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/macro.h b/src/sensorctl/macro.h new file mode 100644 index 0000000..6895a35 --- /dev/null +++ b/src/sensorctl/macro.h @@ -0,0 +1,22 @@ +/* + * 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 // _COMMON_H_ + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp new file mode 100644 index 0000000..8bb7c61 --- /dev/null +++ b/src/sensorctl/sensor_manager.cpp @@ -0,0 +1,172 @@ +/* + * 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 "sensor_manager.h" + +#define NAME_MAX_TEST 32 + +struct sensor_info { + sensor_type_t type; + char name[NAME_MAX_TEST]; + /* if manual is true, the way of injecting fake event will be created */ + bool manual; +}; + +static struct sensor_info sensor_infos[] = { + {ALL_SENSOR, "all", false}, + + // General Sensors + {ACCELEROMETER_SENSOR, "accelerometer", false}, + {GRAVITY_SENSOR, "gravity", false}, + {LINEAR_ACCEL_SENSOR, "linear_accel", false}, + {GEOMAGNETIC_SENSOR, "magnetic", false}, + {ROTATION_VECTOR_SENSOR, "rotation_vector", false}, + {ORIENTATION_SENSOR, "orientation", false}, + {GYROSCOPE_SENSOR, "gyroscope", false}, + {LIGHT_SENSOR, "light", false}, + {PROXIMITY_SENSOR, "proximity", true}, + {PRESSURE_SENSOR, "pressure", false}, + {ULTRAVIOLET_SENSOR, "ultraviolet", false}, + {TEMPERATURE_SENSOR, "temperature", false}, + {HUMIDITY_SENSOR, "humidity", false}, + {HRM_RAW_SENSOR, "hrm_raw", false}, + {HRM_SENSOR, "hrm", false}, + {HRM_LED_GREEN_SENSOR, "hrm_led_green", false}, + {HRM_LED_IR_SENSOR, "hrm_led_ir", false}, + {HRM_LED_RED_SENSOR, "hrm_led_red", false}, + {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal", false}, + {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal", false}, + {GYROSCOPE_RV_SENSOR, "gyro_rv", false}, + {GEOMAGNETIC_RV_SENSOR, "mag_rv", false}, + + {HUMAN_PEDOMETER_SENSOR, "pedo", true}, + {HUMAN_SLEEP_MONITOR_SENSOR,"sleep_monitor", true}, + + /* + {AUTO_ROTATION_SENSOR, "auto_rotation", true}, + {AUTO_BRIGHTNESS_SENSOR, "auto_brightness", true}, + {MOTION_SENSOR, "motion", true}, + {PIR_SENSOR, "pir", true}, + {PIR_LONG_SENSOR, "pir_long", true}, + {DUST_SENSOR, "dust", false}, + {THERMOMETER_SENSOR, "thermometer", false}, + {FLAT_SENSOR, "flat", true}, + {TILT_SENSOR, "tilt", false}, + {RV_RAW_SENSOR, "rv_raw", false}, + {EXERCISE_SENSOR, "exercise", false}, + {GSR_SENSOR, "gsr", false}, + {SIMSENSE_SENSOR, "simsense", false}, + {PPG_SENSOR, "ppg", false}, + + {GESTURE_MOVEMENT_SENSOR, "movement", true}, + {GESTURE_WRIST_UP_SENSOR, "wristup", true}, + {GESTURE_WRIST_DOWN_SENSOR, "wristdown", true}, + {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state",true}, + + {WEAR_STATUS_SENSOR, "wear_status", true}, + {WEAR_ON_MONITOR_SENSOR, "wear_on", true}, + {GPS_BATCH_SENSOR, "gps_batch", true}, + {ACTIVITY_TRACKER_SENSOR, "activity_tracker", true}, + {SLEEP_DETECTOR_SENSOR, "sleep_detector", true}, + {NO_MOVE_DETECTOR_SENSOR, "no_move", true}, + {HRM_CTRL_SENSOR, "hrm_ctrl", true}, + {EXERCISE_COACH_SENSOR, "ex_coach", true}, + {EXERCISE_HR_SENSOR, "ex_hr", true}, + {RESTING_HR_SENSOR, "resting_hr", true}, + {STEP_LEVEL_MONITOR_SENSOR, "step_level", true}, + {ACTIVITY_LEVEL_MONITOR_SENSOR, "activity", true}, + {CYCLE_MONITOR_SENSOR, "cycle", true}, + {STRESS_MONITOR_SENSOR, "stress", true}, + {AUTOSESSION_EXERCISE_SENSOR,"autosesstion", true}, + {STAIR_TRACKER_SENSOR, "stair_tracker", true} + */ + +}; + +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); + + if (is_number(name)) + return (sensor_type_t) (atoi(name)); + + 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; +} + +bool sensor_manager::is_number(char *value) +{ + if (value == NULL || *value == 0) + return false; + + while (*value) { + if (*value < '0' || *value > '9') + return false; + value++; + } + + return true; +} diff --git a/src/sensorctl/sensor_manager.h b/src/sensorctl/sensor_manager.h new file mode 100644 index 0000000..2a9c937 --- /dev/null +++ b/src/sensorctl/sensor_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 // _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); +private: + bool is_number(char *value); +}; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp new file mode 100644 index 0000000..f01ff64 --- /dev/null +++ b/src/sensorctl/sensorctl.cpp @@ -0,0 +1,96 @@ +/* + * 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" + +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"); +} + +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 (!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..2172c66 --- /dev/null +++ b/src/sensorctl/sensorctl_log.h @@ -0,0 +1,52 @@ +/* + * 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 RED(str) KRED str RESET; +#define GRN(str) KGRN str RESET; + +#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_auto.cpp b/src/sensorctl/tester_auto.cpp new file mode 100644 index 0000000..b6b4bc7 --- /dev/null +++ b/src/sensorctl/tester_auto.cpp @@ -0,0 +1,83 @@ +/* + * 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 + +static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + +} + +static void test_func(const char *name, std::function func) +{ + bool ret = func(); + + /* + if (ret) PRINT(GRN "[PASS] %s", name); + else PRINT(RED "[FAIL] %s", name); + */ +} + +static bool operate_sensor(sensor_type_t type) +{ + sensor_t sensor = sensord_get_sensor(type); + return false; +} + +static bool start_sensor(sensor_t sensor) +{ + return false; +} + +static bool read_sensor(sensor_t sensor) +{ + return false; +} + +static bool is_supported(sensor_type_t type, sensor_t sensor) +{ + return false; +} + +bool tester_auto::init(void) +{ + return true; +} + +bool tester_auto::test(sensor_type_t type, int option_count, char *options[]) +{ + /* + sensor_t *list = sensord_get_sensors(ALL_SENSOR); + for (int i = 0; i< ARRAY_SIZE(list); ++i) { + sensor_type_t type = sensord_get_type(list[i]); + */ + sensor_t sensor = sensord_get_sensor(ACCELEROMETER_SENSOR); + test_func("SENSOR_NAME", std::bind(operate_sensor, ACCELEROMETER_SENSOR)); + test_func("SENSOR_NAME", std::bind(start_sensor, sensor)); + test_func("SENSOR_NAME", std::bind(read_sensor, sensor)); + test_func("SENSOR_NAME", std::bind(is_supported, ACCELEROMETER_SENSOR, sensor)); + //} +} diff --git a/src/sensorctl/tester_auto.h b/src/sensorctl/tester_auto.h new file mode 100644 index 0000000..77045ab --- /dev/null +++ b/src/sensorctl/tester_auto.h @@ -0,0 +1,36 @@ +/* + * 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_AUTO_H_ + +#include +#include +#include +#include + +#include "tester.h" + +class tester_auto : public tester_interface { +public: + tester_auto() {} + virtual ~tester_auto() {} + + virtual bool init(void); + virtual bool test(sensor_type_t type, int option_count, char *options[]); +}; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp new file mode 100644 index 0000000..495ff1e --- /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]; + strcpy(options[i], 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..905c1ec --- /dev/null +++ b/src/sensorctl/tester_sensor.cpp @@ -0,0 +1,152 @@ +/* + * 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 "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); +}; -- 2.7.4 From 3adb660ed137a0cf56bcdce09b7e6e37c36b8ec4 Mon Sep 17 00:00:00 2001 From: Kibak Yoon Date: Mon, 4 Apr 2016 18:25:42 -0700 Subject: [PATCH 15/16] Revert "sensorctl test" This reverts commit 2f18f5a17af85c0b0c70d77c7a800f9ee14d6cef. Change-Id: I8806d63b95156b4d9402eae26502ba24b1921657 --- CMakeLists.txt | 1 - packaging/sensord.spec | 1 - src/sensorctl/CMakeLists.txt | 28 ---- src/sensorctl/dbus_util.cpp | 107 --------------- src/sensorctl/dbus_util.h | 30 ----- src/sensorctl/info_manager.cpp | 93 ------------- src/sensorctl/info_manager.h | 34 ----- src/sensorctl/injector.h | 32 ----- src/sensorctl/injector_context_orientation.cpp | 60 --------- src/sensorctl/injector_context_orientation.h | 32 ----- src/sensorctl/injector_manager.cpp | 130 ------------------- src/sensorctl/injector_manager.h | 58 --------- src/sensorctl/injector_wristup_algo.cpp | 77 ----------- src/sensorctl/injector_wristup_algo.h | 33 ----- src/sensorctl/injector_wristup_conf.cpp | 59 --------- src/sensorctl/injector_wristup_conf.h | 34 ----- src/sensorctl/macro.h | 22 ---- src/sensorctl/sensor_manager.cpp | 172 ------------------------- src/sensorctl/sensor_manager.h | 34 ----- src/sensorctl/sensorctl.cpp | 96 -------------- src/sensorctl/sensorctl_log.h | 52 -------- src/sensorctl/tester.h | 28 ---- src/sensorctl/tester_auto.cpp | 83 ------------ src/sensorctl/tester_auto.h | 36 ------ src/sensorctl/tester_manager.cpp | 79 ------------ src/sensorctl/tester_manager.h | 32 ----- src/sensorctl/tester_sensor.cpp | 152 ---------------------- src/sensorctl/tester_sensor.h | 34 ----- 28 files changed, 1629 deletions(-) delete mode 100644 src/sensorctl/CMakeLists.txt delete mode 100644 src/sensorctl/dbus_util.cpp delete mode 100644 src/sensorctl/dbus_util.h delete mode 100644 src/sensorctl/info_manager.cpp delete mode 100644 src/sensorctl/info_manager.h delete mode 100644 src/sensorctl/injector.h delete mode 100644 src/sensorctl/injector_context_orientation.cpp delete mode 100644 src/sensorctl/injector_context_orientation.h delete mode 100644 src/sensorctl/injector_manager.cpp delete mode 100644 src/sensorctl/injector_manager.h delete mode 100644 src/sensorctl/injector_wristup_algo.cpp delete mode 100644 src/sensorctl/injector_wristup_algo.h delete mode 100644 src/sensorctl/injector_wristup_conf.cpp delete mode 100644 src/sensorctl/injector_wristup_conf.h delete mode 100644 src/sensorctl/macro.h delete mode 100644 src/sensorctl/sensor_manager.cpp delete mode 100644 src/sensorctl/sensor_manager.h delete mode 100644 src/sensorctl/sensorctl.cpp delete mode 100644 src/sensorctl/sensorctl_log.h delete mode 100644 src/sensorctl/tester.h delete mode 100644 src/sensorctl/tester_auto.cpp delete mode 100644 src/sensorctl/tester_auto.h delete mode 100644 src/sensorctl/tester_manager.cpp delete mode 100644 src/sensorctl/tester_manager.h delete mode 100644 src/sensorctl/tester_sensor.cpp delete mode 100644 src/sensorctl/tester_sensor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dc8b5a..591edb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,3 @@ 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 722db6b..5bc4a2b 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -149,7 +149,6 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %defattr(-,root,root,-) %{_bindir}/api-test %{_bindir}/sensor-test -%{_bindir}/sensorctl %{_bindir}/multi-thread-performance-test %{_bindir}/multi-process-performance-test %{_bindir}/fusion-data-collection diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt deleted file mode 100644 index 28ee9d2..0000000 --- a/src/sensorctl/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -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} -fPIE") - -# 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 deleted file mode 100644 index 886872e..0000000 --- a/src/sensorctl/dbus_util.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include - -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 deleted file mode 100644 index a51d903..0000000 --- a/src/sensorctl/dbus_util.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _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 deleted file mode 100644 index b35ce8c..0000000 --- a/src/sensorctl/info_manager.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "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); - - delete 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 deleted file mode 100644 index b71dfc0..0000000 --- a/src/sensorctl/info_manager.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _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 deleted file mode 100644 index f9e8b40..0000000 --- a/src/sensorctl/injector.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _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 deleted file mode 100644 index 799e07a..0000000 --- a/src/sensorctl/injector_context_orientation.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 -#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 deleted file mode 100644 index 9757013..0000000 --- a/src/sensorctl/injector_manager.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "dbus_util.h" -#include "injector.h" -#include "injector_manager.h" - -#define NAME_MAX_TEST 32 -#define ARGC_BASE 4 /* e.g. {sensorctl, inject, wristup, conf} */ - -static std::vector injector_infos; - -injector_manager::injector_manager() -{ - if (!dbus_init()) { - _E("Failed to init dbus"); - throw; - } -} - -injector_manager::~injector_manager() -{ - dbus_fini(); -} - -bool injector_manager::register_injector(injector_info info) -{ - injector_infos.push_back(info); - return true; -} - -injector_interface *injector_manager::get_injector(sensor_type_t type, const char *name) -{ - int injector_count; - injector_count = injector_infos.size(); - - for (int i = 0; i < injector_count; ++i) { - if (type == injector_infos[i].type && - !strcmp(injector_infos[i].name, name)) - return injector_infos[i].injector; - } - return NULL; -} - -bool injector_manager::process(int argc, char *argv[]) -{ - int option_count; - char *options[8]; - bool result; - sensor_type_t type; - char *event_name; - int i; - - if (argc < 4) { - usage(); - return false; - } - - /* 1. get sensor type */ - type = get_sensor_type(argv[2]); - if (type == UNKNOWN_SENSOR) { - _E("ERROR : failed to process injector\n"); - return false; - } - - /* 2. set up injector */ - event_name = argv[3]; - - injector_interface *injector = get_injector(type, event_name); - if (injector == NULL) { - _E("ERROR: cannot find matched injector\n"); - return false; - } - - /* 3. init injector */ - result = injector->init(); - if (!result) { - _E("ERROR: failed to init injector\n"); - return false; - } - - /* 4. inject event with options */ - option_count = argc - ARGC_BASE; - for (i = 0; i < option_count; ++i) { - options[i] = new char[NAME_MAX_TEST]; - strcpy(options[i], argv[ARGC_BASE+i]); - } - - result = injector->inject(option_count, options); - if (!result) { - _E("ERROR : failed to process injector\n"); - for (i = 0; i < option_count; ++i) - delete options[i]; - - return false; - } - - for (i = 0; i < option_count; ++i) - delete options[i]; - - return true; -} - -void injector_manager::usage(void) -{ - PRINT("usage: sensorctl inject [] []\n\n"); - - usage_sensors(); -} - diff --git a/src/sensorctl/injector_manager.h b/src/sensorctl/injector_manager.h deleted file mode 100644 index 380c486..0000000 --- a/src/sensorctl/injector_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _INJECT_MANAGER_H_ - -#include -#include -#include "injector.h" -#include "sensor_manager.h" - -#define REGISTER_INJECTOR(sensor_type, sensor_name, injector_type) \ -static void __attribute__((constructor)) reg_injector(void) \ -{ \ - struct injector_info info; \ - info.type = (sensor_type); \ - info.name = (sensor_name); \ - info.injector = new(std::nothrow) (injector_type)(); \ - if (!info.injector) { \ - _E("ERROR: Failed to allocate memory(%s)", #injector_type); \ - return; \ - } \ - injector_manager::register_injector(info); \ -} - -struct injector_info { - sensor_type_t type; - const char *name; - injector_interface *injector; -}; - -class injector_manager : public sensor_manager { -public: - injector_manager(); - virtual ~injector_manager(); - - bool process(int argc, char *argv[]); - - static bool register_injector(injector_info info); -private: - injector_interface *get_injector(sensor_type_t type, const char *name); - void usage(void); -}; diff --git a/src/sensorctl/injector_wristup_algo.cpp b/src/sensorctl/injector_wristup_algo.cpp deleted file mode 100644 index db7b272..0000000 --- a/src/sensorctl/injector_wristup_algo.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "dbus_util.h" -#include "injector_manager.h" -#include "injector_wristup_algo.h" - -#define WRISTUP_ALGO_SIGNAL "algo" -#define OPTION_INDEX 0 - -typedef std::map option_map_t; -static option_map_t option_map; - -bool injector_wristup_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_wristup_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 *)WRISTUP_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_wristup_algo) diff --git a/src/sensorctl/injector_wristup_algo.h b/src/sensorctl/injector_wristup_algo.h deleted file mode 100644 index dcf3c0c..0000000 --- a/src/sensorctl/injector_wristup_algo.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _WRISTUP_INJECTOR_H_ - -#include -#include -#include "injector.h" - -class injector_wristup_algo: public injector_interface { -public: - injector_wristup_algo() {} - virtual ~injector_wristup_algo() {} - - bool init(void); - bool inject(int option_count, char *options[]); -}; diff --git a/src/sensorctl/injector_wristup_conf.cpp b/src/sensorctl/injector_wristup_conf.cpp deleted file mode 100644 index 7c55b40..0000000 --- a/src/sensorctl/injector_wristup_conf.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "dbus_util.h" -#include "injector_manager.h" -#include "injector_wristup_conf.h" - -#define WRISTUP_CONF_SIGNAL "conf" - -bool injector_wristup_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 *)WRISTUP_CONF_SIGNAL, - variant, - NULL); - - PRINT("set options to wristup: \n"); - for(int i=0; i -#include -#include "injector.h" - -#define NAME_MAX_TEST 32 - -class injector_wristup_conf: public injector_interface { -public: - injector_wristup_conf() {} - virtual ~injector_wristup_conf() {} - - bool inject(int option_count, char *options[]); -}; diff --git a/src/sensorctl/macro.h b/src/sensorctl/macro.h deleted file mode 100644 index 6895a35..0000000 --- a/src/sensorctl/macro.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 // _COMMON_H_ - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp deleted file mode 100644 index 8bb7c61..0000000 --- a/src/sensorctl/sensor_manager.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "sensor_manager.h" - -#define NAME_MAX_TEST 32 - -struct sensor_info { - sensor_type_t type; - char name[NAME_MAX_TEST]; - /* if manual is true, the way of injecting fake event will be created */ - bool manual; -}; - -static struct sensor_info sensor_infos[] = { - {ALL_SENSOR, "all", false}, - - // General Sensors - {ACCELEROMETER_SENSOR, "accelerometer", false}, - {GRAVITY_SENSOR, "gravity", false}, - {LINEAR_ACCEL_SENSOR, "linear_accel", false}, - {GEOMAGNETIC_SENSOR, "magnetic", false}, - {ROTATION_VECTOR_SENSOR, "rotation_vector", false}, - {ORIENTATION_SENSOR, "orientation", false}, - {GYROSCOPE_SENSOR, "gyroscope", false}, - {LIGHT_SENSOR, "light", false}, - {PROXIMITY_SENSOR, "proximity", true}, - {PRESSURE_SENSOR, "pressure", false}, - {ULTRAVIOLET_SENSOR, "ultraviolet", false}, - {TEMPERATURE_SENSOR, "temperature", false}, - {HUMIDITY_SENSOR, "humidity", false}, - {HRM_RAW_SENSOR, "hrm_raw", false}, - {HRM_SENSOR, "hrm", false}, - {HRM_LED_GREEN_SENSOR, "hrm_led_green", false}, - {HRM_LED_IR_SENSOR, "hrm_led_ir", false}, - {HRM_LED_RED_SENSOR, "hrm_led_red", false}, - {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal", false}, - {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal", false}, - {GYROSCOPE_RV_SENSOR, "gyro_rv", false}, - {GEOMAGNETIC_RV_SENSOR, "mag_rv", false}, - - {HUMAN_PEDOMETER_SENSOR, "pedo", true}, - {HUMAN_SLEEP_MONITOR_SENSOR,"sleep_monitor", true}, - - /* - {AUTO_ROTATION_SENSOR, "auto_rotation", true}, - {AUTO_BRIGHTNESS_SENSOR, "auto_brightness", true}, - {MOTION_SENSOR, "motion", true}, - {PIR_SENSOR, "pir", true}, - {PIR_LONG_SENSOR, "pir_long", true}, - {DUST_SENSOR, "dust", false}, - {THERMOMETER_SENSOR, "thermometer", false}, - {FLAT_SENSOR, "flat", true}, - {TILT_SENSOR, "tilt", false}, - {RV_RAW_SENSOR, "rv_raw", false}, - {EXERCISE_SENSOR, "exercise", false}, - {GSR_SENSOR, "gsr", false}, - {SIMSENSE_SENSOR, "simsense", false}, - {PPG_SENSOR, "ppg", false}, - - {GESTURE_MOVEMENT_SENSOR, "movement", true}, - {GESTURE_WRIST_UP_SENSOR, "wristup", true}, - {GESTURE_WRIST_DOWN_SENSOR, "wristdown", true}, - {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state",true}, - - {WEAR_STATUS_SENSOR, "wear_status", true}, - {WEAR_ON_MONITOR_SENSOR, "wear_on", true}, - {GPS_BATCH_SENSOR, "gps_batch", true}, - {ACTIVITY_TRACKER_SENSOR, "activity_tracker", true}, - {SLEEP_DETECTOR_SENSOR, "sleep_detector", true}, - {NO_MOVE_DETECTOR_SENSOR, "no_move", true}, - {HRM_CTRL_SENSOR, "hrm_ctrl", true}, - {EXERCISE_COACH_SENSOR, "ex_coach", true}, - {EXERCISE_HR_SENSOR, "ex_hr", true}, - {RESTING_HR_SENSOR, "resting_hr", true}, - {STEP_LEVEL_MONITOR_SENSOR, "step_level", true}, - {ACTIVITY_LEVEL_MONITOR_SENSOR, "activity", true}, - {CYCLE_MONITOR_SENSOR, "cycle", true}, - {STRESS_MONITOR_SENSOR, "stress", true}, - {AUTOSESSION_EXERCISE_SENSOR,"autosesstion", true}, - {STAIR_TRACKER_SENSOR, "stair_tracker", true} - */ - -}; - -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); - - if (is_number(name)) - return (sensor_type_t) (atoi(name)); - - 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; -} - -bool sensor_manager::is_number(char *value) -{ - if (value == NULL || *value == 0) - return false; - - while (*value) { - if (*value < '0' || *value > '9') - return false; - value++; - } - - return true; -} diff --git a/src/sensorctl/sensor_manager.h b/src/sensorctl/sensor_manager.h deleted file mode 100644 index 2a9c937..0000000 --- a/src/sensorctl/sensor_manager.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _SENSOR_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); -private: - bool is_number(char *value); -}; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp deleted file mode 100644 index f01ff64..0000000 --- a/src/sensorctl/sensorctl.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include - -#include -#include "sensor_manager.h" -#include "tester_manager.h" -#include "injector_manager.h" -#include "info_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"); -} - -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 (!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 deleted file mode 100644 index 2172c66..0000000 --- a/src/sensorctl/sensorctl_log.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _SENSORCTL_LOG_H_ - -#include -#include - -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KYEL "\x1B[33m" -#define KBLU "\x1B[34m" -#define KMAG "\x1B[35m" -#define KCYN "\x1B[36m" -#define KWHT "\x1B[37m" -#define RESET "\033[0m" - -#define RED(str) KRED str RESET; -#define GRN(str) KGRN str RESET; - -#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 deleted file mode 100644 index 2d912c9..0000000 --- a/src/sensorctl/tester.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _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_auto.cpp b/src/sensorctl/tester_auto.cpp deleted file mode 100644 index b6b4bc7..0000000 --- a/src/sensorctl/tester_auto.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - -} - -static void test_func(const char *name, std::function func) -{ - bool ret = func(); - - /* - if (ret) PRINT(GRN "[PASS] %s", name); - else PRINT(RED "[FAIL] %s", name); - */ -} - -static bool operate_sensor(sensor_type_t type) -{ - sensor_t sensor = sensord_get_sensor(type); - return false; -} - -static bool start_sensor(sensor_t sensor) -{ - return false; -} - -static bool read_sensor(sensor_t sensor) -{ - return false; -} - -static bool is_supported(sensor_type_t type, sensor_t sensor) -{ - return false; -} - -bool tester_auto::init(void) -{ - return true; -} - -bool tester_auto::test(sensor_type_t type, int option_count, char *options[]) -{ - /* - sensor_t *list = sensord_get_sensors(ALL_SENSOR); - for (int i = 0; i< ARRAY_SIZE(list); ++i) { - sensor_type_t type = sensord_get_type(list[i]); - */ - sensor_t sensor = sensord_get_sensor(ACCELEROMETER_SENSOR); - test_func("SENSOR_NAME", std::bind(operate_sensor, ACCELEROMETER_SENSOR)); - test_func("SENSOR_NAME", std::bind(start_sensor, sensor)); - test_func("SENSOR_NAME", std::bind(read_sensor, sensor)); - test_func("SENSOR_NAME", std::bind(is_supported, ACCELEROMETER_SENSOR, sensor)); - //} -} diff --git a/src/sensorctl/tester_auto.h b/src/sensorctl/tester_auto.h deleted file mode 100644 index 77045ab..0000000 --- a/src/sensorctl/tester_auto.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _TESTER_AUTO_H_ - -#include -#include -#include -#include - -#include "tester.h" - -class tester_auto : public tester_interface { -public: - tester_auto() {} - virtual ~tester_auto() {} - - virtual bool init(void); - virtual bool test(sensor_type_t type, int option_count, char *options[]); -}; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp deleted file mode 100644 index 495ff1e..0000000 --- a/src/sensorctl/tester_manager.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "tester.h" -#include "tester_manager.h" -#include "tester_sensor.h" - -#define NAME_MAX_TEST 32 -#define ARGC_BASE 3 /* e.g. {sensorctl, test, accelerometer} */ - -bool tester_manager::process(int argc, char *argv[]) -{ - int option_count; - char *options[8]; - sensor_type_t type; - int i; - - if (argc == 2) { - usage(); - return false; - } - - /* 1. get sensor type */ - type = get_sensor_type(argv[2]); - if (type == UNKNOWN_SENSOR) { - _E("ERROR : failed to process injector\n"); - return false; - } - - /* 2. set up injector */ - tester_interface *tester = new tester_sensor(); - tester->init(); - - /* 3. test sensor with options */ - option_count = argc - ARGC_BASE; - for (i = 0; i < option_count; ++i) { - options[i] = new char[NAME_MAX_TEST]; - strcpy(options[i], 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 deleted file mode 100644 index 16f4b16..0000000 --- a/src/sensorctl/tester_manager.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _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 deleted file mode 100644 index 905c1ec..0000000 --- a/src/sensorctl/tester_sensor.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "tester_sensor.h" - -#define DEFAULT_INTERVAL 100 -#define DEFAULT_LATENCY 0 -#define DEFAULT_TEST_COUNT 1 -#define DEFAULT_EVENT_COUNT 9999 - -#define SENSOR_SHIFT_TYPE 16 - -static GMainLoop *mainloop; -static int check_loop; - -static const char *result_str(bool result) { - if (result) return KGRN"[PASS]"RESET; - else return KRED"[FAIL]"RESET; -} - -bool tester_sensor::init(void) -{ - return true; -} - -void tester_sensor::test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t type; - int *cnt_event; - - sensord_get_type(sensor, &type); - - cnt_event = (int *)user_data; - - if (check_loop++ >= *cnt_event) { - if (!mainloop) - return; - - g_main_loop_quit(mainloop); - g_main_loop_unref(mainloop); - mainloop = NULL; - return; - } - - PRINT("[%llu] %s:", data->timestamp, sensord_get_name(sensor)); - - if (type == GESTURE_WRIST_UP_SENSOR) { - PRINT("[%d]\n", ((sensorhub_data_t *)data)->hub_data[0]); - return; - } - - for (int i = 0; i < data->value_count; ++i) - PRINT(" [%f]", data->values[i]); - PRINT("\n"); -} - -void tester_sensor::test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event) -{ - bool result; - sensor_t sensor; - unsigned int event_id; - sensor_data_t data; - int handle; - int count = 0; - - event_id = type << SENSOR_SHIFT_TYPE | 0x1; - - while (count++ < cnt_test) { - mainloop = g_main_loop_new(NULL, FALSE); - check_loop = 0; - - PRINT("=======================================\n"); - PRINT("TEST(%d/%d)\n", count, cnt_test); - PRINT("=======================================\n"); - - sensor = sensord_get_sensor(type); - PRINT("%s sensord_get_sensor: sensor(%p)\n", result_str(sensor==NULL?0:1), sensor); - - handle = sensord_connect(sensor); - PRINT("%s sensord_connect: handle(%d)\n", result_str((handle >= 0)), handle); - - result = sensord_register_event(handle, event_id, interval, latency, test_cb, (void *)&cnt_event); - PRINT("%s sensord_register_event\n", result_str(result)); - - result = sensord_start(handle, 3); - PRINT("%s sensord_start\n", result_str(result)); - - result = sensord_get_data(handle, event_id, &data); - PRINT("%s sensord_get_data\n", result_str(result)); - - result = sensord_flush(handle); - PRINT("%s sensord_flush\n", result_str(result)); - - if (result) { - for (int i = 0; i < data.value_count; ++i) - PRINT("[%f] ", data.values[i]); - PRINT("\n"); - } - - g_main_loop_run(mainloop); - - result = sensord_unregister_event(handle, event_id); - PRINT("%s sensord_unregister_event: handle(%d)\n", result_str(result), handle); - result = sensord_stop(handle); - PRINT("%s sensord_stop: handle(%d)\n", result_str(result), handle); - result = sensord_disconnect(handle); - PRINT("%s sensord_disconnect: handle(%d)\n", result_str(result), handle); - } -} - -bool tester_sensor::test(sensor_type_t type, int option_count, char *options[]) -{ - int interval = DEFAULT_INTERVAL; - int latency = DEFAULT_LATENCY; - int cnt_test = DEFAULT_TEST_COUNT; - int cnt_event = DEFAULT_EVENT_COUNT; - - sensor_type_t sensor_type = type; - - if (option_count >= 1) - interval = atoi(options[0]); - if (option_count >= 2) - cnt_event = atoi(options[1]); - if (option_count >= 3) - cnt_test = atoi(options[2]); - - test_sensor(sensor_type, interval, latency, cnt_test, cnt_event); - return true; -} diff --git a/src/sensorctl/tester_sensor.h b/src/sensorctl/tester_sensor.h deleted file mode 100644 index 68b76b4..0000000 --- a/src/sensorctl/tester_sensor.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * sensorctl - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#pragma once // _SENSOR_TESTER_H_ - -#include "tester.h" - -class tester_sensor : public tester_interface { -public: - tester_sensor() {} - virtual ~tester_sensor() {} - - virtual bool init(void); - virtual bool test(sensor_type_t type, int option_count, char *options[]); -private: - void test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event); - static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); -}; -- 2.7.4 From adbf0f1ce69972479ad3e318038eb10023b7f57a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 5 Apr 2016 16:36:30 +0900 Subject: [PATCH 16/16] sensord: change default return value to true for additional commands/HAL APIs - set_interval(uint32_t id, unsigned long val) - set_batch_latency(uint32_t id, unsigned - set_attribute_int(uint32_t id, int32_t attribute, int32_t value) - set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len) - flush(uint32_r id) Change-Id: I63d9110f950948a4ff3a4236b2afef285202a92d Signed-off-by: kibak.yoon --- src/hal/sensor_hal.h | 10 +++++----- src/server/sensor_base.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hal/sensor_hal.h b/src/hal/sensor_hal.h index 21eb205..e557687 100644 --- a/src/hal/sensor_hal.h +++ b/src/hal/sensor_hal.h @@ -52,23 +52,23 @@ public: virtual bool set_interval(uint32_t id, unsigned long val) { - return false; + return true; } virtual bool set_batch_latency(uint32_t id, unsigned long val) { - return false; + return true; } virtual bool set_attribute_int(uint32_t id, int32_t attribute, int32_t value) { - return false; + return true; } virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len) { - return false; + return true; } virtual bool flush(uint32_t id) { - return false; + return true; } }; diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 0af356d..dcc6623 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -108,12 +108,12 @@ bool sensor_base::delete_attribute(int client_id) int sensor_base::set_attribute(int32_t attribute, int32_t value) { - return OP_ERROR; + return OP_SUCCESS; } int sensor_base::set_attribute(int32_t attribute, char *value, int value_size) { - return OP_ERROR; + return OP_SUCCESS; } bool sensor_base::start() -- 2.7.4