Содержащиеся вНайти другие документыРесурсы поддержки | Загрузить это руководство в формате PDF (500 КБ)
Chapter 12 ObjectsThis chapter describes how to create ToolTalk specs for objects your application creates and manages. Before you can identify the type of objects, you need to define otypes and store them in the ToolTalk Types Database. See Chapter 10, Static Message Patterns for more information on otypes. The ToolTalk service uses spec and otype information to determine object-oriented message recipients. Note - Programs coded to the ToolTalk object-oriented messaging interface are not portable to CORBA-compliant systems without source changes. Object-Oriented MessagingObject-oriented messages are addressed to objects managed by applications. To use object-oriented messaging, you need to be familiar with process-oriented messaging concepts and the ToolTalk concept of object. Object DataObject data are stored in two parts as shown in Figure 12-1. Figure 12-1 ToolTalk Object Data
One part is called the object content. The object content is managed by the application that creates or manages the object and is typically a piece, or pieces, of an ordinary file: a paragraph, a source code function, or a range of spreadsheet cells, for example. The second part is called the object specification (spec). A spec contains standard properties such as the type of object, the name of the file in which the object contents are located, and the object owner. Applications can also add their own properties to a spec, for example, the location of the object content within a file. Because applications can store additional information in specs, you can identify data in existing files as objects without changing the formats of the files. You can also create objects from pieces of read-only files. Applications create and write specs to the ToolTalk database managed by rpc.ttdbserverd. Note - You cannot create objects in files that reside in a read-only file system. The ToolTalk service must be able to create a database in the same file system that contains the object. A ToolTalk object is a portion of application data for which a ToolTalk spec has been created. Creating Object SpecsTo instruct the ToolTalk service to deliver messages to your objects, you create a spec that identifies the object and its otype. Table 12-1 lists the ToolTalk functions you use to create and write object spec. Table 12-1 Functions to Create
To create an object spec in memory and obtain an objid for the object, use tt_spec_create. Assigning OtypesTo assign an otype for the object spec, use tt_spec_type_set. You must set the type before the spec is written for the first time. It cannot be changed. Note - If you create an object spec without assigning an otype or with an otype that is unknown to the ToolTalk Types Database, messages addressed to the object cannot be delivered. (The ToolTalk service does not verify that the otype you specified is known to the ToolTalk Types Database.) Determining Object Specification PropertiesYou can determine what properties you want associated with an object; you add these properties to a spec. The ToolTalk service recognizes that it is not always possible to store information in your own internal data; for example, the objid for objects in plain ASCII text files. You can store the location of the objid in a spec property and then use this location to identify where the object is in your tool's internal data structures. The spec properties are also a convenience for the user. A user may want to associate properties (such as a comment or object name) with the object that they can view later. Your application or another ToolTalk-based tool can search for and display these properties for the user. Storing Spec PropertiesTo store properties in a spec, use tt_spec_prop_set. Adding Values to PropertiesTo add to the list of values associated with the property, use tt_spec_prop_add. Writing Object SpecsAfter you set the otype and add properties to an object spec, use tt_spec_write to make it a permanent ToolTalk item and visible to other applications. When you call tt_spec_write, the ToolTalk service writes the spec into the ToolTalk database. Updating Object SpecsTo update existing object spec properties, use tt_spec_prop_set and tt_spec_prop_add specifying the objid of the existing spec. Once the spec properties are updated, use tt_spec_write to write the changes into the ToolTalk database. When you are updating an existing spec and the ToolTalk service returns Maintaining Object SpecsThe ToolTalk service provides the functions to examine, compare, query, and move object specs. Table 12-2 lists the ToolTalk functions you use to maintain object specs. Table 12-2 Functions to Maintain Object Specifications
Examining Spec InformationYou can examine the following spec information with the specified ToolTalk functions:
Comparing Object SpecsTo compare two objids, use tt_objid_equal. tt_objid_equal returns a value of 1 even in the case where one objid is a forwarding pointer for the other. Querying for Specific Specs in a FileCreate a filter function to query for specific specs in a file and obtain the specs in which you are interested. Use tt_file_objects_query to find all the objects in the named file. As the ToolTalk service finds each object, it calls your filter function, and passes it the objid of the object and the two application-supplied pointers. Your filter function does some computation and returns a Tt_filter_action value ( Example 12-1 illustrates how to obtain a list of specs. Example 12-1 Obtaining a List of Specifications
Within the tt_file_objects_query function, the application calls cntl_gather_specs, a filter function that inserts objects into a scrolling list. Example 12-2 illustrates how to insert the objid. Example 12-2 Inserting the objid
Moving Object SpecsThe objid contains a pointer to a particular file system where the spec information is stored. To keep spec information as available as the object described by the spec, the ToolTalk service stores the spec information on the same file system as the object. Therefore, if the object moves, the spec must move, too. Use tt_spec_move to notify the ToolTalk service when an object moves from one file to another (for example, through a cut and paste operation).
When your process sends a message to an out-of-date objid (that is, one with a forwarding pointer), tt_message_send returns a special status code, Note - Update any internal data structures that reference the object with the new objid. Destroying Object SpecsUse tt_spec_destroy to immediately destroy an object's spec. Managing Object and File InformationDespite the efforts of the ToolTalk service and integrated applications, object references can still be broken if you remove, move, or rename files with standard operating system commands such as rm or mv. Broken references will result in undeliverable messages. Managing Files that Contain Object DataTo keep the ToolTalk database that services the disk partition where a file that contains object data is stored up-to-date, use the ToolTalk functions to copy, move, or destroy the file. Table 12-3 lists the ToolTalk functions you use to manage files that contain object data. Table 12-3 Functions to Copy, Move, or Remove Files that Contain Object Data
The return type for these functions is Tt_status. Managing Files that Contain ToolTalk InformationThe ToolTalk service provides ToolTalk-enhanced shell commands to copy, move, and remove ToolTalk object and file information. Table 12-4 lists the ToolTalk-enhanced shell commands that you and users of your application should use to copy, move, and remove files referenced in messages and files that contain objects. Table 12-4 ToolTalk-Wrapped Shell Commands
An Example of Object-Oriented MessagingYou 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
Example 12-4 Object Creation Part 2
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||