Пример #1
0
 def remote_addConnection(self, tagA, tagB):
     """ Create a connection between two interfaces.
         
         @param tagX:        Tag which is used to identify the interface
                             which should be connected. It has to be of the
                             form:
                                 [endpoint tag]/[interface tag]
                             For example:
                                 testRobot/logPublisher
         @type  tagX:        str
     """
     eTagA, iTagA = tagA.split('/', 2)
     eTagB, iTagB = tagB.split('/', 2)
     
     ifA = self._getEndpoint(eTagA).getInterface(iTagA)
     ifB = self._getEndpoint(eTagB).getInterface(iTagB)
     
     if ifA.clsName != ifB.clsName:
         raise InvalidRequest('Can not connect two interfaces with '
                              'different message/service type.')
     
     if not Types.connectable(ifA.iType, ifB.iType):
         raise InvalidRequest('Can not connect an interface of type {0} '
                              'and an interface of type '
                              '{1}.'.format(Types.decode(ifA.iType),
                                            Types.decode(ifB.iType)))
     
     key = hash(tagA)^hash(tagB)
     
     if key in self._connections:
         raise InvalidRequest('Can not add the same connection twice.')
     
     connection = self._realm.createConnection(ifA.obj, ifB.obj)
     self._connections[key] = connection
     connection.notifyOnDeath(self._connectionDied)
Пример #2
0
    def __init__(self, endpoint, connection):
        """ Initialize the Robot.

            @param endpoint:    Robot Client which is responsible for
                                monitoring the robots in this process.
            @type  endpoint:    rce.robot.RobotClient

            @param connection:  The connection manager for robot namespaces.
            @type  connection:  rce.robot.Connection
        """
        Namespace.__init__(self, endpoint)

        interface_map = {
            Types.encode('PublisherConverter') : PublisherConverter,
            Types.encode('SubscriberConverter') : SubscriberConverter,
            Types.encode('ServiceClientConverter') : ServiceClientConverter,
            Types.encode('ServiceProviderConverter') : ServiceProviderConverter,
            Types.encode('PublisherForwarder') : PublisherForwarder,
            Types.encode('SubscriberForwarder') : SubscriberForwarder,
            Types.encode('ServiceClientForwarder') : ServiceClientForwarder,
            Types.encode('ServiceProviderForwarder') : ServiceProviderForwarder
        }
        self._map.update(interface_map)

        self._connection = connection
Пример #3
0
    def __init__(self, endpoint, connection):
        """ Initialize the Robot.

            @param endpoint:    Robot Client which is responsible for
                                monitoring the robots in this process.
            @type  endpoint:    rce.robot.RobotClient

            @param connection:  The connection manager for robot namespaces.
            @type  connection:  rce.robot.Connection
        """
        Namespace.__init__(self, endpoint)

        interface_map = {
            Types.encode('PublisherConverter'): PublisherConverter,
            Types.encode('SubscriberConverter'): SubscriberConverter,
            Types.encode('ServiceClientConverter'): ServiceClientConverter,
            Types.encode('ServiceProviderConverter'): ServiceProviderConverter,
            Types.encode('PublisherForwarder'): PublisherForwarder,
            Types.encode('SubscriberForwarder'): SubscriberForwarder,
            Types.encode('ServiceClientForwarder'): ServiceClientForwarder,
            Types.encode('ServiceProviderForwarder'): ServiceProviderForwarder
        }
        self._map.update(interface_map)

        self._connection = connection
Пример #4
0
    def __init__(self, endpoint):
        """ Initialize the Environment.

            @param endpoint:    Environment Client which is responsible for
                                monitoring the environment in this process.
            @type  endpoint:    rce.robot.EnvironmentClient
        """
        Namespace.__init__(self, endpoint)

        interface_map = {
            Types.encode('PublisherInterface'): PublisherInterface,
            Types.encode('SubscriberInterface'): SubscriberInterface,
            Types.encode('ServiceClientInterface'): ServiceClientInterface,
            Types.encode('ServiceProviderInterface'): ServiceProviderInterface
        }
        self._map.update(interface_map)

        self._nodes = set()
        self._parameters = set()
Пример #5
0
    def __init__(self, endpoint):
        """ Initialize the Environment.

            @param endpoint:    Environment Client which is responsible for
                                monitoring the environment in this process.
            @type  endpoint:    rce.robot.EnvironmentClient
        """
        Namespace.__init__(self, endpoint)

        interface_map = {
            Types.encode('PublisherInterface') : PublisherInterface,
            Types.encode('SubscriberInterface') : SubscriberInterface,
            Types.encode('ServiceClientInterface') : ServiceClientInterface,
            Types.encode('ServiceProviderInterface') : ServiceProviderInterface
        }
        self._map.update(interface_map)

        self._nodes = set()
        self._parameters = set()
