metababel 0.0.3 → 0.0.5
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/bin/metababel +58 -29
- data/lib/metababel/bt2_stream_classes_generator.rb +133 -67
- data/lib/metababel/bt2_values_generator.rb +19 -16
- data/lib/metababel/version.rb +1 -1
- data/template/component.c.erb +0 -1
- data/template/component.h.erb +3 -0
- data/template/downstream.c.erb +6 -6
- data/template/downstream.h.erb +2 -2
- data/template/filter.c.erb +250 -145
- data/template/sink.c.erb +34 -15
- data/template/upstream.c.erb +118 -8
- data/template/upstream.h.erb +36 -6
- metadata +2 -2
data/template/filter.c.erb
CHANGED
|
@@ -9,44 +9,46 @@
|
|
|
9
9
|
* https://babeltrace.org/docs/v2.0/libbabeltrace2/example-simple-flt-cmp-cls.html
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
static char *get_port_name(uint64_t current) {
|
|
13
|
-
int num_len = snprintf(NULL, 0, "in%ld", current);
|
|
14
|
-
char *result = (char *)malloc(num_len + 1);
|
|
15
|
-
sprintf(result, "in%ld", current);
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
/*
|
|
20
|
-
*
|
|
13
|
+
* _____ _ _ ___ ___ _ _
|
|
14
|
+
* / ___| | | | | \/ | | | (_)
|
|
15
|
+
* \ `--.| |_ __ _| |_ ___ | . . | __ _ ___| |__ _ _ __ ___ ___
|
|
16
|
+
* `--. \ __/ _` | __/ _ \ | |\/| |/ _` |/ __| '_ \| | '_ \ / _ \/ __|
|
|
17
|
+
* /\__/ / || (_| | || __/ | | | | (_| | (__| | | | | | | | __/\__ \
|
|
18
|
+
* \____/ \__\__,_|\__\___| \_| |_/\__,_|\___|_| |_|_|_| |_|\___||___/
|
|
21
19
|
*/
|
|
22
20
|
|
|
21
|
+
/* _
|
|
22
|
+
* |_ o ._ _. | o _ _
|
|
23
|
+
* | | | | (_| | | /_ (/_
|
|
24
|
+
*/
|
|
23
25
|
static inline bt_message_iterator_class_next_method_status
|
|
24
|
-
|
|
26
|
+
filter_message_iterator_next_finalizing(
|
|
25
27
|
bt_self_message_iterator *self_message_iterator,
|
|
26
28
|
bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
|
|
27
|
-
|
|
29
|
+
|
|
28
30
|
btx_message_iterator_t *message_iterator_private_data =
|
|
29
31
|
bt_self_message_iterator_get_data(self_message_iterator);
|
|
30
32
|
|
|
31
|
-
/*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (message_iterator_private_data->queue)
|
|
44
|
-
message_iterator_private_data->processing_state =
|
|
45
|
-
BTX_FILTER_PROCESSING_STATE_SENDING;
|
|
46
|
-
|
|
47
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
33
|
+
/* No more messages, we can stop the plugin, and transition to END */
|
|
34
|
+
if (!message_iterator_private_data->queue) {
|
|
35
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_FINISHED;
|
|
36
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END;
|
|
37
|
+
}
|
|
38
|
+
/* Still some message, because we moved message, we can send
|
|
39
|
+
BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK, and we will be recalled
|
|
40
|
+
latter by BT
|
|
41
|
+
*/
|
|
42
|
+
btx_downstream_move_messages(message_iterator_private_data, messages,
|
|
43
|
+
capacity, count);
|
|
44
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
|
|
48
45
|
}
|
|
49
46
|
|
|
47
|
+
/* _ __
|
|
48
|
+
* |_) ._ _ _ _ _ _ o ._ _ (_ _ ._ _| o ._ _
|
|
49
|
+
* | | (_) (_ (/_ _> _> | | | (_| __) (/_ | | (_| | | | (_|
|
|
50
|
+
* _| _|
|
|
51
|
+
*/
|
|
50
52
|
static inline bt_message_iterator_class_next_method_status
|
|
51
53
|
filter_message_iterator_next_processing_sending(
|
|
52
54
|
bt_self_message_iterator *self_message_iterator,
|
|
@@ -55,9 +57,19 @@ filter_message_iterator_next_processing_sending(
|
|
|
55
57
|
btx_message_iterator_t *message_iterator_private_data =
|
|
56
58
|
bt_self_message_iterator_get_data(self_message_iterator);
|
|
57
59
|
|
|
60
|
+
/* This should never append. When transitioning to sending,
|
|
61
|
+
we check that we have some messages to send */
|
|
62
|
+
if (!message_iterator_private_data->queue) {
|
|
63
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
64
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
btx_downstream_move_messages(message_iterator_private_data, messages,
|
|
59
68
|
capacity, count);
|
|
60
69
|
|
|
70
|
+
/* No more messages to send; we can transition back to reading
|
|
71
|
+
If not, this function will be called again
|
|
72
|
+
in order to minimize memory usage */
|
|
61
73
|
if (!message_iterator_private_data->queue) {
|
|
62
74
|
message_iterator_private_data->processing_state =
|
|
63
75
|
BTX_FILTER_PROCESSING_STATE_READING;
|
|
@@ -65,109 +77,172 @@ filter_message_iterator_next_processing_sending(
|
|
|
65
77
|
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
/* _ _
|
|
81
|
+
* |_) ._ _ _ _ _ _ o ._ _ |_) _ _. _| o ._ _
|
|
82
|
+
* | | (_) (_ (/_ _> _> | | | (_| | \ (/_ (_| (_| | | | (_|
|
|
83
|
+
* _| _|
|
|
84
|
+
*/
|
|
85
|
+
static inline bool filter_message_iterator_next_unregister(
|
|
86
|
+
btx_message_iterator_t *message_iterator_private_data) {
|
|
87
|
+
|
|
88
|
+
/* Unregister from BT */
|
|
89
|
+
bt_message_iterator_put_ref(
|
|
90
|
+
message_iterator_private_data->head_mi->message_iterator);
|
|
91
|
+
/* Delete from our ring buffer */
|
|
92
|
+
struct el_mi *tmp = message_iterator_private_data->head_mi;
|
|
93
|
+
CDL_DELETE(message_iterator_private_data->head_mi, tmp);
|
|
94
|
+
free(tmp);
|
|
95
|
+
/* Return if empty or not */
|
|
96
|
+
return message_iterator_private_data->head_mi;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static inline void filter_message_iterator_next_call_dispatchers(
|
|
100
|
+
const bt_message *upstream_message,
|
|
101
|
+
btx_message_iterator_t *message_iterator_private_data) {
|
|
75
102
|
|
|
76
103
|
common_data_t *common_data = message_iterator_private_data->common_data;
|
|
104
|
+
/* Borrow the event message's event and its class */
|
|
105
|
+
const bt_event *event = bt_message_event_borrow_event_const(upstream_message);
|
|
106
|
+
const bt_event_class *event_class = bt_event_borrow_class_const(event);
|
|
107
|
+
/* Lazy modified variable */
|
|
108
|
+
bool is_callback_called = false;
|
|
109
|
+
/* Event dispatcher */
|
|
110
|
+
{
|
|
111
|
+
const char *class_name = bt_event_class_get_name(event_class);
|
|
112
|
+
name_to_dispatcher_t *s = NULL;
|
|
113
|
+
HASH_FIND_STR(common_data->name_to_dispatcher, class_name, s);
|
|
114
|
+
if (s)
|
|
115
|
+
(*((dispatcher_t(*))(s->dispatcher)))(
|
|
116
|
+
s->callbacks, common_data, upstream_message, &is_callback_called);
|
|
117
|
+
}
|
|
118
|
+
/* Matching Dispacher */
|
|
119
|
+
{
|
|
120
|
+
const bt_stream_class *stream_class =
|
|
121
|
+
bt_event_class_borrow_stream_class_const(event_class);
|
|
122
|
+
const char *stream_class_name = bt_stream_class_get_name(stream_class);
|
|
77
123
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
name_to_dispatcher_t *s = NULL;
|
|
125
|
+
if (stream_class_name)
|
|
126
|
+
HASH_FIND_STR(common_data->name_to_matching_dispatcher,
|
|
127
|
+
stream_class_name, s);
|
|
128
|
+
if (s)
|
|
129
|
+
(*((dispatcher_t(*))(s->dispatcher)))(
|
|
130
|
+
s->callbacks, common_data, upstream_message, &is_callback_called);
|
|
131
|
+
}
|
|
132
|
+
/* Drop or push upstream message*/
|
|
133
|
+
if (is_callback_called) {
|
|
134
|
+
bt_message_put_ref(upstream_message);
|
|
135
|
+
} else {
|
|
136
|
+
btx_downstream_push_message(message_iterator_private_data,
|
|
137
|
+
upstream_message);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
81
140
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
141
|
+
static inline void
|
|
142
|
+
filter_message_iterator_next_processing_reading_to_finalizing(
|
|
143
|
+
bt_self_message_iterator *self_message_iterator,
|
|
144
|
+
btx_message_iterator_t *message_iterator_private_data) {
|
|
145
|
+
/* Call Finalize user callback */
|
|
146
|
+
btx_call_callbacks_finalize_usr_data(
|
|
147
|
+
message_iterator_private_data->common_data,
|
|
148
|
+
message_iterator_private_data->common_data->usr_data);
|
|
149
|
+
/* End of Stream */
|
|
150
|
+
btx_push_messages_stream_end(self_message_iterator,
|
|
151
|
+
message_iterator_private_data);
|
|
85
152
|
|
|
86
|
-
/*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/* We are setting the state, so this function will never being call twice */
|
|
92
|
-
bt_message_iterator_put_ref(
|
|
93
|
-
message_iterator_private_data->head_mi->message_iterator);
|
|
94
|
-
struct el_mi *tmp = message_iterator_private_data->head_mi;
|
|
95
|
-
CDL_DELETE(message_iterator_private_data->head_mi, tmp);
|
|
96
|
-
free(tmp);
|
|
97
|
-
|
|
98
|
-
if (!message_iterator_private_data->head_mi) {
|
|
99
|
-
/* Call Finalize user callback */
|
|
100
|
-
btx_call_callbacks_finalize_usr_data(
|
|
101
|
-
message_iterator_private_data->common_data,
|
|
102
|
-
message_iterator_private_data->common_data->usr_data);
|
|
103
|
-
message_iterator_private_data->state = BTX_FILTER_STATE_FINALIZING;
|
|
104
|
-
message_iterator_private_data->processing_state =
|
|
105
|
-
BTX_FILTER_PROCESSING_STATE_FINISHED;
|
|
106
|
-
}
|
|
107
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
108
|
-
case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
|
|
109
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
110
|
-
case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
|
|
111
|
-
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
112
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR;
|
|
113
|
-
case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
|
|
114
|
-
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
115
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
116
|
-
case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
|
|
117
|
-
break;
|
|
118
|
-
default:
|
|
119
|
-
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
120
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
121
|
-
}
|
|
153
|
+
/* Transition to switch */
|
|
154
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_FINALIZING;
|
|
155
|
+
message_iterator_private_data->processing_state =
|
|
156
|
+
BTX_FILTER_PROCESSING_STATE_FINISHED;
|
|
157
|
+
}
|
|
122
158
|
|
|
159
|
+
static inline void filter_message_iterator_next_processing_reading_callbacks(
|
|
160
|
+
btx_message_iterator_t *message_iterator_private_data,
|
|
161
|
+
common_data_t *common_data, uint64_t upstream_message_count,
|
|
162
|
+
bt_message_array_const upstream_messages) {
|
|
123
163
|
/* For each consumed message */
|
|
124
164
|
for (uint64_t upstream_i = 0; upstream_i < upstream_message_count;
|
|
125
165
|
upstream_i++) {
|
|
126
166
|
/* Current message */
|
|
127
167
|
const bt_message *upstream_message = upstream_messages[upstream_i];
|
|
128
|
-
/*
|
|
168
|
+
/* Forward all non-event-messages downstream */
|
|
129
169
|
if (bt_message_get_type(upstream_message) != BT_MESSAGE_TYPE_EVENT) {
|
|
130
|
-
bt_message_put_ref(upstream_message);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
/* Borrow the event message's event and its class */
|
|
134
|
-
const bt_event *event =
|
|
135
|
-
bt_message_event_borrow_event_const(upstream_message);
|
|
136
|
-
const bt_event_class *event_class = bt_event_borrow_class_const(event);
|
|
137
|
-
|
|
138
|
-
/* Call dispatcher or forward message downstream */
|
|
139
|
-
name_to_dispatcher_t *s = NULL;
|
|
140
|
-
const char *class_name = bt_event_class_get_name(event_class);
|
|
141
|
-
HASH_FIND_STR(common_data->name_to_dispatcher, class_name, s);
|
|
142
|
-
if (s) {
|
|
143
|
-
(*((dispatcher_t(*))(s->dispatcher)))(s->callbacks, common_data, event);
|
|
144
|
-
/* The message have been consumed, we can discard it */
|
|
145
|
-
bt_message_put_ref(upstream_message);
|
|
146
|
-
} else {
|
|
147
170
|
btx_downstream_push_message(message_iterator_private_data,
|
|
148
171
|
upstream_message);
|
|
172
|
+
} else {
|
|
173
|
+
filter_message_iterator_next_call_dispatchers(
|
|
174
|
+
upstream_message, message_iterator_private_data);
|
|
149
175
|
}
|
|
150
176
|
}
|
|
177
|
+
}
|
|
151
178
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
static inline bt_message_iterator_class_next_method_status
|
|
180
|
+
filter_message_iterator_next_processing_reading(
|
|
181
|
+
bt_self_message_iterator *self_message_iterator,
|
|
182
|
+
bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
|
|
183
|
+
/* Retrieve our private data from the message iterator's user data */
|
|
184
|
+
btx_message_iterator_t *message_iterator_private_data =
|
|
185
|
+
bt_self_message_iterator_get_data(self_message_iterator);
|
|
155
186
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
/*
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
187
|
+
common_data_t *common_data = message_iterator_private_data->common_data;
|
|
188
|
+
|
|
189
|
+
while (!message_iterator_private_data->queue) {
|
|
190
|
+
/* Consume a batch of messages from the upstream message iterator */
|
|
191
|
+
uint64_t upstream_message_count;
|
|
192
|
+
bt_message_array_const upstream_messages;
|
|
193
|
+
|
|
194
|
+
bt_message_iterator_next_status next_status = bt_message_iterator_next(
|
|
195
|
+
message_iterator_private_data->head_mi->message_iterator,
|
|
196
|
+
&upstream_messages, &upstream_message_count);
|
|
197
|
+
|
|
198
|
+
switch (next_status) {
|
|
199
|
+
case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
|
|
200
|
+
filter_message_iterator_next_processing_reading_callbacks(
|
|
201
|
+
message_iterator_private_data, common_data, upstream_message_count,
|
|
202
|
+
upstream_messages);
|
|
203
|
+
/* Round Robin between Upstream MessageIterator */
|
|
204
|
+
message_iterator_private_data->head_mi =
|
|
205
|
+
message_iterator_private_data->head_mi->next;
|
|
206
|
+
break;
|
|
207
|
+
case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
|
|
208
|
+
if (filter_message_iterator_next_unregister(
|
|
209
|
+
message_iterator_private_data))
|
|
210
|
+
break;
|
|
211
|
+
filter_message_iterator_next_processing_reading_to_finalizing(
|
|
212
|
+
self_message_iterator, message_iterator_private_data);
|
|
213
|
+
return filter_message_iterator_next_finalizing(self_message_iterator,
|
|
214
|
+
messages, capacity, count);
|
|
215
|
+
case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
|
|
216
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
217
|
+
case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
|
|
218
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
219
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR;
|
|
220
|
+
case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
|
|
221
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
222
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
223
|
+
default:
|
|
224
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_ERROR;
|
|
225
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
message_iterator_private_data->processing_state =
|
|
230
|
+
BTX_FILTER_PROCESSING_STATE_SENDING;
|
|
231
|
+
/* optimization to not send AGAIN */
|
|
232
|
+
return filter_message_iterator_next_processing_sending(
|
|
233
|
+
self_message_iterator, messages, capacity, count);
|
|
164
234
|
}
|
|
165
235
|
|
|
236
|
+
/* _ __
|
|
237
|
+
* |_) ._ _ _ _ _ _ o ._ _ (_ o _|_ _ |_
|
|
238
|
+
* | | (_) (_ (/_ _> _> | | | (_| __) \/\/ | |_ (_ | |
|
|
239
|
+
* _|
|
|
240
|
+
*/
|
|
166
241
|
static inline bt_message_iterator_class_next_method_status
|
|
167
242
|
filter_message_iterator_next_processing(
|
|
168
243
|
bt_self_message_iterator *self_message_iterator,
|
|
169
244
|
bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
|
|
170
|
-
|
|
245
|
+
|
|
171
246
|
btx_message_iterator_t *message_iterator_private_data =
|
|
172
247
|
bt_self_message_iterator_get_data(self_message_iterator);
|
|
173
248
|
|
|
@@ -185,26 +260,52 @@ filter_message_iterator_next_processing(
|
|
|
185
260
|
}
|
|
186
261
|
}
|
|
187
262
|
|
|
263
|
+
/* ___
|
|
264
|
+
* | ._ o _|_ o _. | o _ o ._ _
|
|
265
|
+
* _|_ | | | |_ | (_| | | /_ | | | (_|
|
|
266
|
+
* _|
|
|
267
|
+
*/
|
|
188
268
|
static inline bt_message_iterator_class_next_method_status
|
|
189
|
-
|
|
269
|
+
filter_message_iterator_next_initializing(
|
|
190
270
|
bt_self_message_iterator *self_message_iterator,
|
|
191
271
|
bt_message_array_const messages, uint64_t capacity, uint64_t *count) {
|
|
272
|
+
|
|
192
273
|
/* Retrieve our private data from the message iterator's user data */
|
|
193
274
|
btx_message_iterator_t *message_iterator_private_data =
|
|
194
275
|
bt_self_message_iterator_get_data(self_message_iterator);
|
|
195
276
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
message_iterator_private_data->state = BTX_FILTER_STATE_FINISHED;
|
|
200
|
-
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END;
|
|
201
|
-
}
|
|
277
|
+
/* Begining of Stream */
|
|
278
|
+
btx_push_messages_stream_beginning(self_message_iterator,
|
|
279
|
+
message_iterator_private_data);
|
|
202
280
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
281
|
+
/* Call Initialize user callback */
|
|
282
|
+
btx_call_callbacks_initialize_usr_data(
|
|
283
|
+
message_iterator_private_data->common_data,
|
|
284
|
+
&message_iterator_private_data->common_data->usr_data);
|
|
285
|
+
/* Call read callbacks */
|
|
286
|
+
btx_call_callbacks_read_params(
|
|
287
|
+
message_iterator_private_data->common_data,
|
|
288
|
+
message_iterator_private_data->common_data->usr_data,
|
|
289
|
+
message_iterator_private_data->common_data->btx_params);
|
|
290
|
+
|
|
291
|
+
/* We need to transition to the processing state*/
|
|
292
|
+
message_iterator_private_data->state = BTX_FILTER_STATE_PROCESSING;
|
|
293
|
+
if (message_iterator_private_data->queue) {
|
|
294
|
+
message_iterator_private_data->processing_state =
|
|
295
|
+
BTX_FILTER_PROCESSING_STATE_SENDING;
|
|
296
|
+
} else {
|
|
297
|
+
message_iterator_private_data->processing_state =
|
|
298
|
+
BTX_FILTER_PROCESSING_STATE_READING;
|
|
299
|
+
}
|
|
300
|
+
return filter_message_iterator_next_processing(self_message_iterator,
|
|
301
|
+
messages, capacity, count);
|
|
206
302
|
}
|
|
207
303
|
|
|
304
|
+
/* _ __
|
|
305
|
+
* / _ ._ _ ._ _ ._ _ ._ _|_ (_ o _|_ _ |_
|
|
306
|
+
* \_ (_) | | | |_) (_) | | (/_ | | |_ __) \/\/ | |_ (_ | |
|
|
307
|
+
* |
|
|
308
|
+
*/
|
|
208
309
|
static bt_message_iterator_class_next_method_status
|
|
209
310
|
filter_message_iterator_next(bt_self_message_iterator *self_message_iterator,
|
|
210
311
|
bt_message_array_const messages, uint64_t capacity,
|
|
@@ -231,9 +332,22 @@ filter_message_iterator_next(bt_self_message_iterator *self_message_iterator,
|
|
|
231
332
|
}
|
|
232
333
|
}
|
|
233
334
|
|
|
234
|
-
/*
|
|
235
|
-
*
|
|
335
|
+
/* _____ _
|
|
336
|
+
* / __ \ | |
|
|
337
|
+
* | / \/ ___ _ __ ___ _ __ ___ _ __ ___ _ __ | |_
|
|
338
|
+
* | | / _ \| '_ ` _ \| '_ \ / _ \| '_ \ / _ \ '_ \| __|
|
|
339
|
+
* | \__/\ (_) | | | | | | |_) | (_) | | | | __/ | | | |_
|
|
340
|
+
* \____/\___/|_| |_| |_| .__/ \___/|_| |_|\___|_| |_|\__|
|
|
341
|
+
* | |
|
|
342
|
+
* |_|
|
|
236
343
|
*/
|
|
344
|
+
static char *_btx_get_port_name(uint64_t current) {
|
|
345
|
+
int num_len = snprintf(NULL, 0, "in%ld", current);
|
|
346
|
+
char *result = (char *)malloc(num_len + 1);
|
|
347
|
+
sprintf(result, "in%ld", current);
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
|
|
237
351
|
static bt_component_class_initialize_method_status
|
|
238
352
|
filter_initialize(bt_self_component_filter *self_component_filter,
|
|
239
353
|
bt_self_component_filter_configuration *configuration,
|
|
@@ -243,7 +357,7 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
243
357
|
common_data_t *common_data = calloc(1, sizeof(common_data_t));
|
|
244
358
|
common_data->btx_params = calloc(1, sizeof(btx_params_t));
|
|
245
359
|
common_data->params = params;
|
|
246
|
-
|
|
360
|
+
/* Read parameters */
|
|
247
361
|
btx_populate_params(common_data);
|
|
248
362
|
bt_value_get_ref(common_data->params);
|
|
249
363
|
|
|
@@ -276,19 +390,18 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
276
390
|
const uint64_t current =
|
|
277
391
|
bt_component_filter_get_input_port_count(common_data->component);
|
|
278
392
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
393
|
+
char *name = _btx_get_port_name(current);
|
|
394
|
+
bt_self_component_filter_add_input_port(self_component_filter, name, NULL,
|
|
395
|
+
NULL);
|
|
396
|
+
free(name);
|
|
397
|
+
|
|
285
398
|
bt_self_component_filter_add_output_port(self_component_filter, "out", NULL,
|
|
286
399
|
NULL);
|
|
287
400
|
|
|
288
|
-
/* Create message that will be used by the filter */
|
|
401
|
+
/* Create message classes that will be used by the filter */
|
|
289
402
|
bt_self_component *self_component =
|
|
290
403
|
bt_self_component_filter_as_self_component(self_component_filter);
|
|
291
|
-
/* Create a `trace_class` and all the children classes (stream and events) */
|
|
404
|
+
/* Create a `trace_class` and all the children's classes (stream and events) */
|
|
292
405
|
bt_trace_class *trace_class =
|
|
293
406
|
btx_downstream_trace_class_create_rec(self_component);
|
|
294
407
|
/* Instantiate a `downstream_trace` of `trace_class` and all the children
|
|
@@ -304,15 +417,14 @@ bt_component_class_port_connected_method_status
|
|
|
304
417
|
filter_input_port_connected(bt_self_component_filter *self_component_filter,
|
|
305
418
|
bt_self_component_port_input *self_port,
|
|
306
419
|
const bt_port_output *other_port) {
|
|
420
|
+
|
|
307
421
|
const uint64_t current = bt_component_filter_get_input_port_count(
|
|
308
422
|
bt_self_component_filter_as_component_filter(self_component_filter));
|
|
309
423
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
free(name);
|
|
315
|
-
}
|
|
424
|
+
char *name = _btx_get_port_name(current);
|
|
425
|
+
bt_self_component_filter_add_input_port(self_component_filter, name, NULL,
|
|
426
|
+
NULL);
|
|
427
|
+
free(name);
|
|
316
428
|
|
|
317
429
|
return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK;
|
|
318
430
|
}
|
|
@@ -365,9 +477,6 @@ filter_message_iterator_initialize(
|
|
|
365
477
|
message_iterator_private_data);
|
|
366
478
|
|
|
367
479
|
message_iterator_private_data->state = BTX_FILTER_STATE_INITIALIZING;
|
|
368
|
-
message_iterator_private_data->processing_state =
|
|
369
|
-
BTX_FILTER_PROCESSING_STATE_READING;
|
|
370
|
-
|
|
371
480
|
return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
372
481
|
}
|
|
373
482
|
|
|
@@ -376,18 +485,14 @@ static void filter_finalize(bt_self_component_filter *self_component_filter) {
|
|
|
376
485
|
bt_self_component_filter_as_self_component(self_component_filter));
|
|
377
486
|
|
|
378
487
|
btx_streams_put_ref(common_data->downstream_trace); // ??
|
|
379
|
-
|
|
488
|
+
/* We allocate it, we need to put ref */
|
|
380
489
|
bt_trace_put_ref(common_data->downstream_trace);
|
|
381
490
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
386
|
-
utarray_free(current->callbacks);
|
|
387
|
-
free(current);
|
|
388
|
-
}
|
|
491
|
+
/* Delete name_to_dispatchers */
|
|
492
|
+
btx_delete_dispatchers(common_data);
|
|
493
|
+
btx_delete_matching_dispatchers(common_data);
|
|
389
494
|
|
|
390
|
-
|
|
495
|
+
/* We allocate it, we need to free it */
|
|
391
496
|
free(common_data->btx_params);
|
|
392
497
|
bt_value_put_ref(common_data->params);
|
|
393
498
|
free(common_data);
|
data/template/sink.c.erb
CHANGED
|
@@ -48,24 +48,47 @@ sink_consume(bt_self_component_sink *self_component_sink) {
|
|
|
48
48
|
}
|
|
49
49
|
/* For each consumed message */
|
|
50
50
|
for (uint64_t i = 0; i < message_count; i++) {
|
|
51
|
-
const bt_message *
|
|
52
|
-
if (bt_message_get_type(
|
|
53
|
-
bt_message_put_ref(
|
|
51
|
+
const bt_message *upstream_message = messages[i];
|
|
52
|
+
if (bt_message_get_type(upstream_message) != BT_MESSAGE_TYPE_EVENT) {
|
|
53
|
+
bt_message_put_ref(upstream_message);
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/* Borrow the event message's event and its class */
|
|
58
|
-
const bt_event *event = bt_message_event_borrow_event_const(
|
|
58
|
+
const bt_event *event = bt_message_event_borrow_event_const(upstream_message);
|
|
59
59
|
const bt_event_class *event_class = bt_event_borrow_class_const(event);
|
|
60
60
|
|
|
61
61
|
/* Call dispatcher */
|
|
62
|
-
|
|
62
|
+
bool is_callback_called = false;
|
|
63
63
|
const char *class_name = bt_event_class_get_name(event_class);
|
|
64
|
-
HASH_FIND_STR(common_data->name_to_dispatcher, class_name, s);
|
|
65
|
-
if (s)
|
|
66
|
-
(*((dispatcher_t(*))(s->dispatcher)))(s->callbacks, common_data, event);
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
{
|
|
66
|
+
name_to_dispatcher_t *s = NULL;
|
|
67
|
+
HASH_FIND_STR(common_data->name_to_dispatcher, class_name, s);
|
|
68
|
+
if (s) {
|
|
69
|
+
(*((dispatcher_t(*))(s->dispatcher)))(s->callbacks, common_data, upstream_message,
|
|
70
|
+
&is_callback_called);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
{
|
|
75
|
+
const bt_stream_class *stream_class =
|
|
76
|
+
bt_event_class_borrow_stream_class_const(event_class);
|
|
77
|
+
const char *stream_class_name = bt_stream_class_get_name(stream_class);
|
|
78
|
+
|
|
79
|
+
name_to_dispatcher_t *s = NULL;
|
|
80
|
+
if (stream_class_name)
|
|
81
|
+
HASH_FIND_STR(common_data->name_to_matching_dispatcher, stream_class_name,
|
|
82
|
+
s);
|
|
83
|
+
if (s) {
|
|
84
|
+
// is_callback_called will only be modified if at least one callback is
|
|
85
|
+
// called.
|
|
86
|
+
(*((dispatcher_t(*))(s->dispatcher)))(s->callbacks, common_data, upstream_message,
|
|
87
|
+
&is_callback_called);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
bt_message_put_ref(upstream_message);
|
|
69
92
|
}
|
|
70
93
|
end:
|
|
71
94
|
return status;
|
|
@@ -122,12 +145,8 @@ static void sink_finalize(bt_self_component_sink *self_component_sink) {
|
|
|
122
145
|
btx_call_callbacks_finalize_usr_data(common_data, common_data->usr_data);
|
|
123
146
|
|
|
124
147
|
// Delete name_to_dispatcher
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
128
|
-
utarray_free(current->callbacks);
|
|
129
|
-
free(current);
|
|
130
|
-
}
|
|
148
|
+
btx_delete_dispatchers(common_data);
|
|
149
|
+
btx_delete_matching_dispatchers(common_data);
|
|
131
150
|
|
|
132
151
|
// We allocate it, we need to free it
|
|
133
152
|
free(common_data->btx_params);
|