def generate_advertisement_connection_details(self, connection_type, name, node): ''' Creates all the extra details to create a connection object from an advertisement rule. This is a bit different to the previous one - we just need the type and single node uri that everything originates from (don't need to generate all the pub/sub connections themselves. Probably flips could be merged into this sometime, but it'd be a bit gnarly. @param connection_type : the connection type (one of gateway_msgs.msg.ConnectionType) @type string @param name : the name of the connection @type string @param node : the master node name it comes from @param string @return the utils.Connection object complete with type_info and xmlrpc_uri @type utils.Connection ''' xmlrpc_uri = self.lookupNode(node) if connection_type == PUBLISHER or connection_type == SUBSCRIBER: type_info = rostopic.get_topic_type(name)[0] # message type connection = utils.Connection(Rule(connection_type, name, node), type_info, xmlrpc_uri) elif connection_type == SERVICE: type_info = rosservice.get_service_uri(name) connection = utils.Connection(Rule(connection_type, name, node), type_info, xmlrpc_uri) elif connection_type == ACTION_SERVER or connection_type == ACTION_CLIENT: goal_topic = name + '/goal' goal_topic_type = rostopic.get_topic_type(goal_topic) type_info = re.sub('ActionGoal$', '', goal_topic_type[0]) # Base type for action connection = utils.Connection(Rule(connection_type, name, node), type_info, xmlrpc_uri) return connection
def _get_connections_from_service_list(self, connection_list, connection_type): connections = [] for service in connection_list: service_name = service[0] #service_uri = rosservice.get_service_uri(service_name) nodes = service[1] for node in nodes: #try: # node_uri = self.lookupNode(node) #except: # continue rule = Rule(connection_type, service_name, node) connection = utils.Connection(rule, None, None) # service_uri, node_uri connections.append(connection) return connections
def _get_connections_from_pub_sub_list(self, connection_list, connection_type): connections = [] for topic in connection_list: topic_name = topic[0] #topic_type = rostopic.get_topic_type(topic_name) #topic_type = topic_type[0] nodes = topic[1] for node in nodes: #try: #node_uri = self.lookupNode(node) #except: # continue rule = Rule(connection_type, topic_name, node) connection = utils.Connection(rule, None, None) # topic_type, node_uri connections.append(connection) return connections
def _get_connections_from_action_list(self, connection_list, connection_type): connections = [] for action in connection_list: action_name = action[0] #goal_topic = action_name + '/goal' #goal_topic_type = rostopic.get_topic_type(goal_topic) #topic_type = re.sub('ActionGoal$', '', goal_topic_type[0]) # Base type for action nodes = action[1] for node in nodes: #try: # node_uri = self.lookupNode(node) #except: # continue rule = Rule(connection_type, action_name, node) connection = utils.Connection(rule, None, None) # topic_type, node_uri connections.append(connection) return connections
import socket import process import copy import utils import threading import sys s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) host = '127.0.0.1' port = int(sys.argv[1]) s.bind((host, port)) s.listen(10) print(f'Server is running at {host}:{port}') connection = utils.Connection() while True: c, addr = s.accept() c_id = connection.add(c, addr) child = threading.Thread(target=process.main, args=(connection, c_id)) child.start()
def generate_connection_details(self, connection_type, name, node): ''' Creates all the extra details to create a connection object from a rule. @param connection_type : the connection type (one of gateway_msgs.msg.ConnectionType) @type string @param name : the name of the connection @type string @param node : the master node name it comes from @param string @return the utils.Connection object complete with type_info and xmlrpc_uri @type utils.Connection ''' xmlrpc_uri = self.lookupNode(node) connections = [] if connection_type == PUBLISHER or connection_type == SUBSCRIBER: type_info = rostopic.get_topic_type(name)[0] # message type connections.append( utils.Connection(Rule(connection_type, name, node), type_info, xmlrpc_uri)) elif connection_type == SERVICE: type_info = rosservice.get_service_uri(name) connections.append( utils.Connection(Rule(connection_type, name, node), type_info, xmlrpc_uri)) elif connection_type == ACTION_SERVER: type_info = rostopic.get_topic_type(name + '/goal')[0] # message type connections.append( utils.Connection(Rule(SUBSCRIBER, name + '/goal', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/cancel')[0] # message type connections.append( utils.Connection(Rule(SUBSCRIBER, name + '/cancel', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/status')[0] # message type connections.append( utils.Connection(Rule(PUBLISHER, name + '/status', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/feedback')[0] # message type connections.append( utils.Connection(Rule(PUBLISHER, name + '/feedback', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/result')[0] # message type connections.append( utils.Connection(Rule(PUBLISHER, name + '/result', node), type_info, xmlrpc_uri)) elif connection_type == ACTION_CLIENT: type_info = rostopic.get_topic_type(name + '/goal')[0] # message type connections.append( utils.Connection(Rule(PUBLISHER, name + '/goal', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/cancel')[0] # message type connections.append( utils.Connection(Rule(PUBLISHER, name + '/cancel', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/status')[0] # message type connections.append( utils.Connection(Rule(SUBSCRIBER, name + '/status', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/feedback')[0] # message type connections.append( utils.Connection(Rule(SUBSCRIBER, name + '/feedback', node), type_info, xmlrpc_uri)) type_info = rostopic.get_topic_type(name + '/result')[0] # message type connections.append( utils.Connection(Rule(SUBSCRIBER, name + '/result', node), type_info, xmlrpc_uri)) return connections