Class: Orocos::Log::Property

Inherits:
Object
  • Object
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

Instance Method Summary collapse

Constructor Details

#initialize(task, stream) ⇒ Property

Returns a new instance of Property.


513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/orocos/log/task_context.rb', line 513

def initialize(task, stream)
    if !stream.respond_to?(:name) || !stream.respond_to?(:type) || !stream.respond_to?(:typename) || !stream.respond_to?(:metadata)
        raise "Cannot create Property out of #{stream.class}"
    end
    @stream = stream
    @name = stream.name.to_s.match(/\.(.*$)/)
    raise 'Stream name does not follow the convention TASKNAME.PROPERTYNAME' if @name == nil
    @name = @name[1]
    @type = stream.type
    @task = task
    @current_data = nil
    @type_name = stream.typename
    @notify_blocks =[]
end

Instance Attribute Details

#nameObject (readonly)

The property/attribute name


506
507
508
# File 'lib/orocos/log/task_context.rb', line 506

def name
  @name
end

#streamObject (readonly)

dedicated stream for simulating the port


510
511
512
# File 'lib/orocos/log/task_context.rb', line 510

def stream
  @stream
end

#taskObject (readonly)

The underlying TaskContext instance


504
505
506
# File 'lib/orocos/log/task_context.rb', line 504

def task
  @task
end

#trackedObject

true –> this property shall be replayed


502
503
504
# File 'lib/orocos/log/task_context.rb', line 502

def tracked
  @tracked
end

#typeObject (readonly)

The attribute type, as a subclass of Typelib::Type


508
509
510
# File 'lib/orocos/log/task_context.rb', line 508

def type
  @type
end

#type_nameObject (readonly)

Returns the value of attribute type_name


511
512
513
# File 'lib/orocos/log/task_context.rb', line 511

def type_name
  @type_name
end

Instance Method Details

#aligned?Boolean

returns true if Log::Replay is aligned

Returns:

  • (Boolean)

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

def aligned?
    task.log_replay.aligned?
end

#doc?Boolean

Returns:

  • (Boolean)

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

def doc?
    false
end

#full_nameObject

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


596
597
598
# File 'lib/orocos/log/task_context.rb', line 596

def full_name
    stream.name
end

#metadataObject

returns the metadata associated with the underlying stream


605
606
607
# File 'lib/orocos/log/task_context.rb', line 605

def 
    stream.
end

#new_sampleObject


578
579
580
# File 'lib/orocos/log/task_context.rb', line 578

def new_sample
    type.new
end

#notify(&block) ⇒ Object

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


574
575
576
# File 'lib/orocos/log/task_context.rb', line 574

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

#number_of_samplesObject

Returns the number of samples for the property.


591
592
593
# File 'lib/orocos/log/task_context.rb', line 591

def number_of_samples
    return @stream.size
end

#on_change(&block) ⇒ Object

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


565
566
567
568
569
570
# File 'lib/orocos/log/task_context.rb', line 565

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

#orocos_type_nameObject


582
583
584
585
586
587
588
# File 'lib/orocos/log/task_context.rb', line 582

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:


600
601
602
# File 'lib/orocos/log/task_context.rb', line 600

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

#raw_readObject


555
556
557
558
559
560
561
# File 'lib/orocos/log/task_context.rb', line 555

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


549
550
551
552
553
# File 'lib/orocos/log/task_context.rb', line 549

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

#update(sample_info) ⇒ Object


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

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

#used?Boolean

Returns:

  • (Boolean)

609
610
611
# File 'lib/orocos/log/task_context.rb', line 609

def used?
    tracked
end