Skip to content

Native C calling Java method #318

@paulocabrita-ionos

Description

@paulocabrita-ionos

Hello.

I am having some issues in transforming a Pointer into a java object through a callback function (C is calling a Java Method).

My flow is as follows:
// calling native function. xpto is the native library. The second parameter is the Java method that the C native will call.
int ret = xpto.setAuthenticate(this.context, new JavaAuthenticateImpl());

// My class with the method called by Native C. I know that C calls this method because I can get the pointer address in Java. How to build a java object from the Pointer??

public class JavaAuthenticateImpl implements JavaAuthenticateCb {

@Override
public boolean javaAuthenticateCb(Pointer context, Pointer token) {

    // I know the token is a "MyToken" type but how to convert it??

    System.out.println("Authenticate: " + token);
    return false;
}

}

// My interface.
public interface JavaAuthenticateCb {
@DeleGate
public boolean javaAuthenticateCb(Pointer context, Pointer token);
}

Are they some examples? I just can't find them.

Another thing, my native library has an include file with the description of all the C structs and they are ABI compliant. But, from my knowledge, JNR does not have the option to use ABI. But maybe I'm wrong.

How can I build a java object from a pointer inside a Java method that is called by a native function?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions