A
adityar7
I'm a C programmer with limited Java experience, and need to use JNI
to implement a library in Java on top of a C library that consists of
a bunch of functions, each receiving some parameters from the
operating system. For each C function, the corresponding Java method
will be called, and some values would be returned back to the C
function. i.e. C -> Java -> C.
I know how to deal with simple primitive types, but I need to pass and
return multiple fields which could be primitive types or C structs. I
understand that to pass C structs I would need to define a
corresponding Java class and copy over the struct fields.
The question, though, is how to deal with multiple parameters/return
values of different types. Here is a sample C function specification:
int getattr (const char *, struct stat *)
I have approximately 35 such functions with differing number and types
of parameters. The corresponding Java method needs to be passed both
these parameters, and it also needs to return both of them! Since I'm
new to JNI the only way I can think of is to define 35 Java classes,
each corresponding to a particular set of parameters. Hopefully there
is a better way to do it!
Any help would be greatly appreciated
to implement a library in Java on top of a C library that consists of
a bunch of functions, each receiving some parameters from the
operating system. For each C function, the corresponding Java method
will be called, and some values would be returned back to the C
function. i.e. C -> Java -> C.
I know how to deal with simple primitive types, but I need to pass and
return multiple fields which could be primitive types or C structs. I
understand that to pass C structs I would need to define a
corresponding Java class and copy over the struct fields.
The question, though, is how to deal with multiple parameters/return
values of different types. Here is a sample C function specification:
int getattr (const char *, struct stat *)
I have approximately 35 such functions with differing number and types
of parameters. The corresponding Java method needs to be passed both
these parameters, and it also needs to return both of them! Since I'm
new to JNI the only way I can think of is to define 35 Java classes,
each corresponding to a particular set of parameters. Hopefully there
is a better way to do it!
Any help would be greatly appreciated