Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: JNI binding generator can't handle function pointers as method parameters #776

Open
bluca opened this issue Jan 2, 2017 · 11 comments

Comments

@bluca
Copy link
Member

bluca commented Jan 2, 2017

https://github.com/zeromq/zproject/blob/master/zproject_java_lib.gsl#L156

        if resolve_container (argument) = 1
            my.method.okay = 0
            #echo "Skipping $(class.name).$(my.method.name) - can't deal with argument type $(argument.type)"

So the class is skipped given the constructor can't be generated.

This is a problem in CZMQ since it means that zactor bindings can't be generated. We'd need some help here from JNI experts! How can we fix this?

zeromq/czmq#1443

@jimrthy
Copy link

jimrthy commented May 21, 2017

It looks to me as though this is also a problem with ZLoop.

@jimrthy
Copy link

jimrthy commented Jun 4, 2017

I'm not an expert in any of the tech involved here.

I think one valid approach would be:

  • the caller needs to supply an instance that fulfills some sort of ICallback interface (much like you hand anonymous event handler instances to Swing)
  • we set up a C-level callback wrapper to hand to the 0mq API
  • that callback's "args" parameter is a struct that contains
    • JNI environment pointer
    • method ID
    • "real" arguments
  • that callback wrapper function does the "real" callback

I took a first pass at this approach (and started pointing out the places that look obviously broken) here:
jimrthy#1

I probably won't get another chance to look at this until next weekend, at the earliest.

Maybe someone who's more familiar with GSL can help push it further along?

@sappo
Copy link
Member

sappo commented Jun 4, 2017

Thanks for investigating I'll give it at try next week

@jimrthy
Copy link

jimrthy commented Jun 4, 2017

Thank you!

@sappo
Copy link
Member

sappo commented Jun 23, 2017

@jimrthy I havn't forgotten this issue but I'm a bit short on time for time being.

@jimrthy
Copy link

jimrthy commented Jul 8, 2017

I haven't forgotten either. Just also distracted by other things.

@diorcety
Copy link

diorcety commented Feb 12, 2018

Could you take a look on https://github.com/diorcety/zproject/tree/x_java2 ?

@diorcety
Copy link

python use ffi in order to handle the callbacks. I used jffi which is an Java implementation which allow to use java callback quickly. This is almost the same thing that python stuff

@sappo
Copy link
Member

sappo commented Feb 12, 2018 via email

@hgourvest
Copy link
Contributor

I managed to write a pure java class for zactor, and doing this I also discovered zsys::create_pipe was not working for the same reason, it pass a pointer to a handle.

@stephan57160
Copy link
Contributor

Found this link, but unable to see if really useful or not:
https://stackoverflow.com/questions/819536/how-to-call-java-functions-from-c

(my 2 cents).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants