Class: Orocos::Async::Log::OutputPort

Inherits:
ObjectBase
  • Object
show all
Extended by:
Utilrb::EventLoop::Forwardable
Defined in:
lib/orocos/async/log/ports.rb

Instance Attribute Summary collapse

Attributes inherited from ObjectBase

#emitting, #event_loop, #name, #options, #pending_adds

Instance Method Summary collapse

Methods inherited from ObjectBase

#add_listener, define_event, define_events, #disable_emitting, #event, event_names, #event_names, #invalidate_delegator!, #listener?, #listeners, #number_of_listeners, #on_event, #proxy_event, #reachable!, #reachable?, #remove_all_listeners, #remove_listener, #remove_proxy_event, #unreachable!, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait

Constructor Details

#initialize(async_task, port, options = Hash.new) ⇒ OutputPort

Returns a new instance of OutputPort



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/orocos/async/log/ports.rb', line 66

def initialize(async_task,port,options=Hash.new)
    @options ||= options
    @readers ||= Array.new
    @task = async_task
    super(port.name,async_task.event_loop)

    # do not queue reachable event no listeners are registered so far
    disable_emitting do 
        reachable! port
    end
    @on_raw_data = port.on_raw_data do |sample, _|
        emit_raw_data sample
    end
    @on_raw_data.disable

    @on_data = port.on_data do |sample, _|
        emit_data sample
    end
    @on_data.disable
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task



64
65
66
# File 'lib/orocos/async/log/ports.rb', line 64

def task
  @task
end

Instance Method Details

#last_sampleObject



99
100
101
# File 'lib/orocos/async/log/ports.rb', line 99

def last_sample
    @delegator_obj.read
end

#on_data(policy = Hash.new, &block) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/orocos/async/log/ports.rb', line 152

def on_data(policy = Hash.new,&block)
    @options = if policy.empty?
                   @options
               elsif @options.empty? && !@global_reader
                   policy
               elsif @options == policy
                   @options
               else
                   Orocos.warn "Log::OutputPort #{full_name} cannot emit :data with different policies."
                   Orocos.warn "The current policy is: #{@options}."
                   Orocos.warn "Ignoring policy: #{policy}."
                   @options
               end
    on_event :data,&block
end

#periodObject



140
141
142
143
144
145
146
# File 'lib/orocos/async/log/ports.rb', line 140

def period
    if @options.has_key?(:period)
        @options[:period]
    else
        OutputReader.default_period
    end
end

#period=(value) ⇒ Object



148
149
150
# File 'lib/orocos/async/log/ports.rb', line 148

def period=(value)
    @options[:period] = value
end

#raw_last_sampleObject



103
104
105
# File 'lib/orocos/async/log/ports.rb', line 103

def raw_last_sample
    @delegator_obj.raw_read
end

#reader(options = Hash.new, &block) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/orocos/async/log/ports.rb', line 130

def reader(options = Hash.new,&block)
    if block
        orig_reader(policy) do |reader|
            block.call OutputReader.new(self,reader,options)
        end
    else
        OutputReader.new(self,orig_reader(policy),options)
    end
end

#really_add_listener(listener) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/orocos/async/log/ports.rb', line 107

def really_add_listener(listener)
    return super unless listener.use_last_value?

    if listener.event == :data
        sample = last_sample
        if sample
            event_loop.once do
                listener.call sample
            end
        end
        @on_data.enable
    elsif listener.event == :raw_data
        sample = raw_last_sample
        if sample
            event_loop.once do
                listener.call sample
            end
        end
        @on_raw_data.enable
    end
    super
end

#to_async(options = Hash.new) ⇒ Object



91
92
93
# File 'lib/orocos/async/log/ports.rb', line 91

def to_async(options=Hash.new)
    self
end

#to_proxy(options = Hash.new) ⇒ Object



95
96
97
# File 'lib/orocos/async/log/ports.rb', line 95

def to_proxy(options=Hash.new)
    task.to_proxy(options).port(name).wait
end

#type?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/orocos/async/log/ports.rb', line 87

def type?
    true
end