JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
ToolTalk User's Guide
search filter icon
search icon

Document Information

Preface

1.  Introducing the ToolTalk Service

2.  An Overview of the ToolTalk Service

3.  Message Patterns

4.  Setting Up and Maintaining the ToolTalk Processes

5.  Maintaining Application Information

6.  Maintaining Files and Objects Referenced in ToolTalk Messages

7.  Participating in ToolTalk Sessions

8.  Sending Messages

9.  Dynamic Message Patterns

10.  Static Message Patterns

11.  Receiving Messages

12.  Objects

Object-Oriented Messaging

Object Data

Creating Object Specs

Assigning Otypes

Determining Object Specification Properties

Storing Spec Properties

Adding Values to Properties

Writing Object Specs

Updating Object Specs

Maintaining Object Specs

Examining Spec Information

Comparing Object Specs

Querying for Specific Specs in a File

Moving Object Specs

Destroying Object Specs

Managing Object and File Information

Managing Files that Contain Object Data

Managing Files that Contain ToolTalk Information

An Example of Object-Oriented Messaging

13.  Managing Information Storage

14.  Handling Errors

A.  Migrating from the Classing Engine to the ToolTalk Types Database

B.  A Simple Demonstration of How the ToolTalk Service Works

C.  The ToolTalk Standard Message Sets

D.  Frequently Asked Questions

Glossary

Index

An Example of Object-Oriented Messaging

You can run the edit_demo program for a demonstration of ToolTalk object-oriented messaging. This demo consists of two programs – cntl and edit. The cntl program uses the ToolTalk service to start an edit process with which to edit a specified file; the edit program allows you to create ToolTalk objects and associate the objects with text in the file. Once objects have been created and associated with text, you can use the cntl program to query the file for the objects and to send messages to the objects.

The following example code creates an object for its user. It has been divided into two parts. It creates the object spec, sets the otype, writes the spec to the ToolTalk database, and wraps the user's selection with C-style comments. The application also sends out a procedure-addressed notice after it creates the new object to update other applications who observe messages with the ToolTalk_EditDemo_new_object operation. If other applications are displaying a list of objects in a file managed by ToolTalk_EditDemo, they update their list after receiving this notice.

Example 12-3 Object Creation Part 1

/*
 * Make a ToolTalk spec out of the selected text in this textpane. Once
 * the spec is successfully created and written to a database, wrap the
 * text with C-style comments in order to delimit the object and send out
 * a notification that an object has been created in this file.
 */
Menu_item
edit_ui_make_object(item, event)
   Panel_item        item;
   Event        *event;
{
         int               mark = tt_mark();
    char        *objid;
    char        *file;
    char        *sel;
    Textsw_index        first, last;
    char        obj_start_text[100];
    char        obj_end_text[100];
    Tt_message        msg;

    if (! get_selection(edit_ui_xserver, edit_ui_textpane,
              &sel, &first, &last)) {
        xv_set(edit_ui_base_window, FRAME_LEFT_FOOTER,
               “First select some text”, NULL);
        tt_release(mark);
        return item;
    }
    file = tt_default_file();

    if (file == (char *)0) {
        xv_set(edit_ui_base_window, FRAME_LEFT_FOOTER,
               “Not editing any file”, NULL);
        tt_release(mark);
        return item;
    }

Example 12-4 Object Creation Part 2

/*
    /* create a new spec */

    objid = tt_spec_create(tt_default_file());
    if (tt_pointer_error(objid) != TT_OK) {
        xv_set(edit_ui_base_window, FRAME_LEFT_FOOTER,
               “Couldn't create object”, NULL);
        tt_release(mark);
        return item;
    }

    /* set its otype */

    tt_spec_type_set(objid, “Sun_EditDemo_object”);
    if (tt_spec_write(objid) != TT_OK) {
        xv_set(edit_ui_base_window, FRAME_LEFT_FOOTER,
               “Couldn't write out object”, NULL);
        tt_release(mark);
        return item;
    }

    /* wrap spec's contents (the selected text) with C-style */
    /* comments. */

    sprintf(obj_start_text,” /* begin_object(%s) */”, objid);
    sprintf(obj_end_text,”    /* end_object(%s) */”, objid);
    (void)wrap_selection(edit_ui_xserver, edit_ui_textpane,
               obj_start_text, obj_end_text);

    /* now send out a notification that we've added a new object */

    msg = tt_pnotice_create(TT_FILE_IN_SESSION,”Sun_EditDemo_new_object”);
    tt_message_file_set(msg, file);
    tt_message_send(msg);

    tt_release(mark);
    return item;
}