|
From: William S F. <ws...@fu...> - 2011-01-07 07:41:18
|
This looks like a bug where multi-argument typemaps are not implemented
for directors. You'd better log a bug report in the SF bug tracker. A
possible workaround is to change your API to use a single parameter, so
replace (u8* data, int size) with say DataSize_t, where
typedef struct {
u8* data;
int size;
} DataSize_t;
then write your typemaps to marshall DataSize_t to byte[].
William
On 27/12/10 11:52, José Santos wrote:
> 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) };
> #endif
>
> but I get a swig warning:
>
> JavaSerialPortListener.h(13) : Warning 810: No jni typemap defined for
> se 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* <ke...@gm... <mailto:ke...@gm...>>
> Date: Sun, Dec 26, 2010 at 6:22 PM
> Subject: How to typemap u8*(unsigned char *) to java byte[] (jbyteArray)?
> To: swi...@li... <mailto:swi...@li...>
>
>
> Hi,
>
> 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");
> }
>
> @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
> Swi...@li...
> https://lists.sourceforge.net/lists/listinfo/swig-user
|