COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
GenericMessage.h
Go to the documentation of this file.
1//
2// Copyright 2017 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
13#include <tuple>
14#include <cstdint>
15
16#include "options.h"
17#include "MessageBase.h"
18#include "field/ArrayList.h"
19
20namespace comms
21{
22
30template <typename TFieldBase, typename TExtraOpts = comms::option::app::EmptyOption>
32 std::tuple<
34 TFieldBase,
35 std::uint8_t,
36 TExtraOpts
37 >
38 >;
39
62template <
63 typename TMessage,
64 typename TFieldOpts = comms::option::app::EmptyOption,
65 typename TExtraOpts = comms::option::app::EmptyOption
66>
67class GenericMessage : public
69 TMessage,
70 comms::option::def::FieldsImpl<GenericMessageFields<typename TMessage::Field, TFieldOpts> >,
71 comms::option::def::MsgType<GenericMessage<TMessage, TFieldOpts, TExtraOpts> >,
72 comms::option::def::HasDoGetId,
73 comms::option::def::HasName,
74 TExtraOpts
75 >
76{
77 using Base =
79 TMessage,
84 TExtraOpts
85 >;
86public:
89 using MsgIdType = typename Base::MsgIdType;
90
94
96 GenericMessage() = delete;
97
100 explicit GenericMessage(MsgIdParamType id) : m_id(id) {}
101
104
107
109 ~GenericMessage() noexcept = default;
110
112 GenericMessage& operator=(const GenericMessage&) = default;
113
115 GenericMessage& operator=(GenericMessage&&) = default;
116
122
127 {
128 return m_id;
129 }
130
134 static const char* doName()
135 {
136 return "Generic Message";
137 }
138
139private:
140 MsgIdType m_id;
141};
142
143} // namespace comms
Contains definition of comms::field::ArrayList.
Provides common base class for the custom messages with default implementation.
Generic Message.
Definition GenericMessage.h:76
GenericMessage(MsgIdParamType id)
Constructor.
Definition GenericMessage.h:100
GenericMessage()=delete
Default constructor is deleted.
GenericMessage(const GenericMessage &)=default
Copy constructor.
typename Base::MsgIdType MsgIdType
Type of the message ID.
Definition GenericMessage.h:89
~GenericMessage() noexcept=default
Destructor.
MsgIdParamType doGetId() const
Get message ID information.
Definition GenericMessage.h:126
typename Base::MsgIdParamType MsgIdParamType
Type of the message ID passed as parameter.
Definition GenericMessage.h:93
GenericMessage(GenericMessage &&)=default
Move constructor.
static const char * doName()
Get message name information.
Definition GenericMessage.h:134
Base class for all the custom protocol messages.
Definition MessageBase.h:83
#define COMMS_MSG_FIELDS_NAMES(...)
Provide names for message fields.
Definition MessageBase.h:1066
typename BaseImpl::MsgIdType MsgIdType
Type used for message ID.
Definition Message.h:196
typename BaseImpl::MsgIdParamType MsgIdParamType
Type used for message ID passed as parameter or returned from function.
Definition Message.h:203
Field that represents a sequential collection of fields.
Definition ArrayList.h:192
Main namespace for all classes / functions of COMMS library.
std::tuple< comms::field::ArrayList< TFieldBase, std::uint8_t, TExtraOpts > > GenericMessageFields
Definition of fields for comms::GenericMessage message.
Definition GenericMessage.h:38
Contains definition of all the options used by the COMMS library.
No-op option, doesn't have any effect.
Definition options.h:1250
Option used to specify fields of the message and force implementation of default read,...
Definition options.h:234
Option that notifies comms::MessageBase about existence of doGetId() member function in derived class...
Definition options.h:250
Mark message class as providing its name information.
Definition options.h:1141
Option used to specify actual type of the message.
Definition options.h:202