diff --git a/include/plugins/converters.h b/include/plugins/converters.h index de947a850c..092cdc7260 100644 --- a/include/plugins/converters.h +++ b/include/plugins/converters.h @@ -126,7 +126,7 @@ struct gcode_paths_modify_response : public details::convertermodifyCall(grpc_context, status, ret_value, original_value, std::forward(args)...); + return this->modifyCall(grpc_context, status, value, std::forward(args)...); }, boost::asio::detached); grpc_context.run(); @@ -228,7 +227,6 @@ class PluginProxy spdlog::error("Plugin for slot {} failed with error: {}", slot_info_.slot_id, status.error_message()); throw exceptions::RemoteException(slot_info_, status.error_message()); } - return ret_value; } template @@ -305,19 +303,19 @@ class PluginProxy co_return; } - boost::asio::awaitable modifyCall(agrpc::GrpcContext& grpc_context, grpc::Status& status, value_type& ret_value, auto& original_value, auto&&... args) + boost::asio::awaitable modifyCall(agrpc::GrpcContext& grpc_context, grpc::Status& status, value_type& value, auto&&... args) { using RPC = agrpc::ClientRPC<&invoke_stub_t::PrepareAsyncCall>; grpc::ClientContext client_context{}; prep_client_context(client_context, slot_info_); // Construct request - auto request{ req_(original_value, std::forward(args)...) }; + auto request{ req_(value, std::forward(args)...) }; // Make unary request rsp_msg_type response; status = co_await RPC::request(grpc_context, invoke_stub_, client_context, request, response, boost::asio::use_awaitable); - ret_value = std::move(rsp_(original_value, response)); + rsp_(value, response); co_return; } diff --git a/include/plugins/slotproxy.h b/include/plugins/slotproxy.h index a156286295..613615caaa 100644 --- a/include/plugins/slotproxy.h +++ b/include/plugins/slotproxy.h @@ -83,24 +83,21 @@ class SlotProxy return std::invoke(default_process, std::forward(args)...); } - constexpr auto modify(auto& original_value, auto&&... args) + constexpr auto modify(auto& value, auto&&... args) { if (! plugins_.empty()) { - auto modified_value = original_value; - for (value_type& plugin : plugins_) { - modified_value = plugin.modify(modified_value, std::forward(args)...); + plugin.modify(value, std::forward(args)...); } - - return modified_value; + return; } if constexpr (sizeof...(args) == 0) { - return std::invoke(default_process, original_value); + return std::invoke(default_process, value); } - return std::invoke(default_process, original_value, std::forward(args)...); + return std::invoke(default_process, value, std::forward(args)...); } template diff --git a/include/plugins/slots.h b/include/plugins/slots.h index 515a1a41ab..96275a06a0 100644 --- a/include/plugins/slots.h +++ b/include/plugins/slots.h @@ -35,6 +35,14 @@ struct default_process }; }; +struct modify_default +{ + constexpr void operator()(auto&& arg, auto&&...) + { + return; // Do nothing, but add some code for clangd-format not to mess up the syntax + }; +}; + struct simplify_default { auto operator()(auto&& arg, auto&&... args) @@ -218,9 +226,9 @@ struct Holder } // namespace details -using slot_gcode_paths_modify = details::slot_gcode_paths_modify_<>; +using slot_gcode_paths_modify = details::slot_gcode_paths_modify_; using slot_infill_generate = details::slot_infill_generate_; -using slot_postprocess = details::slot_postprocess_<>; +using slot_postprocess = details::slot_postprocess_; using slot_settings_broadcast = details::slot_settings_broadcast_<>; using slot_simplify = details::slot_simplify_; diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index a72c5b6110..5c80f4da7c 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -2586,7 +2586,7 @@ void LayerPlan::applyModifyPlugin() scripta::CellVDI{ "is_travel_path", &GCodePath::isTravelPath }, scripta::CellVDI{ "extrusion_mm3_per_mm", &GCodePath::getExtrusionMM3perMM }); - extruder_plan.paths_ = slots::instance().modify(extruder_plan.paths_, extruder_plan.extruder_nr_, layer_nr_); + slots::instance().modify(extruder_plan.paths_, extruder_plan.extruder_nr_, layer_nr_); scripta::log( "extruder_plan_1", diff --git a/src/communication/ArcusCommunication.cpp b/src/communication/ArcusCommunication.cpp index 0f0fd4e6d3..5480d95a37 100644 --- a/src/communication/ArcusCommunication.cpp +++ b/src/communication/ArcusCommunication.cpp @@ -356,13 +356,13 @@ void ArcusCommunication::beginGCode() void ArcusCommunication::flushGCode() { std::string gcode_output_stream = private_data->gcode_output_stream.str(); - auto message_str = slots::instance().modify(gcode_output_stream); - if (message_str.size() == 0) + slots::instance().modify(gcode_output_stream); + if (gcode_output_stream.size() == 0) { return; } std::shared_ptr message = std::make_shared(); - message->set_data(message_str); + message->set_data(gcode_output_stream); // Send the g-code to the front-end! Yay! private_data->socket->sendMessage(message); @@ -390,7 +390,8 @@ void ArcusCommunication::sendGCodePrefix(const std::string& prefix) const { std::shared_ptr message = std::make_shared(); std::string message_str = prefix; - message->set_data(slots::instance().modify(message_str)); + slots::instance().modify(message_str); + message->set_data(message_str); private_data->socket->sendMessage(message); } diff --git a/src/plugins/converters.cpp b/src/plugins/converters.cpp index 964a50007d..f66fd262cc 100644 --- a/src/plugins/converters.cpp +++ b/src/plugins/converters.cpp @@ -434,12 +434,10 @@ gcode_paths_modify_request::value_type .fan_speed = path.fan_speed() }; } -gcode_paths_modify_response::native_value_type - gcode_paths_modify_response::operator()(gcode_paths_modify_response::native_value_type& original_value, const gcode_paths_modify_response::value_type& message) const +void gcode_paths_modify_response::operator()(gcode_paths_modify_response::native_value_type& value, const gcode_paths_modify_response::value_type& message) const { - std::vector paths; using map_t = std::unordered_map>; - auto meshes = original_value + auto meshes = value | ranges::views::filter( [](const auto& path) { @@ -452,6 +450,9 @@ gcode_paths_modify_response::native_value_type }) | ranges::to; + value.clear(); + value.reserve(message.gcode_paths().size()); + for (const auto& gcode_path_msg : message.gcode_paths()) { GCodePath path{ @@ -482,10 +483,8 @@ gcode_paths_modify_response::native_value_type }) | ranges::to_vector; - paths.emplace_back(path); + value.push_back(path); } - - return paths; } } // namespace cura::plugins