diff src/fdl/PSX.java @ 17:609b288f47f9

*** empty log message ***
author kono
date Mon, 18 Aug 2008 07:28:29 +0900
parents
children 2cbd98257d61
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/PSX.java	Mon Aug 18 07:28:29 2008 +0900
@@ -0,0 +1,106 @@
+
+/*
+ * @(#)PSXQueueInterface.java       1.1 06/04/01
+ *
+ * Copyright 2006  Shinji KONO
+ * 
+
+   PSX Lidna
+     Trasport layer of PSX Linda library
+
+ */
+
+package fdl;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+
+
+/**
+  PSXQueueInterface 
+
+ */
+
+public class PSX {
+    static final int PSX_IN =		'i';
+    static final int PSX_OUT =		'o';
+    static final int PSX_UPDATE =	'u';
+    static final int PSX_RD =		'r';
+    static final int PSX_CHECK =	'c';
+    static final int PSX_REPLY =	'?';
+    static final int PSX_WAIT_RD =	'w';
+    static final int PSX_ANSWER =	'a';
+    static final int PSX_HTTP_ANSWER =	'P';   // Put
+    static final int PSX_HTTP_REQUEST =	'G';  // Get
+    static final int PSX_COM_DEBUG = 'D';  //Communication DEBUG
+    
+    static final int LINDA_PACKET_LENGTH_OFFSET	=0;
+    static final int LINDA_MODE_OFFSET          =0+4;
+    static final int LINDA_ID_OFFSET            =1+4;
+    static final int LINDA_SEQ_OFFSET           =3+4;
+    static final int LINDA_DATA_LENGTH_OFFSET   =7+4;
+    static final int LINDA_HEADER_SIZE          =12+4;
+    static final int INT_SIZE          =4;
+    static final int SHORT_SIZE          =2;
+    
+    static final int PRIVILEGED_ID_START   = 32768;
+    static final int PRIVILEGED_ID_END   = 36864;
+    
+    // this method should be removed
+	static void setReportCommand(ByteBuffer command, String report_txt) {
+		command.order(ByteOrder.BIG_ENDIAN);
+		command.putInt(LINDA_PACKET_LENGTH_OFFSET,(report_txt).length()*2+LINDA_HEADER_SIZE-INT_SIZE);
+		command.put(LINDA_MODE_OFFSET,(byte)'D');
+		command.putShort(LINDA_ID_OFFSET,(short) 0);
+		command.putInt(LINDA_SEQ_OFFSET,0);
+		command.putInt(LINDA_DATA_LENGTH_OFFSET,(report_txt).length()*2);
+		command.rewind();
+	}
+	
+	static void printCommand(ByteBuffer command, ByteBuffer data) {
+		char id = (char)command.getShort(LINDA_ID_OFFSET);
+		System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
+				"MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
+				"ID:"+(int)id+" "+
+				"SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+
+				"DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" ");
+		System.out.println("DATA:"+data);
+		command.rewind();
+	}
+	
+	static void printData(ByteBuffer command) {
+		/*** print data ***/
+		char id = (char)command.getShort(LINDA_ID_OFFSET);
+		System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
+				"MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
+				"ID:"+(int)id+" "+
+				"SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" ");
+		command.rewind();
+	}
+	
+	
+	static void setCommand(ByteBuffer command, int _mode, int _id, int _seq, int _datalen) {
+		command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
+		command.order(ByteOrder.BIG_ENDIAN);
+	
+		command.putInt(LINDA_PACKET_LENGTH_OFFSET,
+					_datalen+LINDA_HEADER_SIZE-INT_SIZE);
+		command.put(LINDA_MODE_OFFSET,(byte)_mode);
+		command.putShort(LINDA_ID_OFFSET,(short)_id);
+		command.putInt(LINDA_SEQ_OFFSET,_seq);
+		command.putInt(LINDA_DATA_LENGTH_OFFSET,_datalen);
+		command.rewind();
+	}
+
+	static void setAnserCommand(ByteBuffer command, int seq) {
+		command.put(LINDA_MODE_OFFSET, (byte)'a');
+		command.rewind();
+		command.putInt(LINDA_SEQ_OFFSET, seq);
+		command.rewind();
+	}
+    
+
+}
+
+/* end */