Class: Orocos::AttributeBase

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/task_context_base.rb

Overview

This class represents both RTT attributes and properties

Direct Known Subclasses

TaskContextAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, name, orocos_type_name) ⇒ AttributeBase

Returns a new instance of AttributeBase.


22
23
24
25
26
# File 'lib/orocos/task_context_base.rb', line 22

def initialize(task, name, orocos_type_name)
    @task, @name = task, name
    @orocos_type_name = orocos_type_name
    ensure_type_available(:fallback_to_null_type => true)
end

Instance Attribute Details

#log_portObject

If set, this is an input port object in which new values set from within Ruby are sent


18
19
20
# File 'lib/orocos/task_context_base.rb', line 18

def log_port
  @log_port
end

#log_streamObject

If set, this is a Pocolog::DataStream object in which new values set from within Ruby are set


15
16
17
# File 'lib/orocos/task_context_base.rb', line 15

def log_stream
  @log_stream
end

#nameObject (readonly)

The property/attribute name


10
11
12
# File 'lib/orocos/task_context_base.rb', line 10

def name
  @name
end

#orocos_type_nameObject (readonly)

The type name as registered in the orocos type system


20
21
22
# File 'lib/orocos/task_context_base.rb', line 20

def orocos_type_name
  @orocos_type_name
end

#taskObject (readonly)

The underlying TaskContext instance


8
9
10
# File 'lib/orocos/task_context_base.rb', line 8

def task
  @task
end

#typeObject (readonly)

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


12
13
14
# File 'lib/orocos/task_context_base.rb', line 12

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object


40
41
42
# File 'lib/orocos/task_context_base.rb', line 40

def ==(other)
    name == other.name && task == other.task
end

#docObject


105
106
107
108
109
110
# File 'lib/orocos/task_context_base.rb', line 105

def doc
    if task.model
        property = task.model.find_property(name)
        property.doc if property
    end
end

#doc?Boolean

Returns:

  • (Boolean)

101
102
103
# File 'lib/orocos/task_context_base.rb', line 101

def doc?
    (doc && !doc.empty?)
end

#ensure_type_available(options = Hash.new) ⇒ Object


51
52
53
54
55
# File 'lib/orocos/task_context_base.rb', line 51

def ensure_type_available(options = Hash.new)
    if !type || type.null?
        @type = Orocos.find_type_by_orocos_type_name(@orocos_type_name, options)
    end
end

#full_nameObject


29
30
31
# File 'lib/orocos/task_context_base.rb', line 29

def full_name
    "#{task.name}.#{name}"
end

#log_current_value(timestamp = Time.now) ⇒ Object

Write the current value of the property or attribute to #log_stream


79
80
81
# File 'lib/orocos/task_context_base.rb', line 79

def log_current_value(timestamp = Time.now)
    log_value(read)
end

#log_metadataObject


44
45
46
47
48
49
# File 'lib/orocos/task_context_base.rb', line 44

def 
    Hash['rock_task_model' => (task.model.name || ''),
        'rock_task_name' => task.name,
        'rock_task_object_name' => name,
        'rock_orocos_type_name' => orocos_type_name]
end

#log_value(value, timestamp = Time.now) ⇒ Object


83
84
85
86
87
88
89
90
# File 'lib/orocos/task_context_base.rb', line 83

def log_value(value, timestamp = Time.now)
    if log_stream
        log_stream.write(timestamp, timestamp, value)
    end
    if log_port
        log_port.write(value)
    end
end

#new_sampleObject


92
93
94
95
# File 'lib/orocos/task_context_base.rb', line 92

def new_sample
    ensure_type_available
    type.new
end

#pretty_print(pp) ⇒ Object

:nodoc:


97
98
99
# File 'lib/orocos/task_context_base.rb', line 97

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

#raw_readObject


57
58
59
60
61
62
# File 'lib/orocos/task_context_base.rb', line 57

def raw_read
    ensure_type_available
    value = type.new
    do_read(@orocos_type_name, value)
    value
end

#readObject

Read the current value of the property/attribute


65
66
67
# File 'lib/orocos/task_context_base.rb', line 65

def read
    Typelib.to_ruby(raw_read)
end

#type_nameObject

Deprecated.

Returns the name of the typelib type. Use #type.name instead.


35
36
37
38
# File 'lib/orocos/task_context_base.rb', line 35

def type_name
    ensure_type_available
    type.name
end

#write(value, timestamp = Time.now, direct: false) ⇒ Object

Sets a new value for the property/attribute


70
71
72
73
74
75
76
# File 'lib/orocos/task_context_base.rb', line 70

def write(value, timestamp = Time.now, direct: false)
    ensure_type_available
    value = Typelib.from_ruby(value, type)
    do_write(@orocos_type_name, value, direct: direct)
    log_value(value, timestamp)
    value
end