示例#1
0
    def getParam(self, caller_id, key, client_ip_address="127.0.0.1"):
        """
        Retrieve parameter value from server.
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter to lookup. If key is a namespace,
        getParam() will return a parameter tree.
        @type  key: str
        getParam() will return a parameter tree.

        @return: [code, statusMessage, parameterValue]. If code is not
            1, parameterValue should be ignored. If key is a namespace,
            the return value will be a dictionary, where each key is a
            parameter in that namespace. Sub-namespaces are also
            represented as dictionaries.
        @rtype: [int, str, XMLRPCLegalValue]
        """
        try:
            key = resolve_name(key, caller_id)
            param = self.param_server.get_param(key)
        except KeyError as e:
            return -1, "Parameter [%s] is not set" % key, 0
        if not self.auth.check_param_getter(key, client_ip_address):
            self.logger.warn("getParam( %s, %s, %s) parameter not authorized" %
                             (caller_id, key, client_ip_address))
            return -1, "parameter not authorized", 0
        return 1, "Parameter [%s]" % key, param
示例#2
0
 def validator(param_value, caller_id):
     if not isstring(param_value):
         raise ParameterInvalid("ERROR: parameter [%s] must be a string"%param_name)              
     if not param_value:
         return ''
     #return resolve_name(param_value, namespace(caller_id))
     return resolve_name(param_value, caller_id)
示例#3
0
 def unsubscribeParam(self, caller_id, caller_api, key, client_ip_address):
     """
     Retrieve parameter value from server and subscribe to updates to that param. See
     paramUpdate() in the Node API. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to lookup.
     @type  key: str
     @param caller_api: API URI for paramUpdate callbacks.
     @type  caller_api: str
     @return: [code, statusMessage, numUnsubscribed]. 
        If numUnsubscribed is zero it means that the caller was not subscribed to the parameter.
     @rtype: [int, str, int]
     """
     if not is_uri_match(caller_api, client_ip_address):
         self.logger.warn(
             "unsubscribeParam( %s, %s, %s, %s) caller_api not authorized" %
             (caller_id, caller_api, key, client_ip_address))
         return -1, "caller_api not authorized", 0
     key = resolve_name(key, caller_id)
     try:
         # ps_lock is required due to potential self.reg_manager modification
         self.ps_lock.acquire()
         retval = self.param_server.unsubscribe_param(
             key, (caller_id, caller_api))
     finally:
         self.ps_lock.release()
     return 1, "Unsubscribe to parameter [%s]" % key, 1
示例#4
0
    def setParam(self, caller_id, key, value):
        """
        Parameter Server: set parameter.  NOTE: if value is a
        dictionary it will be treated as a parameter tree, where key
        is the parameter namespace. For example:::
          {'x':1,'y':2,'sub':{'z':3}}

        will set key/x=1, key/y=2, and key/sub/z=3. Furthermore, it
        will replace all existing parameters in the key parameter
        namespace with the parameters in value. You must set
        parameters individually if you wish to perform a union update.
        
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter name
        @type  key: str
        @param value: parameter value.
        @type  value: XMLRPCLegalValue
        @return: [code, msg, 0]
        @rtype: [int, str, int]
        """
        key = resolve_name(key, caller_id)
        self.param_server.set_param(key, value, self._notify_param_subscribers)
        mloginfo("+PARAM [%s] by %s",key, caller_id)
        return 1, "parameter %s set"%key, 0
