metababel 0.0.0
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 +7 -0
- data/README.md +60 -0
- data/bin/metababel +233 -0
- data/lib/metababel/bt2_generator_utils.rb +38 -0
- data/lib/metababel/bt2_stream_classes_generator.rb +716 -0
- data/lib/metababel/bt2_values_generator.rb +132 -0
- data/lib/metababel/version.rb +3 -0
- data/lib/metababel.rb +4 -0
- data/template/component.c.erb +69 -0
- data/template/component.h.erb +160 -0
- data/template/downstream.c.erb +119 -0
- data/template/downstream.h.erb +34 -0
- data/template/filter.c.erb +400 -0
- data/template/metababel.h.erb +7 -0
- data/template/sink.c.erb +166 -0
- data/template/source.c.erb +200 -0
- data/template/upstream.c.erb +47 -0
- data/template/upstream.h.erb +22 -0
- metadata +62 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#include "uthash.h"
|
|
2
|
+
#include "utlist.h"
|
|
3
|
+
#include <babeltrace2/babeltrace.h>
|
|
4
|
+
#include <metababel/metababel.h>
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
|
|
8
|
+
/* Loosely inspired by
|
|
9
|
+
* https://babeltrace.org/docs/v2.0/libbabeltrace2/example-simple-src-cmp-cls.html
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Handle Upstream Messages
|
|
14
|
+
*/
|
|
15
|
+
static bt_message_iterator_class_next_method_status
|
|
16
|
+
source_message_iterator_next(bt_self_message_iterator *self_message_iterator,
|
|
17
|
+
bt_message_array_const messages, uint64_t capacity,
|
|
18
|
+
uint64_t *count) {
|
|
19
|
+
|
|
20
|
+
/* The clean thing to do will be to refractor the code, so we can reuse some
|
|
21
|
+
* part of the filter state-machine... For now unoptimal and simple state
|
|
22
|
+
* machine will be enough */
|
|
23
|
+
|
|
24
|
+
/* Retrieve our private data from the message iterator's user data */
|
|
25
|
+
btx_message_iterator_t *message_iterator_private_data =
|
|
26
|
+
bt_self_message_iterator_get_data(self_message_iterator);
|
|
27
|
+
|
|
28
|
+
/* When you return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END, you must
|
|
29
|
+
* not put any message into the message array */
|
|
30
|
+
switch (message_iterator_private_data->state) {
|
|
31
|
+
case BTX_SOURCE_STATE_INITIALIZING:
|
|
32
|
+
/* Begining of Stream */
|
|
33
|
+
btx_push_messages_stream_beginning(self_message_iterator,
|
|
34
|
+
message_iterator_private_data);
|
|
35
|
+
|
|
36
|
+
/* Call Initialize user callback */
|
|
37
|
+
btx_call_callbacks_initialize_usr_data(
|
|
38
|
+
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);
|
|
45
|
+
|
|
46
|
+
message_iterator_private_data->state = BTX_SOURCE_STATE_PROCESSING;
|
|
47
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
48
|
+
case BTX_SOURCE_STATE_PROCESSING:
|
|
49
|
+
if (message_iterator_private_data->queue) {
|
|
50
|
+
btx_downstream_move_messages(message_iterator_private_data, messages,
|
|
51
|
+
capacity, count);
|
|
52
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
btx_source_status_t status = BTX_SOURCE_END;
|
|
56
|
+
|
|
57
|
+
btx_call_callbacks_push_usr_messages(
|
|
58
|
+
message_iterator_private_data->common_data,
|
|
59
|
+
message_iterator_private_data->common_data->usr_data, &status);
|
|
60
|
+
if (status == BTX_SOURCE_END) {
|
|
61
|
+
|
|
62
|
+
/* Call Finalize user callback */
|
|
63
|
+
btx_call_callbacks_finalize_usr_data(
|
|
64
|
+
message_iterator_private_data->common_data,
|
|
65
|
+
message_iterator_private_data->common_data->usr_data);
|
|
66
|
+
/* End of Stream */
|
|
67
|
+
btx_push_messages_stream_end(self_message_iterator,
|
|
68
|
+
message_iterator_private_data);
|
|
69
|
+
message_iterator_private_data->state = BTX_SOURCE_STATE_FINALIZING;
|
|
70
|
+
}
|
|
71
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN;
|
|
72
|
+
case BTX_SOURCE_STATE_FINALIZING:
|
|
73
|
+
if (message_iterator_private_data->queue) {
|
|
74
|
+
btx_downstream_move_messages(message_iterator_private_data, messages,
|
|
75
|
+
capacity, count);
|
|
76
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
|
|
77
|
+
}
|
|
78
|
+
message_iterator_private_data->state = BTX_SOURCE_STATE_FINISHED;
|
|
79
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END;
|
|
80
|
+
case BTX_SOURCE_STATE_FINISHED:
|
|
81
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END;
|
|
82
|
+
default:
|
|
83
|
+
return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* Initializes the source component.
|
|
89
|
+
*/
|
|
90
|
+
bt_component_class_initialize_method_status
|
|
91
|
+
source_initialize(bt_self_component_source *self_component_source,
|
|
92
|
+
bt_self_component_source_configuration *configuration,
|
|
93
|
+
const bt_value *params, void *initialize_method_data) {
|
|
94
|
+
/* Allocate a private data structure */
|
|
95
|
+
common_data_t *common_data = calloc(1, sizeof(common_data_t));
|
|
96
|
+
common_data->params = params;
|
|
97
|
+
// Read parameters
|
|
98
|
+
btx_populate_params(common_data);
|
|
99
|
+
bt_value_get_ref(common_data->params);
|
|
100
|
+
|
|
101
|
+
/* Register User Callbacks */
|
|
102
|
+
btx_register_usr_callbacks((void *)common_data);
|
|
103
|
+
/* Upcast `self_component_source` to the `bt_self_component` type */
|
|
104
|
+
bt_self_component *self_component =
|
|
105
|
+
bt_self_component_source_as_self_component(self_component_source);
|
|
106
|
+
|
|
107
|
+
bt_trace_class *trace_class =
|
|
108
|
+
btx_downstream_trace_class_create_rec(self_component);
|
|
109
|
+
|
|
110
|
+
/* Instantiate a `downstream_trace` of `trace_class` and all the children
|
|
111
|
+
* stream */
|
|
112
|
+
common_data->downstream_trace = btx_downstream_trace_create_rec(trace_class);
|
|
113
|
+
|
|
114
|
+
/* Set the component's user data to our private data structure */
|
|
115
|
+
bt_self_component_set_data(self_component, common_data);
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* Add an output port named `out` to the source component.
|
|
119
|
+
*
|
|
120
|
+
* This is needed so that this source component can be connected to
|
|
121
|
+
* a filter or a sink component. Once a downstream component is
|
|
122
|
+
* connected, it can create our message iterator.
|
|
123
|
+
*/
|
|
124
|
+
bt_self_component_source_add_output_port(self_component_source, "out", NULL,
|
|
125
|
+
NULL);
|
|
126
|
+
|
|
127
|
+
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* Initializes the message iterator.
|
|
132
|
+
*/
|
|
133
|
+
static bt_message_iterator_class_initialize_method_status
|
|
134
|
+
source_message_iterator_initialize(
|
|
135
|
+
bt_self_message_iterator *self_message_iterator,
|
|
136
|
+
bt_self_message_iterator_configuration *configuration,
|
|
137
|
+
bt_self_component_port_output *self_port) {
|
|
138
|
+
/* Allocate a private data structure */
|
|
139
|
+
btx_message_iterator_t *message_iterator_private_data =
|
|
140
|
+
calloc(1, sizeof(btx_message_iterator_t));
|
|
141
|
+
|
|
142
|
+
message_iterator_private_data->state = BTX_SOURCE_STATE_INITIALIZING;
|
|
143
|
+
|
|
144
|
+
/* Retrieve the component's private data from its user data */
|
|
145
|
+
common_data_t *common_data = bt_self_component_get_data(
|
|
146
|
+
bt_self_message_iterator_borrow_component(self_message_iterator));
|
|
147
|
+
|
|
148
|
+
/* Save a link to the self_message_iterator */
|
|
149
|
+
common_data->self_message_iterator = self_message_iterator;
|
|
150
|
+
|
|
151
|
+
/* Keep a link to the component's private data */
|
|
152
|
+
message_iterator_private_data->common_data = common_data;
|
|
153
|
+
|
|
154
|
+
/* Set the message iterator's user data to our private data structure */
|
|
155
|
+
bt_self_message_iterator_set_data(self_message_iterator,
|
|
156
|
+
message_iterator_private_data);
|
|
157
|
+
|
|
158
|
+
return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static void source_finalize(bt_self_component_source *self_component_source) {
|
|
162
|
+
common_data_t *common_data = bt_self_component_get_data(
|
|
163
|
+
bt_self_component_source_as_self_component(self_component_source));
|
|
164
|
+
// We allocate it, we need to free it
|
|
165
|
+
free(common_data->btx_params);
|
|
166
|
+
bt_value_put_ref(common_data->params);
|
|
167
|
+
free(common_data);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static void source_message_iterator_finalize(
|
|
171
|
+
bt_self_message_iterator *self_message_iterator) {
|
|
172
|
+
/* Retrieve our private data from the message iterator's user data */
|
|
173
|
+
btx_message_iterator_t *message_iterator_private_data =
|
|
174
|
+
bt_self_message_iterator_get_data(self_message_iterator);
|
|
175
|
+
|
|
176
|
+
struct el *elt, *tmp;
|
|
177
|
+
DL_FOREACH_SAFE(message_iterator_private_data->pool, elt, tmp) {
|
|
178
|
+
DL_DELETE(message_iterator_private_data->pool, elt);
|
|
179
|
+
free(elt);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Free the allocated structure */
|
|
183
|
+
free(message_iterator_private_data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* Mandatory */
|
|
187
|
+
BT_PLUGIN_MODULE();
|
|
188
|
+
|
|
189
|
+
BT_PLUGIN(<%= options[:plugin_name] %>);
|
|
190
|
+
BT_PLUGIN_SOURCE_COMPONENT_CLASS(<%= options[:component_name] %>,
|
|
191
|
+
source_message_iterator_next);
|
|
192
|
+
|
|
193
|
+
BT_PLUGIN_SOURCE_COMPONENT_CLASS_INITIALIZE_METHOD(<%= options[:component_name] %>,
|
|
194
|
+
source_initialize);
|
|
195
|
+
BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD(<%= options[:component_name] %>,
|
|
196
|
+
source_finalize);
|
|
197
|
+
BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD(
|
|
198
|
+
<%= options[:component_name] %>, source_message_iterator_initialize);
|
|
199
|
+
BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD(
|
|
200
|
+
<%= options[:component_name] %>, source_message_iterator_finalize);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#include "utarray.h"
|
|
2
|
+
#include "uthash.h"
|
|
3
|
+
#include <assert.h>
|
|
4
|
+
#include <babeltrace2/babeltrace.h>
|
|
5
|
+
#include <metababel/btx_component.h>
|
|
6
|
+
#include <metababel/btx_upstream.h>
|
|
7
|
+
|
|
8
|
+
<% event_dispatchers.each do |e| %>
|
|
9
|
+
static void
|
|
10
|
+
btx_dispatch_<%= e.name_sanitized %>(UT_array *callbacks,
|
|
11
|
+
common_data_t *common_data,
|
|
12
|
+
const bt_event *<%= event_name %>) {
|
|
13
|
+
|
|
14
|
+
<% e.args.each do |s| %>
|
|
15
|
+
<%= s.type %> <%= s.name %>;
|
|
16
|
+
<% end %>
|
|
17
|
+
<%= e.body %>
|
|
18
|
+
// Call all the callbacks who where registered
|
|
19
|
+
// Their type are declared in 'upstream.h'
|
|
20
|
+
<%= e.name_sanitized %>_callback_f **p = NULL;
|
|
21
|
+
while ((p = utarray_next(callbacks, p))) {
|
|
22
|
+
(*p)((void *)common_data, common_data->usr_data,
|
|
23
|
+
<%= e.args.map{ |s| s.name }.join(", ") %>);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
28
|
+
void *btx_handle, <%= e.name_sanitized %>_callback_f *callback) {
|
|
29
|
+
// Look-up our dispatcher
|
|
30
|
+
name_to_dispatcher_t *s = NULL;
|
|
31
|
+
name_to_dispatcher_t **name_to_dispatcher =
|
|
32
|
+
&((common_data_t *)btx_handle)->name_to_dispatcher;
|
|
33
|
+
HASH_FIND_STR(*name_to_dispatcher, "<%= e.name %>", s);
|
|
34
|
+
if (!s) {
|
|
35
|
+
// We didn't find the dispatcher, so we need to:
|
|
36
|
+
// 1. Create it
|
|
37
|
+
s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
|
|
38
|
+
s->name = "<%= e.name %>";
|
|
39
|
+
s->dispatcher = (void *)&btx_dispatch_<%= e.name_sanitized %>;
|
|
40
|
+
utarray_new(s->callbacks, &ut_ptr_icd);
|
|
41
|
+
// 2. Register it
|
|
42
|
+
HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
|
|
43
|
+
}
|
|
44
|
+
// Add the callbacks to the array
|
|
45
|
+
utarray_push_back(s->callbacks, &callback);
|
|
46
|
+
}
|
|
47
|
+
<% end %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <metababel/btx_component.h>
|
|
3
|
+
#ifdef __cplusplus
|
|
4
|
+
extern "C" {
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
// Dispatcher
|
|
8
|
+
typedef void(dispatcher_t)(UT_array *callbacks, common_data_t *common_data,
|
|
9
|
+
const bt_event *message);
|
|
10
|
+
|
|
11
|
+
<% event_dispatchers.each do |e| %>
|
|
12
|
+
<%# The signature type of callbacks %>
|
|
13
|
+
typedef void
|
|
14
|
+
<%= e.name_sanitized %>_callback_f(void *btx_handle, void *usr_data,
|
|
15
|
+
<%= e.args.map{ |s| s.type }.join(", ") %>);
|
|
16
|
+
<%# The Function who register the callbacks to the dispatcher %>
|
|
17
|
+
extern void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
18
|
+
void *btx_handle, <%= e.name_sanitized %>_callback_f *callback);
|
|
19
|
+
<% end %>
|
|
20
|
+
#ifdef __cplusplus
|
|
21
|
+
}
|
|
22
|
+
#endif
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: metababel
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Thomas Applencourt
|
|
8
|
+
- Aurelio A. Vivas Meza
|
|
9
|
+
- Brice Videau
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
|
14
|
+
dependencies: []
|
|
15
|
+
description:
|
|
16
|
+
email:
|
|
17
|
+
executables:
|
|
18
|
+
- metababel
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- README.md
|
|
23
|
+
- bin/metababel
|
|
24
|
+
- lib/metababel.rb
|
|
25
|
+
- lib/metababel/bt2_generator_utils.rb
|
|
26
|
+
- lib/metababel/bt2_stream_classes_generator.rb
|
|
27
|
+
- lib/metababel/bt2_values_generator.rb
|
|
28
|
+
- lib/metababel/version.rb
|
|
29
|
+
- template/component.c.erb
|
|
30
|
+
- template/component.h.erb
|
|
31
|
+
- template/downstream.c.erb
|
|
32
|
+
- template/downstream.h.erb
|
|
33
|
+
- template/filter.c.erb
|
|
34
|
+
- template/metababel.h.erb
|
|
35
|
+
- template/sink.c.erb
|
|
36
|
+
- template/source.c.erb
|
|
37
|
+
- template/upstream.c.erb
|
|
38
|
+
- template/upstream.h.erb
|
|
39
|
+
homepage:
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
metadata: {}
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.1.2
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: Helper for creation Babeltrace plugins
|
|
62
|
+
test_files: []
|