You'd probably better writing a little Java instead, i.e. a class that implements the interface through a method that calls a custom native method you could hook up to whatever you want from the native side.
Quite the contrary, I am very much interrested in any information, if you have any links, documentation or tutorial on that it would be great.
Well, the usual way to do that in Java is to use a library to generate a .class file directly in memory, then load it with a JavaClassLoader()
The file contains a definition for a new class with one or more native methods that implements your interface.
That was a usual way priori to 1.4 which introduced dynamic proxies (java.lang.reflect.Proxy) which are supported on android as well (at least documentation states so, never tried it). Dynamic proxy is exactly what OP needs - dynamic class generator. Since it delegates invocation to standardized InvocationHandler interface, it's possible to create mediation layer between native and VM side.
First one will need a InvocationHandler implementation that delegates all calls to native side:
public class NativeInvocationHandler implements InvocationHandler {
public NativeInvocationHandler(long ptr) {
this.ptr = ptr;
}
Object invoke(Object proxy, Method method, Object[] args) {
return invoke0(proxy, method, args);
}
native private Object invoke0(Object proxy, Method method, Object[] args);
private long ptr;
}
where pointer should be pointer to native representation of InvocationHandler something like:
class NativeInvocationHandler {
public:
virtual ~NativeInvocationHandler();
virtual jobject Invoke(JNIEnv *, jobject method, jobjectArray args) = 0;
};
and a piece of glue code:
jobject invoke0(JNIEnv *env, jobject thiz, jobject method, jobjectArray args) {
jfieldID ptrField = env->GetFieldID(env->GetObjectClass(thiz), "ptr", "J");
jlong jptr = env->GetLongField(thiz, ptrField);
NativeInvocationHandler *h = reinterpret_cast<NativeInvocationHandler> (jptr);
return h->Invoke(env, method, args);
}
Now, there is a need for a small piece of java code but it's static so as I understand this is fine with OP.
Disclaimer: I did use this technique on embedded systems with java CDC VM, but never tried it on android so I have no idea if everything will work as advertised.
--
Bart