class Orocos::Async::CORBA::InputPort

Public Class Methods

new(*args) click to toggle source
Calls superclass method Orocos::Async::CORBA::Port.new
# File lib/orocos/async/ports.rb, line 400
def initialize(*args)
    super
    @write_blocks = []
end

Public Instance Methods

options=(options) click to toggle source
Calls superclass method
# File lib/orocos/async/ports.rb, line 437
def options=(options)
    super
    @global_writer = nil
end
reachable!(port,options = Hash.new) click to toggle source
Calls superclass method Orocos::Async::CORBA::Port#reachable!
# File lib/orocos/async/ports.rb, line 425
def reachable!(port,options = Hash.new)
    super
    #TODO we have to call reachable on all writer
    if @global_writer
        orig_writer(@global_writer.policy) do |writer,error|
            unless error
                @global_writer.reachable!(writer)
            end
        end
    end
end
write(sample,options=@options,&block) click to toggle source
# File lib/orocos/async/ports.rb, line 442
def write(sample,options=@options,&block)
    if @options != options
        Orocos.warn "Changing global writer policy for #{full_name} from #{@options} to #{options}" unless @options.empty?
        self.options = options
    end
    if block
        if @global_writer.respond_to? :write
            @global_writer.write(sample) do |result,error|
                if block.arity == 2
                    block.call result,error
                elsif !error
                    block.call result
                end
            end
        # writer is requested waiting for writer obj
        elsif @global_writer
            # store code block until writer is obtained
            @write_blocks << [block,sample]
            @global_writer
        # create new global writer
        else
            @write_blocks << [block,sample]
            @global_writer ||= writer(@options) do |writer,error|
                if error
                    block.call result,error if block.arity == 2
                else
                    @global_writer = writer # overwrites @global_writer before that it is a ThreadPool::Task
                    @global_writer.period = @options[:period] if @options.has_key? :period
                    @write_blocks.each do |b,s|
                        write(s,&b)
                    end
                    @write_blocks = []
                end
            end
        end
    else
        raise NotImplementedError, "Async::InputPort#write(sample) not implemented, provide a completion block as e.g. port.write(sample) { }"
    end
end
writer(options = Hash.new,&block) click to toggle source
# File lib/orocos/async/ports.rb, line 405
def writer(options = Hash.new,&block)
    if block
        orig_writer(options) do |writer,error|
            unless error
                writer = InputWriter.new(self,writer)
                proxy_event(writer,:error)
            end
            if block.arity == 2
                block.call(writer,error)
            elsif !error
                block.call(writer)
            end
        end
    else
        writer = InputWriter.new(self,orig_writer(options))
        proxy_event(writer,:error)
        writer
    end
end