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