using Callback Based Data Buffers with Java

Hans-Christoph Steiner hans at
Mon Jul 15 22:44:09 CEST 2013

I'm trying to use the "Callback Based Data Buffers" in Java/JNI to implement
GnuPGData/gpgme_data_t objects that allow gpgme to work with Java InputStreams
and OutputStreams.  Conceptually its simple, InputStreams have a read()
method, OutputStreams have a write() method, and they just need to be hooked
up to gpgme_data_read_cb() and gpgme_data_write_db() respectively.

But of course the devil is in the details.  Right now I'm struggling with the
two incompatible declarations of the callback functions in gpgme.h and data.h.


typedef ssize_t (*gpgme_data_read_cb_t) (void *handle,
					 void *buffer,
					 size_t size);

typedef gpgme_ssize_t (*gpgme_data_read_cb) (gpgme_data_t dh,
                                             void *buffer,
                                             size_t size);

For the GnuPGData.c implementation of the Java class that corresponds to
gpgme_data_t, it needs to include both gpgme.h and data.h since it needs to
get the definition of the gpgme_data struct in order to access elements of it.
 Or maybe I'm missing something.

I've tried a bunch of things, but gcc is always telling me:

jni/GnuPGData.c:101:9: error: 'gpgme_data_read_cb' redeclared as different
kind of symbol
In file included from jni/GnuPGData.c:9:0:
./external/gpgme/src/data.h:39:25: note: previous declaration of
'gpgme_data_read_cb' was here
jni/GnuPGData.c: In function 'gpgme_data_read_cb':

I'm using gpgme 1.4.2~ commit c29dad2315406bed75b9547103650bef642e6aa7.


PGP fingerprint: 5E61 C878 0F86 295C E17D  8677 9F0F E587 374B BE81

More information about the Gnupg-devel mailing list