B
Bill Medland
Is there an easier way to do this?
I am writing a library layer of code that uses JNI to call down into a
library implemented in C.
The C library includes a callback mechanism including both register and
unregister;
e.g. registerCallback(functiontype func, void *context);
unregisterCallback(functiontype func, void *context);
The java library layer will export a similar ability to add and remove a
listener.
The JNI layer will pass the listener as the context and the address of a
small redirector function as the func arguments.
So clearly I will have to call NewGlobalRef on the jobject passed down as
the listener.
(Presumably that global reference will be valid in different environments
when it comes back to the redirector)
The problem is with removing the listener; how am I going to figure out what
jobject to pass to the DeleteGlobalRef.
It seems to me that the JNI layer is going to have to keep a copy of all the
global references generated and then search that list using IsSameObject to
find the global reference that was used that refers to the same object as
the local reference being passed down.
Is there an easier way? Like is there a way to find the global reference
corresponding to a local reference?
I am writing a library layer of code that uses JNI to call down into a
library implemented in C.
The C library includes a callback mechanism including both register and
unregister;
e.g. registerCallback(functiontype func, void *context);
unregisterCallback(functiontype func, void *context);
The java library layer will export a similar ability to add and remove a
listener.
The JNI layer will pass the listener as the context and the address of a
small redirector function as the func arguments.
So clearly I will have to call NewGlobalRef on the jobject passed down as
the listener.
(Presumably that global reference will be valid in different environments
when it comes back to the redirector)
The problem is with removing the listener; how am I going to figure out what
jobject to pass to the DeleteGlobalRef.
It seems to me that the JNI layer is going to have to keep a copy of all the
global references generated and then search that list using IsSameObject to
find the global reference that was used that refers to the same object as
the local reference being passed down.
Is there an easier way? Like is there a way to find the global reference
corresponding to a local reference?