Make `CompClsBridge::init` pass the initialization method data (received
from the lib as a `void *`) down to the user component's constructor.
For convenience, user component classes can specify the type of the data
they expect to receive as a template parameter, sparing them of doing a
static_cast. This template parameter can be omitted, in which case it
defaults to `void`.
Change-Id: I6b64ea6d75d535d7f2f3b8d559bd2698c186f0ca
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11787
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
static bt_component_class_initialize_method_status init(const _LibSelfCompPtr libSelfCompPtr,
typename LibTypesT::SelfCompCfg *,
const bt_value * const libParamsPtr,
static bt_component_class_initialize_method_status init(const _LibSelfCompPtr libSelfCompPtr,
typename LibTypesT::SelfCompCfg *,
const bt_value * const libParamsPtr,
+ void * const initData) noexcept
{
const auto selfComp = wrap(libSelfCompPtr);
try {
{
const auto selfComp = wrap(libSelfCompPtr);
try {
- const auto comp = new UserCompClsT {selfComp, wrap(libParamsPtr).asMap()};
+ const auto comp =
+ new UserCompClsT {selfComp, wrap(libParamsPtr).asMap(),
+ static_cast<typename UserCompClsT::InitData *>(initData)};
selfComp.data(*comp);
} catch (const std::bad_alloc&) {
selfComp.data(*comp);
} catch (const std::bad_alloc&) {
* See the specific `bt2::UserSourceComponent`,
* `bt2::UserFilterComponent`, and `bt2::UserSinkComponent`.
*/
* See the specific `bt2::UserSourceComponent`,
* `bt2::UserFilterComponent`, and `bt2::UserSinkComponent`.
*/
-template <typename SelfCompT>
+template <typename SelfCompT, typename InitDataT>
class UserComponent
{
/* Give a related message iterator access to this logger */
template <typename, typename>
friend class UserMessageIterator;
class UserComponent
{
/* Give a related message iterator access to this logger */
template <typename, typename>
friend class UserMessageIterator;
+public:
+ using InitData = InitDataT;
+
protected:
explicit UserComponent(const SelfCompT selfComp, const std::string& logTag) :
_mLogger {selfComp, fmt::format("{}/[{}]", logTag, selfComp.name())}, _mSelfComp {selfComp}
protected:
explicit UserComponent(const SelfCompT selfComp, const std::string& logTag) :
_mLogger {selfComp, fmt::format("{}/[{}]", logTag, selfComp.name())}, _mSelfComp {selfComp}
/*
* Base class of a user source component `UserComponentT` (CRTP).
*
/*
* Base class of a user source component `UserComponentT` (CRTP).
*
- * `UserComponentT::UserComponentT()` must accept a
- * `bt2::SelfSourceComponent` parameter, which it needs to forward to
- * bt2::UserSourceComponent::UserSourceComponent(), and a
- * `bt2::ConstValue` parameter (initialization parameters).
+ * UserComponentT::UserComponentT() must accept, in this order:
+ *
+ * 1. A `bt2::SelfSourceComponent` parameter, which it needs to forward
+ * to bt2::UserSourceComponent::UserSourceComponent().
+ *
+ * 2. A `bt2::ConstValue` parameter (the initialization parameters).
+ *
+ * 3. An `InitDataT *` parameter (the initialization method data).
*
* `UserMessageIteratorT`, the message iterator class to use, must inherit
* `UserMessageIterator`.
*/
*
* `UserMessageIteratorT`, the message iterator class to use, must inherit
* `UserMessageIterator`.
*/
-template <typename UserComponentT, typename UserMessageIteratorT>
-class UserSourceComponent : public UserComponent<SelfSourceComponent>
+template <typename UserComponentT, typename UserMessageIteratorT, typename InitDataT = void>
+class UserSourceComponent : public UserComponent<SelfSourceComponent, InitDataT>
{
static_assert(std::is_base_of<UserMessageIterator<UserMessageIteratorT, UserComponentT>,
UserMessageIteratorT>::value,
{
static_assert(std::is_base_of<UserMessageIterator<UserMessageIteratorT, UserComponentT>,
UserMessageIteratorT>::value,
using _OutputPorts = SelfSourceComponent::OutputPorts;
explicit UserSourceComponent(const SelfSourceComponent selfComp, const std::string& logTag) :
using _OutputPorts = SelfSourceComponent::OutputPorts;
explicit UserSourceComponent(const SelfSourceComponent selfComp, const std::string& logTag) :
- UserComponent<SelfSourceComponent> {selfComp, logTag}
+ UserComponent<SelfSourceComponent, InitDataT> {selfComp, logTag}
/*
* Base class of a user filter component `UserComponentT` (CRTP).
*
/*
* Base class of a user filter component `UserComponentT` (CRTP).
*
- * `UserComponentT::UserComponentT()` must accept a
- * `bt2::SelfFilterComponent` parameter, which it needs to forward to
- * bt2::UserFilterComponent::UserFilterComponent(), and a
- * `bt2::ConstValue` parameter (initialization parameters).
+ * UserComponentT::UserComponentT() must accept, in this order:
+ *
+ * 1. A `bt2::SelfFilterComponent` parameter, which it needs to forward
+ * to bt2::UserFilterComponent::UserFilterComponent().
+ *
+ * 2. A `bt2::ConstValue` parameter (the initialization parameters).
+ *
+ * 3. An `InitDataT *` parameter (the initialization method data).
*
* `UserMessageIteratorT`, the message iterator class to use, must inherit
* `UserMessageIterator`.
*/
*
* `UserMessageIteratorT`, the message iterator class to use, must inherit
* `UserMessageIterator`.
*/
-template <typename UserComponentT, typename UserMessageIteratorT>
-class UserFilterComponent : public UserComponent<SelfFilterComponent>
+template <typename UserComponentT, typename UserMessageIteratorT, typename InitDataT = void>
+class UserFilterComponent : public UserComponent<SelfFilterComponent, InitDataT>
{
static_assert(std::is_base_of<UserMessageIterator<UserMessageIteratorT, UserComponentT>,
UserMessageIteratorT>::value,
{
static_assert(std::is_base_of<UserMessageIterator<UserMessageIteratorT, UserComponentT>,
UserMessageIteratorT>::value,
using _OutputPorts = SelfFilterComponent::OutputPorts;
explicit UserFilterComponent(const SelfFilterComponent selfComp, const std::string& logTag) :
using _OutputPorts = SelfFilterComponent::OutputPorts;
explicit UserFilterComponent(const SelfFilterComponent selfComp, const std::string& logTag) :
- UserComponent<SelfFilterComponent> {selfComp, logTag}
+ UserComponent<SelfFilterComponent, InitDataT> {selfComp, logTag}
/*
* Base class of a user sink component `UserComponentT` (CRTP).
*
/*
* Base class of a user sink component `UserComponentT` (CRTP).
*
- * `UserComponentT::UserComponentT()` must accept a
- * `bt2::SelfSinkComponent` parameter, which it needs to forward to
- * bt2::UserSinkComponent::UserSinkComponent(), and a `bt2::ConstValue`
- * parameter (initialization parameters).
+ * UserComponentT::UserComponentT() must accept, in this order:
+ *
+ * 1. A `bt2::SelfSinkComponent` parameter, which it needs to forward
+ * to bt2::UserSinkComponent::UserSinkComponent().
+ *
+ * 2. A `bt2::ConstValue` parameter (the initialization parameters).
+ *
+ * 3. An `InitDataT *` parameter (the initialization method data).
*
* `UserComponentT` must implement:
*
*
* `UserComponentT` must implement:
*
* This method returns `true` if the sink component still needs to
* consume, or `false` if it's finished.
*/
* This method returns `true` if the sink component still needs to
* consume, or `false` if it's finished.
*/
-template <typename UserComponentT>
-class UserSinkComponent : public UserComponent<SelfSinkComponent>
+template <typename UserComponentT, typename InitDataT = void>
+class UserSinkComponent : public UserComponent<SelfSinkComponent, InitDataT>
{
protected:
using _InputPorts = SelfSinkComponent::InputPorts;
explicit UserSinkComponent(const SelfSinkComponent selfComp, const std::string& logTag) :
{
protected:
using _InputPorts = SelfSinkComponent::InputPorts;
explicit UserSinkComponent(const SelfSinkComponent selfComp, const std::string& logTag) :
- UserComponent<SelfSinkComponent> {selfComp, logTag}
+ UserComponent<SelfSinkComponent, InitDataT> {selfComp, logTag}
-Comp::Comp(const bt2::SelfFilterComponent selfComp, const bt2::ConstMapValue params) :
+Comp::Comp(const bt2::SelfFilterComponent selfComp, const bt2::ConstMapValue params, void *) :
bt2::UserFilterComponent<Comp, MsgIter> {selfComp, "PLUGIN/FLT.UTILS.MUXER"}
{
BT_CPPLOGI_STR("Initializing component.");
bt2::UserFilterComponent<Comp, MsgIter> {selfComp, "PLUGIN/FLT.UTILS.MUXER"}
{
BT_CPPLOGI_STR("Initializing component.");
friend bt2::UserFilterComponent<Comp, MsgIter>;
public:
friend bt2::UserFilterComponent<Comp, MsgIter>;
public:
- explicit Comp(bt2::SelfFilterComponent selfComp, bt2::ConstMapValue params);
+ explicit Comp(bt2::SelfFilterComponent selfComp, bt2::ConstMapValue params, void *);
private:
void _inputPortConnected(bt2::SelfComponentInputPort selfPort, bt2::ConstOutputPort otherPort);
private:
void _inputPortConnected(bt2::SelfComponentInputPort selfPort, bt2::ConstOutputPort otherPort);