4a85ff9966162aefa6c61b757ff510a62a659dec
[babeltrace.git] / include / babeltrace / context.h
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 *
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:
21 *
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
24 */
25
26 #include <unistd.h>
27 #include <babeltrace/format.h>
28
29 /* struct bt_context is opaque to the user */
30 struct bt_context;
31 struct stream_pos;
32 struct bt_ctf_event;
33
34 /*
35 * bt_context_create : create a Babeltrace context
36 *
37 * Allocate a new context. The creation of the context sets the refcount
38 * to 1.
39 *
40 * Returns an allocated context on success and NULL on error
41 */
42 struct bt_context *bt_context_create(void);
43
44 /*
45 * bt_context_add_trace : Add a trace by path to the context
46 *
47 * Open a trace.
48 *
49 * path is the path to the trace, it is not recursive. If "path" is NULL,
50 * stream_list is used instead as a list of mmap streams to open for the trace.
51 *
52 * format is a string containing the format name in which the trace was
53 * produced.
54 *
55 * packet_seek can be NULL to use the default packet_seek handler provided by
56 * the trace format. If non-NULL, it is used as an override of the handler for
57 * seeks across packets. It takes as parameter a stream position, the packet
58 * index it needs to seek to (for SEEK_SET), and a "whence" parameter (either
59 * SEEK_CUR: seek to next packet, or SEEK_SET: seek to packet at packet index).
60 *
61 * stream_list is a linked list of streams, it is used to open a trace where
62 * the trace data is located in memory mapped areas instead of trace files,
63 * this argument should be set to NULL when path is not NULL.
64 *
65 * The metadata parameter acts as a metadata override when not NULL, otherwise
66 * the format handles the metadata opening.
67 *
68 * Return: the trace handle id (>= 0) on success, a negative
69 * value on error.
70 */
71 int bt_context_add_trace(struct bt_context *ctx, const char *path,
72 const char *format,
73 void (*packet_seek)(struct stream_pos *pos,
74 size_t index, int whence),
75 struct mmap_stream_list *stream_list,
76 FILE *metadata);
77
78 /*
79 * bt_context_remove_trace: Remove a trace from the context.
80 *
81 * Effectively closing the trace.
82 */
83 void bt_context_remove_trace(struct bt_context *ctx, int trace_id);
84
85 /*
86 * bt_context_get and bt_context_put : increments and decrement the
87 * refcount of the context
88 *
89 * These functions ensures that the context won't be destroyed when it
90 * is in use. The same number of get and put (plus one extra put to
91 * release the initial reference done at creation) has to be done to
92 * destroy a context.
93 *
94 * When the context refcount is decremented to 0 by a bt_context_put,
95 * the context is freed.
96 */
97 void bt_context_get(struct bt_context *ctx);
98 void bt_context_put(struct bt_context *ctx);
99
100 /*
101 * bt_ctf_get_context : get the context associated with an event
102 *
103 * Returns NULL on error
104 */
105 struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
106
107 #endif /* _BABELTRACE_CONTEXT_H */
This page took 0.029962 seconds and 4 git commands to generate.