I'm working on a plugin project on cocos2d-x platform , I'd like to write some c++ wrapper interface to invoke java method through JNI from jar
SDK . I know how to use JNI to invoke a static java method, but I'm confused by the interface parameter in the java function.
I hava a cpp function pointer to handling callbacks:
typedef void (* MyCallback)(int responseCode, string arg1, set<string> arg2);
and I want to write a cpp wrapper method like :
static void MyCpp::setTags(set<string> tags, MyCallback callback) //it use `JNI` to invoke java method setTags(Context context, Set<String> tags, TagCallback callback).
The java method I want to invoke in the wrapper is
public static void setTags(Context context, Set<String> tags, TagCallback callback)
and the TagCallback
is an interface for API user to implement.
So, is it possible to get TagCallback
finally callback to MyCallback
function? in other words , can I use jni
to convert a cpp function pointer to java interface?
Thanks for your patience .
EDIT:
here is how to use setTag
if user want to use java only:
public static void setTags(context, tags, new TagCallback{
@Override
public void callback(int arg0, String arg1, Set<String> arg2) {
// TODO Auto-generated method stub
}
})
I'd like my SDK user to use my cpp wrapper method like this:
void setTagCallback(int responseCode, string arg1, set<string> arg2){
//users handle callback themselves.
}
void someOtherMethodInvokeTheCppWrapperMethod(){
MyCallback callback = setTagCallback;
set<string> tags;
MyCpp::setTags(tags,callback);
}
.jar
file is needed?? If you can provide some code example that would be a great help. – Tantalum