You can tell the ToolTalk service to invoke a callback when a message arrives because a pattern has been matched.
p = tt_pattern_create(); tt_pattern_op_add(p, "EDIT"); ... other pattern attributes tt_pattern_callback_add(p, do_edit_message); tt_pattern_register(p); |
Callbacks are called in reverse order of registration (for example, the most recently added callback is called first).
Figure 11-1 illustrates how the ToolTalk service invokes message and pattern callbacks when tt_message_receive is called to retrieve a new message.
After the ToolTalk service determines the receiver for a message addressed to a handler, it matches the message against any patterns registered by the receiver. (Messages explicitly addressed to handlers are point-to-point messages and do not use pattern matching.)
If the message does not match a pattern, the message is delivered in the normal manner.
If the message is matched to a pattern, any callbacks attached to the pattern are run.
Numeric tags (opnums) can be attached to each signature in a ptype when a static pattern is created. A callback can now be attached to the opnum. When a message is delivered because it matched a static pattern with an opnum, the ToolTalk service checks for any callbacks attached to the opnum and, if any exists, runs them.