Write my own Java implementation of a method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Write my own Java implementation of a method

Hi, I want to expose my C++ pure virtual classes with Java interfaces. To do so, I've already tried some solution around the directors feature. Unfortunately, some use cases can't be solved with this solution. From the following C++ code:

class Foo {
virtual ~Foo(){}
void bar() = 0;

class Zorg {
void work(Foo* foo);
I wish I can have the following Java code:

interface IFoo {
void bar();

class Zorg {
  void work(IFoo foo) {
    // not MyModule.work(Foo.getCPtr(foo), foo));
   // I do not control the implementations of IFoo
And then write manually MyOwnNatives

void Java_org_acme_MyOwnNatives_work(jobject jfoo) {
Foo* foo = MyFooImpl(jfoo);
The director feature do the proxy job in Java, here, I do it in C++. It's simpler when dealing with Java interfaces prototype and implementation of these interfaces done by end user. The GC handling is a pain to handle between Java side, JNI side and C++ side. Is there any way to do so? Or an alternative solution?