module Syskit::Actions::LibraryExtension

Extension to the models of Roby::Actions::Interface

Public Instance Methods

find_through_method_missing(m, args) click to toggle source
Calls superclass method
# File lib/syskit/actions/interface_model_extension.rb, line 123
def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        profile, m, args, '_tag'.freeze => :find_tag) || super
end
has_through_method_missing?(m) click to toggle source
Calls superclass method
# File lib/syskit/actions/interface_model_extension.rb, line 118
def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        profile, m, '_tag'.freeze => :has_tag?) || super
end
profile(name = nil, &block) click to toggle source

The main Syskit::Actions::Profile object that is used in an action interface

Calls superclass method
# File lib/syskit/actions/interface_model_extension.rb, line 7
def profile(name = nil, &block)
    return super if name

    if !@profile
        @profile = super("Profile") { self }
        setup_main_profile(@profile)
    end

    if block
        Roby.warn_deprecated "calling profile do ... end in an action interface is deprecated, call use_profile do .. end instead"
        use_profile(&block)
    else
        @profile
    end
end
profile_library() click to toggle source

@api private

An action library that is created and included on-the-fly to support the actions derived from {#profile}

# File lib/syskit/actions/interface_model_extension.rb, line 40
def profile_library
    if !@profile_library
        @profile_library = Roby::Actions::Library.new_submodel
        use_library @profile_library
    end
    @profile_library
end
register_action_from_profile(action_model) click to toggle source

@api private

Registers an action that has been derived from a profile definition or device

# File lib/syskit/actions/interface_model_extension.rb, line 66
def register_action_from_profile(action_model)
    action_model = action_model.rebind(self)
    action_name  = action_model.name
    profile_library.register_action(action_name, action_model)
    action_model = find_action_by_name(action_name)

    args = action_model.each_arg.to_a
    if args.any?(&:required?)
        profile_library.send(:define_method, action_name) do |arguments|
            action_model.to_instance_requirements(arguments)
        end
    elsif !args.empty?
        profile_library.send(:define_method, action_name) do |arguments = Hash.new|
            action_model.to_instance_requirements(arguments)
        end
    else
        profile_library.send(:define_method, action_name) do
            action_model.to_instance_requirements(Hash.new)
        end
    end
end
robot(&block) click to toggle source

Returns the robot definition object used by this action interface @return [Syskit::Robot::RobotDefinition]

# File lib/syskit/actions/interface_model_extension.rb, line 50
def robot(&block)
    existing_devices = profile.robot.each_master_device.to_a
    profile.robot(&block)
    new_devices = profile.robot.each_master_device.to_a - existing_devices
    new_devices.each do |dev|
        register_action_from_profile(dev.to_action_model)
    end
end
setup_main_profile(profile) click to toggle source
# File lib/syskit/actions/interface_model_extension.rb, line 23
def setup_main_profile(profile)
end
tag(name, model) click to toggle source

Define a tag on {#profile}

# File lib/syskit/actions/interface_model_extension.rb, line 60
def tag(name, model); profile.tag(name, model) end
use_profile(used_profile = nil, tag_selection = Hash.new, transform_names: ->(name) { name } click to toggle source

Export the definitions contained in the given profile as actions on this action interface

@param [Profile] used_profile the profile that should be used @param [Hash] tag_selection selection for the profile tags, see

{Profile#use_profile}

@return [void]

# File lib/syskit/actions/interface_model_extension.rb, line 95
def use_profile(used_profile = nil, tag_selection = Hash.new, transform_names: ->(name) { name })
    if block_given?
        if !tag_selection.empty?
            raise ArgumentError, "cannot provide a tag selection when defining a new anonymous profile"
        end

        used_profile = Profile.new("#{self.name}::<anonymous>", register: true)
        used_profile.instance_eval(&proc)
        tag_selection = use_profile_tags(used_profile)
    elsif !used_profile
        raise ArgumentError, "must provide either a profile object or a block"
    end

    @current_description = nil
    new_definitions =
        profile.use_profile(used_profile, tag_selection, transform_names: transform_names)
    new_definitions.each do |definition|
        register_action_from_profile(definition.to_action_model)
    end
end
use_profile_tags(profile) click to toggle source

Define on self tags that match the profile's tags

# File lib/syskit/actions/interface_model_extension.rb, line 27
def use_profile_tags(profile)
    tag_map = Hash.new
    profile.each_tag do |tag|
        tagged_models = [*tag.proxied_data_services]
        tag_map[tag.tag_name] = @profile.tag(tag.tag_name, *tagged_models)
    end
    tag_map
end