Comments (9)
Do you think this is a feature we should lift up to jnr-ffi?
Oh, absolutely! This is the scenario I'm facing: I'm trying to implement an SPI for a filesystem in Java. The Java method receives a C callback -- a visitor -- which it should then invoke for each file in a directory.
AFAIK, JNA has this feature, too.
from jnr-ffi.
+1. I am developing a virtual machine which exposes a JNI-like interface, where the C native program receives a struct (like JNIEnv
) and each API function is a function pointer in that struct. If a Java programmer wants to control a native component that exposes such an interface (imagine controlling another JVM from one JVM), it will be very common to call many functions via their function pointers.
The desired JNR interface should be similar to Closure, albeit it is Java calling C rather than C calling back to Java. The callee is a stateless C function rather than an object-bound Java method, so it should be easier to implement.
from jnr-ffi.
Directly? Not really. But I think you have at least two options:
- Bind syscall directly. I have no idea the correct way to call it from there because I've never used it.
- Use jffi to invoke the function. jffi contains the low-level native bits that jnr-ffi uses for function calls. See Foreign, which has "invoke" endpoints, and look at code that uses them.
Do you think this is a feature we should lift up to jnr-ffi?
from jnr-ffi.
+1, very important feature. Also, function pointer and structures as closure parameters would be very useful.
from jnr-ffi.
I don't think we've made any progress on this, but it's probably still useful. Anyone want to bring this issue back to life and try to come up with a good API for this?
from jnr-ffi.
I think it's useful, How to implement this kind of callback?
What' the equivalent of com.sun.jna.Callback
?
https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
CURLOPT_HEADERFUNCTION
Callback for writing received headers. See CURLOPT_HEADERFUNCTION
setopt(CurlOption.CURLOPT_HEADERFUNCTION, headerHandler);
setopt(CurlOption.CURLOPT_WRITEFUNCTION, contentHandler);
from jnr-ffi.
It seems unlikely that you can't already do this in jnr-ffi via some combination of APIs. Are we simply missing a nice endpoint that says "give me a callable wrapper around this C function pointer?
from jnr-ffi.
I think someone has made such an API here.
from jnr-ffi.
I'm interested by this functionality as well. Is there a better way to accomplish this now? If not, I'll look at Foreign
and jffi
as @headius mentioned.
from jnr-ffi.
Related Issues (20)
- Test Suite Overhaul and Improvement HOT 5
- UnsatisfiedLinkError when loading 3 dependent libraries HOT 11
- Unsatisfied link when used in conjunction with jnr-posix HOT 5
- Investigate failing Pointer Boolean tests on Darwin (macOS)
- LibraryLoader.search() path not taken into consideration unless also in LD_LIBRARY_PATH HOT 3
- What's the mapping Java type of C type FILE *?
- [feature request] HOT 1
- Erorr : jnr.ffi.provider.jffi.Provider
- Native Object filling "not working"
- Native C calling Java method HOT 1
- Cannot pass a struct to 'c' function by value
- Multi-dimensional arrays as struct members HOT 1
- Load the static link library HOT 1
- Release new version of jnr-ffi HOT 1
- Why use JNR over JNA HOT 1
- support convert pointer to struct
- String parameter of a callback function gets messed when passed from DLL (Rust) to Java HOT 1
- Android and bytecode
- document build procedures
- JVM crash invoking some SDL Library function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jnr-ffi.