| 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 a copy |
| 15 | * of this software and associated documentation files (the "Software"), to deal |
| 16 | * in the Software without restriction, including without limitation the rights |
| 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 18 | * copies of the Software, and to permit persons to whom the Software is |
| 19 | * furnished to do so, subject to the following conditions: |
| 20 | * |
| 21 | * The above copyright notice and this permission notice shall be included in |
| 22 | * all copies or substantial portions of the Software. |
| 23 | */ |
| 24 | |
| 25 | struct trace_collection; |
| 26 | |
| 27 | /* |
| 28 | * The context represents the object in which a trace_collection is open. As |
| 29 | * long as this structure is allocated, the trace_collection is open and the |
| 30 | * traces it contains can be read and seeked by the iterators and callbacks. |
| 31 | * |
| 32 | * It has to be created with the bt_context_create() function and destroyed by |
| 33 | * bt_context_destroy() |
| 34 | */ |
| 35 | struct bt_context { |
| 36 | struct trace_collection *tc; |
| 37 | int refcount; |
| 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * bt_context_create : create a Babeltrace context |
| 42 | * |
| 43 | * Allocate a new context and assign the trace_collection passed in |
| 44 | * parameter as the context trace_collection. The trace_collection |
| 45 | * must contain an array of valid trace_descriptors. The creation of |
| 46 | * the context sets the refcount to 1. |
| 47 | * |
| 48 | * Returns an allocated context on success and NULL on error |
| 49 | */ |
| 50 | struct bt_context *bt_context_create(struct trace_collection *tc); |
| 51 | |
| 52 | /* |
| 53 | * bt_context_destroy : destroy a context |
| 54 | * |
| 55 | * If the context is still in use (by an iterator or a callback), the |
| 56 | * destroy fails and returns -1, on success : return 0. |
| 57 | */ |
| 58 | int bt_context_destroy(struct bt_context *ctx); |
| 59 | |
| 60 | /* |
| 61 | * bt_context_get and bt_context_put : increments and decrement the refcount of |
| 62 | * the context |
| 63 | * |
| 64 | * These functions ensures that the context won't be destroyed when it is in |
| 65 | * use. The same number of get and put has to be done to be able to destroy a |
| 66 | * context. |
| 67 | * |
| 68 | * Return 0 on success, -1 if the context pointer is invalid. When the context |
| 69 | * refcount is decremented to 0 by a bt_context_put, it calls |
| 70 | * bt_context_destroy to free the context. In this case the return code of |
| 71 | * bt_context_destroy is returned. |
| 72 | */ |
| 73 | int bt_context_get(struct bt_context *ctx); |
| 74 | int bt_context_put(struct bt_context *ctx); |
| 75 | |
| 76 | #endif /* _BABELTRACE_CONTEXT_H */ |