From: Stefan R. <ken...@go...> - 2011-09-18 22:15:22
|
José Santos <kephrao <at> gmail.com> writes: > > > Hello!I've been trying some aproaches but still can find a solution. Anyway, I think I'm very close:I added this to my module interface:%include "various.i" > %include "typemaps.i"#if defined(SWIGJAVA)%typemap(in) (u8 * BYTE, int LENGTH) {/* Functions from jni.h */$1 = (u8 *) JCALL2(GetByteArrayElements, jenv, $input, 0);$2 = (int) JCALL1(GetArrayLength, jenv, $input); > > }%typemap(jni) (u8 * BYTE, int LENGTH) "jbyteArray"%typemap(jtype) (u8 * BYTE, int LENGTH) "byte[]"%typemap(jstype) (u8 * BYTE, int LENGTH) "byte[]"%typemap(javain) (u8 * BYTE, int LENGTH) "$javainput"/* Specify signature of method to handle */%apply (u8 * BYTE, int LENGTH) { (u8 * data, int size) };#else%apply (u8 * STRING, int LENGTH) { (u8 * data, int size) };#endifbut I get a swig warning:JavaSerialPortListener.h(13) : Warning 810: No jni typemap defined forse in JavaSerialPortListener::ReceivedBytes (skipping director method)and when I run, java throws an exception:Exception in thread "main" java.lang.NoSuchMethodError: SwigDirector_JavaSerialPortListener_ReceivedBytes > > at SerialPortJNI.swig_module_init(Native Method) at SerialPortJNI. <clinit>(SerialPortJNI.java:27) at SerialPortEngine.getInstance(SerialPortEngine.java:38) at SerialPort.main(SerialPort.java:41)What I'm missing?Thanks!José Santos > > > ---------- Forwarded message ----------From: José Santos <kephrao <at> gmail.com> > > Date: Sun, Dec 26, 2010 at 6:22 PMSubject: How to typemap u8*(unsigned char *) to java byte[] (jbyteArray)?To: swig-user <at> lists.sourceforge.netHi,I'm trying to understand typemaps and java typemaps but I couldn't yet realize what should I do to achieve my goal, so I'm asking for help.First, I've a typedef that I massively use in the project:typedef unsigned char u8;I have a "observer/caller" implementation that I want to extend to Java and call from c++:class JavaSerialPortListener{public: JavaSerialPortListener(){}; > > > > virtual ~JavaSerialPortListener(){}; virtual void ReceivedBytes(u8* data, int size){return;}; };class SerialPortEngine{protected: std::set<JavaSerialPortListener *> _serialPortListeners;public: // *** CONSTRUCTORS & DESTRUCTOR *** SerialPortEngine(); virtual ~SerialPortEngine(); // *** METHODS *** void addSerialPortListener(JavaSerialPortListener & listener) {_serialPortListeners.insert(&listener);}; > > > > void removeSerialPortListener(JavaSerialPortListener& listener) {_serialPortListeners.erase(&listener);}; void Process() { ... u8* data = ...somedata int readedData = ...data size > > > > for(std::set<ISerialPortListener*>::iterator it=_serialPortListeners.begin();it!=_serialPortListeners.end();it++) { (*it)->ReceivedBytes(data,readedData); } }; > > > > };Now, my module interface file:%module(directors="1") SerialPort%{#include "JavaSerialPortListener.h"#include "SerialPortEngine.h"%}/* turn on director wrapping JavaSerialPortListener */ > > > > %feature("director") JavaSerialPortListener;%include "JavaSerialPortListener.h"and I would like that Java's ReceivedBytes method looked like this:public class SerialPort extends JavaSerialPortListener > > > > { static { System.loadLibrary("SerialPort"); } <at> Override public void ReceivedBytes(byte[] data) { ... }}So, how can I typemap u8*(unsigned char *) to java byte[] (jbyteArray) in a director like this?Thanks!-- José Santos > > > > -- José Santos > > -- José Santos > > > ------------------------------------------------------------------------------ > Learn how Oracle Real Application Clusters (RAC) One Node allows customers > to consolidate database storage, standardize their database environment, and, > should the need arise, upgrade to a full multi-node Oracle RAC database > without downtime or disruption > http://p.sf.net/sfu/oracle-sfdevnl > > _______________________________________________ > Swig-user mailing list > Swig-user <at> lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/swig-user > Hi Jose, i know, the topic is some month old, but i have the same problem and i cant find something about a solution for it. it would be great, when you find a solution to give me some help to implement it into my own project. regards Stefan Reusch |