Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
8.  Sending Messages Modifying Applications to Send ToolTalk Messages Adding Message Callbacks  Previous   Contents   Next 
   
 

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.

Sending a Message

When you have completed your message, use tt_message_send to send it.

If the ToolTalk service returns TT_WRN_STALE_OBJID, it has found a forwarding pointer in the ToolTalk database that indicates the object mentioned in the message has been moved. However, the ToolTalk service will send the message with the new objid. You can then use tt_message_object to retrieve the new objid from the message and put it into your internal data structure.

If you will not need the message in the future (for example, if the message was a notice), you can use tt_message_destroy to delete the message and free storage space.


Note - If you are expecting a reply to the message, do not destroy the message until you have handled the reply.


Examples

Example 8-5 illustrates how to create and send a pnotice.


Example 8-5 Creating and Sending a Pnotice

	/*
	* Create and send a ToolTalk notice message
	* ttsample1_value(in int <new value)
	*/

	msg_out = tt_pnotice_create(TT_SESSION, "ttsample1_value");
	tt_message_arg_add(msg_out, TT_IN, "integer", NULL);
	tt_message_arg_ival_set(msg_out, 0, (int)xv_get(slider, 
	    PANEL_VALUE));
	tt_message_send(msg_out);

	/*
	* Since this message is a notice, we don't expect a reply, so
	* there's no reason to keep a handle for the message.
	*/

	tt_message_destroy(msg_out);

Example 8-6 illustrates how an orequest is created and sent when the callback routine for cntl_ui_hilite_button is called.


Example 8-6 Creating and Sending an Orequest

/*
 * Notify callback function for `cntl_ui_hilite_button'.
 */
void
cntl_ui_hilite_button_handler(item, event)
	Panel_item		item;
	Event		*event;
{
	Tt_message		msg;
	
	if (cntl_objid == (char *)0) {
		xv_set(cntl_ui_base_window, FRAME_LEFT_FOOTER,
		 "No object id selected", NULL);
		return;
	}
	msg = tt_orequest_create(cntl_objid, "hilite_obj");
	tt_message_arg_add(msg, TT_IN, "string", cntl_objid);
	tt_message_callback_add(msg, cntl_msg_callback);
	tt_message_send(msg);
}

 
 
 
  Previous   Contents   Next