| 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 | |
| 28 | /* struct bt_context is opaque to the user */ |
| 29 | struct bt_context; |
| 30 | struct stream_pos; |
| 31 | |
| 32 | /* |
| 33 | * bt_context_create : create a Babeltrace context |
| 34 | * |
| 35 | * Allocate a new context. The creation of the context sets the refcount |
| 36 | * to 1. |
| 37 | * |
| 38 | * Returns an allocated context on success and NULL on error |
| 39 | */ |
| 40 | struct bt_context *bt_context_create(void); |
| 41 | |
| 42 | /* |
| 43 | * bt_context_add_trace : Add a trace by path to the context |
| 44 | * |
| 45 | * Open a trace. Parameter packet_seek can be NULL to use the default |
| 46 | * packet_seek handle of the format. |
| 47 | * |
| 48 | * Return: the trace handle id (>= 0) on success, a negative |
| 49 | * value on error. |
| 50 | */ |
| 51 | int bt_context_add_trace(struct bt_context *ctx, const char *path, |
| 52 | const char *format, |
| 53 | void (*packet_seek)(struct stream_pos *pos, |
| 54 | size_t index, int whence)); |
| 55 | |
| 56 | /* |
| 57 | * bt_context_remove_trace: Remove a trace from the context. |
| 58 | * |
| 59 | * Effectively closing the trace. |
| 60 | */ |
| 61 | void bt_context_remove_trace(struct bt_context *ctx, int trace_id); |
| 62 | |
| 63 | /* |
| 64 | * bt_context_get and bt_context_put : increments and decrement the |
| 65 | * refcount of the context |
| 66 | * |
| 67 | * These functions ensures that the context won't be destroyed when it |
| 68 | * is in use. The same number of get and put (plus one extra put to |
| 69 | * release the initial reference done at creation) has to be done to |
| 70 | * destroy a context. |
| 71 | * |
| 72 | * When the context refcount is decremented to 0 by a bt_context_put, |
| 73 | * the context is freed. |
| 74 | */ |
| 75 | void bt_context_get(struct bt_context *ctx); |
| 76 | void bt_context_put(struct bt_context *ctx); |
| 77 | |
| 78 | #endif /* _BABELTRACE_CONTEXT_H */ |