Programming with OmniRpcHandle

For an easy example, we show a program which adds values which set the in setAB function and get its value, and use the IDL file as is.

Define Sample;

Globals {
 int a,b;
}

Define setAB(int in a0, int in b0)
{
   a = a0; b = b0;
}

Define plusAB(int out ab[])
{
     *ab = a + b;
}

In the Globals directive, we define, in a style similar to C language, the variables which are used in the whole module. In the Globals scope, we write the module definitions in the style of C language.

You should compile this module with omrpc-cc, and register Sample.rex on the remote host (alice.is.tsukuba.ac.jp)) with omrpc-register.

#include <OmniRpc.h>
#include <stdio.h>

int main(int argc,char *argv[]){
   int ab;
   OmniRpcHandle handle;

   OmniRpcInit(&argc,&argv);
   handle = OmniRpcCreateHandle("alice.is.tsukuba.ac.jp","Sample");

   OmniRpcCallbyHandle(handle,"setAB",10,20);
   OmniRpcCallbyHandle(handle,"plusAB",&ab);
   printf("a+b=%d\n",ab);
  
   OmniRpcHandleDestroy(handle);

   OmniRpcFinalize();
   exit(0);
}

After the modules are initialized, the client program first activates the remote executable programs with OmniRpcCreateHandle API, and gets the OmniRpcHandle corresponding to it. Otherwise, by using OmniRpcCallbyHandle, the client program can call functions in the modules. Finally, the client program can stop the remote executable program with OmniRpcDestroyHandle API.

Also available is OmniRpcCallAsyncByHandle API, which call RPCs asynchronously.