132e84e98SVishwanatha Subbanna #include "occ_device.hpp"
294df8c90SGunnar Mills 
3*cbad219eSEddie James #include "occ_manager.hpp"
4482e31ffSEddie James #include "occ_status.hpp"
532e84e98SVishwanatha Subbanna 
694df8c90SGunnar Mills #include <iostream>
794df8c90SGunnar Mills 
832e84e98SVishwanatha Subbanna namespace open_power
932e84e98SVishwanatha Subbanna {
1032e84e98SVishwanatha Subbanna namespace occ
1132e84e98SVishwanatha Subbanna {
1232e84e98SVishwanatha Subbanna 
1332e84e98SVishwanatha Subbanna fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
1432e84e98SVishwanatha Subbanna fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";
1532e84e98SVishwanatha Subbanna 
16774f9af9SEddie James std::string Device::getPathBack(const fs::path& path)
17774f9af9SEddie James {
18774f9af9SEddie James     if (path.empty())
19bcef3b48SGeorge Liu     {
20774f9af9SEddie James         return std::string();
21bcef3b48SGeorge Liu     }
22774f9af9SEddie James 
23774f9af9SEddie James     // Points to the last element in the path
24774f9af9SEddie James     auto conf = --path.end();
25774f9af9SEddie James 
26bcef3b48SGeorge Liu     if (conf->empty() && conf != path.begin())
27774f9af9SEddie James     {
28774f9af9SEddie James         return *(--conf);
29774f9af9SEddie James     }
30774f9af9SEddie James     else
31774f9af9SEddie James     {
32774f9af9SEddie James         return *conf;
33774f9af9SEddie James     }
34774f9af9SEddie James }
35774f9af9SEddie James 
36636577f4SEdward A. James bool Device::master() const
37636577f4SEdward A. James {
38636577f4SEdward A. James     int master;
39774f9af9SEddie 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 
52*cbad219eSEddie James void Device::errorCallback(bool error)
53*cbad219eSEddie James {
54*cbad219eSEddie James     if (error)
55*cbad219eSEddie James     {
56*cbad219eSEddie James         statusObject.deviceError();
57*cbad219eSEddie James     }
58*cbad219eSEddie James }
59*cbad219eSEddie James 
60*cbad219eSEddie James #ifdef PLDM
61*cbad219eSEddie James void Device::timeoutCallback(bool error)
62*cbad219eSEddie James {
63*cbad219eSEddie James     if (error)
64*cbad219eSEddie James     {
65*cbad219eSEddie James         managerObject.sbeTimeout(instance);
66*cbad219eSEddie James     }
67*cbad219eSEddie James }
68*cbad219eSEddie James #endif
69*cbad219eSEddie James 
70482e31ffSEddie James void Device::throttleProcTempCallback(bool error)
71482e31ffSEddie James {
72482e31ffSEddie James     statusObject.throttleProcTemp(error);
73482e31ffSEddie James }
74482e31ffSEddie James 
75482e31ffSEddie James void Device::throttleProcPowerCallback(bool error)
76482e31ffSEddie James {
77482e31ffSEddie James     statusObject.throttleProcPower(error);
78482e31ffSEddie James }
79482e31ffSEddie James 
80482e31ffSEddie James void Device::throttleMemTempCallback(bool error)
81482e31ffSEddie James {
82482e31ffSEddie James     statusObject.throttleMemTemp(error);
83482e31ffSEddie James }
84482e31ffSEddie James 
8532e84e98SVishwanatha Subbanna } // namespace occ
8632e84e98SVishwanatha Subbanna } // namespace open_power
87