diff --git a/include/plugins/slotproxy.h b/include/plugins/slotproxy.h index 82dd57d2a5..a156286295 100644 --- a/include/plugins/slotproxy.h +++ b/include/plugins/slotproxy.h @@ -40,7 +40,7 @@ class SlotProxy { Default default_process{}; using value_type = PluginProxy; - std::optional plugin_{ std::nullopt }; + std::vector plugins_; public: static constexpr plugins::v0::SlotID slot_id{ SlotID }; @@ -53,14 +53,15 @@ class SlotProxy SlotProxy() noexcept = default; /** - * @brief Constructs a SlotProxy object with a plugin. - * - * Constructs a SlotProxy object and initializes the plugin using the provided gRPC channel. - * + * @brief Adds a plugin to this proxy. + * @param name The fully-qualified name of the plugin + * @param version The full verison of the plugin * @param channel A shared pointer to the gRPC channel for communication with the plugin. */ - SlotProxy(const std::string& name, const std::string& version, std::shared_ptr channel) - : plugin_{ value_type{ name, version, channel } } {}; + void addPlugin(const std::string& name, const std::string& version, std::shared_ptr channel) + { + plugins_.emplace_back(name, version, channel); + } /** * @brief Executes the plugin operation. @@ -75,18 +76,25 @@ class SlotProxy */ constexpr auto generate(auto&&... args) { - if (plugin_.has_value()) + if (! plugins_.empty()) { - return plugin_.value().generate(std::forward(args)...); + return plugins_.front().generate(std::forward(args)...); } return std::invoke(default_process, std::forward(args)...); } constexpr auto modify(auto& original_value, auto&&... args) { - if (plugin_.has_value()) + if (! plugins_.empty()) { - return plugin_.value().modify(original_value, std::forward(args)...); + auto modified_value = original_value; + + for (value_type& plugin : plugins_) + { + modified_value = plugin.modify(modified_value, std::forward(args)...); + } + + return modified_value; } if constexpr (sizeof...(args) == 0) { @@ -98,9 +106,9 @@ class SlotProxy template void broadcast(auto&&... args) { - if (plugin_.has_value()) + for (value_type& plugin : plugins_) { - plugin_.value().template broadcast(std::forward(args)...); + plugin.template broadcast(std::forward(args)...); } } }; diff --git a/include/plugins/slots.h b/include/plugins/slots.h index 30740be3c4..515a1a41ab 100644 --- a/include/plugins/slots.h +++ b/include/plugins/slots.h @@ -160,8 +160,7 @@ class Registry, Unit> : public Registry { if (slot_id == T::slot_id) { - using Tp = typename Unit::value_type; - value_.proxy = Tp{ name, version, std::forward(channel) }; + value_.proxy.addPlugin(name, version, std::forward(channel)); return; } Base::connect(slot_id, name, version, std::forward(channel));