14#include "comms/details/detect.h"
15#include "comms/details/DispatchMsgPolymorphicHelper.h"
16#include "comms/details/process.h"
17#include "comms/details/tag.h"
41 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename... TExtraValues>
47 TExtraValues... extraValues)
49 std::size_t consumed = 0U;
51 comms::util::makeScopeGuard(
52 [&bufIter, &consumed]()
54 std::advance(bufIter, consumed);
56 static_cast<void>(onExit);
58 while (consumed < len) {
63 auto es = frame.read(msg, iter, len - consumed, extraValues...);
74 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
81 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
88 TExtraValues... extraValues)
90 using MsgType =
typename std::decay<
decltype(msg)>::type;
91 using HandlerType =
typename std::decay<
decltype(handler)>::type;
92 using Tag = DispatchTag<MsgType, HandlerType>;
93 return processSingleWithDispatchInternal(bufIter, len, frame, msg, handler, extraValues..., Tag());
96 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
103 TExtraValues... extraValues)
105 using MsgType =
typename std::decay<
decltype(msg)>::type;
106 using FrameType =
typename std::decay<
decltype(frame)>::type;
107 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
108 "Cannot dispatch with Dispatcher when using pre-allocated message, use regular polymorphic dispatch with "
109 "comms::option::def::Handler option");
111 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
112 static_assert(!std::is_void<LocalMsgIdType>(),
"Invalid type of msg param");
114 LocalMsgIdType
id = LocalMsgIdType();
115 std::size_t idx = 0U;
121 std::forward<TFrame>(frame),
131 using FrameType =
typename std::decay<
decltype(frame)>::type;
132 using AllMessagesType =
typename FrameType::AllMessages;
134 comms::isMsgDispatcher<TDispatcher>(),
135 "TDispatcher is expected to be a variant of comms::MsgDispatcher");
137 auto& msgObj = details::processMsgCastToMsgObj(msg);
138 TDispatcher::template dispatch<AllMessagesType>(
id, idx, msgObj, handler);
142 template <
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
149 std::size_t consumed = 0U;
150 using FrameType =
typename std::decay<
decltype(frame)>::type;
151 using MsgPtr =
typename FrameType::MsgPtr;
152 while (consumed < len) {
153 auto begIter = bufIter + consumed;
163 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
173 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
180 std::size_t consumed = 0U;
181 using FrameType =
typename std::decay<
decltype(frame)>::type;
182 using MsgPtr =
typename FrameType::MsgPtr;
183 while (consumed < len) {
184 auto begIter = bufIter + consumed;
188 auto es = processSingleWithDispatchViaDispatcher<TDispatcher>(iter, len - consumed, std::forward<TFrame>(frame), msg, handler);
189 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
199 template <
typename... TParams>
200 using PolymorphicDispatchTag = comms::details::tag::Tag1<>;
202 template <
typename... TParams>
203 using RegularDispatchTag = comms::details::tag::Tag2<>;
205 template <
typename TMsg,
typename THandler,
typename...>
206 using DispatchTagTmp =
207 typename comms::util::LazyShallowConditional<
208 details::dispatchMsgPolymorphicIsCompatibleHandler<TMsg, THandler>()
210 PolymorphicDispatchTag,
214 template <
typename TMsg,
typename THandler,
typename...>
216 typename comms::util::LazyShallowConditional<
217 comms::isMessage<TMsg>()
224 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
231 TExtraValues... extraValues,
232 RegularDispatchTag<>)
234 using MsgType =
typename std::decay<
decltype(msg)>::type;
235 using FrameType =
typename std::decay<
decltype(frame)>::type;
236 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
237 "Cannot process pre-allocated message, impossible to retrieve message index for proper dispatch, "
238 "use comms::option::def::Handler option to support polymorphic dispatch");
240 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
241 LocalMsgIdType
id = LocalMsgIdType();
242 std::size_t idx = 0U;
248 std::forward<TFrame>(frame),
258 using FrameType =
typename std::decay<
decltype(frame)>::type;
259 using AllMessagesType =
typename FrameType::AllMessages;
260 auto& msgObj = details::processMsgCastToMsgObj(msg);
261 comms::dispatchMsg<AllMessagesType>(
id, idx, msgObj, handler);
265 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
272 TExtraValues... extraValues,
273 PolymorphicDispatchTag<>)
279 std::forward<TFrame>(frame),
287 auto& msgObj = details::processMsgCastToMsgObj(msg);
288 msgObj.dispatch(handler);
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:168
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:1623
details::MsgIdRetriever< TId > msgId(TId &val)
Add "message ID" output parameter to frame's "read" operation.
Definition FrameLayerBase.h:1586
comms::option::def::MsgType< TMsg > MsgType
Same as comms::option::def::MsgType.
Definition options.h:1498
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ 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:157
auto readIteratorFor(TIter &&iter) -> decltype(details::ReadIteratorHelper<>::template get< TMessage >(std::forward< TIter >(iter)))
Create and initialise iterator for message read.
Definition iterator.h:26
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:43
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:81
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:123
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:190
Replacement to some types from standard type_traits.