| 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 | struct trace_collection; |
| 27 | struct GHashTable; |
| 28 | |
| 29 | /* |
| 30 | * The context represents the object in which a trace_collection is |
| 31 | * open. As long as this structure is allocated, the trace_collection is |
| 32 | * open and the traces it contains can be read and seeked by the |
| 33 | * iterators and callbacks. |
| 34 | * |
| 35 | * It has to be created with the bt_context_create() function and |
| 36 | * destroyed by calling one more bt_context_put() than bt_context_get() |
| 37 | */ |
| 38 | struct bt_context { |
| 39 | struct trace_collection *tc; |
| 40 | GHashTable *trace_handles; |
| 41 | int refcount; |
| 42 | int last_trace_handle_id; |
| 43 | }; |
| 44 | |
| 45 | /* |
| 46 | * bt_context_create : create a Babeltrace context |
| 47 | * |
| 48 | * Allocate a new context. The creation of the context sets the refcount |
| 49 | * to 1. |
| 50 | * |
| 51 | * Returns an allocated context on success and NULL on error |
| 52 | */ |
| 53 | struct bt_context *bt_context_create(void); |
| 54 | |
| 55 | /* |
| 56 | * bt_context_add_trace : Add a trace by path to the context |
| 57 | * |
| 58 | * Open a trace |
| 59 | * |
| 60 | * Return the trace handle id of the opened trace |
| 61 | */ |
| 62 | int bt_context_add_trace(struct bt_context *ctx, const char *path, |
| 63 | const char *format); |
| 64 | |
| 65 | /* |
| 66 | * bt_context_add_traces: Open a trace recursively |
| 67 | * |
| 68 | * Find each trace present in the subdirectory starting from the given |
| 69 | * path, and add them to the context. |
| 70 | * |
| 71 | * Return: 0 on success, nonzero on failure. |
| 72 | */ |
| 73 | int bt_context_add_traces(struct bt_context *ctx, const char *path, |
| 74 | const char *format); |
| 75 | |
| 76 | /* |
| 77 | * bt_context_remove_trace: Remove a trace from the context. |
| 78 | * |
| 79 | * Effectively closing the trace. |
| 80 | */ |
| 81 | void bt_context_remove_trace(struct bt_context *ctx, int trace_id); |
| 82 | |
| 83 | /* |
| 84 | * bt_context_get and bt_context_put : increments and decrement the |
| 85 | * refcount of the context |
| 86 | * |
| 87 | * These functions ensures that the context won't be destroyed when it |
| 88 | * is in use. The same number of get and put (plus one extra put to |
| 89 | * release the initial reference done at creation) has to be done to |
| 90 | * destroy a context. |
| 91 | * |
| 92 | * When the context refcount is decremented to 0 by a bt_context_put, |
| 93 | * the context is freed. |
| 94 | */ |
| 95 | void bt_context_get(struct bt_context *ctx); |
| 96 | void bt_context_put(struct bt_context *ctx); |
| 97 | |
| 98 | #endif /* _BABELTRACE_CONTEXT_H */ |