class OroGen::Spec::ConnPolicy

Representation of a RTT connection policy

Attributes

lock_policy[RW]

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

pull[RW]

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.

size[RW]

If type is :buffer, the size of the buffer

type[RW]

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

Public Class Methods

from_hash(hash) click to toggle source

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.

# 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
new() click to toggle source
# File lib/orogen/spec/deployment.rb, line 54
def initialize
    @type      = :data
    @lock_policy = :lock_free
    @pull      = false
    @size      = 0
end

Public Instance Methods

to_code(varname) click to toggle source
# 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