InputDispatcher和InputReader的创定都相对简单。InputDispatcher会创建本身线程的Looper,以及设置根据传入的dispatchPolicy设置分发规矩。InputReader则会将传入的InputDispatcher封装为监听对象存起来,做一些数据初始化就停止了。
那么这里抛出一个问题:为什么要把管道的读端住册到epoll中?假如EventHub因为getEvents读不到事宜而壅塞在epoll_wait()里,而我们没有绑决定肯定端的话,我们要怎么唤醒EventHub?如不雅绑定了管道的读端,我们就可以经由过程向管道的写端写数据大年夜而让EventHub因为获得管道写端的数据而被唤醒。
InputManager的创建
接下来持续说InputManager的创建,它的创建就简零丁了,创建一个InputDispatcher对象用于分发事宜,一个InputReader对象用于读事宜并把事宜交给InputDispatcher分发,,然后调用initialize()初始化,其实也就是创建了InputReaderThread和InputDispatcherThread。
- EventHub.cpp
- EventHub::EventHub(void) :
- mBuiltInKeyboardId(NO_BUILT_IN_KEYBOARD), mNextDeviceId(1), mControllerNumbers(),
- mOpeningDevices(0), mClosingDevices(0),
- mNeedToSendFinishedDeviceScan(false),
- mNeedToReopenDevices(false), mNeedToScanDevices(true),
- mPendingEventCount(0), mPendingEventIndex(0), mPendingINotify(false) {
- acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
- mEpollFd = epoll_create(EPOLL_SIZE_HINT);
- LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance. errno=%d", errno);
- mINotifyFd = inotify_init();
- int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
- ……
- result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
- ……
- int wakeFds[2];
- result = pipe(wakeFds);
- ……
- mWakeReadPipeFd = wakeFds[0];
推荐阅读
51CTO诚邀您9月23号和秒拍/国美/美团元专家一路聊智能CDN的优化之路,抓紧时光哦! 以前几个月,安然界见证了多起重大年夜云数据泄漏事宜。6月份1.97亿美国选平易近的泄漏事宜,震动全球。>>>详细阅读
本文标题:Android Input子系统:Input进程的创建,监听线程的启动
地址:http://www.17bianji.com/lsqh/37309.html
1/2 1