[zeromq-dev] Wrapping a C API in JNI?

gonzalo diethelm gdiethelm at dcv.cl
Mon Nov 18 20:04:18 CET 2013


Well, I have mucked around such APIs with JNI a couple of times, and what I would do is something like this:

In java:

public class DropsJNI
{
  public native long drops_new(String directory);
  public native void drops_destroy(long self);
}

What this is doing is providing a really shallow JNI interface to your C API, using longs to store pointers. You really want this in order to simplify all the JNI rigmarole.

You can then provide a higher-level, pure Java class “Drops” that uses “DropsJNI” to implement whatever abstraction you wish to implement. This class could have a private member of type “DropsJNI” to call your JNI shim, and a private member of type “long” to store the “self” pointer returned by drops_new. That seems to be all the context you need to handle.

In other words, keep things as simple as possible.

Does this help? Good luck,

--
Gonzalo Diethelm
DCV Chile

From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-bounces at lists.zeromq.org] On Behalf Of shancat
Sent: Monday, November 18, 2013 3:45 PM
To: ZeroMQ development list
Subject: Re: [zeromq-dev] Wrapping a C API in JNI?


struct drops_t {
    void *pipe;
    zctx_t *ctx;
};

drops_t * drops_new (const char *directory);
void drops_destroy (drops_t **self_p);

The main problem is that I don't know the proper way to manage the drops_t struct
On Nov 19, 2013 5:38 AM, "gonzalo diethelm" <gdiethelm at dcv.cl<mailto:gdiethelm at dcv.cl>> wrote:
Hi Shannen,

If you can post here a brief overview of the C API, I can give you a couple of hints.

Regards,

--
Gonzalo Diethelm
DCV Chile

From: zeromq-dev-bounces at lists.zeromq.org<mailto:zeromq-dev-bounces at lists.zeromq.org> [mailto:zeromq-dev-bounces at lists.zeromq.org<mailto:zeromq-dev-bounces at lists.zeromq.org>] On Behalf Of shancat
Sent: Monday, November 18, 2013 3:32 PM
To: ZeroMQ development list
Subject: [zeromq-dev] Wrapping a C API in JNI?

I'm working with Pieter on a ZeroMQ related free-software project and
could use some help. We need to wrap up the (simple) C API in JNI.

The project can be viewed at https://github.com/edgenet/drops

I don't "know" JNI so I'm getting quite stuck and any help is
appreciated :)

- Shannen
________________________________
Declaración de confidencialidad: Este Mensaje esta destinado para el uso de la o las personas o entidades a quien ha sido dirigido y puede contener información reservada y confidencial que no puede ser divulgada, difundida, ni aprovechada en forma alguna. El uso no autorizado de la información contenida en este correo podrá ser sancionado de conformidad con la ley chilena. Si usted ha recibido este correo electrónico por error, le pedimos eliminarlo junto con los archivos adjuntos y avisar inmediatamente al remitente, respondiendo este mensaje. Disclosure: This Message is to be used by the individual, individuals or entities that it is addressed to and may include private and confidential information that may not be disclosed, made public nor used in any way at all. Unauthorized use of the information in this electronic mail message may be subject to the penalties set forth by Chilean law. If you have received this electronic mail message in error, we ask you to destroy the message and its attached file(s) and to immediately notify the sender by answering this message.

_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org<mailto:zeromq-dev at lists.zeromq.org>
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

----------------------------------------- 
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena. 
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje. 

"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law. 
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20131118/8e6cdd7f/attachment.html>


More information about the zeromq-dev mailing list