Remove popt from project's dependencies All of the argument parsing having been moved to use the internal argpar library, we can now stop linking with popt. And since it was the last use of popt in the repo, remove anything related to it. Change-Id: Id2aee4869780e586833d6b6646e12e19c6d78f6a Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/1795 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib: force user to include `<babeltrace2/babeltrace.h>` This patch makes all the library headers except `<babeltrace2/babeltrace.h>` refuse to be included directly. This will allow us to change how those headers are organized, and even remove some if needed (as long as we move the existing content to another existing header), because we know the user does not include specific headers. To do this, the main `<babeltrace2/babeltrace.h>` defines `__BT_IN_BABELTRACE_H`, and each specific header does: #ifndef __BT_IN_BABELTRACE_H # error "Please include <babeltrace2/babeltrace.h> instead." #endif at the beginning. Because each specific header has the guarantee that it is included from `<babeltrace2/babeltrace.h>`, they don't include `<babeltrace2/func-status.h>`: `<babeltrace2/babeltrace.h>` includes it, and clears the private status definitions itself at the end. Therefore this patch removes `undef-func-status.h`. Some parts of the project need to have access to the `__BT_FUNC_STATUS_*` definitions. To do that, they do: #define __BT_IN_BABELTRACE_H #include <babeltrace2/func-status.h> Because `<babeltrace2/babeltrace.h>` is now manually written and maintained, this patch removes `extras/gen-babeltrace-h.py` which we used to generate it from `include/Makefile.am`. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Icc3bf0bec18a465024b316f02f84df7a75429b87 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1671 Tested-by: jenkins <jenkins@lttng.org>
lib: strictly type function return status enumerations Rigour strikes again. This patch makes each function (or group of related functions) of the library which returns a status enumeration return its own, function-specific status enumeration. For example, where bt_graph_run() used to return the generic `bt_graph_status` type, it now returns `bt_graph_run_status`. The benefits are: * Each function defines its own set of available status codes. With appropriate compiler warnings, you can catch comparisons between a returned status and an incompatible enumerator, and assignments of incompatible enumerators. For example, with clang 8: file.c:13:13: warning: implicit conversion from enumeration type 'enum bt_component_class_init_method_status' to different enumeration type 'enum bt_component_class_port_connected_method_status' [-Wenum-conversion] bt_component_class_port_connected_method_status status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; This was not possible before because all the status-returning functions of a given header could possibly return any value defined by the header-wide status enumeration. * A function's possible return values are self-documented: there's no need to document that a given function can only return some subset of the header-wide status enumerators. * In future minor releases of Babeltrace 2, we can add new status codes for a specific function. * Some smart IDEs will list the possible enumerators when checking the return value of a function or when returning a value from a function. To uniformize the status enumerator integer values, the new `<babeltrace2/func-status.h>` public header contains definitions for all the possible status codes. They are definitions instead of enumerators because they are not meant to be used directly by user code. To make sure a user does not write: #include <babeltrace2/func-status.h> to use the `__BT_FUNC_STATUS_*` definitions directly (which would inhibit the precious type checking that this patch is all about), the compiler will show the error: > Do NOT include <babeltrace2/func-status.h> in user code. unless you define `__BT_FUNC_STATUS_ENABLE` before including the header. Each public header which needs `__BT_FUNC_STATUS_*` definitions to define its own status enumerations does: /* For __BT_FUNC_STATUS_* */ #define __BT_FUNC_STATUS_ENABLE #include <babeltrace2/func-status.h> #undef __BT_FUNC_STATUS_ENABLE at the beginning of the file, and: #include <babeltrace2/undef-func-status.h> at the end of the file. The `<babeltrace2/undef-func-status.h>` header cancels all the existing `__BT_FUNC_STATUS_*` definitions so that they are not available to user code. Within the library, `"lib/func-status.h"` uses the definitions of `<babeltrace2/func-status.h>` to define its own, similar definitions, but without the `__` prefix for improved internal code readability. Internal library code does not need to "undefine" those definitions. As this system guarantees that any public status enumerator is an alias of one of the `__BT_FUNC_STATUS_*` definitions, the library code never uses the function-specific status enumerators directly: it always uses one of the `BT_FUNC_STATUS_*` definitions found in `"lib/func-status.h"`. This made it easier to adapt existing code. This also allows to pass such status codes easily between internal and public functions because they are `int` values until they finally reach public enumeration types where they are implicitly casted. When an internal (hidden, static) function returns a status code, it now returns `int`, using one of the `BT_FUNC_STATUS_*` values, where this could be used by at least two functions returning different public status enumerations. In internal headers, all the bt_*_status_string() are removed in favor of bt_common_func_status_string() which returns only the suffix string (e.g., `OK`, `ERROR`, `OVERFLOW`). This function is typically used when logging. The `*_NOMEM` enumerators are renamed to `*_MEMORY_ERROR` to make this clear and remove this abbreviation which was the only one amongst other public status enumerators. Because the Python bindings are within the Babeltrace project, they use the `__BT_FUNC_STATUS_*` definitions internally. Those values will not change in the future anyway. All the _handle_*status() and bt2.utils._handle_ret() functions are removed in favor of bt2.utils._handle_func_status() which can handle all the possible status codes and raise a corresponding exception, possibly with a given message. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I3966ac0e691219102897920617711c518c34fbdf
ctf-writer: externalize libbabeltrace2-ctf-writer Completely split the ctf writer part from the main babeltrace2 library. * Remove the obsolete libbabeltrace2-ctf library * Add a new libbabeltrace2-ctf-writer library * Remove the ctf writer includes from the main include file * Fork an internal copy of assert-pre.h that doesn't use the library structures. * Add a logging context specific to ctf writer Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: Iff9ab62ee9eeb8abd290fb1d758a73050e21c99b Reviewed-on: https://review.lttng.org/c/babeltrace/+/1410 Tested-by: jenkins Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Cleanup: remove useless Makefiles from extras Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: I8eaf99fab641f264699c16b2069b81c16e27bda5 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1354 CI-Build: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib: rename include dir to babeltrace2 Rename the include dir to be co-installable with bt1. Change-Id: Icb9a048988544eaca7054648b9c7a9e76d70b9db Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/1405 Tested-by: jenkins Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib: graph: add "self" and some "private" APIs The main purpose of this patch is to create different "views" of the same graph objects. The terms are as such: Public API: You can only read properties of the object. Example: bt_graph_is_canceled(). Private API: You can create the object and set properties. Example: bt_private_graph_create(). Self API: You conceptually inherit this object. Example: bt_self_component_set_data(). This means that component user method now accepts a "self component", on which: * You can set and get user data (bt_self_component_set_data() and bt_self_component_get_data()). * You can add ports (for example, bt_self_component_source_add_output_port()). * You can borrow "self component ports", on which you can get user data (bt_self_component_port_get_data()) that you set previously with a port adding function. A notification iterator method now accepts a "self notification iterator", on which: * You can set and get user data (bt_self_notification_iterator_set_data() and bt_self_notification_iterator_get_data()). * You can borrow your "self component" (bt_self_notification_iterator_borrow_component()) or "self component output port" (bt_self_notification_iterator_borrow_port()). Also, you now use the private component class API to create component classes and set optional methods, a description, and the rest. Also in this patch: * Component class and component APIs are split into source, filter, and sink parts. This makes everything more type safe considering that: * We don't need any polymorphism like we do, for example, for field classes, for component classes and components: you always know, contextually, with which type you're dealing. * We don't need to have collections of components or component classes of different types: we can just use three collections each time. This means that the private graph API, for example, now has the three distinct bt_private_graph_add_source_component(), bt_private_graph_add_filter_component(), and bt_private_graph_add_sink_component(), each of them accepting the appropriate component class type and returning the corresponding component type. No function exists to borrow a source component's input port or a sink component's output port. * The port API is split into input and output parts, with the new `struct bt_port_in` and `struct bt_port_out` types. An interesting consequence is that, as a component class developer, there are different methods for input and output ports, so that a fitler component class, for example, can have both an "input port connected" and an "output port connected". The `flt.utils.muxer` component class is an example which takes advantage of this, not having to check the port's type in its "input port connected" method now. * Functions to go from one type to another (private to public, self to public, input port to port, and so on) are now `static inline` to avoid any performance hit. Those functions are now universally named bt_X_borrow_Y(), where `X` is the API's prefix (for example, `private_component_class`) and `Y` is the transformed type name (for example, `component_class`). * The query executor API is split into private (create, query, cancel) and public (is canceled?) parts. A user's query method accepts a "self component class" of the appropriate type. * "Private connection private notification iterator" is removed in favor of "self component input port notification iterator": you need to call bt_self_component_port_input_notification_iterator_create() with a self component input port (which you can only borrow from your own self component). Because of this, `enum bt_connection_status` is removed because it's not needed anymore. * `enum bt_component_status` is removed because it's not needed anymore. Most statuses are moved to `enum bt_self_component_status` (what a component class method returns). * `bt_output_port_notification_iterator` is renamed to `bt_port_output_notification_iterator` to be consistent with `bt_self_component_port_input_notification_iterator`. * Graph and plugin API status values are standardized. * Precondition assertion macros are used to validate preconditions in developer mode across the whole graph and plugin APIs. Consequences: * bt_plugin_get_version() returns `enum bt_property_availability` instead of `enum bt_plugin_status`. * Functions which return a count return `uint64_t` instead of `int64_t`. * Status ending with `_INVALID` are removed (not needed anymore). * Types ending with `_UNKNOWN` are removed (not needed anymore). * All "getting" functions in the graph/plugin APIs are removed in favor of "borrowing" functions. Interesting changes needed to be made to bt_connection_end() and remove_port_by_index() to support this. * bt_plugin_find_component_class() is removed. Let's not encourage this because it creates a plugin object each time, whereas the recommended approach is to create a plugin first (with bt_plugin_find() for example), and then borrow the required component classes. * Graph API: when an object's member is destroyed, internally, its pointer is set to `NULL` immediately. This makes it possible to log partial objects during destruction while keeping Valgrind's memcheck happy. * Generic logging is replaced by library logging in the graph and plugin API implementations. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Add extras/gen-babeltrace-h.py: include/babeltrace/babeltrace.h generator This Python 3 script reads include/Makefile.am and prints the equivalent content of include/babeltrace/babeltrace.h. From the source tree's root, you can use it as such: $ python3 extras/gen-babeltrace-h.py > include/babeltrace/babeltrace.h Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>