M
Martin Maercker
Hi,
I will soon need to reimplement parts of an existing object model in a
mixture of Java and C++ code. I leafed through "The Java Native
Interface - Programmer's Guide and Specification" but am still not
sure whether JNI can do what I need, especially as regards the
creation and management of C++ objects from Java code (the creation of
Java objects from C++ code, on the other hand, seems to be standard
procedure, at least as far as I could tell from the JNI book...).
What I need to happen on the C++ side is:
- Set up a singleton which starts a native timer thread.
- Listener objects register with the singleton.
- At each timer thread callback, a specific method is called in each
listener.
- At different times in the course of the app's lifecycle, individual
listeners need to be unregistered and destroyed and other listeners
created and registered.
These management tasks are driven by user interaction. Most of the
app, including the UI, is in Java, so I need to find a way to control
the C++ class lifecycles and relationships from Java.
Is this kind of setup possible with JNI? If so, could someone give me
some advice or direct me to reference material on how best to go about
it? If not, does anyone know an alternative?
Any help greatly appreciated,
Martin Maercker
I will soon need to reimplement parts of an existing object model in a
mixture of Java and C++ code. I leafed through "The Java Native
Interface - Programmer's Guide and Specification" but am still not
sure whether JNI can do what I need, especially as regards the
creation and management of C++ objects from Java code (the creation of
Java objects from C++ code, on the other hand, seems to be standard
procedure, at least as far as I could tell from the JNI book...).
What I need to happen on the C++ side is:
- Set up a singleton which starts a native timer thread.
- Listener objects register with the singleton.
- At each timer thread callback, a specific method is called in each
listener.
- At different times in the course of the app's lifecycle, individual
listeners need to be unregistered and destroyed and other listeners
created and registered.
These management tasks are driven by user interaction. Most of the
app, including the UI, is in Java, so I need to find a way to control
the C++ class lifecycles and relationships from Java.
Is this kind of setup possible with JNI? If so, could someone give me
some advice or direct me to reference material on how best to go about
it? If not, does anyone know an alternative?
Any help greatly appreciated,
Martin Maercker