diff --git a/include/msg/detail/indexed_builder_common.hpp b/include/msg/detail/indexed_builder_common.hpp index ad876694..d26c3cc9 100644 --- a/include/msg/detail/indexed_builder_common.hpp +++ b/include/msg/detail/indexed_builder_common.hpp @@ -141,12 +141,12 @@ struct indexed_builder_base { ExtraCallbackArgsT...>{new_callbacks}; } - using callback_func_t = void (*)(BaseMsgT const &, - ExtraCallbackArgsT... args); + using callback_func_t = auto (*)(BaseMsgT const &, + ExtraCallbackArgsT... args) -> bool; template constexpr static auto invoke_callback(BaseMsgT const &data, - ExtraCallbackArgsT... args) { + ExtraCallbackArgsT... args) -> bool { // FIXME: incomplete message callback invocation... // 1) bit_cast message argument constexpr auto cb = IndexSpec{}.apply([&]( @@ -173,7 +173,9 @@ struct indexed_builder_base { stdx::ct_string_to_type(), orig_cb.matcher.describe(), cb.matcher.describe()); cb.callable(view, args...); + return true; } + return false; } template diff --git a/include/msg/detail/indexed_handler_common.hpp b/include/msg/detail/indexed_handler_common.hpp index 98cc4379..742daaa2 100644 --- a/include/msg/detail/indexed_handler_common.hpp +++ b/include/msg/detail/indexed_handler_common.hpp @@ -32,9 +32,6 @@ constexpr callback_args_t callback_args{}; template struct indexed_handler : handler_interface { - using callback_func_t = void (*)(BaseMsgT const &, - ExtraCallbackArgsT... args); - IndexT index; CallbacksT callback_entries; @@ -52,16 +49,14 @@ struct indexed_handler : handler_interface { ExtraCallbackArgsT... args) const -> bool final { auto const callback_candidates = index(msg); - for_each([&](auto i) { callback_entries[i](msg, args...); }, + bool handled{}; + for_each([&](auto i) { handled |= callback_entries[i](msg, args...); }, callback_candidates); - bool const candidates_found = !callback_candidates.none(); - - if (not candidates_found) { + if (not handled) { CIB_ERROR("None of the registered callbacks claimed this message."); } - - return candidates_found; + return handled; } }; diff --git a/test/msg/indexed_builder.cpp b/test/msg/indexed_builder.cpp index 6bd927f6..107b4854 100644 --- a/test/msg/indexed_builder.cpp +++ b/test/msg/indexed_builder.cpp @@ -68,8 +68,8 @@ TEST_CASE("match output success", "[handler_builder]") { cib::nexus test_nexus{}; test_nexus.init(); - cib::service->handle( - test_msg_t{"test_id_field"_field = 0x80}); + CHECK(cib::service->handle( + test_msg_t{"test_id_field"_field = 0x80})); CAPTURE(log_buffer); CHECK(log_buffer.find("Incoming message matched") != std::string::npos); CHECK(log_buffer.find("[TestCallback]") != std::string::npos); @@ -81,8 +81,8 @@ TEST_CASE("match output failure", "[handler_builder]") { cib::nexus test_nexus{}; test_nexus.init(); - cib::service->handle( - test_msg_t{"test_id_field"_field = 0x81}); + CHECK(not cib::service->handle( + test_msg_t{"test_id_field"_field = 0x81})); CHECK(log_buffer.find( "None of the registered callbacks claimed this message") != std::string::npos); @@ -189,8 +189,8 @@ TEST_CASE("message matching partial index but not callback matcher", log_buffer.clear(); callback_success = false; - cib::service->handle(test_msg_t{ - "test_id_field"_field = 0x80, "test_opcode_field"_field = 2}); + CHECK(not cib::service->handle(test_msg_t{ + "test_id_field"_field = 0x80, "test_opcode_field"_field = 2})); CHECK(not callback_success); } diff --git a/test/msg/indexed_handler.cpp b/test/msg/indexed_handler.cpp index fecc1ab7..f7efa39a 100644 --- a/test/msg/indexed_handler.cpp +++ b/test/msg/indexed_handler.cpp @@ -34,6 +34,8 @@ using msg_defn = message<"test_msg", opcode_field, sub_opcode_field, field_3, field_4>; using test_msg = owning; +using callback_t = auto (*)(test_msg const &) -> bool; + template using bitset = stdx::bitset; bitset<32> callbacks_called{}; @@ -45,7 +47,7 @@ TEST_CASE("create empty handler", "[indexed_handler]") { msg::indices{msg::index{ opcode_field{}, lookup::make(CX_VALUE( lookup::input>{}))}}, - std::array{}}; + std::array{}}; } TEST_CASE("create handler with one index and callback", "[indexed_handler]") { @@ -56,8 +58,10 @@ TEST_CASE("create handler with one index and callback", "[indexed_handler]") { lookup::make(CX_VALUE(lookup::input, 1>{ bitset<32>{}, std::array{lookup::entry{ 42u, bitset<32>{stdx::place_bits, 0}}}}))}}, - std::array{ - [](test_msg const &) { callbacks_called.set(0); }}}; + std::array{[](test_msg const &) { + callbacks_called.set(0); + return true; + }}}; callbacks_called.reset(); CHECK(h.handle(test_msg{"opcode_field"_field = 42})); @@ -97,16 +101,42 @@ TEST_CASE("create handler with multiple indices and callbacks", entry{2u, bitset<32>{stdx::place_bits, 2, 6, 8}}, entry{3u, bitset<32>{stdx::place_bits, 3, 7, 8}}, }}))}}, - std::array{ - [](test_msg const &) { callbacks_called.set(0); }, - [](test_msg const &) { callbacks_called.set(1); }, - [](test_msg const &) { callbacks_called.set(2); }, - [](test_msg const &) { callbacks_called.set(3); }, - [](test_msg const &) { callbacks_called.set(4); }, - [](test_msg const &) { callbacks_called.set(5); }, - [](test_msg const &) { callbacks_called.set(6); }, - [](test_msg const &) { callbacks_called.set(7); }, - [](test_msg const &) { callbacks_called.set(8); }}}; + std::array{[](test_msg const &) { + callbacks_called.set(0); + return true; + }, + [](test_msg const &) { + callbacks_called.set(1); + return true; + }, + [](test_msg const &) { + callbacks_called.set(2); + return true; + }, + [](test_msg const &) { + callbacks_called.set(3); + return true; + }, + [](test_msg const &) { + callbacks_called.set(4); + return true; + }, + [](test_msg const &) { + callbacks_called.set(5); + return true; + }, + [](test_msg const &) { + callbacks_called.set(6); + return true; + }, + [](test_msg const &) { + callbacks_called.set(7); + return true; + }, + [](test_msg const &) { + callbacks_called.set(8); + return true; + }}}; auto const check_msg = [&](std::uint32_t op, std::uint32_t sub_op, std::size_t callback_index) { @@ -151,8 +181,11 @@ TEST_CASE("create handler with extra callback arg", "[indexed_handler]") { lookup::make(CX_VALUE(lookup::input, 1>{ bitset<32>{}, std::array{lookup::entry{ 42u, bitset<32>{stdx::place_bits, 0}}}}))}}, - std::array{ - [](test_msg const &, std::size_t i) { callbacks_called.set(i); }}}; + std::arraybool, 1>{ + [](test_msg const &, std::size_t i) { + callbacks_called.set(i); + return true; + }}}; callbacks_called.reset(); CHECK(h.handle(test_msg{"opcode_field"_field = 42}, std::size_t{1}));