Class: Syskit::Property

Inherits:
Object show all
Defined in:
lib/syskit/property.rb

Overview

Syskit-side representation of a property

Writing on such an object does not write on the task. The write is performed either at configuration time, or when #commit_properties is called

Direct Known Subclasses

LiveProperty

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Property

Returns a new instance of Property



41
42
43
44
45
46
47
48
# File 'lib/syskit/property.rb', line 41

def initialize(name, type)
    @name  = name
    @type  = type
    @remote_value = nil
    @value = nil
    @log_stream = nil
    @log_metadata = Hash.new
end

Instance Attribute Details

#log_metadataObject (readonly)

The metadata for the log stream



30
31
32
# File 'lib/syskit/property.rb', line 30

def 
  @log_metadata
end

#log_streamnil, #write

The stream on which this property is logged

Returns:



34
35
36
# File 'lib/syskit/property.rb', line 34

def log_stream
  @log_stream
end

#nameString (readonly)

This property's name

Returns:

  • (String)


11
12
13
# File 'lib/syskit/property.rb', line 11

def name
  @name
end

#remote_valueTypelib::Type (readonly)

The value of this property on the component side

Returns:

  • (Typelib::Type)


21
22
23
# File 'lib/syskit/property.rb', line 21

def remote_value
  @remote_value
end

#typeString (readonly)

This property's type

Returns:

  • (String)


16
17
18
# File 'lib/syskit/property.rb', line 16

def type
  @type
end

#valueTypelib::Type (readonly)

The value that would be applied on this property next time TaskContext#commit_properties is called

Returns:

  • (Typelib::Type)


27
28
29
# File 'lib/syskit/property.rb', line 27

def value
  @value
end

Instance Method Details

#clear_valueObject

Remove the current value

This will in effect ensure that the property won't get written



108
109
110
# File 'lib/syskit/property.rb', line 108

def clear_value
    @value = nil
end

#has_value?Boolean

Whether a value has been set with #write

Returns:

  • (Boolean)


51
52
53
# File 'lib/syskit/property.rb', line 51

def has_value?
    !!@value
end

#logged?Boolean

Whether this property is being logged

Returns:

  • (Boolean)


37
38
39
# File 'lib/syskit/property.rb', line 37

def logged?
    !!log_stream
end

#raw_readObject

Read the current Syskit-side value of this property as a Typelib object

This is not necessarily the value on the component side



79
80
81
# File 'lib/syskit/property.rb', line 79

def raw_read
    @value
end

#raw_write(value, _timestap = nil) ⇒ Object

Update this property with a Typelib object

The object's type and value will not be checked



98
99
100
101
102
103
# File 'lib/syskit/property.rb', line 98

def raw_write(value, _timestap = nil)
    if value.class != type
        raise ArgumentError, "expected a typelib value of type #{type}, but got #{value.class}"
    end
    @value = value
end

#readObject

Read the current Syskit-side value of this property

This is not necessarily the value on the component side



71
72
73
# File 'lib/syskit/property.rb', line 71

def read
    Typelib.to_ruby(@value)
end

#update_log(timestamp = Time.now, value = self.remote_value) ⇒ Object

Update the log stream with the currently none remote value



113
114
115
116
117
# File 'lib/syskit/property.rb', line 113

def update_log(timestamp = Time.now, value = self.remote_value)
    if logged?
        log_stream.write(timestamp, timestamp, value)
    end
end

#update_log_metadata(metadata) ⇒ Object

Add metadata to #log_metadata



56
57
58
# File 'lib/syskit/property.rb', line 56

def ()
    .merge!()
end

#update_remote_value(value) ⇒ Object

Update the known value for the property on the node side

Parameters:

  • value (Object)

    a valid value for the property. It will be converted to the propertie's own type



64
65
66
# File 'lib/syskit/property.rb', line 64

def update_remote_value(value)
    @remote_value = Typelib.from_ruby(value, type).dup
end

#write(value, _timestamp = nil) ⇒ Object

Request updating this property with the given value

The property will be updated only at the task's configuration time, or when TaskContext#commit_properties is called.

Parameters:

  • value (Typelib::Type, Object)

    the property value

  • _timestamp (Time) (defaults to: nil)

    ignored, for compatibility with Orocos::Property



91
92
93
# File 'lib/syskit/property.rb', line 91

def write(value, _timestamp = nil)
    raw_write(Typelib.from_ruby(value, type))
end