Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 1 | #include "occ_device.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 2 | |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 3 | #include "occ_status.hpp" |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 4 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 5 | #include <iostream> |
| 6 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 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 | |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 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 | |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 36 | bool Device::master() const |
| 37 | { |
| 38 | int master; |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 39 | auto masterFile = devPath / "occ_master"; |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 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 | |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 52 | void Device::throttleProcTempCallback(bool error) |
| 53 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 54 | statusObject.throttleProcTemp(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void Device::throttleProcPowerCallback(bool error) |
| 58 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 59 | statusObject.throttleProcPower(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void Device::throttleMemTempCallback(bool error) |
| 63 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 64 | statusObject.throttleMemTemp(error); |
Eddie James | 482e31f | 2017-09-14 13:17:17 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 67 | } // namespace occ |
| 68 | } // namespace open_power |