package nxm.sys.inc;

/**
 *  Holds RMIF constants and static methods
 *  (Note: this could eventually be expanded to allow users to substitute their on RMIF implementations)
 *  @author Jeanette McCall
 *  @since NeXtMidas 3.9.2 to break lib dependency on net, which has libg dependencies
 */
public interface RmifInterface {

  /** Packet message functions (see nxm.sys.net.Rmif for details). */
  public static final byte
        SET=101,     GET=102,           // for results/message/parameter access
        RET=103,     ACK=104,           // for results/message/parameter access
        OPEN=105,    CLOSE=106,         // open/close channel
        SEND=107,    RECV=108,          // message access
        PING=109,    PONG=110,          // keep alive checks
        DHDR=111,    DBUF=112,          // file data access
        ADDR=113,    MODIFY=114,        // address, modify
        OPENED=115,  CLOSED=116,        // response to OPEN,CLOSE
        DBUFC=117,   DBUFD=118,         // file data buffer, Compressed Direct
        DBUFZ=119,   DBUFX=120,         // file data buffer, Zipped eXtended
        GETPROP=121, RETPROP=122,       // published keyname access
        RECEIPT=123, LINKTEST=124,      // low-level RDP hooks
        MFTP=125,                       // Midas File Transfer Protocol command
        DROPPED=0;                      // dropped remote state

  /** Array of strings for the different function types (see nxm.sys.net.Rmif for details). */
  public static String[] functionList = {
    "SET", "GET", "RET", "ACK", "OPEN", "CLOSE",
    "SEND", "RECV", "PING", "PONG", "DHDR", "DBUF",
    "ADDR", "MODIFY", "OPENED", "CLOSED", "DBUFC", "DBUFD",
    "<UNSPECIFIED>", "<UNSPECIFIED>",
    "GETPROP", "RETPROP", "RECEIPT", "LINKTEST", "MFTP"
  };

  /** The index of the lowest numbered function.  */
  public static final int MINFUNCTION = 101;
  /** The index of the highest numbered function.  */
  public static final int MAXFUNCTION = MINFUNCTION + functionList.length - 1;

  /** Packet header byte offsets (see nxm.sys.net.Rmif for details). */
  public static final byte FUNC=0, FLAG=1, INFO=2, REP=3, SEQ=4, TRY=5, RPT=6, ADJ=7, DATA=8;

  /** Packet transport layer reliability modes (see nxm.sys.net.Rmif for details). */
  public static final byte RDP=0, UDP=1, TCP=2, IDP=3;
  /** List of packet transport protocols (starts at 0, not 1) */
  public static final String protocolList = "RDP,UDP,TCP,IDP";

  /** Data type indicator (see nxm.sys.net.Rmif for details). */
  public static final byte TYPE_RAW=0, TYPE_BINARY=1, TYPE_XML=2, TYPE_ASCII=3;

  /** Adjunct header type flag (see nxm.sys.net.Rmif for details). */
  public static final byte ADJ_TIME=0x10, ADJ_OFFSET=0x20, ADJ_USER=(byte)0x80;

  /** property types (see {@link #typeList}) */
  public static final byte PIPE=1, RESULT=2, KEY=3, MESSAGE=4, FILE=5;
  /** Property types: <code>{@value}</code> */
  public static final String typeList = "Pipe,Result,Key,Message,File";

  /** packet DBUF compression modes */
  public static final byte DC_RAW=91, DC_BAND=92, DC_CONST=93, DC_PACK=94;

  /** Converts from function ID to name (see {@link #functionList}).
   *  @param func function ID
   *  @return function name
   */
  public static String functionName (byte func) {
    if (func<MINFUNCTION || func>MAXFUNCTION) {
      return (func == DROPPED)? "Dropped" : "Unknown";
    }
    return functionList[func-MINFUNCTION];
  }

}
