Class: Syskit::Models::DynamicDataService::InstantiationContext
- Defined in:
- lib/syskit/models/dynamic_data_service.rb
Overview
Intermediate object used to evaluate the blocks given to Component#dynamic_service
Direct Known Subclasses
Instance Attribute Summary collapse
-
#component_model ⇒ Object
readonly
The component model in which this service is being instantiated.
-
#dynamic_service ⇒ Object
readonly
The dynamic service description.
-
#name ⇒ Object
readonly
The name of the service that is being instantiated.
-
#options ⇒ Hash
readonly
A set of options that are accessible from the instanciation block.
-
#service ⇒ Object
readonly
The instantiated service.
Instance Method Summary collapse
-
#argument(name, options = Hash.new) ⇒ Object
Proxy to declare a new argument on the (specialized) component model.
- #driver_for(device_model, port_mappings = Hash.new, **options) ⇒ Object
-
#initialize(component_model, name, dynamic_service, **options) ⇒ InstantiationContext
constructor
A new instance of InstantiationContext.
-
#provides(service_model, port_mappings = Hash.new, as: nil, **arguments) ⇒ Object
Proxy for component_model#provides which does some sanity checks.
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, **) @component_model, @name, @dynamic_service, @options = component_model, name, dynamic_service, end |
Instance Attribute Details
#component_model ⇒ Object (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_service ⇒ Object (readonly)
The dynamic service description
61 62 63 |
# File 'lib/syskit/models/dynamic_data_service.rb', line 61 def dynamic_service @dynamic_service end |
#name ⇒ Object (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 |
#options ⇒ Hash (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
68 69 70 |
# File 'lib/syskit/models/dynamic_data_service.rb', line 68 def @options end |
#service ⇒ Object (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, = Hash.new) component_model.argument(name, ) 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, **) dserv = provides(device_model, port_mappings, **) 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. = self..dup service rescue InvalidPortMapping => e raise InvalidProvides.new(component_model, service_model, e), "while instanciating the dynamic service #{dynamic_service}: #{e}", e.backtrace end |