|
1 package org.hedgewars.hedgeroid.frontlib; |
|
2 |
|
3 import com.sun.jna.DefaultTypeMapper; |
|
4 import com.sun.jna.FromNativeContext; |
|
5 import com.sun.jna.ToNativeContext; |
|
6 import com.sun.jna.TypeConverter; |
|
7 import com.sun.jna.TypeMapper; |
|
8 |
|
9 class AndroidTypeMapper extends DefaultTypeMapper { |
|
10 static final int NATIVE_INT_SIZE = 4; |
|
11 static final int NATIVE_SIZE_T_SIZE = 4; |
|
12 static final int NATIVE_BOOL_SIZE = 1; |
|
13 public static final TypeMapper INSTANCE = new AndroidTypeMapper(); |
|
14 |
|
15 protected AndroidTypeMapper() { |
|
16 addTypeConverter(Boolean.class, new BooleanConverter()); |
|
17 addTypeConverter(NativeSizeT.class, new SizeTConverter()); |
|
18 } |
|
19 |
|
20 private static final class BooleanConverter implements TypeConverter { |
|
21 public Class<Byte> nativeType() { |
|
22 return Byte.class; |
|
23 } |
|
24 public Object fromNative(Object value, FromNativeContext context) { |
|
25 return ((Byte)value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE; |
|
26 } |
|
27 public Object toNative(Object value, ToNativeContext context) { |
|
28 return Byte.valueOf((byte)(Boolean.TRUE.equals(value) ? 1 : 0)); |
|
29 } |
|
30 } |
|
31 |
|
32 private static final class SizeTConverter implements TypeConverter { |
|
33 public Class<Integer> nativeType() { |
|
34 return Integer.class; |
|
35 } |
|
36 public Object fromNative(Object value, FromNativeContext context) { |
|
37 return NativeSizeT.valueOf((Integer)value); |
|
38 } |
|
39 public Object toNative(Object value, ToNativeContext context) { |
|
40 return Integer.valueOf(value==null ? 0 : ((NativeSizeT)value).intValue()); |
|
41 } |
|
42 } |
|
43 } |
|
44 |