Class: OroGen::Spec::Deployment

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

Overview

Instances of this class are used to define a deployment. The deployment is the part in which the TaskContext classes are instanciated and associated with specific Activity classes.

Constant Summary collapse

KNOWN_LOG_LEVELS =
{
    :info => 'Info',
    :debug => 'Debug'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project = nil, name = nil) ⇒ Deployment

Returns a new instance of Deployment



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/orogen/spec/deployment.rb', line 532

def initialize(project = nil, name = nil)
    @project       = project
    @name            = name

    @install         = true
    @task_activities = Array.new
    @file_reporters  = Hash.new
    @loggers         = Hash.new
    @connections     = Array.new
    @tcp_reporters   = Hash.new
    @peers           = Set.new
    @corba_enabled   = nil
    @browse          = nil
    @loglevel        = nil
    @transports      = Array.new
    @manually_loaded_types = Set.new
    @lock_timeout_no_period = nil
    @lock_timeout_period_factor =  nil
end

Instance Attribute Details

#connectionsObject (readonly)

The set of connections set up for this deployment. This is a set of [from, to] PortDeployment objects.



747
748
749
# File 'lib/orogen/spec/deployment.rb', line 747

def connections
  @connections
end

#nameObject (readonly)

The deployment name



516
517
518
# File 'lib/orogen/spec/deployment.rb', line 516

def name
  @name
end

#peersObject (readonly)

The set of peer pairs set up for this deployment. This is a set of [a, b] TaskDeployment objects.



743
744
745
# File 'lib/orogen/spec/deployment.rb', line 743

def peers
  @peers
end

#projectObject (readonly)

The underlying Project object



518
519
520
# File 'lib/orogen/spec/deployment.rb', line 518

def project
  @project
end

#task_activitiesObject (readonly)

The set of tasks that need to be deployed



520
521
522
# File 'lib/orogen/spec/deployment.rb', line 520

def task_activities
  @task_activities
end

Instance Method Details

#activity_ordered_tasks(ordered = Array.new) ⇒ Object

handels theActivity creation order to be sure that all activities are created in the right order



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/orogen/spec/deployment.rb', line 706

def activity_ordered_tasks(ordered=Array.new)
    oldsize = ordered.size()
    (task_activities - ordered).each do |task|
        if !task.master || ordered.include?(task.master)
            ordered << task
        end
    end
    if ordered.size == task_activities.size
        return ordered
    elsif oldsize == ordered.size()
        activities = task_activities.map do |task|
            "\n  #{task.name} (master: #{task.master ? task.master.name : "none"})"
        end
        raise ArgumentError, "I cannot find an order in which to create the deployed tasks of #{name} during deployment" <<
            "Did you created a loop among master and slave activities ?. The #{activities.size} deployed tasks are:#{activities.join("\n  ")}"
    else
        return activity_ordered_tasks(ordered)
    end
end

#add_default_loggerObject



736
737
738
739
# File 'lib/orogen/spec/deployment.rb', line 736

def add_default_logger
    project.using_task_library "logger"
    task("#{name}_Logger", 'logger::Logger')
end

#add_peers(a, b) ⇒ Object

Declare that the given tasks are peers



766
767
768
769
# File 'lib/orogen/spec/deployment.rb', line 766

def add_peers(a, b)
    peers << [a, b]
    self
end

#connect(from, to, policy = Hash.new) ⇒ Object

Connects the two given ports or tasks



750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'lib/orogen/spec/deployment.rb', line 750

def connect(from, to, policy = Hash.new)
    add_peers from.activity, to.activity

    if from.kind_of?(Port)
        if !from.kind_of?(OutputPort)
            raise ArgumentError, "in connect(a, b), 'a' must be a writer port"
        elsif !to.kind_of?(InputPort)
            raise ArgumentError, "in connect(a, b), 'b' must be a reader port"
        end
    end

    connections << [from, to, ConnPolicy.from_hash(policy)]
    self
end

