Class: Syskit::InputWriter

Inherits:
PortAccessor show all
Defined in:
lib/syskit/port.rb

Overview

A data writer for a port attached to a component

Instance Attribute Summary collapse

Attributes inherited from PortAccessor

#actual_port, #policy, #port, #resolved_port

Instance Method Summary collapse

Methods inherited from PortAccessor

#initialize

Constructor Details

This class inherits a constructor from Syskit::PortAccessor

Instance Attribute Details

#writerOrocos::InputWriter (readonly)

The actual data writer itself

Returns:

  • (Orocos::InputWriter)


363
364
365
# File 'lib/syskit/port.rb', line 363

def writer
  @writer
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/syskit/port.rb', line 373

def connected?
    writer && writer.connected?
end

#disconnectObject



377
378
379
380
381
382
383
384
385
386
# File 'lib/syskit/port.rb', line 377

def disconnect
    @disconnected = true
    if actual_writer = self.writer
        actual_port.component.execution_engine.promise(description: "disconnect #{self}") do
            begin actual_writer.disconnect
            rescue Orocos::ComError
            end
        end.on_success { @writer = nil }.execute
    end
end

#modelObject



365
366
367
# File 'lib/syskit/port.rb', line 365

def model
    Models::InputWriter.new(port.model, policy)
end

#new_sampleObject



408
409
410
# File 'lib/syskit/port.rb', line 408

def new_sample
    @port.new_sample
end

#ready?Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/syskit/port.rb', line 369

def ready?
    writer && actual_port.component.running?
end

#resolve(main, port) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolves the underlying writer object



391
392
393
# File 'lib/syskit/port.rb', line 391

def resolve(main, port)
    super(main, port, :writer) { |w| @writer = w }
end

#write(sample) ⇒ Boolean

Write a sample on the associated port

Returns:

  • (Boolean)

    true if the writer was in a state that allowed writing to the actual task, false otherwise



399
400
401
402
403
404
405
406
# File 'lib/syskit/port.rb', line 399

def write(sample)
    if ready?
        writer.write(sample)
    else
        Typelib.from_ruby(sample, port.type)
        nil
    end
end