29 messages in net.java.dev.jna.usersRe: [jna-users] Struct with Union wit...
FromSent OnAttachments
Wolfgang PichlerMar 25, 2009 5:58 am 
Timothy WallMar 25, 2009 7:02 am 
Timothy WallMar 25, 2009 7:06 am 
Wolfgang PichlerMar 25, 2009 7:21 am 
Timothy WallMar 25, 2009 7:24 am 
Wolfgang PichlerMar 25, 2009 8:11 am 
Wolfgang PichlerMar 25, 2009 8:20 am 
Novatchkov HristoMar 25, 2009 8:41 am 
Timothy WallMar 25, 2009 9:59 am 
Timothy WallMar 25, 2009 10:28 am 
Timothy WallMar 25, 2009 10:38 am 
Hristo NovatchkovMar 25, 2009 11:40 am 
Wolfgang PichlerMar 25, 2009 12:02 pm 
LYou...@gkservices.comMar 25, 2009 12:11 pm 
Timothy WallMar 25, 2009 12:52 pm 
Wolfgang PichlerMar 26, 2009 12:22 am 
Timothy WallMar 26, 2009 4:46 am 
Wolfgang PichlerMar 26, 2009 5:23 am 
Timothy WallMar 26, 2009 6:09 am 
Wolfgang PichlerMar 26, 2009 6:13 am 
Wolfgang PichlerMar 26, 2009 6:26 am 
Timothy WallMar 26, 2009 6:40 am 
Wolfgang PichlerMar 26, 2009 12:22 pm 
Timothy WallMar 26, 2009 1:00 pm 
Wolfgang PichlerMar 26, 2009 3:15 pm 
Timothy WallMar 30, 2009 6:06 am 
Wolfgang PichlerMar 30, 2009 11:55 am 
Timothy WallMar 30, 2009 12:14 pm 
Wolfgang PichlerMar 31, 2009 12:35 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Struct with Union with Structs...Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Mar 25, 2009 7:02:50 am
List:net.java.dev.jna.users

Once you've determined the type of your union, call Union.setType(Class) followed by Union.read(), which will initialize the active structure. JNA can't do this automatically.

Note that structure fields are ByValue by default, and structures are ByReference by default as parameters.

On Mar 25, 2009, at 8:59 AM, Wolfgang Pichler wrote:

Hi all,

i am new here – so please be nice if I am asking a dumb question…

I am trying to wrap the iaxclient library to be useable with java. There is already an implementation – but quit old – and with the iaxclient v1 – not v2…

You can find the iaxclient.h here:
http://iaxclient.sourceforge.net/doc/html/iaxclient_8h.html

I have it already working to get loaded – and it does already registers with my server – but I am not able at time to handle all events correctly. I do have already done the function to install a callback for the events – the callback does also gets called – and does already get the event as it should – but the event structure is the following c code

00538 typedef struct iaxc_event_struct { 00543 struct iaxc_event_struct *next; 00544 00549 int type; 00550 00554 union { 00556 struct iaxc_ev_levels levels; 00558 struct iaxc_ev_text text; 00560 struct iaxc_ev_call_state call; 00562 struct iaxc_ev_netstats netstats; 00564 struct iaxc_ev_video_stats videostats; 00566 struct iaxc_ev_url url; 00568 struct iaxc_ev_video video; 00570 struct iaxc_ev_audio audio; 00572 struct iaxc_ev_registration reg; 00573 } ev; 00574 } iaxc_event;

With iaxc_ev_registriation 00513 struct iaxc_ev_registration { 00519 int id; 00520 00527 int reply; 00528 00532 int msgcount; 00533 };

And iaxc_ev_levels 00183 struct iaxc_ev_levels { 00187 float input; 00188 00192 float output; 00193 };

I have mapped it to

public static class iaxc_ev_registration extends Structure { public int id; public int reply; public int msgcount; }

public static class iaxc_ev_levels extends Structure { public float input; public float output; }

public static class iaxc_event_struct extends Structure { public static class ByValue extends iaxc_event_struct implements Structure.ByValue { } public Pointer next; public int type; public static class iaxc_event_union extends Union { public iaxc_ev_registration registration; public iaxc_ev_levels levels; } public iaxc_event_union ev; }

In the callback i will get the iaxc_event_struct passed correctly – I can distinguish between the event types – but then when I try to access a specific event type structure – the structure is not initialized (nulled). When i for example directly add iaxc_ev_registration instead of the union – then I will have an initialized structure in the event handler for the registration event – but can’t analyze all other events. I have read about using setType and read function to initialize the union – but it does not work.

Here is the callback function IAXClient.INSTANCE.iaxc_set_event_callback(new IAXClient.FUNCTION() { @Override public int invoke(iaxc_event_struct.ByValue event) { if (event==null) { return 0; } switch(event.type) { case IAXClient.IAXC_EVENT_REGISTRATION: System.out.println("Event Raw: " + event.ev.toString());

event.ev.setType(IAXClient.iaxc_ev_registration.class); event.ev.read(); IAXClient.iaxc_ev_registration reg = (iaxc_ev_registration) event.ev.getTypedValue(IAXClient.iaxc_ev_registration.class); System.out.println("Event Reg: " + reg.reply); break; case IAXClient.IAXC_EVENT_LEVELS: IAXClient.iaxc_ev_levels levels = (iaxc_ev_levels) event.ev.getTypedValue(IAXClient.iaxc_ev_levels.class); System.out.println("Event LEvel: " + levels.input); break; default: break; } return 0; } });

I think it will be something trivial – but I don’t get it working by myself…

Can someone here enlighten me ?

Best regards, Wolfgang