metababel 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8622843bd93dc9b0e2ed91f3ad7bb444ea2216ba183651d17773de232749a187
4
- data.tar.gz: 762a87b56229cee6bebe99ebb5358610672a6fb2a171718c3255ad079391ba85
3
+ metadata.gz: 29d62dad7a8e18caa6eae836db0caf7b0e7dd5012c6d83492e51140d9c4ab110
4
+ data.tar.gz: 9781c211009fbb238c4a96b3faf0341607da2b202155179f58aa545d75f45809
5
5
  SHA512:
6
- metadata.gz: 0fbe1685dafbc6d45e03a494607efa1010cde5973167f394150322b36d784eb23305664b8adea0ef12d90c0552a61d726cb1fce83620211f8827c1e4101f0ee0
7
- data.tar.gz: cb578b9f45359fd1a93d219761f41ecdb0e0670150be69c731f4d5c1c2695e3ade918e2b5e825701cff380dcaaad6f76c09638628664f3d879f009191e9f9b58
6
+ metadata.gz: d0fef46f9f4461770e2b1994e087788a53dfe3b198d8a529e9e0486320a788f6eac20b4230605f612dbd7cdcbc69746b93e9605f06086353f78a70f6da5774f0
7
+ data.tar.gz: '0791014239ed111d63148bdb45c2a8d48f45ad0e51a2440fc9171e2220465add097e1f7a4340fef82aca2f4f2b303e1083803ab9d76a6252cfbf9795fc72dfbe'
data/bin/metababel CHANGED
@@ -7,6 +7,7 @@ require 'metababel'
7
7
  require 'fileutils'
8
8
  require 'set'
9
9
  require 'ostruct'
10
+ require 'abbrev'
10
11
 
11
12
  class Array
12
13
  def join_with_prefix(sep)
@@ -54,14 +55,18 @@ class BaseDispatch
54
55
 
55
56
  # https://ruby-doc.org/3.2.2/Hash.html#class-Hash-label-User-Defined+Hash+Keys
56
57
  def ==(other)
57
- self.class === other and
58
+ other.is_a?(self.class) and
58
59
  instance_variables.all? { |s| instance_variable_get(s) == other.instance_variable_get(s) }
59
60
  end
60
61
 
61
62
  alias eql? ==
62
63
 
63
64
  def hash
64
- instance_variables.reduce(0) { |a, b| a ^ instance_variable_get(b).hash }
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(:^)
65
70
  end
66
71
  end
67
72
 
@@ -101,8 +106,8 @@ class Dispatcher < BaseDispatch
101
106
  @index_stream_class = index_stream_class
102
107
  @index_event_class = index_event_class
103
108
  @default_clock_class = default_clock_class
104
- @dispatch_types = []
105
109
  @name = event.name
110
+ @dispatch_types = []
106
111
  end
107
112
 
108
113
  def body_args
@@ -173,8 +178,13 @@ def parse_argv
173
178
  exit
174
179
  end
175
180
 
176
- opts.on('-t', '--component TYPE', '[Mandatory] Node within a trace processing graph.') do |p|
177
- options[:component_type] = p
181
+ opts.on('-t', '--component TYPE',
182
+ '[Mandatory] Node within a trace processing graph [one of: SINK, SOURCE, FILTER].') do |p|
183
+ l = %w[SOURCE FILTER SINK]
184
+ h = Abbrev.abbrev(l)
185
+ raise "Invalid component type, should be #{l} (case insentitive)" unless h.include?(p.upcase)
186
+
187
+ options[:component_type] = h[p.upcase]
178
188
  end
179
189
 
180
190
  opts.on('-u', '--upstreams PATH', Array, '[Mandatory] Path to the bt2 YAML files for the upstream model.') do |p|
@@ -212,7 +222,6 @@ def parse_argv
212
222
  opts.on('--enable-callbacks NAME', Array, '[Optional] Enable some callbacks type') do |p|
213
223
  options[:disable_callbaks] -= p.to_set
214
224
  end
215
-
216
225
  end.parse!
217
226
 
