Android应用程序的消息处理机制学习心得(一)

浏览:
字体:
发布时间:2013-12-11 11:03:12
来源:

InputManager类处理过程:

InputManager 先创建InputDispatcher 和InputReader对象,并把InputReader和InputDispatcher对象为参数再创建两个线程对象,InputReaderThread 以及InputDispatcherThread。InputManager::start()启动两个线程。

InputReader类处理过程:

InputReader::loopOnce()--->EventHub::getEvents()--->InputReader::processEventsLocked()---

--->InputReader::processEventsForDeviceLocked()--->InputDevice::process()--->TouchInputMapper::process()--

--->TouchInputMapper::sync()--->TouchInputMapper::dispatchTouches()

EventHub类处理过程:

getEvents()函数负责处理事件,可以处理不止一个事件,这个之前版本源码不同,scanDirLock()负责扫描设备,openDeviceLock()负责生成设备相关信息,新版函数都在后面加了Lock。


读过一些源码之后,我思考了两个问题

1.有些文章说InputReaderThread 和InputDispatcherThread都会在没有事件时进入睡眠状态。研读源码发现InputDispatcher::dispatchOnce()以及mLooper->pollOnce()确实在没有事件需要处理时进行睡眠,但研读InputRedaer源码时,没有了解其如何睡眠。

2.InputReader是如何和InputDispatcher交互的?因为老版本源码,InputReader有getDispatcher()函数,但新版本替换为getListener()。


继续研读代码发现答案:

1.InputReaderThread::loopOnce会休眠到EventHub::getEvents()中的epoll_wait(),epoll_wait()是系统调用,负责轮询IO的。

2.getListener()是一个队列 ,队列里面是一个Inputdispatcher对象。

明天继续研读,写写笔记免得自己忘掉。

>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();