示例#5
0
    def unsubscribeParam(self, caller_id, caller_api, key):
        """
        Retrieve parameter value from server and subscribe to updates to that param. See
        paramUpdate() in the Node API. 
        @param caller_id str: ROS caller id
        @type  caller_id: str
        @param key: parameter to lookup.
        @type  key: str
        @param caller_api: API URI for paramUpdate callbacks.
        @type  caller_api: str
        @return: [code, statusMessage, numUnsubscribed]. 
           If numUnsubscribed is zero it means that the caller was not subscribed to the parameter.
        @rtype: [int, str, int]
        """
        key = resolve_name(key, caller_id)
        try:
            # ps_lock is required due to potential self.reg_manager modification
            self.ps_lock.acquire()
            retval = self.param_server.unsubscribe_param(
                key, (caller_id, caller_api))

            # Pushyami : Save the latest registration
            if self.rescue_opt:
                # print("In register of topic:" + key + "caller id: " + caller_id)
                self.rescue_obj.saveState()
        finally:
            self.ps_lock.release()
        return 1, "Unsubscribe to parameter [%s]" % key, 1
示例#6
0
    def setParam(self, caller_id, key, value):
        """
        Parameter Server: set parameter.  NOTE: if value is a
        dictionary it will be treated as a parameter tree, where key
        is the parameter namespace. For example:::
          {'x':1,'y':2,'sub':{'z':3}}

        will set key/x=1, key/y=2, and key/sub/z=3. Furthermore, it
        will replace all existing parameters in the key parameter
        namespace with the parameters in value. You must set
        parameters individually if you wish to perform a union update.
        
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter name
        @type  key: str
        @param value: parameter value.
        @type  value: XMLRPCLegalValue
        @return: [code, msg, 0]
        @rtype: [int, str, int]
        """
        key = resolve_name(key, caller_id)
        self.param_server.set_param(key, value, self._notify_param_subscribers)
        mloginfo("+PARAM [%s] by %s", key, caller_id)
        return 1, "parameter %s set" % key, 0
示例#7
0
 def subscribeParam(self, caller_id, caller_api, key):
     """
     Retrieve parameter value from server and subscribe to updates to that param. See
     paramUpdate() in the Node API. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to lookup.
     @type  key: str
     @param caller_api: API URI for paramUpdate callbacks.
     @type  caller_api: str
     @return: [code, statusMessage, parameterValue]. If code is not
        1, parameterValue should be ignored. parameterValue is an empty dictionary if the parameter
        has not been set yet.
     @rtype: [int, str, XMLRPCLegalValue]
     """
     key = resolve_name(key, caller_id)
     try:
         # ps_lock has precedence and is required due to
         # potential self.reg_manager modification
         self.ps_lock.acquire()
         val = self.param_server.subscribe_param(key,
                                                 (caller_id, caller_api))
     finally:
         self.ps_lock.release()
     return 1, "Subscribed to parameter [%s]" % key, val
示例#8
0
def valid_name_validator_resolved(param_name, param_value, caller_id):
    if not param_value or not isstring(param_value):
        raise ParameterInvalid("ERROR: parameter [%s] must be a non-empty string"%param_name)            
    #TODO: actual validation of chars
    # I added the colon check as the common error will be to send an URI instead of name
    if ':' in param_value or ' ' in param_value:
        raise ParameterInvalid("ERROR: parameter [%s] contains illegal chars"%param_name) 
    #return resolve_name(param_value, namespace(caller_id))
    return resolve_name(param_value, caller_id)
示例#9
0
 def hasParam(self, caller_id, key):
     """
     Check if parameter is stored on server. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to check
     @type  key: str
     @return: [code, statusMessage, hasParam]
     @rtype: [int, str, bool]
     """
     key = resolve_name(key, caller_id)
     if self.param_server.has_param(key):
         return 1, key, True
     else:
         return 1, key, False            
示例#10
0
 def hasParam(self, caller_id, key):
     """
     Check if parameter is stored on server. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to check
     @type  key: str
     @return: [code, statusMessage, hasParam]
     @rtype: [int, str, bool]
     """
     key = resolve_name(key, caller_id)
     if self.param_server.has_param(key):
         return 1, key, True
     else:
         return 1, key, False
