7 * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
23 typedef GQuark bt_event_name
;
25 /* Forward declarations */
26 struct babeltrace_iter
;
27 struct trace_collection
;
28 struct ctf_stream_event
;
30 struct babeltrace_saved_pos
;
31 struct bt_dependencies
;
37 BT_CB_ERROR_CONTINUE
= 3,
40 struct trace_collection_pos
{
42 BT_SEEK_TIME
, /* uses u.seek_time */
43 BT_SEEK_RESTORE
, /* uses u.restore */
50 struct babeltrace_saved_pos
*restore
;
55 struct ctf_stream_event
*event
;
56 struct ctf_stream
*stream
;
60 * babeltrace_iter_create - Allocate a trace collection iterator.
62 * begin_pos and end_pos are optional parameters to specify the position
63 * at which the trace collection should be seeked upon iterator
64 * creation, and the position at which iteration will start returning
67 * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at
68 * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of
69 * trace) is the EOF criterion.
71 struct babeltrace_iter
*babeltrace_iter_create(struct trace_collection
*tc
,
72 struct trace_collection_pos
*begin_pos
,
73 struct trace_collection_pos
*end_pos
);
76 * babeltrace_iter_destroy - Free a trace collection iterator.
78 void babeltrace_iter_destroy(struct babeltrace_iter
*iter
);
81 * babeltrace_iter_next: Move trace collection position to the next event.
83 * Returns 0 on success, a negative value on error
85 int babeltrace_iter_next(struct babeltrace_iter
*iter
);
88 * babeltrace_iter_save_pos - Save the current trace collection position.
90 * The position returned by this function needs to be freed by
91 * babeltrace_iter_free_pos after use.
93 struct trace_collection_pos
*
94 babeltrace_iter_save_pos(struct babeltrace_iter
*iter
);
97 * babeltrace_iter_free_pos - Free the position.
99 void babeltrace_iter_free_pos(struct trace_collection_pos
*pos
);
102 * babeltrace_iter_seek: seek iterator to given position.
104 * Return EOF if position is after the last event of the trace collection.
105 * Return other negative value for other errors.
106 * Return 0 for success.
108 int babeltrace_iter_seek(struct babeltrace_iter
*iter
,
109 const struct trace_collection_pos
*pos
);
112 * babeltrace_iter_read_event: Read the iterator's current event data.
114 * @iter: trace collection iterator (input)
115 * @stream: stream containing event at current position (output)
116 * @event: current event (output)
117 * Return 0 on success, negative error value on error.
119 int babeltrace_iter_read_event(struct babeltrace_iter
*iter
,
120 struct ctf_stream
**stream
,
121 struct ctf_stream_event
**event
);
124 * Receives a variable number of strings as parameter, ended with NULL.
126 struct bt_dependencies
*babeltrace_dependencies_create(const char *first
, ...);
129 * struct bt_dependencies must be destroyed explicitly if not passed as
130 * parameter to a babeltrace_iter_add_callback().
132 void babeltrace_dependencies_destroy(struct bt_dependencies
*dep
);
135 * babeltrace_iter_add_callback: Add a callback to iterator.
137 * @iter: trace collection iterator (input)
138 * @event: event to target. 0 for all events.
139 * @private_data: private data pointer to pass to the callback
140 * @flags: specific flags controlling the behavior of this callback
143 * @callback: function pointer to call
144 * @depends: struct bt_dependency detailing the required computation results.
146 * @weak_depends: struct bt_dependency detailing the optional computation
147 * results that can be optionally consumed by this
149 * @provides: struct bt_dependency detailing the computation results
150 * provided by this callback.
153 * "depends", "weak_depends" and "provides" memory is handled by the
154 * babeltrace library after this call succeeds or fails. These objects
155 * can still be used by the caller until the babeltrace iterator is
156 * destroyed, but they belong to the babeltrace library.
158 * (note to implementor: we need to keep a gptrarray of struct
159 * bt_dependencies to "garbage collect" in struct babeltrace_iter, and
160 * dependencies need to have a refcount to handle the case where they
161 * would be passed to more than one iterator. Upon iterator detroy, we
162 * iterate on all the gc ptrarray and decrement the refcounts, freeing
164 * (note to implementor: we calculate the dependency graph when
165 * babeltrace_iter_read_event() is executed after a
166 * babeltrace_iter_add_callback(). Beware that it is valid to create/add
167 * callbacks/read/add more callbacks/read some more.)
169 int babeltrace_iter_add_callback(struct babeltrace_iter
*iter
,
170 bt_event_name event
, void *private_data
, int flags
,
171 enum bt_cb_ret (*callback
)(struct bt_ctf_data
*ctf_data
,
173 struct bt_dependencies
*depends
,
174 struct bt_dependencies
*weak_depends
,
175 struct bt_dependencies
*provides
);
178 * For flags parameter above.
181 BT_FLAGS_FREE_PRIVATE_DATA
= (1 << 0),
184 #endif /* _BABELTRACE_H */