PROLOGIO for RPC

An RPC package is required because one application cannot simply call into another's program area. The arguments and return value(s) need to be wrapped up at one end and parsed at the other. This library provides a convenient way of doing so, allowing a range of types of data to be passed between applications, namely integers, reals, strings, words (unquoted strings), and lists of these types (which can include further lists). Therefore two main capabilities are required: a way of encoding information in a string, and a way of communicating this string between applications. The basic PROLOGIO functions described above are used for the first, and the wxWindows implementation of DDE is used for the second.

The RPC facility is used in much the same way as the DDE facility in wxWindows, only the base classes to use are rpcServer, rpcClient and rpcConnection. From these derive your own client, server and connection classes, overriding OnAcceptConnection (server) and OnMakeConnection (client) as usual. You now have a choice of how the server connection responds to calls: either you can install your own OnCall handler which accepts and returns Prolog structures, or you may install an rpcCallTable so calls get automatically routed to appropriate C++ functions. If no call table has been installed, the library will call OnCall instead.

Note that the topic name when using the RPC package must always be "RPC".

RPC is implemented as follows. When the client calls rpcConnection::Call with a PrologExpr structure as argument, this structure is written to a string and Execute is called. At the server end, the data is parsed back into a PrologExpr structure, and either OnCall is called, or, if there is a call table, a functor (procedure name) matching the supplied name is searched for. If one is found, the argument types are checked. If they are incorrect, an error structure is sent back to the client. If they are correct, the appropriate user-supplied C++ function implementing this command is called, which returns another PrologExpr. This structure is written to a string, and when the client side Requests the result, is returned. The client side parses the result and returns a PrologExpr as the result of the original Call.

To the client application, the Call is like a normal procedure call except the name and arguments need to be wrapped up in a PrologExpr structure, and the result is also a PrologExpr. Similarly, the server application implements a series of functions, one per command, receiving and returning PrologExpr structures.

To use the library, include "wx.h", "read.h", "prorpc.h" and link with libproio.a (UNIX) or prologio.lib (PC) and the wxWindows library.