示例#11
0
 def deleteParam(self, caller_id, key):
     """
     Parameter Server: delete parameter
     @param caller_id: ROS caller id
     @type  caller_id: str
     @param key: parameter name
     @type  key: str
     @return: [code, msg, 0]
     @rtype: [int, str, int]
     """
     try:
         key = resolve_name(key, caller_id)
         self.param_server.delete_param(key, self._notify_param_subscribers)
         mloginfo("-PARAM [%s] by %s", key, caller_id)
         return 1, "parameter %s deleted" % key, 0
     except KeyError as e:
         return -1, "parameter [%s] is not set" % key, 0
示例#12
0
 def deleteParam(self, caller_id, key):
     """
     Parameter Server: delete parameter
     @param caller_id: ROS caller id
     @type  caller_id: str
     @param key: parameter name
     @type  key: str
     @return: [code, msg, 0]
     @rtype: [int, str, int]
     """
     try:
         key = resolve_name(key, caller_id)
         self.param_server.delete_param(key, self._notify_param_subscribers)
         mloginfo("-PARAM [%s] by %s",key, caller_id)            
         return  1, "parameter %s deleted"%key, 0                
     except KeyError as e:
         return -1, "parameter [%s] is not set"%key, 0
示例#13
0
文件: test_names.py 项目: Aand1/ROSCH
def test_resolve_name():
      from rosgraph.names import resolve_name
      # TODO: test with remappings
      tests = [
          ('', '/', '/'),
          ('', '/node', '/'),
          ('', '/ns1/node', '/ns1/'),

          ('foo', '', '/foo'),
          ('foo/', '', '/foo'),
          ('/foo', '', '/foo'),
          ('/foo/', '', '/foo'),
          ('/foo', '/', '/foo'),
          ('/foo/', '/', '/foo'),
          ('/foo', '/bar', '/foo'),
          ('/foo/', '/bar', '/foo'),

          ('foo', '/ns1/ns2', '/ns1/foo'),
          ('foo', '/ns1/ns2/', '/ns1/foo'),
          ('foo', '/ns1/ns2/ns3/', '/ns1/ns2/foo'),
          ('foo/', '/ns1/ns2', '/ns1/foo'),
          ('/foo', '/ns1/ns2', '/foo'),
          ('foo/bar', '/ns1/ns2', '/ns1/foo/bar'),
          ('foo//bar', '/ns1/ns2', '/ns1/foo/bar'),
          ('foo/bar', '/ns1/ns2/ns3', '/ns1/ns2/foo/bar'),
          ('foo//bar//', '/ns1/ns2/ns3', '/ns1/ns2/foo/bar'),

          ('~foo', '/', '/foo'),            
          ('~foo', '/node', '/node/foo'),            
          ('~foo', '/ns1/ns2', '/ns1/ns2/foo'),            
          ('~foo/', '/ns1/ns2', '/ns1/ns2/foo'),            
          ('~foo/bar', '/ns1/ns2', '/ns1/ns2/foo/bar'),

          # #3044
          ('~/foo', '/', '/foo'),            
          ('~/foo', '/node', '/node/foo'),            
          ('~/foo', '/ns1/ns2', '/ns1/ns2/foo'),            
          ('~/foo/', '/ns1/ns2', '/ns1/ns2/foo'),            
          ('~/foo/bar', '/ns1/ns2', '/ns1/ns2/foo/bar'),

          ]
      for name, node_name, v in tests:
          assert v == resolve_name(name, node_name)
示例#14
0
 def hasParam(self, caller_id, key, client_ip_address):
     """
     Check if parameter is stored on server. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to check
     @type  key: str
     @return: [code, statusMessage, hasParam]
     @rtype: [int, str, bool]
     """
     key = resolve_name(key, caller_id)
     if not self.auth.check_param_setter(key, client_ip_address):
         self.logger.warn("hasParam( %s, %s, %s) parameter not authorized" %
                          (caller_id, key, client_ip_address))
         return -1, "parameter not authorized", 0
     if self.param_server.has_param(key):
         return 1, key, True
     else:
         return 1, key, False
