For example, the following input callback:
|
and the following message callback:
|
results in the following output:
|
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
|
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:
|
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:
|
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:
|
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.