forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
cpscript0.py
1 """
2 cpscript TYP name count1 type name ... count2 type name
3 """
4 
5 import sys
6 from socket import *
7 
8 cmdType = sys.argv[1]
9 cmdName = sys.argv[2]
10 count1 = int(sys.argv[3])
11 i = 4; j = 0
12 reqType = [""] * 100
13 reqName = [""] * 100
14 reqDesc = [""] * 100
15 while (j < count1) :
16  reqType[j] = sys.argv[i];
17  reqName[j] = sys.argv[i+1];
18  reqDesc[j] = sys.argv[i+2];
19  i += 3; j += 1;
20 count2 = int(sys.argv[i])
21 i += 1; j = 0;
22 repType = [""] * 100
23 repName = [""] * 100
24 repDesc = [""] * 100
25 while (j < count2) :
26  repType[j] = sys.argv[i];
27  repName[j] = sys.argv[i+1];
28  repDesc[j] = sys.argv[i+2];
29  i += 3; j += 1;
30 
31 sys.stdout.write("/** Format a " + cmdType + " control packet (request).\n");
32 for i in range(count1) :
33  sys.stdout.write(" * @param " + reqName[i] + " " + reqDesc[i] + "\n")
34 sys.stdout.write(" * @param snum is the sequence number for the "
35  + "control packet\n")
36 sys.stdout.write(" */\n")
37 sys.stdout.write("void CtlPkt::fmt" + cmdName + "(")
38 for i in range(count1) :
39  if i != 0 : sys.stdout.write(", ")
40  sys.stdout.write(reqType[i] + " " + reqName[i])
41 sys.stdout.write(", int64_t snum) {\n")
42 sys.stdout.write("\ttype = " + cmdType + "; mode = REQUEST; seqNum = snum;\n")
43 sys.stdout.write("\tsetup();\n\t")
44 for i in range(count1) :
45  sys.stdout.write("put(" + reqName[i] + "); ")
46 if (count1 > 0) : sys.stdout.write("\n\t")
47 sys.stdout.write("paylen = next - payload;\n}\n\n")
48 
49 sys.stdout.write("/** Extract a " + cmdType + " control packet (request).\n");
50 for i in range(count1) :
51  sys.stdout.write(" * @param " + reqName[i] + " " + reqDesc[i] + "\n")
52 sys.stdout.write(" * @return true if the extracted packet passes"
53  + " basic checks\n")
54 sys.stdout.write(" */\n")
55 sys.stdout.write("bool CtlPkt::xtr" + cmdName + "(")
56 for i in range(count1) :
57  if i != 0 : sys.stdout.write(", ")
58  sys.stdout.write(reqType[i] + "& " + reqName[i])
59 sys.stdout.write(") {\n\treturn\ttype == " + cmdType
60  + " && mode == REQUEST\n\t\t");
61 for i in range(count1) :
62  sys.stdout.write("&& get(" + reqName[i] + ") ")
63 if (count1 > 0) : sys.stdout.write("\n\t\t")
64 sys.stdout.write("&& paylen >= (next - payload);\n}\n\n");
65 
66 sys.stdout.write("/** Format a " + cmdType + " control packet reply.\n");
67 for i in range(count2) :
68  sys.stdout.write(" * @param " + repName[i] + " " + repDesc[i] + "\n")
69 sys.stdout.write(" * @param snum is the sequence number for the "
70  + "reply (optional)\n")
71 sys.stdout.write(" */\n")
72 sys.stdout.write("void CtlPkt::fmt" + cmdName + "Reply(")
73 for i in range(count2) :
74  if i != 0 : sys.stdout.write(", ")
75  sys.stdout.write(repType[i] + " " + repName[i])
76 if count2 > 0 : sys.stdout.write(", ")
77 sys.stdout.write("int64_t snum) {\n")
78 sys.stdout.write("\ttype = " + cmdType + "; mode = POS_REPLY; "
79  + "\n\tif (snum != 0) seqNum = snum;\n")
80 sys.stdout.write("\tsetup();\n\t")
81 for i in range(count2) :
82  sys.stdout.write("put(" + repName[i] + "); ")
83 if (count2 > 0) : sys.stdout.write("\n\t")
84 sys.stdout.write("paylen = next - payload;\n}\n\n")
85 
86 sys.stdout.write("/** Extract a " + cmdType + " control packet reply.\n");
87 for i in range(count2) :
88  sys.stdout.write(" * @param " + repName[i] + " " + repDesc[i] + "\n")
89 sys.stdout.write(" * @return true if the extracted packet passes"
90  + " basic checks\n")
91 sys.stdout.write(" */\n")
92 sys.stdout.write("bool CtlPkt::xtr" + cmdName + "Reply(")
93 for i in range(count2) :
94  if i != 0 : sys.stdout.write(", ")
95  sys.stdout.write(repType[i] + "& " + repName[i])
96 sys.stdout.write(") {\n\treturn\ttype == " + cmdType
97  + " && mode == REQUEST\n\t\t");
98 for i in range(count2) :
99  sys.stdout.write("&& get(" + repName[i] + ") ")
100 if (count2 > 0) : sys.stdout.write("\n\t\t")
101 sys.stdout.write("&& paylen >= (next - payload);\n}\n\n");