Java and LXRT/COMEDI

Fillod Stephane stephane.fillod at thomson.net
Thu Oct 28 19:40:35 CEST 2004


[...]
> It appears that the LXRT/Java approach would require me and my
> students to write Java-callable routines in C for the actual, time-
> critical RT code.  These "methods" themselves would invoke
> rt_make_hard_real_time(), rt_make_soft_real_time(), etc., and have to
> be written following the JNI (Java Native Interface).
>
> Compared to using the multiple thread/kernel modules approach
> described above, this would be a *lot* of work (unless someone else
> has already done it) and require learning JNI.  Also, I'm not sure
> there wouldn't be problems (scheduling, timing, etc) with the JNI
> "RT methods" interacting with the Java virtual machine.

Everybody should know about the SWIG project http://swig.org !

"SWIG is a software development tool that connects programs written 
in C and C++ with a variety of high-level programming languages."
IOW, SWIG allows you to turn a C or C++ *API* into a wrapper (or binding)
for any of the following languages: Tcl,Python,Perl,Guile,Java,
Ruby,Mzscheme,PHP,Ocaml,C#,Chicken,Allegro CL,Modula-3,Eiffel,..
This way, you can call directly from those languages functions
of your C/C++ developped library.

So for the LXRT/Java binding, you would not have to learn JNI.
Let SWIG munch the LXRT header files and automatically generate
the *NI tedious bindings. You may want to give SWIG some directives
if you wanna change the signature of some calls, or OOifiy 
a bare C API to match the target language, ie. make C code like
"p = xxx_init(); xxx_do_stuf(p); xxx_release(p);" seen like
"obj = new xxx(); obj->do_stuf(); delete obj;". Quite nice.

I haven't used SWIG yet with LXRT, but I did on couple other projects
to either plug easily a GUI or allow scripting of low-level libraries.
It is such a pleasure because once you've done the (little) work
for one language, SWIG open you the access to all the other languages.
I'll be never thankful enough for SWIG. This enabler project is as 
clever as LXRT is, I mean so smart, and patent free ;-)

And YES, this would even allow a Java application to run under LXRT hard 
real-time, as long as no syscall is made (otherwise LXRT alt. mode),
and as long as you have a good idea of what the naughty Java is doing 
behind your back (garbage collector, interpreter lock, etc.).

Let me know if you need more information. I can help for a quickstart 
with SWIG on the LXRT interface, but won't be able to devote much time
to do a complete work.


Best Regards,

-- 
Stephane

PS: every project manager of a C/C++ library should offer free-for-all
    bindings using SWIG :-)




More information about the Rtai mailing list