|
| 1 | +// Generated by commsdsl2comms v7.1.0 |
| 2 | + |
| 3 | +/// @file |
| 4 | +/// @brief Contains dispatch to handling function(s) for client input input messages. |
| 5 | + |
| 6 | +#pragma once |
| 7 | + |
| 8 | +#include <cstdint> |
| 9 | +#include "tutorial26/input/ClientInputMessages.h" |
| 10 | +#include "tutorial26/options/DefaultOptions.h" |
| 11 | + |
| 12 | +namespace tutorial26 |
| 13 | +{ |
| 14 | + |
| 15 | +namespace dispatch |
| 16 | +{ |
| 17 | + |
| 18 | +/// @brief Dispatch message object to its appropriate handling function. |
| 19 | +/// @details @b switch statement based (on message ID) cast and dispatch functionality. |
| 20 | +/// @tparam TProtOptions Protocol options struct used for the application, |
| 21 | +/// like @ref tutorial26::options::DefaultOptions. |
| 22 | +/// @param[in] id Numeric message ID. |
| 23 | +/// @param[in] idx Index of the message among messages with the same ID. |
| 24 | +/// @param[in] msg Message object held by reference to its interface class. |
| 25 | +/// @param[in] handler Reference to handling object. Must define |
| 26 | +/// @b handle() member function for every message type it exects |
| 27 | +/// to handle and one for the interface class as well. |
| 28 | +/// @code |
| 29 | +/// using MyInterface = tutorial26::Message<...>; |
| 30 | +/// using MyMsg1 = tutorial26::message::Msg1<MyInterface, tutorial26::options::DefaultOptions>; |
| 31 | +/// using MyMsg2 = tutorial26::message::Msg2<MyInterface, tutorial26::options::DefaultOptions>; |
| 32 | +/// struct MyHandler { |
| 33 | +/// void handle(MyMsg1& msg) {...} |
| 34 | +/// void handle(MyMsg2& msg) {...} |
| 35 | +/// ... |
| 36 | +/// // Handle all unexpected or irrelevant messages. |
| 37 | +/// void handle(MyInterface& msg) {...} |
| 38 | +/// }; |
| 39 | +/// @endcode |
| 40 | +/// Every @b handle() function may return a value, but every |
| 41 | +/// function must return the @b same type. |
| 42 | +/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h |
| 43 | +template<typename TProtOptions, typename TId, typename TMsg, typename THandler> |
| 44 | +auto dispatchClientInputMessage( |
| 45 | + TId id, |
| 46 | + std::size_t idx, |
| 47 | + TMsg& msg, |
| 48 | + THandler& handler) -> decltype(handler.handle(msg)) |
| 49 | +{ |
| 50 | + using InterfaceType = typename std::decay<decltype(msg)>::type; |
| 51 | + switch(static_cast<std::intmax_t>(id)) { |
| 52 | + case 0 /* 0x0 */: |
| 53 | + { |
| 54 | + switch (idx) { |
| 55 | + case 0U: |
| 56 | + { |
| 57 | + using MsgType = tutorial26::message::Msg1<InterfaceType, TProtOptions>; |
| 58 | + return handler.handle(static_cast<MsgType&>(msg)); |
| 59 | + } |
| 60 | + case 1U: |
| 61 | + { |
| 62 | + using MsgType = tutorial26::message::Msg2<InterfaceType, TProtOptions>; |
| 63 | + return handler.handle(static_cast<MsgType&>(msg)); |
| 64 | + } |
| 65 | + case 2U: |
| 66 | + { |
| 67 | + using MsgType = tutorial26::message::Msg3<InterfaceType, TProtOptions>; |
| 68 | + return handler.handle(static_cast<MsgType&>(msg)); |
| 69 | + } |
| 70 | + default: |
| 71 | + return handler.handle(msg); |
| 72 | + }; |
| 73 | + break; |
| 74 | + } |
| 75 | + default: |
| 76 | + break; |
| 77 | + }; |
| 78 | + |
| 79 | + return handler.handle(msg); |
| 80 | +} |
| 81 | + |
| 82 | +/// @brief Dispatch message object to its appropriate handling function. |
| 83 | +/// @details Same as other dispatchClientInputMessage(), but without @b idx parameter. |
| 84 | +/// @tparam TProtOptions Protocol options struct used for the application, |
| 85 | +/// like @ref tutorial26::options::DefaultOptions. |
| 86 | +/// @param[in] id Numeric message ID. |
| 87 | +/// @param[in] msg Message object held by reference to its interface class. |
| 88 | +/// @param[in] handler Reference to handling object. |
| 89 | +/// @see dispatchClientInputMessage() |
| 90 | +/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h |
| 91 | +template<typename TProtOptions, typename TId, typename TMsg, typename THandler> |
| 92 | +auto dispatchClientInputMessage( |
| 93 | + TId id, |
| 94 | + TMsg& msg, |
| 95 | + THandler& handler) -> decltype(handler.handle(msg)) |
| 96 | +{ |
| 97 | + return dispatchClientInputMessage<TProtOptions>(id, 0U, msg, handler); |
| 98 | +} |
| 99 | + |
| 100 | +/// @brief Dispatch message object to its appropriate handling function. |
| 101 | +/// @details Same as other dispatchClientInputMessage(), but passing |
| 102 | +/// tutorial26::options::DefaultOptions as first template parameter. |
| 103 | +/// @param[in] id Numeric message ID. |
| 104 | +/// @param[in] idx Index of the message among messages with the same ID. |
| 105 | +/// @param[in] msg Message object held by reference to its interface class. |
| 106 | +/// @param[in] handler Reference to handling object. |
| 107 | +/// @see dispatchClientInputMessage() |
| 108 | +/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h |
| 109 | +template<typename TId, typename TMsg, typename THandler> |
| 110 | +auto dispatchClientInputMessageDefaultOptions( |
| 111 | + TId id, |
| 112 | + std::size_t idx, |
| 113 | + TMsg& msg, |
| 114 | + THandler& handler) -> decltype(handler.handle(msg)) |
| 115 | +{ |
| 116 | + return dispatchClientInputMessage<tutorial26::options::DefaultOptions>(id, idx, msg, handler); |
| 117 | +} |
| 118 | + |
| 119 | +/// @brief Dispatch message object to its appropriate handling function. |
| 120 | +/// @details Same as other dispatchClientInputMessageDefaultOptions(), |
| 121 | +/// but without @b idx parameter. |
| 122 | +/// @param[in] id Numeric message ID. |
| 123 | +/// @param[in] msg Message object held by reference to its interface class. |
| 124 | +/// @param[in] handler Reference to handling object. |
| 125 | +/// @see dispatchClientInputMessageDefaultOptions() |
| 126 | +/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h |
| 127 | +template<typename TId, typename TMsg, typename THandler> |
| 128 | +auto dispatchClientInputMessageDefaultOptions( |
| 129 | + TId id, |
| 130 | + TMsg& msg, |
| 131 | + THandler& handler) -> decltype(handler.handle(msg)) |
| 132 | +{ |
| 133 | + return dispatchClientInputMessage<tutorial26::options::DefaultOptions>(id, msg, handler); |
| 134 | +} |
| 135 | + |
| 136 | +/// @brief Message dispatcher class to be used with |
| 137 | +/// @b comms::processAllWithDispatchViaDispatcher() function (or similar). |
| 138 | +/// @tparam TProtOptions Protocol options struct used for the application, |
| 139 | +/// like @ref tutorial26::options::DefaultOptions. |
| 140 | +/// @headerfile tutorial26/dispatch/DispatchClientInputMessage.h |
| 141 | +template <typename TProtOptions = tutorial26::options::DefaultOptions> |
| 142 | +struct ClientInputMsgDispatcher |
| 143 | +{ |
| 144 | + /// @brief Class detection tag |
| 145 | + using MsgDispatcherTag = void; |
| 146 | + |
| 147 | + /// @brief Dispatch message to its handler. |
| 148 | + /// @details Uses appropriate @ref dispatchClientInputMessage() function. |
| 149 | + /// @param[in] id ID of the message. |
| 150 | + /// @param[in] idx Index (or offset) of the message among those having the same numeric ID. |
| 151 | + /// @param[in] msg Reference to message object. |
| 152 | + /// @param[in] handler Reference to handler object. |
| 153 | + /// @return What the @ref dispatchClientInputMessage() function returns. |
| 154 | + template <typename TMsg, typename THandler> |
| 155 | + static auto dispatch(tutorial26::MsgId id, std::size_t idx, TMsg& msg, THandler& handler) -> |
| 156 | + decltype(tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, idx, msg, handler)) |
| 157 | + { |
| 158 | + return tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, idx, msg, handler); |
| 159 | + } |
| 160 | + |
| 161 | + /// @brief Complementary dispatch function. |
| 162 | + /// @details Same as other dispatch without @b TAllMessages template parameter, |
| 163 | + /// used by @b comms::processAllWithDispatchViaDispatcher(). |
| 164 | + template <typename TAllMessages, typename TMsg, typename THandler> |
| 165 | + static auto dispatch(tutorial26::MsgId id, std::size_t idx, TMsg& msg, THandler& handler) -> |
| 166 | + decltype(dispatch(id, idx, msg, handler)) |
| 167 | + { |
| 168 | + return dispatch(id, idx, msg, handler); |
| 169 | + } |
| 170 | + |
| 171 | + /// @brief Dispatch message to its handler. |
| 172 | + /// @details Uses appropriate @ref dispatchClientInputMessage() function. |
| 173 | + /// @param[in] id ID of the message. |
| 174 | + /// @param[in] msg Reference to message object. |
| 175 | + /// @param[in] handler Reference to handler object. |
| 176 | + /// @return What the @ref dispatchClientInputMessage() function returns. |
| 177 | + template <typename TMsg, typename THandler> |
| 178 | + static auto dispatch(tutorial26::MsgId id, TMsg& msg, THandler& handler) -> |
| 179 | + decltype(tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, msg, handler)) |
| 180 | + { |
| 181 | + return tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, msg, handler); |
| 182 | + } |
| 183 | + |
| 184 | + /// @brief Complementary dispatch function. |
| 185 | + /// @details Same as other dispatch without @b TAllMessages template parameter, |
| 186 | + /// used by @b comms::processAllWithDispatchViaDispatcher(). |
| 187 | + template <typename TAllMessages, typename TMsg, typename THandler> |
| 188 | + static auto dispatch(tutorial26::MsgId id, TMsg& msg, THandler& handler) -> |
| 189 | + decltype(dispatch(id, msg, handler)) |
| 190 | + { |
| 191 | + return dispatch(id, msg, handler); |
| 192 | + } |
| 193 | +}; |
| 194 | + |
| 195 | +/// @brief Message dispatcher class to be used with |
| 196 | +/// @b comms::processAllWithDispatchViaDispatcher() function (or similar). |
| 197 | +/// @details Same as ClientInputMsgDispatcher, but passing |
| 198 | +/// @ref tutorial26::options::DefaultOptions as template parameter. |
| 199 | +/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h |
| 200 | +using ClientInputMsgDispatcherDefaultOptions = |
| 201 | + ClientInputMsgDispatcher<>; |
| 202 | + |
| 203 | +} // namespace dispatch |
| 204 | + |
| 205 | +} // namespace tutorial26 |
0 commit comments