0 Star 0 Fork 0

openbmc/phosphor-gpio-monitor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
evdev.cpp 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
Patrick Venture 提交于 2018-11-01 16:52 . Add clang-format to repo
#include "evdev.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <fcntl.h>
#include <libevdev/libevdev.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
namespace phosphor
{
namespace gpio
{
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
// Populate the file descriptor for passed in device
int Evdev::openDevice()
{
using namespace phosphor::logging;
auto fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
log<level::ERR>("Failed to open device path",
entry("DEVICEPATH=%s", path.c_str()),
entry("ERRNO=%d", errno));
elog<InternalFailure>();
}
return fd;
}
// Initializes the event device with the fd
void Evdev::initEvDev()
{
if (devicePtr)
{
// Init can be done only once per device
return;
}
struct libevdev* evdev = nullptr;
auto rc = libevdev_new_from_fd((fd)(), &evdev);
if (rc < 0)
{
log<level::ERR>("Failed to initialize evdev");
elog<InternalFailure>();
return;
}
// Packing in the unique_ptr
devicePtr.reset(evdev);
}
// Attaches the FD to event loop and registers the callback handler
void Evdev::registerCallback()
{
decltype(eventSource.get()) sourcePtr = nullptr;
auto rc = sd_event_add_io(event.get(), &sourcePtr, (fd)(), EPOLLIN,
callbackHandler, this);
eventSource.reset(sourcePtr);
if (rc < 0)
{
log<level::ERR>("Failed to register callback handler",
entry("ERROR=%s", strerror(-rc)));
elog<InternalFailure>();
}
}
} // namespace gpio
} // namespace phosphor
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openbmc_masterhu/phosphor-gpio-monitor.git
git@gitee.com:openbmc_masterhu/phosphor-gpio-monitor.git
openbmc_masterhu
phosphor-gpio-monitor
phosphor-gpio-monitor
master

搜索帮助