-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc_client.py
132 lines (106 loc) · 5.04 KB
/
rpc_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import xmlrpclib
from worldstate import WorldState
import pickle
from threading import Thread
class French75Client():
def __init__(self, ip, port):
print "Starting client to connect on port", port
#WorldState.Instance() = WorldState.Instance()
self.server = xmlrpclib.ServerProxy('http://' + ip + ':' + str(port))
def perform_actions(self):
pass
def list_actions(self):
print self.server.system.listMethods()
def start_partner_client(self, ip):
self.server.start_client(ip)
def test(self):
WorldState.Instance().lamport_clock += 1
self.server.test(WorldState.Instance().lamport_clock)
def request_session(self):
"""
works
"""
data = self.server.get_session_dict()
WorldState.Instance().unpickle_session(data)
WorldState.Instance().push_state()
return True
def add_annotation(self, annotation):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps(annotation),), kwargs={'name':self.server.add_annotation})
thread.start()
#if new_clock is not None:
# WorldState.Instance().lamport_clock = new_clock
def update_annotation(self, a_id, text):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps(a_id), pickle.dumps(text),), kwargs={'name':self.server.update_annotation})
thread.start()
def launch_large_plot(self):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(), kwargs={'name':self.server.launch_large_plot})
thread.start()
def close_large_plot(self):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(), kwargs={'name':self.server.close_large_plot})
thread.start()
def update_legend(self, line, file_key, species_key):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps((line, file_key, species_key)),), kwargs={'name':self.server.update_legend})
thread.start()
def reset_session(self):
thread = Thread(target=self.non_blocking, args=(), kwargs={'name':self.server.reset_session})
thread.start()
def undo(self):
thread = Thread(target=self.non_blocking, args=(), kwargs={'name':self.server.undo})
thread.start()
def redo(self):
thread = Thread(target=self.non_blocking, args=(), kwargs={'name':self.server.redo})
thread.start()
def delete_anime_annotation(self, a_id):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, a_id,), kwargs={'name':self.server.delete_anime_annotation})
thread.start()
def add_anime_annotation(self, (key, annotation)):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps((key, annotation)),), kwargs={'name':self.server.add_anime_annotation})
thread.start()
#self.server.add_anime_annotation(WorldState.Instance().lamport_clock, pickle.dumps((key, annotation)))
def non_blocking(self, *args, **kwargs):
"""
Every thread call comes here. It is passed the server method to call
and the arguments to that function
"""
new_clock = kwargs['name'](*args)
if new_clock is not None:
WorldState.Instance().lamport_clock = new_clock
def delete_annotation(self, a_id):
"""
works
"""
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps(a_id),), kwargs={'name':self.server.delete_annotation})
thread.start()
def toggle_param(self, param, value):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, param, value,), kwargs={'name':self.server.toggle_param})
thread.start()
def play_animation(self):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock,), kwargs={'name':self.server.play_animation})
thread.start()
def set_clock(self):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, pickle.dumps(WorldState.Instance().session_dict['clock']),), kwargs={'name':self.server.set_clock})
thread.start()
def switch_animation(self, n):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, n,), kwargs={'name':self.server.switch_animation})
thread.start()
def change_animation_species(self, n):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, n,), kwargs={'name':self.server.change_animation_species})
thread.start()
def change_animation_file(self, n):
thread = Thread(target=self.non_blocking, args=(WorldState.Instance().lamport_clock, n,), kwargs={'name':self.server.change_animation_file})
thread.start()