Class: Orocos::Log::Property

Inherits:
InterfaceObject show all
Defined in:
lib/orocos/log/task_context.rb

Overview

Simulated Property based on a configuration log file It is automatically replayed if at least one OutputPort of the task is replayed

Instance Attribute Summary collapse

Attributes inherited from InterfaceObject

#name, #stream, #type, #type_name

Instance Method Summary collapse

Methods inherited from InterfaceObject

#guess_object_name, #guess_orocos_type_name

Constructor Details

#initialize(task, stream) ⇒ Property

Returns a new instance of Property



540
541
542
543
544
545
546
# File 'lib/orocos/log/task_context.rb', line 540

def initialize(task, stream)
    super(stream)

    @task = task
    @current_data = nil
    @notify_blocks =[]
end

Instance Attribute Details

#taskObject (readonly)

The underlying TaskContext instance



538
539
540
# File 'lib/orocos/log/task_context.rb', line 538

def task
  @task
end

#trackedObject

true –> this property shall be replayed



536
537
538
# File 'lib/orocos/log/task_context.rb', line 536

def tracked
  @tracked
end

Instance Method Details

#aligned?Boolean

returns true if Log::Replay is aligned

Returns:

  • (Boolean)


555
556
557
# File 'lib/orocos/log/task_context.rb', line 555

def aligned?
    task.log_replay.aligned?
end

#doc?Boolean

Returns:

  • (Boolean)


559
560
561
# File 'lib/orocos/log/task_context.rb', line 559

def doc?
    false
end

#full_nameObject

Give the full name for this property. It is the stream name.



616
617
618
# File 'lib/orocos/log/task_context.rb', line 616

def full_name
    stream.name
end

#metadataObject

returns the metadata associated with the underlying stream



625
626
627
# File 'lib/orocos/log/task_context.rb', line 625

def 
    stream.
end

#new_sampleObject



598
599
600
# File 'lib/orocos/log/task_context.rb', line 598

def new_sample
    type.new
end

#notify(&block) ⇒ Object

registers a code block which will be called when the property changes



594
595
596
# File 'lib/orocos/log/task_context.rb', line 594

def notify(&block)
    @notify_blocks << block
end

#number_of_samplesObject

Returns the number of samples for the property.



611
612
613
# File 'lib/orocos/log/task_context.rb', line 611

def number_of_samples
    return @stream.size
end

#on_change(&block) ⇒ Object

registers a code block which will be called when the property changes



585
586
587
588
589
590
# File 'lib/orocos/log/task_context.rb', line 585

def on_change(&block)
    self.tracked = true
    notify do
        block.call(read)
    end
end

#orocos_type_nameObject



602
603
604
605
606
607
608
# File 'lib/orocos/log/task_context.rb', line 602

def orocos_type_name
    if  && .has_key?(:rock_orocos_type_name)
        [:rock_orocos_type_name]
    else
        type_name
    end
end

#pretty_print(pp) ⇒ Object

:nodoc:



620
621
622
# File 'lib/orocos/log/task_context.rb', line 620

def pretty_print(pp) # :nodoc:
    pp.text "property #{name} (#{type.name})"
end

#raw_readObject



575
576
577
578
579
580
581
# File 'lib/orocos/log/task_context.rb', line 575

def raw_read
    if @sample_info && !@current_data
        stream, position = *@sample_info
        @current_data = stream.read_one_raw_data_sample(position)
    end
    @current_data
end

#readObject

Read the current value of the property/attribute



569
570
571
572
573
# File 'lib/orocos/log/task_context.rb', line 569

def read
    if sample = raw_read
        Typelib.to_ruby(sample)
    end
end

#update(sample_info) ⇒ Object



563
564
565
566
# File 'lib/orocos/log/task_context.rb', line 563

def update(sample_info)
    @current_data = nil
    @sample_info = sample_info
end

#used?Boolean

Returns:

  • (Boolean)


629
630
631
# File 'lib/orocos/log/task_context.rb', line 629

def used?
    tracked
end