开发者

JNA and ZBar(library for bar code reader)

开发者 https://www.devze.com 2022-12-22 07:37 出处:网络
I\'m creating Java Interface with JNA for ZBar(library for bar code reader). In JNA, structures in C are needed to declare. For example::

I'm creating Java Interface with JNA for ZBar(library for bar code reader).

In JNA, structures in C are needed to declare. For example::

// In C
typedef struct {
    char* id;
    char* name;开发者_JAVA技巧
    int age;
    char* sectionId
} EMPLOYEE;

to

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

But in ZBar, structures have no members. For example::

// 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;

That doesn't declare size or members of the structures.

How can I write interfaces for these structures in JNA?


the struct zbar_image_scanner_s is declared in img_scanner.c as:

/* 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
};

not knowing what your setup (ie: ENABLE_QRCODE, NO_STATS, etc) for compilation is; I will leave the c to jna structure conversion to you, but the mapping rules as desccribe in https://jna.dev.java.net/javadoc/overview-summary.html should apply to it.


Since the structures are opaque, the API can not require any knowledge of their contents, and so you don't need to worry about them.

Just use Pointer whenever you see a reference to "zbar_image_scanner_t *".

0

精彩评论

暂无评论...
验证码 换一张
取 消