ToolTalk User's Guide

Retrieving Messages

When a message arrives for your process, the ToolTalk-supplied file descriptor becomes active. When notified of the active state of the file descriptor, your process must call tt_message_receive to get a handle for the incoming message.

Example 11–1 illustrates how to receive a message.

Example 11–1 Receiving a Message

 * When a ToolTalk message is available, receive it; if it's a
 * ttsample1_value message, update the gauge with the new value.
	Tt_message msg_in;
	int mark;
	int val_in;

	msg_in = tt_message_receive();

	 * It's possible that the file descriptor would become active
	 * even though ToolTalk doesn't really have a message for us.
	 * The returned message handle is NULL in this case.

	if (msg_in == NULL) return;

Handles for messages remain constant. For example, when a process sends a message, both the message and any replies to the message have the same handle as the sent message. Example 11–2 is an example of how you can check the message state for TT_HANDLED.

Example 11–2 Code Checking the Message State

Tt_message m, n;
m = tt_message_create();

... wait around for tt_fd to become active

n = tt_message_receive();
if (m == n) {
	/* This is the reply to the message we sent */
	if (TT_HANDLED == tt_message_state(m) ) {
			/* The receiver has handled the message so we can go
on */
} else {
	/* This is a new message coming in */

Identifying and Processing Messages Easily

To easily identify and process messages received by you:

Recognizing and Handling Replies Easily

To easily recognize and handle replies to messages sent by you: