14#include "comms/details/detect.h"
15#include "comms/details/DispatchMsgPolymorphicHelper.h"
16#include "comms/details/process.h"
17#include "comms/details/tag.h"
40 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename... TExtraValues>
46 TExtraValues... extraValues)
48 std::size_t consumed = 0U;
50 comms::util::makeScopeGuard(
51 [&bufIter, &consumed]()
53 std::advance(bufIter, consumed);
55 static_cast<void>(onExit);
57 while (consumed < len) {
62 auto es = frame.read(msg, iter, len - consumed, extraValues...);
73 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
80 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
87 TExtraValues... extraValues)
89 using MsgType =
typename std::decay<
decltype(msg)>::type;
90 using HandlerType =
typename std::decay<
decltype(handler)>::type;
91 using Tag = DispatchTag<MsgType, HandlerType>;
92 return processSingleWithDispatchInternal(bufIter, len, frame, msg, handler, extraValues..., Tag());
95 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
102 TExtraValues... extraValues)
104 using MsgType =
typename std::decay<
decltype(msg)>::type;
105 using FrameType =
typename std::decay<
decltype(frame)>::type;
106 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
107 "Cannot dispatch with Dispatcher when using pre-allocated message, use regular polymorphic dispatch with "
108 "comms::option::def::Handler option");
110 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
111 static_assert(!std::is_void<LocalMsgIdType>(),
"Invalid type of msg param");
113 LocalMsgIdType
id = LocalMsgIdType();
114 std::size_t idx = 0U;
120 std::forward<TFrame>(frame),
130 using FrameType =
typename std::decay<
decltype(frame)>::type;
131 using AllMessagesType =
typename FrameType::AllMessages;
133 comms::isMsgDispatcher<TDispatcher>(),
134 "TDispatcher is expected to be a variant of comms::MsgDispatcher");
136 auto& msgObj = details::processMsgCastToMsgObj(msg);
137 TDispatcher::template dispatch<AllMessagesType>(
id, idx, msgObj, handler);
141 template <
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
148 std::size_t consumed = 0U;
149 using FrameType =
typename std::decay<
decltype(frame)>::type;
150 using MsgPtr =
typename FrameType::MsgPtr;
151 while (consumed < len) {
152 auto begIter = bufIter + consumed;
157 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
167 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
174 std::size_t consumed = 0U;
175 using FrameType =
typename std::decay<
decltype(frame)>::type;
176 using MsgPtr =
typename FrameType::MsgPtr;
177 while (consumed < len) {
178 auto begIter = bufIter + consumed;
182 auto es = processSingleWithDispatchViaDispatcher<TDispatcher>(iter, len - consumed, std::forward<TFrame>(frame), msg, handler);
183 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
193 template <
typename... TParams>
194 using PolymorphicDispatchTag = comms::details::tag::Tag1<>;
196 template <
typename... TParams>
197 using RegularDispatchTag = comms::details::tag::Tag2<>;
199 template <
typename TMsg,
typename THandler,
typename...>
200 using DispatchTagTmp =
201 typename comms::util::LazyShallowConditional<
202 details::dispatchMsgPolymorphicIsCompatibleHandler<TMsg, THandler>()
204 PolymorphicDispatchTag,
208 template <
typename TMsg,
typename THandler,
typename...>
210 typename comms::util::LazyShallowConditional<
211 comms::isMessage<TMsg>()
218 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
225 TExtraValues... extraValues,
226 RegularDispatchTag<>)
228 using MsgType =
typename std::decay<
decltype(msg)>::type;
229 using FrameType =
typename std::decay<
decltype(frame)>::type;
230 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
231 "Cannot process pre-allocated message, impossible to retrieve message index for proper dispatch, "
232 "use comms::option::def::Handler option to support polymorphic dispatch");
234 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
235 LocalMsgIdType
id = LocalMsgIdType();
236 std::size_t idx = 0U;
242 std::forward<TFrame>(frame),
252 using FrameType =
typename std::decay<
decltype(frame)>::type;
253 using AllMessagesType =
typename FrameType::AllMessages;
254 auto& msgObj = details::processMsgCastToMsgObj(msg);
255 comms::dispatchMsg<AllMessagesType>(
id, idx, msgObj, handler);
259 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
266 TExtraValues... extraValues,
267 PolymorphicDispatchTag<>)
273 std::forward<TFrame>(frame),
281 auto& msgObj = details::processMsgCastToMsgObj(msg);
282 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:1622
details::MsgIdRetriever< TId > msgId(TId &val)
Add "message ID" output parameter to frame's "read" operation.
Definition FrameLayerBase.h:1585
comms::option::def::MsgType< TMsg > MsgType
Same as comms::option::def::MsgType.
Definition options.h:1487
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:156
auto readIteratorFor(TIter &&iter) -> decltype(details::ReadIteratorHelper<>::template get< TMessage >(std::forward< TIter >(iter)))
Create and initialise iterator for message read.
Definition iterator.h:24
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:42
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:80
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:122
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:189
Replacement to some types from standard type_traits.