Adding cconfig parent class for XML configuration 79/30679/1
authorRamasamy <ram.kannan@samsung.com>
Mon, 24 Nov 2014 07:46:58 +0000 (13:16 +0530)
committerRamasamy <ram.kannan@samsung.com>
Mon, 24 Nov 2014 07:47:08 +0000 (13:17 +0530)
Adding cconfig parent class for XML configuration

Added cconfig parent class for cvirtual_sensor_config and
csensor_config. Removed config namespace as XML configuration
related code is small to have a separate namespace. Cleanup of
namespace related code. Changed derived class
cvirtual_sensor_config and csensor_config classes code based
on new cconfig parent class

Change-Id: I296dc7be45b201c70d040e7dac2e2b5325d5abc5

17 files changed:
src/accel/accel_sensor_hal.cpp
src/geo/geo_sensor_hal.cpp
src/gyro/gyro_sensor_hal.cpp
src/light/light_sensor_hal.cpp
src/pressure/pressure_sensor.cpp
src/pressure/pressure_sensor.h
src/pressure/pressure_sensor_hal.cpp
src/proxi/proxi_sensor_hal.cpp
src/shared/CMakeLists.txt
src/shared/cconfig.cpp [new file with mode: 0644]
src/shared/cconfig.h [new file with mode: 0644]
src/shared/csensor_config.cpp
src/shared/csensor_config.h
src/shared/cvirtual_sensor_config.cpp
src/shared/cvirtual_sensor_config.h
src/shared/sensor_hal.cpp
src/temperature/temperature_sensor_hal.cpp

index cb74385..53bb2d7 100755 (executable)
  */
 #include <fcntl.h>
 #include <sys/stat.h>
-
 #include <linux/input.h>
 #include <csensor_config.h>
-
 #include <accel_sensor_hal.h>
 #include <sys/poll.h>
 
 using std::ifstream;
-using config::csensor_config;
 
 #define GRAVITY 9.80665
 #define G_TO_MG 1000
index bfbb50e..d742b26 100755 (executable)
@@ -27,7 +27,6 @@
 #include <iio_common.h>
 
 using std::ifstream;
-using config::csensor_config;
 
 #define SENSOR_TYPE_MAGNETIC   "MAGNETIC"
 #define ELEMENT_NAME                   "NAME"
index 34184bc..c9bf135 100755 (executable)
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <dirent.h>
-
 #include <linux/input.h>
 #include <csensor_config.h>
-
 #include <gyro_sensor_hal.h>
 #include <sys/ioctl.h>
 #include <fstream>
 #include <sys/poll.h>
 
 using std::ifstream;
-using config::csensor_config;
 
 #define DPS_TO_MDPS 1000
 #define MIN_RANGE(RES) (-((1 << (RES))/2))
index 6498728..4cc630c 100755 (executable)
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <dirent.h>
-
 #include <linux/input.h>
 #include <csensor_config.h>
-
 #include <light_sensor_hal.h>
 #include <sys/ioctl.h>
 #include <iio_common.h>
 
 using std::ifstream;
-using config::csensor_config;
 
 #define SENSOR_TYPE_LIGHT              "LIGHT"
 #define ELEMENT_NAME                   "NAME"
index 710c86a..d29311c 100755 (executable)
 
 #include <common.h>
 #include <sf_common.h>
-
 #include <pressure_sensor.h>
 #include <sensor_plugin_loader.h>
 #include <algorithm>
 #include <csensor_config.h>
 
-using config::csensor_config;
 using std::bind1st;
 using std::mem_fun;
 
index 1da5cab..1bd8df2 100755 (executable)
@@ -25,7 +25,8 @@
 #include <physical_sensor.h>
 #include <sensor_hal.h>
 
