From 0bd9a6b6dba2efc5a269279a0eefacd892b885fd Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 29 Jun 2016 11:51:58 +0900 Subject: [PATCH] sensord: remove unused sensor_config sources - device_config - virtual_sensor_config Change-Id: I91eb3abf9c062c6dd0576b846440fc199b6be89f Signed-off-by: kibak.yoon --- packaging/sensord.spec | 1 - src/sensor/virtual_sensors.xml | 271 ------------------------------ src/server/CMakeLists.txt | 2 +- src/server/device_config.cpp | 72 -------- src/server/device_config.h | 40 ----- src/server/virtual_sensor_config.cpp | 315 ----------------------------------- src/server/virtual_sensor_config.h | 83 --------- 7 files changed, 1 insertion(+), 783 deletions(-) delete mode 100644 src/sensor/virtual_sensors.xml delete mode 100644 src/server/device_config.cpp delete mode 100644 src/server/device_config.h delete mode 100644 src/server/virtual_sensor_config.cpp delete mode 100644 src/server/virtual_sensor_config.h diff --git a/packaging/sensord.spec b/packaging/sensord.spec index e743bc9..9111df8 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -12,7 +12,6 @@ Source3: sensord_event.socket BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libsystemd-daemon) diff --git a/src/sensor/virtual_sensors.xml b/src/sensor/virtual_sensors.xml deleted file mode 100644 index c0c08f5..0000000 --- a/src/sensor/virtual_sensors.xml +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 50ac418..763e904 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensord CXX) -SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon libxml-2.0 cynara-client cynara-creds-socket cynara-session") +SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS}) diff --git a/src/server/device_config.cpp b/src/server/device_config.cpp deleted file mode 100644 index 082b6d6..0000000 --- a/src/server/device_config.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * sensord - * - * 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 - -using std::ifstream; -using std::string; -using std::istringstream; - -device_config::device_config(void) -{ -} - -device_config::~device_config(void) -{ -} - -bool device_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) - continue; - - start_pos = start_pos + START_DELIMETER.size(); - end_pos = line.find(END_DELIMETER, start_pos); - - if (end_pos == std::string::npos) - continue; - - m_device_id = line.substr(start_pos, end_pos - start_pos); - ret = true; - break; - } - - in_file.close(); - - return ret; -} diff --git a/src/server/device_config.h b/src/server/device_config.h deleted file mode 100644 index 5c73509..0000000 --- a/src/server/device_config.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * sensord - * - * 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 _DEVICE_CONFIG_H_ -#define _DEVICE_CONFIG_H_ - -#include -#include -#include - -class device_config { -public: - device_config(); - virtual ~device_config(); - - bool get_device_id(void); - -protected: - virtual bool load_config(const std::string& config_path) = 0; - - std::string m_device_id; -}; - -#endif /* _DEVICE_CONFIG_H_ */ diff --git a/src/server/virtual_sensor_config.cpp b/src/server/virtual_sensor_config.cpp deleted file mode 100644 index fc57bd8..0000000 --- a/src/server/virtual_sensor_config.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - * sensord - * - * 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 "sensor_log.h" -#include -#include -#include -#include -#include - -using std::string; -using std::stringstream; - -#define ROOT_ELEMENT "VIRTUAL_SENSOR" -#define DEVICE_TYPE_ATTR "type" -#define TEXT_ELEMENT "text" -#define DEFAULT_ATTR "value" -#define DEFAULT_ATTR1 "value1" -#define DEFAULT_ATTR2 "value2" -#define DEFAULT_ATTR3 "value3" -#define DEFAULT_DEVICE "Default" - -virtual_sensor_config::virtual_sensor_config() -{ -} - -virtual_sensor_config& virtual_sensor_config::get_instance(void) -{ - static bool load_done = false; - static virtual_sensor_config inst; - - if (!load_done) { - inst.load_config(VIRTUAL_SENSOR_CONFIG_FILE_PATH); - inst.get_device_id(); - if (!inst.m_device_id.empty()) - _I("Device ID = %s", inst.m_device_id.c_str()); - else - _E("Failed to get Device ID"); - load_done = true; - } - - return inst; -} - -bool virtual_sensor_config::load_config(const string& config_path) -{ - xmlDocPtr doc; - xmlNodePtr cur; - - _D("virtual_sensor_config::load_config(\"%s\") is called!\n", config_path.c_str()); - - doc = xmlParseFile(config_path.c_str()); - - if (doc == NULL) { - _E("There is no %s\n", config_path.c_str()); - return false; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - _E("There is no root element in %s\n", config_path.c_str()); - xmlFreeDoc(doc); - return false; - } - - if (xmlStrcmp(cur->name, (const xmlChar *)ROOT_ELEMENT)) { - _E("Wrong type document: there is no [%s] root element in %s\n", ROOT_ELEMENT, config_path.c_str()); - xmlFreeDoc(doc); - return false; - } - - xmlNodePtr device_node_ptr; - xmlNodePtr virtual_sensor_node_ptr; - xmlNodePtr element_node_ptr; - xmlAttrPtr attr_ptr; - char* prop = NULL; - - device_node_ptr = cur->xmlChildrenNode; - while (device_node_ptr != NULL){ - //skip garbage element, [text] - if (!xmlStrcmp(device_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) { - device_node_ptr = device_node_ptr->next; - continue; - } - - string device_type; - prop = (char*)xmlGetProp(device_node_ptr, (const xmlChar*)DEVICE_TYPE_ATTR); - device_type = prop; - free(prop); - - //insert device to device_list - m_virtual_sensor_configs[device_type]; - _D("\n", device_type.c_str()); - - virtual_sensor_node_ptr = device_node_ptr->xmlChildrenNode; - - while (virtual_sensor_node_ptr != NULL) { - //skip garbage element, [text] - if (!xmlStrcmp(virtual_sensor_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) { - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; - continue; - } - - m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name]; - _D("<%s>\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name); - - element_node_ptr = virtual_sensor_node_ptr->xmlChildrenNode; - while (element_node_ptr != NULL) { - //skip garbage element, [text] - if (!xmlStrcmp(element_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) { - element_node_ptr = element_node_ptr->next; - continue; - } - - //insert Element to Model - m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name]; - _D("<%s><%s>\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name); - - attr_ptr = element_node_ptr->properties; - while (attr_ptr != NULL) { - string key, value; - key = (char*)attr_ptr->name; - prop = (char*)xmlGetProp(element_node_ptr, attr_ptr->name); - value = prop; - free(prop); - - //insert attribute to Element - m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key] = value; - _D("<%s><%s \"%s\"=\"%s\">\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name, key.c_str(), value.c_str()); - attr_ptr = attr_ptr->next; - } - - element_node_ptr = element_node_ptr->next; - } - - _D("\n"); - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; - } - - device_node_ptr = device_node_ptr->next; - } - - xmlFreeDoc(doc); - return true; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, string& value) -{ - auto it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) { - _E("There is no <%s> device\n", m_device_id.c_str()); - - m_device_id = DEFAULT_DEVICE; - it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) { - _E("There is no Default device\n"); - return false; - } - - _I("m_device_id is set to Default\n"); - } - - auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - - if (it_virtual_sensor_list == it_device_list->second.end()) { - _E("There is no <%s> sensor\n", sensor_type.c_str()); - return false; - } - - auto it_element = it_virtual_sensor_list->second.find(element); - - if (it_element == it_virtual_sensor_list->second.end()) { - _E("There is no <%s><%s> element\n", sensor_type.c_str(), element.c_str()); - return false; - } - - auto it_attr = it_element->second.find(attr); - - if (it_attr == it_element->second.end()) { - _D("There is no <%s><%s \"%s\">\n", sensor_type.c_str(), element.c_str(), attr.c_str()); - return false; - } - - value = it_attr->second; - - return true; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, float *value) -{ - string str_value; - - if (get(sensor_type, element, attr, str_value) == false) - return false; - - stringstream str_stream(str_value); - - str_stream >> *value; - - return true; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, int *value) -{ - string str_value; - - if (get(sensor_type, element, attr, str_value) == false) - return false; - - stringstream str_stream(str_value); - - str_stream >> *value; - - return true; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, string& value) -{ - if (get(sensor_type, element, DEFAULT_ATTR, value)) - return true; - - return false; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, float *value, int count) -{ - if (count == 1) { - if (get(sensor_type, element, DEFAULT_ATTR, value)) - return true; - } - - if (count == 3) { - if (!get(sensor_type, element, DEFAULT_ATTR1, value)) - return false; - - value++; - - if (!get(sensor_type, element, DEFAULT_ATTR2, value)) - return false; - - value++; - - if (!get(sensor_type, element, DEFAULT_ATTR3, value)) - return false; - - return true; - } - - _D("Count value not supported.\n"); - - return false; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, int *value, int count) -{ - if (count == 1) { - if (get(sensor_type, element, DEFAULT_ATTR, value)) - return true; - } - - if (count == 3) { - if (!get(sensor_type, element, DEFAULT_ATTR1, value)) - return false; - - value++; - - if (!get(sensor_type, element, DEFAULT_ATTR2, value)) - return false; - - value++; - - if (!get(sensor_type, element, DEFAULT_ATTR3, value)) - return false; - - return true; - } - - _D("Count value not supported.\n"); - - return false; -} - -bool virtual_sensor_config::is_supported(const string& sensor_type) -{ - auto it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) - return false; - - auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - - if (it_virtual_sensor_list == it_device_list->second.end()) - return false; - - return true; -} diff --git a/src/server/virtual_sensor_config.h b/src/server/virtual_sensor_config.h deleted file mode 100644 index 949d840..0000000 --- a/src/server/virtual_sensor_config.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * sensord - * - * 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 _VIRTUAL_SENSOR_CONFIG_H_ -#define _VIRTUAL_SENSOR_CONFIG_H_ - -#include - -#define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml" - -typedef std::unordered_map Element; -/* -* an Element is a group of attributes -* -* -*/ - -typedef std::unordered_map Virtual_sensor; -/* -* a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration -* -* -* -* ... -*/ - -typedef std::unordered_map virtual_sensor_configs; -/* -* a Virtual_sensor_config represents virtual_sensors.xml -* -* -* -* -*/ - -typedef std::unordered_map virtual_sensor_device_configs; -/* -* a virtual_sensor_device_config represents virtual_sensors.xml -* -* -* -*/ - -class virtual_sensor_config : public device_config { -private: - virtual_sensor_config(); - virtual_sensor_config& operator=(virtual_sensor_config const&); - - bool load_config(const std::string& config_path); - - virtual_sensor_device_configs m_virtual_sensor_configs; - -public: - static virtual_sensor_config& get_instance(void); - - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, std::string& value); - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, float *value); - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, int *value); - - bool get(const std::string& sensor_type, const std::string& element, std::string& value); - bool get(const std::string& sensor_type, const std::string& element, float *value, int count = 1); - bool get(const std::string& sensor_type, const std::string& element, int *value, int count = 1); - - bool is_supported(const std::string &sensor_type); -}; - -#endif /* _VIRTUAL_SENSOR_CONFIG_H_ */ -- 2.7.4