Message Queue Processing Mechanism in Logoff

Source: Internet
Author: User

Message Queue Processing Mechanism in Logoff

Logoff also provides the definition of the message, the sending of the message, the customization of the message processor, and the message queue. In the header file login.h, the message struct message is defined. It has only one type member and the message is defined as follows (see the login.h file, the same below ):

Messagehandler can process the message:

You can extend the message by deriving a subclass. To process a message, you must overload the handlemessage function in the subclass of messagehandler.

They will be encapsulated in the message "envelope" messageenvolope and then sent to the message queue. Messageenvolope is defined as follows:

Logoff maintains a message queue:

You can use sendmessageattime of logoff (the other two versions also use sendmessageattime) to send messages to the Message Queue:

The message sending function packs the parameters into the message envelope and places them in the message queue. Finally, if there is no message in the Message Queue (that is, waiting for sleep on the receiver), let the wake function write characters to the pipeline write end to wake up the sleeping wait on the receiver epoll_wait in the pollinner, start receiving and processing the message. The pollinner code snippet for Message Queue processing is as follows:

After waking up, if the message queue is not empty in row 275 above, check whether the first item in the queue has timed out. If it times out, remove it and call the handlemessage function of messagehandler specified in the message envelope to process the message (line 294 ).

Therefore, with the help of the sendmessagexxx function and pollonce function of logoff, you can send messages to the message queue in logoff. Then, the caller of pollonce will be awakened to process the messages, when the message is processed and there is no message, the system will wait.

This article is excerpted from the book "in-depth analysis of Android system ".

Yang Changgang

Published by Electronic Industry Publishing House

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.