Class: Orocos::Async::CORBA::InputPort
- Inherits:
-
Port
- Object
- ObjectBase
- Port
- Orocos::Async::CORBA::InputPort
- Defined in:
- lib/orocos/async/ports.rb
Instance Attribute Summary
Attributes inherited from Port
Attributes inherited from ObjectBase
#emitting, #event_loop, #name, #options, #pending_adds
Instance Method Summary collapse
-
#initialize(*args) ⇒ InputPort
constructor
A new instance of InputPort.
- #options=(options) ⇒ Object
- #reachable!(port, options = Hash.new) ⇒ Object
- #write(sample, options = @options, &block) ⇒ Object
- #writer(options = Hash.new, &block) ⇒ Object
Methods inherited from Port
#reachable?, #task, #to_async, #to_proxy, #unreachable!
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?, #really_add_listener, #remove_all_listeners, #remove_listener, #remove_proxy_event, #unreachable!, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait
Constructor Details
#initialize(*args) ⇒ InputPort
Returns a new instance of InputPort
400 401 402 403 |
# File 'lib/orocos/async/ports.rb', line 400 def initialize(*args) super @write_blocks = [] end |
Instance Method Details
#options=(options) ⇒ Object
437 438 439 440 |
# File 'lib/orocos/async/ports.rb', line 437 def () super @global_writer = nil end |
#reachable!(port, options = Hash.new) ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/orocos/async/ports.rb', line 425 def reachable!(port, = 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) ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/orocos/async/ports.rb', line 442 def write(sample,=@options,&block) if @options != Orocos.warn "Changing global writer policy for #{full_name} from #{@options} to #{}" unless @options.empty? self. = 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) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/orocos/async/ports.rb', line 405 def writer( = Hash.new,&block) if block orig_writer() 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()) proxy_event(writer,:error) writer end end |