CORE JDK

From ICE Enterprises
Jump to navigation Jump to search

The Core class in nxm.ice.lib provides the standard framework for developing a Java callable Core. The wrappers for each hardware implementation are auto-generated by the inner class definitions in the Java reference class.

Example

Here is an example Java reference implementation of the noop function contained in the file Noop.java:

The three declarations for the CPU, VHS, and ICE classes are all that is needed to have NeXtMidas build the Native code and/or code wrappers for those implementations as well.

 package nxm.ice.core;
 
 import nxm.ice.lib.*;
 import nxm.sys.lib.Data;
 import nxm.sys.lib.Convert;
 
 /**
   Implements data copy with optional decimation and reformat.
 */
 public class Noop extends CoreFactory {
 
  // native implementation wrappers
  public static class CPU extends CoreNative { public native long alloc(); }
  public static class VHS extends CoreNative { public native long alloc(); }
  public static class ICE extends CoreNative { public native long alloc(); }
 
  // java implementation
  public static class JVM extends Core {
 
   private int dec,ioff,ibps,obps;
 
   /** set parameters */
   public void set (String key, Data value) {
     if (key.equals("DECIMATION")) dec  = value.toL();
     else super.set(key,value);
   }
 
   /** get parameters */
   public Data get (String key, byte type) {
     if (key.equals("DECIMATION"))  return new Data(dec);
     else return super.get(key,type);
   }
 
   /** Ready this engine with current parameters */
   public int open() {
     ioff = 0;
     ibps = getFormatBytes(1);
     obps = getFormatBytes(2);
     return 0;  /** process a buffer of data */
   }
 
   public int process (byte[] a, int na, byte[] b, int nb) {
     int n=0,i=ioff,n1=na/ibps;
     if (ibps==1) {
       for (; i<n1; i+=dec) b[n++]=a[i];
     }
     else if (ibps==2) {
       short[] ai = Convert.castI(a,true);
       short[] bi = Convert.castI(b,false);
       for (; i<n1; i+=dec) bi[n++]=ai[i];
       Convert.uncast(ai,a,false);
       Convert.uncast(bi,b,true);
     }
     else if (ibps==4) {
       int[] ai = Convert.castL(a,true);
       int[] bi = Convert.castL(b,false);
       for (; i<n1; i+=dec) bi[n++]=ai[i];
       Convert.uncast(ai,a,false);
       Convert.uncast(bi,b,true);
     }
     ioff = i%n1;
     return n*obps;
   }
 
  }
 }