Class: OroGen::Spec::ConnPolicy

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

Overview

Representation of a RTT connection policy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnPolicy

Returns a new instance of ConnPolicy



54
55
56
57
58
59
# File 'lib/orogen/spec/deployment.rb', line 54

def initialize
    @type      = :data
    @lock_policy = :lock_free
    @pull      = false
    @size      = 0
end

Instance Attribute Details

#lock_policyObject

The connection lock type. Can be either :lock_free (the default) or :locked



46
47
48
# File 'lib/orogen/spec/deployment.rb', line 46

def lock_policy
  @lock_policy
end

#pullObject

If false (the default), samples are pushed across process boundaries automatically. If true, then the accessor side has to require the sample to be transferred.



50
51
52
# File 'lib/orogen/spec/deployment.rb', line 50

def pull
  @pull
end

#sizeObject

If type is :buffer, the size of the buffer



52
53
54
# File 'lib/orogen/spec/deployment.rb', line 52

def size
  @size
end

#typeObject

The connection type. Can be either :data (the default) or :buffer



44
45
46
# File 'lib/orogen/spec/deployment.rb', line 44

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates a new ConnPolicy object from a hash. For instance,

ConnPolicy.to_hash :type -> :data, :lock_policy -> :lock_free

Would create a connection policy with the given type and lock type, using default values for the rest. See attributes of ConnPolicy for valid parameters and valid values.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/orogen/spec/deployment.rb', line 68

def self.from_hash(hash)
    hash = hash.to_hash.dup

    policy = ConnPolicy.new
    type = hash.delete(:type) || :data
    if type == :data || type == :buffer
        policy.type = type
    else
        raise ArgumentError, "'type' can only be either :data or :buffer"
    end
        
    lock_policy = hash.delete(:lock_policy) || :lock_free
    if lock_policy == :lock_free || lock_policy == :locked
        policy.lock_policy = lock_policy
    else
        raise ArgumentError, "'lock_policy' can only be either :lock_free or :locked"
    end

    policy.pull = !!hash.delete(:pull)

    size = hash.delete(:size)
    if type == :data && size
        raise ArgumentError, "data connections don't have any size"
    end
    policy.size = Integer(size || 0)

    if !hash.empty?
        raise ArgumentError, "unknown policy specification options #{hash.keys.join(", ")}"
    elsif type == :buffer && policy.size <= 0
        raise ArgumentError, "you have to specify a buffer size"
    end

    policy
end

Instance Method Details

#to_code(varname) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/orogen/spec/deployment.rb', line 103

def to_code(varname)
    str = "RTT::ConnPolicy #{varname};\n"
    str << "#{varname}.type      = RTT::ConnPolicy::#{type.to_s.upcase};\n"
    str << "#{varname}.lock_policy = RTT::ConnPolicy::#{lock_policy.to_s.upcase};\n"
    str << "#{varname}.init      = false;\n"
    str << "#{varname}.pull      = #{pull ? "true" : "false"};\n"
    str << "#{varname}.size      = #{size};\n"
    str
end