eventhub

http://blog.csdn.net/myarrow/article/details/7091061

frameworks/base/services/input/EventHub.cpp

4.1)创建InputReader对象

4.1.1)把EventHub、readerPolicy<实质为NativeInputManager对象>和创建的InputDispatcher对象作为参数创建InputReader对象:mReader = new InputReader(eventHub, readerPolicy, mDispatcher);

4.1.2)在创建InputReader时, 保存EventHub对象到mEventHub中,并创建QueuedInputListener对象并保存在mQueuedListener中

4.2)创建InputDispatcher对象

4.2.1)把传入的参数dispatcherPolicy<实质为NativeInputManager对象>作为参数创建InputDispatcher对象:mDispatcher = new InputDispatcher(dispatcherPolicy);

4.2.1)在创建InputDispatcher时,创建了一个looper对象:mLooper = new Looper(false);

如何获取输入子系统事件:

EventHub::EventHub(void) 

mEpollFd = epoll_create(EPOLL_SIZE_HINT);创建epoll集合

EventHub::EventHub(void) 

epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);监测/dev/input目录文件下的删除与创建;

epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);监控读写管道中的读管道;

status_t openDeviceLocked(const char *devicePath) 

epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem);监控输入子系统

void EventHub::closeDeviceLocked(Device* device) 

epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)删除监控文件 

size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) 

int pollResult = epoll_wait(mEpollFd, mPendingEventItems, EPOLL_MAX_EVENTS, timeoutMillis); 阻塞等待输入事件


EventHub->getEvents

InputReader::processEventsLocked分类处理输入子系统事件和新增、删除设备事件

processEventsForDeviceLocked 处理输入子系统事件

device->process(rawEvents, count);相应的设备处理输入子系统事件

mapper->process(rawEvent);

addDeviceLocked(rawEvent->when, rawEvent->deviceId);增加设备

InputDevice* device = createDeviceLocked(deviceId, identifier, classes);创建Mapper


InputListenerInterface* InputReader::ContextImpl::getListener() {
    return mReader->mQueuedListener.get();
}

status_t EventHub::openDeviceLocked(const char *devicePath)

InputDeviceIdentifier identifier;记录打开设备信息

mExcludedDevices记录打开的设备

Device* device = new Device(fd, deviceId, String8(devicePath), identifier);创建新设备

查看设备类型;

epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem);加入轮询设备集

addDeviceLocked(device);增加设备到设备链表

size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize)获取所有Event

eventItem.events & EPOLLIN

1.关闭设备Event

2.打开设备Event

status_t EventHub::readNotifyLocked() 

openDeviceLocked(devname);

closeDeviceByPathLocked(devname);

你可能感兴趣的:(eventhub)