218
227
  raise OptionParser::MissingArgument if options[:component_type].nil?
@@ -224,7 +233,12 @@ def parse_argv
224
233
  end
225
234
 
226
235
  def get_dispatch_type(em, default_clock_class, context)
227
- dispatchers = em.domain ? OpenStruct.new(context).instance_eval(em.domain) : context['all']
236
+ begin
237
+ dispatchers = em.domain ? OpenStruct.new(context).instance_eval(em.domain) : context['all']
238
+ rescue StandardError
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}."
240
+ end
241
+ raise 'Metababel Hash Set problem' unless (dispatchers - dispatchers).empty?
228
242
  raise "Nil or empty event set for '#{em.set_id}'." unless dispatchers.is_a?(Set)
229
243
 
230
244
  matched_dispatchers, signatures = dispatchers.filter_map do |dispatcher|
@@ -239,19 +253,20 @@ def get_dispatch_type(em, default_clock_class, context)
239
253
  # Verify the uniqueness of signatures.
240
254
  # Note that `s.type` takes into account the `cast_type`
241
255
  # (see TestMatchingConflictingSignatures for more details)
242
- unique_signatures = signatures.uniq
256
+ unique_signatures = signatures.map { |s| "(#{s.map(&:type).join(', ')})" }.uniq
243
257
  unless unique_signatures.size == 1
244
- signatures_str = unique_signatures.map { |s| "(#{s.map(&:type).join(', ')})" }.join(', ')
258
+ signatures_str = unique_signatures.join(', ')
245
259
  raise "Conflicting signatures for '#{em.set_id}', found #{unique_signatures.size} signatures, only one allowed: '#{signatures_str}'"
246
260
  end
247
261
 
248
262
  # Modify the dispatcher to add the new dispatchType
249
- name = em.set_id
250
- dispatch_type_args = []
251
- dispatch_type_args += [GeneratedArg.new('int64_t', '_timestamp')] if default_clock_class
252
- dispatch_type_args += [GeneratedArg.new('const char *', '_event_class_name')]
253
- dispatch_type_args += signatures.pop
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
254
268
 
269
+ name = em.set_id
255
270
  dispatch_type = DispatchType.new(
256
271
  name, dispatch_type_args, "matching_#{sanitize(name)}", matched_dispatchers
257
272
  )
@@ -342,7 +357,7 @@ class ContextBuilder
342
357
 
343
358
  def callback_types
344
359
  @callback_types ||= begin
345
- callback_types = ['generic']
360
+ callback_types = ['automatic']
346
361
  if @cli_options.key?(:matching)
347
362
  event_classes = trace_matcher.stream_classes.map(&:event_classes).flatten(1).filter do |em|
348
363
  raise "Key ':set_id' required for matching events." unless em.set_id
@@ -415,7 +430,7 @@ class ContextBuilder
415
430
  dispatchers, automatic_dispatch_types = t.filter_map_event_classes_with_index do |e, index_stream_class, index_event_class, default_clock_class|
416
431
  dispatcher = Dispatcher.new(e, event_name, 'getter', index_stream_class, index_event_class,
417
432
  default_clock_class)
418
- dispatch_type = DispatchType.new(e.name, dispatcher.args, 'generic', [dispatcher])
433
+ dispatch_type = DispatchType.new(e.name, { e.name => dispatcher.args }, 'automatic', [dispatcher])
419
434
  dispatcher.dispatch_types << dispatch_type
420
435
 
421
436
  [dispatcher, dispatch_type]
@@ -447,7 +462,7 @@ end
447
462
 
448
463
  def wrote_upstream(cb)
449
464
  erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.h', cb.folder)
450
- erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.c', cb.folder)
465
+ erb_render_and_save(cb.get_context(%w[upstream callback_types]), 'upstream.c', cb.folder)
451
466
  end
452
467
 
453
468
  def wrote_downstream(cb)
@@ -609,7 +609,7 @@ module Babeltrace2Gen
609
609
  variable = bt_get_variable(arg_variables).name
610
610
 
