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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#include <fcntl.h>
#include <unistd.h>
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <libevdev/libevdev.h>
#include "utility.hpp"
#include "cooling_type.hpp"
#include "sdbusplus.hpp"
namespace phosphor
{
namespace cooling
{
namespace type
{
// For throwing exception
using namespace phosphor::logging;
using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
Error::InternalFailure;
std::unique_ptr<libevdev, FreeEvDev> evdevOpen(int fd)
{
libevdev* gpioDev = nullptr;
auto rc = libevdev_new_from_fd(fd, &gpioDev);
if (!rc)
{
return decltype(evdevOpen(0))(gpioDev);
}
log<level::ERR>("Failed to get libevdev from file descriptor",
entry("RC=%d", rc));
elog<InternalFailure>();
return decltype(evdevOpen(0))(nullptr);
}
void CoolingType::setAirCooled()
{
airCooled = true;
}
void CoolingType::setWaterCooled()
{
waterCooled = true;
}
void CoolingType::readGpio(const std::string& gpioPath, unsigned int keycode)
{
using namespace phosphor::logging;
gpioFd.open(gpioPath.c_str(), O_RDONLY);
auto gpioDev = evdevOpen(gpioFd());
auto value = static_cast<int>(0);
auto fetch_rc = libevdev_fetch_event_value(gpioDev.get(), EV_KEY,
keycode, &value);
if (0 == fetch_rc)
{
log<level::ERR>("Device does not support event type",
entry("KEYCODE=%d", keycode));
elog<InternalFailure>();
}
// TODO openbmc/phosphor-fan-presence#6
if (value > 0)
{
setAirCooled();
}
else
{
setWaterCooled();
}
}
CoolingType::ObjectMap CoolingType::getObjectMap(const std::string& objpath)
{
ObjectMap invObj;
InterfaceMap invIntf;
PropertyMap invProp;
invProp.emplace("AirCooled", airCooled);
invProp.emplace("WaterCooled", waterCooled);
invIntf.emplace("xyz.openbmc_project.Inventory.Decorator.CoolingType",
std::move(invProp));
invObj.emplace(objpath, std::move(invIntf));
return invObj;
}
void CoolingType::updateInventory(const std::string& objpath)
{
using namespace phosphor::fan;
ObjectMap invObj = getObjectMap(objpath);
// Update inventory
auto invMgrResponseMsg = util::SDBusPlus::lookupAndCallMethod(
bus,
util::INVENTORY_PATH,
util::INVENTORY_INTF,
"Notify",
std::move(invObj));
}
}
}
}
// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|