metababel 0.1.0 → 1.0.1

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.
@@ -7,151 +7,102 @@
7
7
  #include <stdbool.h>
8
8
  #include <stdlib.h>
9
9
 
10
- <% event_class_dispatchers.each do |e| %>
11
- static void btx_dispatch_<%= e.name_sanitized %>(
12
- UT_array *callbacks, common_data_t *common_data,
13
- const bt_message *upstream_message, bool *is_callback_called) {
10
+ <% dispatchers.each do |dispatcher| %>
11
+ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
12
+ callbacks_t *callbacks, common_data_t *common_data,
13
+ const bt_message *upstream_message) {
14
14
 
15
- <% e.args.each do |s| %>
15
+ <% dispatcher.args.each do |s| %>
16
16
  <%= s.type %> <%= s.name %>;
17
17
  <% end %>
18
18
 
19
19
  <%# Since now event is a variable, we need to check if the body will render variables that accesses it. %>
20
- <% if not e.body.empty? %>
21
- const bt_event *<%= event_name %> = bt_message_event_borrow_event_const(upstream_message);
22
- <%= "\n" + e.body %>
20
+ <% if not dispatcher.body.strip.empty? %>
21
+ const bt_event *<%= event_name %> =
22
+ bt_message_event_borrow_event_const(upstream_message);
23
+ <%= dispatcher.body %>
23
24
  <% end %>
24
-
25
- <% if e.default_clock_class %>
26
- int64_t _timestamp;
27
- const bt_clock_snapshot *clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(upstream_message);
25
+ <% if dispatcher.default_clock_class %>
26
+ const bt_clock_snapshot *clock_snapshot =
27
+ bt_message_event_borrow_default_clock_snapshot_const(upstream_message);
28
28
  bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
29
29
  <% end %>
30
- // Call all the callbacks who where registered
31
- // Their type are declared in 'upstream.h'
32
- <%= e.name_sanitized %>_callback_f **p = NULL;
33
- while ((p = utarray_next(callbacks, p))) {
34
- (*p)((void *)common_data,
35
- common_data
36
- ->usr_data<%= ', _timestamp' if e.default_clock_class %><%= e.args.map{ |s| s.name }.join_with_prefix(", ") %>);
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' } %>
32
+ const char *_event_class_name = "<%= dispatcher.name %>";
33
+ <% end %>
34
+
35
+ // Call registered matching callbacks
36
+ <% dispatcher.dispatch_types.each do |dispatch_type| %>
37
+ {
38
+ if (callbacks-><%= dispatch_type.id %>) {
39
+ void **_p = NULL;
40
+ while ((_p = utarray_next(callbacks-><%= dispatch_type.id %>, _p))) {
41
+ (*((<%= dispatch_type.name_sanitized %>_callback_f **)(_p)))(
42
+ (void *)common_data,
43
+ common_data
44
+ ->usr_data<%= dispatch_type.args.map{ |a| a.name }.join_with_prefix(", ") %>);
45
+ }
46
+ }
37
47
  }
38
48
 
39
- <% e.args_to_free.each do |s| %>
49
+ <% end %>
50
+ <% dispatcher.args_to_free.each do |s| %>
40
51
  <%= "free(#{s.name});" %>
41
52
  <% end %>
42
-
43
- if (callbacks)
44
- *is_callback_called = true;
45
53
  }
46
54
 
47
- void btx_register_callbacks_<%= e.name_sanitized %>(
48
- void *btx_handle, <%= e.name_sanitized %>_callback_f *callback) {
55
+ <% end %>
56
+ <% dispatchers.each do |dispatcher| %>
57
+ void btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
58
+ void *btx_handle, const char *id, void *callback) {
49
59
  // Look-up our dispatcher
50
60
  name_to_dispatcher_t *s = NULL;
51
61
  name_to_dispatcher_t **name_to_dispatcher =
52
62
  &((common_data_t *)btx_handle)->name_to_dispatcher;
53
- HASH_FIND_STR(*name_to_dispatcher, "<%= e.name %>", s);
63
+ HASH_FIND_STR(*name_to_dispatcher, "<%= dispatcher.name %>", s);
54
64
  if (!s) {
55
- // We didn't find the dispatcher, so we need to:
56
- // 1. Create it
65
+ // We didn't find the dispatcher, so we need to create it.
57
66
  s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
58
- s->name = "<%= e.name %>";
59
- s->dispatcher = (void *)&btx_dispatch_<%= e.name_sanitized %>;
60
- utarray_new(s->callbacks, &ut_ptr_icd);
67
+ s->name = "<%= dispatcher.name %>";
68
+ s->dispatcher = (void *)&btx_dispatch_<%= dispatcher.name_sanitized %>;
69
+ s->callbacks = calloc(1, sizeof(callbacks_t));
61
70
  // 2. Register it
62
71
  HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
63
72
  }
64
- // Add the callbacks to the array
65
- utarray_push_back(s->callbacks, &callback);
66
- }
67
- <% end %>
68
73
 
69
- <% stream_classes_matching_dispatchers.each do |s| %>
70
- void btx_matching_dispatch_<%= s.name_sanitized %>(UT_array *callbacks,
71
- common_data_t *common_data,
72
- const bt_message *upstream_message,
73
- bool *is_callback_called) {
74
+ <% dispatcher.dispatch_types.each do |dispatch_type| %>
75
+ if (strcmp("<%= dispatch_type.id %>", id) == 0) {
76
+ // 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);
80
+ }
74
81
 
75
- <% s.args.each do |a| %>
76
- <%= a.type %> <%= a.name %>;
77
82
  <% end %>
78
- const bt_event *<%= event_name %> = bt_message_event_borrow_event_const(upstream_message);
79
- <%= s.body %>
80
- const bt_event_class *event_class = bt_event_borrow_class_const(<%= event_name %>);
81
- const char *event_class_name = bt_event_class_get_name(event_class);
82
-
83
- condition_to_callback_t **p = NULL;
84
- while ((p = utarray_next(callbacks, p))) {
85
- <%= s.name_sanitized %>_callback_condition_f *condition =
86
- (<%= s.name_sanitized %>_callback_condition_f *)((*p)->condition);
87
- <%= s.name_sanitized %>_conditioned_callback_f *callback =
88
- (<%= s.name_sanitized %>_conditioned_callback_f *)((*p)->callback);
89
- <% if s.default_clock_class %>
90
- int64_t _timestamp;
91
- const bt_clock_snapshot *clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(upstream_message);
92
- bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
93
- <% end %>
94
- bool is_condition_met = false;
95
- condition(
96
- (void *)common_data, common_data->usr_data, event_class_name,
97
- &is_condition_met<%= ', _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.name }.join_with_prefix(", ") %>);
98
- if (is_condition_met) {
99
- callback(
100
- (void *)common_data, common_data->usr_data,
101
- event_class_name<%= ', _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.name }.join_with_prefix(", ") %>);
102
- *is_callback_called = true;
103
- }
104
- }
105
83
  }
106
84
 
107
- void btx_register_matching_callback_<%= s.name_sanitized %>(
108
- void *btx_handle, <%= s.name_sanitized %>_callback_condition_f *condition,
109
- <%= s.name_sanitized %>_conditioned_callback_f *callback) {
110
- // Look-up our dispatcher
111
- name_to_dispatcher_t *s = NULL;
112
- name_to_dispatcher_t **name_to_matching_dispatcher =
113
- &((common_data_t *)btx_handle)->name_to_matching_dispatcher;
114
- HASH_FIND_STR(*name_to_matching_dispatcher, "<%= s.name_sanitized %>", s);
115
- if (!s) {
116
- // We didn't find the dispatcher, so we need to:
117
- // 1. Create it
118
- s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
119
- s->name = "<%= s.name_sanitized %>";
120
- s->dispatcher = (void *)&btx_matching_dispatch_<%= s.name_sanitized %>;
121
- utarray_new(s->callbacks, &ut_ptr_icd);
122
- // 2. Register it
123
- HASH_ADD_KEYPTR(hh, *name_to_matching_dispatcher, s->name, strlen(s->name),
124
- s);
125
- }
126
- // Add the callbacks to the array
127
- condition_to_callback_t *m =
128
- (condition_to_callback_t *)malloc(sizeof(condition_to_callback_t));
129
- m->condition = (void *)condition;
130
- m->callback = (void *)callback;
131
- utarray_push_back(s->callbacks, &m);
132
- }
133
85
  <% end %>
86
+ <% dispatch_types.each do |dispatch_type| %>
87
+ void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
88
+ void *btx_handle,
89
+ <%= dispatch_type.name_sanitized %>_callback_f *callback) {
90
+ <% dispatch_type.matched_dispatchers.each do |dispatcher| %>
91
+ btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
92
+ btx_handle, "<%= dispatch_type.id %>", (void *)callback);
93
+ <% end %>
94
+ }
134
95
 
96
+ <% end %>
135
97
  void btx_delete_dispatchers(common_data_t *common_data) {
136
98
  name_to_dispatcher_t *current, *tmp;
137
99
  HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
138
100
  HASH_DEL(common_data->name_to_dispatcher, current);
139
- utarray_free(current->callbacks);
140
- free(current);
141
- }
142
- }
143
-
144
- void btx_delete_matching_dispatchers(common_data_t *common_data) {
145
- name_to_dispatcher_t *current, *tmp;
146
- HASH_ITER(hh, common_data->name_to_matching_dispatcher, current, tmp) {
147
- // Removes the item from the hash table.
148
- HASH_DEL(common_data->name_to_matching_dispatcher, current);
149
- // Deletes every condition, callback pair.
150
- condition_to_callback_t **p = NULL;
151
- while ((p = utarray_next(current->callbacks, p))) {
152
- free(*p);
153
- }
154
- utarray_free(current->callbacks);
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);
155
106
  free(current);
156
107
  }
