Class: Roby::Log::Notifications
- Inherits:
-
DataDecoder
- Object
- DataDecoder
- Roby::Log::Notifications
- Defined in:
- lib/roby/log/notifications.rb
Constant Summary collapse
- GENERATOR_CALL_LIMIT =
0.1
Instance Attribute Summary collapse
-
#histories ⇒ Object
readonly
Returns the value of attribute histories.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Attributes inherited from DataDecoder
Instance Method Summary collapse
- #added_task(task) ⇒ Object
- #clear ⇒ Object
- #event(name, *args) ⇒ Object
-
#initialize(name) ⇒ Notifications
constructor
A new instance of Notifications.
- #process(data) ⇒ Object
- #removed_task(remote_id) ⇒ Object
Methods inherited from DataDecoder
Constructor Details
#initialize(name) ⇒ Notifications
15 16 17 18 19 |
# File 'lib/roby/log/notifications.rb', line 15 def initialize(name) @tasks = Hash.new @histories = Hash.new { |h, k| h[k] = Array.new } super(name) end |
Instance Attribute Details
#histories ⇒ Object (readonly)
Returns the value of attribute histories.
14 15 16 |
# File 'lib/roby/log/notifications.rb', line 14 def histories @histories end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
12 13 14 |
# File 'lib/roby/log/notifications.rb', line 12 def tasks @tasks end |
Instance Method Details
#added_task(task) ⇒ Object
21 22 23 24 25 |
# File 'lib/roby/log/notifications.rb', line 21 def added_task(task) task.remote_siblings.each_value do |id| tasks[id] = task end end |
#clear ⇒ Object
33 34 35 36 37 38 |
# File 'lib/roby/log/notifications.rb', line 33 def clear super @tasks.clear @histories.clear end |
#event(name, *args) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/roby/log/notifications.rb', line 94 def event(name, *args) displays.each do |display| if display.respond_to?(name) display.send(name, *args) end end end |
#process(data) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/roby/log/notifications.rb', line 41 def process(data) data.each_slice(4) do |m, sec, usec, args| time = Time.at(sec, usec) case m.to_s when /inserted/ task = tasks[args[1]] task.mission = true event :added_mission, args[0], task when /discarded/ task = tasks[args[1]] task.mission = false event :discarded_mission, args[0], task when /discovered_tasks/ args[1].each { |t| added_task(t) } when /finalized_task/ id = args[1] task = tasks[id] if histories[id].empty? event :finalized_pending, time, task end histories.delete(task) removed_task(args[1]) when /generator_calling/ @current_call = [time, args[0]] when /generator_called/ if @current_call[1] == args[0] duration = time - @current_call[0] if duration > GENERATOR_CALL_LIMIT event :overly_long_call, time, duration, tasks[args[0].task], args[0].symbol, args[1] end end when /exception/ error, involved_tasks = *args involved_tasks = involved_tasks.map { |id| tasks[id] } event m, time, error, involved_tasks when /generator_fired/ generator = args[0] if generator.respond_to?(:task) histories[generator.task] << args if generator.symbol == :failed event :failed_task, time, tasks[generator.task], histories[generator.task] end end end end end |
#removed_task(remote_id) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/roby/log/notifications.rb', line 26 def removed_task(remote_id) task = tasks.delete(remote_id) task.remote_siblings.each_value do |id| tasks.delete(id) end end |