MessageQueue Example

This example application shows the use of message queue in interprocess communication using the RMsgQueue class.

Download

Click on the following link to download the example: MessageQueueExample.zip .

Click: browse to view the example code.

Description

The example describes the global message queue. The following sections provide more information.

MessageQueueExample

The example comprises two processes: a Collector, which collects words from the user via the console, and an Inverter, which periodically reverses the order of the collected words. The Collector and the Inverter pass words to each other using two message queues: InverterInQ and InverterOutQ. The Collector is the main process which starts the Inverter process. The Collector process takes user input in form of different words and sends to the Inverter process via message queue. The Inverter process receives messages at a regular interval of 10 seconds, inverts the words in the message and sends it back to the Collector.

The Collector creates an active object to collect words from the user and another active object to receive words from the Inverter. Each active object has its own console for display. More information about running the example is given in the build section of this document.

Design

The following block diagram describes the example in more detail.

CCollector.exe is the Collector process. The user starts the Collector and creates an active scheduler and two global message queues. It also starts the Inverter process called Inverter.exe . The Collector creates one active object to collect words from the user and another active object to monitor its input queue (InverterOutQ). The active object to collect words is an object of class CCollector and the active object which monitors InverterOutQ is an object of class CMsgQActive . The two active objects have different consoles (one for user input and one for displaying the output message).

The user inputs words in the console. The set of words goes to the InverterInQ when the " Enter " key is pressed. If the " ESC " key is pressed, the system stops and sends the command to the Inverter process to stop.

The Inverter is another process which opens the global message queues. It creates an active scheduler and implements a periodic timer. The timer wakes every 10 seconds to receive the words from the InverterInQ . It also checks for a stop command, which closes the message queue and the two process. The Inverter inverts the received words and sends the result to InverterOutQ .

In the Collector process, the active object that monitors the InveterOutQ opens the message queue, receives the received words and displays them in its console. It uses the NotifyDataAvailable(TRequestStatus&) API to monitor the queue for the next set of data.

The Class diagram of the example is shown below

Class summary

Build

The example builds an executable called Inverter.exe and Collector.exe in the standard locations.

To run the example, first build Inverter.exe and start Collector.exe from the file system or from your IDE. After launching the .exes (and depending on the emulator you are using) you may need to navigate away from the application launcher or shell screen to view the console.

A message input console is used for user input and an output message console is used to display inverted words. The output message console that is displayed at startup. The user can switch between two consoles by Ctrl+Shift+Alt+t combination.

The input message console is used to input words. A user presses enter to send the words to the Inverter and presses ESC to exit the application. When a user presses "Enter" the words go to the InverterInQ . The Inverter opens the InverterInQ at periodic intervals of 10 secs and inverts the words which it sends to the collector via InverterOutQ . The Collector opens the InverterOutQ and display the words in the output message console.