Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.cldc.jna
Class DynamicStructure

    java.lang.Object
      com.sun.cldc.jna.Structure
          com.sun.cldc.jna.DynamicStructure

Direct Known Subclasses:
  SocketImpl.sockaddr_inImpl, SocketImpl.sockaddr_inImpl

    public abstract class DynamicStructure

extends Structure

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

### DEBUG

    public static final boolean DEBUG

See Also:
  Constant Field Values

### STRUCTURE_SIZE_INDEX

    public static final int STRUCTURE_SIZE_INDEX

  The first element of the layout structure in Java is the size of the C structure in bytes

  See Also:
    Constant Field Values

Constructor Detail

### DynamicStructure

    public DynamicStructure()

Method Detail

### initLayout

    protected static int[] initLayout(Class c,
                                      int numFields)

  Read the C layout structure into a Java array. This is typically called by a subclass an stored in a static.

  Parameters:
    `c` - the class
  Returns:
    a array of ints of length numFields + 1 containing the layout information
  Throws:
    `IllegalStateException` - if the C structure has less than numFields items

### getLayout

    public abstract int[] getLayout()

  Return the structure layout used by this class. Typical implementations return a static variable that has been initialized with initLayout.

  Returns:
    the layout

### size

    public int size()

  Return the size of this structure. The size is the first element of the layout array.

  Specified by:
    `size` in class `Structure`
  Returns:
    the size of the native C structure in bytes

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"