summaryrefslogtreecommitdiffstats
path: root/occ_device.cpp
blob: 6cd6a1f8a87fb8bcca5e6bdb8305292ee41c0694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "occ_device.hpp"

#include "occ_status.hpp"

#include <iostream>

namespace open_power
{
namespace occ
{

fs::path Device::bindPath = fs::path(OCC_HWMON_PATH) / "bind";
fs::path Device::unBindPath = fs::path(OCC_HWMON_PATH) / "unbind";

std::string Device::getPathBack(const fs::path& path)
{
    if (path.empty())
        return std::string();

    // Points to the last element in the path
    auto conf = --path.end();

    // The last element will be '.' if the path ends in '/'
    // This behavior differs between filesystem and experimental::filesystem
    // Verify there is an element before too
    if (!conf->compare(".") && conf != path.begin())
    {
        return *(--conf);
    }
    else
    {
        return *conf;
    }
}

bool Device::master() const
{
    int master;
    auto masterFile = devPath / "occ_master";
    std::ifstream file(masterFile, std::ios::in);

    if (!file)
    {
        return false;
    }

    file >> master;
    file.close();
    return (master != 0);
}

void Device::throttleProcTempCallback(bool error)
{
    statusObject.throttleProcTemp(error);
}

void Device::throttleProcPowerCallback(bool error)
{
    statusObject.throttleProcPower(error);
}

void Device::throttleMemTempCallback(bool error)
{
    statusObject.throttleMemTemp(error);
}

} // namespace occ
} // namespace open_power
OpenPOWER on IntegriCloud