|
From: <ha...@po...> - 2007-01-11 13:08:32
|
Hello,
I have a set of functions (pure C) that need to make use of
callbacks into java code.
As basis I for my first tries I use the example that comes with the
tgz of swig-1.31. This example creates a caller object and a
callback object. The Java code registers the callback at the
caller. Then the callback can be executed from the C++ code.
To use this mechanism for my C code I see 2 possibilities:
1) Get access to the caller object and use the registered callback.
2) Have a global reference to a callback object and provide a
separate function to the Caller that sets this global reference.
I hope my understanding is correct so far. However my knowledge of
C++ is limited and my changes were not successful.
Here are some snippets for the second approach:
--- example.h
class Callback {
...
}
/* my global reference to the callback */
Callback *myCallback;
class Caller {
..
void setMyVCallback(Callback *cb) { myCallback = cb;}
}
--- main.java
public class main {
public static void main(String argv[]) {
System.loadLibrary("example");
Caller caller = new Caller();
callback = new JavaCallback();
caller.setMyCallback(callback);
caller.call();
}
}
class JavaCallback extends Callback
{
...
}
---
I am thankful for any pointers.
Ruediger
|