Linux/Android——input_handler之evdev (四) 【转】

简介: 转自:http://blog.csdn.net/u013491946/article/details/72638919 版权声明:免责声明: 本人在此发文(包括但不限于汉字、拼音、拉丁字母)均为随意敲击键盘所出,用于检验本人电脑键盘录入、屏幕显示的机械、光电性能,并不代表本人局部或全部同意、支持或者反对观点。

转自:http://blog.csdn.net/u013491946/article/details/72638919

目录(?)[+]

    在前文Linux/Android——input子系统核心 (三) 中概括了总体的结构,以及介绍了input核心的职责,其中有说道注册input设备时会去匹配已有的事件处理器handler,

而这个handler也是存放在一个链表里面的,这里介绍下input子系统中的事件处理input_handler机制.


                                              撰写不易,转载需注明出处:http://blog.csdn.net/jscese/article/details/42238377#t6


evdev:

  /kernel/drivers/input下众多事件处理器handler其中的一个,可以看下源码/kernel/drivers/input/evdev.c中的模块init:

 

[objc]  view plain  copy
 
 
  1. staticintvoid return }  


这个初始化就是往input核心中注册一个input_handler类型的evdev_handler,调用的是input.c提供的接口,input_handler结构前文有介绍,看下evdev_handler的赋值:

 

 

[objc]  view plain  copy
 
 
  1. staticstruct       = evdev_event,  
  2.     = evdev_connect,  
  3.  = evdev_disconnect,  
  4.        = &evdev_fops,  
  5.       = EVDEV_MINOR_BASE,  
  6.        = ,  
  7.    = evdev_ids,  
  8. };  


赋值各个函数指针!

 



input_register_handler:

 可以看到上面的evdev handler 就是调用这个接口注册到input核心中的,同样evdev.c同目录下也还有其它的handler,有兴趣可以看看它们的init函数,都是会调用到这个接口去注册的.

 

[objc]  view plain  copy
 
 
  1. /** 
  2.  * input_register_handler - register a new input handler 
  3.  * @handler: handler to be registered 
  4.  * 
  5.  * This function registers a new input handler (interface) for input 
  6.  * devices in the system and attaches it to all input devices that 
  7.  * are compatible with the handler. 
  8.  */ intstructinput_handler structinput_dev int if return ifNULL if]) {  
  9. goto ] = handler;   
  10.   
  11.   
  12.  out return }  


 

input核心中保存的handler数组:

 

[objc]  view plain  copy
 
 
  1. staticstructinput_handler];  


这是保存注册到input核心中的handler数组,因为在之前input注册的时候注册的字符设备主设备号为13.字符设备的次设备号为0~255,可以有256个设备,

这里后面会看到一个handler可以connect处理32个input设备,所以input体系中,最多拥有8个handler


这个匹配过程和上一篇中的过程是一样的,最后匹配上的话会调用匹配上的handler 中connect指针指向的函数.


另外可以注意的是evdev是匹配所有设备的,因为:

 

[objc]  view plain  copy
 
 
  1. staticconststruct  =  },     
  2.   
  3. };  


如果没有特定的handler添加进handler链表,那么在匹配的时候,只要有这个evdev的handler,最后都会匹配到evdev,这个具体可以去看看上篇的匹配过程.

 

我这边调试的是usb触摸屏,所以用的是evdev的handler,下面看下evdev的connect.


evdev_connect:

 注册的evdev_handler中connect指向的函数为evdev_connect:

[objc]  view plain  copy
 
 
  1. /* 
  2.  * Create new evdev device. Note that input core serializes calls 
  3.  * to connect and disconnect so we don't need to lock evdev_table here. 
  4.  */ staticintstructinput_handlerstructinput_dev conststructinput_device_idid structevdev int int for; minor < EVDEV_MINORS; minor++)  
  5. if break if return // 可以看到这里evdev handler匹配连接好的设备都以evdev 类型存在这个evdev_table数组的,这个数组大小为32个,这就是我上面说到的,为什么只有8个handler //这里是判断evdev的32个位置中是否有空 sizeofstruct  
  6. if return   
  7. , minor);    
  8. true   
  9.  = input_get_device(dev);    
  10.  = dev_name(&evdev->dev);  
  11.  = handler;  
  12.  = evdev;  
  13.  = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor);  
  14.  = &input_class;  
  15.  = &dev->dev;  
  16.  = evdev_free;  
  17.   
  18. if goto   
  19. if goto   
  20. if goto return;  
  21.  err_cleanup_evdev  err_unregister_handle  err_free_evdev return }  



evdev:

这里的evdev变量的结构如下:

 

[objc]  view plain  copy
 
 
  1. struct int  
  2. int  
  3. struct  
  4.   
  5. struct__rcu  
  6. struct  
  7.   
  8. struct struct bool };  



关于这个结构变量我的理解是抽象出来一个设备,代表一个input_dev与其匹配好的handler的组合(handle),可以看作提供给事件处理层的一个封装.

 


input_handle:

