Class: Orocos::Async::CORBA::TaskContext

Inherits:
TaskContextBase show all
Defined in:
lib/orocos/async/task_context.rb

Instance Attribute Summary

Attributes inherited from TaskContextBase

#raise_on_access_error?

Attributes included from ObjectBase::Periodic::ClassMethods

#default_period

Attributes inherited from ObjectBase

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

Instance Method Summary collapse

Methods inherited from TaskContextBase

#attribute, #call_with_async, #clear_interface, #each_attribute, #each_port, #each_property, #name, #port, #property, #reachable!, #reachable?, #ruby_task_context?, #to_async, #to_proxy, to_ruby, #to_ruby, #unreachable!

Methods included from ObjectBase::Periodic

#default_period, #period, #period=

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!, #reachable?, #remove_all_listeners, #remove_listener, #remove_proxy_event, #unreachable!, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait

Constructor Details

#initialize(options) ⇒ TaskContext #initialize(task, options) ⇒ TaskContext

A TaskContext

If not specified the default option settings are:

:event_loop => Async.event_loop
:raise => false
:watchdog => true
:period => 1.0

Overloads:

  • #initialize(task, options) ⇒ TaskContext

    Options Hash (options):

    • :task (#ior, #name)

      a task context.

Parameters:

  • ior (String, #ior)

    The ior of the task or a task context.

  • options (Hash) (defaults to: Hash.new)

    The options.

Options Hash (options):

  • :name (String)

    The name of the task.

  • :event_loop (Utilrb::EventLoop)

    The event loop.

  • :ior (String)

    The IOR

  • :raise (Boolean)

    Raises an Orocos::NotFound error if the remote task is unreachable or went offline. Otherwise tries to reconnect and silently ignores method calls on the remote task object as long as the task is unreachable.

  • :watchdog (Boolean)

    Checks the state of the tasks and if it is reachable.

  • :period (Float)

    The period of the watchdog in seconds.

  • :use (Orocos::TaskContext)

    Use the given task as designated object. After this any other other code path is not allowed to use the given task otherwise there might be multi threading problems. Furthermore it is assumed that the given task is reachable.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/orocos/async/task_context.rb', line 28

def initialize(ior,options=Hash.new)
    if ior.respond_to?(:ior)
        ior = ior.ior
    end
    ior,options = if ior.is_a? Hash
                      [nil,ior]
                  else
                      [ior,options]
                  end
    ior ||= if options.has_key? :ior
                options[:ior]
            elsif options.has_key? :use
                options[:use].ior
            end
    name = options[:name] || ior
    super(name,options.merge(:ior => ior))
    @ior = ior.to_str
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/orocos/async/task_context.rb', line 94

def method_missing(m,*args)
    if respond_to_missing?(m)
        event_loop.sync(@delegator_obj,args) do |args|
            @delegator_obj.method(m).call(*args)
        end
    else
        super
    end
end

Instance Method Details

#configure_delegation(options = Hash.new) ⇒ Object

Parameters:

  • options (Hash) (defaults to: Hash.new)

    a customizable set of options

Options Hash (options):

  • name (String)

    the task name

  • ior (String)

    the task IOR



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/orocos/async/task_context.rb', line 71

def configure_delegation(options = Hash.new)
    options = Kernel.validate_options options,
        :name=> nil,
        :ior => nil

    ior = options[:ior]
    @ior,@name = if valid_delegator?
                     [@delegator_obj.ior,@delegator_obj.name]
                 elsif ior.respond_to?(:ior)
                     [ior.ior, ior.name]
                 else
                     [ior, @name]
                 end

    if !@ior
        raise ArgumentError, "no IOR or task has been given"
    end
end

#iorObject



61
62
63
64
65
# File 'lib/orocos/async/task_context.rb', line 61

def ior
    @mutex.synchronize do
        @ior.dup if @ior
    end
end

#really_add_listener(listener) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/orocos/async/task_context.rb', line 47

def really_add_listener(listener)
    super

    # call new listeners with the current value
    # to prevent different behaviors depending on
    # the calling order
    if listener.use_last_value? && listener.event == :state_change
        state = @mutex.synchronize do
            @delegator_obj.current_state if valid_delegator?
        end
        event_loop.once{listener.call state} if state
    end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/orocos/async/task_context.rb', line 90

def respond_to_missing?(method_name, include_private = false)
    (reachable? && @delegator_obj.respond_to?(method_name)) || super
end