1 #include "occ_device.hpp" 2 3 #include "occ_status.hpp" 4 5 #include <iostream> 6 7 namespace open_power 8 { 9 namespace occ 10 { 11 12 fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind"; 13 fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind"; 14 15 std::string Device::getPathBack(const fs::path& path) 16 { 17 if (path.empty()) 18 return std::string(); 19 20 // Points to the last element in the path 21 auto conf = --path.end(); 22 23 // The last element will be '.' if the path ends in '/' 24 // This behavior differs between filesystem and experimental::filesystem 25 // Verify there is an element before too 26 if (!conf->compare(".") && conf != path.begin()) 27 { 28 return *(--conf); 29 } 30 else 31 { 32 return *conf; 33 } 34 } 35 36 bool Device::master() const 37 { 38 int master; 39 auto masterFile = devPath / "occ_master"; 40 std::ifstream file(masterFile, std::ios::in); 41 42 if (!file) 43 { 44 return false; 45 } 46 47 file >> master; 48 file.close(); 49 return (master != 0); 50 } 51 52 void Device::throttleProcTempCallback(bool error) 53 { 54 statusObject.throttleProcTemp(error); 55 } 56 57 void Device::throttleProcPowerCallback(bool error) 58 { 59 statusObject.throttleProcPower(error); 60 } 61 62 void Device::throttleMemTempCallback(bool error) 63 { 64 statusObject.throttleMemTemp(error); 65 } 66 67 } // namespace occ 68 } // namespace open_power 69