Class: Syskit::TaskConfigurationManager

Inherits:
Orocos::TaskConfigurations
  • Object
show all
Defined in:
lib/syskit/task_configuration_manager.rb

Overview

Adapter for Orocos::TaskConfigurations to take into account the conventions inside Syskit apps

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, syskit_model) ⇒ TaskConfigurationManager

Returns a new instance of TaskConfigurationManager



10
11
12
13
14
# File 'lib/syskit/task_configuration_manager.rb', line 10

def initialize(app, syskit_model)
    @app = app
    @syskit_model = syskit_model
    super(orogen_model)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app



5
6
7
# File 'lib/syskit/task_configuration_manager.rb', line 5

def app
  @app
end

#syskit_modelObject (readonly)

Returns the value of attribute syskit_model



6
7
8
# File 'lib/syskit/task_configuration_manager.rb', line 6

def syskit_model
  @syskit_model
end

Instance Method Details

#apply(syskit_task, conf: syskit_task.conf, override: false) ⇒ void

This method returns an undefined value.

Applies a configuration to the given component instance

Parameters:

  • syskit_task (TaskContext)

    the task instance on which the configuration should be applied

  • conf (String, Array<String>)

    a list of configuration sections. It defaults to the Syskit::TaskConfigurationManager.syskit_tasksyskit_task.conf

  • override (Boolean)

    if true, the various selected sections can override each other. Otherwise, that would generate an error



29
30
31
32
33
34
35
36
37
# File 'lib/syskit/task_configuration_manager.rb', line 29

def apply(syskit_task, conf: syskit_task.conf, override: false)
    syskit_task.properties.each do |p|
        if (existing = p.value)
            existing.apply_changes_from_converted_types
            existing.invalidate_changes_from_converted_types
        end
    end
    super(syskit_task, conf, override)
end

#cache_dirObject

The cache directory used by the Syskit app to speed up configuration loading



108
109
110
# File 'lib/syskit/task_configuration_manager.rb', line 108

def cache_dir
    File.join(app.app_dir, 'config', 'orogen', '.cache')
end

#changed_on_disk?Boolean

Tests whether the file changed on disk, i.e. whether reload will do something

Returns:

  • (Boolean)


83
84
85
86
87
88
# File 'lib/syskit/task_configuration_manager.rb', line 83

def changed_on_disk?
    if conf_file = existing_configuration_file
        stat = File.stat(conf_file)
        conf_file != @loaded_file || stat != @loaded_file_stat
    end
end

#existing_configuration_file(local_only: false) ⇒ String?

Returns the path to an existing configuration file

Parameters:

  • local_only (Boolean)

    whether the search should restrict itself to the current Roby app or should include the inherited apps as well

Returns:

  • (String, nil)

    the path found or nil if no file was found



44
45
46
47
48
49
50
51
52
53
# File 'lib/syskit/task_configuration_manager.rb', line 44

def existing_configuration_file(local_only: false)
    return if !orogen_model.name

    local_option = Hash.new
    if local_only
        local_option[:path] = [app.app_dir]
    end
    app.find_file('config', 'orogen', 'ROBOT', "#{orogen_model.name}.yml",
                  order: :specific_first, all: false, **local_option)
end

#extract_from_taskObject

Extract the configuration from a running task



17
18
# File 'lib/syskit/task_configuration_manager.rb', line 17

def extract_from_task
end

#has_configuration_file?(local_only: false) ⇒ Boolean

Tests whether there is a configuration file for this model

Returns:

  • (Boolean)


56
57
58
# File 'lib/syskit/task_configuration_manager.rb', line 56

def has_configuration_file?(local_only: false)
    !!existing_configuration_file(local_only: local_only)
end

#load_from_yaml(path, cache_dir: self.cache_dir) ⇒ Object



112
113
114
115
# File 'lib/syskit/task_configuration_manager.rb', line 112

def load_from_yaml(path, cache_dir: self.cache_dir)
    FileUtils.mkdir_p self.cache_dir
    super
end

#orogen_modelObject



8
# File 'lib/syskit/task_configuration_manager.rb', line 8

def orogen_model; syskit_model.orogen_model end

#reloadArray<String>

Loads or reload the configuration for this task from disk

Returns:

  • (Array<String>)

    a list of configuration sections that have been modified



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/syskit/task_configuration_manager.rb', line 94

def reload
    if conf_file = existing_configuration_file
        stat = File.stat(conf_file)
        app.isolate_load_errors("could not load oroGen configuration file #{conf_file}") do
            @loaded_file = conf_file
            @loaded_file_stat = stat
            load_from_yaml(conf_file)
        end
    else
        Array.new
    end
end

#save(section_name, file: nil, replace: false) ⇒ void

This method returns an undefined value.

Save a configuration section to file

Note that it does NOT extract the configuration from the running task(s), it only saves the state of the configuration as currently stored in the manager

Parameters:

  • section_name (String)

    the section that should be saved

  • file (String)

    the file to save into. It defaults to saving at the standard location in this Roby app

  • replace (Boolean)

    if true, existing sections that have been changed (and all their custom comments) will be removed by the operation. If false, the new sections are appended (which also means that duplicate sections will exist in the file)



74
75
76
77
78
79
# File 'lib/syskit/task_configuration_manager.rb', line 74

def save(section_name, file: nil, replace: false)
    path = file ||
        existing_configuration_file(local_only: true) ||
        File.join(Roby.app_dir, 'config', 'orogen', "#{orogen_model.name}.yml")
    super(section_name, path, replace: replace)
end