I have got some way with Swig but the above question is a show stopper for me. I have a fairly complex struct which contains my application data and I need to pass it between C code in the ndroid NDK and Java code at the top level application.
The struct is as follows :
typedef struct
{
uint16_t x1;
char s1[4][16];
char s2[4][16];
char s3[4][16];
uint32_t x2[4];
} MY_STRUCT;
It obviously has an unholy brew of multi-dimensional arrays and structure types and I have tried a few things but nothing works.
I need to be able to set and get values in the arrays in both the Java and C code, can anyone tell me the general strategy I should follow to achieve this ?
Thanks,
Boo
You should probably build your set of accessors:
%inline %{
void MY_STRUCT_x1_set(struct MY_STRUCT *obj, uint_16 val) {
obj->x1 = val;
}
void MY_STRUCT_s1_set(struct MY_STRUCT *obj, int i, int j, char val) {
obj->s1[i][j] = val;
}
char MY_STRUCT_s2_get(struct MY_STRUCT *obj, int i, int j) {
return obj->s2[i][j];
}
%}
... and so on. This way you can have full access from Java (through the generated wrappers) to your structure.
Note that SWIG does not perform out-of-bounds or other conditions that may be violated by misuse of the wrapper code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.