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;
158 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
168 template <
typename TDispatcher,
typename TBufIter,
typename TFrame,
typename THandler,
typename... TExtraValues>
175 std::size_t consumed = 0U;
176 using FrameType =
typename std::decay<
decltype(frame)>::type;
177 using MsgPtr =
typename FrameType::MsgPtr;
178 while (consumed < len) {
179 auto begIter = bufIter + consumed;
183 auto es = processSingleWithDispatchViaDispatcher<TDispatcher>(iter, len - consumed, std::forward<TFrame>(frame), msg, handler);
184 consumed +=
static_cast<decltype(consumed)
>(std::distance(begIter, iter));
194 template <
typename... TParams>
195 using PolymorphicDispatchTag = comms::details::tag::Tag1<>;
197 template <
typename... TParams>
198 using RegularDispatchTag = comms::details::tag::Tag2<>;
200 template <
typename TMsg,
typename THandler,
typename...>
201 using DispatchTagTmp =
202 typename comms::util::LazyShallowConditional<
203 details::dispatchMsgPolymorphicIsCompatibleHandler<TMsg, THandler>()
205 PolymorphicDispatchTag,
209 template <
typename TMsg,
typename THandler,
typename...>
211 typename comms::util::LazyShallowConditional<
212 comms::isMessage<TMsg>()
219 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
226 TExtraValues... extraValues,
227 RegularDispatchTag<>)
229 using MsgType =
typename std::decay<
decltype(msg)>::type;
230 using FrameType =
typename std::decay<
decltype(frame)>::type;
231 static_assert((!comms::isMessage<MsgType>()) || (details::allMessagesAreStrongSorted<typename FrameType::AllMessages>()),
232 "Cannot process pre-allocated message, impossible to retrieve message index for proper dispatch, "
233 "use comms::option::def::Handler option to support polymorphic dispatch");
235 using LocalMsgIdType = details::ProcessMsgIdType<MsgType>;
236 LocalMsgIdType
id = LocalMsgIdType();
237 std::size_t idx = 0U;
243 std::forward<TFrame>(frame),
253 using FrameType =
typename std::decay<
decltype(frame)>::type;
254 using AllMessagesType =
typename FrameType::AllMessages;
255 auto& msgObj = details::processMsgCastToMsgObj(msg);
256 comms::dispatchMsg<AllMessagesType>(
id, idx, msgObj, handler);
260 template <
typename TBufIter,
typename TFrame,
typename TMsg,
typename THandler,
typename... TExtraValues>
267 TExtraValues... extraValues,
268 PolymorphicDispatchTag<>)
274 std::forward<TFrame>(frame),
282 auto& msgObj = details::processMsgCastToMsgObj(msg);
283 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: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: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: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.