Пример #6
0
    def view_addConnection(self, user, tagA, tagB):
        """ Create a connection between two interfaces.

            @param user:        User for which the connection will be created.
            @type  user:        rce.core.user.User

            @param tagX:        Tag which is used to identify the interface
                                which should be connected. It has to be of the
                                form:
                                    [endpoint tag]/[interface tag]
                                For example:
                                    testRobot/logPublisher
            @type  tagX:        str
        """
        eTagA, iTagA = tagA.split('/', 2)
        eTagB, iTagB = tagB.split('/', 2)

        ifA = user.getEndpoint(eTagA).getInterface(iTagA)
        ifB = user.getEndpoint(eTagB).getInterface(iTagB)

        if ifA.clsName != ifB.clsName:
            raise InvalidRequest('Can not connect two interfaces with '
                                 'different message/service type.')

        if not Types.connectable(ifA.iType, ifB.iType):
            raise InvalidRequest('Can not connect an interface of type {0} '
                                 'and an interface of type '
                                 '{1}.'.format(Types.decode(ifA.iType),
                                               Types.decode(ifB.iType)))

        key = int(md5(tagA).hexdigest(), 16) ^ int(md5(tagB).hexdigest(), 16)

        if key in user.connections:
            raise InvalidRequest('Can not add the same connection twice.')

        connection = user.realm.createConnection(ifA.obj, ifB.obj)
        user.connections[key] = connection
        connection.notifyOnDeath(user.connectionDied)
Пример #7
0
    def view_addConnection(self, user, tagA, tagB):
        """ Create a connection between two interfaces.

            @param user:        User for which the connection will be created.
            @type  user:        rce.core.user.User

            @param tagX:        Tag which is used to identify the interface
                                which should be connected. It has to be of the
                                form:
                                    [endpoint tag]/[interface tag]
                                For example:
                                    testRobot/logPublisher
            @type  tagX:        str
        """
        eTagA, iTagA = tagA.split('/', 2)
        eTagB, iTagB = tagB.split('/', 2)

        ifA = user.getEndpoint(eTagA).getInterface(iTagA)
        ifB = user.getEndpoint(eTagB).getInterface(iTagB)

        if ifA.clsName != ifB.clsName:
            raise InvalidRequest('Can not connect two interfaces with '
                                 'different message/service type.')

        if not Types.connectable(ifA.iType, ifB.iType):
            raise InvalidRequest('Can not connect an interface of type {0} '
                                 'and an interface of type '
                                 '{1}.'.format(Types.decode(ifA.iType),
                                               Types.decode(ifB.iType)))

        key = int(md5(tagA).hexdigest(), 16) ^ int(md5(tagB).hexdigest(), 16)

        if key in user.connections:
            raise InvalidRequest('Can not add the same connection twice.')

        connection = user.realm.createConnection(ifA.obj, ifB.obj)
        user.connections[key] = connection
        connection.notifyOnDeath(user.connectionDied)
Пример #8
0
    def addInterface(self, iTag, iType, clsName, addr):
        """ Add an interface to the ROS environment inside the container.

            @param iTag:        Tag which is used to identify the interface in
                                subsequent requests.
            @type  iTag:        str

            @param iType:       Type of the interface. The type has to be of
                                the form:
                                    {prefix}Interface
                                whit valid prefixes:
                                    ServiceClient, ServiceProvider,
                                    Publisher, Subscriber
            @type  iType:       str

            @param clsName:     Message type/Service type consisting of the
                                package and the name of the message/service,
                                i.e. 'std_msgs/Int32'.
            @type  clsName:     str

            @param addr:        ROS name/address which the interface should
                                use.
            @type  addr:        str
        """
        try:
            validateName(iTag)
        except IllegalName:
            raise InvalidRequest('Interface tag is not a valid.')

        if iTag in self._interfaces:
            raise InvalidRequest("Can not use the same interface tag '{0}' "
                                 'in the same container twice.'.format(iTag))

        try:
            iType = Types.encode(iType)
        except TypeError:
            raise InvalidRequest('Interface type is invalid (Unknown prefix).')

        interface = self._obj.createInterface(iType, clsName, addr)
        interface = Interface(interface, iType, clsName)
        self._interfaces[iTag] = interface
        interface.notifyOnDeath(self._interfaceDied)
Пример #9
0
    def addInterface(self, iTag, iType, clsName):
        """ Add an interface to the Robot object.

            @param iTag:        Tag which is used to identify the interface in
                                subsequent requests.
            @type  iTag:        str

            @param iType:       Type of the interface. The type consists of a
                                prefix and a suffix.
                                 - Valid prefixes are:
                                     ServiceClient, ServiceProvider,
                                     Publisher, Subscriber
                                 - Valid suffixes are:
                                     Converter, Forwarder
            @type  iType:       str

            @param clsName:     Message type/Service type consisting of the
                                package and the name of the message/service,
                                i.e. 'std_msgs/Int32'.
            @type  clsName:     str
        """

        try:
            validateName(iTag)
        except IllegalName as e:
            raise InvalidRequest('Interface tag is invalid: {0}'.format(e))

        if iTag in self._interfaces:
            raise InvalidRequest("Can not use the same interface tag '{0}' "
                                 'in the same robot twice.'.format(iTag))

        modifier = 4 if iType.endswith('Forwarder') else 0

        try:
            iType = Types.encode(iType)
        except TypeError:
            raise InvalidRequest('Interface type is invalid (Unknown prefix).')

        interface = self._obj.createInterface(iType + modifier, clsName, iTag)
        interface = Interface(interface, iType, clsName)
        self._interfaces[iTag] = interface
        interface.notifyOnDeath(self._interfaceDied)