-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathocc_presence.cpp
59 lines (50 loc) · 1.44 KB
/
occ_presence.cpp
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
#include "occ_presence.hpp"
#include "occ_manager.hpp"
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <org/open_power/OCC/Device/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace open_power
{
namespace occ
{
// Reads the occs_present file and analyzes the data
void Presence::analyzeEvent()
{
using namespace phosphor::logging;
using namespace sdbusplus::org::open_power::OCC::Device::Error;
// Get the number of bytes to read
int len = -1;
auto r = ioctl(fd, FIONREAD, &len);
if (r < 0)
{
elog<ConfigFailure>(
phosphor::logging::org::open_power::OCC::Device::ConfigFailure::
CALLOUT_ERRNO(errno),
phosphor::logging::org::open_power::OCC::Device::ConfigFailure::
CALLOUT_DEVICE_PATH(file.c_str()));
}
auto data = readFile(len);
if (data.empty())
{
return;
}
// Let stoi determine the base
auto occsPresent = std::stoi(data, nullptr, 0);
if (manager.getNumOCCs() != occsPresent)
{
lg2::error("OCC presence mismatch - BMC: {BNUM}, OCC: {ONUM}", "BNUM",
manager.getNumOCCs(), "ONUM", occsPresent);
if (callBack)
{
callBack(occsPresent);
}
}
}
} // namespace occ
} // namespace open_power