示例#15
0
 def unsubscribeParam(self, caller_id, caller_api, key):
     """
     Retrieve parameter value from server and subscribe to updates to that param. See
     paramUpdate() in the Node API. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to lookup.
     @type  key: str
     @param caller_api: API URI for paramUpdate callbacks.
     @type  caller_api: str
     @return: [code, statusMessage, numUnsubscribed]. 
        If numUnsubscribed is zero it means that the caller was not subscribed to the parameter.
     @rtype: [int, str, int]
     """        
     key = resolve_name(key, caller_id)        
     try:
         # ps_lock is required due to potential self.reg_manager modification
         self.ps_lock.acquire()
         retval = self.param_server.unsubscribe_param(key, (caller_id, caller_api))
     finally:
         self.ps_lock.release()
     return 1, "Unsubscribe to parameter [%s]"%key, 1
示例#16
0
    def getParam(self, caller_id, key):
        """
        Retrieve parameter value from server.
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter to lookup. If key is a namespace,
        getParam() will return a parameter tree.
        @type  key: str
        getParam() will return a parameter tree.

        @return: [code, statusMessage, parameterValue]. If code is not
            1, parameterValue should be ignored. If key is a namespace,
            the return value will be a dictionary, where each key is a
            parameter in that namespace. Sub-namespaces are also
            represented as dictionaries.
        @rtype: [int, str, XMLRPCLegalValue]
        """
        try:
            key = resolve_name(key, caller_id)
            return 1, "Parameter [%s]" % key, self.param_server.get_param(key)
        except KeyError as e:
            return -1, "Parameter [%s] is not set" % key, 0
示例#17
0
    def getParam(self, caller_id, key):
        """
        Retrieve parameter value from server.
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter to lookup. If key is a namespace,
        getParam() will return a parameter tree.
        @type  key: str
        getParam() will return a parameter tree.

        @return: [code, statusMessage, parameterValue]. If code is not
            1, parameterValue should be ignored. If key is a namespace,
            the return value will be a dictionary, where each key is a
            parameter in that namespace. Sub-namespaces are also
            represented as dictionaries.
        @rtype: [int, str, XMLRPCLegalValue]
        """
        try:
            key = resolve_name(key, caller_id)
            return 1, "Parameter [%s]"%key, self.param_server.get_param(key)
        except KeyError as e: 
            return -1, "Parameter [%s] is not set"%key, 0
示例#18
0
def test_resolve_name():
    from rosgraph.names import resolve_name
    # TODO: test with remappings
    tests = [
        ('', '/', '/'),
        ('', '/node', '/'),
        ('', '/ns1/node', '/ns1/'),
        ('foo', '', '/foo'),
        ('foo/', '', '/foo'),
        ('/foo', '', '/foo'),
        ('/foo/', '', '/foo'),
        ('/foo', '/', '/foo'),
        ('/foo/', '/', '/foo'),
        ('/foo', '/bar', '/foo'),
        ('/foo/', '/bar', '/foo'),
        ('foo', '/ns1/ns2', '/ns1/foo'),
        ('foo', '/ns1/ns2/', '/ns1/foo'),
        ('foo', '/ns1/ns2/ns3/', '/ns1/ns2/foo'),
        ('foo/', '/ns1/ns2', '/ns1/foo'),
        ('/foo', '/ns1/ns2', '/foo'),
        ('foo/bar', '/ns1/ns2', '/ns1/foo/bar'),
        ('foo//bar', '/ns1/ns2', '/ns1/foo/bar'),
        ('foo/bar', '/ns1/ns2/ns3', '/ns1/ns2/foo/bar'),
        ('foo//bar//', '/ns1/ns2/ns3', '/ns1/ns2/foo/bar'),
        ('~foo', '/', '/foo'),
        ('~foo', '/node', '/node/foo'),
        ('~foo', '/ns1/ns2', '/ns1/ns2/foo'),
        ('~foo/', '/ns1/ns2', '/ns1/ns2/foo'),
        ('~foo/bar', '/ns1/ns2', '/ns1/ns2/foo/bar'),

        # #3044
        ('~/foo', '/', '/foo'),
        ('~/foo', '/node', '/node/foo'),
        ('~/foo', '/ns1/ns2', '/ns1/ns2/foo'),
        ('~/foo/', '/ns1/ns2', '/ns1/ns2/foo'),
        ('~/foo/bar', '/ns1/ns2', '/ns1/ns2/foo/bar'),
    ]
    for name, node_name, v in tests:
        assert v == resolve_name(name, node_name)
