SWIG interface to receive an opaque struct reference in Java through function argument

Posted by Beeo on Stack Overflow See other posts from Stack Overflow or by Beeo
Published on 2012-10-05T04:08:34Z Indexed on 2012/10/07 9:37 UTC
Read the original article Hit count: 246

Filed under:
|
|

I am trying to use SWIG in order to use the Spotify API (libspotify) for Android: https://developer.spotify.com/technologies/libspotify/

I am having trouble defining the SWIG interface file to be able to successfully call the following native C function:

sp_error sp_session_create(const sp_session_config * config, sp_session ** sess);

Which in C would be called like this:

//config struct defined previously
sp_session *sess;
sp_session_create(&config, &sess);

But in Java I would need to call it like this:

//config object defined previously
sp_session javaSess = new sp_session();
sp_session_create(config, javaSess);

sp_session is an opaque struct and is only defined in libspotify's API.h file as:

typedef struct sp_session sp_session;

I'm expecting the libspotify library to create it and give me a reference to it. The only thing I need that reference for then is to pass to other functions in the API.

I believe the answer lies within the SWIG interface and typemaps, but I have been unsuccessful in trying to apply the examples I found in the documentation: http://www.swig.org/Doc2.0/SWIGDocumentation.html#Java_struct_pointer_pointer `http://www.swig.org/Doc2.0/SWIGDocumentation.html#Java_using_typemaps_return_arguments

Help!

© Stack Overflow or respective owner

Related posts about java

Related posts about swig