Class: OroGen::Spec::TaskDeployment

Inherits:
Object
  • Object
show all
Defined in:
lib/orogen/spec/deployment.rb

Overview

The instances of this class hold the deployment-specific information needed for a task.

Defined Under Namespace

Classes: ActivityDefinition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, task_model) ⇒ TaskDeployment


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/orogen/spec/deployment.rb', line 197

def initialize(name, task_model)
    @name     = name
    @task_model  = task_model
    @realtime = false
    @priority = :lowest
    @max_overruns = -1
    @master = nil
    @slaves = Array.new
    if task_model.default_activity
        send(*task_model.default_activity)
        @explicit_activity = task_model.required_activity?
    end

    { :properties  => PropertyDeployment,
        :ports    => PortDeployment,
        :operations => OperationDeployment }.each do |collection_name, klass|
            deployed_objects = task_model.send("all_#{collection_name}").map do |obj|
                klass.new(self, obj)
            end
            instance_variable_set "@#{collection_name}", deployed_objects
        end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object

:nodoc:


480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/orogen/spec/deployment.rb', line 480

def method_missing(m, *args) # :nodoc:
    name = m.to_s
    if name =~ /=$/
        setter = true
        name = $`
    end

    { :properties  => PropertyDeployment,
        :ports    => PortDeployment,
        :operations  => OperationDeployment }.each do |collection_name, klass|
        if obj = send(collection_name).find { |el| el.name == name.to_s }
            if setter
                if args.size != 1
                    raise ArgumentError, "wrong number of arguments for #{name}=: expected 1 got #{args.size}"
                end
                obj.set args[0]
                return args[0]
            else
                if !args.empty?
                    raise ArgumentError, "wrong number of arguments for #{name}: expected 1 got #{args.size}"
                end
                return obj
            end
        end
    end
    
    return super
end

Instance Attribute Details

#masterTaskDeployment

If this task is deployed with a slave activity, this is the master task


144
145
146
# File 'lib/orogen/spec/deployment.rb', line 144

def master
  @master
end

#minimal_trigger_latencyObject

Returns the minimal latency between the time the task gets triggered (for instance because of data on an input event port), and the time updateHook() is actually called, based on its scheduler and priority. All tasks will return a value (even non-periodic ones).

Default values are set in the DEFAULT_RT_MINIMAL_TRIGGER_LATENCY and DEFAULT_NONRT_MINIMAL_TRIGGER_LATENCY constants. They can be overriden by setting the minimal_trigger_latency property


135
136
137
# File 'lib/orogen/spec/deployment.rb', line 135

def minimal_trigger_latency
  @minimal_trigger_latency
end

#nameObject

The task name as specified by the user


118
119
120
# File 'lib/orogen/spec/deployment.rb', line 118

def name
  @name
end

#operationsObject (readonly)

The deployed operations, as OperationDeployment instances


129
130
131
# File 'lib/orogen/spec/deployment.rb', line 129

def operations
  @operations
end

#periodObject (readonly)

Returns the task period, or nil if the task is not periodic. Call #periodic to define a periodic task and one of the other triggering methods otherwise.


317
318
319
# File 'lib/orogen/spec/deployment.rb', line 317

def period
  @period
end

#portsObject (readonly)

The deployed ports, as PortDeployment instances


127
128
129
# File 'lib/orogen/spec/deployment.rb', line 127

def ports
  @ports
end

#propertiesObject (readonly)

The deployed properties, as PropertyDeployment instances


125
126
127
# File 'lib/orogen/spec/deployment.rb', line 125

def properties
  @properties
end

#slavesArray<TaskDeployment> (readonly)

If this task is the master of other tasks deployed as slave activities, they are listed here


148
149
150
# File 'lib/orogen/spec/deployment.rb', line 148

def slaves
  @slaves
end

#task_modelObject (readonly)

The TaskContext model used to define this task


120
121
122
# File 'lib/orogen/spec/deployment.rb', line 120

def task_model
  @task_model
end

#worstcase_trigger_latencyObject

Returns the expected (average) latency between the time the task gets triggered (for instance because of data on an input event port), and the time updateHook() is actually called, based on its scheduler and priority. All tasks will return a value (even non-periodic ones).

Default values are set in the DEFAULT_RT_WORSTCASE_TRIGGER_LATENCY and DEFAULT_NONRT_WORSTCASE_TRIGGER_LATENCY constants. They can be overriden by setting the worstcase_trigger_latency property


140
141
142
# File 'lib/orogen/spec/deployment.rb', line 140

def worstcase_trigger_latency
  @worstcase_trigger_latency
end

Instance Method Details

#activity_setup(&block) ⇒ Object


422
423
424
# File 'lib/orogen/spec/deployment.rb', line 422

def activity_setup(&block)
    @activity_setup = block
end

#activity_xml(&block) ⇒ Object


426
427
428
# File 'lib/orogen/spec/deployment.rb', line 426

def activity_xml(&block)
    @activity_xml = block
end

#contextObject

Backward compatibility only. Use #task_model instead.


122
# File 'lib/orogen/spec/deployment.rb', line 122

def context; task_model end

#disable_overruns_controlObject

Do no check for overruns. Valid for periodic tasks. See #max_overruns for a more precise description.


441
# File 'lib/orogen/spec/deployment.rb', line 441

def disable_overruns_control; @max_overruns = -1; self end

#fd_drivenObject

Makes this task's activity driven by a file descriptor. The underlying task context must be a subclass of FileDescriptorActivity::Provider


285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/orogen/spec/deployment.rb', line 285

def fd_driven
    activity_type 'FileDescriptorActivity', 'RTT::extras::FileDescriptorActivity', 'rtt/extras/FileDescriptorActivity.hpp'
    activity_xml do
        result = "<struct name=\"\#{name}\" type=\"FileDescriptorActivity\">\n<simple name=\"Priority\" type=\"short\"><value>\#{rtt_priority}</value></simple>\n<simple name=\"Scheduler\" type=\"string\"><value>\#{rtt_scheduler}</value></simple>\n</struct>\n"
    end
    self
end

#fd_driven?Boolean


275
276
277
# File 'lib/orogen/spec/deployment.rb', line 275

def fd_driven?
    activity_type.name == 'FileDescriptorActivity'
end

#highest_priorityObject

Make this task as being of the highest priority allowed by the underlying OS


222
# File 'lib/orogen/spec/deployment.rb', line 222

def highest_priority; @priority = :highest; self end

#initialize_copy(old) ⇒ Object


150
151
152
153
# File 'lib/orogen/spec/deployment.rb', line 150

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

#inspectObject


466
467
468
# File 'lib/orogen/spec/deployment.rb', line 466

def inspect
    to_s
end

#irq_drivenObject

Makes this task's activity driven by events on an IRQ line. The underlying task context must be a subclass of IRQActivity::Provider


301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/orogen/spec/deployment.rb', line 301

def irq_driven
    activity_type 'IRQActivity', 'RTT::extras::IRQActivity', 'rtt/extras/IRQActivity.hpp'
    activity_xml do
        result = "<struct name=\"\#{name}\" type=\"IRQActivity\">\n<simple name=\"Priority\" type=\"short\"><value>\#{rtt_priority}</value></simple>\n<simple name=\"Scheduler\" type=\"string\"><value>\#{rtt_scheduler}</value></simple>\n</struct>\n"
    end
    self
end

#lowest_priorityObject

Make this task as being of the lowest priority allowed by the underlying OS


225
# File 'lib/orogen/spec/deployment.rb', line 225

def lowest_priority;  @priority = :lowest; self end

#non_realtimeObject

Marks this task as being part of the non-realtime scheduling class (the default)


461
# File 'lib/orogen/spec/deployment.rb', line 461

def non_realtime; @realtime = false; self end

#periodic(value) ⇒ Object

call-seq:

periodic(period_in_seconds) -> self

Sets this task as being periodic. Call #period to return the current task's period (or nil if the task is not periodic), and one of the other triggering methods if you want a different activity type.


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/orogen/spec/deployment.rb', line 332

def periodic(value)
    activity_type 'Periodic', 'RTT::Activity', 'rtt/Activity.hpp'
    activity_setup do
       result = "\#{activity_type.class_name}* activity_\#{name} = new \#{activity_type.class_name}(\n\#{rtt_scheduler},\n\#{rtt_priority},\n\#{period},\ntask_\#{name}->engine(),\n\"\#{name}\");\nRTT::os::Thread* thread_\#{name} =\ndynamic_cast<RTT::os::Thread*>(activity_\#{name}->thread());\nthread_\#{name}->setMaxOverrun(\#{max_overruns});\n"
    end
    activity_xml do
        result = "<struct name=\"\#{name}\" type=\"Activity\">\n<simple name=\"Period\" type=\"double\"><value>\#{period}</value></simple>\n<simple name=\"Priority\" type=\"short\"><value>\#{rtt_priority}</value></simple>\n<simple name=\"Scheduler\" type=\"string\"><value>\#{rtt_scheduler}</value></simple>\n</struct>\n"
    end

    @period = Float(value)
    self
end

#periodic?Boolean


271
272
273
# File 'lib/orogen/spec/deployment.rb', line 271

def periodic?
    activity_type.name == 'Triggered' && period != 0
end

#pretty_print(pp) ⇒ Object

:nodoc:


470
471
472
473
474
475
476
477
478
# File 'lib/orogen/spec/deployment.rb', line 470

def pretty_print(pp) # :nodoc:
    pp.text "#{name}[#{task_model.name}]"
    pp.nest(2) do
        pp.breakable
        pp.text "activity: #{@activity_type.name}, prio=#{@priority}"
        pp.breakable
        pp.text "scheduler: #{@realtime ? 'realtime' : 'non realtime'}"
    end
end

#projectObject

The Project object this task is part of


238
# File 'lib/orogen/spec/deployment.rb', line 238

def project; task_model.project end

#realtimeObject

Marks this task as being part of the realtime scheduling class


458
# File 'lib/orogen/spec/deployment.rb', line 458

def realtime; @realtime = true; self end

#realtime?Boolean

True if this task should be deployed using a realtime scheduler, and false otherwise


456
# File 'lib/orogen/spec/deployment.rb', line 456

def realtime?; @realtime end

#sequentialObject

Marks this task as being “sequential”. Sequential tasks are thread-less, and are triggered by the task context that is calling step() on them, or – in the case of port-driven tasks – by the task context that wrote on their read ports.


392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/orogen/spec/deployment.rb', line 392

def sequential
    activity_type 'Sequential', 'RTT::extras::SequentialActivity', 'rtt/extras/SequentialActivity.hpp'
    activity_setup do
        result = "\#{activity_type.class_name}* activity_\#{name} = new \#{activity_type.class_name}(task_\#{name}->engine());\n"
    end
    activity_xml do
        "<struct name=\"\#{name}\" type=\"SequentialActivity\" />\n"
    end

    self
end

#sequential?Boolean


263
264
265
# File 'lib/orogen/spec/deployment.rb', line 263

def sequential?
    activity_type.name == 'Sequential'
end

#slave?Boolean


279
280
281
# File 'lib/orogen/spec/deployment.rb', line 279

def slave?
    activity_type.name == 'SlaveActivity'
end

#slave_of(master) ⇒ Object


408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/orogen/spec/deployment.rb', line 408

def slave_of(master)
    activity_type 'SlaveActivity', 'RTT::extras::SlaveActivity', 'rtt/extras/SlaveActivity.hpp'
    self.master = master
    master.slaves << self
    activity_setup do
        "\#{activity_type.class_name}* activity_\#{name} = new \#{activity_type.class_name}(activity_\#{master.name},task_\#{name}->engine());\n"
    end
    activity_xml do
        "<struct name=\"#{name}\" type=\"SlaveActivity\" />"
    end
end

#startObject

Call to make the deployer start this task when the task context is launched


432
# File 'lib/orogen/spec/deployment.rb', line 432

def start; @start = true; self end

#start?Boolean

True if this task should be started when the task context is started. Note that the deployer must honor the initial_state of the underlying task context (i.e. call configure() if initial_state is PreOperational)


437
# File 'lib/orogen/spec/deployment.rb', line 437

def start?; !!@start end

#to_sObject


463
464
465
# File 'lib/orogen/spec/deployment.rb', line 463

def to_s
    "#<#{self.class} name=#{name} model=#{task_model}>"
end

#trigger_port?(port) ⇒ Boolean

Returns true if port is a trigger for this task


320
321
322
323
# File 'lib/orogen/spec/deployment.rb', line 320

def trigger_port?(port)
    port.trigger_port? &&
        activity_type.name != 'Periodic'
end

#triggeredObject

Marks this task as being explicitely triggered (the default). To make it periodic, call #period with the required period


363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/orogen/spec/deployment.rb', line 363

def triggered
    activity_type 'Triggered', 'RTT::Activity', 'rtt/Activity.hpp'
    activity_setup do
       result = "\#{activity_type.class_name}* activity_\#{name} = new \#{activity_type.class_name}(\n\#{rtt_scheduler},\n\#{rtt_priority},\n0,\ntask_\#{name}->engine(),\n\"\#{name}\");\n"
    end
    activity_xml do
        result = "<struct name=\"\#{name}\" type=\"Activity\">\n<simple name=\"Period\" type=\"double\"><value>0</value></simple>\n<simple name=\"Priority\" type=\"short\"><value>\#{rtt_priority}</value></simple>\n<simple name=\"Scheduler\" type=\"string\"><value>\#{rtt_scheduler}</value></simple>\n</struct>\n"
    end
    @period = 0
    self
end

#triggered?Boolean


267
268
269
# File 'lib/orogen/spec/deployment.rb', line 267

def triggered?
    activity_type.name == 'Triggered' && period == 0
end