示例#19
0
 def deleteParam(self, caller_id, key, client_ip_address):
     """
     Parameter Server: delete parameter
     @param caller_id: ROS caller id
     @type  caller_id: str
     @param key: parameter name
     @type  key: str
     @return: [code, msg, 0]
     @rtype: [int, str, int]
     """
     try:
         key = resolve_name(key, caller_id)
         if not self.auth.check_param_setter(key, client_ip_address):
             self.logger.warn(
                 "deleteParam( %s, %s, %s) parameter not authorized" %
                 (caller_id, key, client_ip_address))
             return -1, "parameter not authorized", 0
         self.param_server.delete_param(key, self._notify_param_subscribers)
         mloginfo("-PARAM [%s] by %s", key, caller_id)
         return 1, "parameter %s deleted" % key, 0
     except KeyError as e:
         return -1, "parameter [%s] is not set" % key, 0
示例#20
0
 def unsubscribeParam(self, caller_id, caller_api, key):
     """
     Retrieve parameter value from server and subscribe to updates to that param. See
     paramUpdate() in the Node API. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to lookup.
     @type  key: str
     @param caller_api: API URI for paramUpdate callbacks.
     @type  caller_api: str
     @return: [code, statusMessage, numUnsubscribed]. 
        If numUnsubscribed is zero it means that the caller was not subscribed to the parameter.
     @rtype: [int, str, int]
     """        
     key = resolve_name(key, caller_id)        
     try:
         # ps_lock is required due to potential self.reg_manager modification
         self.ps_lock.acquire()
         retval = self.param_server.unsubscribe_param(key, (caller_id, caller_api))
     finally:
         self.ps_lock.release()
     mloginfo("-CACHEDPARAM [%s] by %s",key, caller_id)
     return 1, "Unsubscribe to parameter [%s]"%key, 1
示例#21
0
    def deleteParam(self, caller_id, key):
        """
        Parameter Server: delete parameter
        @param caller_id: ROS caller id
        @type  caller_id: str
        @param key: parameter name
        @type  key: str
        @return: [code, msg, 0]
        @rtype: [int, str, int]
        """
        try:
            key = resolve_name(key, caller_id)
            self.param_server.delete_param(key, self._notify_param_subscribers)

            # Pushyami : save state when a new param is deleted
            if self.rescue_opt:
                # print("In register of topic:" + key + "caller id: " + caller_id)
                self.rescue_obj.update_params()
                self.rescue_obj.saveState()

            mloginfo("-PARAM [%s] by %s", key, caller_id)
            return 1, "parameter %s deleted" % key, 0
        except KeyError as e:
            return -1, "parameter [%s] is not set" % key, 0
示例#22
0
 def subscribeParam(self, caller_id, caller_api, key):
     """
     Retrieve parameter value from server and subscribe to updates to that param. See
     paramUpdate() in the Node API. 
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param key: parameter to lookup.
     @type  key: str
     @param caller_api: API URI for paramUpdate callbacks.
     @type  caller_api: str
     @return: [code, statusMessage, parameterValue]. If code is not
        1, parameterValue should be ignored. parameterValue is an empty dictionary if the parameter
        has not been set yet.
     @rtype: [int, str, XMLRPCLegalValue]
     """
     key = resolve_name(key, caller_id)        
     try:
         # ps_lock has precedence and is required due to
         # potential self.reg_manager modification
         self.ps_lock.acquire()
         val = self.param_server.subscribe_param(key, (caller_id, caller_api))
     finally:
         self.ps_lock.release()
     return 1, "Subscribed to parameter [%s]"%key, val