#include #include #include #include #include #include #include #include #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 evdevOpen(int fd) { libevdev* gpioDev = nullptr; auto rc = libevdev_new_from_fd(fd, &gpioDev); if (!rc) { return decltype(evdevOpen(0))(gpioDev); } log("Failed to get libevdev from file descriptor", entry("RC=%d", rc)); elog(); 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(0); auto fetch_rc = libevdev_fetch_event_value(gpioDev.get(), EV_KEY, keycode, &value); if (0 == fetch_rc) { log("Device does not support event type", entry("KEYCODE=%d", keycode)); elog(); } // 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