-class pressure_sensor : public physical_sensor {
+class pressure_sensor : public physical_sensor
+{
 public:
        pressure_sensor();
        virtual ~pressure_sensor();
@@ -52,7 +53,6 @@ private:
        bool process_event(void);
        float pressure_to_altitude(float pressure);
        void raw_to_base(sensor_data_t &data);
-
 };
 
 #endif
index 2823baa..c899d3e 100755 (executable)
@@ -29,7 +29,6 @@
 
 using std::ifstream;
 using std::string;
-using config::csensor_config;
 
 #define SENSOR_TYPE_PRESSURE   "PRESSURE"
 #define ELEMENT_NAME                   "NAME"
index 328211e..3154c18 100755 (executable)
@@ -27,7 +27,6 @@
 #include <iio_common.h>
 
 using std::ifstream;
-using config::csensor_config;
 
 #define NO_FLAG                        0
 #define PROXIMITY_TYPE 8
@@ -42,7 +41,6 @@ using config::csensor_config;
 
 #define PROXI_CODE     0x0019
 
-
 proxi_sensor_hal::proxi_sensor_hal()
 : m_state(PROXIMITY_STATE_FAR)
 , m_fired_time(0)
index 4a305da..2653782 100755 (executable)
@@ -38,6 +38,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
 add_library(sensord-server SHARED
        crw_lock.cpp
        worker_thread.cpp
+       cconfig.cpp
        csensor_config.cpp
        cvirtual_sensor_config.cpp
        csensor_event_queue.cpp
@@ -75,6 +76,7 @@ install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
 install(FILES
        crw_lock.h
        worker_thread.h
+       cconfig.h
        csensor_config.h
        cvirtual_sensor_config.h
        csensor_event_queue.h
diff --git a/src/shared/cconfig.cpp b/src/shared/cconfig.cpp
new file mode 100644 (file)
index 0000000..23d11a5
--- /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.
+ *
+ */
+
+#include <cconfig.h>
+#include <fstream>
+
+using std::ifstream;
+
+cconfig::cconfig(void)
+{
+
+}
+
+cconfig::~cconfig(void)
+{
+
+}
+
+bool cconfig::get_device_id(void)
+{
+       const string INFO_INI_PATH = "/etc/info.ini";
+       const string START_DELIMETER = "Model=";
+       const string END_DELIMETER = ";";
+       string line;
+       ifstream in_file;
+       std::size_t start_pos, end_pos;
+       bool ret = false;
+
+       in_file.open(INFO_INI_PATH);
+
+       if (!in_file.is_open())
+               return false;
+
+       while (!in_file.eof()) {
+               getline(in_file, line);
+               start_pos = line.find(START_DELIMETER);
+
+               if (start_pos != std::string::npos) {
+                       start_pos = start_pos + START_DELIMETER.size();
+                       end_pos = line.find(END_DELIMETER, start_pos);
+
+                       if (end_pos != std::string::npos) {
+                               m_device_id = line.substr(start_pos, end_pos - start_pos);
+                               ret = true;
+                               break;
+                       }
+               }
+       }
+
+       in_file.close();
+
+       return ret;
+}
diff --git a/src/shared/cconfig.h b/src/shared/cconfig.h
new file mode 100644 (file)
index 0000000..aa92fdd
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 _CCONFIG_H_
+#define _CCONFIG_H_
+
+#include <string>
+#include <unordered_map>
+#include <common.h>
+
+using std::unordered_map;
+using std::string;
+using std::istringstream;
+
+class cconfig
+{
+protected:
+       virtual bool load_config(const string& config_path) = 0;
+
+       string m_device_id;
+public:
+       cconfig();
+       virtual ~cconfig();
+
+       bool get_device_id(void);
+
+};
+
+#endif /* _CCONFIG_H_ */
index 013a086..1f193a7 100755 (executable)
@@ -25,7 +25,6 @@
 #include <iostream>
 #include <fstream>
 
-using namespace config;
 using std::ifstream;
 
 #define ROOT_ELEMENT   "SENSOR"
@@ -275,39 +274,3 @@ bool csensor_config::is_supported(const string& sensor_type,const string& model_
 
        return true;
 }
-
-bool csensor_config::get_device_id(void)
-{
-       const string INFO_INI_PATH = "/etc/info.ini";
-       const string START_DELIMETER = "Model=";
-       const string END_DELIMETER = ";";
-       string line;
-       ifstream in_file;
-       std::size_t start_pos, end_pos;
-       bool ret = false;
-
-       in_file.open(INFO_INI_PATH);
-
-       if (!in_file.is_open())
-               return false;
-
-       while (!in_file.eof()) {
-               getline(in_file, line);
-               start_pos = line.find(START_DELIMETER);
-
-               if (start_pos != std::string::npos) {
-                       start_pos = start_pos + START_DELIMETER.size();
-                       end_pos = line.find(END_DELIMETER, start_pos);
-
-                       if (end_pos != std::string::npos) {
-                               m_device_id = line.substr(start_pos, end_pos - start_pos);
-                               ret = true;
-                               break;
-                       }
-               }
-       }
-
-       in_file.close();
-
-       return ret;
-}
index 0c77f98..d4c69a5 100755 (executable)
 #if !defined(_CSENSOR_CONFIG_CLASS_H_)
 #define _CSENSOR_CONFIG_CLASS_H_
 
-#include <string>
-#include <unordered_map>
-#include <common.h>
-
-using std::unordered_map;
-using std::string;
-using std::istringstream;
+#include <cconfig.h>
 
 #define SENSOR_CONFIG_FILE_PATH "/usr/etc/sensors.xml"
 
@@ -74,30 +68,28 @@ typedef unordered_map<string,Model_list> Sensor_config;
 *
 */
 
-namespace config
+class csensor_config : public cconfig
 {
-       class csensor_config
-       {
-       private:
-               csensor_config();
-               csensor_config(csensor_config const&) {};
-               csensor_config& operator=(csensor_config const&);
-               bool load_config(const string& config_path);
-               Sensor_config m_sensor_config;
-               string m_device_id;
-       public:
-               static csensor_config& get_instance(void);
+private:
+       csensor_config();
+       csensor_config(csensor_config const&) {};
+       csensor_config& operator=(csensor_config const&);
+
+       bool load_config(const string& config_path);
+
+       Sensor_config m_sensor_config;
+public:
+       static csensor_config& get_instance(void);
+
+       bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value);
+       bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value);
+       bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value);
 
-               bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value);
-               bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value);
-               bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value);
+       bool get(const string& sensor_type, const string& model_id, const string& element, string& value);
+       bool get(const string& sensor_type, const string& model_id, const string& element, double& value);
+       bool get(const string& sensor_type, const string& model_id, const string& element, long& value);
 