611
611
  pr "// Dump data to a temporal string."
612
- pr "char *#{field}_temp = malloc(sizeof(#{variable}));"
612
+ pr "char *#{field}_temp = (char *)malloc(sizeof(#{variable}));"
613
613
  pr "assert(#{field}_temp != NULL && \"Out of memory\");"
614
614
  pr "memcpy(#{field}_temp, &#{variable}, sizeof(#{variable}));"
615
615
  pr ""
@@ -632,6 +632,7 @@ module Babeltrace2Gen
632
632
 
633
633
  class BTFieldClass::Array::Static < BTFieldClass::Array
634
634
  extend BTFromH
635
+ using HashRefinements
635
636
  attr_reader :length
636
637
 
637
638
  def initialize(parent:, element_field_class:, length:)
@@ -645,8 +646,34 @@ module Babeltrace2Gen
645
646
  pr "bt_field_class *#{element_field_class_variable};"
646
647
  @element_field_class.get_declarator(trace_class: trace_class, variable: element_field_class_variable)
647
648
  pr "#{variable} = bt_field_class_array_static_create(#{trace_class}, #{element_field_class_variable}, #{@length});"
649
+ pr "bt_field_class_put_ref(#{element_field_class_variable});"
650
+ end
651
+ end
652
+
653
+ def get_setter(field:, arg_variables:)
654
+ usr_var = bt_get_variable(arg_variables, is_array: true)
655
+ pr "for(uint64_t _i=0; _i < #{@length} ; _i++)"
656
+ scope do
657
+ v = "#{field}_e"
658
+ pr "bt_field* #{v} = bt_field_array_borrow_element_field_by_index(#{field}, _i);"
659
+ arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
660
+ @element_field_class.get_setter(field: v, arg_variables: arg_variables)
661
+ end
662
+ end
663
+
664
+ def get_getter(field:, arg_variables:)
665
+ length = @length
666
+ usr_var = bt_get_variable(arg_variables, is_array: true)
667
+ pr "#{usr_var.name} = (#{usr_var.type}) malloc(#{length} * sizeof(#{usr_var.name}));"
668
+ pr "for(uint64_t _i=0; _i < #{length} ; _i++)"
669
+ scope do
670
+ v = "#{field}_e"
671
+ pr "const bt_field* #{v} = bt_field_array_borrow_element_field_by_index_const(#{field}, _i);"
672
+ arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
673
+ @element_field_class.get_getter(field: v, arg_variables: arg_variables)
648
674
  end
649
675
  end
676
+
650
677
  end
651
678
 
652
679
  class BTFieldClass::Array::Dynamic < BTFieldClass::Array
@@ -731,10 +758,13 @@ module Babeltrace2Gen
731
758
 
732
759
  attr_reader :parent, :name, :field_class
733
760
 
734
- def initialize(parent:, field_class:, name: nil)
761
+ def initialize(parent:, field_class: nil, name: nil)
735
762
  @parent = parent
763
+ is_match_model = parent.rec_trace_class.match
764
+ raise ArgumentError.new("missing keyword: :name") unless name || is_match_model
765
+ raise ArgumentError.new("missing keyword: :field_class") unless field_class || is_match_model
736
766
  @name = name # Name can be nil in the matching callbacks
737
- @field_class = BTFieldClass.from_h(self, field_class)
767
+ @field_class = BTFieldClass.from_h(self, field_class || {} )
738
768
  end
739
769
 
740
770
  def bt_get_variable()
@@ -1,3 +1,3 @@
1
1
  module Metababel
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -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
+ }
@@ -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(
@@ -20,8 +20,8 @@ void btx_downstream_move_messages(
20
20
  }
21
21
  }
22
22
 
