Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
D.  Frequently Asked Questions Questions What happens when a message arrives to my application?  Previous   Contents   Next 
   
 

For example, the following input callback:

input_callback(...)
{
     Tt_message m;
     printf ("input callback entered\n");
     m = tt_message_receive();
     printf ("input callback exiting, message handle is %d\n",
             (int)m);
}

and the following message callback:

message_callback(...)
{
     printf("message callback entered\n");
     return TT_CALLBACK_PROCESSED;
}

results in the following output:

input callback entered
message callback entered
input callback exiting, message handle is 0

How can I differentiate between messages?

You can differentiate between messages as follows:

  • Each message has an identifier that uniquely identifies the message across all running ttsessions.

  • You can use the tt_message_user call to include information on a user cell to associate the message to the application's internal state.

  • Message handles remain the same. For example, Example D-1 tells you whether the message you received is the same as the message you sent.


Example D-1 Differentiating Between Messages

    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 a 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 some new message coming in
    }

Can a process send a request to itself?

Yes. A process can send a request that gets handled by itself. A typical pattern for this type of request is:

{	...
	tt_message_arg_val_set(m, 1, "answer");
	tt_message_reply(m);
	tt_message_destroy(m);
	return TT_CALLBACK_PROCESSED;
}

However, in the case where the handler and the sender are the same process, the message has already been destroyed when the reply comes back (to the same process). Any messages (such as callbacks or user data) attached to the message by the sender are also destroyed. To avoid this situation, do not destroy the message; for example:

{	...
	if (0!=strcmp(tt_message_sender(m),tt_default_procid())) {
		tt_message_destroy(m);
}

Can I pass my own data to a function registered by tt_message_callback_add?

To pass your own data to a function registered by tt_message_callback_add, use the user data cells on the message; for example:

       x = tt_message_create();
       tt_message_callback_add(x,my_callback);
       tt_message_user_set(x, 1, (void *)my_data);

....

Tt_callback_action
Tt_message_callback(Tt_message m, Tt_pattern p)
{
	struct my_data_t *my_data;
	my data = (struct my_data_t *)tt_message_user(m, 1);

        ...

}

Note - User data can only be seen in the client where the data is sent.


How can I send arbitrary data in a message?

The ToolTalk service does not provide a built-in way to send structs; it only provides a way to send strings, ints, and byte arrays. To send structs, use an XDR routine to turn the struct into a byte array and put the bytes in the message. To deserialize, use the same XDR routine.

Can I transfer files with the ToolTalk service?

No, not directly. You can however:

  • Place the file data in a message argument.

    The ToolTalk service copies the message data from the application into the library, from the library to ttsession, from ttsession to the receiver's library, and then out of the library when the receiver gets the argument value.If the data is large, this method can be very slow and use up a large amount of memory.

  • Place the file name in a message argument.

    This method assumes that every receiver mounts the file, and mounts it at the same mount point.

  • Place the file name in the tt_message_file attribute.

    This method also assumes that every receiver mounts the file; however, the ToolTalk service will resolve any mount point differences.

 
 
 
  Previous   Contents   Next