Beispiel #1
0
 def __init__(self, manager, userID, converter):
     """ Initialize the Converter monitor.
         
         @param manager:     Manager which is used in this node and
                             implements necessary callback.
         @type  manager:     core.manager._RobotManager
         
         @param userID:      User ID of the interface owner.
         @type  userID:      str
         
         @param converter:   Converter instance which describes converter
                             which should be monitored.
         @type  converter:   core.interfaces.IEndpointConverterCommand
         
         @raise:     util.interfaces.InterfaceError
     """
     verifyObject(IEndpointConverterCommand, converter)
     
     super(_ConverterMonitor, self).__init__(userID, converter.tag)
     
     self._msgType = converter.msgType
     self._robotID = converter.endpointID
     self._converter = manager.converter
     self._manager = manager
     
     self._inputMsgCls = None
     self._outputMsgCls = None
     
     self._loadClass(manager.loader)
Beispiel #2
0
 def add(self, producer):
     """ Add a new producer to the FIFO.
         
         @raise:     util.interfaces.InterfaceError
     """
     verifyObject(IRCEProducer, producer)
     self._fifo.append((producer, datetime.now()))
Beispiel #3
0
 def __init__(self, user, robotID, commID, key, control):
     """ Initialize the Robot proxy.
         
         @param user:        User to which this robot belongs.
         @type  user:        core.user.User
         
         @param robotID:     RobotID which is used to identify the robot.
         @type  robotID:     str
         
         @param commID:      Communication ID of this robot.
         @type  commID:      str
         
         @param key:         Key which should be used to verify connection
                             from represented robot.
         @type  key:         str
                                 
         @param control:     Control which is used to communicate with the
                             robot.
         @type  control:     core.interfaces.IRobotControl
     """
     verifyObject(IRobotControl, control)
     
     super(RobotProxy, self).__init__(user, robotID, commID, control)
     
     control.createRobot(RobotCommand(robotID, key))
Beispiel #4
0
 def __init__(self, user, cTag, commID, control):
     """ Initialize the Container proxy.
         
         @param user:        User instance to which this Container belongs.
         @type  user:        core.user.User
                                 
         @param control:     Control which is used to communicate with the
                             Container.
         @type  control:     core.interfaces.IContainerControl
         
         @param commID:      CommID of the ROS environment inside the
                             Container.
         @type  commID:      str
         
         @param cTag:        Container tag which is used by the user to
                             identify this Container.
         @type  cTag:        str
     """
     verifyObject(IContainerControl, control)
     
     super(ContainerProxy, self).__init__(user, cTag, commID, control)
     
     self._connected = False   # TODO: At the moment not used
     
     log.msg('Start container "{0}".'.format(commID))
     control.createContainer(ContainerCommand(cTag, commID))
Beispiel #5
0
 def __init__(self, commMngr, postInit=[], postClose=[]):
     """ Initialize the RCEFactory.
         
         @param commMngr:    CommManager instance which should be used with
                             this factory and its build protocols.
         @type  commMngr:    comm.manager.CommManager
         
         @param postInit:    Instances which should be informed about the
                             successful initialization of a connection.
         @type  postInit:    comm.interfaces.IPostInit
         
         @param postClose:   Instances which should be informed about the
                             closing of a connection.
         @type  postClose:   comm.interfaces.IPostClose
         
         @raise:     util.interfaces.InterfaceError if the callbacks from
                     postInit do not implement comm.interfaces.IPostInit 
                     and the callbacks from postClose do not implement
                     comm.interfaces.IPostClose.
     """
     for cb in postInit:
         verifyObject(IPostInit, cb)
     
     for cb in postClose:
         verifyObject(IPostClose, cb)
     
     self._commManager = commMngr
     self._filter = set([types.INIT_REQUEST, types.ROUTE_INFO])
     self._postInit = postInit
     self._postClose = postClose
Beispiel #6
0
 def serialize(self, s, msg):
     try:
         s.addElement(msg['user'])
         cmd = msg['cmd']
     except KeyError as e:
         raise SerializationError('Could not serialize content of '
                                  'Command Message. Missing key: '
                                  '{0}'.format(e))
     
     try:
         verifyObject(ISerializable, cmd)
     except InterfaceError as e:
         raise SerializationError('Content of Command Message can not '
                                  'be serialized: {0}'.format(e))
     
     try:
         cls = self._cmdCls[cmd.IDENTIFIER]
     except KeyError:
         raise SerializationError('The object class is not registered.')
     
     if not isinstance(cmd, cls):
         raise SerializationError('The object is of invalid type.')
     
     s.addIdentifier(cmd.IDENTIFIER, 1)
     cmd.serialize(s)
