class Roby::Interface::Async::NewJobListener
Listener object for {Interface#on_job}
Attributes
@return [String,nil] the name of the action whose job we are
tracking. If nil, tracks all actions.
@return [#call] the notification callback
@return [Interface] the interface we are connected to
The last ID of the jobs received by this listener.
This is used to avoid double-notifications of new jobs. The assumption is that the job IDs are ever-increasing and that they are fed in-order to {#call}.
Public Class Methods
# File lib/roby/interface/async/new_job_listener.rb, line 21 def initialize(interface, action_name, block) @interface = interface @action_name = action_name @block = block @last_job_id = -1 end
Public Instance Methods
Call the listener for the given job
@param [JobMonitor] job
# File lib/roby/interface/async/new_job_listener.rb, line 53 def call(job) @last_job_id = job.job_id block.call(job) end
Tell this listener that the given job was received, but ignored.
This is an optimization to avoid re-considering this listener for the given job
# File lib/roby/interface/async/new_job_listener.rb, line 63 def ignored(job) @last_job_id = job.job_id end
Tests whether the provided job matches what this listener wants
# File lib/roby/interface/async/new_job_listener.rb, line 46 def matches?(job) !action_name || (job.action_name == action_name) end
Resets the listener so that it can be used on a new connection
This currently only resets {#last_job_id}
# File lib/roby/interface/async/new_job_listener.rb, line 31 def reset @last_job_id = -1 end
Tests whether this listener has already seen the job with the given ID
@param [Integer] job_id @see last_job_id
# File lib/roby/interface/async/new_job_listener.rb, line 40 def seen_job_with_id?(job_id) last_job_id >= job_id end
Start listening for jobs
# File lib/roby/interface/async/new_job_listener.rb, line 68 def start interface.add_new_job_listener(self) end
Stop listening for jobs
# File lib/roby/interface/async/new_job_listener.rb, line 73 def stop interface.remove_new_job_listener(self) end