|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.cldc.jna.Structure
com.sun.cldc.jna.DynamicStructure
public abstract class DynamicStructure
A DynamicStructure is a structure with support for getting the field offsets for a particular platform from native code. A native data "layout" structure must be defined that contains the offsets. By convention, the name of the data structure is CLASSNAME+"_layout", where CLASSNAME is equal to class.getName().replace('.', '_').replace('$', '_'); The C layout structure is an array of 4-byte words. The first element is the length total of this layout structure itself in words. The second element is the size of the structure being described in bytes. The remaining elements are the offsets of the fields of interest to the java code. The order isn't important, but it's typically in the order that the fields are defined in the C and java structures. The Java format of the layout is an int array. It's like the C layout, but without first "layout length" field. The first element of the Java is the size of the C structure in bytes. Example: IN C: #define com_sun_squawk_platform_posix_callouts_Libc_Stat_layout_LEN 5 const int com_sun_squawk_platform_posix_callouts_Libc_Stat_layout[com_sun_squawk_platform_posix_callouts_Libc_Stat_layout_LEN] = { com_sun_squawk_platform_posix_callouts_Libc_Stat_layout_LEN, sizeof(struct stat), offsetof(struct stat, st_mode), offsetof(struct stat, st_mtime), offsetof(struct stat, st_size) } IN JAVA: package com.sun.squawk.platform.posix.callouts; class LibC { static class Stat extends DynamicStructure { final static int ST_MODE_INDEX = 1; final static int ST_MTIME_INDEX = 2; final static int ST_SIZE_INDEX = 3; final static int[] layout = DynamicStructure.initLayout(Stat.class, 3); public int[] getLayout() { return layout; } public void read() { Pointer p = getPointer(); st_mode = p.getShort(layout[ST_MODE_INDEX]) & 65535; st_mtime = p.getInt(layout[ST_MTIME_INDEX]); st_size = p.getLong(layout[ST_SIZE_INDEX]); } .... } .... }
Field Summary | |
---|---|
static boolean |
DEBUG
|
static int |
STRUCTURE_SIZE_INDEX
The first element of the layout structure in Java is the size of the C structure in bytes |
Fields inherited from class com.sun.cldc.jna.Structure |
---|
backingNativeMemory, NULL |
Constructor Summary | |
---|---|
DynamicStructure()
|
Method Summary | |
---|---|
abstract int[] |
getLayout()
Return the structure layout used by this class. |
protected static int[] |
initLayout(Class c,
int numFields)
Read the C layout structure into a Java array. |
int |
size()
Return the size of this structure. |
Methods inherited from class com.sun.cldc.jna.Structure |
---|
allocateMemory, allocateMemory, clear, freeMemory, getPointer, read, release, toString, useMemory, write |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final boolean DEBUG
public static final int STRUCTURE_SIZE_INDEX
Constructor Detail |
---|
public DynamicStructure()
Method Detail |
---|
protected static int[] initLayout(Class c, int numFields)
c
- the class
IllegalStateException
- if the C structure has less than numFields itemspublic abstract int[] getLayout()
public int size()
size
in class Structure
|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |