Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
B.  A Simple Demonstration of How the ToolTalk Service Works Adding Inter-Operability Functionality Modifying the Xfontsel Application  Previous   Contents   Next 
   
 

We Have Tool Communication!

You are now ready to see how the ToolTalk technology works.

  1. Start the Xedit application.

    To start Xedit, enter the command as follows:

    machine_name% xedit

    A screen similar to the one shown in Figure B-1 is displayed.

    Figure B-1 The Xedit Screen

  2. Load a file.

    The file you loaded is displayed in the xedit screen.

  3. Change the displayed font.

    1. Click in the `changefont' button on the Xedit screen.

      The xfontsel screen is displayed.

    2. Select the new font on the Xfontsel screen.

    3. Click in the `apply' button on the Xfontsel screen.

      The xedit screen showing the font change is displayed.

Adding ToolTalk Code to the Demonstration Applications

This section illustrates how ToolTalk code was added to the Xedit and Xfontsel applications.

  • The ellipses (. . .) indicate code has been skipped. The code examples only show a few lines of the code preceding and following the inserted ToolTalk lines of code.

  • The actual ToolTalk code that you need to add to the files is shown in bold type; for example:

 #include <desktop/tt_c.h>
/* ToolTalk header */

Adding ToolTalk Code to the Xedit Files

The changes made to the Xedit files are described in "Modifying the Xedit Application".


Example B-1 Modify the Xedit.h File

 /*
 *	rcs_id[] = "$XConsortium: xedit.h,v 1.18 89/07/21 19:52:58 kit Exp $";
 */

...

 #include <X11/Xaw/Viewport.h>
 #include <X11/Xaw/Cardinals.h>

 /*
 * For the ToolTalk demonstration, add the following include line.
 */
 #include <desktop/tt_c.h>	
 /* ToolTalk header */

 extern struct _app_resources {
 Boolean enableBackups;
 char *backupNamePrefix;
 char *backupNameSuffix;

...

 /*	externals in xedit.c 	*/

 extern void Feep();
 /*
 * For the ToolTalk demonstration, add the following externals.
 */
 extern void processToolTalkMessage();	/* Process ToolTalk message */
 extern void dieFromToolTalkError();
		/* Fail if error occurs */
 extern Display *CurDpy;
  /* Display */

...

  /* externs in commands.c */

...

 extern void DoChangeFont();
 		/* Change font */


Example B-2 Modified Xedit.c File

#if (!defined(lint) && !defined(SABER)) \
 static char Xrcsid[] = "$XConsortium: \
 xedit.c,v 1.23 89/12/07 \
 19:19:17 kit Exp $";
 #endif 			/* lint && SABER */

...

 void main(argc, argv)
 int argc;
 char **argv;
 {
 Widget top;
 String filename = NULL;
 static void makeButtonsAndBoxes();

 /*
  * For the ToolTalk demonstration, 
    add the following lines:
  */
 int ttmark;
/* ToolTalk mark */
 int ttfd;
/* ToolTalk file descriptor */
 char *procid;	
/* Process identifier */
 Tt_status ttrc;
/* ToolTalk status */

 top = XtInitialize( "xedit", \ 
"Xedit", NULL, 0, &argc, argv);

...

XtRealizeWidget(top);
XDefineCursor(XtDisplay(top),XtWindow(top), \
XCreateFontCursor( XtDisplay(top), \ 
XC_left_ptr));
 /*
  * For the ToolTalk demonstration, 
  * add the following lines
  * to make the top of stack the ToolTalk
  * session and set
  * it to be the default session.
  */
 ttmark = tt_mark();
 ttrc = tt_default_session_set( 
	/* set the default session .. */
 tt_X_session( 	
	/* .. to the X session for .. */
 DisplayString( 
	/* .. the X server displaying ..*/
 XtDisplay(top))));
 /* .. our top window... */
	/*
 	* Fail if no default session
		*/
 dieFromToolTalkError( \
 "tt_default_session_set",ttrc); 
 procid = tt_open();	
		/* Initialize ToolTalk */
		/*
		 * Fail if no process identifier
		 */
 dieFromToolTalkError("tt_open" \
,tt_ptr_error(procid));
 ttfd = tt_fd();	
		/* ToolTalk file descriptor */
		/*
		 * Fail if no file descriptor
		 */
dieFromToolTalkError("tt_fd", \
tt_int_error(ttfd));
		/*
		 * Activate file descriptor
		 */
XtAddInput(ttfd, (XtPointer)XtInputReadMask, \
 processToolTalkMessage, 0);

 XtMainLoop();
 }

...

 MakeCommandButton(b_row, "load", DoLoad);
 /*
  * For the ToolTalk demonstration, add the 
  * next line to make
  * a button for the font change command:
  */
 MakeCommandButton(b_row, "changefont", \ 
 DoChangeFont);	
 filenamewindow = MakeStringBox(b_row, \ 
"filename", filename);
 }
 XtCreateManagedWidget("bc_label", 
 labelWidgetClass, outer, NULL, ZERO);

...

 void Feep()
 {
 XBell(CurDpy, 0);
 /*
  * For the ToolTalk demonstration, add the 
  * following lines to receive and
  * process an incoming message:
  */
 }


 void processToolTalkMessage()
		/* Process ToolTalk message */
 {
 	int ttmark;				
  /* ToolTalk mark */
 	Tt_message incoming;						
		/* Incoming message */

 	ttmark = tt_mark();					
		/* ToolTalk mark */

 	incoming = tt_message_receive();
		/* Receive incoming message */
 	/*
 	 * The callback should process the 
   * message, so we should never
 	 * get a message returned.
 	 */
 	if (incoming == 0) return;	
		/* Return incoming message */

	if (tt_is_err(tt_ptr_error(incoming))) {
 		dieFromToolTalkError("tt_message_receive",
 				 tt_ptr_error(incoming));
 	}
 
 	/*
   * This is not a message we recognize.
 	 * If it is a request, or a notice that 
   * caused us to start, fail it.
 	 */

 	if (tt_message_class(incoming) == TT_REQUEST ||
 	 tt_message_status(incoming) ==
   TT_WRN_START_MESSAGE) {
 		tt_message_fail(incoming);
 	}
 	tt_message_destroy(incoming);								
			/* Destroy message */
 	tt_release(ttmark);						
			/* Free space */
 }

 void dieFromToolTalkError(procname, errid)
 char *procname;
 Tt_status errid;
		/* Fail if error occurs */
 {
 	/*
 	 * Don't die on warnings or TT_OK.
 	 */

 	if (tt_is_err(errid)) {
 		fprintf(stderr,"%s returned ToolTalk 
   error: %s\n",
 			procname, tt_status_message(errid));
 		exit(1);
 	}
 }

 
 
 
  Previous   Contents   Next