Hopefully someone can help me with this problem.
I am trying to write a wrapper class for a C library, using the
JNIWrapper library.
I understand how to use the Pointer class, but what I'm not sure about
is how to wrap funciton pointers.
Specifically, in the C library there are several structures defined as
follows
struct vtable {
getValue_proto getValue; /* A function to get the current value
*/
...
... /* Similar functions */
...
};
struct quantity {
Quantity_getVTable getVTable /* a function to get the vtable */
...
... /* Misc. items related to the quantity */
};
Then there are several type definitions:
typedef vtable * (*Quantity_getVTable)();
typedef double (*getValue_proto) (quantity *quant, ...);
I've set up four seperate classes using JNIWrapper. Two to extend the
Structure class, and two extending Callback (which is what I assume
one is supposed to do with function pointers, though I'm not really
sure.)
Thus:
public class vtable extends Structure
{
public Pointer getValue = new Pointer(new getValue_proto());
...
}
public class quantity extends Structure
{
public Pointer getVTable = new Pointer(new Quantity_getVTable());
...
}
public class Quantity_getVTable extends Callback
{
public Pointer retVal = new Pointer(new vtable());
...
}
public class getValue_proto extends Callback
{
public Pointer quant = new Pointer(new quantity());
...
}
Doing things this way introduces a stack overflow as the classes are
now circularly dependent. So, my question is, how are virtual
functions supposed to be implemented within JNIWrapper in order to
solve this problem?
If this is the wrong forum to post, please let me know where I should
redirect this to.
Thanks,
Paul
On Mon, 23 Jul 2007 05:48:29 -0700, "paul.h.burns"
<paul.h.burns@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>Doing things this way introduces a stack overflow as the classes are
>now circularly dependent. So, my question is, how are virtual
>functions supposed to be implemented within JNIWrapper in order to
>solve this problem?
The equivalent animal in Java is a Delegate class with a single
method. Perhaps you can wrap the C method into a Delegate C++ class.
see http://mindprod.com/jgloss/delegate.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
paul.h.burns - 23 Jul 2007 20:23 GMT
On Jul 23, 2:36 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Mon, 23 Jul 2007 05:48:29 -0700, "paul.h.burns"
> <paul.h.bu...@gmail.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 12 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Thanks for the reply. I might have to give that a shot if what I've
managed to hack together doesn't work.
-Paul