24 import com.sun.jna.ToNativeContext; |
24 import com.sun.jna.ToNativeContext; |
25 import com.sun.jna.TypeConverter; |
25 import com.sun.jna.TypeConverter; |
26 import com.sun.jna.TypeMapper; |
26 import com.sun.jna.TypeMapper; |
27 |
27 |
28 class AndroidTypeMapper extends DefaultTypeMapper { |
28 class AndroidTypeMapper extends DefaultTypeMapper { |
29 static final int NATIVE_INT_SIZE = 4; |
29 static final int NATIVE_INT_SIZE = 4; |
30 static final int NATIVE_SIZE_T_SIZE = 4; |
30 static final int NATIVE_SIZE_T_SIZE = 4; |
31 static final int NATIVE_BOOL_SIZE = 1; |
31 static final int NATIVE_BOOL_SIZE = 1; |
32 public static final TypeMapper INSTANCE = new AndroidTypeMapper(); |
32 public static final TypeMapper INSTANCE = new AndroidTypeMapper(); |
33 |
33 |
34 protected AndroidTypeMapper() { |
34 protected AndroidTypeMapper() { |
35 addTypeConverter(Boolean.class, new BooleanConverter()); |
35 addTypeConverter(Boolean.class, new BooleanConverter()); |
36 addTypeConverter(NativeSizeT.class, new SizeTConverter()); |
36 addTypeConverter(NativeSizeT.class, new SizeTConverter()); |
37 } |
37 } |
38 |
38 |
39 private static final class BooleanConverter implements TypeConverter { |
39 private static final class BooleanConverter implements TypeConverter { |
40 public Class<Byte> nativeType() { |
40 public Class<Byte> nativeType() { |
41 return Byte.class; |
41 return Byte.class; |
42 } |
42 } |
43 public Object fromNative(Object value, FromNativeContext context) { |
43 public Object fromNative(Object value, FromNativeContext context) { |
44 return ((Byte)value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE; |
44 return ((Byte)value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE; |
45 } |
45 } |
46 public Object toNative(Object value, ToNativeContext context) { |
46 public Object toNative(Object value, ToNativeContext context) { |
47 return Byte.valueOf((byte)(Boolean.TRUE.equals(value) ? 1 : 0)); |
47 return Byte.valueOf((byte)(Boolean.TRUE.equals(value) ? 1 : 0)); |
48 } |
48 } |
49 } |
49 } |
50 |
50 |
51 private static final class SizeTConverter implements TypeConverter { |
51 private static final class SizeTConverter implements TypeConverter { |
52 public Class<Integer> nativeType() { |
52 public Class<Integer> nativeType() { |
53 return Integer.class; |
53 return Integer.class; |
54 } |
54 } |
55 public Object fromNative(Object value, FromNativeContext context) { |
55 public Object fromNative(Object value, FromNativeContext context) { |
56 return NativeSizeT.valueOf((Integer)value); |
56 return NativeSizeT.valueOf((Integer)value); |
57 } |
57 } |
58 public Object toNative(Object value, ToNativeContext context) { |
58 public Object toNative(Object value, ToNativeContext context) { |
59 return Integer.valueOf(value==null ? 0 : ((NativeSizeT)value).intValue()); |
59 return Integer.valueOf(value==null ? 0 : ((NativeSizeT)value).intValue()); |
60 } |
60 } |
61 } |
61 } |
62 } |
62 } |
63 |
63 |