Class: Orocos::Async::AttributeBaseProxy

Inherits:
ObjectBase
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/orocos/async/task_context_proxy.rb

Direct Known Subclasses

AttributeProxy, PropertyProxy

Instance Attribute Summary collapse

Attributes inherited from ObjectBase

#emitting, #event_loop, #name, #options, #pending_adds

Instance Method Summary collapse

Methods inherited from ObjectBase

#add_listener, define_event, define_events, #disable_emitting, #event, event_names, #event_names, #invalidate_delegator!, #listener?, #listeners, #number_of_listeners, #on_event, #proxy_event, #reachable?, #remove_all_listeners, #remove_listener, #remove_proxy_event, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait

Constructor Details

#initialize(task_proxy, attribute_name, options = Hash.new) ⇒ AttributeBaseProxy

Returns a new instance of AttributeBaseProxy



15
16
17
18
19
20
21
# File 'lib/orocos/async/task_context_proxy.rb', line 15

def initialize(task_proxy,attribute_name,options=Hash.new)
    @type = options.delete(:type)
    @options = options
    super(attribute_name,task_proxy.event_loop)
    @task_proxy = task_proxy
    @raw_last_sample = nil
end

Instance Attribute Details

#raw_last_sampleObject (readonly)

Returns the value of attribute raw_last_sample



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

def raw_last_sample
  @raw_last_sample
end

Instance Method Details

#full_nameObject



27
28
29
# File 'lib/orocos/async/task_context_proxy.rb', line 27

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

#last_sampleObject



49
50
51
# File 'lib/orocos/async/task_context_proxy.rb', line 49

def last_sample
    Typelib.to_ruby(@raw_last_sample) if @raw_last_sample
end

#new_sampleObject



45
46
47
# File 'lib/orocos/async/task_context_proxy.rb', line 45

def new_sample
    type.new
end

#on_change(policy = Hash.new, &block) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/orocos/async/task_context_proxy.rb', line 106

def on_change(policy = Hash.new,&block)
    @options = if policy.empty?
                   @options
               elsif @options.empty? && !valid_delegator?
                   policy
               elsif @options == policy
                   @options
               else
                   Orocos.warn "ProxyProperty #{full_name} cannot emit :change with different policies."
                   Orocos.warn "The current policy is: #{@options}."
                   Orocos.warn "Ignoring policy: #{policy}."
                   @options
               end
    on_event :change,&block
end

#on_raw_change(policy = Hash.new, &block) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/orocos/async/task_context_proxy.rb', line 122

def on_raw_change(policy = Hash.new,&block)
    @options = if policy.empty?
                   @options
               elsif @options.empty? && !valid_delegator?
                   policy
               elsif @options == policy
                   @options
               else
                   Orocos.warn "ProxyProperty #{full_name} cannot emit :raw_change with different policies."
                   Orocos.warn "The current policy is: #{@options}."
                   Orocos.warn "Ignoring policy: #{policy}."
                   @options
               end
    on_event :raw_change,&block
end

#periodObject



72
73
74
75
76
77
78
# File 'lib/orocos/async/task_context_proxy.rb', line 72

def period
    if @options.has_key? :period
        @options[:period]
    else
        nil
    end
end

#period=(period) ⇒ Object



80
81
82
83
# File 'lib/orocos/async/task_context_proxy.rb', line 80

def period=(period)
    @options[:period] = period
    @delegator_obj.period = period if valid_delegator?
end

#reachable!(attribute, options = Hash.new) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/orocos/async/task_context_proxy.rb', line 53

def reachable!(attribute,options = Hash.new)
    @options = attribute.options
    if @type && @type != attribute.type && @type.name != attribute.orocos_type_name
        raise RuntimeError, "the given type #{@type} for attribute #{attribute.name} differes from the real type name #{attribute.type}"
    end
    @type = attribute.type
    remove_proxy_event(@delegator_obj,@delegator_obj.event_names) if valid_delegator?
    @raw_last_sample = attribute.raw_last_sample
    super(attribute,options)
    proxy_event(@delegator_obj,@delegator_obj.event_names-[:reachable])
rescue Orocos::NotFound
    unreachable!
end

#really_add_listener(listener) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/orocos/async/task_context_proxy.rb', line 85

def really_add_listener(listener)
    return super unless listener.use_last_value?

    if listener.event == :change
        sample = last_sample
        if sample
            event_loop.once do
                listener.call sample
            end
        end
    elsif listener.event == :raw_change
        sample = raw_last_sample
        if sample
            event_loop.once do
                listener.call sample
            end
        end
    end
    super
end

#taskObject



23
24
25
# File 'lib/orocos/async/task_context_proxy.rb', line 23

def task
    @task_proxy
end

#typeObject

Raises:



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

def type
    raise Orocos::NotFound, "#{self} is not reachable" unless @type
    @type
end

#type?Boolean

returns true if the proxy stored the type

Returns:

  • (Boolean)


41
42
43
# File 'lib/orocos/async/task_context_proxy.rb', line 41

def type?
    !!@type
end

#type_nameObject



31
32
33
# File 'lib/orocos/async/task_context_proxy.rb', line 31

def type_name
    type.name
end

#unreachable!(options = Hash.new) ⇒ Object



67
68
69
70
# File 'lib/orocos/async/task_context_proxy.rb', line 67

def unreachable!(options=Hash.new)
    remove_proxy_event(@delegator_obj,@delegator_obj.event_names) if valid_delegator?
    super(options)
end