23#include "comms/details/MessageInterfaceBuilder.h"
24#include "comms/details/transport_fields_access.h"
25#include "comms/details/detect.h"
26#include "comms/details/MessageIdTypeRetriever.h"
27#include "comms/details/field_alias.h"
78template <
typename... TOptions>
79class Message :
public details::MessageInterfaceBuilderT<TOptions...>
81 using BaseImpl = details::MessageInterfaceBuilderT<TOptions...>;
99 return InterfaceOptions::HasMsgIdType;
106 return InterfaceOptions::HasEndian;
113 return hasMsgIdType() && InterfaceOptions::HasMsgIdInfo;
121 return InterfaceOptions::HasReadIterator;
129 return InterfaceOptions::HasWriteIterator;
136 return InterfaceOptions::HasValid;
143 return InterfaceOptions::HasLength;
150 return InterfaceOptions::HasRefresh;
158 return InterfaceOptions::HasHandler;
166 return InterfaceOptions::HasExtraTransportFields;
173 return InterfaceOptions::HasVersionInExtraTransportFields;
181 return InterfaceOptions::VersionInExtraTransportFields;
188 return InterfaceOptions::HasName;
191#ifdef FOR_DOXYGEN_DOC_ONLY
209 using Endian =
typename BaseImpl::Endian;
365#ifdef FOR_DOXYGEN_DOC_ONLY
458 template <
typename T,
typename TIter>
477 template <std::
size_t TSize,
typename T,
typename TIter>
495 template <
typename T,
typename TIter>
514 template <
typename T, std::
size_t TSize,
typename TIter>
522template <
typename... TOptions>
531template <
typename... TOptions>
545 return details::hasInterfaceOptions<T>();
556template <
typename TMsg,
typename TDefaultType = std::
intmax_t>
558 typename comms::util::LazyDeepConditional<
559 TMsg::InterfaceOptions::HasMsgIdType
561 comms::details::MessageIdTypeRetriever,
562 comms::util::AliasType,
575#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS(...) \
576 COMMS_EXPAND(COMMS_DEFINE_TRANSPORT_FIELD_ENUM(__VA_ARGS__)) \
577 COMMS_MSG_TRANSPORT_FIELDS_ACCESS_FUNC { \
578 auto& msgBase = comms::toMessage(*this); \
579 using MsgBase = typename std::decay<decltype(msgBase)>::type; \
580 static_assert(MsgBase::hasTransportFields(), \
581 "Message interface class doesn't define extra transport fields."); \
582 using TransportFieldsTuple = typename MsgBase::TransportFields; \
583 static_assert(std::tuple_size<TransportFieldsTuple>::value == TransportFieldIdx_numOfValues, \
584 "Invalid number of names for transport fields tuple"); \
585 return msgBase.transportFields(); \
587 COMMS_MSG_TRANSPORT_FIELDS_ACCESS_CONST_FUNC { \
588 return comms::toMessage(*this).transportFields(); \
590 COMMS_EXPAND(COMMS_DO_TRANSPORT_FIELD_ACC_FUNC(TransportFields, transportFields(), __VA_ARGS__))
716#define COMMS_MSG_TRANSPORT_FIELDS_NAMES(...) \
717 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELDS_ACCESS(__VA_ARGS__)) \
718 COMMS_EXPAND(COMMS_DO_FIELD_TYPEDEF(typename Base::TransportFields, TransportField_, TransportFieldIdx_, __VA_ARGS__))
733#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, ...) COMMS_EXPAND(COMMS_DO_ALIAS(transportField_, f_, __VA_ARGS__))
742#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE(f_, ...) COMMS_EXPAND(COMMS_DO_ALIAS_NOTEMPLATE(transportField_, f_, __VA_ARGS__))
845#define COMMS_MSG_TRANSPORT_FIELD_ALIAS(f_, ...) \
846 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, __VA_ARGS__)) \
847 COMMS_EXPAND(COMMS_DO_ALIAS_TYPEDEF(TransportField_, f_, __VA_ARGS__))
856#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_NOTEMPLATE(f_, ...) \
857 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE(f_, __VA_ARGS__)) \
858 COMMS_EXPAND(COMMS_DO_ALIAS_TYPEDEF(TransportField_, f_, __VA_ARGS__))
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
Contains definition of comms::Field class.
Main interface class for all the messages.
Definition Message.h:80
static constexpr bool hasValid()
Compile type inquiry whether message interface class defines valid() and validImpl() member functions...
Definition Message.h:134
static constexpr bool hasEndian()
Compile type inquiry whether message interface class defines Endian and Field types.
Definition Message.h:104
FieldsProvidedWithOption TransportFields
std::tuple of extra fields from transport layers that may affect the way the message fields get seria...
Definition Message.h:325
typename BaseImpl::Endian Endian
Serialisation endian type.
Definition Message.h:209
static constexpr bool hasRead()
Compile type inquiry whether message interface class defines read() and readImpl() member functions a...
Definition Message.h:119
static constexpr std::size_t versionIdxInTransportFields()
Compile type inquiry of version field index in transport field.
Definition Message.h:179
~Message() noexcept=default
Destructor.
TypeProvidedWithOption Handler
Type of the message handler object.
Definition Message.h:307
VersionType & version()
Access to version information.
static constexpr bool hasMsgIdType()
Compile type inquiry whether message interface class defines MsgIdType and MsgIdParamType types.
Definition Message.h:97
typename Handler::RetType DispatchRetType
Return type of the dispatch() member function.
Definition Message.h:311
TypeProvidedWithOption ReadIterator
Type of the iterator used for reading message contents from sequence of bytes stored somewhere.
Definition Message.h:230
BaseImpl::Field Field
Type of default base class for all the fields.
Definition Message.h:215
static T readData(TIter &iter)
Read partial data from input area.
static constexpr bool hasTransportFields()
Compile type inquiry whether message interface class defines transportFields() member functions as we...
Definition Message.h:164
static void writeData(T value, TIter &iter)
Write data into the output area.
details::MessageInterfaceOptionsParser< TOptions... > InterfaceOptions
All the options bundled into struct.
Definition Message.h:86
ErrorStatus read(ReadIterator &iter, std::size_t size)
Read message contents using provided iterator.
virtual bool validImpl() const
Pure virtual function used to implement contents validity check.
virtual comms::ErrorStatus readImpl(ReadIterator &iter, std::size_t size)
Virtual function used to implement read operation.
const VersionType & version() const
Const access to version information.
std::size_t length() const
Get number of bytes required to serialise this message.
const char * name() const
Get name of the message.
TransportFields & transportFields()
Get access to extra transport fields.
static constexpr bool hasGetId()
Compile type inquiry whether message interface class defines getId() and getIdImpl() member functions...
Definition Message.h:111
const TransportFields & transportFields() const
Const version of transportFields.
static constexpr bool hasWrite()
Compile type inquiry whether message interface class defines write() and writeImpl() member functions...
Definition Message.h:127
typename BaseImpl::MsgIdType MsgIdType
Type used for message ID.
Definition Message.h:196
virtual MsgIdParamType getIdImpl() const =0
Pure virtual function used to retrieve ID of the message.
typename BaseImpl::MsgIdParamType MsgIdParamType
Type used for message ID passed as parameter or returned from function.
Definition Message.h:203
MsgIdParamType getId() const
Retrieve ID of the message.
static constexpr bool hasLength()
Compile type inquiry whether message interface class defines length() and lengthImpl() member functio...
Definition Message.h:141
virtual const char * nameImpl() const =0
Pure virtual function used to retrieve actual message name.
virtual DispatchRetType dispatchImpl(Handler &handler)
Virtual function used to dispatch message to the handler object for processing.
static constexpr bool hasName()
Compile type inquiry whether message interface class defines name() and nameImpl() member functions.
Definition Message.h:186
static void writeData(T value, TIter &iter)
Write partial data into the output area.
static T readData(TIter &iter)
Read data from input area.
ErrorStatus write(WriteIterator &iter, std::size_t size) const
Write message contents using provided iterator.
virtual std::size_t lengthImpl() const
Virtual function used to retrieve number of bytes required to serialise this message.
typename BaseImpl::VersionType VersionType
Type used for version info.
Definition Message.h:350
bool refresh()
Refresh to contents of the message.
static constexpr bool hasRefresh()
Compile type inquiry whether message interface class defines refresh() and refreshImpl() member funct...
Definition Message.h:148
virtual comms::ErrorStatus writeImpl(WriteIterator &iter, std::size_t size) const
Virtual function used to implement write operation.
bool valid() const
Check validity of message contents.
static constexpr bool hasDispatch()
Compile type inquiry whether message interface class defines dispatch() and dispatchImpl() member fun...
Definition Message.h:156
TypeProvidedWithOption WriteIterator
Type of the iterator used for writing message contents into sequence of bytes stored somewhere.
Definition Message.h:250
DispatchRetType dispatch(Handler &handler)
Dispatch message to the handler for processing.
virtual bool refreshImpl()
Virtual function used to bring contents of the message into a consistent state.
static constexpr bool hasVersionInTransportFields()
Compile type inquiry whether there is version information inside transport fields.
Definition Message.h:171
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
constexpr bool isMessage()
Compile time check of of whether the type is a message.
Definition Message.h:543
typename comms::util::LazyDeepConditional< TMsg::InterfaceOptions::HasMsgIdType >::template Type< comms::details::MessageIdTypeRetriever, comms::util::AliasType, TDefaultType, TMsg > MessageIdType
Get type of message ID used by interface class.
Definition Message.h:564
Message< TOptions... > & toMessage(Message< TOptions... > &msg)
Upcast type of the message object to comms::Message in order to have access to its internal types.
Definition Message.h:524
Replacement to some types from standard type_traits.