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     {
19         return std::string();
20     }
21 
22     // Points to the last element in the path
23     auto conf = --path.end();
24 
25     if (conf->empty() && conf != path.begin())
26     {
27         return *(--conf);
28     }
29     else
30     {
31         return *conf;
32     }
33 }
34 
35 bool Device::master() const
36 {
37     int master;
38     auto masterFile = devPath / "occ_master";
39     std::ifstream file(masterFile, std::ios::in);
40 
41     if (!file)
42     {
43         return false;
44     }
45 
46     file >> master;
47     file.close();
48     return (master != 0);
49 }
50 
51 void Device::throttleProcTempCallback(bool error)
52 {
53     statusObject.throttleProcTemp(error);
54 }
55 
56 void Device::throttleProcPowerCallback(bool error)
57 {
58     statusObject.throttleProcPower(error);
59 }
60 
61 void Device::throttleMemTempCallback(bool error)
62 {
63     statusObject.throttleMemTemp(error);
64 }
65 
66 } // namespace occ
67 } // namespace open_power
68