xref: /openbmc/phosphor-hwmon/sensorset.cpp (revision 6e8f6239)
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 <regex>
176292aeedSMatthew Barth #include <iostream>
186292aeedSMatthew Barth #include "sensorset.hpp"
196292aeedSMatthew Barth #include "directory.hpp"
20*6e8f6239SBrad Bishop #include "hwmon.hpp"
216292aeedSMatthew Barth 
226292aeedSMatthew Barth // TODO: Issue#2 - STL regex generates really bloated code.  Use POSIX regex
236292aeedSMatthew Barth //       interfaces instead.
246292aeedSMatthew Barth static const std::regex sensors_regex =
256292aeedSMatthew Barth     std::regex("^(fan|in|temp)([0-9]+)_([a-z]*)", std::regex::extended);
266292aeedSMatthew Barth static const auto sensor_regex_match_count = 4;
276292aeedSMatthew Barth 
286292aeedSMatthew Barth SensorSet::SensorSet(const std::string& path)
296292aeedSMatthew Barth {
306292aeedSMatthew Barth     Directory d(path);
316292aeedSMatthew Barth     std::string file;
326292aeedSMatthew Barth 
336292aeedSMatthew Barth     while (d.next(file))
346292aeedSMatthew Barth     {
356292aeedSMatthew Barth         std::smatch match;
366292aeedSMatthew Barth         std::regex_search(file, match, sensors_regex);
376292aeedSMatthew Barth 
386bb97a97SBrad Bishop         if (match.size() != sensor_regex_match_count)
396bb97a97SBrad Bishop         {
406bb97a97SBrad Bishop             continue;
416bb97a97SBrad Bishop         }
426292aeedSMatthew Barth 
43*6e8f6239SBrad Bishop         if (match[3] == hwmon::entry::label)
44*6e8f6239SBrad Bishop         {
45*6e8f6239SBrad Bishop             continue;
46*6e8f6239SBrad Bishop         }
47*6e8f6239SBrad Bishop 
486292aeedSMatthew Barth         container[make_pair(match[1], match[2])].emplace(match[3]);
496292aeedSMatthew Barth     }
506292aeedSMatthew Barth }
5103476f11SBrad Bishop 
5203476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
53