JNA和ZBar(条形码阅读器库)

时间:2010-03-07 05:43:45

标签: java jna

我正在为JNA创建ZBar(library for bar code reader)的Java接口。

在JNA中,需要声明C中的结构。例如::

// In C
typedef struct {
    char* id;
    char* name;
    int age;
    char* sectionId
} EMPLOYEE;

// In Java with JNA
public static class Employee extends Structure {  // com.sun.jna.Structure
    String id;
    String name;
    int age;
    String sectionId;
}

但在ZBar中,结构没有成员。例如::

// zbar-0.10/include/zbar.h
// line:1009-1011
struct zbar_image_scanner_s;
/** opaque image scanner object. */
typedef struct zbar_image_scanner_s zbar_image_scanner_t;

这不会声明结构的大小或成员。

如何在JNA中为这些结构编写接口?

2 个答案:

答案 0 :(得分:0)

struct zbar_image_scanner_s在img_scanner.c中声明为:

/* image scanner state */
struct zbar_image_scanner_s {
    zbar_scanner_t *scn;        /* associated linear intensity scanner */
    zbar_decoder_t *dcode;      /* associated symbol decoder */
#ifdef ENABLE_QRCODE
    qr_reader *qr;              /* QR Code 2D reader */
#endif

    const void *userdata;       /* application data */
    /* user result callback */
    zbar_image_data_handler_t *handler;

    unsigned long time;         /* scan start time */
    zbar_image_t *img;          /* currently scanning image *root* */
    int dx, dy, du, umin, v;    /* current scan direction */
    zbar_symbol_set_t *syms;    /* previous decode results */
    /* recycled symbols in 4^n size buckets */
    recycle_bucket_t recycle[RECYCLE_BUCKETS];

    int enable_cache;           /* current result cache state */
    zbar_symbol_t *cache;       /* inter-image result cache entries */

    /* configuration settings */
    unsigned config;            /* config flags */
    int configs[NUM_SCN_CFGS];  /* int valued configurations */

#ifndef NO_STATS
    int stat_syms_new;
    int stat_iscn_syms_inuse, stat_iscn_syms_recycle;
    int stat_img_syms_inuse, stat_img_syms_recycle;
    int stat_sym_new;
    int stat_sym_recycle[RECYCLE_BUCKETS];
#endif
};

不知道你的设置(即:ENABLE_QRCODE,NO_STATS等)用于编译;我将把c转换为jna结构转换给你,但https://jna.dev.java.net/javadoc/overview-summary.html中描述的映射规则应该适用于它。

答案 1 :(得分:0)

由于结构不透明,API不需要任何内容​​知识,因此您无需担心它们。

只要看到对“zbar_image_scanner_t *”的引用,就可以使用Pointer。