Beispiel #7
0
 def registerControlFactory(self, ctrlFactory):
     """ Register the ControlFactory.
         
         @param ctrlFactory:     ControlFactory which should be registered.
         @type  ctrlFactory:     core.interfaces.IControlFactory
     """
     verifyObject(IControlFactory, ctrlFactory)
     self._ctrlFactory = ctrlFactory
Beispiel #8
0
 def registerLoadBalancer(self, loadBalancer):
     """ Register the LoadBalancer.
         
         @param loadBalancer:    LoadBalancer which should be registered.
         @type  loadBalancer:    core.interfaces.ILoadBalancer
     """
     verifyObject(ILoadBalancer, loadBalancer)
     self._loadBalancer = loadBalancer
Beispiel #9
0
 def onConnect(self, req):
     """ Method is called by the Autobahn engine when a request to establish
         a connection has been received.
         
         @param req:     Connection Request object.
         @type  req:     autobahn.websocket.ConnectionRequest
         
         @raise:         autobahn.websocket.HttpException
     """
     params = req.params
     
     try:
         userID = params['userID']
         robotID = params['robotID']
         key = params['key']
     except KeyError as e:
         raise HttpException(httpstatus.HTTP_STATUS_CODE_BAD_REQUEST[0],
                             'Request is missing parameter: {0}'.format(e))
     
     for name, param in [('userID', userID),
                         ('robotID', robotID),
                         ('key', key)]:
         if len(param) != 1:
             raise HttpException(httpstatus.HTTP_STATUS_CODE_BAD_REQUEST[0],
                                 "Parameter '{0}' has to be unique in "
                                 'request.'.format(name))
     
     userID = userID[0]
     robotID = robotID[0]
     key = key[0]
     
     try:
         self._manager.robotConnected(userID, robotID, key, self)
     except AuthenticationError as e:
         raise HttpException(httpstatus.HTTP_STATUS_CODE_FORBIDDEN[0],
                             str(e))
     except Exception as e:
         import traceback
         raise HttpException(
             httpstatus.HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR[0],
             traceback.format_exc()
         )
         
     self._robotID = robotID
     self._userID = userID
     
     # TODO: List should probably not be hard coded here,
     #       but given as an argument...
     for handler in [ CreateContainerHandler(self._manager, userID),
                      DestroyContainerHandler(self._manager, userID),
                      ConfigureContainerHandler(self._manager, userID),
                      ConnectInterfacesHandler(self._manager, userID),
                      DataMessageHandler(self._manager, userID) ]:
         verifyObject(IClientMsgHandler, handler)
         self._msgHandler[handler.TYPE] = handler
     
     self._assembler.start()
     return None
Beispiel #10
0
 def registerMessenger(self, messenger):
     """ Register the Messenger.
         
         @param messenger:   Messenger which should be registered.
         @type  messenger:   core.interfaces.IMessenger
     """
     verifyObject(IMessenger, messenger)
     
     if self._messenger:
         raise InternalError('There is already a messenger registered.')
     
     self._messenger = messenger
Beispiel #11
0
 def registerRequestSender(self, sender):
     """ Register the RequestSender.
         
         @param sender:      RequestSender which should be registered.
         @type  sender:      core.interfaces.IRequestSender
     """
     if self._reqSender:
         raise InternalError('There is already a RequestSender registered.')
     
     verifyObject(IRequestSender, sender)
     
     self._reqSender = sender
Beispiel #12
0
 def registerMessageProcessors(self, processors):
     """ Method to register a message processor which are used for the
         incoming messages. If there already exists a message processor for
         the same message type the old message processor is dropped.
                             
         @param processors:  Processor which should be registered.
         @type  processors:  [ comm.interfaces.IMessageProcessor ]
         
         @raise:     util.interfaces.InterfaceError if the processors do not
                     implement comm.interfaces.IContentSerializer.errors.
     """
     for processor in processors:
         verifyObject(IMessageProcessor, processor)
         self._processors[processor.IDENTIFIER] = processor
Beispiel #13
0
 def registerContentSerializers(self, serializers):
     """ Method to register a content serializer which are used for
         serializing/deserializing the messages. If there already exists a
         serializer for the same message type the old serializer is dropped.
         
         @param serializers:     Content serializers which should be
                                 registered.
         @type  serializers:     [ comm.interfaces.IContentSerializer ]
         
         @raise:     util.interfaces.InterfaceError if the serializers do
                     not implement comm.interfaces.IContentSerializer.
     """
     for serializer in serializers:
         verifyObject(IContentSerializer, serializer)
         self._contentSerializer[serializer.IDENTIFIER] = serializer
