The command set of WorkShop Visual Replay is intended for replaying user actions and for checking the state of an application with respect to its widget hierarchy and its resource settings. You are not limited to this set of commands. You can extend it to include commands to meet your own needs, for example:
We will describe how to create a module which contains one command. This command prints a message on standard error and the name of the current shell widget. You can use this example as a template for constructing your own commands.
The source files for the command, together with a Makefile are provided in the $VISUROOT/src/examples/replay/usertemplate directory, where $VISUROOT is the location of your visu installation.
The contents of this directory are listed below:
The support files provide the framework which allows your extra commands to communicate with the WorkShop Visual Replay engine. You only need to change the xdsResources.h file - the remaining files prefixed with xds should not be altered in any way.
The contents of the interface.c file are shown below:
#include "stdio.h" #include "X11/Xos.h" #include "X11/Xlib.h" #include "X11/Intrinsic.h" void exampleHalloWorld( shell, message) Widget shell; char * message; { if (!message) message = "no message"; (void) fprintf ( stderr, "Widget %s says '%s'\n",XtName(shell), message);}
As you can see, a user-defined function should have two arguments:
The message is all the text which follows the user command syntax on that line in the script. The example script fragment below shows how a command would be accessed and used:
import usertemplate in ApplicationShell user HalloWorld I'm here
Here the message is "I'm here".
The interface between all objects and the WorkShop Visual Replay engine takes place using the standard Xt resource handling routines.
An entry for the new command is added to the resource list in xdsResources.h, as shown below:
{ "HalloWorld", XtCCallback, XtRPointer, sizeof(XtPointer), XtOffsetOf(data_t,HalloWorld), XtRImmediate, (XtPointer)exampleHalloWorld}
Only three items are of significance within this code:
"HalloWorld"
is the resource name
XtOffsetOf(data_t, HalloWorld)
gives the offset to the relevant entry in the data structure
(XtPointer)exampleHalloWorld
is a pointer to the address of the function
A pointer to that resource is added to the data structure within this file:
typedef struct { int type; XtPointer setValues; XtPointer getValues; XtPointer engineSetValues; XtPointer engineGetValues; /*-----------------------*/ XtPointer HalloWorld;
Entries above the line in the data structure are common to all WorkShop Visual Replay objects.
The last thing to do in this file is to declare the function:
extern void exampleHalloWorld();
You only need to change the OBJECT line in the Makefile in order to build the module. For this example, we change it to:
OBJECT=usertemplate
and then build the module by typing:
make solaris
Finally, we copy or link the shared object we have built to the $VISUROOT/lib/xds directory:
cp libusertemplate.so $VISUROOT/lib/xds
That is all there is to it.
To add a new command to the WorkShop Visual Replay command set:
You can create as many modules as you wish and load them into a script at any time.
See also: