Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd81befb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Look up devices by fd"

parents a5ba7b54 4bc561ca
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -192,8 +192,6 @@ bool EventHub::Device::hasValidFd() {

// --- EventHub ---

const uint32_t EventHub::EPOLL_ID_INOTIFY;
const uint32_t EventHub::EPOLL_ID_WAKE;
const int EventHub::EPOLL_SIZE_HINT;
const int EventHub::EPOLL_MAX_EVENTS;

@@ -216,7 +214,7 @@ EventHub::EventHub(void) :
    struct epoll_event eventItem;
    memset(&eventItem, 0, sizeof(eventItem));
    eventItem.events = EPOLLIN;
    eventItem.data.u32 = EPOLL_ID_INOTIFY;
    eventItem.data.fd = mINotifyFd;
    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add INotify to epoll instance.  errno=%d", errno);

@@ -235,7 +233,7 @@ EventHub::EventHub(void) :
    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking.  errno=%d",
            errno);

    eventItem.data.u32 = EPOLL_ID_WAKE;
    eventItem.data.fd = mWakeReadPipeFd;
    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance.  errno=%d",
            errno);
@@ -734,6 +732,16 @@ EventHub::Device* EventHub::getDeviceByPathLocked(const char* devicePath) const
    return nullptr;
}

EventHub::Device* EventHub::getDeviceByFdLocked(int fd) const {
    for (size_t i = 0; i < mDevices.size(); i++) {
        Device* device = mDevices.valueAt(i);
        if (device->fd == fd) {
            return device;
        }
    }
    return nullptr;
}

size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
    ALOG_ASSERT(bufferSize >= 1);

@@ -810,7 +818,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
        bool deviceChanged = false;
        while (mPendingEventIndex < mPendingEventCount) {
            const struct epoll_event& eventItem = mPendingEventItems[mPendingEventIndex++];
            if (eventItem.data.u32 == EPOLL_ID_INOTIFY) {
            if (eventItem.data.fd == mINotifyFd) {
                if (eventItem.events & EPOLLIN) {
                    mPendingINotify = true;
                } else {
@@ -819,7 +827,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
                continue;
            }

            if (eventItem.data.u32 == EPOLL_ID_WAKE) {
            if (eventItem.data.fd == mWakeReadPipeFd) {
                if (eventItem.events & EPOLLIN) {
                    ALOGV("awoken after wake()");
                    awoken = true;
@@ -835,14 +843,13 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
                continue;
            }

            ssize_t deviceIndex = mDevices.indexOfKey(eventItem.data.u32);
            if (deviceIndex < 0) {
                ALOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
                        eventItem.events, eventItem.data.u32);
            Device* device = getDeviceByFdLocked(eventItem.data.fd);
            if (device == nullptr) {
                ALOGW("Received unexpected epoll event 0x%08x for unknown device fd %d.",
                        eventItem.events, eventItem.data.fd);
                continue;
            }

            Device* device = mDevices.valueAt(deviceIndex);
            if (eventItem.events & EPOLLIN) {
                int32_t readSize = read(device->fd, readBuffer,
                        sizeof(struct input_event) * capacity);
@@ -1063,7 +1070,7 @@ status_t EventHub::registerDeviceForEpollLocked(Device* device) {
    if (mUsingEpollWakeup) {
        eventItem.events |= EPOLLWAKEUP;
    }
    eventItem.data.u32 = device->id;
    eventItem.data.fd = device->fd;
    if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, device->fd, &eventItem)) {
        ALOGE("Could not add device fd to epoll instance.  errno=%d", errno);
        return -errno;
+1 −4
Original line number Diff line number Diff line
@@ -401,6 +401,7 @@ private:
    Device* getDeviceByDescriptorLocked(const std::string& descriptor) const;
    Device* getDeviceLocked(int32_t deviceId) const;
    Device* getDeviceByPathLocked(const char* devicePath) const;
    Device* getDeviceByFdLocked(int fd) const;

    bool hasKeycodeLocked(Device* device, int keycode) const;

@@ -449,10 +450,6 @@ private:
    int mWakeReadPipeFd;
    int mWakeWritePipeFd;

    // Ids used for epoll notifications not associated with devices.
    static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
    static const uint32_t EPOLL_ID_WAKE = 0x80000002;

    // Epoll FD list size hint.
    static const int EPOLL_SIZE_HINT = 8;