Chatting with input devices in Linux (6) at first sight is destined to be held in hand for a lifetime

Source: Internet
Author: User

Some of our friends are getting angry. How can we get rid of our beautiful input device? It's just a flash and I will not describe her specific wedding process in detail, which handler did she marry? What is in phase? What have they done together? Well, to satisfy this brother's desire, let's take a look at the previous input_attach_handler (Dev, Handler) function in detail. It is in this function that all this happens.

Static int input_attach_handler (struct input_dev * Dev, struct input_handler * Handler)

{

1 const struct input_device_id * ID;

2 int error;

 

3 if (Handler-> blacklist & input_match_device (Handler-> blacklist, Dev ))

4 return-enodev;

 

5 Id = input_match_device (Handler-> id_table, Dev );

6 if (! ID)

7 Return-enodev;

 

8 Error = Handler-> connect (handler, Dev, ID );

9 If (error & error! =-Enodev)

10 printk (kern_err

11 "input: failed to attach handler % s to device % s ,"

12 "error: % d/N ",

13 Handler-> name, kobject_name (& Dev-> Dev. kobj), error );

 

14 return error;

}

One line defines the variable ID of a struct input_device_id. This struct belongs to handler and provides a set of mate selection criteria for our handler. No matter where you are, you will be rejected.

Line 2 defines an integer error, which will be used later.

In the three rows, Our handler should be not small, not a rich generation, or at least a rich generation. There are not only a bunch of matching standards, but also a blacklist list. For those devices that are in the blacklist, for example, it is difficult to find a girl, a phone call, and the sound of Fengjie suddenly emerges. Don't say handler, I guess I can't accept it, so I just shot it. If you are not Feng Jie, it proves that you are not in the blacklist, even if you are only 1 meter tall, even if you have a mouth, even if you have a tooth, let's give me a face to have a chat first, and then find a reason to say that you do not meet my mate selection criteria.

Four rows. Okay, our input device girl starts to meet handler for the first time, and then matches the information of both parties. You will find in input_match_device, the final initiative lies in our handler brother.

Static const struct input_device_id * input_match_device (const struct input_device_id * ID,

Struct input_dev * Dev)

{

Int I;

 

For (; id-> flags | ID-> driver_info; Id ++ ){

 

If (ID-> flags & input_device_id_match_bus)

If (ID-> bustype! = Dev-> ID. bustype)

Continue;

 

If (ID-> flags & input_device_id_match_vendor)

If (ID-> vendor! = Dev-> ID. Vendor)

Continue;

 

If (ID-> flags & input_device_id_match_product)

If (ID-> product! = Dev-> ID. Product)

Continue;

 

If (ID-> flags & input_device_id_match_version)

If (ID-> version! = Dev-> ID. Version)

Continue;

 

Match_bit (evbit, ev_max );

Match_bit (keybit, key_max );

Match_bit (relbit, rel_max );

Match_bit (absbit, abs_max );

Match_bit (mscbit, msc_max );

Match_bit (ledbit, led_max );

Match_bit (sndbit, snd_max );

Match_bit (ffbit, ff_max );

Match_bit (swbit, sw_max );

 

Return ID;

}

 

Return NULL;

}

No, as long as our handler has a flag set, the corresponding conditions of your input device must be met. Otherwise, we will be done. In-depth match_bit macro:

# Define match_bit (bit, max )/

For (I = 0; I <bits_to_longs (max); I ++ )/

If (ID-> bit [I] & Dev-> bit [I])! = ID-> bit [I])/

Break ;/

If (I! = Bits_to_longs (max ))/

Continue;

Still, as long as one of the evbit, keybit, and so on in our handler's ID is set, the input device Meimei must also meet this condition (remember to use set_bit (ev_abs, AKM-> input_dev-> evbit) in section 2 ); create a condition for the input device). Otherwise, the device will still be shot. As a result, I began to suspect that the boys who write Linux code are more pure than those of Chun Ge, and all the women who want to meet him must obey these harsh conditions, even if one of them does not match, you don't want to be nice with him. However, people do have that capital. It is generally not simple to be able to ride in the Linux Kernel world. It is estimated that there are not many people in China. Fortunately, our input device Meimei can traverse all handler brothers on input_handler_list, so we don't believe that there is no condition that requires a low point. So where are handler with very low requirements? Ah! This girl is lucky. There is exactly one here.

Let's take a look at this elder brother's mate selection criteria:

 

Static const struct input_device_id evdev_ids [] = {

{. Driver_info = 1},/* matches all devices */

{},/* Terminating zero entry */

};

It is just a condition, and it can be said that it is not a condition. Why do we say this? Please go back to our input_match_device function and see it? Some of my friends may be surprised to scream, my mom! He does not need to set flag, but evbit and keybit. So... So... This buddy is actually the most blessed, that is, all the input devices that cannot find a boyfriend will be nice to him. (Of course, Feng Jie doesn't know him because he is not a master of economics from Peking University and Tsinghua University, he is not as tall as Jin Cheng Wu Shuai, and he is not 1 meter 8 ......) Therefore, the legendary polygamous architecture emerged.

Here, the input device is too good because some conditions are not enough. (here, we declare that not our input device has poor conditions, but the other handler is too targeted. For example, as long as there is a beauty in the bottom of his mouth, he laughs like Zhang manyu and has to have a body like Zhang Xinyu, or around the age of 20, cancer, never talked about love, but also has a face of Cecilia Cheung) So it is also combined with our evdev_handler. Brother evdev_handler sneaked into a smile and scolded other buddies for being silly.

Rows 6 and 7 are returned if no value is found.

Line 8: now that we have found the connection, we will immediately call the connect function in our evdev handler for marriage. What happened in this function? Let's leave it to the next section.

Rows 9-13. If the match fails, the result is printed.

Line 14: Go home.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.