13 import rocon_gateway_utils
16 from .
import interactive_interface
26 The pulled interface is the set of rules 27 (pubs/subs/services/actions) and rules controlling pulls from 31 def __init__(self, default_rule_blacklist, default_rules, all_targets):
33 Initialises the pulled interface. 35 @param default_rule_blacklist : used when in flip all mode 36 @type dictionary of gateway 37 @param default_rules : static rules to pull on startup 38 @type gateway_msgs.msg.RemoteRule[] 39 @param all_targets : static pull all targets to pull to on startup 42 interactive_interface.InteractiveInterface.__init__(self, default_rule_blacklist, default_rules, all_targets)
49 def update(self, remote_connections, unique_name):
51 Computes a new pulled interface from the incoming connections list 52 and returns two dictionaries - 53 removed and newly added pulls so the watcher thread can take 54 appropriate action ((un)registrations). 56 This is run in the watcher thread (warning: take care - other 57 additions come from ros service calls in different threads!) 59 @param remote_gateway_hub_index : full gateway-hub database index to parse 60 @type gateway hash names keyed into a dic with a list of their hubs 64 pulled = utils.create_empty_connection_type_dictionary()
65 new_pulls = utils.create_empty_connection_type_dictionary()
66 removed_pulls = utils.create_empty_connection_type_dictionary()
70 for remote_gateway
in remote_connections.keys():
71 connections = remote_connections[remote_gateway]
72 for connection_type
in connections:
73 for connection
in connections[connection_type]:
74 pulled[connection_type].extend(
81 for connection_type
in utils.connection_types:
82 new_pulls[connection_type] = utils.difflist(pulled[connection_type], self.
pulled[connection_type])
83 removed_pulls[connection_type] = utils.difflist(self.
pulled[connection_type], pulled[connection_type])
84 self.
pulled = copy.deepcopy(pulled)
86 return new_pulls, removed_pulls
112 Checks if a local rule (obtained from master.get_system_state) 113 is a suitable association with any of the rules or patterns. This can 114 return multiple matches, since the same local rule 115 properties can be multiply pulled to different remote gateways. 117 Used in the update() call above that is run in the watcher thread. 119 Note, don't need to lock here as the update() function takes care of it. 121 @param connection_type : rule type 122 @type str : string constant from gateway_msgs.Rule 124 @param name : fully qualified topic, service or action name 127 @param node : ros node name (coming from master.get_system_state) 130 @param gateway : remote gateway hash name. 133 @return all the pull rules that match this local rule 134 @return list of RemoteRule objects updated with node names from self.watchlist 136 matched_pull_rules = []
137 for rule
in self.
watchlist[connection_type]:
139 gateway_match_result = re.match(rule.gateway, gateway)
141 if gateway_match_result
and gateway_match_result.group() == gateway:
143 elif rule.gateway == rocon_gateway_utils.gateway_basename(gateway):
149 rule_name = rule.rule.name
150 matched = self.
is_matched(rule, rule_name, name, node)
152 rule_name =
'/' + unique_name +
'/' + rule.rule.name
153 matched = self.
is_matched(rule, rule_name, name, node)
156 rule_name =
'/' + rule.rule.name
157 matched = self.
is_matched(rule, rule_name, name, node)
160 matched_pull = copy.deepcopy(rule)
161 matched_pull.gateway = gateway
162 matched_pull.rule.name = name
163 matched_pull.rule.node = node
164 matched_pull_rules.append(matched_pull)
165 return matched_pull_rules
173 Collects all gateways that it should watch for (i.e. those 174 currently handled by existing registrations). 176 @return set of gateway string ids 180 for connection_type
in utils.connection_types:
182 if registration.remote_gateway
not in gateways:
183 gateways.append(registration.remote_gateway)
def is_matched(self, rule, rule_name, name, node)
Accessors for Gateway Info.
def list_remote_gateway_names(self)
Pulled Interface Specific Methods.
def add_all(self, gateway, blacklist)
def __init__(self, default_rule_blacklist, default_rules, all_targets)
def remove_all(self, gateway)
def update(self, remote_connections, unique_name)
def _generate_pulls(self, connection_type, name, node, gateway, unique_name)
Utility Methods.