Dynamic Loading API

The LayGO Dynamic Loading API consists of 3 functions and 1 global variable:

These are declared in laygodll.h and exported by laygodll shared objects:

Relying on the LayGO Dynamic Loading API instead of implicit loading is largely transparent to the application. The application can still be written using the normal function call syntax for LayGO API functions. The application only needs to do 3 additional things:

  1. #include laygodll.h in place of laygo.h and laygomsg.h.
  2. Add code to call lgo_LoadLaygoDll() before the first call to a LayGO API function
  3. Add code to call lgo_UnloadLaygoDll() after the last call to a LayGO API function.

A successful call to lgo_LoadLaygoDll() sets the value of the global variable lgo_Fn to the address of a function table containing a correctly typed function pointer for each LayGO API function in the loaded DLL. laygodll.h contains a macro definition for each LayGO API function which transforms function call syntax into a reference to a member in the function table lgo_Fn. For instance, the macro definition

#define lgo_Open    lgo_Fn->Open

transforms

cid = lgo_Open(serviceName);

into

cid = lgo_Fn->Open(serviceName);

The effect is the same, but with 1 layer of indirection. (Note: lgo_GetFunctionTable() simply returns the value of lgo_Fn and need not be called to use the API.)

The following sample code illustrates using this API to load the RPC-enabled version of the LayGO API:

#include <stdio.h>
#include "laygodll.h"

if (lgo_LoadLaygoDll(lgo_DLL_RPC) < 0)
{
    printf("Failure loading LayGO DLL.\n");
}
else
{
    if (lgo_ConnectServerLocal() < 0)
    {
        printf("Failure connecting to RPC server.\n");
    }

    /* Process... */

    if (lgo_DisconnectServer() < 0)
    {
        printf("Failure disconnecting RPC server.\n");
    }

    lgo_UnloadLaygoDll();
}

It's as easy as that! And building clients is just as easy. The LayGO for Java package uses dynamic loading to support the standard, Hardware Interface and RPC-enabled versions of the API in a single JNI implementation.