Moving frequently used read_node_value template function to iio_common library 00/28100/1
authorAmit Dharmapurikar <amit.vd@samsung.com>
Fri, 26 Sep 2014 06:13:09 +0000 (11:43 +0530)
committerAmit Dharmapurikar <amit.vd@samsung.com>
Fri, 26 Sep 2014 06:13:09 +0000 (11:43 +0530)
Change-Id: I1c682fd091cdc03de539887ba01211aaa34041d6
Signed-off-by: Amit Dharmapurikar <amit.vd@samsung.com>
src/geo/geo_sensor_hal.cpp
src/geo/geo_sensor_hal.h
src/light/light_sensor_hal.cpp
src/light/light_sensor_hal.h
src/pressure/pressure_sensor_hal.h
src/shared/iio_common.h

index 0d65ab7..f611162 100755 (executable)
@@ -25,6 +25,7 @@
 #include <linux/input.h>
 #include <cconfig.h>
 #include <geo_sensor_hal.h>
+#include <iio_common.h>
 
 using std::ifstream;
 using std::string;
index 471e7a7..c723fe6 100755 (executable)
@@ -22,7 +22,6 @@
 
 #include <sensor_hal.h>
 #include <string>
-#include <fstream>
 
 #define IIO_DIR                        "/sys/bus/iio/devices/"
 #define X_RAW_VAL_NODE "/in_magn_x_raw"
@@ -34,7 +33,6 @@
 #define NAME_NODE              "/name"
 
 using std::string;
-using std::ifstream;
 
 class geo_sensor_hal : public sensor_hal
 {
@@ -81,21 +79,5 @@ private:
        bool update_value(void);
        bool is_sensorhub_supported(void);
        bool init_resources(void);
-
-       template <typename value_t>
-       bool read_node_value(string node_path, value_t &value)
-       {
-               ifstream handle;
-               handle.open(node_path.c_str());
-               if (!handle)
-               {
-                       ERR("Failed to open handle(%s)", node_path.c_str());
-                       return false;
-               }
-               handle >> value;
-               handle.close();
-
-               return true;
-       }
 };
 #endif /*_GEO_SENSOR_HAL_H_*/
index 6beb3c1..445828c 100755 (executable)
@@ -25,6 +25,7 @@
 #include <linux/input.h>
 #include <cconfig.h>
 #include <light_sensor_hal.h>
+#include <iio_common.h>
 
 using std::ifstream;
 using config::CConfig;
index 4c39805..30c53f2 100755 (executable)
 
 #include <sensor_hal.h>
 #include <string>
-#include <fstream>
 
-#define IIO_DIR                                "/sys/bus/iio/devices/"
-#define NAME_NODE                      "/name"
-#define ILL_CLEAR_NODE         "/in_illuminance_clear_raw"
+#define IIO_DIR                        "/sys/bus/iio/devices/"
+#define NAME_NODE              "/name"
+#define ILL_CLEAR_NODE "/in_illuminance_clear_raw"
 
 #define IIO_DEV_BASE_NAME      "iio:device"
 #define IIO_DEV_STR_LEN                10
 
 using std::string;
-using std::ifstream;
 
 class light_sensor_hal : public sensor_hal
 {
@@ -63,21 +61,5 @@ private:
 
        bool update_value(void);
        bool is_sensorhub_supported(void);
-
-       template <typename value_t>
-       bool read_node_value(string node_path, value_t &value)
-       {
-               ifstream handle;
-               handle.open(node_path.c_str());
-               if (!handle)
-               {
-                       ERR("Failed to open handle(%s)", node_path.c_str());
-                       return false;
-               }
-               handle >> value;
-               handle.close();
-
-               return true;
-       }
 };
 #endif /*_LIGHT_SENSOR_HAL_H_*/
index ca95085..96fc362 100755 (executable)
@@ -22,7 +22,6 @@
 
 #include <sensor_hal.h>
 #include <string>
-#include <fstream>
 
 #define IIO_DIR                        "/sys/bus/iio/devices/"
 #define NAME_NODE              "/name"
@@ -39,7 +38,6 @@
 #define IIO_DEV_STR_LEN                10
 
 using std::string;
-using std::ifstream;
 
 class pressure_sensor_hal : public sensor_hal
 {
@@ -92,21 +90,5 @@ private:
        bool update_value(bool wait);
        bool enable_resource(bool enable);
        bool is_sensorhub_supported(void);
-
-       template <typename value_t>
-       bool read_node_value(string node_path, value_t &value)
-       {
-               ifstream handle;
-               handle.open(node_path.c_str());
-               if (!handle)
-               {
-                       ERR("Failed to open handle(%s)", node_path.c_str());
-                       return false;
-               }
-               handle >> value;
-               handle.close();
-
-               return true;
-       }
 };
 #endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/
index 9f00c13..0d72947 100644 (file)
 #define IIO_COMMON_H_
 
 #include <linux/ioctl.h>
+#include <fstream>
+#include <string>
+#include <common.h>
+
+using std::string;
+using std::ifstream;
 
 #define NO_OF_ULL_BYTES                8
 #define NO_OF_SHORT_VAL                4
@@ -77,4 +83,20 @@ int update_sysfs_num(const char *filepath, int val, bool verify = false);
 int update_sysfs_string(const char *filepath, char *val, bool verify = false);
 int convert_bytes_to_int(int input, struct channel_parameters *info);
 
+template <typename value_t>
+bool read_node_value(string node_path, value_t &value)
+{
+       ifstream handle;
+       handle.open(node_path.c_str());
+       if (!handle)
+       {
+               ERR("Failed to open handle(%s)", node_path.c_str());
+               return false;
+       }
+       handle >> value;
+       handle.close();
+
+       return true;
+}
+
 #endif /* IIO_COMMON_H_ */