Beispiel #14
0
 def registerControl(self, control):
     """ Register control for the communication with the endpoint.
         
         @param control: Control which should be registered for the
                         communication with the endpoint.
         @type  control: core.interfaces.IEndpointControl
         
         @raise:     errors.InternalError, util.interfaces.InterfaceError
     """
     if self._control:
         raise InternalError('There is already a control for the '
                             'communication registered.')
     
     verifyObject(IEndpointControl, control)
     self._control = control
Beispiel #15
0
 def __init__(self, endpoint, tag, iType, msgType, rosAddr=None):
     """ Initialize the Interface.
         
         @param endpoint:    Endpoint to which this interface belongs.
         @type  endpoint:    core.interfaces.IEndpointProxy
         
         @param tag:         Tag which is used to identify this interface.
         @type  tag:         str
         
         @param iType:       Interface type; valid values are:
                                 service, publisher, subscriber
         @type  iType:       str
         
         @param msgType:     Message type of the form package/messageClass,
                             i.e. 'std_msgs/Int8'.
         @type  msgType:     str
         
         @param rosAddr:     Address which is used for the interface in the
                             ROS environment, i.e. '/namespace/interface';
                             only necessary if it is a ROS environment
                             interface.
         @type  rosAddr:     str / None
         
         @raise:     errors.InvalidRequest, util.interfaces.InterfaceError
     """
     verifyObject(IEndpointProxy, endpoint)
     
     if iType not in Interface._MAP:
         raise InvalidRequest('"{0}" is not a valid interface type.')
     
     self._endpoint = endpoint
     self._control = None
     self._tag = tag
     self._iType = Interface._MAP[iType]
     self._msgType = msgType
     self._rosAddr = rosAddr
     
     self._conn = set()
     
     endpoint.registerInterface(self)
     endpoint.owner.registerInterface(self)
     
     if rosAddr:
         try:
             endpoint.reserveAddr(rosAddr)
         except ValueError:
             raise InvalidRequest('Another interface with the same ROS '
                                  'address already exists.')
Beispiel #16
0
 def __init__(self, manager, userID, interface):
     """ Initialize the Interface monitor.
         
         @param manager:     Manager which is used in this node and
                             implements necessary callback.
         @type  manager:     core.manager._InterfaceManager
         
         @param userID:      User ID of the interface owner.
         @type  userID:      str
         
         @param interface:   Interface instance which describes interface
                             which should be monitored.
         @type  interface:   IEndpointInterface
         
         @raise:     util.interfaces.InterfaceError
     """
     verifyObject(IEndpointInterfaceCommand, interface)
     
     super(_InterfaceMonitor, self).__init__(userID, interface.tag)
     
     self._name = interface.name
     self._manager = manager
     self._ready = False
Beispiel #17
0
 def __init__(self, manager, userID, forwarder):
     """ Initialize the Forwarder monitor.
         
         @param manager:     Manager which is used in this node and
                             implements necessary callback.
         @type  manager:     core.manager._RobotManager
         
         @param userID:      User ID of the interface owner.
         @type  userID:      str
         
         @param forwarder:   Forwarder instance which describes forwarder
                             which should be monitored.
         @type  forwarder:   core.interfaces.IEndpointConverterCommand
         
         @raise:     util.interfaces.InterfaceError
     """
     verifyObject(IEndpointConverterCommand, forwarder)
     
     super(_ForwarderMonitor, self).__init__(userID, forwarder.tag)
     
     self._msgType = forwarder.msgType
     self._robotID = forwarder.endpointID
     self._manager = manager
Beispiel #18
0
 def __init__(self, user, uid, commID, control):
     """ Initialize the endpoint monitor.
         
         @param user:        User to which this endpoint belongs.
         @type  user:        core.user.User
         
         @param uid:         Identifier of this endpoint.
         @type  uid:         str
         
         @param commID:      Communication ID of this endpoint.
         @type  commID:      str
         
         @param control:     Control which is used to send the commands to
                             the endpoint.
         @type  control:     core.interfaces.IEndpointControl
     """
     verifyObject(IEndpointControl, control)
     
     self._user = user
     self._uid = uid
     self._commID = commID
     self._control = control
     self._interfaces = set()
Beispiel #19
0
 def __init__(self, user, tag, commID, control):
     """ Initialize the ROS environment proxy.
         
         @param user:        User instance to which this ROS environment
                             belongs.
         @type  user:        core.user.User
         
         @param tag:         Tag of this environment.
         @type  tag:         str
         
         @param commID:      CommID of the ROS environment.
         @type  commID:      str
          
         @param control:     Control which is used to communicate with the
                             ROS environment.
         @type  control:     core.interfaces.IROSEnvControl
     """
     verifyObject(INodeControl, control)
     verifyObject(IParameterControl, control)
     
     super(ROSEnvProxy, self).__init__(user, tag, commID, control)
     
     self._rosAddrs = set()