예제 #1
0
    def _updates_msg(self, msg):
        if self.group_description is None:
            self.get_group_descriptions()
        self.config = decode_config(msg, self.group_description)

        with self._cv:
            self._cv.notifyAll()
        if self._config_callback is not None:
            self._config_callback(self.config)
예제 #2
0
    def _updates_msg(self, msg):
        if self.group_description is None:
            self.get_group_descriptions()
        self.config = decode_config(msg, self.group_description)

        with self._cv:
            self._cv.notifyAll()
        if self._config_callback is not None:
            self._config_callback(self.config)
    def _dynamic_reconfigure_listener_callback(self, config_msg):
        """
        Callback for the dynamic_reconfigure update message

        :param config_msg: msg
        :type config_msg: DelegationManagerConfig_msg
        """

        config = encoding.decode_config(msg=config_msg)

        self.update_config(config=config)
 def _set_callback(self, req):
     return encode_config(
         self.update_configuration(
             decode_config(req.config, self.type.config_description)))
예제 #5
0
    def update_configuration(self, changes, timeout=None):
        """
        Change the server's configuration

        @param changes: dictionary of key value pairs for the parameters that are changing
        @type  changes: {str: value}
        """
        # Retrieve the parameter descriptions
        if self.param_description is None:
            self.get_parameter_descriptions(timeout)

        # Cast the parameters to the appropriate types
        if self.param_description is not None:
            for name, value in list(changes.items())[:]:
                if name != 'groups':
                    dest_type = self._param_types.get(name)
                    if dest_type is None:
                        raise DynamicReconfigureParameterException(
                            'don\'t know parameter: %s' % name)

                    try:
                        found = False
                        descr = [
                            x for x in self.param_description
                            if x['name'].lower() == name.lower()
                        ][0]

                        # Fix not converting bools properly
                        if dest_type is bool and type(value) is str:
                            changes[name] = value.lower() in ("yes", "true",
                                                              "t", "1")
                            found = True
                        # Handle enums
                        elif type(value
                                  ) is str and not descr['edit_method'] == '':
                            enum_descr = eval(descr['edit_method'])
                            found = False
                            for const in enum_descr['enum']:
                                if value.lower() == const['name'].lower():
                                    val_type = self._param_type_from_string(
                                        const['type'])
                                    changes[name] = val_type(const['value'])
                                    found = True
                        if not found:
                            if sys.version_info.major < 3:
                                if type(value) is unicode:
                                    changes[name] = unicode(value)
                                else:
                                    changes[name] = dest_type(value)
                            else:
                                changes[name] = dest_type(value)

                    except ValueError as e:
                        raise DynamicReconfigureParameterException(
                            'can\'t set parameter \'%s\' of %s: %s' %
                            (name, str(dest_type), e))

        if 'groups' in changes.keys():
            changes['groups'] = self.update_groups(changes['groups'])

        config = encode_config(changes)

        try:
            msg = self._set_service(config).config
        except ServiceException as e:
            raise DynamicReconfigureCallbackException('service call failed')

        if self.group_description is None:
            self.get_group_descriptions(timeout)
        resp = decode_config(msg, self.group_description)

        return resp
예제 #6
0
 def _set_callback(self, req):
     return encode_config(self.update_configuration(decode_config(req.config, self.type.config_description)))
예제 #7
0
    def update_configuration(self, changes):
        """
        Change the server's configuration

        @param changes: dictionary of key value pairs for the parameters that are changing
        @type  changes: {str: value}
        """
        # Retrieve the parameter descriptions
        if self.param_description is None:
            self.get_parameter_descriptions()

        # Cast the parameters to the appropriate types
        if self.param_description is not None:
            for name, value in list(changes.items())[:]:
                if name != 'groups':
                    dest_type = self._param_types.get(name)
                    if dest_type is None:
                        raise DynamicReconfigureParameterException('don\'t know parameter: %s' % name)

                    try:
                        found = False
                        descr = [x for x in self.param_description if x['name'].lower() == name.lower()][0]

                        # Fix not converting bools properly
                        if dest_type is bool and type(value) is str:
                            changes[name] = value.lower() in ("yes", "true", "t", "1")
                            found = True
                        # Handle enums
                        elif type(value) is str and not descr['edit_method'] == '':
                            enum_descr = eval(descr['edit_method'])
                            found = False
                            for const in enum_descr['enum']:
                                if value.lower() == const['name'].lower():
                                    val_type = self._param_type_from_string(const['type'])
                                    changes[name] = val_type(const['value'])
                                    found = True
                        if not found:
                            if sys.version_info.major < 3:
                                if type(value) is unicode:
                                    changes[name] = unicode(value)
                                else:
                                    changes[name] = dest_type(value)
                            else:
                                changes[name] = dest_type(value)

                    except ValueError as e:
                        raise DynamicReconfigureParameterException('can\'t set parameter \'%s\' of %s: %s' % (name, str(dest_type), e))

        if 'groups' in changes.keys():
            changes['groups'] = self.update_groups(changes['groups'])

        config = encode_config(changes)

        try:
            msg = self._set_service(config).config
        except ServiceException as e:
            raise DynamicReconfigureCallbackException('service call failed')

        if self.group_description is None:
            self.get_group_descriptions()
        resp = decode_config(msg, self.group_description)

        return resp