Class: Syskit::Actions::Models::Action

Inherits:
Roby::Actions::Models::Action
  • Object
show all
Defined in:
lib/syskit/actions/action_model.rb

Overview

Representation of the deployment of a syskit instance requirement on the action interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requirements, doc = nil) ⇒ Action

Returns a new instance of Action



15
16
17
18
19
# File 'lib/syskit/actions/action_model.rb', line 15

def initialize(requirements, doc = nil)
    super(doc)
    @requirements = requirements
    returns(requirements.placeholder_model)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/syskit/actions/action_model.rb', line 131

def method_missing(m, *args, &block)
    if requirements.respond_to?(m)
        req = requirements.dup
        req.send(m, *args, &block)
        Actions::Models::Action.new(req, doc)
    else super
    end
end

Instance Attribute Details

#requirementsInstanceRequirements (readonly)

The instance requirement object for this action

It is the “pure” requirements, where the enclsoing DI context is not yet injected



13
14
15
# File 'lib/syskit/actions/action_model.rb', line 13

def requirements
  @requirements
end

Instance Method Details

#droby_dump!(peer) ⇒ Object

Called by Roby::Actions::Models::Action to modify self so that it is droby-marshallable

It only resets the requirements attribute, as InstanceRequirements are not (yet) marshallable in droby



110
111
112
113
# File 'lib/syskit/actions/action_model.rb', line 110

def droby_dump!(peer)
    super
    @requirements = peer.dump(requirements)
end

#initialize_copy(old) ⇒ Object



58
59
60
61
# File 'lib/syskit/actions/action_model.rb', line 58

def initialize_copy(old)
    super
    @requirements = old.requirements.dup
end

#instanciate(plan, **arguments) ⇒ Object

Instanciate this action on the given plan



90
91
92
93
# File 'lib/syskit/actions/action_model.rb', line 90

def instanciate(plan, **arguments)
    plan.add(task = plan_pattern(**arguments))
    task
end

#new(**arguments) ⇒ Action

Returns an action instance based on this model

Returns:

  • (Action)

    an action instance based on this model



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

def new(**arguments)
    Actions::Action.new(self, **arguments)
end

#plan_pattern(**arguments) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/syskit/actions/action_model.rb', line 68

def plan_pattern(**arguments)
    job_id = Hash.new
    if arguments.has_key?(:job_id)
        job_id[:job_id] = arguments.delete(:job_id)
    end
    req = to_instance_requirements(**arguments)
    placeholder = req.as_plan(**job_id)
    placeholder.planning_task.action_model = self
    placeholder.planning_task.action_arguments = req.arguments
    placeholder
end

#proxy!(peer) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/syskit/actions/action_model.rb', line 115

def proxy!(peer)
    super
    if @requirements_model # Backward compatibility
        @requirements.add_models([peer.local_object(@requirements_model)])
        @requirements.name = @requirements_name
        @requirements.with_arguments(peer.local_object(@requirements_arguments))
        @requirements_model = @requirements_name = @requirements_arguments = nil
    else
        @requirements = peer.local_object(@requirements)
    end
end

#rebind(action_interface_model) ⇒ Object

Rebind this action to another action interface



37
38
39
40
41
42
43
44
45
46
# File 'lib/syskit/actions/action_model.rb', line 37

def rebind(action_interface_model)
    # NOTE: use_profile maps all definitions into the new profile.
    # NOTE: DI injection will happen at this point, and we just
    # NOTE: have to look for already-defined actions
    if overloaded = action_interface_model.actions[name]
        overloaded
    else
        dup
    end
end

#rebind_requirements(profile) ⇒ Action

Create a new action with the same arguments but the requirements rebound to a new profile

Parameters:

  • the (Profile)

    profile onto which definitions should be rebound

Returns:



54
55
56
# File 'lib/syskit/actions/action_model.rb', line 54

def rebind_requirements(profile)
    requirements.rebind(profile).to_action_model
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/syskit/actions/action_model.rb', line 127

def respond_to_missing?(m, include_private)
    requirements.respond_to?(m) || super
end

#run(action_interface, **arguments) ⇒ Roby::Task

Injects the tasks necessary to deploy #requirements on the plan associated with the given action interface

Parameters:

  • the (ActionInterface)

    action interface

  • arguments (Hash)

    the arguments (unused)

Returns:

  • (Roby::Task)

    the action task



101
102
103
# File 'lib/syskit/actions/action_model.rb', line 101

def run(action_interface, **arguments)
    instanciate(action_interface.plan, **arguments)
end

#to_instance_requirements(**arguments) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/syskit/actions/action_model.rb', line 80

def to_instance_requirements(**arguments)
    if !requirements.has_template? && requirements.can_use_template?
        requirements.compute_template
    end
    req = requirements.dup
    req.with_arguments(**arguments)
    req
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/syskit/actions/action_model.rb', line 21

def to_s
    name =
        if (requirement_name = requirements.name)
            "#{requirement_name}_def"
        else
            requirements.to_s
        end

    if requirements.respond_to?(:profile)
        "#{name} of #{requirements.profile}"
    else
        name
    end
end