129dbfa6dSBrad Bishop /** 229dbfa6dSBrad Bishop * Copyright © 2016 IBM Corporation 329dbfa6dSBrad Bishop * 429dbfa6dSBrad Bishop * Licensed under the Apache License, Version 2.0 (the "License"); 529dbfa6dSBrad Bishop * you may not use this file except in compliance with the License. 629dbfa6dSBrad Bishop * You may obtain a copy of the License at 729dbfa6dSBrad Bishop * 829dbfa6dSBrad Bishop * http://www.apache.org/licenses/LICENSE-2.0 929dbfa6dSBrad Bishop * 1029dbfa6dSBrad Bishop * Unless required by applicable law or agreed to in writing, software 1129dbfa6dSBrad Bishop * distributed under the License is distributed on an "AS IS" BASIS, 1229dbfa6dSBrad Bishop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1329dbfa6dSBrad Bishop * See the License for the specific language governing permissions and 1429dbfa6dSBrad Bishop * limitations under the License. 1529dbfa6dSBrad Bishop */ 166292aeedSMatthew Barth #include "sensorset.hpp" 17*043d3230SPatrick Venture 186e8f6239SBrad Bishop #include "hwmon.hpp" 196292aeedSMatthew Barth 20*043d3230SPatrick Venture #include <experimental/filesystem> 21*043d3230SPatrick Venture #include <iostream> 22*043d3230SPatrick Venture #include <regex> 23*043d3230SPatrick Venture 246292aeedSMatthew Barth // TODO: Issue#2 - STL regex generates really bloated code. Use POSIX regex 256292aeedSMatthew Barth // interfaces instead. 26*043d3230SPatrick Venture static const std::regex sensors_regex = std::regex( 27*043d3230SPatrick Venture "^(fan|in|temp|power|energy|curr)([0-9]+)_([a-z]*)", std::regex::extended); 286292aeedSMatthew Barth static const auto sensor_regex_match_count = 4; 296292aeedSMatthew Barth 306292aeedSMatthew Barth SensorSet::SensorSet(const std::string& path) 316292aeedSMatthew Barth { 3208379a31SBrad Bishop namespace fs = std::experimental::filesystem; 336292aeedSMatthew Barth 3408379a31SBrad Bishop for (const auto& file : fs::directory_iterator(path)) 356292aeedSMatthew Barth { 366292aeedSMatthew Barth std::smatch match; 3708379a31SBrad Bishop auto fileName = file.path().filename(); 3808379a31SBrad Bishop std::regex_search(fileName.native(), match, sensors_regex); 396292aeedSMatthew Barth 406bb97a97SBrad Bishop if (match.size() != sensor_regex_match_count) 416bb97a97SBrad Bishop { 426bb97a97SBrad Bishop continue; 436bb97a97SBrad Bishop } 446292aeedSMatthew Barth 456e8f6239SBrad Bishop if (match[3] == hwmon::entry::label) 466e8f6239SBrad Bishop { 476e8f6239SBrad Bishop continue; 486e8f6239SBrad Bishop } 496e8f6239SBrad Bishop 506292aeedSMatthew Barth container[make_pair(match[1], match[2])].emplace(match[3]); 516292aeedSMatthew Barth } 526292aeedSMatthew Barth } 5303476f11SBrad Bishop 5403476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 55