23
- static inline
24
- void _btx_push_message(btx_message_iterator_t *message_iterator_private_data,
23
+ static inline void
24
+ _btx_push_message(btx_message_iterator_t *message_iterator_private_data,
25
25
  const bt_message *message) {
26
26
 
27
27
  struct el *elt;
@@ -51,7 +51,7 @@ void btx_downstream_push_message(
51
51
  btx_message_iterator_t *message_iterator_private_data,
52
52
  const bt_message *message) {
53
53
 
54
- <% unless options[:disable_callbaks].include?('on_downstream') %>
54
+ <% unless options[:disable_callbaks].include?('on_downstream') %>
55
55
  on_downstream_message_callback_f *p =
56
56
  (on_downstream_message_callback_f *)message_iterator_private_data
57
57
  ->common_data->on_downstream_message_callback;
@@ -60,7 +60,7 @@ void btx_downstream_push_message(
60
60
  message_iterator_private_data->common_data->usr_data, message);
61
61
  return;
62
62
  }
63
- <% end %>
63
+ <% end %>
64
64
  _btx_push_message(message_iterator_private_data, message);
65
65
  }
66
66
 
@@ -168,7 +168,8 @@ void btx_push_message_<%= e.name_sanitized %>(
168
168
  _downstream_event<%= e.args.map{ |s| s.name }.join_with_prefix(", ") %>);
169
169
 
170
170
  btx_message_iterator_t *_message_iterator_private_data =
171
- bt_self_message_iterator_get_data(common_data->self_message_iterator);
171
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
172
+ common_data->self_message_iterator);
172
173
  btx_downstream_push_message(_message_iterator_private_data, _message);
173
174
  }
174
175
  <% end %>
@@ -28,7 +28,8 @@ filter_message_iterator_next_finalizing(
28
28
  bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
29
29
 
30
30
  btx_message_iterator_t *message_iterator_private_data =
31
- bt_self_message_iterator_get_data(self_message_iterator);
31
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
32
+ self_message_iterator);
32
33
 
33
34
  /* No more messages, we can stop the plugin, and transition to END */
34
35
  if (!message_iterator_private_data->queue) {
@@ -55,7 +56,8 @@ filter_message_iterator_next_processing_sending(
55
56
  bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
56
57
  /* Retrieve our private data from the message iterator's user data */
57
58
  btx_message_iterator_t *message_iterator_private_data =
58
- bt_self_message_iterator_get_data(self_message_iterator);
59
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
60
+ self_message_iterator);
59
61
 
60
62
  /* This should never append. When transitioning to sending,
61
63
  we check that we have some messages to send */
@@ -167,7 +169,8 @@ filter_message_iterator_next_processing_reading(
167
169
  bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
168
170
  /* Retrieve our private data from the message iterator's user data */
169
171
  btx_message_iterator_t *message_iterator_private_data =
170
- bt_self_message_iterator_get_data(self_message_iterator);
172
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
173
+ self_message_iterator);
171
174
 
172
175
  common_data_t *common_data = message_iterator_private_data->common_data;
173
176
 
@@ -229,7 +232,8 @@ filter_message_iterator_next_processing(
229
232
  bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
230
233
 
231
234
  btx_message_iterator_t *message_iterator_private_data =
232
- bt_self_message_iterator_get_data(self_message_iterator);
235
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
236
+ self_message_iterator);
233
237
 
234
238
  switch (message_iterator_private_data->processing_state) {
235
239
  case BTX_FILTER_PROCESSING_STATE_READING:
@@ -257,7 +261,8 @@ filter_message_iterator_next_initializing(
257
261
 
258
262
  /* Retrieve our private data from the message iterator's user data */
259
263
  btx_message_iterator_t *message_iterator_private_data =
260
- bt_self_message_iterator_get_data(self_message_iterator);
264
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
265
+ self_message_iterator);
261
266
 
262
267
  /* Begining of Stream */
263
268
  btx_push_messages_stream_beginning(self_message_iterator,
@@ -293,7 +298,8 @@ filter_message_iterator_next(bt_self_message_iterator *self_message_iterator,
293
298
 
294
299
  /* Retrieve our private data from the message iterator's user data */
295
300
  btx_message_iterator_t *message_iterator_private_data =
296
- bt_self_message_iterator_get_data(self_message_iterator);
301
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
302
+ self_message_iterator);
297
303
 
298
304
  switch (message_iterator_private_data->state) {
299
305
  case BTX_FILTER_STATE_INITIALIZING:
@@ -334,9 +340,11 @@ filter_initialize(bt_self_component_filter *self_component_filter,
334
340
  const bt_value *params, void *initialize_method_data) {
335
341
 
336
342
  /* Allocate a private data structure */
337
- common_data_t *common_data = calloc(1, sizeof(common_data_t));
338
- common_data->static_callbacks = calloc(1, sizeof(static_callbacks_t));
339
- common_data->btx_params = calloc(1, sizeof(btx_params_t));
343
+ common_data_t *common_data =
344
+ (common_data_t *)calloc(1, sizeof(common_data_t));
345
+ common_data->static_callbacks =
346
+ (static_callbacks_t *)calloc(1, sizeof(static_callbacks_t));
347
+ common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
340
348
  common_data->params = params;
341
349
 
342
350
  /* Read parameters */
@@ -346,8 +354,7 @@ filter_initialize(bt_self_component_filter *self_component_filter,
346
354
  /* Register User Callbacks */
347
355
  btx_register_usr_callbacks((void *)common_data);
348
356
  /* Call initialize_processing*/
349
- btx_call_callbacks_initialize_component((void *)common_data,
350
- &common_data->usr_data);
357
+ btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
351
358
  /* Call read callbacks */
352
359
  btx_call_callbacks_read_params(common_data, common_data->usr_data,
353
360
  common_data->btx_params);
@@ -427,10 +434,10 @@ filter_message_iterator_initialize(
427
434
  bt_self_component_port_output *self_port_output) {
428
435
  /* Allocate a private data structure */
429
436
  btx_message_iterator_t *message_iterator_private_data =
430
- calloc(1, sizeof(btx_message_iterator_t));
437
+ (btx_message_iterator_t *)calloc(1, sizeof(btx_message_iterator_t));
431
438
 
432
439
  /* Retrieve the component's private data from its user data */
433
- common_data_t *common_data = bt_self_component_get_data(
440
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
434
441
  bt_self_message_iterator_borrow_component(self_message_iterator));
435
442
 
436
443
  /* Save a link to the self_message_iterator */
@@ -470,7 +477,7 @@ filter_message_iterator_initialize(
470
477
  }
471
478
 
472
479
  static void filter_finalize(bt_self_component_filter *self_component_filter) {
473
- common_data_t *common_data = bt_self_component_get_data(
480
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
474
481
  bt_self_component_filter_as_self_component(self_component_filter));
475
482
 
476
483
  /* Finalize Component */
@@ -481,7 +488,7 @@ static void filter_finalize(bt_self_component_filter *self_component_filter) {
481
488
  bt_trace_put_ref(common_data->downstream_trace);
482
489
 
483
490
  /* Delete name_to_dispatchers */
484
- btx_delete_dispatchers(common_data);
491
+ btx_unregister_callbacks(common_data);
485
492
 
486
493
  /* We allocate it, we need to free it */
487
494
  free(common_data->btx_params);
@@ -494,7 +501,8 @@ static void filter_message_iterator_finalize(
494
501
  bt_self_message_iterator *self_message_iterator) {
495
502
  /* Retrieve our private data from the message iterator's user data */
496
503
  btx_message_iterator_t *message_iterator_private_data =
497
- bt_self_message_iterator_get_data(self_message_iterator);
504
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
505
+ self_message_iterator);
498
506
 
499
507
  {
500
508
  struct el *elt, *tmp;
data/template/sink.c.erb CHANGED
@@ -19,7 +19,7 @@ sink_consume(bt_self_component_sink *self_component_sink) {
19
19
 
20
20
  /* Retrieve our private data from the component's user data */
21
21
  /* This containt user data and the message iterator */
22
- common_data_t *common_data = bt_self_component_get_data(
22
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
23
23
  bt_self_component_sink_as_self_component(self_component_sink));
24
24
 
25
25
  /* Consume a batch of messages from the upstream message iterator */
@@ -82,9 +82,11 @@ sink_initialize(bt_self_component_sink *self_component_sink,
82
82
  bt_self_component_sink_configuration *configuration,
83
83
  const bt_value *params, void *initialize_method_data) {
84
84
  /* Allocate a private data structure */
85
- common_data_t *common_data = calloc(1, sizeof(common_data_t));
86
- common_data->static_callbacks = calloc(1, sizeof(static_callbacks_t));
87
- common_data->btx_params = calloc(1, sizeof(btx_params_t));
85
+ common_data_t *common_data =
86
+ (common_data_t *)calloc(1, sizeof(common_data_t));
87
+ common_data->static_callbacks =
88
+ (static_callbacks_t *)calloc(1, sizeof(static_callbacks_t));
89
+ common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
88
90
  common_data->params = params;
89
91
 
90
92
  /* Read parameters */
@@ -94,8 +96,7 @@ sink_initialize(bt_self_component_sink *self_component_sink,
94
96
  /* Register User Callbacks */
95
97
  btx_register_usr_callbacks((void *)common_data);
96
98
  /* Call initialize_processing*/
97
- btx_call_callbacks_initialize_component((void *)common_data,
98
- &common_data->usr_data);
99
+ btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
99
100
  /* Call read callbacks */
100
101
  btx_call_callbacks_read_params(common_data, common_data->usr_data,
101
102
  common_data->btx_params);
@@ -118,14 +119,14 @@ sink_initialize(bt_self_component_sink *self_component_sink,
118
119
  }
119
120
 
120
121
  static void sink_finalize(bt_self_component_sink *self_component_sink) {
121
- common_data_t *common_data = bt_self_component_get_data(
122
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
122
123
  bt_self_component_sink_as_self_component(self_component_sink));
123
124
 
124
125
  /* Finalize Component */
125
126
  btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
126
127
 
127
128
  // Delete name_to_dispatcher
128
- btx_delete_dispatchers(common_data);
129
+ btx_unregister_callbacks(common_data);
129
130
 
130
131
  // We allocate it, we need to free it
131
132
  free(common_data->btx_params);
@@ -145,7 +146,7 @@ static void sink_finalize(bt_self_component_sink *self_component_sink) {
145
146
  static bt_component_class_sink_graph_is_configured_method_status
146
147
  sink_graph_is_configured(bt_self_component_sink *self_component_sink) {
147
148
  /* Retrieve our private data from the component's user data */
148
- common_data_t *common_data = bt_self_component_get_data(
149
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
149
150
  bt_self_component_sink_as_self_component(self_component_sink));
150
151
 
151
152
  /* Borrow our unique port */
@@ -23,7 +23,11 @@ source_message_iterator_next(bt_self_message_iterator *self_message_iterator,
23
23
 
24
24
  /* Retrieve our private data from the message iterator's user data */
25
25
  btx_message_iterator_t *message_iterator_private_data =
26
- bt_self_message_iterator_get_data(self_message_iterator);
26
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
27
+ self_message_iterator);
28
+
29
+ // Avoid C++ crosses initialization warning
30
+ btx_source_status_t status;
27
31
 
28
32
  /* When you return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END, you must
29
33
  * not put any message into the message array */
@@ -46,7 +50,7 @@ source_message_iterator_next(bt_self_message_iterator *self_message_iterator,
46
50
  return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
47
51
  }
48
52
 
49
- btx_source_status_t status = BTX_SOURCE_END;
53
+ status = BTX_SOURCE_END;
50
54
 
51
55
  btx_call_callbacks_push_usr_messages(
52
56
  message_iterator_private_data->common_data,
@@ -85,9 +89,11 @@ source_initialize(bt_self_component_source *self_component_source,
85
89
  bt_self_component_source_configuration *configuration,
86
90
  const bt_value *params, void *initialize_method_data) {
87
91
  /* Allocate a private data structure */
88
- common_data_t *common_data = calloc(1, sizeof(common_data_t));
89
- common_data->static_callbacks = calloc(1, sizeof(static_callbacks_t));
90
- common_data->btx_params = calloc(1, sizeof(btx_params_t));
92
+ common_data_t *common_data =
93
+ (common_data_t *)calloc(1, sizeof(common_data_t));
94
+ common_data->static_callbacks =
95
+ (static_callbacks_t *)calloc(1, sizeof(static_callbacks_t));
96
+ common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
91
97
  common_data->params = params;
92
98
 
93
99
  /* Read parameters */
@@ -97,8 +103,7 @@ source_initialize(bt_self_component_source *self_component_source,
97
103
  /* Register User Callbacks */
98
104
  btx_register_usr_callbacks((void *)common_data);
99
105
  /* Call initialize_processing*/
100
- btx_call_callbacks_initialize_component((void *)common_data,
101
- &common_data->usr_data);
106
+ btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
102
107
  /* Call read callbacks */
103
108
  btx_call_callbacks_read_params(common_data, common_data->usr_data,
104
109
  common_data->btx_params);
@@ -142,12 +147,12 @@ source_message_iterator_initialize(
142
147
  bt_self_component_port_output *self_port) {
143
148
  /* Allocate a private data structure */
144
149
  btx_message_iterator_t *message_iterator_private_data =
145
- calloc(1, sizeof(btx_message_iterator_t));
150
+ (btx_message_iterator_t *)calloc(1, sizeof(btx_message_iterator_t));
146
151
 
147
152
  message_iterator_private_data->state = BTX_SOURCE_STATE_INITIALIZING;
148
153
 
149
154
  /* Retrieve the component's private data from its user data */
150
- common_data_t *common_data = bt_self_component_get_data(
155
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
151
156
  bt_self_message_iterator_borrow_component(self_message_iterator));
152
157
 
153
158
  /* Save a link to the self_message_iterator */
@@ -164,26 +169,20 @@ source_message_iterator_initialize(
164
169
  }
165
170
 
166
171
  static void source_finalize(bt_self_component_source *self_component_source) {
167
- common_data_t *common_data = bt_self_component_get_data(
172
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
168
173
  bt_self_component_source_as_self_component(self_component_source));
169
174
 
170
175
  /* Finalize Component */
171
176
  btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
172
177
 
173
178
  btx_streams_put_ref(common_data->downstream_trace); // ??
174
- // We allocate it, we need to put ref
179
+ /* We allocate it, we need to put ref */
175
180
  bt_trace_put_ref(common_data->downstream_trace);
176
181
 
177
- // Delete name_to_dispatcher
178
- name_to_dispatcher_t *current, *tmp;
179
- HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
180
- HASH_DEL(common_data->name_to_dispatcher, current);
181
- utarray_free(current->callbacks->generic);
182
- free(current->callbacks);
183
- free(current);
184
- }
182
+ /* Delete name_to_dispatchers */
183
+ btx_unregister_callbacks(common_data);
185
184
 
186
- // We allocate it, we need to free it
185
+ /* We allocate it, we need to free it */
187
186
  free(common_data->btx_params);
188
187
  free(common_data->static_callbacks);
189
188
  bt_value_put_ref(common_data->params);
@@ -194,7 +193,8 @@ static void source_message_iterator_finalize(
194
193
  bt_self_message_iterator *self_message_iterator) {
195
194
  /* Retrieve our private data from the message iterator's user data */
196
195
  btx_message_iterator_t *message_iterator_private_data =
197
- bt_self_message_iterator_get_data(self_message_iterator);
196
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
197
+ self_message_iterator);
198
198
 
199
199
  struct el *elt, *tmp;
200
200
  DL_FOREACH_SAFE(message_iterator_private_data->pool, elt, tmp) {
@@ -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(&:args).flatten.any? { |arg| arg.name == '_event_class_name' } %>
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
 
@@ -37,11 +37,12 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
37
37
  {
38
38
  if (callbacks-><%= dispatch_type.id %>) {
39
39
  void **_p = NULL;
40
- while ((_p = utarray_next(callbacks-><%= dispatch_type.id %>, _p))) {
40
+ while ((
41
+ _p = (void **)utarray_next(callbacks-><%= dispatch_type.id %>, _p))) {
41
42
  (*((<%= dispatch_type.name_sanitized %>_callback_f **)(_p)))(
42
43
  (void *)common_data,
43
44
  common_data
44
- ->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(", ") %>);
45
46
  }
46
47
  }
47
48
  }
@@ -53,56 +54,45 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
53
54
  }
54
55
 
55
56
  <% end %>
56
- <% dispatchers.each do |dispatcher| %>
57
- void btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
58
- void *btx_handle, const char *id, void *callback) {
59
- // Look-up our dispatcher
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
+
60
62
  name_to_dispatcher_t *s = NULL;
63
+
61
64
  name_to_dispatcher_t **name_to_dispatcher =
62
65
  &((common_data_t *)btx_handle)->name_to_dispatcher;
63
- HASH_FIND_STR(*name_to_dispatcher, "<%= dispatcher.name %>", s);
66
+ HASH_FIND_STR(*name_to_dispatcher, dispatcher_name, s);
67
+
64
68
  if (!s) {
65
69
  // We didn't find the dispatcher, so we need to create it.
66
70
  s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
67
- s->name = "<%= dispatcher.name %>";
68
- s->dispatcher = (void *)&btx_dispatch_<%= dispatcher.name_sanitized %>;
69
- s->callbacks = calloc(1, sizeof(callbacks_t));
71
+ s->name = dispatcher_name;
72
+ s->dispatcher = btx_dispatch_p;
73
+ s->callbacks = (callbacks_t *)calloc(1, sizeof(callbacks_t));
70
74
  // 2. Register it
71
75
  HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
72
76
  }
73
77
 
74
- <% dispatcher.dispatch_types.each do |dispatch_type| %>
75
- if (strcmp("<%= dispatch_type.id %>", id) == 0) {
78
+ <% callback_types.each_with_index do |id,i| %>
79
+ <%= i == 0 ? "if" : "else if" %>(strcmp("<%= id %>", id) == 0) {
76
80
  // Add the callbacks to the array
77
- if (!s->callbacks-><%= dispatch_type.id %>)
78
- utarray_new(s->callbacks-><%= dispatch_type.id %>, &ut_ptr_icd);
79
- utarray_push_back(s->callbacks-><%= dispatch_type.id %>, &callback);
81
+ if (!s->callbacks-><%= id %>)
82
+ utarray_new(s->callbacks-><%= id %>, &ut_ptr_icd);
83
+ utarray_push_back(s->callbacks-><%= id %>, &callback);
80
84
  }
81
-
82
85
  <% end %>
83
86
  }
84
87
 
85
- <% end %>
86
88
  <% dispatch_types.each do |dispatch_type| %>
87
89
  void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
88
90
  void *btx_handle,
89
91
  <%= dispatch_type.name_sanitized %>_callback_f *callback) {
90
92
  <% dispatch_type.matched_dispatchers.each do |dispatcher| %>
91
- btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
92
- btx_handle, "<%= dispatch_type.id %>", (void *)callback);
93
+ bt_register_callbacks(btx_handle, "<%= dispatcher.name %>",
94
+ (void *)&btx_dispatch_<%= dispatcher.name_sanitized %>,
95
+ "<%= dispatch_type.id %>", (void *)callback);
93
96
  <% end %>
94
97
  }
95
-
96
98
  <% end %>
97
- void btx_delete_dispatchers(common_data_t *common_data) {
98
- name_to_dispatcher_t *current, *tmp;
99
- HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
100
- HASH_DEL(common_data->name_to_dispatcher, current);
101
- <% dispatch_types.map(&:id).uniq.each do |name| %>
102
- if (current->callbacks-><%= name %>)
103
- utarray_free(current->callbacks-><%= name %>);
104
- <% end %>
105
- free(current->callbacks);
106
- free(current);
107
- }
108
- }
@@ -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 btx_delete_dispatchers(common_data_t *common_data);
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.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Applencourt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-31 00:00:00.000000000 Z
13
+ date: 2024-01-05 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email: