On Jan 24, 2008 3:57 PM, Olivier Lefevre <[EMAIL PROTECTED]> wrote:
> I had been clear about this when I asked the first time, though
> (on the general Octave mailing list).

Sorry, I didn't remember (so many mails, I don't remember everything).

> So, back to the drawing board:
> is there a ready-made solution for calling Octave from Java, or
> even from C? I can write JNI code if I must, I just don't know
> Octave internals and don't wish to have to figure them out.

What I stated previously still holds. The java package provides
some way (through the Octave.java class) for java code to
access octave. However, and that's the crucial point, the
Octave.java class assumes that octave engine is already running
and that the java package (from octave-forge) has been
initialized. So it's designed to work in the following way:
octave -> java -> octave.

This part of the java package is internal, so don't expect to find
any documentation about it. However, I can give you already an
idea about how it's working. Let's assume octave is running:
1) octave wants to make a call to some Java code
2) octave initializes the java package
  2a) the JVM is started (and the octave thread ID is stored internally)
  2b) the java package installs an input_event_hook function that is
        called regularly by readline (== when octave is idle)
  2c) octave transfer the call to the JVM (actually to the
        ClassHelper.java class, that takes care of finding and calling
        the java method)
3) let's state now that the (called-from-octave) java code wants to
    make a call in octave; it uses the Octave.java class for that and
    for instance call evalAndWait(String)
4) if the current thread is the same as the octave thread, the call
    is executed immediately (through JNI); if it's another thread, the
    call is put on a stack and the calling thread is stopped
5) the input_event_hook installed in 2b checks if there are any pending
    call to execute and executes them; finally it notifies any waiting thread
6) the calling thread in 4 resumes

This implementation has several limitations:
1) it assumes octave is running and the java package is initialized
2) there's no mechanism to get the return value of octave calls back
    to octave

What you're looking for (calling directly octave from a java application)
is currently not possible with the existing code; however I think it can
serves as a starting point to add this functionality. What is missing:
1) a way to initialize the octave engine without starting the standard
read-eval-print loop; there's currently no API to do that.
2) the __java__.cc file (and probably some java classes) should be
adapted in order to initialize the internal variables with the running
JVM (== the running java application).

You're not the only one to want this feature. See for instance this
thread: 
http://www.nabble.com/How-to-initialize-octave-without-read-eval-print-loop--to14261528.html#a14494130

I don't have time to work on that, but I'd be glad to integrate patches
that would implement it.

Michael.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to