Explanation of directfb source code and process of peripheral Input

Source: Internet
Author: User

Next, let's take a look at how the input device event is transmitted from hardware to the DFB end user. The following code is a method for DFB users to handle peripheral events:

  

Directfbinit (& argc, & argv );

Directfbcreate (& DFB );

DFB-> enuminputdevices (DFB, enum_input_device, & devices );// Enumerate all peripherals that exist in the system and are supported by DFB.

                                                 // One call will call the callback function once.

                                                  // Records the details of each device in the callback function.

DFB-> createinputeventbuffer (DFB, dicaps_all, dfb_true, & events ));// Create an inputeventbuffer with the second parameter

                                                         // The number of events that the buffer cares about,

                                                          // DFB classifies all peripheral events into three types: key,

                                                         // Axis,
Button, you can specify

                                                         // Any combination of the three types
If (events-> waitforeventwithtimeout (events, 10, 0 )! = Dfb_timeout)
// Wait for the event to occur.

{

         While (1)

         {
              Dfbinputevent EVT;

              While (events-> getevent (events, dfb_event (& EVT) = dfb_ OK)// Obtain all events

              {
                // Dosomething .........                                   // Process the event

               }

              Events-> waitforevent (events );                             // Continue to wait for the event
         }
 }

 

It must be noted that the above is only one way to use the input event. You can also create an input device, use this device to create a general event buffer (instead of the input event buffer) of its own ).

 

Now let's follow the above Code to see what DFB has done internally?

(1) In the first two steps, directfbinit and directfbcreate initialize DFB. In this example, the input core part is initialized, the result is as described in the previous section "initialization of directfb source code interpretation-10". It should be added that when you call opendevice to open the device, you will get the device_info, which is filled in by each driver, one of which is desc. caps indicates the device type: key,
Button or axis. Of course, some devices can have both buttons and axes, such as the mouse.

 

(2) DFB-> enuminputdevices is also very simple. According to the previous section, all device and driver information is recorded in the linked list of the global variable core_local. Just traverse the linked list.

 

(3) DFB-> createinputeventbuffer, this step does two things,
First, create an eventbuffer object (just like calling DFB-> createeventbuffer), including the function interface for initializing it. The second is to bind the device.

 

   First, let's take a look at the content of the event buffer object: idirectfbeventbuffer's private data is idirectfbeventbuffer_data. There are two linked lists that we care about. One is that devices records all the devices associated with the eventbuffer, one is that events records all the events in this eventbuffer. 

    The association between devices and eventbuffer is to fill in the dotted line reaction in the figure "initialization of directfb source code interpretation-10". Each reaction contains two pointers: idirectfbeventbuffer_data and the processing function (Unified as idirectfbeventbuffer_inputreact ), the previous one indicates who cares about the device event, and the last one indicates how to handle the event. The link is completed in idirectfbeventbuffer_attachinputdevice. The calling process is as follows:

 

   In the previous section, we mentioned that DFB creates a thread for each valid input device. After obtaining the lower-level event, this thread performs a simple Event Match and calls dfb_input_dispatch to start distribution. It will call fusion_reactor_dispatch, And it will call the processing function (idirectfbeventbuffer_inputreact) of each reaction on the device, which will attach the event to the event
The waiting thread (if any) in the events linked list of the buffer ).

 

(4) events-> waitforeventwithtimeout. If data exists in the events linked list, it is returned directly; otherwise, pthread_cond_timedwait is called to block the current thread until an event or timeout occurs.

 

(5) events-> getevent is to get the event from the linked list.

 

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.