ToolTalk ユーザーズガイド

メッセージの検索

メッセージがユーザーのプロセスに届くと、ToolTalk が提供したファイル記述子が使用可能になります。このファイル記述子が使用可能だと通知されると、プロセスは tt_message_receive を呼び出し、着信メッセージのハンドルを取得しなければなりません。

メッセージの受信方法を例 11-1 に示します。


例 11-1 メッセージの受信

/*
 * When a ToolTalk message is available, receive it; if it's a
 * ttsample1_value message, update the gauge with the new value.
 */
void
receive_tt_message()
{
	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;


メッセージのハンドルは不変です。たとえば、プロセスがメッセージを送信するとき、メッセージとそのメッセージに対する応答は、送信されたメッセージと同じハンドルを持ちます。例 11-2 に、TT_HANDLED のメッセージ状態を検査する方法の例を示します。


例 11-2 メッセージ状態のコード検査

Tt_message m, n;
m = tt_message_create();
...
tt_message_send(m);

... 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 */
)


メッセージの容易な識別方法と処理方法

ユーザーが受信したメッセージを容易に識別および処理するには、次のようにします。

応答の容易な認識方法と処理方法

ユーザーが送信したメッセージに対する応答を容易に認識および処理するには、次のようにします。