16#include "comms/details/detect.h"
17#include "comms/details/DispatchMsgPolymorphicHelper.h"
18#include "comms/details/process.h"
19#include "comms/details/tag.h"
43 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename... TExtraValues>
49 TExtraValues... extraValues)
51 std::size_t consumed = 0U;
53 comms::util::makeScopeGuard(
54 [&bufIter, &consumed]()
56 std::advance(bufIter, consumed);
58 static_cast<void>(onExit);
60 while (consumed < len) {
65 auto es = frame.read(msg, iter, len - consumed, extraValues...);
76 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
83 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
90 TExtraValues... extraValues)
92 using MsgType =
typename std::decay<
decltype(msg)>::type;
93 using HandlerType =
typename std::decay<
decltype(handler)>::type;
94 using Tag = DispatchTag<MsgType, HandlerType>;
95 return processSingleWithDispatchInternal(bufIter, len, frame, msg, handler, extraValues..., Tag());
98 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
105 TExtraValues... extraValues)
107 using MsgType =
typename std::decay<
decltype(msg)>::type;
108 using FrameType =
typename std::decay<
decltype(frame)>::type;
109 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
110 "Cannot dispatch with Dispatcher when using pre-allocated message, use regular polymorphic dispatch with "
111 "comms::option::def::Handler option");
113 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
114 static_assert(!std::is_void<LocalMsgIdType>(),
"Invalid type of msg param");
116 LocalMsgIdType
id = LocalMsgIdType();
117 std::size_t idx = 0U;
123 std::forward<TFrame>(frame),
133 using FrameType =
typename std::decay<
decltype(frame)>::type;
134 using AllMessagesType =
typename FrameType::AllMessages;
136 comms::isMsgDispatcher<TDispatcher>(),
137 "TDispatcher is expected to be a variant of comms::MsgDispatcher");
139 auto& msgObj = details::processMsgCastToMsgObj(msg);
140 TDispatcher::template dispatch<AllMessagesType>(
id, idx, msgObj, handler);
144 template <
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
151 std::size_t consumed = 0U;
152 using FrameType =
typename std::decay<
decltype(frame)>::type;
153 using MsgPtr =
typename FrameType::MsgPtr;
154 while (consumed < len) {
155 auto begIter = bufIter + consumed;
165 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
175 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
182 std::size_t consumed = 0U;
183 using FrameType =
typename std::decay<
decltype(frame)>::type;
184 using MsgPtr =
typename FrameType::MsgPtr;
185 while (consumed < len) {
186 auto begIter = bufIter + consumed;
190 auto es = processSingleWithDispatchViaDispatcher<TDispatcher>(iter, len - consumed, std::forward<TFrame>(frame), msg, handler);
191 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
201 template <
typename... TParams>
202 using PolymorphicDispatchTag = comms::details::tag::Tag1<>;
204 template <
typename... TParams>
205 using RegularDispatchTag = comms::details::tag::Tag2<>;
207 template <
typename TMsg,
typename THandler,
typename...>
208 using DispatchTagTmp =
209 typename comms::util::LazyShallowConditional<
210 details::dispatchMsgPolymorphicIsCompatibleHandler<TMsg, THandler>()
212 PolymorphicDispatchTag,
216 template <
typename TMsg,
typename THandler,
typename...>
218 typename comms::util::LazyShallowConditional<
219 comms::isMessage<TMsg>()
226 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
233 TExtraValues... extraValues,
234 RegularDispatchTag<>)
236 using MsgType =
typename std::decay<
decltype(msg)>::type;
237 using FrameType =
typename std::decay<
decltype(frame)>::type;
238 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
239 "Cannot process pre-allocated message, impossible to retrieve message index for proper dispatch, "
240 "use comms::option::def::Handler option to support polymorphic dispatch");
242 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
243 LocalMsgIdType
id = LocalMsgIdType();
244 std::size_t idx = 0U;
250 std::forward<TFrame>(frame),
260 using FrameType =
typename std::decay<
decltype(frame)>::type;
261 using AllMessagesType =
typename FrameType::AllMessages;
262 auto& msgObj = details::processMsgCastToMsgObj(msg);
263 comms::dispatchMsg<AllMessagesType>(
id, idx, msgObj, handler);
267 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
274 TExtraValues... extraValues,
275 PolymorphicDispatchTag<>)
281 std::forward<TFrame>(frame),
289 auto& msgObj = details::processMsgCastToMsgObj(msg);
290 msgObj.dispatch(handler);
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
This file contain definition of error statuses used by comms module.
Contains definition of comms::frame::FrameLayerBase.
Contains definition of Message object interface and various base classes for custom messages.
Contains definition of MsgDispatcher class which facilitates dispatching of message object to appropr...
Contains definition of the "Scope Guard" idiom, see comms::util::ScopeGuard.
Contains extra logic to help with dispatching message types and objects.
Provides auxiliary functions for retrieving best type of iterator for read/write operations.
details::MsgIndexRetriever msgIndex(std::size_t &val)
Add "message index" output parameter to frame's "read" operation.
Definition FrameLayerBase.h:1627
details::MsgIdRetriever< TId > msgId(TId &val)
Add "message ID" output parameter to frame's "read" operation.
Definition FrameLayerBase.h:1590
comms::option::def::MsgType< TMsg > MsgType
Same as comms::option::def::MsgType.
Definition options.h:1500
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
@ Success
Used to indicate successful outcome of the operation.
std::size_t processAllWithDispatch(TBufIter bufIter, std::size_t len, TFrame &&frame, THandler &handler)
Process all available input and dispatch all created message objects to appropriate handling function...
Definition process.h:159
auto readIteratorFor(TIter &&iter) -> decltype(details::ReadIteratorHelper<>::template get< TMessage >(std::forward< TIter >(iter)))
Create and initialise iterator for message read.
Definition iterator.h:29
comms::ErrorStatus processSingle(TBufIter &bufIter, std::size_t len, TFrame &&frame, TMsg &msg, TExtraValues... extraValues)
Process input until first message is recognized and its object is created or missing data is reported...
Definition process.h:45
comms::ErrorStatus processSingleWithDispatch(TBufIter &bufIter, std::size_t len, TFrame &&frame, TMsg &msg, THandler &handler, TExtraValues... extraValues)
Process input until first message is recognized, its object is created and dispatched to appropriate ...
Definition process.h:83
comms::ErrorStatus processSingleWithDispatchViaDispatcher(TBufIter &bufIter, std::size_t len, TFrame &&frame, TMsg &msg, THandler &handler, TExtraValues... extraValues)
Process input until first message is recognized, its object is created and dispatched to appropriate ...
Definition process.h:125
std::size_t processAllWithDispatchViaDispatcher(TBufIter bufIter, std::size_t len, TFrame &&frame, THandler &handler)
Process all available input and dispatch all created message objects to appropriate handling function...
Definition process.h:192
Replacement to some types from standard type_traits.