6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/babeltrace.h>
30 #include <babeltrace/babeltrace-internal.h>
31 #include <babeltrace/context.h>
32 #include <babeltrace/context-internal.h>
33 #include <babeltrace/ctf-ir/metadata.h>
34 #include <babeltrace/iterator-internal.h>
35 #include <babeltrace/ctf/events.h>
36 #include <babeltrace/ctf/events-internal.h>
37 #include <babeltrace/ctf/callbacks-internal.h>
41 struct bt_dependencies
*_bt_dependencies_create(const char *first
,
45 struct bt_dependencies
*dep
;
47 dep
= g_new0(struct bt_dependencies
, 1);
49 dep
->deps
= g_array_new(FALSE
, TRUE
, sizeof(GQuark
));
52 GQuark q
= g_quark_from_string(iter
);
53 g_array_append_val(dep
->deps
, q
);
54 iter
= va_arg(ap
, const char *);
59 struct bt_dependencies
*bt_dependencies_create(const char *first
, ...)
62 struct bt_dependencies
*deps
;
65 deps
= _bt_dependencies_create(first
, ap
);
71 * bt_ctf_iter_add_callback: Add a callback to CTF iterator.
73 int bt_ctf_iter_add_callback(struct bt_ctf_iter
*iter
,
74 bt_intern_str event
, void *private_data
, int flags
,
75 enum bt_cb_ret (*callback
)(struct bt_ctf_event
*ctf_data
,
77 struct bt_dependencies
*depends
,
78 struct bt_dependencies
*weak_depends
,
79 struct bt_dependencies
*provides
)
82 gpointer
*event_id_ptr
;
83 unsigned long event_id
;
84 struct trace_collection
*tc
;
86 if (!iter
|| !callback
)
89 tc
= iter
->parent
.ctx
->tc
;
90 for (i
= 0; i
< tc
->array
->len
; i
++) {
91 struct ctf_trace
*tin
;
92 struct bt_trace_descriptor
*td_read
;
94 td_read
= g_ptr_array_index(tc
->array
, i
);
95 tin
= container_of(td_read
, struct ctf_trace
, parent
);
97 for (stream_id
= 0; stream_id
< tin
->streams
->len
; stream_id
++) {
98 struct ctf_stream_declaration
*stream
;
99 struct bt_stream_callbacks
*bt_stream_cb
= NULL
;
100 struct bt_callback_chain
*bt_chain
= NULL
;
101 struct bt_callback new_callback
;
103 stream
= g_ptr_array_index(tin
->streams
, stream_id
);
105 if (stream_id
>= iter
->callbacks
->len
) {
106 g_array_set_size(iter
->callbacks
, stream
->stream_id
+ 1);
108 bt_stream_cb
= &g_array_index(iter
->callbacks
,
109 struct bt_stream_callbacks
, stream
->stream_id
);
110 if (!bt_stream_cb
->per_id_callbacks
) {
111 bt_stream_cb
->per_id_callbacks
= g_array_new(FALSE
, TRUE
,
112 sizeof(struct bt_callback_chain
));
116 /* find the event id */
117 event_id_ptr
= g_hash_table_lookup(stream
->event_quark_to_id
,
118 (gconstpointer
) (unsigned long) event
);
119 /* event not found in this stream class */
121 fprintf(stderr
, "[error] Event ID not found in stream class\n");
124 event_id
= (uint64_t)(unsigned long) *event_id_ptr
;
126 /* find or create the bt_callback_chain for this event */
127 if (event_id
>= bt_stream_cb
->per_id_callbacks
->len
) {
128 g_array_set_size(bt_stream_cb
->per_id_callbacks
, event_id
+ 1);
130 bt_chain
= &g_array_index(bt_stream_cb
->per_id_callbacks
,
131 struct bt_callback_chain
, event_id
);
132 if (!bt_chain
->callback
) {
133 bt_chain
->callback
= g_array_new(FALSE
, TRUE
,
134 sizeof(struct bt_callback
));
137 /* callback for all events */
138 if (!iter
->main_callbacks
.callback
) {
139 iter
->main_callbacks
.callback
= g_array_new(FALSE
, TRUE
,
140 sizeof(struct bt_callback
));
142 bt_chain
= &iter
->main_callbacks
;
145 new_callback
.private_data
= private_data
;
146 new_callback
.flags
= flags
;
147 new_callback
.callback
= callback
;
148 new_callback
.depends
= depends
;
149 new_callback
.weak_depends
= weak_depends
;
150 new_callback
.provides
= provides
;
152 /* TODO : take care of priority, for now just FIFO */
153 g_array_append_val(bt_chain
->callback
, new_callback
);
161 int extract_ctf_stream_event(struct ctf_stream_definition
*stream
,
162 struct bt_ctf_event
*event
)
164 struct ctf_stream_declaration
*stream_class
= stream
->stream_class
;
165 struct ctf_event_declaration
*event_class
;
166 uint64_t id
= stream
->event_id
;
168 if (id
>= stream_class
->events_by_id
->len
) {
169 fprintf(stderr
, "[error] Event id %" PRIu64
" is outside range.\n", id
);
172 event
->parent
= g_ptr_array_index(stream
->events_by_id
, id
);
173 if (!event
->parent
) {
174 fprintf(stderr
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
177 event_class
= g_ptr_array_index(stream_class
->events_by_id
, id
);
179 fprintf(stderr
, "[error] Event id %" PRIu64
" is unknown.\n", id
);
186 void process_callbacks(struct bt_ctf_iter
*iter
,
187 struct ctf_stream_definition
*stream
)
189 struct bt_stream_callbacks
*bt_stream_cb
;
190 struct bt_callback_chain
*bt_chain
;
191 struct bt_callback
*cb
;
194 struct bt_ctf_event ctf_data
;
196 assert(iter
&& stream
);
198 ret
= extract_ctf_stream_event(stream
, &ctf_data
);
202 /* process all events callback first */
203 if (iter
->main_callbacks
.callback
) {
204 for (i
= 0; i
< iter
->main_callbacks
.callback
->len
; i
++) {
205 cb
= &g_array_index(iter
->main_callbacks
.callback
, struct bt_callback
, i
);
206 ret
= cb
->callback(&ctf_data
, cb
->private_data
);
209 case BT_CB_ERROR_STOP
:
217 /* process per event callbacks */
218 bt_stream_cb
= &g_array_index(iter
->callbacks
,
219 struct bt_stream_callbacks
, stream
->stream_id
);
220 if (!bt_stream_cb
|| !bt_stream_cb
->per_id_callbacks
)
223 if (stream
->event_id
>= bt_stream_cb
->per_id_callbacks
->len
)
225 bt_chain
= &g_array_index(bt_stream_cb
->per_id_callbacks
,
226 struct bt_callback_chain
, stream
->event_id
);
227 if (!bt_chain
|| !bt_chain
->callback
)
230 for (i
= 0; i
< bt_chain
->callback
->len
; i
++) {
231 cb
= &g_array_index(bt_chain
->callback
, struct bt_callback
, i
);
232 ret
= cb
->callback(&ctf_data
, cb
->private_data
);
235 case BT_CB_ERROR_STOP
:
This page took 0.033629 seconds and 4 git commands to generate.