From 5cb9b01b7ae6c559300f7dc5f1666bba9b791848 Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 28 Oct 2015 13:01:58 +0530 Subject: [PATCH] Adding interface file and updating the corresponding files Change-Id: I8f91282995b2ff49195ae9b2c15b740df6635a42 --- src/plugins/accel/accel_sensor.cpp | 2 +- src/plugins/bio_led_red/bio_led_red_sensor.cpp | 2 +- src/plugins/geo/geo_sensor.cpp | 2 +- src/plugins/gyro/gyro_sensor.cpp | 2 +- src/plugins/light/light_sensor.cpp | 2 +- src/plugins/pressure/pressure_sensor.cpp | 2 +- src/plugins/proxi/proxi_sensor.cpp | 2 +- .../rotation_vector/rv_raw/rv_raw_sensor.cpp | 2 +- src/plugins/temperature/temperature_sensor.cpp | 2 +- src/plugins/ultraviolet/ultraviolet_sensor.cpp | 2 +- src/shared/sensor_hal.cpp | 404 --------------------- src/shared/sensor_hal.h | 86 +---- 12 files changed, 17 insertions(+), 493 deletions(-) delete mode 100644 src/shared/sensor_hal.cpp diff --git a/src/plugins/accel/accel_sensor.cpp b/src/plugins/accel/accel_sensor.cpp index 0db4c12..8bd5451 100755 --- a/src/plugins/accel/accel_sensor.cpp +++ b/src/plugins/accel/accel_sensor.cpp @@ -98,7 +98,7 @@ bool accel_sensor::process_event(void) { sensor_event_t base_event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(base_event.data); diff --git a/src/plugins/bio_led_red/bio_led_red_sensor.cpp b/src/plugins/bio_led_red/bio_led_red_sensor.cpp index 07006c7..42405b8 100755 --- a/src/plugins/bio_led_red/bio_led_red_sensor.cpp +++ b/src/plugins/bio_led_red/bio_led_red_sensor.cpp @@ -75,7 +75,7 @@ bool bio_led_red_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/geo/geo_sensor.cpp b/src/plugins/geo/geo_sensor.cpp index 6d9c170..7c9f670 100755 --- a/src/plugins/geo/geo_sensor.cpp +++ b/src/plugins/geo/geo_sensor.cpp @@ -84,7 +84,7 @@ bool geo_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/gyro/gyro_sensor.cpp b/src/plugins/gyro/gyro_sensor.cpp index 2cb2859..aeab006 100755 --- a/src/plugins/gyro/gyro_sensor.cpp +++ b/src/plugins/gyro/gyro_sensor.cpp @@ -87,7 +87,7 @@ bool gyro_sensor::process_event(void) { sensor_event_t event; - if (m_sensor_hal->is_data_ready(true) == false) + if (m_sensor_hal->is_data_ready() == false) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/light/light_sensor.cpp b/src/plugins/light/light_sensor.cpp index e0a61f1..0b9062e 100755 --- a/src/plugins/light/light_sensor.cpp +++ b/src/plugins/light/light_sensor.cpp @@ -87,7 +87,7 @@ bool light_sensor::process_event(void) sensor_event_t event; int level; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/pressure/pressure_sensor.cpp b/src/plugins/pressure/pressure_sensor.cpp index 0559021..33f3b76 100755 --- a/src/plugins/pressure/pressure_sensor.cpp +++ b/src/plugins/pressure/pressure_sensor.cpp @@ -117,7 +117,7 @@ bool pressure_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/proxi/proxi_sensor.cpp b/src/plugins/proxi/proxi_sensor.cpp index 9486de7..ab11ee3 100755 --- a/src/plugins/proxi/proxi_sensor.cpp +++ b/src/plugins/proxi/proxi_sensor.cpp @@ -74,7 +74,7 @@ bool proxi_sensor::process_event(void) sensor_event_t event; int state; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp b/src/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp index f1b3a2b..3b9b09e 100755 --- a/src/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp +++ b/src/plugins/rotation_vector/rv_raw/rv_raw_sensor.cpp @@ -82,7 +82,7 @@ bool rv_raw_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/temperature/temperature_sensor.cpp b/src/plugins/temperature/temperature_sensor.cpp index 5b09eb1..679be58 100755 --- a/src/plugins/temperature/temperature_sensor.cpp +++ b/src/plugins/temperature/temperature_sensor.cpp @@ -81,7 +81,7 @@ bool temperature_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/plugins/ultraviolet/ultraviolet_sensor.cpp b/src/plugins/ultraviolet/ultraviolet_sensor.cpp index e47dc9d..0b0cd43 100755 --- a/src/plugins/ultraviolet/ultraviolet_sensor.cpp +++ b/src/plugins/ultraviolet/ultraviolet_sensor.cpp @@ -82,7 +82,7 @@ bool ultraviolet_sensor::process_event(void) { sensor_event_t event; - if (!m_sensor_hal->is_data_ready(true)) + if (!m_sensor_hal->is_data_ready()) return true; m_sensor_hal->get_sensor_data(event.data); diff --git a/src/shared/sensor_hal.cpp b/src/shared/sensor_hal.cpp deleted file mode 100644 index dc4fcfb..0000000 --- a/src/shared/sensor_hal.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include - -using std::ifstream; -using std::ofstream; -using std::fstream; -using std::string; - -cmutex sensor_hal::m_shared_mutex; - -sensor_hal::sensor_hal() -{ -} - -sensor_hal::~sensor_hal() -{ -} - -bool sensor_hal::init(void *data) -{ - return true; -} - -bool sensor_hal::is_wakeup_supported(void) -{ - return false; -} - -bool sensor_hal::set_interval(unsigned long val) -{ - return true; -} - -long sensor_hal::set_command(unsigned int cmd, long val) -{ - return -1; -} - -bool sensor_hal::set_wakeup(int wakeup) -{ - return false; -} - -int sensor_hal::send_sensorhub_data(const char* data, int data_len) -{ - return -1; -} - -int sensor_hal::get_sensor_data(sensor_data_t &data) -{ - return -1; -} - -int sensor_hal::get_sensor_data(sensorhub_data_t &data) -{ - return -1; -} - -unsigned long long sensor_hal::get_timestamp(void) -{ - struct timespec t; - clock_gettime(CLOCK_MONOTONIC, &t); - return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000; -} - -unsigned long long sensor_hal::get_timestamp(timeval *t) -{ - if (!t) { - ERR("t is NULL"); - return 0; - } - - return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec); -} - -bool sensor_hal::is_sensorhub_controlled(const string &key) -{ - string key_node = string("/sys/class/sensors/ssp_sensor/") + key; - - if (access(key_node.c_str(), F_OK) == 0) - return true; - - return false; -} - -bool sensor_hal::get_node_info(const node_info_query &query, node_info &info) -{ - bool ret = false; - int method; - string device_num; - - if (!get_input_method(query.key, method, device_num)) { - ERR("Failed to get input method for %s", query.key.c_str()); - return false; - } - - info.method = method; - - if (method == IIO_METHOD) { - if (query.sensorhub_controlled) - ret = get_sensorhub_iio_node_info(query.sensorhub_interval_node_name, device_num, info); - else - ret = get_iio_node_info(query.iio_enable_node_name, device_num, info); - } else { - if (query.sensorhub_controlled) - ret = get_sensorhub_input_event_node_info(query.sensorhub_interval_node_name, device_num, info); - else - ret = get_input_event_node_info(device_num, info); - } - - return ret; -} - - -void sensor_hal::show_node_info(node_info &info) -{ - if (info.data_node_path.size()) - INFO("Data node: %s", info.data_node_path.c_str()); - if (info.enable_node_path.size()) - INFO("Enable node: %s", info.enable_node_path.c_str()); - if (info.interval_node_path.size()) - INFO("Interval node: %s", info.interval_node_path.c_str()); - if (info.buffer_enable_node_path.size()) - INFO("Buffer enable node: %s", info.buffer_enable_node_path.c_str()); - if (info.buffer_length_node_path.size()) - INFO("Buffer length node: %s", info.buffer_length_node_path.c_str()); - if (info.trigger_node_path.size()) - INFO("Trigger node: %s", info.trigger_node_path.c_str()); -} - -bool sensor_hal::get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info) -{ - const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/"); - - info.data_node_path = string("/dev/iio:device") + device_num; - info.enable_node_path = base_dir + enable_node_name; - info.interval_node_path = base_dir + string("sampling_frequency"); - info.buffer_enable_node_path = base_dir + string("buffer/enable"); - info.buffer_length_node_path = base_dir + string("buffer/length"); - info.trigger_node_path = base_dir + string("trigger/current_trigger"); - - return true; -} - -bool sensor_hal::get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info) -{ - const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/"); - const string hub_dir = "/sys/class/sensors/ssp_sensor/"; - - info.data_node_path = string("/dev/iio:device") + device_num; - info.enable_node_path = hub_dir + string("enable"); - info.interval_node_path = hub_dir + interval_node_name; - info.buffer_enable_node_path = base_dir + string("buffer/enable"); - info.buffer_length_node_path = base_dir + string("buffer/length"); - return true; -} - -bool sensor_hal::get_input_event_node_info(const string& device_num, node_info &info) -{ - string base_dir; - string event_num; - - base_dir = string("/sys/class/input/input") + device_num + string("/"); - - if (!get_event_num(base_dir, event_num)) - return false; - - info.data_node_path = string("/dev/input/event") + event_num; - - info.enable_node_path = base_dir + string("enable"); - info.interval_node_path = base_dir + string("poll_delay"); - return true; -} - -bool sensor_hal::get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info) -{ - const string base_dir = "/sys/class/sensors/ssp_sensor/"; - string event_num; - - string input_dir = string("/sys/class/input/input") + device_num + string("/"); - - if (!get_event_num(input_dir, event_num)) - return false; - - info.data_node_path = string("/dev/input/event") + event_num; - info.enable_node_path = base_dir + string("enable"); - info.interval_node_path = base_dir + interval_node_name; - return true; -} - -bool sensor_hal::set_node_value(const string &node_path, int value) -{ - ofstream node(node_path, ofstream::binary); - - if (!node) - return false; - - node << value; - - return true; -} - -bool sensor_hal::set_node_value(const string &node_path, unsigned long long value) -{ - ofstream node(node_path, ofstream::binary); - - if (!node) - return false; - - node << value; - - return true; -} - - -bool sensor_hal::get_node_value(const string &node_path, int &value) -{ - ifstream node(node_path, ifstream::binary); - - if (!node) - return false; - - node >> value; - - return true; -} - -bool sensor_hal::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit) -{ - int prev_status, status; - - AUTOLOCK(m_shared_mutex); - - if (!get_node_value(node_path, prev_status)) { - ERR("Failed to get node: %s", node_path.c_str()); - return false; - } - - int _enable_bit = sensorhub_controlled ? enable_bit : 0; - - if (enable) - status = prev_status | (1 << _enable_bit); - else - status = prev_status & (~(1 << _enable_bit)); - - if (!set_node_value(node_path, status)) { - ERR("Failed to set node: %s", node_path.c_str()); - return false; - } - - return true; -} - - -bool sensor_hal::find_model_id(const string &sensor_type, string &model_id) -{ - string dir_path = "/sys/class/sensors/"; - string name_node, name; - string d_name; - DIR *dir = NULL; - struct dirent *dir_entry = NULL; - bool find = false; - - dir = opendir(dir_path.c_str()); - if (!dir) { - DBG("Failed to open dir: %s", dir_path.c_str()); - return false; - } - - while (!find && (dir_entry = readdir(dir))) { - d_name = string(dir_entry->d_name); - - if ((d_name != ".") && (d_name != "..") && (dir_entry->d_ino != 0)) { - name_node = dir_path + d_name + string("/name"); - - ifstream infile(name_node.c_str()); - - if (!infile) - continue; - - infile >> name; - - if (csensor_config::get_instance().is_supported(sensor_type, name)) { - model_id = name; - find = true; - break; - } - } - } - - closedir(dir); - - return find; -} - -bool sensor_hal::get_event_num(const string &input_path, string &event_num) -{ - const string event_prefix = "event"; - DIR *dir = NULL; - struct dirent *dir_entry = NULL; - string node_name; - bool find = false; - - dir = opendir(input_path.c_str()); - if (!dir) { - ERR("Failed to open dir: %s", input_path.c_str()); - return false; - } - - int prefix_size = event_prefix.size(); - - while (!find && (dir_entry = readdir(dir))) { - node_name = dir_entry->d_name; - - if (node_name.compare(0, prefix_size, event_prefix) == 0) { - event_num = node_name.substr(prefix_size, node_name.size() - prefix_size); - find = true; - break; - } - } - - closedir(dir); - - return find; -} - -bool sensor_hal::get_input_method(const string &key, int &method, string &device_num) -{ - input_method_info input_info[2] = { - {INPUT_EVENT_METHOD, "/sys/class/input/", "input"}, - {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"} - }; - - const int input_info_len = sizeof(input_info)/sizeof(input_info[0]); - size_t prefix_size; - string name_node, name; - string d_name; - DIR *dir = NULL; - struct dirent *dir_entry = NULL; - bool find = false; - - for (int i = 0; i < input_info_len; ++i) { - - prefix_size = input_info[i].prefix.size(); - - dir = opendir(input_info[i].dir_path.c_str()); - if (!dir) { - ERR("Failed to open dir: %s", input_info[i].dir_path.c_str()); - return false; - } - - find = false; - - while (!find && (dir_entry = readdir(dir))) { - d_name = string(dir_entry->d_name); - - if (d_name.compare(0, prefix_size, input_info[i].prefix) == 0) { - name_node = input_info[i].dir_path + d_name + string("/name"); - - ifstream infile(name_node.c_str()); - if (!infile) - continue; - - infile >> name; - - if (name == key) { - device_num = d_name.substr(prefix_size, d_name.size() - prefix_size); - find = true; - method = input_info[i].method; - break; - } - } - } - - closedir(dir); - - if (find) - break; - } - - return find; -} diff --git a/src/shared/sensor_hal.h b/src/shared/sensor_hal.h index 7111276..8e14b22 100644 --- a/src/shared/sensor_hal.h +++ b/src/shared/sensor_hal.h @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -19,20 +19,8 @@ #ifndef _SENSOR_HAL_H_ #define _SENSOR_HAL_H_ -#include -#include -#include -#include #include - -/* -* As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock -* Current kernel-headers package doesn't have it so we should define it here. -*/ - -#ifndef EVIOCSCLOCKID -#define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */ -#endif +#include typedef enum { SENSOR_HAL_TYPE_ACCELEROMETER, @@ -59,36 +47,7 @@ typedef enum { SENSOR_HAL_TYPE_FUSION, } sensor_hal_type_t; -typedef struct { - int method; - std::string data_node_path; - std::string enable_node_path; - std::string interval_node_path; - std::string buffer_enable_node_path; - std::string buffer_length_node_path; - std::string trigger_node_path; -} node_info; - -typedef struct { - bool sensorhub_controlled; - std::string sensor_type; - std::string key; - std::string iio_enable_node_name; - std::string sensorhub_interval_node_name; -} node_info_query; -enum input_method { - IIO_METHOD = 0, - INPUT_EVENT_METHOD = 1, -}; - -typedef struct { - int method; - std::string dir_path; - std::string prefix; -} input_method_info; - -#define DEFAULT_WAIT_TIME 0 class sensor_hal { @@ -96,44 +55,13 @@ public: sensor_hal(); virtual ~sensor_hal(); - virtual bool init(void *data = NULL); virtual std::string get_model_id(void) = 0; virtual sensor_hal_type_t get_type(void) = 0; virtual bool enable(void) = 0; virtual bool disable(void) = 0; - virtual bool set_interval(unsigned long val); - virtual bool is_data_ready(bool wait) = 0; - virtual bool is_wakeup_supported(void); - virtual bool get_properties(sensor_properties_s &properties) {return false;}; - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) {return false;}; - virtual int get_sensor_data(sensor_data_t &data); - virtual int get_sensor_data(sensorhub_data_t &data); - virtual long set_command(unsigned int cmd, long val); - virtual bool set_wakeup(int wakeup); - virtual int send_sensorhub_data(const char *data, int data_len); - -protected: - cmutex m_mutex; - static cmutex m_shared_mutex; - - virtual bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0); - - static unsigned long long get_timestamp(void); - static unsigned long long get_timestamp(timeval *t); - static bool find_model_id(const std::string &sensor_type, std::string &model_id); - static bool is_sensorhub_controlled(const std::string &key); - static bool get_node_info(const node_info_query &query, node_info &info); - static void show_node_info(node_info &info); - static bool set_node_value(const std::string &node_path, int value); - static bool set_node_value(const std::string &node_path, unsigned long long value); - static bool get_node_value(const std::string &node_path, int &value); -private: - static bool get_event_num(const std::string &node_path, std::string &event_num); - static bool get_input_method(const std::string &key, int &method, std::string &device_num); - - static bool get_iio_node_info(const std::string& enable_node_name, const std::string& device_num, node_info &info); - static bool get_sensorhub_iio_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info); - static bool get_input_event_node_info(const std::string& device_num, node_info &info); - static bool get_sensorhub_input_event_node_info(const std::string &interval_node_name, const std::string& device_num, node_info &info); + virtual bool is_data_ready(void) = 0; + virtual bool set_interval(unsigned long val) = 0; + virtual int get_sensor_data(sensor_data_t &data) = 0; + virtual bool get_properties(sensor_properties_s &properties) = 0; }; -#endif /*_SENSOR_HAL_CLASS_H_*/ +#endif /*_SENSOR_HAL_H_*/ -- 2.7.4