8
|
1 import psxlinda
|
|
2
|
|
3 class FederatedLinda:
|
|
4 def __init__(self):
|
|
5 self.tuplespaces = []
|
|
6
|
|
7 def open(self, hostname, port):
|
|
8 tsid = psxlinda.open(hostname, port)
|
|
9 if (tsid == -1):
|
|
10 return None
|
|
11
|
|
12 linda = Linda(tsid)
|
|
13 # self.tuplespaces.append(linda)
|
|
14
|
|
15 return linda
|
|
16
|
|
17 def sync(self):
|
|
18 psxlinda.sync()
|
|
19
|
|
20
|
|
21 # Reply from TupleSpace
|
|
22
|
|
23 class Reply:
|
|
24 def __init__(self, seq):
|
|
25 self.seq = seq
|
|
26
|
|
27 def reply(self):
|
|
28 return psxlinda.reply(self.seq)
|
|
29
|
|
30
|
|
31 # Linda class
|
|
32 TUPLE_ID_COUNT_CLIENT = 65535
|
|
33
|
|
34 class Linda:
|
|
35 def __init__(self, tsid):
|
|
36 self.tsid = tsid
|
|
37
|
|
38 def In(self, tid):
|
|
39 seq = psxlinda.In(self.tsid, tid)
|
|
40 return Reply(seq)
|
|
41
|
|
42 def Rd(self, tid):
|
|
43 seq = psxlinda.Rd(self.tsid, tid)
|
|
44 return Reply(seq)
|
|
45
|
|
46 def Ck(self, tid):
|
|
47 seq = psxlinda.Ck(self.tsid, tid)
|
|
48 return Reply(seq)
|
|
49
|
|
50 def WaitRd(self, tid):
|
|
51 seq = psxlinda.WaitRd(self.tsid, tid)
|
|
52 return Reply(seq)
|
|
53
|
|
54 def Out(self, tid, data):
|
|
55 psxlinda.Out(self.tsid, tid, data)
|
|
56
|
|
57 def close(self):
|
|
58 psxlinda.close(self.tsid)
|
|
59 self.tsid = None
|
|
60
|
|
61 def getid(self):
|
|
62 rep = self.In(TUPLE_ID_COUNT_CLIENT)
|
|
63 ret = None
|
|
64 while (not ret):
|
|
65 psxlinda.sync()
|
|
66 ret = rep.reply()
|
|
67 return ret
|
|
68
|
|
69 def __del__(self):
|
|
70 if self.tsid:
|
|
71 self.close()
|
|
72
|