Commit | Line | Data |
---|---|---|
b469d2dd JD |
1 | #ifndef _BABELTRACE_CONTEXT_H |
2 | #define _BABELTRACE_CONTEXT_H | |
3 | ||
4 | /* | |
5 | * BabelTrace | |
6 | * | |
7 | * context header | |
8 | * | |
9 | * Copyright 2012 EfficiOS Inc. and Linux Foundation | |
10 | * | |
11 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
12 | * Julien Desfossez <julien.desfossez@efficios.com> | |
13 | * | |
6cba487f MD |
14 | * Permission is hereby granted, free of charge, to any person obtaining |
15 | * a copy of this software and associated documentation files (the | |
16 | * "Software"), to deal in the Software without restriction, including | |
17 | * without limitation the rights to use, copy, modify, merge, publish, | |
18 | * distribute, sublicense, and/or sell copies of the Software, and to | |
19 | * permit persons to whom the Software is furnished to do so, subject to | |
20 | * the following conditions: | |
b469d2dd | 21 | * |
6cba487f MD |
22 | * The above copyright notice and this permission notice shall be |
23 | * included in all copies or substantial portions of the Software. | |
c462e188 MD |
24 | * |
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
31 | * SOFTWARE. | |
b469d2dd JD |
32 | */ |
33 | ||
613f532b | 34 | #include <unistd.h> |
0d4c669f | 35 | #include <babeltrace/format.h> |
613f532b | 36 | |
6946751f JD |
37 | #ifdef __cplusplus |
38 | extern "C" { | |
39 | #endif | |
40 | ||
08c22d05 MD |
41 | /* struct bt_context is opaque to the user */ |
42 | struct bt_context; | |
1cf393f6 | 43 | struct bt_stream_pos; |
c50d2a7a | 44 | struct bt_ctf_event; |
b469d2dd JD |
45 | |
46 | /* | |
47 | * bt_context_create : create a Babeltrace context | |
48 | * | |
6cba487f MD |
49 | * Allocate a new context. The creation of the context sets the refcount |
50 | * to 1. | |
b469d2dd JD |
51 | * |
52 | * Returns an allocated context on success and NULL on error | |
53 | */ | |
6cba487f | 54 | struct bt_context *bt_context_create(void); |
b469d2dd JD |
55 | |
56 | /* | |
6cba487f | 57 | * bt_context_add_trace : Add a trace by path to the context |
b469d2dd | 58 | * |
2f5d314f MD |
59 | * Open a trace. |
60 | * | |
31265d84 JD |
61 | * path is the path to the trace, it is not recursive. If "path" is NULL, |
62 | * stream_list is used instead as a list of mmap streams to open for the trace. | |
63 | * | |
64 | * format is a string containing the format name in which the trace was | |
65 | * produced. | |
66 | * | |
67 | * packet_seek can be NULL to use the default packet_seek handler provided by | |
68 | * the trace format. If non-NULL, it is used as an override of the handler for | |
69 | * seeks across packets. It takes as parameter a stream position, the packet | |
70 | * index it needs to seek to (for SEEK_SET), and a "whence" parameter (either | |
71 | * SEEK_CUR: seek to next packet, or SEEK_SET: seek to packet at packet index). | |
72 | * | |
73 | * stream_list is a linked list of streams, it is used to open a trace where | |
74 | * the trace data is located in memory mapped areas instead of trace files, | |
14865672 | 75 | * this argument should be non-NULL when path is NULL. |
31265d84 JD |
76 | * |
77 | * The metadata parameter acts as a metadata override when not NULL, otherwise | |
78 | * the format handles the metadata opening. | |
0d4c669f | 79 | * |
1059a2bf JD |
80 | * Return: the trace handle id (>= 0) on success, a negative |
81 | * value on error. | |
6cba487f MD |
82 | */ |
83 | int bt_context_add_trace(struct bt_context *ctx, const char *path, | |
613f532b | 84 | const char *format, |
1cf393f6 | 85 | void (*packet_seek)(struct bt_stream_pos *pos, |
0d4c669f | 86 | size_t index, int whence), |
c150f912 | 87 | struct bt_mmap_stream_list *stream_list, |
0d4c669f | 88 | FILE *metadata); |
6cba487f | 89 | |
6cba487f MD |
90 | /* |
91 | * bt_context_remove_trace: Remove a trace from the context. | |
92 | * | |
7f89ddce MD |
93 | * Effectively closing the trace. Return negative error value if trace |
94 | * is not in context. | |
b469d2dd | 95 | */ |
7f89ddce | 96 | int bt_context_remove_trace(struct bt_context *ctx, int trace_id); |
b469d2dd JD |
97 | |
98 | /* | |
6cba487f MD |
99 | * bt_context_get and bt_context_put : increments and decrement the |
100 | * refcount of the context | |
b469d2dd | 101 | * |
6cba487f MD |
102 | * These functions ensures that the context won't be destroyed when it |
103 | * is in use. The same number of get and put (plus one extra put to | |
104 | * release the initial reference done at creation) has to be done to | |
105 | * destroy a context. | |
b469d2dd | 106 | * |
6cba487f MD |
107 | * When the context refcount is decremented to 0 by a bt_context_put, |
108 | * the context is freed. | |
b469d2dd | 109 | */ |
6cba487f MD |
110 | void bt_context_get(struct bt_context *ctx); |
111 | void bt_context_put(struct bt_context *ctx); | |
b469d2dd | 112 | |
98a04903 JD |
113 | /* |
114 | * bt_ctf_get_context : get the context associated with an event | |
115 | * | |
116 | * Returns NULL on error | |
117 | */ | |
c50d2a7a | 118 | struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event); |
98a04903 | 119 | |
6946751f JD |
120 | #ifdef __cplusplus |
121 | } | |
122 | #endif | |
123 | ||
b469d2dd | 124 | #endif /* _BABELTRACE_CONTEXT_H */ |