metababel 0.1.0 → 1.0.2

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.
@@ -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 */
@@ -32,16 +36,10 @@ source_message_iterator_next(bt_self_message_iterator *self_message_iterator,
32
36
  /* Begining of Stream */
33
37
  btx_push_messages_stream_beginning(self_message_iterator,
34
38
  message_iterator_private_data);
35
-
36
39
  /* Call Initialize user callback */
37
- btx_call_callbacks_initialize_usr_data(
40
+ btx_call_callbacks_initialize_processing(
38
41
  message_iterator_private_data->common_data,
39
- &message_iterator_private_data->common_data->usr_data);
40
- /* Call read callbacks */
41
- btx_call_callbacks_read_params(
42
- message_iterator_private_data->common_data,
43
- message_iterator_private_data->common_data->usr_data,
44
- message_iterator_private_data->common_data->btx_params);
42
+ message_iterator_private_data->common_data->usr_data);
45
43
 
46
44
  message_iterator_private_data->state = BTX_SOURCE_STATE_PROCESSING;
47
45
  return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
@@ -52,15 +50,14 @@ source_message_iterator_next(bt_self_message_iterator *self_message_iterator,
52
50
  return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
53
51
  }
54
52
 
55
- btx_source_status_t status = BTX_SOURCE_END;
53
+ status = BTX_SOURCE_END;
56
54
 
57
55
  btx_call_callbacks_push_usr_messages(
58
56
  message_iterator_private_data->common_data,
59
57
  message_iterator_private_data->common_data->usr_data, &status);
60
58
  if (status == BTX_SOURCE_END) {
61
-
62
59
  /* Call Finalize user callback */
63
- btx_call_callbacks_finalize_usr_data(
60
+ btx_call_callbacks_finalize_processing(
64
61
  message_iterator_private_data->common_data,
65
62
  message_iterator_private_data->common_data->usr_data);
66
63
  /* End of Stream */
@@ -92,15 +89,25 @@ source_initialize(bt_self_component_source *self_component_source,
92
89
  bt_self_component_source_configuration *configuration,
93
90
  const bt_value *params, void *initialize_method_data) {
94
91
  /* Allocate a private data structure */
95
- common_data_t *common_data = calloc(1, sizeof(common_data_t));
96
- 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));
97
97
  common_data->params = params;
98
- // Read parameters
98
+
99
+ /* Read parameters */
99
100
  btx_populate_params(common_data);
100
101
  bt_value_get_ref(common_data->params);
101
102
 
102
103
  /* Register User Callbacks */
103
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
+
104
111
  /* Upcast `self_component_source` to the `bt_self_component` type */
105
112
  bt_self_component *self_component =
106
113
  bt_self_component_source_as_self_component(self_component_source);
@@ -140,12 +147,12 @@ source_message_iterator_initialize(
140
147
  bt_self_component_port_output *self_port) {
141
148
  /* Allocate a private data structure */
142
149
  btx_message_iterator_t *message_iterator_private_data =
143
- calloc(1, sizeof(btx_message_iterator_t));
150
+ (btx_message_iterator_t *)calloc(1, sizeof(btx_message_iterator_t));
144
151
 
145
152
  message_iterator_private_data->state = BTX_SOURCE_STATE_INITIALIZING;
146
153
 
147
154
  /* Retrieve the component's private data from its user data */
148
- common_data_t *common_data = bt_self_component_get_data(
155
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
149
156
  bt_self_message_iterator_borrow_component(self_message_iterator));
150
157
 
151
158
  /* Save a link to the self_message_iterator */
@@ -162,9 +169,12 @@ source_message_iterator_initialize(
162
169
  }
163
170
 
164
171
  static void source_finalize(bt_self_component_source *self_component_source) {
165
- common_data_t *common_data = bt_self_component_get_data(
172
+ common_data_t *common_data = (common_data_t *)bt_self_component_get_data(
166
173
  bt_self_component_source_as_self_component(self_component_source));
167
174
 
175
+ /* Finalize Component */
176
+ btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
177
+
168
178
  btx_streams_put_ref(common_data->downstream_trace); // ??
169
179
  // We allocate it, we need to put ref
170
180
  bt_trace_put_ref(common_data->downstream_trace);
@@ -173,12 +183,14 @@ static void source_finalize(bt_self_component_source *self_component_source) {
173
183
  name_to_dispatcher_t *current, *tmp;
174
184
  HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
175
185
  HASH_DEL(common_data->name_to_dispatcher, current);
176
- utarray_free(current->callbacks);
186
+ utarray_free(current->callbacks->generic);
187
+ free(current->callbacks);
177
188
  free(current);
178
189
  }
179
190
 
180
191
  // We allocate it, we need to free it
181
192
  free(common_data->btx_params);
193
+ free(common_data->static_callbacks);
182
194
  bt_value_put_ref(common_data->params);
183
195
  free(common_data);
184
196
  }
@@ -187,7 +199,8 @@ static void source_message_iterator_finalize(
187
199
  bt_self_message_iterator *self_message_iterator) {
188
200
  /* Retrieve our private data from the message iterator's user data */
189
201
  btx_message_iterator_t *message_iterator_private_data =
190
- bt_self_message_iterator_get_data(self_message_iterator);
202
+ (btx_message_iterator_t *)bt_self_message_iterator_get_data(
203
+ self_message_iterator);
191
204
 
192
205
  struct el *elt, *tmp;
193
206
  DL_FOREACH_SAFE(message_iterator_private_data->pool, elt, tmp) {
@@ -7,151 +7,103 @@
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 ((
41
+ _p = (void **)utarray_next(callbacks-><%= dispatch_type.id %>, _p))) {
42
+ (*((<%= dispatch_type.name_sanitized %>_callback_f **)(_p)))(
43
+ (void *)common_data,
44
+ common_data
45
+ ->usr_data<%= dispatch_type.args.map{ |a| a.name }.join_with_prefix(", ") %>);
46
+ }
47
+ }
37
48
  }
38
49
 
39
- <% e.args_to_free.each do |s| %>
50
+ <% end %>
51
+ <% dispatcher.args_to_free.each do |s| %>
40
52
  <%= "free(#{s.name});" %>
41
53
  <% end %>
42
-
43
- if (callbacks)
44
- *is_callback_called = true;
45
54
  }
46
55
 
47
- void btx_register_callbacks_<%= e.name_sanitized %>(
48
- void *btx_handle, <%= e.name_sanitized %>_callback_f *callback) {
56
+ <% end %>
57
+ <% dispatchers.each do |dispatcher| %>
58
+ void btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
59
+ void *btx_handle, const char *id, void *callback) {
49
60
  // Look-up our dispatcher
50
61
  name_to_dispatcher_t *s = NULL;
51
62
  name_to_dispatcher_t **name_to_dispatcher =
52
63
  &((common_data_t *)btx_handle)->name_to_dispatcher;
53
- HASH_FIND_STR(*name_to_dispatcher, "<%= e.name %>", s);
64
+ HASH_FIND_STR(*name_to_dispatcher, "<%= dispatcher.name %>", s);
54
65
  if (!s) {
55
- // We didn't find the dispatcher, so we need to:
56
- // 1. Create it
66
+ // We didn't find the dispatcher, so we need to create it.
57
67
  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);
68
+ s->name = "<%= dispatcher.name %>";
69
+ s->dispatcher = (void *)&btx_dispatch_<%= dispatcher.name_sanitized %>;
70
+ s->callbacks = (callbacks_t *)calloc(1, sizeof(callbacks_t));
61
71
  // 2. Register it
62
72
  HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
63
73
  }
64
- // Add the callbacks to the array
65
- utarray_push_back(s->callbacks, &callback);
66
- }
67
- <% end %>
68
74
 
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) {
75
+ <% dispatcher.dispatch_types.each do |dispatch_type| %>
76
+ if (strcmp("<%= dispatch_type.id %>", id) == 0) {
77
+ // Add the callbacks to the array
78
+ if (!s->callbacks-><%= dispatch_type.id %>)
79
+ utarray_new(s->callbacks-><%= dispatch_type.id %>, &ut_ptr_icd);
80
+ utarray_push_back(s->callbacks-><%= dispatch_type.id %>, &callback);
81
+ }
74
82
 
75
- <% s.args.each do |a| %>
76
- <%= a.type %> <%= a.name %>;
77
83
  <% 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
84
  }
106
85
 
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
86
  <% end %>
87
+ <% dispatch_types.each do |dispatch_type| %>
88
+ void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
89
+ void *btx_handle,
90
+ <%= dispatch_type.name_sanitized %>_callback_f *callback) {
91
+ <% dispatch_type.matched_dispatchers.each do |dispatcher| %>
92
+ btx_generic_register_callback_<%= dispatcher.name_sanitized %>(
93
+ btx_handle, "<%= dispatch_type.id %>", (void *)callback);
94
+ <% end %>
95
+ }
134
96
 
97
+ <% end %>
135
98
  void btx_delete_dispatchers(common_data_t *common_data) {
136
99
  name_to_dispatcher_t *current, *tmp;
137
100
  HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
138
101
  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);
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);
155
107
  free(current);
156
108
  }
157
109
  }
@@ -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.2
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-11-07 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: