metababel 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/btx_gen_source_callbacks +113 -0
- data/bin/metababel +31 -15
- data/lib/metababel/bt2_trace_class_generator.rb +41 -10
- data/lib/metababel/version.rb +1 -1
- data/template/component.c.erb +13 -1
- data/template/component.h.erb +1 -0
- data/template/downstream.c.erb +9 -0
- data/template/downstream.h.erb +5 -0
- data/template/filter.c.erb +13 -13
- data/template/sink.c.erb +1 -1
- data/template/source.c.erb +16 -22
- data/template/upstream.c.erb +20 -31
- data/template/upstream.h.erb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94a55badce2025551858542b3ad05ec6f2fadfa18ea7a3d32e43dfc8fa588505
|
|
4
|
+
data.tar.gz: 861f4853f64c5de23d47f6678e8a369b49b1e5f84cd4ad1944b077a32e5a8a87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10357d19a20bb264699f6f586f49fd2d5229a7da0ea7dd51234d5b5733bee78340c83f564a2084a26a99db9d13073332ad211c67def4b469c6251e2f219b4efa
|
|
7
|
+
data.tar.gz: 92a55fb2d187388088d13d30a827548b1543bec100f81ff4fa58a7dae41d77ad52f53268b33abd93a1149ea9479c838354b3d1b1773e6dbdf8f2b54a0ae1351b
|
data/README.md
CHANGED
|
@@ -38,8 +38,8 @@ stateDiagram-v2
|
|
|
38
38
|
|
|
39
39
|
```mermaid
|
|
40
40
|
stateDiagram-v2
|
|
41
|
-
[*] -->
|
|
42
|
-
|
|
41
|
+
[*] --> BTX_FILTER_STATE_INITIALIZING
|
|
42
|
+
BTX_FILTER_STATE_INITIALIZING --> BTX_FILTER_PROCESSING
|
|
43
43
|
state BTX_FILTER_PROCESSING {
|
|
44
44
|
[*] --> BTX_FILTER_PROCESSING_STATE_READING
|
|
45
45
|
[*] --> BTX_FILTER_PROCESSING_STATE_SENDING
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'erb'
|
|
6
|
+
require 'time'
|
|
7
|
+
|
|
8
|
+
REGEXT_PRETTY = /
|
|
9
|
+
=\s # We are interested to the right of the equal sign
|
|
10
|
+
(
|
|
11
|
+
""| # Empty string
|
|
12
|
+
".*?[^\\]"| # String who can contain space and quoted string
|
|
13
|
+
[^\s,]+ # Anything except space and comma
|
|
14
|
+
)
|
|
15
|
+
/x.freeze
|
|
16
|
+
|
|
17
|
+
SOURCE_TEMPLATE = <<~TEXT.freeze
|
|
18
|
+
/* Code generated by #{__FILE__} */
|
|
19
|
+
|
|
20
|
+
#include <metababel/metababel.h>
|
|
21
|
+
|
|
22
|
+
void btx_push_usr_messages(void *btx_handle, void *usr_data, btx_source_status_t *status) {
|
|
23
|
+
<%- if not data.empty? and not data.first[:hostname].nil? -%>
|
|
24
|
+
btx_downstream_set_environment_hostname(btx_handle, "<%= data.first[:hostname] %>");
|
|
25
|
+
<%- end -%>
|
|
26
|
+
|
|
27
|
+
<%- data.each do | entry | -%>
|
|
28
|
+
<%- entry.fetch(:times,1).times do -%>
|
|
29
|
+
btx_push_message_<%= entry[:name] %>(btx_handle<%= ', ' if not entry[:field_values].empty? %><%= entry[:field_values].join(", ") %>);
|
|
30
|
+
<%- end -%>
|
|
31
|
+
<%- end -%>
|
|
32
|
+
|
|
33
|
+
*status = BTX_SOURCE_END;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void btx_register_usr_callbacks(void *btx_handle) {
|
|
37
|
+
btx_register_callbacks_push_usr_messages(btx_handle, &btx_push_usr_messages);
|
|
38
|
+
}
|
|
39
|
+
TEXT
|
|
40
|
+
|
|
41
|
+
def parse_event(line)
|
|
42
|
+
h = { hostname: nil,
|
|
43
|
+
name: nil,
|
|
44
|
+
field_values: [] }
|
|
45
|
+
# Parse a token one at a time
|
|
46
|
+
head, tail = line.split(nil, 2)
|
|
47
|
+
# Timestamp?
|
|
48
|
+
if head.start_with?('[')
|
|
49
|
+
t = Time.parse(head[1...-1])
|
|
50
|
+
# Need to convert in nasosecond
|
|
51
|
+
h[:field_values] << ((t.to_i * 1_000_000_000) + t.nsec)
|
|
52
|
+
# discard next token, the offset "(+x.xxxxxxxx)", which
|
|
53
|
+
# always follows the bracketed timestamp
|
|
54
|
+
_, head, tail = tail.split(nil, 3)
|
|
55
|
+
end
|
|
56
|
+
# Hostname?
|
|
57
|
+
unless head.end_with?(':')
|
|
58
|
+
h[:hostname] = head
|
|
59
|
+
head, tail = tail.split(nil, 2)
|
|
60
|
+
end
|
|
61
|
+
h[:name] = head.chop.gsub(/[^0-9A-Za-z-]/, '_')
|
|
62
|
+
# Handle the fields
|
|
63
|
+
h[:field_values] += tail.scan(REGEXT_PRETTY).flatten
|
|
64
|
+
h
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def parse_log(input_path)
|
|
68
|
+
File.open(input_path, 'r') do |file|
|
|
69
|
+
file.each_line.map do |line|
|
|
70
|
+
parse_event(line)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def render_and_save(data, output_path)
|
|
76
|
+
renderer = ERB.new(SOURCE_TEMPLATE, trim_mode: '-')
|
|
77
|
+
output = renderer.result(binding)
|
|
78
|
+
File.write(output_path, output, mode: 'w')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
DOCS = <<-DOCS.freeze
|
|
82
|
+
Usage: #{$0}.rb [options]
|
|
83
|
+
|
|
84
|
+
Example:
|
|
85
|
+
ruby #{$0} -y stream_classes.yaml -i btx_log.txt -o callbacks.c
|
|
86
|
+
DOCS
|
|
87
|
+
|
|
88
|
+
# Display help if no arguments.
|
|
89
|
+
ARGV << '-h' if ARGV.empty?
|
|
90
|
+
|
|
91
|
+
options = {}
|
|
92
|
+
|
|
93
|
+
OptionParser.new do |opts|
|
|
94
|
+
opts.banner = DOCS
|
|
95
|
+
|
|
96
|
+
opts.on('-h', '--help', 'Prints this help') do
|
|
97
|
+
puts opts
|
|
98
|
+
exit
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
opts.on('-i', '--log PATH', '[Mandatory] Path to btx_log.txt.') do |p|
|
|
102
|
+
options[:input_path] = p
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
opts.on('-o', '--output PATH', '[Mandatory] Path to the bt2 SOURCE file.') do |p|
|
|
106
|
+
options[:output_path] = p
|
|
107
|
+
end
|
|
108
|
+
end.parse!
|
|
109
|
+
|
|
110
|
+
raise OptionParser::MissingArgument if options[:output_path].nil?
|
|
111
|
+
|
|
112
|
+
data = options.key?(:input_path) ? parse_log(options[:input_path]) : []
|
|
113
|
+
render_and_save(data, options[:output_path])
|
data/bin/metababel
CHANGED
|
@@ -62,8 +62,11 @@ class BaseDispatch
|
|
|
62
62
|
alias eql? ==
|
|
63
63
|
|
|
64
64
|
def hash
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
# Remove cycle in dependency, and memos
|
|
66
|
+
blacklist = %i[@dispatch_types @matched_dispatchers @body_args]
|
|
67
|
+
instance_variables.filter_map do |i|
|
|
68
|
+
instance_variable_get(i).hash unless blacklist.include?(i)
|
|
69
|
+
end.reduce(:^)
|
|
67
70
|
end
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -103,8 +106,8 @@ class Dispatcher < BaseDispatch
|
|
|
103
106
|
@index_stream_class = index_stream_class
|
|
104
107
|
@index_event_class = index_event_class
|
|
105
108
|
@default_clock_class = default_clock_class
|
|
106
|
-
@dispatch_types = []
|
|
107
109
|
@name = event.name
|
|
110
|
+
@dispatch_types = []
|
|
108
111
|
end
|
|
109
112
|
|
|
110
113
|
def body_args
|
|
@@ -230,13 +233,12 @@ def parse_argv
|
|
|
230
233
|
end
|
|
231
234
|
|
|
232
235
|
def get_dispatch_type(em, default_clock_class, context)
|
|
233
|
-
|
|
234
236
|
begin
|
|
235
237
|
dispatchers = em.domain ? OpenStruct.new(context).instance_eval(em.domain) : context['all']
|
|
236
238
|
rescue StandardError
|
|
237
239
|
raise "Please ensure the domain '#{em.domain}' uses valid ruby expressions and all set_id have been previously defined. Current defined set_ids: #{context.keys}."
|
|
238
240
|
end
|
|
239
|
-
|
|
241
|
+
raise 'Metababel Hash Set problem' unless (dispatchers - dispatchers).empty?
|
|
240
242
|
raise "Nil or empty event set for '#{em.set_id}'." unless dispatchers.is_a?(Set)
|
|
241
243
|
|
|
242
244
|
matched_dispatchers, signatures = dispatchers.filter_map do |dispatcher|
|
|
@@ -251,19 +253,20 @@ def get_dispatch_type(em, default_clock_class, context)
|
|
|
251
253
|
# Verify the uniqueness of signatures.
|
|
252
254
|
# Note that `s.type` takes into account the `cast_type`
|
|
253
255
|
# (see TestMatchingConflictingSignatures for more details)
|
|
254
|
-
unique_signatures = signatures.uniq
|
|
256
|
+
unique_signatures = signatures.map { |s| "(#{s.map(&:type).join(', ')})" }.uniq
|
|
255
257
|
unless unique_signatures.size == 1
|
|
256
|
-
signatures_str = unique_signatures.
|
|
258
|
+
signatures_str = unique_signatures.join(', ')
|
|
257
259
|
raise "Conflicting signatures for '#{em.set_id}', found #{unique_signatures.size} signatures, only one allowed: '#{signatures_str}'"
|
|
258
260
|
end
|
|
259
261
|
|
|
260
262
|
# Modify the dispatcher to add the new dispatchType
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
dispatch_type_args
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
timestamp = default_clock_class ? [GeneratedArg.new('int64_t', '_timestamp')] : []
|
|
264
|
+
event_class_name = [GeneratedArg.new('const char *', '_event_class_name')]
|
|
265
|
+
dispatch_type_args = matched_dispatchers.zip(signatures).map do |m, s|
|
|
266
|
+
[m.name, timestamp + event_class_name + s]
|
|
267
|
+
end.to_h
|
|
266
268
|
|
|
269
|
+
name = em.set_id
|
|
267
270
|
dispatch_type = DispatchType.new(
|
|
268
271
|
name, dispatch_type_args, "matching_#{sanitize(name)}", matched_dispatchers
|
|
269
272
|
)
|
|
@@ -354,7 +357,7 @@ class ContextBuilder
|
|
|
354
357
|
|
|
355
358
|
def callback_types
|
|
356
359
|
@callback_types ||= begin
|
|
357
|
-
callback_types = ['
|
|
360
|
+
callback_types = ['automatic']
|
|
358
361
|
if @cli_options.key?(:matching)
|
|
359
362
|
event_classes = trace_matcher.stream_classes.map(&:event_classes).flatten(1).filter do |em|
|
|
360
363
|
raise "Key ':set_id' required for matching events." unless em.set_id
|
|
@@ -409,7 +412,20 @@ class ContextBuilder
|
|
|
409
412
|
t.get_declarator(variable: '_trace_class', self_component: '_self_component')
|
|
410
413
|
end
|
|
411
414
|
|
|
415
|
+
downstream_environements = if t.environment.nil?
|
|
416
|
+
[]
|
|
417
|
+
else
|
|
418
|
+
t.environment.entries.map do |e|
|
|
419
|
+
args = {}
|
|
420
|
+
body = "\n" + Babeltrace2Gen.context(indent: 1) do
|
|
421
|
+
e.get_setter(trace: '_trace', arg_variables: args)
|
|
422
|
+
end
|
|
423
|
+
[args['outputs'].first, body]
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
412
427
|
{ body_declarator_classes: body_declarator_classes,
|
|
428
|
+
downstream_environements: downstream_environements,
|
|
413
429
|
downstream_events: downstream_events,
|
|
414
430
|
stream_classes: t.stream_classes,
|
|
415
431
|
event_name: event_name }
|
|
@@ -427,7 +443,7 @@ class ContextBuilder
|
|
|
427
443
|
dispatchers, automatic_dispatch_types = t.filter_map_event_classes_with_index do |e, index_stream_class, index_event_class, default_clock_class|
|
|
428
444
|
dispatcher = Dispatcher.new(e, event_name, 'getter', index_stream_class, index_event_class,
|
|
429
445
|
default_clock_class)
|
|
430
|
-
dispatch_type = DispatchType.new(e.name, dispatcher.args, '
|
|
446
|
+
dispatch_type = DispatchType.new(e.name, { e.name => dispatcher.args }, 'automatic', [dispatcher])
|
|
431
447
|
dispatcher.dispatch_types << dispatch_type
|
|
432
448
|
|
|
433
449
|
[dispatcher, dispatch_type]
|
|
@@ -459,7 +475,7 @@ end
|
|
|
459
475
|
|
|
460
476
|
def wrote_upstream(cb)
|
|
461
477
|
erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.h', cb.folder)
|
|
462
|
-
erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.c', cb.folder)
|
|
478
|
+
erb_render_and_save(cb.get_context(%w[upstream callback_types]), 'upstream.c', cb.folder)
|
|
463
479
|
end
|
|
464
480
|
|
|
465
481
|
def wrote_downstream(cb)
|
|
@@ -100,8 +100,6 @@ module Babeltrace2Gen
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def get_declarator(variable:, self_component:)
|
|
103
|
-
raise NotImplementedError, "':environment' keyword not supported in downstream model" if environment
|
|
104
|
-
|
|
105
103
|
pr "#{variable} = bt_trace_class_create(#{self_component});"
|
|
106
104
|
bt_set_conditionally(@assigns_automatic_stream_class_id) do |v|
|
|
107
105
|
pr "bt_trace_class_set_assigns_automatic_stream_class_id(#{variable}, #{v});"
|
|
@@ -632,6 +630,7 @@ module Babeltrace2Gen
|
|
|
632
630
|
|
|
633
631
|
class BTFieldClass::Array::Static < BTFieldClass::Array
|
|
634
632
|
extend BTFromH
|
|
633
|
+
using HashRefinements
|
|
635
634
|
attr_reader :length
|
|
636
635
|
|
|
637
636
|
def initialize(parent:, element_field_class:, length:)
|
|
@@ -645,8 +644,34 @@ module Babeltrace2Gen
|
|
|
645
644
|
pr "bt_field_class *#{element_field_class_variable};"
|
|
646
645
|
@element_field_class.get_declarator(trace_class: trace_class, variable: element_field_class_variable)
|
|
647
646
|
pr "#{variable} = bt_field_class_array_static_create(#{trace_class}, #{element_field_class_variable}, #{@length});"
|
|
647
|
+
pr "bt_field_class_put_ref(#{element_field_class_variable});"
|
|
648
648
|
end
|
|
649
649
|
end
|
|
650
|
+
|
|
651
|
+
def get_setter(field:, arg_variables:)
|
|
652
|
+
usr_var = bt_get_variable(arg_variables, is_array: true)
|
|
653
|
+
pr "for(uint64_t _i=0; _i < #{@length} ; _i++)"
|
|
654
|
+
scope do
|
|
655
|
+
v = "#{field}_e"
|
|
656
|
+
pr "bt_field* #{v} = bt_field_array_borrow_element_field_by_index(#{field}, _i);"
|
|
657
|
+
arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
|
|
658
|
+
@element_field_class.get_setter(field: v, arg_variables: arg_variables)
|
|
659
|
+
end
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
def get_getter(field:, arg_variables:)
|
|
663
|
+
length = @length
|
|
664
|
+
usr_var = bt_get_variable(arg_variables, is_array: true)
|
|
665
|
+
pr "#{usr_var.name} = (#{usr_var.type}) malloc(#{length} * sizeof(#{usr_var.name}));"
|
|
666
|
+
pr "for(uint64_t _i=0; _i < #{length} ; _i++)"
|
|
667
|
+
scope do
|
|
668
|
+
v = "#{field}_e"
|
|
669
|
+
pr "const bt_field* #{v} = bt_field_array_borrow_element_field_by_index_const(#{field}, _i);"
|
|
670
|
+
arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
|
|
671
|
+
@element_field_class.get_getter(field: v, arg_variables: arg_variables)
|
|
672
|
+
end
|
|
673
|
+
end
|
|
674
|
+
|
|
650
675
|
end
|
|
651
676
|
|
|
652
677
|
class BTFieldClass::Array::Dynamic < BTFieldClass::Array
|
|
@@ -958,15 +983,20 @@ module Babeltrace2Gen
|
|
|
958
983
|
end
|
|
959
984
|
|
|
960
985
|
def get_getter(trace:, arg_variables:)
|
|
961
|
-
var_name =
|
|
962
|
-
arg_variables.fetch_append('outputs', bt_get_variable)
|
|
963
|
-
bt_func_get = self.class.instance_variable_get(:@bt_func)
|
|
986
|
+
var_name = bt_get_variable(arg_variables).name
|
|
964
987
|
pr "const bt_value *#{var_name}_value = bt_trace_borrow_environment_entry_value_by_name_const(#{trace}, \"#{var_name}\");"
|
|
965
|
-
pr "#{var_name} = #{
|
|
988
|
+
pr "#{var_name} = bt_value_#{@type}_get(#{var_name}_value);"
|
|
966
989
|
end
|
|
967
990
|
|
|
968
|
-
def
|
|
969
|
-
|
|
991
|
+
def get_setter(trace:, arg_variables:)
|
|
992
|
+
var_name = bt_get_variable(arg_variables).name
|
|
993
|
+
bt_type_set = self.class.instance_variable_get(:@bt_type_set)
|
|
994
|
+
pr "bt_trace_set_environment_entry_#{bt_type_set}(#{trace}, \"#{var_name}\", #{var_name});"
|
|
995
|
+
end
|
|
996
|
+
|
|
997
|
+
def bt_get_variable(arg_variables={})
|
|
998
|
+
var = GeneratedArg.new(self.class.instance_variable_get(:@bt_type), @name)
|
|
999
|
+
arg_variables.fetch_append('outputs', var)
|
|
970
1000
|
end
|
|
971
1001
|
end
|
|
972
1002
|
|
|
@@ -978,13 +1008,14 @@ module Babeltrace2Gen
|
|
|
978
1008
|
extend BTFromH
|
|
979
1009
|
|
|
980
1010
|
@bt_type = 'const char*'
|
|
981
|
-
@
|
|
1011
|
+
@bt_type_set = 'string'
|
|
982
1012
|
end
|
|
983
1013
|
|
|
984
1014
|
class BTEntryClass::IntegerSigned < BTEntryClass
|
|
985
1015
|
extend BTFromH
|
|
986
1016
|
|
|
987
1017
|
@bt_type = 'int64_t'
|
|
988
|
-
|
|
1018
|
+
# Sadly it's ` bt_trace_set_environment_entry_integer() ` and not ` bt_trace_set_environment_entry_integer_signed()`
|
|
1019
|
+
@bt_type_set = 'integer'
|
|
989
1020
|
end
|
|
990
1021
|
end
|
data/lib/metababel/version.rb
CHANGED
data/template/component.c.erb
CHANGED
|
@@ -14,7 +14,6 @@ void btx_populate_params(common_data_t *common_data) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
<% static_callback_types.each do |e| %>
|
|
17
|
-
|
|
18
17
|
void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
19
18
|
void *btx_handle, <%= e.name_sanitized %>_static_callback_f *callback) {
|
|
20
19
|
((common_data_t *)btx_handle)->static_callbacks-><%= e.name_sanitized %> =
|
|
@@ -32,3 +31,16 @@ void btx_call_callbacks_<%= e.name_sanitized %>(
|
|
|
32
31
|
<%= e.args.map{ |s| s.name }.join(", ") %>);
|
|
33
32
|
}
|
|
34
33
|
<% end %>
|
|
34
|
+
|
|
35
|
+
void btx_unregister_callbacks(common_data_t *common_data) {
|
|
36
|
+
name_to_dispatcher_t *current, *tmp;
|
|
37
|
+
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
38
|
+
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
39
|
+
<% callback_types.each do |id| %>
|
|
40
|
+
if (current->callbacks-><%= id %>)
|
|
41
|
+
utarray_free(current->callbacks-><%= id %>);
|
|
42
|
+
<% end %>
|
|
43
|
+
free(current->callbacks);
|
|
44
|
+
free(current);
|
|
45
|
+
}
|
|
46
|
+
}
|
data/template/component.h.erb
CHANGED
|
@@ -169,6 +169,7 @@ struct common_data_s {
|
|
|
169
169
|
<% end %>
|
|
170
170
|
|
|
171
171
|
void btx_register_usr_callbacks(void *btx_handle);
|
|
172
|
+
void btx_unregister_callbacks(common_data_t *common_data);
|
|
172
173
|
|
|
173
174
|
<% static_callback_types.each do |e| %>
|
|
174
175
|
typedef void <%= e.name_sanitized %>_static_callback_f(
|
data/template/downstream.c.erb
CHANGED
|
@@ -173,3 +173,12 @@ void btx_push_message_<%= e.name_sanitized %>(
|
|
|
173
173
|
btx_downstream_push_message(_message_iterator_private_data, _message);
|
|
174
174
|
}
|
|
175
175
|
<% end %>
|
|
176
|
+
|
|
177
|
+
<% downstream_environements.each do |arg, body| %>
|
|
178
|
+
void btx_downstream_set_environment_<%= arg.name%>(void *btx_handle,
|
|
179
|
+
<%= arg.type%> <%= arg.name%>) {
|
|
180
|
+
common_data_t *common_data = (common_data_t *)btx_handle;
|
|
181
|
+
bt_trace *_trace = common_data->downstream_trace;
|
|
182
|
+
<%= body %>
|
|
183
|
+
}
|
|
184
|
+
<% end %>
|
data/template/downstream.h.erb
CHANGED
|
@@ -42,6 +42,11 @@ void btx_register_on_downstream_message_callback(
|
|
|
42
42
|
void *btx_handle, on_downstream_message_callback_f *callback);
|
|
43
43
|
<% end %>
|
|
44
44
|
|
|
45
|
+
<% downstream_environements.each do |arg, body| %>
|
|
46
|
+
void btx_downstream_set_environment_<%= arg.name%>(void *btx_handle,
|
|
47
|
+
<%= arg.type%> <%= arg.name%>);
|
|
48
|
+
<% end %>
|
|
49
|
+
|
|
45
50
|
#ifdef __cplusplus
|
|
46
51
|
}
|
|
47
52
|
#endif
|
data/template/filter.c.erb
CHANGED
|
@@ -347,18 +347,6 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
347
347
|
common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
|
|
348
348
|
common_data->params = params;
|
|
349
349
|
|
|
350
|
-
/* Read parameters */
|
|
351
|
-
btx_populate_params(common_data);
|
|
352
|
-
bt_value_get_ref(common_data->params);
|
|
353
|
-
|
|
354
|
-
/* Register User Callbacks */
|
|
355
|
-
btx_register_usr_callbacks((void *)common_data);
|
|
356
|
-
/* Call initialize_processing*/
|
|
357
|
-
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
358
|
-
/* Call read callbacks */
|
|
359
|
-
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
360
|
-
common_data->btx_params);
|
|
361
|
-
|
|
362
350
|
/* Set the component's user data to our private data structure */
|
|
363
351
|
bt_self_component_set_data(
|
|
364
352
|
bt_self_component_filter_as_self_component(self_component_filter),
|
|
@@ -406,6 +394,18 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
406
394
|
btx_streams_get_ref(common_data->downstream_trace); // ??
|
|
407
395
|
bt_trace_class_put_ref(trace_class);
|
|
408
396
|
|
|
397
|
+
/* Read parameters */
|
|
398
|
+
btx_populate_params(common_data);
|
|
399
|
+
bt_value_get_ref(common_data->params);
|
|
400
|
+
|
|
401
|
+
/* Register User Callbacks */
|
|
402
|
+
btx_register_usr_callbacks((void *)common_data);
|
|
403
|
+
/* Call initialize_processing*/
|
|
404
|
+
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
405
|
+
/* Call read callbacks */
|
|
406
|
+
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
407
|
+
common_data->btx_params);
|
|
408
|
+
|
|
409
409
|
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
410
410
|
}
|
|
411
411
|
|
|
@@ -488,7 +488,7 @@ static void filter_finalize(bt_self_component_filter *self_component_filter) {
|
|
|
488
488
|
bt_trace_put_ref(common_data->downstream_trace);
|
|
489
489
|
|
|
490
490
|
/* Delete name_to_dispatchers */
|
|
491
|
-
|
|
491
|
+
btx_unregister_callbacks(common_data);
|
|
492
492
|
|
|
493
493
|
/* We allocate it, we need to free it */
|
|
494
494
|
free(common_data->btx_params);
|
data/template/sink.c.erb
CHANGED
|
@@ -126,7 +126,7 @@ static void sink_finalize(bt_self_component_sink *self_component_sink) {
|
|
|
126
126
|
btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
|
|
127
127
|
|
|
128
128
|
// Delete name_to_dispatcher
|
|
129
|
-
|
|
129
|
+
btx_unregister_callbacks(common_data);
|
|
130
130
|
|
|
131
131
|
// We allocate it, we need to free it
|
|
132
132
|
free(common_data->btx_params);
|
data/template/source.c.erb
CHANGED
|
@@ -96,18 +96,6 @@ source_initialize(bt_self_component_source *self_component_source,
|
|
|
96
96
|
common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
|
|
97
97
|
common_data->params = params;
|
|
98
98
|
|
|
99
|
-
/* Read parameters */
|
|
100
|
-
btx_populate_params(common_data);
|
|
101
|
-
bt_value_get_ref(common_data->params);
|
|
102
|
-
|
|
103
|
-
/* Register User Callbacks */
|
|
104
|
-
btx_register_usr_callbacks((void *)common_data);
|
|
105
|
-
/* Call initialize_processing*/
|
|
106
|
-
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
107
|
-
/* Call read callbacks */
|
|
108
|
-
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
109
|
-
common_data->btx_params);
|
|
110
|
-
|
|
111
99
|
/* Upcast `self_component_source` to the `bt_self_component` type */
|
|
112
100
|
bt_self_component *self_component =
|
|
113
101
|
bt_self_component_source_as_self_component(self_component_source);
|
|
@@ -134,6 +122,18 @@ source_initialize(bt_self_component_source *self_component_source,
|
|
|
134
122
|
bt_self_component_source_add_output_port(self_component_source, "out", NULL,
|
|
135
123
|
NULL);
|
|
136
124
|
|
|
125
|
+
/* Read parameters */
|
|
126
|
+
btx_populate_params(common_data);
|
|
127
|
+
bt_value_get_ref(common_data->params);
|
|
128
|
+
|
|
129
|
+
/* Register User Callbacks */
|
|
130
|
+
btx_register_usr_callbacks((void *)common_data);
|
|
131
|
+
/* Call initialize_processing*/
|
|
132
|
+
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
133
|
+
/* Call read callbacks */
|
|
134
|
+
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
135
|
+
common_data->btx_params);
|
|
136
|
+
|
|
137
137
|
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -176,19 +176,13 @@ static void source_finalize(bt_self_component_source *self_component_source) {
|
|
|
176
176
|
btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
|
|
177
177
|
|
|
178
178
|
btx_streams_put_ref(common_data->downstream_trace); // ??
|
|
179
|
-
|
|
179
|
+
/* We allocate it, we need to put ref */
|
|
180
180
|
bt_trace_put_ref(common_data->downstream_trace);
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
185
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
186
|
-
utarray_free(current->callbacks->generic);
|
|
187
|
-
free(current->callbacks);
|
|
188
|
-
free(current);
|
|
189
|
-
}
|
|
182
|
+
/* Delete name_to_dispatchers */
|
|
183
|
+
btx_unregister_callbacks(common_data);
|
|
190
184
|
|
|
191
|
-
|
|
185
|
+
/* We allocate it, we need to free it */
|
|
192
186
|
free(common_data->btx_params);
|
|
193
187
|
free(common_data->static_callbacks);
|
|
194
188
|
bt_value_put_ref(common_data->params);
|
data/template/upstream.c.erb
CHANGED
|
@@ -28,7 +28,7 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
28
28
|
bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
|
|
29
29
|
<% end %>
|
|
30
30
|
<%# event_class_name, only required when there is at least one matching callback for this event. %>
|
|
31
|
-
<% if dispatcher.dispatch_types.map
|
|
31
|
+
<% if dispatcher.dispatch_types.map { |dt| dt.args[dispatcher.name] }.flatten.any? { |arg| arg.name == '_event_class_name' } %>
|
|
32
32
|
const char *_event_class_name = "<%= dispatcher.name %>";
|
|
33
33
|
<% end %>
|
|
34
34
|
|
|
@@ -42,7 +42,7 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
42
42
|
(*((<%= dispatch_type.name_sanitized %>_callback_f **)(_p)))(
|
|
43
43
|
(void *)common_data,
|
|
44
44
|
common_data
|
|
45
|
-
->usr_data<%= dispatch_type.args.map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
45
|
+
->usr_data<%= dispatch_type.args[dispatcher.name].map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -54,56 +54,45 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
<% end %>
|
|
57
|
-
|
|
58
|
-
void
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
static void bt_register_callbacks(void *btx_handle, const char *dispatcher_name,
|
|
59
|
+
void *btx_dispatch_p, const char *id,
|
|
60
|
+
void *callback) {
|
|
61
|
+
|
|
61
62
|
name_to_dispatcher_t *s = NULL;
|
|
63
|
+
|
|
62
64
|
name_to_dispatcher_t **name_to_dispatcher =
|
|
63
65
|
&((common_data_t *)btx_handle)->name_to_dispatcher;
|
|
64
|
-
HASH_FIND_STR(*name_to_dispatcher,
|
|
66
|
+
HASH_FIND_STR(*name_to_dispatcher, dispatcher_name, s);
|
|
67
|
+
|
|
65
68
|
if (!s) {
|
|
66
69
|
// We didn't find the dispatcher, so we need to create it.
|
|
67
70
|
s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
|
|
68
|
-
s->name =
|
|
69
|
-
s->dispatcher =
|
|
71
|
+
s->name = dispatcher_name;
|
|
72
|
+
s->dispatcher = btx_dispatch_p;
|
|
70
73
|
s->callbacks = (callbacks_t *)calloc(1, sizeof(callbacks_t));
|
|
71
74
|
// 2. Register it
|
|
72
75
|
HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
<%
|
|
76
|
-
if (strcmp("<%=
|
|
78
|
+
<% callback_types.each_with_index do |id,i| %>
|
|
79
|
+
<%= i == 0 ? "if" : "else if" %>(strcmp("<%= id %>", id) == 0) {
|
|
77
80
|
// Add the callbacks to the array
|
|
78
|
-
if (!s->callbacks-><%=
|
|
79
|
-
utarray_new(s->callbacks-><%=
|
|
80
|
-
utarray_push_back(s->callbacks-><%=
|
|
81
|
+
if (!s->callbacks-><%= id %>)
|
|
82
|
+
utarray_new(s->callbacks-><%= id %>, &ut_ptr_icd);
|
|
83
|
+
utarray_push_back(s->callbacks-><%= id %>, &callback);
|
|
81
84
|
}
|
|
82
|
-
|
|
83
85
|
<% end %>
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
<% end %>
|
|
87
88
|
<% dispatch_types.each do |dispatch_type| %>
|
|
88
89
|
void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
|
|
89
90
|
void *btx_handle,
|
|
90
91
|
<%= dispatch_type.name_sanitized %>_callback_f *callback) {
|
|
91
92
|
<% dispatch_type.matched_dispatchers.each do |dispatcher| %>
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
bt_register_callbacks(btx_handle, "<%= dispatcher.name %>",
|
|
94
|
+
(void *)&btx_dispatch_<%= dispatcher.name_sanitized %>,
|
|
95
|
+
"<%= dispatch_type.id %>", (void *)callback);
|
|
94
96
|
<% end %>
|
|
95
97
|
}
|
|
96
|
-
|
|
97
98
|
<% end %>
|
|
98
|
-
void btx_delete_dispatchers(common_data_t *common_data) {
|
|
99
|
-
name_to_dispatcher_t *current, *tmp;
|
|
100
|
-
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
101
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
102
|
-
<% dispatch_types.map(&:id).uniq.each do |name| %>
|
|
103
|
-
if (current->callbacks-><%= name %>)
|
|
104
|
-
utarray_free(current->callbacks-><%= name %>);
|
|
105
|
-
<% end %>
|
|
106
|
-
free(current->callbacks);
|
|
107
|
-
free(current);
|
|
108
|
-
}
|
|
109
|
-
}
|
data/template/upstream.h.erb
CHANGED
|
@@ -13,13 +13,13 @@ typedef void(dispatcher_t)(callbacks_t *callbacks, common_data_t *common_data,
|
|
|
13
13
|
typedef void <%= dispatch_type.name_sanitized %>_callback_f(
|
|
14
14
|
void *btx_handle,
|
|
15
15
|
void *
|
|
16
|
-
usr_data<%= dispatch_type.args.map{ |s| s.type }.join_with_prefix(', ') %>);
|
|
16
|
+
usr_data<%= dispatch_type.args.values[0].map{ |s| s.type }.join_with_prefix(', ') %>);
|
|
17
17
|
|
|
18
18
|
void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
|
|
19
19
|
void *btx_handle, <%= dispatch_type.name_sanitized %>_callback_f *callback);
|
|
20
20
|
|
|
21
21
|
<% end %>
|
|
22
|
-
void
|
|
22
|
+
void btx_unregister_callbacks(common_data_t *common_data);
|
|
23
23
|
|
|
24
24
|
#ifdef __cplusplus
|
|
25
25
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metababel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Applencourt
|
|
@@ -10,16 +10,18 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2024-02-16 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email:
|
|
17
17
|
executables:
|
|
18
18
|
- metababel
|
|
19
|
+
- btx_gen_source_callbacks
|
|
19
20
|
extensions: []
|
|
20
21
|
extra_rdoc_files: []
|
|
21
22
|
files:
|
|
22
23
|
- README.md
|
|
24
|
+
- bin/btx_gen_source_callbacks
|
|
23
25
|
- bin/metababel
|
|
24
26
|
- lib/metababel.rb
|
|
25
27
|
- lib/metababel/bt2_generator_utils.rb
|