Common Desktop Environment: ToolTalk Messaging Overview

Creating a Ptype File

The ToolTalk types mechanism is designed to help the ToolTalk service route messages. When your tool declares a ptype, the message patterns listed in it are automatically registered; the ToolTalk service then matches messages it receives to these registered patterns. These static message patterns remain in effect until the tool closes communication with the ToolTalk service.

The ToolTalk Types Database already has installed ptypes for tools bundled with this release. You can extract a list of the installed ptypes from the ToolTalk Types Database, as follows:

% tt_type_comp -d user|system|network -P

The names of the ptypes will be printed out in source format.

For all other tools (that is, tools that are not included in this release), you need to first create a ptype file to define the ptype for your application, and then compile the ptype with the ToolTalk type compiler, tt_type_comp. To define a ptype, you need to include the following information in a file:

To create a ptype file, you can use any text editor (such as vi, emacs, or dtpad). Example 2-2 shows a snippet from the ptype file for the CoEd application.


Example 2-2 CoEd Ptype File

ptype DT_CoEd {                     /* Process type identifier */
    start "CoEd";                   /* Start string */
    handle:                         /* Receiving process */
    /*
     * Display ISO_Latin_1
     */
    session    Display( in    ISO_Latin_1 contents) => start opnum = 1;  /* Signature */
        /* NOTE: A signature is divided
         * into two parts by the => as follows:
         * Part 1 specifies how the message is to be matched;
         * Part 2 specifies what is to be taken when 
         * a match occurs.
         */

}

After you have created the ptype file, you need to install the ptype. To do this, run the ToolTalk type compiler. On the command line, type the following:

% tt_type_compCoEd.ptype

where CoEd.ptype is the name of the CoED ptype file.

Testing for Existing Ptypes in Current Session

The ToolTalk service provides a simple function to test if a given ptype is already registered in the current session.

// Test for existing ptype registered in current session
tt_ptype_exists(const char *ptid)

where ptid is the identifier of the session to test for registration.

Merging a Compiled Ptype File into a Currently Running ttsession

The ToolTalk service provides a function to merge a compiled ToolTalk type file into the currently running ttsession:

// Merge new compiled ptypes into currently running
ttsession tt_session_types_load(current_session, compiled_types_file)

where current_session is the current default ToolTalk session and compiled_types_file is the name of the compiled ToolTalk types file. This function adds new types and replaces existing types of the same name; other existing types remain unchanged.