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

*** empty log message ***
author kono
date Mon, 18 Aug 2008 07:28:29 +0900
parents
children 2cbd98257d61
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
1
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
2 /*
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
3 * @(#)PSXQueueInterface.java 1.1 06/04/01
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
4 *
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
5 * Copyright 2006 Shinji KONO
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
6 *
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
7
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
8 PSX Lidna
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
9 Trasport layer of PSX Linda library
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
10
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
11 */
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
12
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
13 package fdl;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
14
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
15 import java.nio.ByteBuffer;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
16 import java.nio.ByteOrder;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
17
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
18
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
19
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
20 /**
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
21 PSXQueueInterface
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
22
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
23 */
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
24
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
25 public class PSX {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
26 static final int PSX_IN = 'i';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
27 static final int PSX_OUT = 'o';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
28 static final int PSX_UPDATE = 'u';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
29 static final int PSX_RD = 'r';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
30 static final int PSX_CHECK = 'c';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
31 static final int PSX_REPLY = '?';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
32 static final int PSX_WAIT_RD = 'w';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
33 static final int PSX_ANSWER = 'a';
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
34 static final int PSX_HTTP_ANSWER = 'P'; // Put
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
35 static final int PSX_HTTP_REQUEST = 'G'; // Get
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
36 static final int PSX_COM_DEBUG = 'D'; //Communication DEBUG
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
37
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
38 static final int LINDA_PACKET_LENGTH_OFFSET =0;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
39 static final int LINDA_MODE_OFFSET =0+4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
40 static final int LINDA_ID_OFFSET =1+4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
41 static final int LINDA_SEQ_OFFSET =3+4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
42 static final int LINDA_DATA_LENGTH_OFFSET =7+4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
43 static final int LINDA_HEADER_SIZE =12+4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
44 static final int INT_SIZE =4;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
45 static final int SHORT_SIZE =2;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
46
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
47 static final int PRIVILEGED_ID_START = 32768;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
48 static final int PRIVILEGED_ID_END = 36864;
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
49
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
50 // this method should be removed
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
51 static void setReportCommand(ByteBuffer command, String report_txt) {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
52 command.order(ByteOrder.BIG_ENDIAN);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
53 command.putInt(LINDA_PACKET_LENGTH_OFFSET,(report_txt).length()*2+LINDA_HEADER_SIZE-INT_SIZE);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
54 command.put(LINDA_MODE_OFFSET,(byte)'D');
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
55 command.putShort(LINDA_ID_OFFSET,(short) 0);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
56 command.putInt(LINDA_SEQ_OFFSET,0);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
57 command.putInt(LINDA_DATA_LENGTH_OFFSET,(report_txt).length()*2);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
58 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
59 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
60
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
61 static void printCommand(ByteBuffer command, ByteBuffer data) {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
62 char id = (char)command.getShort(LINDA_ID_OFFSET);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
63 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
64 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
65 "ID:"+(int)id+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
66 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
67 "DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" ");
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
68 System.out.println("DATA:"+data);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
69 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
70 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
71
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
72 static void printData(ByteBuffer command) {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
73 /*** print data ***/
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
74 char id = (char)command.getShort(LINDA_ID_OFFSET);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
75 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
76 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
77 "ID:"+(int)id+" "+
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
78 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" ");
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
79 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
80 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
81
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
82
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
83 static void setCommand(ByteBuffer command, int _mode, int _id, int _seq, int _datalen) {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
84 command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
85 command.order(ByteOrder.BIG_ENDIAN);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
86
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
87 command.putInt(LINDA_PACKET_LENGTH_OFFSET,
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
88 _datalen+LINDA_HEADER_SIZE-INT_SIZE);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
89 command.put(LINDA_MODE_OFFSET,(byte)_mode);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
90 command.putShort(LINDA_ID_OFFSET,(short)_id);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
91 command.putInt(LINDA_SEQ_OFFSET,_seq);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
92 command.putInt(LINDA_DATA_LENGTH_OFFSET,_datalen);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
93 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
94 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
95
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
96 static void setAnserCommand(ByteBuffer command, int seq) {
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
97 command.put(LINDA_MODE_OFFSET, (byte)'a');
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
98 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
99 command.putInt(LINDA_SEQ_OFFSET, seq);
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
100 command.rewind();
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
101 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
102
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
103
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
104 }
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
105
609b288f47f9 *** empty log message ***
kono
parents:
diff changeset
106 /* end */