From: Stefan R. <sw...@mi...> - 2011-11-06 22:20:18
|
Hi there, I have a callback function in C++ to fill a byte array passed via pointer and size (I need some audio samples). Now I want to be able to provide this data from a callback in Java. I realize that callbacks are handled via directors in SWIG and that I can use predefined typemaps to combine a (char*, int) in C to a byte[] in Java. Both techniques work when used on their own, but for the life of me, I can't combine them. I tried to modify the Examples/java/callback/ example in swig by simply modifying the signature of Callback::run() to Callback::run(char* buffer, int size), which compiles just fine and will call the java code in JavaCallback::run(String buffer, int size), but as soon as I force (char* buffer, int size) into a jbyteArray by adding %apply (char *STRING, size_t LENGTH) { (char* buffer, int size) }; to example.i, SWIG will complain about "example.h:6: Warning 810: No jni typemap defined for int for use in Callback::run (skipping director method)". I tried to get a grip on the problem by running swig on a clean example with -debug-tmused and -debug-tmsearch but had no luck tracking it down. I modified the files Examples/java/callback/ as follows: in example.h Callback::run(char* buffer, int size) { std::cout << "Callback::run()" << std::endl; } Caller::call() { if (_callback) { char* foo = (char*)malloc(1024); memset(foo, 47, 1024); foo[1023] = 0; _callback->run(foo, 1024); free(foo); } } in runme.java // without the apply in example.i this works @Override JavaCallback::run(String buffer, int size) { System.out.println("JavaCallback.run() " + size + " " + buffer); } // with the apply, this ought to work @Override JavaCallback::run(byte[] buffer) { System.out.println("JavaCallback.run() " + " " + buffer.size); } Please, could someone provide me with a set of typemaps to use a java director class to modify a byte array? Best regards Stefan |