Class: Orocos::Async::EventListener

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/async/object_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, event, use_last_value = true, &block) ⇒ EventListener

Returns a new instance of EventListener



7
8
9
10
11
12
13
14
15
16
# File 'lib/orocos/async/object_base.rb', line 7

def initialize(obj,event,use_last_value=true,&block)
    @block = block
    if !obj
        raise ArgumentError, "no object given"
    end
    @obj = obj
    @event = event
    @use_last_value = use_last_value
    @last_args
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event



4
5
6
# File 'lib/orocos/async/object_base.rb', line 4

def event
  @event
end

#last_argsObject (readonly)

Returns the value of attribute last_args



5
6
7
# File 'lib/orocos/async/object_base.rb', line 5

def last_args
  @last_args
end

Instance Method Details

#call(*args) ⇒ Object

calls the callback



49
50
51
52
# File 'lib/orocos/async/object_base.rb', line 49

def call(*args)
    @last_args = args
    @block.call *args
end

#listening?Boolean

return true if the listener is listing to the event

Returns:

  • (Boolean)


44
45
46
# File 'lib/orocos/async/object_base.rb', line 44

def listening?
    @obj.listener?(self)
end

#pretty_print(pp) ⇒ Object

:nodoc:



24
25
26
# File 'lib/orocos/async/object_base.rb', line 24

def pretty_print(pp) # :nodoc:
    pp.text "EventListener #{@event}"
end

#start(use_last_value = @use_last_value) ⇒ Object

start listing to the event



36
37
38
39
40
# File 'lib/orocos/async/object_base.rb', line 36

def start(use_last_value = @use_last_value)
    @use_last_value = use_last_value
    @obj.add_listener(self)
    self
end

#stopObject

stop listing to the event



29
30
31
32
33
# File 'lib/orocos/async/object_base.rb', line 29

def stop
    @last_args = nil
    @obj.remove_listener(self)
    self
end

#use_last_value?Boolean

returns true if the listener shall be called with the last available value when started

Returns:

  • (Boolean)


20
21
22
# File 'lib/orocos/async/object_base.rb', line 20

def use_last_value?
    !!@use_last_value
end