How the agent runs jBC
SUBROUTINES
A subroutine call finds the subroutine the way CALL does: by name, among the libraries listed in JBCOBJECTLIST, where CATALOG puts it. The session reads JBCOBJECTLIST once, when the connection is opened, so a subroutine cataloged after that is found only by later connections.
The arguments travel as strings. Each one is put into a variable, the subroutine is called with those variables, and their values after the call are sent back, so a subroutine returns results by assigning to its arguments:
SUBROUTINE ADDONE(A, B) CRT "in ADDONE " : A B = A + 1 RETURN END
Called with "41" and "", it sends back "41" and "42", after sending "in ADDONE 41" as output.
If the subroutine is not found, or it ends with an error, the response carries status 1 and the arguments as they were sent. A subroutine that calls JBASECOREDUMP makes the agent send back the core dump text instead.
OUTPUT AND INPUT
Output of the jBC code running for a request reaches the client before the response, in output messages, as it is printed. When the code asks for input and the client allowed it with allow_input, the agent sends an input message and waits for the client to send back a line. Without allow_input, a request for input ends the session.
EXECUTE requests collect the output of the command with CAPTURING, so their output comes back in the response itself.
NOTES
The agent links against the same libraries as compiled jBC programs and creates its sessions the way a jBC program's main program does. A C or C++ program linked against those libraries can do the same: the TAFCSession class in the TAFC include folder creates a session and calls subroutines, and the runtime functions that implement READ, WRITE, EXECUTE and the others are declared in jsystem.h. Most of them are exactly the calls the agent makes for its requests.