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:
- staticintvoid
return
}
这个初始化就是往input核心中注册一个input_handler类型的evdev_handler,调用的是input.c提供的接口,input_handler结构前文有介绍,看下evdev_handler的赋值:
- staticstruct
= evdev_event, - = evdev_connect,
- = evdev_disconnect,
- = &evdev_fops,
- = EVDEV_MINOR_BASE,
- = ,
- = evdev_ids,
- };
赋值各个函数指针!
input_register_handler:
可以看到上面的evdev handler 就是调用这个接口注册到input核心中的,同样evdev.c同目录下也还有其它的handler,有兴趣可以看看它们的init函数,都是会调用到这个接口去注册的.
- /**
- * input_register_handler - register a new input handler
- * @handler: handler to be registered
- *
- * This function registers a new input handler (interface) for input
- * devices in the system and attaches it to all input devices that
- * are compatible with the handler.
- */
intstructinput_handlerstructinput_dev
intif
returnifNULL
if]) { - goto
] = handler;
- out
return
}
input核心中保存的handler数组:
- staticstructinput_handler];
这是保存注册到input核心中的handler数组,因为在之前input注册的时候注册的字符设备主设备号为13.字符设备的次设备号为0~255,可以有256个设备,
这里后面会看到一个handler可以connect处理32个input设备,所以input体系中,最多拥有8个handler
这个匹配过程和上一篇中的过程是一样的,最后匹配上的话会调用匹配上的handler 中connect指针指向的函数.
另外可以注意的是evdev是匹配所有设备的,因为:
- staticconststruct
= }, - };
如果没有特定的handler添加进handler链表,那么在匹配的时候,只要有这个evdev的handler,最后都会匹配到evdev,这个具体可以去看看上篇的匹配过程.
我这边调试的是usb触摸屏,所以用的是evdev的handler,下面看下evdev的connect.
evdev_connect:
注册的evdev_handler中connect指向的函数为evdev_connect:
- /*
- * Create new evdev device. Note that input core serializes calls
- * to connect and disconnect so we don't need to lock evdev_table here.
- */
staticintstructinput_handlerstructinput_dev
conststructinput_device_ididstructevdev
int
intfor; minor < EVDEV_MINORS; minor++)
- if
breakif
return
// 可以看到这里evdev handler匹配连接好的设备都以evdev 类型存在这个evdev_table数组的,这个数组大小为32个,这就是我上面说到的,为什么只有8个handler
//这里是判断evdev的32个位置中是否有空
sizeofstruct
- if
return - , minor);
- true
- = input_get_device(dev);
- = dev_name(&evdev->dev);
- = handler;
- = evdev;
- = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor);
- = &input_class;
- = &dev->dev;
- = evdev_free;
- if
goto - if
goto - if
gotoreturn;
- err_cleanup_evdev
err_unregister_handle
err_free_evdev
return
}
evdev:
这里的evdev变量的结构如下:
- struct
int
- int
- struct
- struct__rcu
- struct
- struct
struct
bool
};
关于这个结构变量我的理解是抽象出来一个设备,代表一个input_dev与其匹配好的handler的组合(handle),可以看作提供给事件处理层的一个封装.
input_handle:
这个代表一个匹配成功的input dev和 handler组合,定义在input.h中,每个evdev中包含一个input_handle,并且注册到input核心中:
- /**
- * struct input_handle - links input device with an input handler
- * @private: handler-specific data
- * @open: counter showing whether the handle is 'open', i.e. should deliver
- * events from its device
- * @name: name given to the handle by handler that created it
- * @dev: input device the handle is attached to
- * @handler: handler that works with the device through this handle
- * @d_node: used to put the handle on device's list of attached handles
- * @h_node: used to put the handle on handler's list of handles from which
- * it gets events
- */
structvoidvoidprivate
- int
constcharcharstructinput_dev
- structinput_handler
- struct
- struct
};
input_register_handle:
看看这个handle的注册,不要和handler搞混淆了,这不是一个概念~
- /**
- * input_register_handle - register a new input handle
- * @handle: handle to register
- *
- * This function puts a new input handle onto device's
- * and handler's lists so that events can flow through
- * it once it is opened using input_open_device().
- *
- * This function is supposed to be called from handler's
- * connect() method.
- */
intstructinput_handlestructinput_handler
structinput_dev - * Filters go to the head of the list, normal handlers
- * to the tail.
- */
ifelse
//把这个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中还有个结构:
- struct
int - int
- int
- struct
bool
char8
structfasync_struct - structevdev
- struct
- int
struct - };
这个结构会在evdev被打开的时候 创建,这里关于evdev的初始以及在input系统中承接作用暂时介绍到这里,
前文Linux/Android——输入子系统input_event传递
(二) 中有记录从设备驱动传递上来的event是怎么到input核心,然后接着往上传递的,接下来就是用到evdev传递了.下篇介绍.
Linux/Android——input_handler之evdev (四) 【转】的更多相关文章
- Linux/Android——input系统之 kernel层 与 frameworks层交互 (五)【转】
本文转载自:http://blog.csdn.net/jscese/article/details/42291149 之前的四篇博文记录的都是linux中的input体系相关的东西,最底层以我调试的u ...
- 热烈庆祝华清远见2014嵌入式系统(Linux&Android)开发就业培训课程全面升级
近日,华清远见公开宣布:2014嵌入式系统 (Linux&Android)开发就业培训课程再次升级!据悉,华清远见如今已经持续10年,一直保持课程每年2次的更新的频率.华清远见的每 次课程更新 ...
- Android bluetooth介绍(四): a2dp connect流程分析
关键词:蓝牙blueZ A2DP.SINK.sink_connect.sink_disconnect.sink_suspend.sink_resume.sink_is_connected.sink_ ...
- Linux & Android 多点触摸协议
Linux & Android 多点触摸协议 Android4.0多点触摸入门 1 KERNEL 对于触摸屏的驱动我们简单的划分为两个主要的部分,一个是注册,另一个是上报. 1.1 注册 单点 ...
- Linux/Android——Input系统之InputReader (七)【转】
本文转载自:http://blog.csdn.net/jscese/article/details/42739197 在前文Linux/Android——Input系统之frameworks层Inpu ...
- Linux/Android——input子系统核心 (三)【转】
本文转载自:http://blog.csdn.net/jscese/article/details/42123673 之前的博客有涉及到linux的input子系统,这里学习记录一下input模块. ...
- 阿里云服务器Linux CentOS安装配置(四)yum安装tomcat
阿里云服务器Linux CentOS安装配置(四)yum安装tomcat 1.yum -y install tomcat 执行命令后,会帮你把jdk也安装好 2.tomcat安装目录:/var/li ...
- Android Animation学习(四) ApiDemos解析:多属性动画
Android Animation学习(四) ApiDemos解析:多属性动画 如果想同时改变多个属性,根据前面所学的,比较显而易见的一种思路是构造多个对象Animator , ( Animator可 ...
- Android Studio系列教程四--Gradle基础
Android Studio系列教程四--Gradle基础 2014 年 12 月 18 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://stormzhang ...
随机推荐
- 2015 acm taipei L-Reward the Troop(uvalive 7465)(找规律)
原题链接 就大概说的是一个将军要给部下发勋章,他的部下以和别人不一样的勋章为荣,但是他没这么多钱,所以问你最少要多少钱 要求是每个人的上司是他的上两级,他的下两级是他的部下,每个人的勋章不能和他的上司 ...
- Docker构建nginx+uwsgi+flask镜像(一)
前言 笔者之前是从事Java方面的工作,自从18年5月左右来到新的公司,接触到Python,被其简单优雅的语法风格深深吸引,同时,新公司也帮助笔者打开Docker世界的大门,让笔者体会到“一次打包,到 ...
- css3 3D
开通黄钻 Css3 -3D效果<!DOCTYPE html><html lang="en"><head> <meta charset=&q ...
- 独立开发unity2d游戏的问答群
129443731 有志独立开发游戏的,只讨论最新的unity2d技术的.群里面主要已问答为主,喜欢聊天的就别加群了,灌水多了会被t.希望能对unity2d比较了解的已及喜欢学习的人加入.
- Lua语言中文手册 转载自网络
Programming in LuaCopyright ® 2005, Translation Team, www.luachina.net Programming in LuaProgramming ...
- ffifdyop
题目地址:http://www.shiyanbar.com/ctf/2036 后台登陆 上来看到这个界面,果断先看一波源代码. 看到是拼接字符串进行sql查询,就想到了注入了. 但是很不幸的是md5( ...
- HTML5 FileReader接口学习笔记
1.FileReader概述 FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据. 其中F ...
- unity值得推荐的网址
免费字体下载网站:http://www.dafont.com/ 免费声音文件下载网站:http://freesound.org/ http://incompetech.com/mus ...
- Ubuntu16.04 问题汇总
Ubuntu16.04安装wps并解决系统缺失字体问题 http://www.cnblogs.com/liutongqing/p/6388160.html
- ctags+cscope替换sourceinsight
背景 windows环境开发+linux交叉编译的开发模式,代码阅读和编写都用的source-insight. 除了检索,跳转,工程构建等方面,sourceinsight自带了一些宏语言,可以轻松实现 ...