Skip to content

Commit cfc6543

Browse files
authored
Merge pull request #574 from mjcaisse-intel/msg-handler
msg::callback::handle args determined by caller
2 parents b6ebdcd + 176f329 commit cfc6543

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

include/msg/callback.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ namespace detail {
2020
* and handling incoming messages.
2121
*/
2222
template <stdx::ct_string Name, typename Msg, match::matcher M,
23-
stdx::callable F, typename... ExtraArgs>
23+
stdx::callable F>
2424
struct callback {
2525
[[nodiscard]] auto is_match(auto const &data) const -> bool {
2626
auto view = typename Msg::view_t{data};
2727
return matcher(view);
2828
}
2929

30+
template <typename... Args>
3031
[[nodiscard]] auto handle(auto const &data,
31-
ExtraArgs const &...args) const -> bool {
32+
Args const &...args) const -> bool {
3233
auto view = typename Msg::view_t{data};
3334
if (matcher(view)) {
3435
CIB_INFO("Incoming message matched [{}], because [{}], executing "
@@ -54,22 +55,21 @@ struct callback {
5455
using callable_t = F;
5556

5657
template <match::matcher NewM>
57-
using rebind_matcher = callback<Name, Msg, NewM, F, ExtraArgs...>;
58+
using rebind_matcher = callback<Name, Msg, NewM, F>;
5859

5960
constexpr static auto name = Name;
6061
[[no_unique_address]] matcher_t matcher;
6162
[[no_unique_address]] callable_t callable;
6263
};
6364

64-
template <stdx::ct_string Name, typename Msg, typename... ExtraArgs>
65-
struct callback_construct_t {
65+
template <stdx::ct_string Name, typename Msg> struct callback_construct_t {
6666
template <match::matcher M, stdx::callable F>
6767
[[nodiscard]] constexpr auto operator()(M, F &&f) const {
6868
using ::operator and;
6969
using matcher_t =
7070
decltype(match::sum_of_products(M{} and typename Msg::matcher_t{}));
71-
return callback<Name, Msg, matcher_t, std::remove_cvref_t<F>,
72-
ExtraArgs...>{matcher_t{}, std::forward<F>(f)};
71+
return callback<Name, Msg, matcher_t, std::remove_cvref_t<F>>{
72+
matcher_t{}, std::forward<F>(f)};
7373
}
7474

7575
template <msg::matcher_maker M, stdx::callable F>
@@ -86,7 +86,6 @@ struct callback_construct_t {
8686
};
8787
} // namespace detail
8888

89-
template <stdx::ct_string Name, typename Msg, typename... ExtraArgs>
90-
constexpr inline auto callback =
91-
detail::callback_construct_t<Name, Msg, ExtraArgs...>{};
89+
template <stdx::ct_string Name, typename Msg>
90+
constexpr inline auto callback = detail::callback_construct_t<Name, Msg>{};
9291
} // namespace msg

test/msg/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ TEST_CASE("match and dispatch only one callback with uint8_t storage",
135135
}
136136

137137
TEST_CASE("dispatch with extra args", "[handler]") {
138-
auto callback = msg::callback<"cb", msg_defn, int>(
138+
auto callback = msg::callback<"cb", msg_defn>(
139139
id_match<0x80>, [](msg::const_view<msg_defn>, int value) {
140140
dispatched = true;
141141
CHECK(value == 0xcafe);

test/msg/handler_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace {
8484
int callback_extra_arg{};
8585

8686
constexpr auto test_callback_extra_args =
87-
msg::callback<"cb", msg_defn, int>(id_match, [](msg_view_t, int i) {
87+
msg::callback<"cb", msg_defn>(id_match, [](msg_view_t, int i) {
8888
callback_success = true;
8989
callback_extra_arg = i;
9090
});

test/msg/indexed_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ namespace {
369369
int callback_extra_arg{};
370370

371371
constexpr auto test_callback_extra_args =
372-
msg::callback<"test_callback_extra_args", msg_defn, int>(
372+
msg::callback<"test_callback_extra_args", msg_defn>(
373373
msg::equal_to<test_id_field, 0x80>, [](auto, int i) {
374374
callback_success = true;
375375
callback_extra_arg = i;

0 commit comments

Comments
 (0)