From 06bb401ef3396a35fe5f43cf44217ed078b862c8 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 13 Feb 2024 11:50:10 -0500 Subject: [PATCH] src/cpp-common: pass user message iterator class to `UserSourceComponent` and `UserFilterComponent` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 🍎 Pass the user message iterator class type as template parameters to `UserSourceComponent` and `UserFilterComponent`. 🍎 Make them set a public type `MessageIterator` with that. 🍎 Update the `BT_CPP_PLUGIN_*` macros to not take the message iterator class type, but use `_userComponentClass::MessageIterator` instead. Change-Id: I7af3a1a088a61e5b83e4a4047f808435221352cc Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11800 Reviewed-by: Philippe Proulx Tested-by: jenkins --- src/cpp-common/bt2/plugin-dev.hpp | 74 +++++++++++++++++++------------ src/plugins/utils/muxer/comp.cpp | 2 +- src/plugins/utils/muxer/comp.hpp | 8 +++- src/plugins/utils/plugin.cpp | 2 +- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/cpp-common/bt2/plugin-dev.hpp b/src/cpp-common/bt2/plugin-dev.hpp index 3bc20e7f..2f255e42 100644 --- a/src/cpp-common/bt2/plugin-dev.hpp +++ b/src/cpp-common/bt2/plugin-dev.hpp @@ -505,10 +505,20 @@ private: * `bt2::SelfSourceComponent` parameter, which it needs to forward to * bt2::UserSourceComponent::UserSourceComponent(), and a * `bt2::ConstValue` parameter (initialization parameters). + * + * `UserMessageIteratorT`, the message iterator class to use, must inherit + * `UserMessageIterator`. */ -template +template class UserSourceComponent : public UserComponent { + static_assert(std::is_base_of, + UserMessageIteratorT>::value, + "`UserMessageIteratorT` inherits `UserMessageIterator`"); + +public: + using MessageIterator = UserMessageIteratorT; + protected: using _OutputPorts = SelfSourceComponent::OutputPorts; @@ -582,10 +592,20 @@ protected: * `bt2::SelfFilterComponent` parameter, which it needs to forward to * bt2::UserFilterComponent::UserFilterComponent(), and a * `bt2::ConstValue` parameter (initialization parameters). + * + * `UserMessageIteratorT`, the message iterator class to use, must inherit + * `UserMessageIterator`. */ -template +template class UserFilterComponent : public UserComponent { + static_assert(std::is_base_of, + UserMessageIteratorT>::value, + "`UserMessageIteratorT` inherits `UserMessageIterator`"); + +public: + using MessageIterator = UserMessageIteratorT; + protected: using _InputPorts = SelfFilterComponent::InputPorts; using _OutputPorts = SelfFilterComponent::OutputPorts; @@ -1006,11 +1026,11 @@ protected: } /* namespace bt2 */ -#define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID( \ - _pluginId, _componentClassId, _name, _userComponentClass, _userMessageIteratorClass) \ +#define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_pluginId, _componentClassId, _name, \ + _userComponentClass) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID( \ _pluginId, _componentClassId, _name, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::next); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::next); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, bt2::internal::SrcCompClsBridge<_userComponentClass>::init); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID( \ @@ -1027,24 +1047,25 @@ protected: bt2::internal::SrcCompClsBridge<_userComponentClass>::query); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::init); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::init); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::finalize); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::finalize); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHODS_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekBeginning, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekBeginning); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::seekBeginning, \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::canSeekBeginning); \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekNsFromOrigin, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekNsFromOrigin); + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::seekNsFromOrigin, \ + bt2::internal::MsgIterClsBridge< \ + _userComponentClass::MessageIterator>::canSeekNsFromOrigin); -#define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID( \ - _pluginId, _componentClassId, _name, _userComponentClass, _userMessageIteratorClass) \ +#define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_pluginId, _componentClassId, _name, \ + _userComponentClass) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID( \ _pluginId, _componentClassId, _name, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::next); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::next); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, bt2::internal::FltCompClsBridge<_userComponentClass>::init); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID( \ @@ -1064,18 +1085,19 @@ protected: bt2::internal::FltCompClsBridge<_userComponentClass>::query); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::init); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::init); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::finalize); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::finalize); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHODS_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekBeginning, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekBeginning); \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::seekBeginning, \ + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::canSeekBeginning); \ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID( \ _pluginId, _componentClassId, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekNsFromOrigin, \ - bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekNsFromOrigin); + bt2::internal::MsgIterClsBridge<_userComponentClass::MessageIterator>::seekNsFromOrigin, \ + bt2::internal::MsgIterClsBridge< \ + _userComponentClass::MessageIterator>::canSeekNsFromOrigin); #define BT_CPP_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(_pluginId, _componentClassId, _name, \ _userComponentClass) \ @@ -1101,15 +1123,11 @@ protected: _pluginId, _componentClassId, \ bt2::internal::SinkCompClsBridge<_userComponentClass>::query); -#define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _userComponentClass, \ - _userMessageIteratorClass) \ - BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass, \ - _userMessageIteratorClass) +#define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _userComponentClass) \ + BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass) -#define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS(_name, _userComponentClass, \ - _userMessageIteratorClass) \ - BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass, \ - _userMessageIteratorClass) +#define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS(_name, _userComponentClass) \ + BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass) #define BT_CPP_PLUGIN_SINK_COMPONENT_CLASS(_name, _userComponentClass) \ BT_CPP_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass) diff --git a/src/plugins/utils/muxer/comp.cpp b/src/plugins/utils/muxer/comp.cpp index d81a4c29..ba44729a 100644 --- a/src/plugins/utils/muxer/comp.cpp +++ b/src/plugins/utils/muxer/comp.cpp @@ -11,7 +11,7 @@ namespace bt2mux { Comp::Comp(const bt2::SelfFilterComponent selfComp, const bt2::ConstMapValue params) : - bt2::UserFilterComponent {selfComp, "PLUGIN/FLT.UTILS.MUXER"} + bt2::UserFilterComponent {selfComp, "PLUGIN/FLT.UTILS.MUXER"} { BT_CPPLOGI_STR("Initializing component."); diff --git a/src/plugins/utils/muxer/comp.hpp b/src/plugins/utils/muxer/comp.hpp index 2ce66a4c..4572d1d4 100644 --- a/src/plugins/utils/muxer/comp.hpp +++ b/src/plugins/utils/muxer/comp.hpp @@ -10,12 +10,16 @@ #include "cpp-common/bt2/plugin-dev.hpp" +#include "msg-iter.hpp" + namespace bt2mux { -class Comp final : public bt2::UserFilterComponent +class MsgIter; + +class Comp final : public bt2::UserFilterComponent { friend class MsgIter; - friend bt2::UserFilterComponent; + friend bt2::UserFilterComponent; public: explicit Comp(bt2::SelfFilterComponent selfComp, bt2::ConstMapValue params); diff --git a/src/plugins/utils/plugin.cpp b/src/plugins/utils/plugin.cpp index acb7801d..4878ab87 100644 --- a/src/plugins/utils/plugin.cpp +++ b/src/plugins/utils/plugin.cpp @@ -54,7 +54,7 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD(trimmer, trimmer_msg_iter_finalize); /* flt.utils.muxer */ -BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS(muxer, bt2mux::Comp, bt2mux::MsgIter); +BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS(muxer, bt2mux::Comp); BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION( muxer, "Sort messages from multiple input ports to a single output port by time."); BT_PLUGIN_FILTER_COMPONENT_CLASS_HELP(muxer, -- 2.34.1