blob: 23fece019a6cb7c27538f6e66ad8552d674c3ff0 [file] [log] [blame]
Edward A. James636577f2017-10-06 10:53:55 -05001#include <fcntl.h>
2#include <unistd.h>
3#include <sys/ioctl.h>
4#include <errno.h>
5#include <phosphor-logging/log.hpp>
6#include <phosphor-logging/elog.hpp>
7#include <xyz/openbmc_project/Common/error.hpp>
8#include <org/open_power/OCC/Device/error.hpp>
9#include "occ_presence.hpp"
10#include "occ_manager.hpp"
11#include "elog-errors.hpp"
12
13namespace open_power
14{
15namespace occ
16{
17
18// Reads the occs_present file and analyzes the data
19void Presence::analyzeEvent()
20{
21 using namespace phosphor::logging;
22 using namespace sdbusplus::org::open_power::OCC::Device::Error;
23
24 // Get the number of bytes to read
25 int len = -1;
26 auto r = ioctl(fd, FIONREAD, &len);
27 if (r < 0)
28 {
29 elog<ConfigFailure>(
30 phosphor::logging::org::open_power::OCC::Device::
31 ConfigFailure::CALLOUT_ERRNO(errno),
32 phosphor::logging::org::open_power::OCC::Device::
33 ConfigFailure::CALLOUT_DEVICE_PATH(file.c_str()));
34 }
35
36 auto data = readFile(len);
37 if (data.empty())
38 {
39 return;
40 }
41
42 // Let stoi determine the base
43 auto occsPresent = std::stoi(data, nullptr, 0);
44 if (manager.getNumOCCs() != occsPresent)
45 {
46 log<level::INFO>("OCC presence mismatch",
47 entry("BMC_OCCS=%d", manager.getNumOCCs(),
48 entry("OCC_OCCS=%d", occsPresent)));
49 if (callBack)
50 {
Eddie James482e31f2017-09-14 13:17:17 -050051 callBack(true);
Edward A. James636577f2017-10-06 10:53:55 -050052 }
53 }
54}
55
56} // namespace occ
57} // namespace open_power