这个代表一个匹配成功的input dev和 handler组合,定义在input.h中,每个evdev中包含一个input_handle,并且注册到input核心中:

 

[objc]  view plain  copy
 
 
  1. /** 
  2.  * struct input_handle - links input device with an input handler 
  3.  * @private: handler-specific data 
  4.  * @open: counter showing whether the handle is 'open', i.e. should deliver 
  5.  *    events from its device 
  6.  * @name: name given to the handle by handler that created it 
  7.  * @dev: input device the handle is attached to 
  8.  * @handler: handler that works with the device through this handle 
  9.  * @d_node: used to put the handle on device's list of attached handles 
  10.  * @h_node: used to put the handle on handler's list of handles from which 
  11.  *    it gets events 
  12.  */ struct voidvoidprivate  
  13. int constcharchar structinput_dev  
  14. structinput_handler  
  15. struct  
  16. struct };  

 

input_register_handle:

 看看这个handle的注册,不要和handler搞混淆了,这不是一个概念~

[objc]  view plain  copy
 
 
  1. /** 
  2.  * input_register_handle - register a new input handle 
  3.  * @handle: handle to register 
  4.  * 
  5.  * This function puts a new input handle onto device's 
  6.  * and handler's lists so that events can flow through 
  7.  * it once it is opened using input_open_device(). 
  8.  * 
  9.  * This function is supposed to be called from handler's 
  10.  * connect() method. 
  11.  */ intstructinput_handle structinput_handler structinput_dev  
  12.      * Filters go to the head of the list, normal handlers 
  13.      * to the tail. 
  14.      */ if else //把这个handle的d_node 加到对应input_dev的h_list链表里面 //把这个handle的h_node 加到对应input_handler的h_list链表里面 }  


这个注册是把handle 本身的链表加入到它自己的input_dev 以及 input_handler的h_list链表中,这样以后就可以通过h_list遍历到这个handle,

这样就实现了三者的绑定联系.



另外在evdev中还有个结构:


[objc]  view plain  copy
 
 
  1. struct int  
  2. int  
  3. int  
  4.   
  5. struct bool char8 structfasync_struct  
  6. structevdev  
  7. struct  
  8. int struct  
  9. };  


 

这个结构会在evdev被打开的时候 创建,这里关于evdev的初始以及在input系统中承接作用暂时介绍到这里,

前文 Linux/Android——输入子系统input_event传递 (二) 中有记录从设备驱动传递上来的event是怎么到input核心,然后接着往上传递的,接下来就是用到evdev传递了.下篇介绍.

【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
6天前
|
设计模式 算法 前端开发
Android面经分享,失业两个月,五一节前拿到Offer,设计思想与代码质量优化+程序性能优化+开发效率优化
Android面经分享,失业两个月,五一节前拿到Offer,设计思想与代码质量优化+程序性能优化+开发效率优化
|
4天前
|
编解码 数据库 Android开发
安卓应用开发:打造高效用户界面的五大技巧
【5月更文挑战第18天】在竞争激烈的应用市场中,一个流畅且直观的用户界面(UI)对于安卓应用的成功至关重要。本文将探讨五种提升安卓应用用户界面性能的技巧,包括合理布局设计、优化资源使用、利用硬件加速、内存管理以及响应式编程。通过这些方法,开发者可以创建出既美观又高效的应用体验,从而吸引和保留用户。
|
6天前
|
XML Android开发 数据格式
ConstraintLayout 2,Android高级开发面试
ConstraintLayout 2,Android高级开发面试
|
3天前
|
搜索推荐 API Android开发
安卓应用开发:打造高效通知管理系统
【5月更文挑战第20天】在移动设备中,通知管理是用户体验的关键部分。一个高效的通知系统不仅能够及时传达重要信息,还能避免用户感到不必要的干扰。本文将深入探讨如何在安卓平台上开发一个高效的通知管理系统,包括通知的设计、发送策略以及用户的个性化设置。通过分析安卓系统的通知机制和最新的API特性,我们将提供一个实用的开发指南,帮助开发者创建更加智能和用户友好的通知体验。
|
6天前
|
JSON Android开发 数据格式
Android框架-Google官方Gson解析,android开发实验报告总结
Android框架-Google官方Gson解析,android开发实验报告总结
|
6天前
|
前端开发 Android开发
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
Android架构组件JetPack之DataBinding玩转MVVM开发实战(四)
|
6天前
|
安全 Linux Android开发
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
|
6天前
|
算法 前端开发 Android开发
Android文字基线Baseline算法的使用讲解,Android开发面试题
Android文字基线Baseline算法的使用讲解,Android开发面试题
Android文字基线Baseline算法的使用讲解,Android开发面试题
|
6天前
|
缓存 Android开发
Android插件化——高手必备的Hook技术,零基础开发android
Android插件化——高手必备的Hook技术,零基础开发android
|
6天前
|
Android开发
Android高级开发面试题以及笞案整理,实战解析
Android高级开发面试题以及笞案整理,实战解析