132e84e98SVishwanatha Subbanna #include "occ_device.hpp" 294df8c90SGunnar Mills 3482e31ffSEddie James #include "occ_status.hpp" 432e84e98SVishwanatha Subbanna 594df8c90SGunnar Mills #include <iostream> 694df8c90SGunnar Mills 732e84e98SVishwanatha Subbanna namespace open_power 832e84e98SVishwanatha Subbanna { 932e84e98SVishwanatha Subbanna namespace occ 1032e84e98SVishwanatha Subbanna { 1132e84e98SVishwanatha Subbanna 1232e84e98SVishwanatha Subbanna fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind"; 1332e84e98SVishwanatha Subbanna fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind"; 1432e84e98SVishwanatha Subbanna 15*774f9af9SEddie James std::string Device::getPathBack(const fs::path& path) 16*774f9af9SEddie James { 17*774f9af9SEddie James if (path.empty()) 18*774f9af9SEddie James return std::string(); 19*774f9af9SEddie James 20*774f9af9SEddie James // Points to the last element in the path 21*774f9af9SEddie James auto conf = --path.end(); 22*774f9af9SEddie James 23*774f9af9SEddie James // The last element will be '.' if the path ends in '/' 24*774f9af9SEddie James // This behavior differs between filesystem and experimental::filesystem 25*774f9af9SEddie James // Verify there is an element before too 26*774f9af9SEddie James if (!conf->compare(".") && conf != path.begin()) 27*774f9af9SEddie James { 28*774f9af9SEddie James return *(--conf); 29*774f9af9SEddie James } 30*774f9af9SEddie James else 31*774f9af9SEddie James { 32*774f9af9SEddie James return *conf; 33*774f9af9SEddie James } 34*774f9af9SEddie James } 35*774f9af9SEddie James 36636577f4SEdward A. James bool Device::master() const 37636577f4SEdward A. James { 38636577f4SEdward A. James int master; 39*774f9af9SEddie James auto masterFile = devPath / "occ_master"; 40636577f4SEdward A. James std::ifstream file(masterFile, std::ios::in); 41636577f4SEdward A. James 42636577f4SEdward A. James if (!file) 43636577f4SEdward A. James { 44636577f4SEdward A. James return false; 45636577f4SEdward A. James } 46636577f4SEdward A. James 47636577f4SEdward A. James file >> master; 48636577f4SEdward A. James file.close(); 49636577f4SEdward A. James return (master != 0); 50636577f4SEdward A. James } 51636577f4SEdward A. James 52482e31ffSEddie James void Device::throttleProcTempCallback(bool error) 53482e31ffSEddie James { 54482e31ffSEddie James statusObject.throttleProcTemp(error); 55482e31ffSEddie James } 56482e31ffSEddie James 57482e31ffSEddie James void Device::throttleProcPowerCallback(bool error) 58482e31ffSEddie James { 59482e31ffSEddie James statusObject.throttleProcPower(error); 60482e31ffSEddie James } 61482e31ffSEddie James 62482e31ffSEddie James void Device::throttleMemTempCallback(bool error) 63482e31ffSEddie James { 64482e31ffSEddie James statusObject.throttleMemTemp(error); 65482e31ffSEddie James } 66482e31ffSEddie James 6732e84e98SVishwanatha Subbanna } // namespace occ 6832e84e98SVishwanatha Subbanna } // namespace open_power 69