Class: Syskit::RobyApp::LoggingGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/syskit/roby_app/logging_group.rb

Overview

Representation of a group of ports

This is used to configure which ports should or should not be configured. The documentation of LoggingConfiguration provides usage information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled = true) ⇒ LoggingGroup

Returns a new instance of LoggingGroup

Parameters:

  • enabled (Boolean) (defaults to: true)

    the group's initial state



10
11
12
13
14
15
16
17
18
# File 'lib/syskit/roby_app/logging_group.rb', line 10

def initialize(enabled = true)
    @deployments = Set.new
    @tasks = Set.new
    @ports = Set.new
    @types = Set.new
    @name_set = Set.new
    @name_matchers = Set.new
    @enabled = enabled
end

Instance Attribute Details

#deploymentsSet<Models::Deployment> (readonly)

Set of deployment models whose ports should match

Returns:



31
32
33
# File 'lib/syskit/roby_app/logging_group.rb', line 31

def deployments
  @deployments
end

#name_matchersSet<#===> (readonly)

Set of objects that can match names. They are matched against the deployment (process) name, port name, task name and type name

Returns:

  • (Set<#===>)


58
59
60
# File 'lib/syskit/roby_app/logging_group.rb', line 58

def name_matchers
  @name_matchers
end

#name_setSet<String> (readonly)

Set of names that are matched against the deployment (process) name, port name, task name and type name

Returns:

  • (Set<String>)


52
53
54
# File 'lib/syskit/roby_app/logging_group.rb', line 52

def name_set
  @name_set
end

#portsSet<Models::Port> (readonly)

Set of port models whose ports should match

Returns:



41
42
43
# File 'lib/syskit/roby_app/logging_group.rb', line 41

def ports
  @ports
end

#tasksSet<Models::TaskContext> (readonly)

Set of task models whose ports should match

Returns:



36
37
38
# File 'lib/syskit/roby_app/logging_group.rb', line 36

def tasks
  @tasks
end

#typesSet<Typelib::Type> (readonly)

Set of types that should match

Returns:

  • (Set<Typelib::Type>)


46
47
48
# File 'lib/syskit/roby_app/logging_group.rb', line 46

def types
  @types
end

Instance Method Details

#add(model) ⇒ Object #add(deployment) ⇒ Object #add(port) ⇒ Object #add(name) ⇒ Object

Adds an object to this logging group

Overloads:

  • #add(model) ⇒ Object

    Parameters:

  • #add(deployment) ⇒ Object

    Parameters:

    • deployment (Models::Deployment)

      match any task which is supported by this deployment

  • #add(port) ⇒ Object

    Parameters:

    • model (Models::Port)

      match any port matching this model

  • #add(name) ⇒ Object

    Parameters:

    • name (String, Regexp, #===)

      match any object (deployment, task, port or type) whose name matches this.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/syskit/roby_app/logging_group.rb', line 78

def add(object)
    case object
    when Class
        if object < Syskit::TaskContext
            tasks << object
        elsif object < Syskit::Deployment
            deployments << object
        elsif object < Typelib::Type
            types << object
        else raise ArgumentError, "unexpected model type #{object}"
        end
    when Models::Port
        ports << object
    when String
        name_set << object
    else
        # Verify that the object can match strings
        begin
            object === "a test string"
        rescue Exception => e
            raise ArgumentError, "expected given object to match strings with #=== but it raised #{e}"
        end
        name_matchers << object
    end
end

#enabled=(flag) ⇒ Object

Controls whether the ports matching this group should be logged (enabled? == true) or not. See Syskit::RobyApp::LoggingConfiguration for the logging behaviour when a port is matched by multiple groups



26
# File 'lib/syskit/roby_app/logging_group.rb', line 26

attr_predicate :enabled? , true

#enabled?Object

Controls whether the ports matching this group should be logged (enabled? == true) or not. See Syskit::RobyApp::LoggingConfiguration for the logging behaviour when a port is matched by multiple groups



26
# File 'lib/syskit/roby_app/logging_group.rb', line 26

attr_predicate :enabled? , true

#matches_deployment?(deployment) ⇒ Boolean

Tests whether the given deployment is matched by this group

Parameters:

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/syskit/roby_app/logging_group.rb', line 115

def matches_deployment?(deployment)
    deployments.include?(deployment.model) ||
        matches_name?(deployment.model.deployment_name)
end

#matches_name?(name) ⇒ Boolean

Tests whether the given name is matched by this group

Parameters:

  • name (String)

Returns:

  • (Boolean)


107
108
109
110
# File 'lib/syskit/roby_app/logging_group.rb', line 107

def matches_name?(name)
    name_set.include?(name) ||
        name_matchers.any? { |m| m === name }
end

#matches_port?(port) ⇒ Boolean

Tests if this group matches the given port

Parameters:

Returns:

  • (Boolean)


145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/syskit/roby_app/logging_group.rb', line 145

def matches_port?(port)
    if ports.include?(port.model)
        true
    elsif ports.any? { |p| p.name == port.name && port.component.model.fullfills?(p.component_model) }
        true
    elsif matches_name?(port.name)
        true
    elsif matches_task?(port.component)
        true
    elsif matches_type?(port.type)
        true
    end
end

#matches_task?(task) ⇒ Boolean

Tests whether the given task is matched by this group

Parameters:

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
# File 'lib/syskit/roby_app/logging_group.rb', line 129

def matches_task?(task)
    if tasks.include?(task.model)
        true
    elsif tasks.any? { |t| task.model.fullfills?(t) }
        true
    elsif matches_name?(task.orocos_name)
        true
    elsif (deployment = task.execution_agent) && matches_deployment?(deployment)
        true
    end
end

#matches_type?(type) ⇒ Boolean

Tests whether the given type is matched by this group

Returns:

  • (Boolean)


121
122
123
124
# File 'lib/syskit/roby_app/logging_group.rb', line 121

def matches_type?(type)
    types.include?(type) ||
        matches_name?(type.name)
end