When a request contains a message callback routine, the callback routine is automatically called when the reply is received to examine the results of the reply and take appropriate actions.
Callbacks are called in reverse order of registration (for example, the most recently added callback is called first).
You use tt_message_callback_add to add the callback routine to your request. When the reply comes back and the reply message has been processed through the callback routine, the reply message must be destroyed before the callback function returns TT_CALLBACK_PROCESSED
. To destroy the reply message, use tt_message_destroy, as illustrated in Example 8-4.
Tt_callback_action sample_msg_callback(Tt_message m, Tt_pattern p) { ... process the reply msg ... tt_message_destroy(m); return TT_CALLBACK_PROCESSED; } |
The following code sample is a callback routine, cntl_msg_callback, that examines the state field of the reply and takes action if the state is started, handled, or failed.
You can also add callbacks to static patterns by attaching a callback to the opnum of a signature in a ptype. 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 runs them.
Use tt_otype_opnum_callback_add to attach the callback routine to the opnum of an osignature.
Use tt_ptype_opnum_callback_add to attach the callback routine to the opnum of a psignature.