15#include "comms/details/detect.h"
16#include "comms/details/field_alias.h"
17#include "comms/details/MessageIdTypeRetriever.h"
18#include "comms/details/MessageInterfaceBuilder.h"
19#include "comms/details/transport_fields_access.h"
77template <
typename... TOptions>
78class Message :
public details::MessageInterfaceBuilderT<TOptions...>
80 using BaseImpl = details::MessageInterfaceBuilderT<TOptions...>;
98 return InterfaceOptions::HasMsgIdType;
105 return InterfaceOptions::HasEndian;
112 return hasMsgIdType() && InterfaceOptions::HasMsgIdInfo;
120 return InterfaceOptions::HasReadIterator;
128 return InterfaceOptions::HasWriteIterator;
135 return InterfaceOptions::HasValid;
142 return InterfaceOptions::HasLength;
149 return InterfaceOptions::HasRefresh;
157 return InterfaceOptions::HasHandler;
165 return InterfaceOptions::HasExtraTransportFields;
172 return InterfaceOptions::HasVersionInExtraTransportFields;
180 return InterfaceOptions::VersionInExtraTransportFields;
187 return InterfaceOptions::HasName;
190#ifdef FOR_DOXYGEN_DOC_ONLY
208 using Endian =
typename BaseImpl::Endian;
364#ifdef FOR_DOXYGEN_DOC_ONLY
457 template <
typename T,
typename TIter>
476 template <std::
size_t TSize,
typename T,
typename TIter>
494 template <
typename T,
typename TIter>
513 template <
typename T, std::
size_t TSize,
typename TIter>
521template <
typename... TOptions>
530template <
typename... TOptions>
544 return details::hasInterfaceOptions<T>();
555template <
typename TMsg,
typename TDefaultType = std::
intmax_t>
557 typename comms::util::LazyDeepConditional<
558 TMsg::InterfaceOptions::HasMsgIdType
560 comms::details::MessageIdTypeRetriever,
561 comms::util::AliasType,
574#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS(...) \
575 COMMS_EXPAND(COMMS_DEFINE_TRANSPORT_FIELD_ENUM(__VA_ARGS__)) \
576 COMMS_MSG_TRANSPORT_FIELDS_ACCESS_FUNC { \
577 auto& msgBase = comms::toMessage(*this); \
578 using MsgBase = typename std::decay<decltype(msgBase)>::type; \
579 static_assert(MsgBase::hasTransportFields(), \
580 "Message interface class doesn't define extra transport fields."); \
581 using TransportFieldsTuple = typename MsgBase::TransportFields; \
582 static_assert(std::tuple_size<TransportFieldsTuple>::value == TransportFieldIdx_numOfValues, \
583 "Invalid number of names for transport fields tuple"); \
584 return msgBase.transportFields(); \
586 COMMS_MSG_TRANSPORT_FIELDS_ACCESS_CONST_FUNC { \
587 return comms::toMessage(*this).transportFields(); \
589 COMMS_EXPAND(COMMS_DO_TRANSPORT_FIELD_ACC_FUNC(TransportFields, transportFields(), __VA_ARGS__))
715#define COMMS_MSG_TRANSPORT_FIELDS_NAMES(...) \
716 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELDS_ACCESS(__VA_ARGS__)) \
717 COMMS_EXPAND(COMMS_DO_FIELD_TYPEDEF(typename Base::TransportFields, TransportField_, TransportFieldIdx_, __VA_ARGS__))
732#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, ...) COMMS_EXPAND(COMMS_DO_ALIAS(transportField_, f_, __VA_ARGS__))
741#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE(f_, ...) COMMS_EXPAND(COMMS_DO_ALIAS_NOTEMPLATE(transportField_, f_, __VA_ARGS__))
844#define COMMS_MSG_TRANSPORT_FIELD_ALIAS(f_, ...) \
845 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS(f_, __VA_ARGS__)) \
846 COMMS_EXPAND(COMMS_DO_ALIAS_TYPEDEF(TransportField_, f_, __VA_ARGS__))
855#define COMMS_MSG_TRANSPORT_FIELD_ALIAS_NOTEMPLATE(f_, ...) \
856 COMMS_EXPAND(COMMS_MSG_TRANSPORT_FIELD_ALIAS_ACCESS_NOTEMPLATE(f_, __VA_ARGS__)) \
857 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:79
static constexpr bool hasValid()
Compile type inquiry whether message interface class defines valid() and validImpl() member functions...
Definition Message.h:133
static constexpr bool hasEndian()
Compile type inquiry whether message interface class defines Endian and Field types.
Definition Message.h:103
FieldsProvidedWithOption TransportFields
std::tuple of extra fields from transport layers that may affect the way the message fields get seria...
Definition Message.h:324
typename BaseImpl::Endian Endian
Serialisation endian type.
Definition Message.h:208
static constexpr bool hasRead()
Compile type inquiry whether message interface class defines read() and readImpl() member functions a...
Definition Message.h:118
static constexpr std::size_t versionIdxInTransportFields()
Compile type inquiry of version field index in transport field.
Definition Message.h:178
~Message() noexcept=default
Destructor.
TypeProvidedWithOption Handler
Type of the message handler object.
Definition Message.h:306
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:96
typename Handler::RetType DispatchRetType
Return type of the dispatch() member function.
Definition Message.h:310
TypeProvidedWithOption ReadIterator
Type of the iterator used for reading message contents from sequence of bytes stored somewhere.
Definition Message.h:229
BaseImpl::Field Field
Type of default base class for all the fields.
Definition Message.h:214
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:163
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:85
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:110
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:126
typename BaseImpl::MsgIdType MsgIdType
Type used for message ID.
Definition Message.h:195
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:202
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:140
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:185
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:349
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:147
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:155
TypeProvidedWithOption WriteIterator
Type of the iterator used for writing message contents into sequence of bytes stored somewhere.
Definition Message.h:249
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:170
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:542
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:563
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:523
Replacement to some types from standard type_traits.