class Roby::Schedulers::State

Objects representing the reports from a scheduler object

They are saved in logs, and can also be listened to through {Interface::Interface}

Attributes

actions[RW]

The list of actions that have been taken by the scheduler

@return [{Task=>}] a mapping from the task on which

an action was performed, to a list of messages and objects. The message
can contain %N placeholders which will be replaced by the
corresponding element from the array
called_generators[RW]

The list of event generators triggered by the scheduler

@return [EventGenerator]

non_scheduled_tasks[RW]

The list of tasks that have been considered for scheduling, but could not be scheduled, along with the reason

@return [{Task=>}] a mapping from the task that was

not scheduled, to a list of messages and objects. The message
can contain %N placeholders which will be replaced by the
corresponding element from the array
pending_non_executable_tasks[RW]

Tasks that are pending in the plan, but are not executable

Public Class Methods

format_message_into_string(msg, *args) click to toggle source

Formats a message stored in {#non_scheduled_tasks} into a plain string

# File lib/roby/schedulers/state.rb, line 116
def self.format_message_into_string(msg, *args)
    args.each_with_index.inject(msg) do |msg, (a, i)|
        a = if a.respond_to?(:map)
                a.map(&:to_s).join(", ")
            else a.to_s
            end
        msg.gsub "%#{i + 1}", a
    end
end
new() click to toggle source
# File lib/roby/schedulers/state.rb, line 30
def initialize
    @pending_non_executable_tasks = Set.new
    @called_generators = Set.new
    @non_scheduled_tasks = Hash.new { |h, k| h[k] = Set.new }
    @actions = Hash.new { |h, k| h[k] = Set.new }
end

Public Instance Methods

merge!(state) click to toggle source

Add information contained in 'state' to this object

# File lib/roby/schedulers/state.rb, line 54
def merge!(state)
    pending_non_executable_tasks.merge(state.pending_non_executable_tasks)
    called_generators.merge(state.called_generators)
    non_scheduled_tasks.merge!(state.non_scheduled_tasks) do |task, msg0, msg1|
        msg0.merge(msg1)
    end
    actions.merge!(state.actions) do |task, msg0, msg1|
        msg0.merge(msg1)
    end
end
pretty_print(pp) click to toggle source
# File lib/roby/schedulers/state.rb, line 65
def pretty_print(pp)
    if !pending_non_executable_tasks.empty?
        has_text = true
        pp.text "Pending non-executable tasks"
        pp.nest(2) do
            pending_non_executable_tasks.each do |args|
                pp.breakable
                pp.text self.class.format_message_into_string(*args)
            end
        end
    end

    if !non_scheduled_tasks.empty?
        pp.breakable if has_text
        has_text = true
        pp.text "Non scheduled tasks"
        pp.nest(2) do
            non_scheduled_tasks.each do |task, msgs|
                pp.breakable
                task.pretty_print(pp)
                pp.nest(2) do
                    msgs.each do |msg, *args|
                        pp.breakable
                        pp.text self.class.format_message_into_string(msg, task, *args)
                    end
                end
            end
        end
    end

    if !actions.empty?
        pp.breakable if has_text
        has_text = true
        pp.text "Actions taken"
        pp.nest(2) do
            actions.each do |task, msgs|
                pp.breakable
                task.pretty_print(pp)
                pp.nest(2) do
                    msgs.each do |msg, *args|
                        pp.breakable
                        pp.text self.class.format_message_into_string(msg, task, *args)
                    end
                end
            end
        end
    end
end
report_action(msg, task, *args) click to toggle source
# File lib/roby/schedulers/state.rb, line 49
def report_action(msg, task, *args)
    actions[task] << [msg, *args]
end
report_holdoff(msg, task, *args) click to toggle source
# File lib/roby/schedulers/state.rb, line 45
def report_holdoff(msg, task, *args)
    non_scheduled_tasks[task] << [msg, *args]
end
report_pending_non_executable_task(msg, task, *args) click to toggle source
# File lib/roby/schedulers/state.rb, line 37
def report_pending_non_executable_task(msg, task, *args)
    pending_non_executable_tasks << [msg, task, *args]
end
report_trigger(generator) click to toggle source
# File lib/roby/schedulers/state.rb, line 41
def report_trigger(generator)
    called_generators << generator
end