29
29
#include "thd_parse.h"
30
30
#include <stdlib.h>
31
32
#include "thd_sys_fs.h"
33
#include "thd_trt_art_reader.h"
33
35
#define DEBUG_PARSER_PRINT(x,...)
35
37
void cthd_parse::string_trim(std::string &str) {
36
std::string::size_type pos = str.find_last_not_of(' ');
37
if (pos != std::string::npos) {
39
pos = str.find_first_not_of(' ');
40
if (pos != std::string::npos)
43
str.erase(str.begin(), str.end());
38
std::string chars = "\n \t\r";
40
for (unsigned int i = 0; i < chars.length(); ++i) {
41
str.erase(std::remove(str.begin(), str.end(), chars[i]), str.end());
72
71
cthd_parse::cthd_parse() :
73
72
matched_thermal_info_index(-1), doc(NULL), root_element(NULL) {
74
std::string name = TDCONFDIR;
75
filename = name + "/" "thermal-conf.xml";
73
std::string name_conf = TDCONFDIR;
74
std::string name_run = TDRUNDIR;
75
filename = name_conf + "/" + "thermal-conf.xml";
76
filename_auto = name_run + "/" + "thermal-conf.xml.auto";
78
79
int cthd_parse::parser_init() {
80
doc = xmlReadFile(filename.c_str(), NULL, 0);
83
ret = rel.generate_conf(filename_auto);
85
thd_log_warn("Using generated %s\n", filename_auto.c_str());
86
doc = xmlReadFile(filename_auto.c_str(), NULL, 0);
88
doc = xmlReadFile(filename.c_str(), NULL, 0);
82
91
thd_log_warn("error: could not parse file %s\n", filename.c_str());
175
186
int cthd_parse::parse_trip_points(xmlNode * a_node, xmlDoc *doc,
176
187
thermal_zone_t *info_ptr) {
177
188
xmlNode *cur_node = NULL;
178
trip_point_t trip_pt;
180
190
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
181
191
if (cur_node->type == XML_ELEMENT_NODE) {
182
192
DEBUG_PARSER_PRINT("node type: Element, name: %s value: %s\n", cur_node->name, xmlNodeListGetString(doc, cur_node->xmlChildrenNode, 1));
183
193
if (!strcasecmp((const char*) cur_node->name, "TripPoint")) {
194
trip_point_t trip_pt;
184
196
trip_pt.hyst = trip_pt.temperature = 0;
185
197
trip_pt.trip_pt_type = PASSIVE;
186
198
trip_pt.control_type = PARALLEL;
551
563
for (unsigned int k = 0;
552
564
k < thermal_info_list[i].zones[j].trip_pts.size(); ++k) {
553
565
thd_log_info("\t\t Trip Point %u \n", k);
554
thd_log_info("\t\t temp id %d \n",
566
thd_log_info("\t\t temp %d \n",
555
567
thermal_info_list[i].zones[j].trip_pts[k].temperature);
556
568
thd_log_info("\t\t trip type %d \n",
557
569
thermal_info_list[i].zones[j].trip_pts[k].trip_pt_type);
558
570
thd_log_info("\t\t hyst id %d \n",
559
571
thermal_info_list[i].zones[j].trip_pts[k].hyst);
572
thd_log_info("\t\t sensor type %s \n",
573
thermal_info_list[i].zones[j].trip_pts[k].sensor_type.c_str());
561
575
for (unsigned int l = 0;
563
577
< thermal_info_list[i].zones[j].trip_pts[k].cdev_trips.size();
565
thd_log_info("\t\t Trip id %u \n", l);
579
thd_log_info("\t\t cdev index %u \n", l);
566
580
thd_log_info("\t\t\t type %s \n",
567
581
thermal_info_list[i].zones[j].trip_pts[k].cdev_trips[l].type.c_str());
568
582
thd_log_info("\t\t\t influence %d \n",
603
617
bool cthd_parse::platform_matched() {
604
csys_fs thd_sysfs("/sys/class/dmi/id/");
606
if (thd_sysfs.exists(std::string("product_uuid"))) {
607
thd_log_debug("checking UUID\n");
609
if (thd_sysfs.read("product_uuid", str) >= 0) {
610
thd_log_info("UUID is [%s]\n", str.c_str());
611
for (unsigned int i = 0; i < thermal_info_list.size(); ++i) {
612
if (thermal_info_list[i].uuid == "*") {
613
matched_thermal_info_index = i;
614
thd_log_info("UUID matched [wildcard]\n");
617
if (thermal_info_list[i].uuid == str) {
618
matched_thermal_info_index = i;
619
thd_log_info("Product UUID matched \n");
621
std::ifstream product_uuid("/sys/class/dmi/id/product_uuid");
623
if (product_uuid.is_open() && getline(product_uuid, line)) {
624
for (unsigned int i = 0; i < thermal_info_list.size(); ++i) {
625
if (!thermal_info_list[i].uuid.size())
628
thd_log_debug("config product uuid [%s] match with [%s]\n",
629
thermal_info_list[i].uuid.c_str(), line.c_str());
630
if (thermal_info_list[i].uuid == "*") {
631
matched_thermal_info_index = i;
632
thd_log_info("UUID matched [wildcard]\n");
635
if (line == thermal_info_list[i].uuid) {
636
matched_thermal_info_index = i;
637
thd_log_info("UUID matched \n");
626
if (thd_sysfs.exists(std::string("product_name"))) {
627
thd_log_debug("checking product name\n");
628
char product_name[128] = { };
629
// Use different read method as the product name contains spaces
630
if (thd_sysfs.read("product_name", product_name, 127) >= 0) {
631
product_name[127] = '\0';
632
int len = strlen(product_name);
635
for (int i = 0; i < len; ++i)
636
if (product_name[i] == '\n')
637
product_name[i] = '\0';
638
thd_log_info("product name is[%s]\n", product_name);
639
for (unsigned int i = 0; i < thermal_info_list.size(); ++i) {
640
if (!thermal_info_list[i].product_name.size())
642
thd_log_debug("config product name %s\n",
643
thermal_info_list[i].product_name.c_str());
644
if (thermal_info_list[i].product_name == "*") {
645
matched_thermal_info_index = i;
646
thd_log_info("Product Name matched [wildcard]\n");
649
if (thermal_info_list[i].product_name.compare(0,
650
strlen(product_name), product_name) == 0) {
651
matched_thermal_info_index = i;
652
thd_log_info("Product Name matched \n");
643
std::ifstream product_name("/sys/class/dmi/id/product_name");
645
if (product_name.is_open() && getline(product_name, line)) {
646
for (unsigned int i = 0; i < thermal_info_list.size(); ++i) {
647
if (!thermal_info_list[i].product_name.size())
650
thd_log_debug("config product name [%s] match with [%s]\n",
651
thermal_info_list[i].product_name.c_str(), line.c_str());
652
if (thermal_info_list[i].product_name == "*") {
653
matched_thermal_info_index = i;
654
thd_log_info("Product Name matched [wildcard]\n");
657
if (line == thermal_info_list[i].product_name) {
658
matched_thermal_info_index = i;
659
thd_log_info("Product Name matched \n");