I have a C++ application that needs to interface with a Java library. I'd like to receive notifications from the Java side so it needs to call back into the C++ app. I've found numerous examples on invoking Java functions from C++ (this is the easy part) and calling C/C++ functions from Java that are exported from a DLL.
Everything I've found so far is how to invoke Java callbacks from an external C++ function within a Java app. I need the opposite.
With straight C++ this, is of course, easy. I'd simply pass a function pointer to the class which would in turn call as a callback when needed. How can I do this when I'm instead invoking a Java function?
In case there's a better way altogether than what I'm asking for here is the overall application:
My C++ application needs to access an external server which will stream data back to my app. The access API is a Java based API. My current plan is to build a Java wrapper that will handle all of the API calls. This wrapper will be invoked from my C++ app using JNI. When data is received, it will process it as much as possible and then notify my C++ app with the adjusted data.
To sum up how can I call a C++ function callback from a Java class which was in turn invoked via JNI from a C++ application. There is no DLL to load for Java to use. Although I can make one if needed if everything can interface properly.
Function Path: C++ application -> Java class library -> C++ callback function