-               bool get(const string& sensor_type, const string& model_id, const string& element, string& value);
-               bool get(const string& sensor_type, const string& model_id, const string& element, double& value);
-               bool get(const string& sensor_type, const string& model_id, const string& element, long& value);
+       bool is_supported(const string &sensor_type, const string &model_id);
+};
 
-               bool is_supported(const string &sensor_type, const string &model_id);
-               bool get_device_id(void);
-       };
-}
 #endif
index 7aebd2d..c0d0f0b 100755 (executable)
@@ -24,9 +24,7 @@
 #include <string>
 #include <iostream>
 #include <sstream>
-#include <fstream>
 
-using std::ifstream;
 using std::string;
 using std::stringstream;
 
@@ -282,38 +280,3 @@ bool cvirtual_sensor_config::is_supported(const string& sensor_type)
        return true;
 }
 
-bool cvirtual_sensor_config::get_device_id(void)
-{
-       const string INFO_INI_PATH = "/etc/info.ini";
-       const string START_DELIMETER = "Model=";
-       const string END_DELIMETER = ";";
-       string line;
-       ifstream in_file;
-       std::size_t start_pos, end_pos;
-       bool ret = false;
-
-       in_file.open(INFO_INI_PATH);
-
-       if (!in_file.is_open())
-               return false;
-
-       while (!in_file.eof()) {
-               getline(in_file, line);
-               start_pos = line.find(START_DELIMETER);
-
-               if (start_pos != std::string::npos) {
-                       start_pos = start_pos + START_DELIMETER.size();
-                       end_pos = line.find(END_DELIMETER, start_pos);
-
-                       if (end_pos != std::string::npos) {
-                               m_device_id = line.substr(start_pos, end_pos - start_pos);
-                               ret = true;
-                               break;
-                       }
-               }
-       }
-
-       in_file.close();
-
-       return ret;
-}
index 754fd00..7cfbcb6 100755 (executable)
 #if !defined(_CVIRTUAL_SENSOR_CONFIG_CLASS_H_)
 #define _CVIRTUAL_SENSOR_CONFIG_CLASS_H_
 
-#include <string>
-#include <unordered_map>
-#include <common.h>
-
-using std::unordered_map;
-using std::string;
-using std::istringstream;
+#include <cconfig.h>
 
 #define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml"
 
@@ -55,15 +49,16 @@ typedef unordered_map<string,Virtual_sensor> Virtual_sensor_config;
 *
 */
 
-class cvirtual_sensor_config
+class cvirtual_sensor_config : public cconfig
 {
 private:
        cvirtual_sensor_config();
        cvirtual_sensor_config(cvirtual_sensor_config const&) {};
        cvirtual_sensor_config& operator=(cvirtual_sensor_config const&);
+
        bool load_config(const string& config_path);
+
        Virtual_sensor_config m_virtual_sensor_config;
-       string m_device_id;
 public:
        static cvirtual_sensor_config& get_instance(void);
 
@@ -76,7 +71,6 @@ public:
        bool get(const string& sensor_type, const string& element, int *value, int count = 1);
 
        bool is_supported(const string &sensor_type);
-       bool get_device_id(void);
 };
 
 #endif
index 55c20f7..a312162 100755 (executable)
@@ -25,7 +25,6 @@
 
 using std::ifstream;
 using std::fstream;
-using config::csensor_config;
 
 cmutex sensor_hal::m_shared_mutex;
 
index 350d530..cf562bb 100755 (executable)
@@ -26,9 +26,7 @@
 #include <sys/ioctl.h>
 #include <iio_common.h>
 
-
 using std::ifstream;
-using config::csensor_config;
 
 #define SENSOR_TYPE_TEMPERATURE                "TEMPERATURE"
 #define ELEMENT_NAME                           "NAME"