sensor-hal: change sensor_device_base to util class 53/58753/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:33 +0000 (16:48 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 3 Feb 2016 07:48:33 +0000 (16:48 +0900)
Change-Id: Ia4ac5e8dbae1764c1dd260ea748f24442f851f6c
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/accel/accel.cpp [moved from src/accel/accel_sensor_device.cpp with 93% similarity]
src/accel/accel.h [moved from src/accel/accel_sensor_device.h with 95% similarity]
src/create.cpp
src/proximity/proxi.cpp [moved from src/proximity/proxi_sensor_device.cpp with 90% similarity]
src/proximity/proxi.h [moved from src/proximity/proxi_sensor_device.h with 94% similarity]
src/sensor_device_base.h [deleted file]
src/util.cpp [moved from src/sensor_device_base.cpp with 82% similarity]
src/util.h [new file with mode: 0644]

similarity index 93%
rename from src/accel/accel_sensor_device.cpp
rename to src/accel/accel.cpp
index 412bd32..2c51cff 100644 (file)
@@ -22,7 +22,8 @@
 #include <sys/stat.h>
 #include <linux/input.h>
 #include <sys/poll.h>
-#include "accel_sensor_device.h"
+#include <util.h>
+#include "accel.h"
 
 #define GRAVITY 9.80665
 #define G_TO_MG 1000
@@ -82,18 +83,18 @@ accel_sensor_device::accel_sensor_device()
        node_info_query query;
        node_info info;
 
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
        query.sensor_type = "ACCEL";
        query.key = "accelerometer_sensor";
        query.iio_enable_node_name = "accel_enable";
        query.sensorhub_interval_node_name = sensorhub_interval_node_name;
 
-       if (!get_node_info(query, info)) {
+       if (!util::get_node_info(query, info)) {
                ERR("Failed to get node info");
                throw ENXIO;
        }
 
-       show_node_info(info);
+       util::show_node_info(info);
 
        m_data_node = info.data_node_path;
        m_enable_node = info.enable_node_path;
@@ -127,7 +128,7 @@ bool accel_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
 
 bool accel_sensor_device::enable(uint32_t id)
 {
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
        set_interval(id, m_polling_interval);
 
        m_fired_time = 0;
@@ -137,7 +138,7 @@ bool accel_sensor_device::enable(uint32_t id)
 
 bool accel_sensor_device::disable(uint32_t id)
 {
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
 
        INFO("Disable accelerometer sensor");
        return true;
@@ -154,7 +155,7 @@ bool accel_sensor_device::set_interval(uint32_t id, unsigned long val)
 
        polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
 
-       if (!set_node_value(m_interval_node, polling_interval_ns)) {
+       if (!util::set_node_value(m_interval_node, polling_interval_ns)) {
                ERR("Failed to set polling resource: %s\n", m_interval_node.c_str());
                return false;
        }
@@ -225,7 +226,7 @@ bool accel_sensor_device::update_value_input_event(void)
                        }
                } else if (accel_input.type == EV_SYN) {
                        syn = true;
-                       fired_time = sensor_device_base::get_timestamp(&accel_input.time);
+                       fired_time = util::get_timestamp(&accel_input.time);
                } else {
                        ERR("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
                        return false;
similarity index 95%
rename from src/accel/accel_sensor_device.h
rename to src/accel/accel.h
index 8c34ae5..533264c 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef _ACCEL_SENSOR_DEVICE_H_
 #define _ACCEL_SENSOR_DEVICE_H_
 
-#include <sensor_device_base.h>
+#include <sensor_hal.h>
 
-class accel_sensor_device : public sensor_device_base
+class accel_sensor_device : public sensor_device
 {
 public:
        accel_sensor_device();
index e7e6ab8..761e04e 100644 (file)
 
 #include <sensor_common.h>
 
-#include "accel/accel_sensor_device.h"
+#include "accel/accel.h"
 //#include "gyro/gyro_sensor_device.h"
 //#include "magnetic/geo_sensor_device.h"
-#include "proximity/proxi_sensor_device.h"
+#include "proximity/proxi.h"
 //#include "light/light_sensor_device.h"
 //#include "rotation_vector/rv_raw_sensor_device.h"
 //#include "pressure/pressure_sensor_device.h"
similarity index 90%
rename from src/proximity/proxi_sensor_device.cpp
rename to src/proximity/proxi.cpp
index 54dce10..027a036 100644 (file)
@@ -20,7 +20,8 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <linux/input.h>
-#include "proxi_sensor_device.h"
+#include <util.h>
+#include "proxi.h"
 
 #define MODEL_NAME "K2HH"
 #define VENDOR "ST Microelectronics"
@@ -63,18 +64,18 @@ proxi_sensor_device::proxi_sensor_device()
        node_info_query query;
        node_info info;
 
-       query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name);
+       query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
        query.sensor_type = "PROXI";
        query.key = "proximity_sensor";
        query.iio_enable_node_name = "proximity_enable";
        query.sensorhub_interval_node_name = sensorhub_interval_node_name;
 
-       if (!get_node_info(query, info)) {
+       if (!util::get_node_info(query, info)) {
                ERR("Failed to get node info");
                throw ENXIO;
        }
 
-       show_node_info(info);
+       util::show_node_info(info);
 
        m_data_node = info.data_node_path;
        m_enable_node = info.enable_node_path;
@@ -107,7 +108,7 @@ bool proxi_sensor_device::get_sensors(std::vector<sensor_handle_t> &sensors)
 
 bool proxi_sensor_device::enable(uint32_t id)
 {
-       set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_PROXIMITY_ENABLE_BIT);
 
        m_fired_time = 0;
        INFO("Enable proximity sensor");
@@ -116,7 +117,7 @@ bool proxi_sensor_device::enable(uint32_t id)
 
 bool proxi_sensor_device::disable(uint32_t id)
 {
-       set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_PROXIMITY_ENABLE_BIT);
 
        INFO("Disable proximity sensor");
        return true;
@@ -163,7 +164,7 @@ bool proxi_sensor_device::update_value(void)
 
        if ((proxi_event.type == EV_ABS) && (proxi_event.code == ABS_DISTANCE)) {
                m_state = proxi_event.value;
-               m_fired_time = sensor_device_base::get_timestamp(&proxi_event.time);
+               m_fired_time = util::get_timestamp(&proxi_event.time);
 
                DBG("m_state = %d, time = %lluus", m_state, m_fired_time);
 
similarity index 94%
rename from src/proximity/proxi_sensor_device.h
rename to src/proximity/proxi.h
index 368c0a2..a52dafc 100644 (file)
@@ -20,9 +20,9 @@
 #ifndef _PROXI_SENSOR_DEVICE_H_
 #define _PROXI_SENSOR_DEVICE_H_
 
-#include <sensor_device_base.h>
+#include <sensor_hal.h>
 
-class proxi_sensor_device : public sensor_device_base
+class proxi_sensor_device : public sensor_device
 {
 public:
        proxi_sensor_device();
diff --git a/src/sensor_device_base.h b/src/sensor_device_base.h
deleted file mode 100644 (file)
index 45c7d66..0000000
+++ /dev/null
@@ -1,92 +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.
- *
- */
-
-#ifndef _SENSOR_DEVICE_BASE_H_
-#define _SENSOR_DEVICE_BASE_H_
-#include <sys/time.h>
-#include <sensor_logs.h>
-#include <string>
-#include <sensor_hal.h>
-
-/*
-* 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
-/* Set clockid to be used for timestamps */
-#define EVIOCSCLOCKID          _IOW('E', 0xa0, int)
-#endif
-
-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;
-
-class sensor_device_base : public sensor_device
-{
-public:
-       sensor_device_base();
-       virtual ~sensor_device_base();
-
-protected:
-       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 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);
-};
-#endif /*_SENSOR_DEVICE_BASE_H_*/
similarity index 82%
rename from src/sensor_device_base.cpp
rename to src/util.cpp
index 0c4f3fe..434eb80 100644 (file)
  *
  */
 
-#include <sensor_device_base.h>
 #include <dirent.h>
 #include <string.h>
 #include <fstream>
+#include <util.h>
 
 using std::ifstream;
 using std::ofstream;
 using std::fstream;
 using std::string;
 
-sensor_device_base::sensor_device_base()
+static bool get_event_num(const string &input_path, string &event_num)
 {
-}
-
-sensor_device_base::~sensor_device_base()
-{
-}
-
-unsigned long long sensor_device_base::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_device_base::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_device_base::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_device_base::get_node_info(const node_info_query &query, node_info &info)
-{
-       bool ret = false;
-       int method;
-       string device_num;
+       const string event_prefix = "event";
+       DIR *dir = NULL;
+       struct dirent *dir_entry = NULL;
+       string node_name;
+       bool find = false;
 
-       if (!get_input_method(query.key, method, device_num)) {
-               ERR("Failed to get input method for %s", query.key.c_str());
+       dir = opendir(input_path.c_str());
+       if (!dir) {
+               ERR("Failed to open dir: %s", input_path.c_str());
                return false;
        }
 
-       info.method = method;
+       int prefix_size = event_prefix.size();
 
-       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);
-       }
+       while (!find && (dir_entry = readdir(dir))) {
+               node_name = dir_entry->d_name;
 
-       return ret;
-}
+               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);
 
-void sensor_device_base::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());
+       return find;
 }
 
-bool sensor_device_base::get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info)
+static bool 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("/");
 
@@ -121,7 +72,7 @@ bool sensor_device_base::get_iio_node_info(const string& enable_node_name, const
        return true;
 }
 
-bool sensor_device_base::get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+static bool get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info)
 {
        const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
        const string hub_dir = "/sys/class/sensors/ssp_sensor/";
@@ -134,7 +85,7 @@ bool sensor_device_base::get_sensorhub_iio_node_info(const string &interval_node
        return true;
 }
 
-bool sensor_device_base::get_input_event_node_info(const string& device_num, node_info &info)
+static bool get_input_event_node_info(const string& device_num, node_info &info)
 {
        string base_dir;
        string event_num;
@@ -151,7 +102,7 @@ bool sensor_device_base::get_input_event_node_info(const string& device_num, nod
        return true;
 }
 
-bool sensor_device_base::get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+static bool get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info)
 {
        const string base_dir = "/sys/class/sensors/ssp_sensor/";
        string event_num;
@@ -167,44 +118,76 @@ bool sensor_device_base::get_sensorhub_input_event_node_info(const string &inter
        return true;
 }
 
-bool sensor_device_base::set_node_value(const string &node_path, int value)
+static bool get_node_value(const string &node_path, int &value)
 {
-       ofstream node(node_path, ofstream::binary);
+       ifstream node(node_path, ifstream::binary);
 
        if (!node)
                return false;
 
-       node << value;
+       node >> value;
 
        return true;
 }
 
-bool sensor_device_base::set_node_value(const string &node_path, unsigned long long value)
+static bool get_input_method(const string &key, int &method, string &device_num)
 {
-       ofstream node(node_path, ofstream::binary);
+       input_method_info input_info[2] = {
+               {INPUT_EVENT_METHOD, "/sys/class/input/", "input"},
+               {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"}
+       };
 
-       if (!node)
-               return false;
+       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;
 
-       node << value;
+       for (int i = 0; i < input_info_len; ++i) {
 
-       return true;
-}
+               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;
+               }
 
-bool sensor_device_base::get_node_value(const string &node_path, int &value)
-{
-       ifstream node(node_path, ifstream::binary);
+               find = false;
 
-       if (!node)
-               return false;
+               while (!find && (dir_entry = readdir(dir))) {
+                       d_name = string(dir_entry->d_name);
 
-       node >> value;
+                       if (d_name.compare(0, prefix_size, input_info[i].prefix) == 0) {
+                               name_node = input_info[i].dir_path + d_name + string("/name");
 
-       return true;
+                               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;
 }
 
-bool sensor_device_base::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
+bool util::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
 {
        int prev_status, status;
 
@@ -228,90 +211,99 @@ bool sensor_device_base::set_enable_node(const string &node_path, bool sensorhub
        return true;
 }
 
-bool sensor_device_base::get_event_num(const string &input_path, string &event_num)
+unsigned long long util::get_timestamp(void)
 {
-       const string event_prefix = "event";
-       DIR *dir = NULL;
-       struct dirent *dir_entry = NULL;
-       string node_name;
-       bool find = false;
+       struct timespec t;
+       clock_gettime(CLOCK_MONOTONIC, &t);
+       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
 
-       dir = opendir(input_path.c_str());
-       if (!dir) {
-               ERR("Failed to open dir: %s", input_path.c_str());
-               return false;
+unsigned long long util::get_timestamp(timeval *t)
+{
+       if (!t) {
+               ERR("t is NULL");
+               return 0;
        }
 
-       int prefix_size = event_prefix.size();
-
-       while (!find && (dir_entry = readdir(dir))) {
-               node_name = dir_entry->d_name;
+       return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
+}
 
-               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;
-               }
-       }
+bool util::is_sensorhub_controlled(const string &key)
+{
+       string key_node = string("/sys/class/sensors/ssp_sensor/") + key;
 
-       closedir(dir);
+       if (access(key_node.c_str(), F_OK) == 0)
+               return true;
 
-       return find;
+       return false;
 }
 
-bool sensor_device_base::get_input_method(const string &key, int &method, string &device_num)
+bool util::get_node_info(const node_info_query &query, node_info &info)
 {
-       input_method_info input_info[2] = {
-               {INPUT_EVENT_METHOD, "/sys/class/input/", "input"},
-               {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"}
-       };
+       bool ret = false;
+       int method;
+       string device_num;
 
-       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;
+       if (!get_input_method(query.key, method, device_num)) {
+               ERR("Failed to get input method for %s", query.key.c_str());
+               return false;
+       }
 
-       for (int i = 0; i < input_info_len; ++i) {
+       info.method = method;
 
-               prefix_size = input_info[i].prefix.size();
+       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);
+       }
 
-               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;
-               }
+       return ret;
+}
 
-               find = false;
 
-               while (!find && (dir_entry = readdir(dir))) {
-                       d_name = string(dir_entry->d_name);
+void util::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());
+}
 
-                       if (d_name.compare(0, prefix_size, input_info[i].prefix) == 0) {
-                               name_node = input_info[i].dir_path + d_name + string("/name");
+bool util::set_node_value(const string &node_path, int value)
+{
+       ofstream node(node_path, ofstream::binary);
 
-                               ifstream infile(name_node.c_str());
-                               if (!infile)
-                                       continue;
+       if (!node)
+               return false;
 
-                               infile >> name;
+       node << value;
 
-                               if (name == key) {
-                                       device_num = d_name.substr(prefix_size, d_name.size() - prefix_size);
-                                       find = true;
-                                       method = input_info[i].method;
-                                       break;
-                               }
-                       }
-               }
+       return true;
+}
 
-               closedir(dir);
+bool util::set_node_value(const string &node_path, unsigned long long value)
+{
+       ofstream node(node_path, ofstream::binary);
 
-               if (find)
-                       break;
-       }
+       if (!node)
+               return false;
 
-       return find;
+       node << value;
+
+       return true;
 }
+
diff --git a/src/util.h b/src/util.h
new file mode 100644 (file)
index 0000000..77561fd
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef _SENSOR_UTIL_H_
+#define _SENSOR_UTIL_H_
+
+#include <sys/time.h>
+#include <sensor_logs.h>
+#include <string>
+#include <sensor_hal.h>
+
+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;
+
+namespace util {
+       bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
+
+       unsigned long long get_timestamp(void);
+       unsigned long long get_timestamp(timeval *t);
+
+       bool is_sensorhub_controlled(const std::string &key);
+       bool get_node_info(const node_info_query &query, node_info &info);
+       void show_node_info(node_info &info);
+       bool set_node_value(const std::string &node_path, int value);
+       bool set_node_value(const std::string &node_path, unsigned long long value);
+}
+#endif /*_SENSOR_UTIL_H_*/