转自: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. 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. };

如果没有特定的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. if
    goto
  18. if
    goto
  19. if
    goto

    return;

  20. err_cleanup_evdev

    err_unregister_handle

    err_free_evdev

    return
    }

evdev:

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

[objc] view
plain
 copy

 
  1. struct

    int

  2. int
  3. struct
  4. struct__rcu
  5. struct
  6. 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. struct
    bool
    char8
    structfasync_struct
  5. structevdev
  6. struct
  7. int
    struct
  8. };

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

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

Linux/Android——input_handler之evdev (四) 【转】的更多相关文章

  1. Linux/Android——input系统之 kernel层 与 frameworks层交互 (五)【转】

    本文转载自:http://blog.csdn.net/jscese/article/details/42291149 之前的四篇博文记录的都是linux中的input体系相关的东西,最底层以我调试的u ...

  2. 热烈庆祝华清远见2014嵌入式系统(Linux&Android)开发就业培训课程全面升级

    近日,华清远见公开宣布:2014嵌入式系统 (Linux&Android)开发就业培训课程再次升级!据悉,华清远见如今已经持续10年,一直保持课程每年2次的更新的频率.华清远见的每 次课程更新 ...

  3. Android bluetooth介绍(四): a2dp connect流程分析

    关键词:蓝牙blueZ  A2DP.SINK.sink_connect.sink_disconnect.sink_suspend.sink_resume.sink_is_connected.sink_ ...

  4. Linux & Android 多点触摸协议

    Linux & Android 多点触摸协议 Android4.0多点触摸入门 1 KERNEL 对于触摸屏的驱动我们简单的划分为两个主要的部分,一个是注册,另一个是上报. 1.1 注册 单点 ...

  5. Linux/Android——Input系统之InputReader (七)【转】

    本文转载自:http://blog.csdn.net/jscese/article/details/42739197 在前文Linux/Android——Input系统之frameworks层Inpu ...

  6. Linux/Android——input子系统核心 (三)【转】

    本文转载自:http://blog.csdn.net/jscese/article/details/42123673 之前的博客有涉及到linux的input子系统,这里学习记录一下input模块. ...

  7. 阿里云服务器Linux CentOS安装配置(四)yum安装tomcat

    阿里云服务器Linux CentOS安装配置(四)yum安装tomcat 1.yum -y install tomcat  执行命令后,会帮你把jdk也安装好 2.tomcat安装目录:/var/li ...

  8. Android Animation学习(四) ApiDemos解析:多属性动画

    Android Animation学习(四) ApiDemos解析:多属性动画 如果想同时改变多个属性,根据前面所学的,比较显而易见的一种思路是构造多个对象Animator , ( Animator可 ...

  9. Android Studio系列教程四--Gradle基础

    Android Studio系列教程四--Gradle基础 2014 年 12 月 18 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://stormzhang ...

随机推荐

  1. easyPOI导出excel报错

    http-nio--exec- at :: - excel cell export error ,data is :com.jn.ssr.superrescue.web.qc.dto.Automati ...

  2. Evevt Loop、任务队列、定时器等

    上周五,一个朋友发给我一道面试题,代码如下: console.log(1); setTimeout(console.log(2), 0); Promise.resolve().then(res =&g ...

  3. java.lang.NoSuchMethodError: cn.makangning.test.dao.Users.getUserBirthday()Ljava/sql/Date;

    有时候出现这种怪异的问题,是由于多个版本的class存在. 比如说:某个java编译成class后,放到classes下面,然后lib目录下,也有这个class所在的jar包,这样就导致classpa ...

  4. springboot 入门2 开发环境与生产环境采用不同配置问题

    目开发中我们通常有两套配置信息  分别配置了我们的数据源信息等? 那么我们要如何不通过修改配置文件大量配置来实现简单的修改与配置来实现相关配置加载功能 首先springboot 有一个核心的配置文件a ...

  5. 《Cracking the Coding Interview》——第5章:位操作——题目2

    2014-03-19 05:47 题目:给定一个double型浮点数,输出其二进制表示,如果不能在32个字符内完成输出,则输出“ERROR”. 解法:如果你熟悉IEEE754标准,应该知道double ...

  6. USACO Section2.1 Hamming Codes 解题报告 【icedream61】

    hamming解题报告----------------------------------------------------------------------------------------- ...

  7. 如何自己编译apue.3e中代码 & 学习写makefile

    本来是搜pthread的相关资料,看blog发现很多linux程序员都看的一本神书<APUE>,里面有系统的两章内容专门讲pthread(不过是用c语言做的代码示例,这个不碍事,还是归到原 ...

  8. 孤荷凌寒自学python第八天 初识Python的序列之元组

    孤荷凌寒自学python第八天 Python的序列之元组 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) (同步音频笔记:https://www.ximalaya.com/keji/19103 ...

  9. 剑指offer-重建二叉树04

    题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...

  10. Linux学习15_CentOS6.5下netcat工具安装教程

    1.下载 下载地址:http://sourceforge.net/projects/netcat/files/netcat/0.7.1/ 下载的是netcat-0.7.1.tar.gz版本 2.拷贝 ...