157
108
  }
@@ -5,47 +5,21 @@ extern "C" {
5
5
  #endif
6
6
 
7
7
  // Dispatcher
8
- typedef void(dispatcher_t)(UT_array *callbacks, common_data_t *common_data,
9
- const bt_message *upstream_message, bool *is_callback_called);
8
+ typedef void(dispatcher_t)(callbacks_t *callbacks, common_data_t *common_data,
9
+ const bt_message *upstream_message);
10
10
 
11
- <% event_class_dispatchers.each do |e| %>
12
- <%# The signature type of callbacks %>
13
- typedef void <%= e.name_sanitized %>_callback_f(
14
- void *btx_handle,
15
- void *usr_data<%= ', int64_t _timestamp' if e.default_clock_class %><%= e.args.map{ |s| s.type }.join_with_prefix(", ") %>);
16
11
  <%# The Function who register the callbacks to the dispatcher %>
17
- void btx_register_callbacks_<%= e.name_sanitized %>(
18
- void *btx_handle, <%= e.name_sanitized %>_callback_f *callback);
19
- <% end %>
20
-
21
- void btx_delete_dispatchers(common_data_t *common_data);
22
-
23
- // Matching dispatcher
24
-
25
- struct condition_to_callback_s {
26
- void *condition;
27
- void *callback;
28
- };
29
- typedef struct condition_to_callback_s condition_to_callback_t;
30
-
31
- <% stream_classes_matching_dispatchers.each do |s| %>
32
- <%# The signature type of condition callbacks %>
33
- typedef void <%= s.name_sanitized %>_callback_condition_f(
34
- void *btx_handle, void *usr_data, const char *event_class_name,
35
- bool *matched<%= ', int64_t _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.type }.join_with_prefix(", ") %>);
12
+ <% dispatch_types.each do |dispatch_type| %>
13
+ typedef void <%= dispatch_type.name_sanitized %>_callback_f(
14
+ void *btx_handle,
15
+ void *
16
+ usr_data<%= dispatch_type.args.map{ |s| s.type }.join_with_prefix(', ') %>);
36
17
 
37
- <%# The signature type of callbacks to be called if the condition is met %>
38
- typedef void <%= s.name_sanitized %>_conditioned_callback_f(
39
- void *btx_handle, void *usr_data,
40
- const char *
41
- event_class_name<%= ', int64_t _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.type }.join_with_prefix(", ") %>);
18
+ void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
19
+ void *btx_handle, <%= dispatch_type.name_sanitized %>_callback_f *callback);
42
20
 
43
- void btx_register_matching_callback_<%= s.name_sanitized %>(
44
- void *btx_handle, <%= s.name_sanitized %>_callback_condition_f *condition,
45
- <%= s.name_sanitized %>_conditioned_callback_f *callback);
46
21
  <% end %>
47
-
48
- void btx_delete_matching_dispatchers(common_data_t *common_data);
22
+ void btx_delete_dispatchers(common_data_t *common_data);
49
23
 
50
24
  #ifdef __cplusplus
51
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: 0.1.0
4
+ version: 1.0.1
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-08-16 00:00:00.000000000 Z
13
+ date: 2023-10-31 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email:
@@ -23,7 +23,8 @@ files:
23
23
  - bin/metababel
24
24
  - lib/metababel.rb
25
25
  - lib/metababel/bt2_generator_utils.rb
26
- - lib/metababel/bt2_stream_classes_generator.rb
26
+ - lib/metababel/bt2_matching_utils.rb
27
+ - lib/metababel/bt2_trace_class_generator.rb
27
28
  - lib/metababel/bt2_values_generator.rb
28
29
  - lib/metababel/version.rb
29
30
  - template/component.c.erb
@@ -39,7 +40,8 @@ files:
39
40
  homepage:
40
41
  licenses:
41
42
  - MIT
42
- metadata: {}
43
+ metadata:
44
+ rubygems_mfa_required: 'true'
43
45
  post_install_message:
44
46
  rdoc_options: []
45
47
  require_paths:
@@ -55,7 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubygems_version: 3.3.3
60
+ rubyforge_project:
61
+ rubygems_version: 2.7.6.3
59
62
  signing_key:
60
63
  specification_version: 4
61
64
  summary: Helper for creation Babeltrace plugins