Class: Syskit::TaskConfigurationManager
- Inherits:
-
Orocos::TaskConfigurations
- Object
- Orocos::TaskConfigurations
- Syskit::TaskConfigurationManager
- 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
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#syskit_model ⇒ Object
readonly
Returns the value of attribute syskit_model.
Instance Method Summary collapse
-
#apply(syskit_task, conf: syskit_task.conf, override: false) ⇒ void
Applies a configuration to the given component instance.
-
#cache_dir ⇒ Object
The cache directory used by the Syskit app to speed up configuration loading.
-
#changed_on_disk? ⇒ Boolean
Tests whether the file changed on disk, i.e.
-
#existing_configuration_file(local_only: false) ⇒ String?
Returns the path to an existing configuration file.
-
#extract_from_task ⇒ Object
Extract the configuration from a running task.
-
#has_configuration_file?(local_only: false) ⇒ Boolean
Tests whether there is a configuration file for this model.
-
#initialize(app, syskit_model) ⇒ TaskConfigurationManager
constructor
A new instance of TaskConfigurationManager.
- #load_from_yaml(path, cache_dir: self.cache_dir) ⇒ Object
- #orogen_model ⇒ Object
-
#reload ⇒ Array<String>
Loads or reload the configuration for this task from disk.
-
#save(section_name, file: nil, replace: false) ⇒ void
Save a configuration section to file.
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
#app ⇒ Object (readonly)
Returns the value of attribute app
5 6 7 |
# File 'lib/syskit/task_configuration_manager.rb', line 5 def app @app end |
#syskit_model ⇒ Object (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
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_dir ⇒ Object
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
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
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_task ⇒ Object
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
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_model ⇒ Object
8 |
# File 'lib/syskit/task_configuration_manager.rb', line 8 def orogen_model; syskit_model.orogen_model end |
#reload ⇒ Array<String>
Loads or reload the configuration for this task from disk
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
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 |