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 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
12
13#pragma once
14
16#include "comms/MessageBase.h"
17#include "comms/options.h"
18
19#include <cstdint>
20#include <tuple>
21
22namespace comms
23{
24
32template <typename TFieldBase, typename TExtraOpts = comms::option::app::EmptyOption>
34 std::tuple<
36 TFieldBase,
37 std::uint8_t,
38 TExtraOpts
39 >
40 >;
41
64template <
65 typename TMessage,
66 typename TFieldOpts = comms::option::app::EmptyOption,
67 typename TExtraOpts = comms::option::app::EmptyOption
68>
69class GenericMessage : public
71 TMessage,
72 comms::option::def::FieldsImpl<GenericMessageFields<typename TMessage::Field, TFieldOpts> >,
73 comms::option::def::MsgType<GenericMessage<TMessage, TFieldOpts, TExtraOpts> >,
74 comms::option::def::HasDoGetId,
75 comms::option::def::HasName,
76 TExtraOpts
77 >
78{
79 using Base =
81 TMessage,
86 TExtraOpts
87 >;
88public:
91 using MsgIdType = typename Base::MsgIdType;
92
96
98 GenericMessage() = delete;
99
102 explicit GenericMessage(MsgIdParamType id) : m_id(id) {}
103
106
109
111 ~GenericMessage() noexcept = default;
112
114 GenericMessage& operator=(const GenericMessage&) = default;
115
117 GenericMessage& operator=(GenericMessage&&) = default;
118
124
129 {
130 return m_id;
131 }
132
136 static const char* doName()
137 {
138 return "Generic Message";
139 }
140
141private:
142 MsgIdType m_id;
143};
144
145} // namespace comms
Contains definition of comms::field::ArrayList.
Provides common base class for the custom messages with default implementation.
Generic Message.
Definition GenericMessage.h:78
GenericMessage(MsgIdParamType id)
Constructor.
Definition GenericMessage.h:102
GenericMessage()=delete
Default constructor is deleted.
GenericMessage(const GenericMessage &)=default
Copy constructor.
typename Base::MsgIdType MsgIdType
Type of the message ID.
Definition GenericMessage.h:91
~GenericMessage() noexcept=default
Destructor.
MsgIdParamType doGetId() const
Get message ID information.
Definition GenericMessage.h:128
typename Base::MsgIdParamType MsgIdParamType
Type of the message ID passed as parameter.
Definition GenericMessage.h:95
GenericMessage(GenericMessage &&)=default
Move constructor.
static const char * doName()
Get message name information.
Definition GenericMessage.h:136
Base class for all the custom protocol messages.
Definition MessageBase.h:88
#define COMMS_MSG_FIELDS_NAMES(...)
Provide names for message fields.
Definition MessageBase.h:1077
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:200
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:40
Contains definition of all the options used by the COMMS library.
No-op option, doesn't have any effect.
Definition options.h:1284
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:1166
Option used to specify actual type of the message.
Definition options.h:202