#corba_enabled?Boolean

True if this deployment should export its tasks through CORBA.

It is true by default if the CORBA transport is enabled

Returns:

  • (Boolean)


686
687
688
689
690
691
# File 'lib/orogen/spec/deployment.rb', line 686

def corba_enabled?
    if @corba_enabled.nil?
        transports.include?('corba')
    else @corba_enabled
    end
end

#disable_corbaObject

Force disabling CORBA support even though the CORBA transport is enabled in this deployment

See #corba_enabled?



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

def disable_corba; @corba_enabled = false end

#disable_transport(transport_name) ⇒ Object

Forbid the deployment from loading the given transport



639
640
641
# File 'lib/orogen/spec/deployment.rb', line 639

def disable_transport(transport_name)
    @transports.delete(transport_name.to_str)
end

#do_not_installObject

Do not install that deployment



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

def do_not_install; @install = false end

#each_task {|task| ... } ⇒ Object

Enumerates the tasks defined on this deployment

Yield Parameters:



671
672
673
# File 'lib/orogen/spec/deployment.rb', line 671

def each_task(&block)
    task_activities.each(&block)
end

#enable_corbaObject

Force enabling CORBA support even though the CORBA transport is not enabled in this deployment

See #corba_enabled?



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

def enable_corba; @corba_enabled = true end

#enable_transport(transport_name) ⇒ Object

Make the deployment load the given transport



643
644
645
# File 'lib/orogen/spec/deployment.rb', line 643

def enable_transport(transport_name)
    @transports << transport_name.to_str
end

#find_task_by_name(name) ⇒ TaskDeployment?

Returns the deployed task that has this name

Returns:

  • (TaskDeployment, nil)

    the deployed task model, or nil if none exists with that name



679
680
681
# File 'lib/orogen/spec/deployment.rb', line 679

def find_task_by_name(name)
    task_activities.find { |act| act.name == name }
end

#get_lock_timeout_no_periodObject



787
788
789
# File 'lib/orogen/spec/deployment.rb', line 787

def get_lock_timeout_no_period
    @lock_timeout_no_period
end

#get_lock_timeout_period_factorObject



797
798
799
# File 'lib/orogen/spec/deployment.rb', line 797

def get_lock_timeout_period_factor
    @lock_timeout_period_factor
end

#initialize_copy(old) ⇒ Object



552
553
554
555
556
557
558
559
560
# File 'lib/orogen/spec/deployment.rb', line 552

def initialize_copy(old)
    super
    @task_activities = @task_activities.dup


    @transports = @transports.dup
    @peers = @peers.dup
    @manually_loaded_types = @manually_loaded_types.dup
end

#inspectObject



571
572
573
# File 'lib/orogen/spec/deployment.rb', line 571

def inspect
    to_s
end

#install?Boolean

True if this deployment should be installed

Returns:

  • (Boolean)


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

def install?; !!@install end

#linux?Boolean

True if we are generating for Linux

Returns:

  • (Boolean)


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

def linux?;     project.linux? end

#load_type(typename) ⇒ Object

Manually Request Loading of Types that are not Provided throught the task_contex typekit.



580
581
582
583
584
585
# File 'lib/orogen/spec/deployment.rb', line 580

def load_type(typename)
    if !project.imported_typekits_for(typename).map(&:name)[0]
        raise ArgumentError, "cannot find a typekit defining #{typename}"
    end
    @manually_loaded_types << typename
end

#lock_timeout_no_period(timeout_in_s) ⇒ Object

Set the lock timeout of a thread, which has no period if set, the minimum setting is 1s



793
794
795
# File 'lib/orogen/spec/deployment.rb', line 793

def lock_timeout_no_period(timeout_in_s)
    @lock_timeout_no_period = [1,timeout_in_s].max
end

#lock_timeout_period_factor(factor) ⇒ Object

Set the mutex timeout for a thread with a given period by a factor of its period if set, the minimum setting is factor 10 (times the period)



