blob: 6cd6a1f8a87fb8bcca5e6bdb8305292ee41c0694 [file] [log] [blame]
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05301#include "occ_device.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05002
Eddie James482e31f2017-09-14 13:17:17 -05003#include "occ_status.hpp"
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05304
Gunnar Mills94df8c92018-09-14 14:50:03 -05005#include <iostream>
6
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +05307namespace open_power
8{
9namespace occ
10{
11
12fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
13fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";
14
Eddie James774f9af2019-03-19 20:58:53 +000015std::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. James636577f2017-10-06 10:53:55 -050036bool Device::master() const
37{
38 int master;
Eddie James774f9af2019-03-19 20:58:53 +000039 auto masterFile = devPath / "occ_master";
Edward A. James636577f2017-10-06 10:53:55 -050040 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 James482e31f2017-09-14 13:17:17 -050052void Device::throttleProcTempCallback(bool error)
53{
Gunnar Mills94df8c92018-09-14 14:50:03 -050054 statusObject.throttleProcTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050055}
56
57void Device::throttleProcPowerCallback(bool error)
58{
Gunnar Mills94df8c92018-09-14 14:50:03 -050059 statusObject.throttleProcPower(error);
Eddie James482e31f2017-09-14 13:17:17 -050060}
61
62void Device::throttleMemTempCallback(bool error)
63{
Gunnar Mills94df8c92018-09-14 14:50:03 -050064 statusObject.throttleMemTemp(error);
Eddie James482e31f2017-09-14 13:17:17 -050065}
66
Vishwanatha Subbanna32e84e92017-06-28 19:17:28 +053067} // namespace occ
68} // namespace open_power