Skip to content

Commit

Permalink
Fix comparator.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Applencourt committed Nov 7, 2023
1 parent 84b6f18 commit 5b3c8f0
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions utils/bt_plugins/comparator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@ def consume_method(_self_component)
# and compare events fields
# If the number of message consumed by message iterator are differnts
# an error is raised
stack_messages = [[], []]

@message_iterators.each_with_index { |message_iterator, i|
message_iterator.next_messages.each { |m|
stack_messages[i] << m.event if m.type == :BT_MESSAGE_TYPE_EVENT
}
}
@message_iterators.each_with_index do |message_iterator, i|
message_iterator.next_messages.each do |m|
@stack_messages[i] << m.event if m.type == :BT_MESSAGE_TYPE_EVENT
end
end
end

def initialize_method(self_component, _configuration, _params, _data)
@stack_messages = [[], []]
self_component.add_input_port('in0')
self_component.add_input_port('in1')
end

stack_messages.transpose.each { |i, j|
%w[payload specific_context common_context].each { |tf|
def finalize_method(_self_component)
@stack_messages.transpose.each do |i, j|
%w[payload specific_context common_context].each do |tf|
i_value = i.send("get_#{tf}_field")
i_value = i_value.value if i_value
j_value = j.send("get_#{tf}_field")
Expand All @@ -26,27 +33,23 @@ def consume_method(_self_component)
pp({ in0: i_value, in1: j_value })
raise "Traces for #{tf} fields are different!"
end
}
}
end

def initialize_method(self_component, _configuration, _params, _data)
self_component.add_input_port('in0')
self_component.add_input_port('in1')
end
end
end

def graph_is_configured_method(self_component)
@message_iterators = self_component.get_input_port_count.times.map { |i|
@message_iterators = self_component.get_input_port_count.times.map do |i|
p = self_component.get_input_port_by_index(i)
self_component.create_message_iterator(p)
}
end
end

def create_component_class
component_class = BT2::BTComponentClass::Sink.new(name: 'comparator',
consume_method: lambda(&method(:consume_method)))

component_class.initialize_method = lambda(&method(:initialize_method))
component_class.finalize_method = lambda(&method(:finalize_method))
component_class.graph_is_configured_method = lambda(&method(:graph_is_configured_method))
component_class
end
Expand Down

0 comments on commit 5b3c8f0

Please sign in to comment.