Reduce the number of Makefiles in 'src/' Continue the effort started by Simon to reduce the overall number of Makefiles to allow for faster parallel builds. Change-Id: I3d87dea9979c09d1a6416c7b9950264a8c4d81dc Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/11155 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
cpp-common: add FileUP Add a unique_ptr type to manage the lifetime of a `FILE *`, with a custom deleter that calls fclose. Change-Id: Idded4546d2a709cd0652975ef83c3ad6a0f511bc Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/8172 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10843 Tested-by: jenkins <jenkins@lttng.org> CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
cpp-common: add GCharUP Add GCharUP, a unique_ptr type that wraps a g_char pointer and has a deleter that calls g_free. It can be used to provide automatic memory management of buffers returned by the GLib API. Change-Id: I9d98be2f972cc008877b55a20eceeb3dce256cdb Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/8170 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10842 Tested-by: jenkins <jenkins@lttng.org> CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common: add fixed-length integer reading functions This patch adds `src/cpp-common/read-fixed-len-int.hpp` which offers function templates to read fixed-length integers from a buffer. The bt2_common::readFixedLenIntLe() (little endian) and bt2_common::readFixedLenIntBe() (big endian) function templates accept one template parameter which is the integral type of the integer to read (and the return type of the function). For example, bt2_common::readFixedLenIntLe<std::int32_t>() reads a 32-bit signed little-endian integer and returns it. The function templates use bt2_common::littleEndianToNative() and bt2_common::bigEndianToNative() as needed. You may combine this with `bt2_common::StdIntT` to have the length in bits and the signedness as independent template parameters, for example: const auto val = readFixedLenIntBe<StdIntT<16, true>>(myBuf); which is equivalent to: const auto val = readFixedLenIntBe<std::int16_t>(myBuf); Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I9c684bede60f7b6324a3140c5fd498c21ad513ab Reviewed-on: https://review.lttng.org/c/babeltrace/+/7939 Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10840 Tested-by: jenkins <jenkins@lttng.org>
Add `src/cpp-common/std-int.hpp` This new header contains the `StdIntT` trait structure to get the standard integer type from a length (bits) and a signedness. For example, `bt2_common::StdIntT<32, true>::Type` is `std::int32_t`. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I69fc9ac7e01c2a82e4ad13afa553ef8e8720bd57 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8086 Reviewed-on: https://review.lttng.org/c/babeltrace/+/10839 Tested-by: jenkins <jenkins@lttng.org>
cpp-common: add bt2_common::messageTypeStr() Change-Id: I6967d232922c7b5ad6b35cc100becb9ff8a6b968 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8651 CI-Build: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10838 Tested-by: jenkins <jenkins@lttng.org> CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
cpp-common: add vectorFastRemove Add the vectorFastRemove function, in src/cpp-common/vector.hpp, as a drop-in replacement for g_ptr_array_remove_index_fast, when replacing a GPtrArray with an std::vector. Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ibee249fd9a8168d02ad99abf36984bf7edd53b5b Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/8493 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10837 CI-Build: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common: improve C++ UUID utilities Philippe Proulx writing below. This patch improves the C++ common UUID utilities. Francis wrote the initial version of `bt2_common::Uuid`, and then we worked together to improve many little things at once, leading to this patch. His original message was: > Add `bt2_common::Uuid` > > This patch adds the `bt2_common::Uuid` class which represent UUIDs. > > `Uuid` instances can be created from byte array, strings, or > bt2_common::UuidView objects. > > The generate() static method returns a Uuid object with newly > generated UUID. > > The operator UuidView() method returns a bt2_common::UuidView object > representing the entire content of the UUID. > > The data() method returns a const pointer to the underlying > std::array<>. > > The str() method returns a new `std::string` instance containing the > canonical string representation of the UUID. The final improvements are: * Add said `bt2_common::Uuid` class. I also added the operator[](), operator=(), isNil(), begin(), and end() methods, the `Val` and `ConstIter` aliases, and the fact that most of the class relies on creating a `bt2_common::UuidView` to wrap itself when needed. data() just returns `const Val *`. * In `bt2_common::UuidView`: * Make the class `final`. * Add the `Val` and `ConstIter` aliases. * Add operator<(): makes it possible to use a `bt2_common::UuidView` as an `std::set` value type or as an `std::map` key type, and to use it with STL algorithms. * Make size() `constexpr`. * Rename string() to str() for consistency with internal C++ naming. * Add begin() and end(). * Add operator=() which accepts a UUID pointer. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Id049953aecc51562e5939db546cb7d82bbaf88eb Reviewed-on: https://review.lttng.org/c/babeltrace/+/10822 Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common: add bt2_common::align() This is a templated C++ version of the BT_ALIGN() macro found in `src/common/align.h`. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I0062778831d20cf19fe28bfa82c867473f7cf50b Reviewed-on: https://review.lttng.org/c/babeltrace/+/7928 Tested-by: jenkins <jenkins@lttng.org> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10817
src/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*() This patch adds the following function templates, under the `bt2_common` namespace, within the new `src/cpp-common/safe-ops.hpp` header: safeToMul(): Returns whether or not you can safely multiply two numbers without causing an overflow. safeToAdd(): Returns whether or not you can safely add two numbers without causing an overflow. safeToSub(): Returns whether or not you can safely subtract two numbers without causing an underflow. safeMul(): Multiplies some number by another, asserting that it's safe to do so, and returns the result. safeAdd(): Adds some number and another, asserting that it's safe to do so, and returns the result. safeSub(): Subtract some number from another, asserting that it's safe to do so, and returns the result. Those are similar to the existing bt_safe_*() C functions, except that: * They're function templates, so you can use any numeric type. * The safeTo*() function templates are `constexpr`. * They only work with unsigned types; signed types introduce some complexity (negative values) which I don't need to deal with right now. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I29ed4b51d50ae2507f5580db20452ec6c188ef66 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7916 Reviewed-on: https://review.lttng.org/c/babeltrace/+/10816 Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common: add bt2_common::makeUnique() This is our equivalent of std::make_unique() (introduced in C++14) for C++11. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Ic58341f7419ac447f83401358ca0884151246dc8 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7465 Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10815 Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common: add bt2_common::{little,big}ToNative() Those are C++ versions (using overloads) of the {le,be}{16,32,64}toh() functions found in `src/compat/endian.h`. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Iab826bb633388d5ce506b4462b7a0417c2c05ad4 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7927 Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10814 Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/Makefile.am: add missing `uuid-view.hpp` Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Idca1204fc2e53cf42633a3dd977f6883a6d55348 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7407 Reviewed-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10812 Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros This patch adds the following files: `src/cpp-common/cfg-logging.hpp`: Offers the following macros: BT_CLOG*_EX(): Logs using a given logging configuration reference. BT_CLOG*_STR_EX(): Logs a literal string using a given logging configuration reference. BT_CLOG*_ERRNO_EX(): Logs an errno message using a given logging configuration reference. BT_CLOG*_MEM_EX(): Logs memory bytes using a given logging configuration reference. All the macros above also have their variant without the `_EX` suffix which uses the logging configuration reference `BT_CLOG_CFG`. Those macros decide, depending on what's available within the provided logging configuration object, how to prefix the complete log message. `src/cpp-common/cfg-error-reporting.hpp`: Offers the following macros: BT_APPEND_CAUSE_EX(): BT_APPEND_CAUSE_STR_EX(): BT_APPEND_CAUSE_ERRNO_EX(): Appends a cause to the error of the current thread using a given logging configuration reference. All the macros above also have their variant without the `_EX` suffix which uses the logging configuration reference `BT_CLOG_CFG`. Those macros decide, depending on what's available within the provided logging configuration object, which BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use. `src/cpp-common/cfg-error-reporting-throw.hpp`: Offers the following macros: BT_APPEND_CAUSE_AND_THROW_EX(): Appends a cause to the error of the current thread using a given logging configuration reference, and throws an exception. BT_APPEND_CAUSE_AND_RETHROW_EX(): Appends a cause to the error of the current thread using a given logging configuration reference, and rethrows. BT_STR_APPEND_CAUSE_AND_THROW_EX(): Appends a cause to the error of the current thread using a given logging configuration reference, and throws an exception. BT_STR_APPEND_CAUSE_AND_RETHROW_EX(): Appends a cause to the error of the current thread using a given logging configuration reference, and rethrows. BT_ERRNO_APPEND_CAUSE_AND_THROW_EX(): Appends a cause with an errno message to the error of the current thread using a given logging configuration reference, and throws an exception. BT_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(): Appends a cause with an errno message to the error of the current thread using a given logging configuration reference, and rethrows. All the macros above also have their variant without the `_EX` suffix which uses the logging configuration reference `BT_CLOG_CFG`. `src/cpp-common/cfg-logging-error-reporting.hpp`: Offers the following macros: BT_CLOGE_APPEND_CAUSE_EX(): Logs using a given logging configuration reference and appends a cause to the error of the current thread. BT_CLOGE_STR_APPEND_CAUSE_EX(): Logs a literal string using a given logging configuration reference and appends a cause to the error of the current thread. BT_CLOGE_ERRNO_APPEND_CAUSE_EX(): Logs an errno message using a given logging configuration reference and appends a cause to the error of the current thread. BT_CLOGE_MEM_APPEND_CAUSE_EX(): Logs memory bytes using a given logging configuration reference and appends a cause to the error of the current thread. All the macros above also have their variant without the `_EX` suffix which uses the logging configuration reference `BT_CLOG_CFG`. Those macros decide, depending on what's available within the provided logging configuration object, which BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use. `src/cpp-common/cfg-logging-error-reporting-throw.hpp`: Offers the following macros: BT_CLOGE_APPEND_CAUSE_AND_THROW_EX(): Logs using a given logging configuration reference, appends a cause to the error of the current thread, and throws an exception. BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX(): Logs using a given logging configuration reference, appends a cause to the error of the current thread, and rethrows. BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX(): Logs a literal string using a given logging configuration reference, appends a cause to the error of the current thread, and throws an exception. BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX(): Logs a literal string using a given logging configuration reference, appends a cause to the error of the current thread, and rethrows. BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX(): Logs an errno message using a given logging configuration reference, appends a cause to the error of the current thread, and throws an exception. BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX(): Logs an errno message using a given logging configuration reference, appends a cause to the error of the current thread, and rethrows. BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX(): Logs memory bytes using a given logging configuration reference, appends a cause to the error of the current thread, and throws an exception. BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX(): Logs memory bytes using a given logging configuration reference, appends a cause to the error of the current thread, and rethrows. All the macros above also have their variant without the `_EX` suffix which uses the logging configuration reference `BT_CLOG_CFG`. The intended usage is as such: 1. In a header file defining a class, have a logging configuration member: bt2_common::LogCfg _mLogCfg; Make the constructor of the class accept a logging configuration reference and copy it to `_mLogCfg`. 2. In the source file which implements the methods of the class, at the top of the file, write: #define BT_LOG_TAG "MY/TAG" #define BT_CLOG_CFG _mLogCfg #include "cpp-common/cfg-logging-error-reporting-throw.hpp" 3. In any method of the class, when there's an error, call: BT_CLOGE_APPEND_CAUSE_AND_THROW(bt2_common::Error, "Cannot do this and that: code=%d", code); Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I3e689fe612b90be2f8f69288bc7947c727434d5a Reviewed-on: https://review.lttng.org/c/babeltrace/+/10810 Tested-by: jenkins <jenkins@lttng.org>
cpp-common: Add common exceptions Add `bt2_common::{End, Error, MemoryError, TryAgain}` exception classes to use in in-tree components and elsewhere. Each exception inherits a C++ standard exception that I believe matches more closely in meaning. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Change-Id: I7335465f2377e032ae9706108708e35d78d38e6e Reviewed-on: https://review.lttng.org/c/babeltrace/+/7918 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10809 Tested-by: jenkins <jenkins@lttng.org> CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common: add `LogCfg` class `LogCfg` is a class to carry around the logging information used by `BT_LOG*()` macros in the in-tree plugins. Philippe added: * Class comment. * Setting other members when possible (for example, `_mSelfComp` when using the self message iterator constructor). * Use references instead of pointers in constructors because they can't be `nullptr`, making it possible to remove some assertions. * Component class member (because the libbabeltrace2 API has nothing to get a self component class from a self component) and compClsName() method. compClsName() is always available when using the self message iterator, component, or component class constructor. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Ic6980a2bcf74f8b270b0a108efc79f25f0e65d8d Reviewed-on: https://review.lttng.org/c/babeltrace/+/7936 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10808 Tested-by: jenkins <jenkins@lttng.org>
cpp-common: add nlohmann/json header-only dependency This commit adds the C++ nlohmann JSON library which comes from the MIT-licensed <https://github.com/nlohmann/json/> project [1]. Babeltrace 2 will be using this library to encode JSON strings during the generation of CTF 2 traces. In any Babeltrace 2 C++ file, include it like this: #include "cpp-common/nlohmann/json.hpp" [1] https://raw.githubusercontent.com/nlohmann/json/a0c1318830519eac027a31edec1a99ce1ae5670e/single_include/nlohmann/json.hpp Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Change-Id: I139ea0c0763a129a8d4db351f8ece2edb1c112dd Reviewed-on: https://review.lttng.org/c/babeltrace/+/7321 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/7138 Tested-by: jenkins <jenkins@lttng.org>
Add `std::string_view` replacement (`bpstd::string_view`) This patch adds an `std::string_view` replacement, `bpstd::string_view`, which comes from the MIT-licensed <https://github.com/bitwizeshift/string_view-standalone> project. Babeltrace 2 cannot use `std::string_view` as it's part of C++17, whereas the project only requires C++11. `bpstd::basic_string_view` and `bpstd::string_view` are meant to work like C++17's `std::basic_string_view` and `std::string_view`. In any Babeltrace 2 C++ file, include it like this: #include "cpp-common/string_view.hpp" Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Icd9329fb55959de92832f4715b02359e1ef44184 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4519
Add `std::optional` replacement (`nonstd::optional`) This patch adds an `std::optional` replacement, `nonstd::optional`, which comes from the Boost-licensed <https://github.com/martinmoene/optional-lite> project. Babeltrace 2 cannot use `std::optional` as it's part of C++17, whereas the project only requires C++11. `nonstd::optional` is meant to work like C++17's `std::optional`. In any Babeltrace 2 C++ file, include it like this: #include "cpp-common/optional.hpp" Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: Icda5af4bd5affd1237786bdb9cb2e64861643440 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4517
Add libbabeltrace2 C++ interface base This patch adds three new C++ headers to `src/cpp-common/bt2/internal`: `borrowed-obj.hpp`: Defines `bt2::internal::BorrowedObj` which wraps a libbabeltrace2 object pointer without managing reference counting. `shared-obj.hpp`: Defines `bt2::internal::SharedObj` which contains a `bt2::internal::BorrowedObj` instance and manages the underlying reference count of the libbabeltrace2 object. Those classes are meant to be used by public classes in `src/cpp-common/bt2`, hence their `internal` namespace. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I1433ef3c1ed9cca5677012ebe68f63545dbbe547 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4505