804
805
806
# File 'lib/orogen/spec/deployment.rb', line 804

def lock_timeout_period_factor(factor)
    @lock_timeout_period_factor = [10,factor.to_i].max
end

#pretty_print(pp) ⇒ Object

Displays this deployment's definition nicely



809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/orogen/spec/deployment.rb', line 809

def pretty_print(pp) # :nodoc:
    pp.text "------- #{name} ------"
    pp.breakable
    if !task_activities.empty?
        pp.text "Tasks"
        pp.nest(2) do
            pp.breakable
            pp.seplist(task_activities) do |act|
                act.pretty_print(pp)
            end
        end
    end

    if !connections.empty?
        pp.breakable if !task_activities.empty?
        pp.text "Connections"
        pp.nest(2) do
            pp.breakable
            pp.seplist(connections) do |conn|
                from, to, policy = *conn
                pp.text "#{from.activity.name} => #{to.activity.name} [#{policy.inspect}]"
            end
        end
    end
end

#rtt_transportsObject

The set of transports loaded by this deployment for which a transport should be loaded on the RTT itself



628
629
630
631
632
# File 'lib/orogen/spec/deployment.rb', line 628

def rtt_transports
    result = self.transports
    result.delete('typelib')
    result
end

#set_master_slave_activity(master, slave) ⇒ Object

Define an master slave avtivity between tasks



727
728
729
730
# File 'lib/orogen/spec/deployment.rb', line 727

def set_master_slave_activity(master, slave)
    slave.slave_of(master)
    self
end

#task(name, klass) ⇒ Object

call-seq:

task name, task_context -> task_deployment

Deploys a new task using the given task context type, and returns the corresponding TaskDeployment object. This instance can be used to configure the task further (for instance specifying the activity). See TaskDeployment documentation for available options.



654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/orogen/spec/deployment.rb', line 654

def task(name, klass)
    if klass.respond_to?(:to_str)
        task_context = project.task_model_from_name(klass)
    else task_context = klass
    end

    if find_task_by_name(name)
        raise ArgumentError, "there is already a task #{name} on the deployment #{self.name}"
    end
    deployment = TaskDeployment.new(name, task_context)
    task_activities << deployment
    deployment
end

#to_sObject



567
568
569
# File 'lib/orogen/spec/deployment.rb', line 567

def to_s
    "#<#{self.class} name=#{name} tasks=#{task_activities.map { |t| "#{t}" }.join(", ")}>"
end

#transportsObject

The set of transports loaded by this deployment, as an array of names



635
636
637
# File 'lib/orogen/spec/deployment.rb', line 635

def transports
    @transports.to_a.sort
end

#used_typekitsObject

Returns the set of typekits required by this particular deployment (i.e. the tasks that are deployed in it)



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# File 'lib/orogen/spec/deployment.rb', line 589

def used_typekits
    task_typekits = task_activities.map do |deployed_task|
        deployed_task.task_model.used_typekits.
            map(&:name)
    end.flatten.to_set
   
    @manually_loaded_types.each do |type|
        tk = project.imported_typekits_for(type).map(&:name)[0]
        if !tk
            raise InternalError, "could not find manually loaded type \"#{type}\""
        end
        task_typekits << tk
    end

    task_typekits.sort.map do |used_name|
        this_tk = project.find_typekit(used_name)
        next if this_tk.virtual?
        if !this_tk
            raise InternalError, "#{used_name} is a typekit that is listed by one of the tasks of the #{name} deployment, but the oroGen project #{project.name} does not list it"
        end
        this_tk
    end.compact
end

#uses_qt?Boolean

Returns:

  • (Boolean)


575
576
577
# File 'lib/orogen/spec/deployment.rb', line 575

def uses_qt?
    task_activities.any?{|t| t.task_model.uses_qt?}
end

#xenomai?Boolean

True if we are generating for Xenomai

Returns:

  • (Boolean)


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

def xenomai?;   project.xenomai? end