class Roby::Interface::Async::NewJobListener

Listener object for {Interface#on_job}

Attributes

action_name[R]

@return [String,nil] the name of the action whose job we are

tracking. If nil, tracks all actions.
block[R]

@return [#call] the notification callback

interface[R]

@return [Interface] the interface we are connected to

last_job_id[R]

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

new(interface, action_name, block) click to toggle source
# 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(job) click to toggle source

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
ignored(job) click to toggle source

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
matches?(job) click to toggle source

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
reset() click to toggle source

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
seen_job_with_id?(job_id) click to toggle source

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() click to toggle source

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() click to toggle source

Stop listening for jobs

# File lib/roby/interface/async/new_job_listener.rb, line 73
def stop
    interface.remove_new_job_listener(self)
end