zoukankan      html  css  js  c++  java
  • Linux/Android——input_handler之evdev (四) 【转】

    转自: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传递了.下篇介绍.

  • 相关阅读:
    Linux: 安装和启用firefox浏览器的java
    Latex: beamer
    时频分析:窗口傅立叶变换
    Python: 面向对象
    Linux: 安装NVIDIA显卡驱动
    Matlab: 路径的操作
    python--文件读写
    python--函数
    python--数据类型
    网络基础——网络协议
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/6896094.html
Copyright © 2011-2022 走看看