Class: Syskit::Models::DynamicDataService::InstantiationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/syskit/models/dynamic_data_service.rb

Overview

Intermediate object used to evaluate the blocks given to Component#dynamic_service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_model, name, dynamic_service, **options) ⇒ InstantiationContext

Returns a new instance of InstantiationContext



70
71
72
73
# File 'lib/syskit/models/dynamic_data_service.rb', line 70

def initialize(component_model, name, dynamic_service, **options)
    @component_model, @name, @dynamic_service, @options =
        component_model, name, dynamic_service, options
end

Instance Attribute Details

#component_modelObject (readonly)

The component model in which this service is being instantiated



57
58
59
# File 'lib/syskit/models/dynamic_data_service.rb', line 57

def component_model
  @component_model
end

#dynamic_serviceObject (readonly)

The dynamic service description



61
62
63
# File 'lib/syskit/models/dynamic_data_service.rb', line 61

def dynamic_service
  @dynamic_service
end

#nameObject (readonly)

The name of the service that is being instantiated



59
60
61
# File 'lib/syskit/models/dynamic_data_service.rb', line 59

def name
  @name
end

#optionsHash (readonly)

A set of options that are accessible from the instanciation block. This allows to create protocols for dynamic service creation, and is specific to the client component model

Returns:

  • (Hash)


68
69
70
# File 'lib/syskit/models/dynamic_data_service.rb', line 68

def options
  @options
end

#serviceObject (readonly)

The instantiated service



63
64
65
# File 'lib/syskit/models/dynamic_data_service.rb', line 63

def service
  @service
end

Instance Method Details

#argument(name, options = Hash.new) ⇒ Object

Proxy to declare a new argument on the (specialized) component model



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

def argument(name, options = Hash.new)
    component_model.argument(name, options)
end

#driver_for(device_model, port_mappings = Hash.new, **options) ⇒ Object



83
84
85
86
87
# File 'lib/syskit/models/dynamic_data_service.rb', line 83

def driver_for(device_model, port_mappings = Hash.new, **options)
    dserv = provides(device_model, port_mappings, **options)
    component_model.argument "#{dserv.name}_dev"
    dserv
end

#provides(service_model, port_mappings = Hash.new, as: nil, **arguments) ⇒ Object

Proxy for component_model#provides which does some sanity checks



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/syskit/models/dynamic_data_service.rb', line 91

def provides(service_model, port_mappings = Hash.new, as: nil, **arguments)
    if service
        raise ArgumentError, "this dynamic service instantiation block already created one new service"
    end

    if !service_model.fullfills?(dynamic_service.service_model)
        raise ArgumentError, "#{service_model.short_name} does not fullfill the model for the dynamic service #{dynamic_service.name}, #{dynamic_service.service_model.short_name}"
    end

    if as && as != name
        raise ArgumentError, "the as: argument was given (with value #{as}) but it is required to be #{name}. Note that it can be omitted in a dynamic service block"
    end
    @service = component_model.provides_dynamic(
        service_model, port_mappings, as: name,
        bound_service_class: BoundDynamicDataService, **arguments)
    service.dynamic_service = dynamic_service
    service.dynamic_service_options = self.options.dup
    service

rescue InvalidPortMapping => e
    raise InvalidProvides.new(component_model, service_model, e), "while instanciating the dynamic service #{dynamic_service}: #{e}", e.backtrace
end