forked from RoboCupAtHome/vizbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backendbase.py
84 lines (66 loc) · 2.16 KB
/
backendbase.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
def call_callbacks_in(cb_list, converter):
def callback(message):
converted = converter(message)
for cb in cb_list:
cb(converted)
return callback
class BackendBase(object):
@staticmethod
def get_instance():
raise NotImplementedError()
def __init__(self):
self.on_operator_text = []
self.on_robot_text = []
self.on_challenge_step = []
self.on_image = []
self.on_story = []
self._title = "Challenge"
self._storyline = ["Enter", "Do stuff", "Exit"]
@property
def title(self):
return self._title
@property
def storyline(self):
return self._storyline
def attach_operator_text(self, callback):
self.on_operator_text += [callback]
def attach_robot_text(self, callback):
self.on_robot_text += [callback]
def attach_challenge_step(self, callback):
self.on_challenge_step += [callback]
def detach_operator_text(self, callback):
self.on_operator_text.remove(callback)
def detach_robot_text(self, callback):
self.on_robot_text.remove(callback)
def detach_challenge_step(self, callback):
self.on_challenge_step.remove(callback)
def accept_command(self, command_text):
raise NotImplementedError()
def attach_image(self, callback):
"""
Add a callback for when an Image is received
:param callback: function accepting a base64-encoded image
:return:
"""
self.on_image += [callback]
def detach_image(self, callback):
"""
Remove a callback from when an Image is received
:param callback:
:return:
"""
self.on_image.remove(callback)
def attach_story(self, callback):
"""
Add a callback for when a Story is received
:param callback: function accepting a tuple of (title: str, storyline: [str])
:return:
"""
self.on_story += [callback]
def detach_story(self, callback):
"""
Remove a callback from when a Story is received
:param callback:
:return:
"""
self.on_story.remove(callback)