|
XCALL Utility
DescriptionIn (V)PRO/5 10.0 and higher, XCALL calls external BBj programs using a syntax similar to the traditional CALL verb. XCALL talks to the BBj XCALL server available in BBj 10.01 and higher. XCALL Server for BBjThe XCALL server is a BBj program found in <bbj install dir>/utils/xcall/xcallserver.bbj. The default prefix includes that path, so that xcallserver.bbj can usually be invoked without specifying a full path. Starting the ServerThe syntax for starting the server is: bbj xcallserver.bbj {- <port>} NOTE: If no port is specified, port 4444 is used. If BBj is running on a different machine from the client, and the called BBj program is GUI or uses client objects, the xcallserver should be run on the client machine with the following command line: bbj –TC –RH<host> xcallserver.bbj {- <port>} where <host> is the name of the machine on which BBjServices is running. The terminal specified for the server is also used for the called BBj program. For example, the INVISIBLE terminal (T2 in the default config.bbx on Windows) can be specified (-tT2) and both the server and the called BBj program will be run with the Sysconsole hidden. Stopping the ServerTo stop the server, use the following command line: bbj {–RH<host>} xcallserver.bbj - STOP XCALL Verb (PRO/5 and Visual PRO/5)The XCALL verb has a similar syntax to the CALL verb: XCALL "fileid{::label}{&}"{,MODE=<mode string>}{,ERR=lineref}{,TIM=<timeout>}{,exprlist...} Most of the options are exactly the same as the CALL verb:
As with CALL, if a parameter in exprlist is the name of a variable and the corresponding variable is changed inside the BBj program, the new value is returned to the calling program. Unlike CALL, an empty ENTER in the BBj program will not cause the called BBj program to inherit the entire workspace from the calling program. If adding an ampersand "&" to the end of the fileid{::label} string, the XCALL will return immediately. Because XCALL returns immediately, no variables that have been passed by reference will be changed and any TIM= option will be ignored. Some examples of calling a program with the "&" option: XCALL "gui.bbj&",a,b%,c$ XCALL introduces an additional option, TIM, that specifies a timeout for the XCALL verb. Visual PRO/5 or PRO/5 will wait the number of seconds specified in the timeout to get a response from BBj. The timeout does not specify a total time for running, but the time between receiving packets in a response from BBj. If the timeout expires, the XCALL verb will return an "!ERROR=0 (Busy or not ready)". This option allows the calling program to gracefully handle any situation in which the called BBj program becomes unresponsive. The default value for TIM is 0, which indicates there is no timeout and the XCALL verb will wait forever. ConfigurationXCALL server settings can be specified in an xcall.ini file. The location of this file can be specified by adding an XCALL=filename entry to the config.bbx file. In a situation where config.bbx does not have an XCALL= entry, (V)PRO/5 looks for xcall.ini in the current working directory when (V)PRO/5 (PRO/5 and Visual PRO/5) starts up. The xcall.ini file can have a PortCommand=<string> statement or a RemoteHost=<hostname> and a RemotePort=<port number> statement. The PortCommand=<string> statement tells (V)PRO/5 what to run and how to get the port number before connecting to the XCALL server. XCALL's default settings allow (V)PRO/5 to XCALL BBj programs in a BBjServices session running on the default port on the local system: RemoteHost=localhost It is only necessary to create an xcall.ini file if the XCALL server runs on a different port, remote machine, or PortCommand=<string> statement is needed. If the XCALL server will launch on a remote machine, "RemoteHost" should be changed to that machine's hostname. If the XCALL Server is invoked on the client machine with -RH<remote host>, RemoteHost should be set to localhost. RemotePort should be specified to match the server's port if the "<port>" option was specified for the XCALL Server. Windows Configuration Example The xcall.ini file contains: PortCommand="C:/Program Files/basis/bin/bbj.exe" "-cC:/Program Files/basis/cfg/config.min" -tT2 -q xcallserver.bbj - 0 For Windows-based systems only, this example causes Visual PRO/5 to start a BBj XCALL server before trying to connect to it. The 0 tells the XCALL server to use any available port and tells VPRO/5 what it is. When a BBj XCALL server is already running, that PortCommand will tell Visual PRO/5 what port the existing BBj XCALL server is running on instead of starting another. UNIX Configuration Example The xcall.ini contains: PortCommand=/usr/local/basis/bin/bbj -c/usr/local/basis/cfg/config.min -tT2 -q xcallserver.bbj - 0 For UNIX-based systems with a graphical user interface (GUI), this example causes PRO/5 to start a BBj XCALL server before trying to connect to it. The 0 tells the XCALL server to use any available port and tells PRO/5 what it is. When a BBj XCALL server is already running, that PortCommand will tell PRO/5 what port the existing BBj XCALL server is running on instead of starting another. Error HandlingXCALL can report the following errors:
Configuration ExamplesRunning the XCALL Server locallyThis is the simplest configuration, since only machine is involved. If the BBj program is GUI-based, uses Client Objects, or otherwise requires user interaction, it will show up on the local machine. BBj should already be installed on this machine and BBjServices should be running. To enable the XCALL verb in PRO/5 or Visual PRO/5, start the XCALL Server with the following line at the command or shell prompt: bbj xcallserver.bbj Running the XCALL Server on a different machineThe next scenario is useful for running BBj programs that do not require user interaction and don't make use of client objects that need access to the client's machine. The XCALL Server runs on a different machine than the BBx program that invokes it. BBj only needs to be installed on the server machine. For this example, suppose the server machine's name is "sparky" and the client machine is "fido". To configure XCALL to work this way:
Running the XCALL Server locally from a remote BBj ServerThe third scenario is useful if you want to run a BBj program that is a GUI program, a program that uses Client Objects, or a program requiring user interaction, but BBjServices is running on a different machine. Let's call the server "sparky" and the client "fido" once again. Both sparky and fido will need to have BBj installed. BBjServices will need to be running on sparky, but does not need to be run on fido.
Program ExamplesBefore these programs can be run, XCALL must be fully configured. Program 1This program demonstrates passing a string into a BBj program by reference and having it changed. Note that BBj needs to be able to find hello.bbj. hello.bbj needs to be accessible from the machine that BBjServices is running on. If hello.bbj will be specified without a full path, hello.bbj needs to be in BBj's PREFIX, which is specified in <bbj install dir>/cfg/config.bbx. Otherwise, XCALL will need the full path to hello.bbj specified. It's important to remember that when you specify a program in XCALL, it's BBj that needs to be able to find it. The BBx program 0010 LET NAME$="Nico" 0020 LET RESPONSE$="" 0030 XCALL "hello.bbj",NAME$,RESPONSE$ 0040 PRINT "Response was: ",RESPONSE$ 0050 END The BBj program ENTER who$, greeting$ greeting$="Well, hello "+who$+"!" EXIT The output of the BBx program should appear as: Response was: Well, hello Nico! Program 2This program demonstrates passing two numbers to BBj to be added together. The same notes apply to add.bbj as hello.bbj in Program 1. The BBx program 0010 LET A=1 0020 LET B=2 0030 XCALL "add.bbj::add_numbers",ERR=XCALL_ERR,A,B,C 0040 PRINT STR(A),"+",STR(B),"=",STR(C) 0050 STOP 0060 XCALL_ERR: 0070 IF ERR = 0 THEN RETRY 0080 PRINT "!ERROR=" + STR(ERR) + " (" + ERRMES(-1) + ")" 0090 ESCAPE The BBj program add_numbers: ENTER A, Y, C C=A+Y EXIT The output of the BBx program should appear as: 1+2=3 See Also
______________________________________________________________________________________ Copyright BASIS International Ltd. BBj®, Visual PRO/5®, PRO/5®, and BBx® are registered trademarks. |