Class: Orocos::Log::InterfaceObject

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/log/task_context.rb

Direct Known Subclasses

OutputPort, Property

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ InterfaceObject

Returns a new instance of InterfaceObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/orocos/log/task_context.rb', line 36

def initialize(stream)
    if !stream.respond_to?(:name) || !stream.respond_to?(:type) || !stream.respond_to?(:typename) || !stream.respond_to?(:metadata)
        raise ArgumentError, "cannot use #{stream} to back "\
            "a #{self.class.name}"
    end

    @stream = stream
    @type = stream.type
    @type_name = stream.type.name

    @name = guess_object_name(stream)
    @orocos_type_name = guess_orocos_type_name(stream)
end

Instance Attribute Details

#nameString (readonly)

The object name

Returns:

  • (String)


23
24
25
# File 'lib/orocos/log/task_context.rb', line 23

def name
  @name
end

#orocos_type_nameObject (readonly)

The underlying opaque type if #type is an intermediate type



34
35
36
# File 'lib/orocos/log/task_context.rb', line 34

def orocos_type_name
  @orocos_type_name
end

#streamPocolog::Datastream (readonly)

The backing stream

Returns:

  • (Pocolog::Datastream)


18
19
20
# File 'lib/orocos/log/task_context.rb', line 18

def stream
  @stream
end

#typeTypelib::Type (readonly)

The object type

Returns:

  • (Typelib::Type)


28
29
30
# File 'lib/orocos/log/task_context.rb', line 28

def type
  @type
end

#type_nameObject (readonly)

Deprecated.

use #type.name instead



31
32
33
# File 'lib/orocos/log/task_context.rb', line 31

def type_name
  @type_name
end

Instance Method Details

#guess_object_name(stream) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/orocos/log/task_context.rb', line 50

def guess_object_name(stream)
    if (name = stream.["rock_task_object_name"])
        return name
    end

    Log.warn "stream '#{stream.name}' has no rock_task_object_name "\
        "metadata, guessing the #{self.class.name} name from the "\
        "stream name"

    # backward compatibility
    if (name = stream.name.to_s.match(/\.(.*)$/))
        name[1]
    else
        Log.warn "stream name '#{stream.name}' does not follow "\
            "the convention TASKNAME.PORTNAME, taking it whole as "\
            "the #{self.class.name} name"
        stream.name
    end
end

#guess_orocos_type_name(stream) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/orocos/log/task_context.rb', line 70

def guess_orocos_type_name(stream)
     = stream. || Hash.new
    if (name = ['rock_orocos_type_name'])
        return name
    elsif (name = ['rock_cxx_type_name'])
        return name
    end

    Log.warn "stream '#{stream.name}' has neither the "\
        "rock_cxx_type_name nor the rock_orocos_type_name metadata set, "\
        "falling back on the Typelib type's name"
    if (match = /^(.*)_m$/.match(stream.type.name))
        match[1]
    else
        stream.type.name
    end
end