The Caché Callout Gateway allows Caché applications to invoke shell or operating system commands, run external programs in spawned processes, and call functions from specially written shared libraries. The Callout Gateway is implemented as a suite of related functions contained in the Caché $ZF
This chapter discusses the following topics:
Callout Gateway Concepts and Terminology
Here are some important concepts that you should understand before reading the rest of this book:
Individual functions in the $ZF
suite are identified by the first argument of the function call, which will be a negative number from -1
. For example, the function that calls an operating system command has the form $ZF(-1, <oscommand>)
, where <oscommand>
is a string containing the command to be executed. When this function is discussed, it will be referred to as $ZF(-1)
. In the same way, the other functions will be referred to as $ZF(-2)
, using only the first parameter of the actual function call.
function is a special case, since it is actually just a container for eight utility functions that are identified by the first two parameters: $ZF(-4,1)
In this book, the term shared library
refers to a dynamically linked file (a DLL
file on Windows, an SO
file on UNIX® and related operating systems, or a shareable image file on OpenVMS). A Callout library
is a shared library that includes hooks to the Callout Gateway, allowing various $ZF
functions to load it at runtime and invoke its functions. Callout libraries are usually written in C (seeCompatible Languages and Compilers
), but could potentially be written in any other compiled language that uses a calling convention understood by your C compiler.
Callout library interfaces
All of the $ZF
functions except $ZF(-1)
are used to provide some form of access to Callout libraries. The $ZF(-3)
, and $ZF(-6)
functions provide three different interfaces for invoking Callout library functions, and $ZF(-4)
is a container for various utility functions used with the $ZF(-5)
Overview of $ZF Functions
function suite includes the following functions:
The $ZF(-1) and $ZF(-2) functions
functions are used to run shell commands and operating system service calls. They are not used to access Callout libraries, and can be called without any previous setup.
function is a simple way to load a Callout library and invoke a library function with a single statement. Both the library and its functions are specified by name, and the library remains in memory until replaced by a call to a different library.
The $ZF(-5) function interface
function and its utility functions allow multiple libraries to be handled efficiently. Both the library and its functions are identified by system-defined ID values. Several libraries can be in virtual memory at the same time. The following $ZF(-4)
functions are used to load and unload libraries, and to obtain library and function ID values:
The $ZF(-6) function interface
function and its utility functions provide a way to write Callout applications that do not require hard-coded library names. Instead, the actual library filenames are contained in a separate index table, where each library is associated with a unique, user-defined index number. Once the index table is defined, it is available to all processes in an instance of Caché. Callout applications identify a library by index number and load it by reading the index table. Several libraries can be in memory at the same time. The following functions are used to manage indexes and load or unload libraries:
Although your C function code will usually be used to generate a Callout library, it could also be directly linked into a custom version of the Caché executable. The $ZF()
function (with no negative number argument) is the interface for invoking statically linked Callout functions. Unlike $ZF(-3)
, or $ZF(-6)
, it does not need to specify an external library identifier, so statically linked functions can be called by just specifying the function name and arguments.
Compatible Languages and Compilers
Using the Callout Gateway you can call routines written in languages other than ObjectScript. On all platforms that support Caché you can call routines written in the C language. In theory you should be able to call routines written in any compiled language that is compatible with C. Two compatibility issues arise. First, the compiler must use an Application Binary Interface (ABI) that is compatible with C. Second, the compiler must generate code that does not rely on any runtime library features that are not compatible with Caché.
InterSystems supports using the same C compiler that we use to generate Caché on all platforms:
|HP HP-UX 11
||HP C/aC++ Compiler
|HP Tru64 UNIX
||IBM XL C for AIX
|Mac OS X (Darwin)
||Microsoft Visual Studio
|Linux (all variants)
||GNU Project GCC C
Most platforms have a standardized Application Binary Interface (ABI), making most compilers compatible. The Intel x86-32 and x86-64 platforms are major exceptions, Multiple calling conventions exist for these platforms. See (http://en.wikipedia.org/wiki/X86_calling_conventions
) for a discussion of calling conventions on these platforms.
Calling languages that use different calling conventions may be possible, as many C compilers allow declaring an external routine to have another calling convention. Therefore is it often possible to call routines written in other languages if one is willing to write a C wrapper routine.