COMMS
Template library intended to help with implementation of communication protocols.
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 
20 namespace comms
21 {
22 
30 template <typename TFieldBase, typename TExtraOpts = comms::option::app::EmptyOption>
32  std::tuple<
34  TFieldBase,
35  std::uint8_t,
36  TExtraOpts
37  >
38  >;
39 
62 template <
63  typename TMessage,
64  typename TFieldOpts = comms::option::app::EmptyOption,
65  typename TExtraOpts = comms::option::app::EmptyOption
66 >
67 class 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  >;
86 public:
89  using MsgIdType = typename Base::MsgIdType;
90 
94 
96  GenericMessage() = delete;
97 
100  explicit GenericMessage(MsgIdParamType id) : m_id(id) {}
101 
103  GenericMessage(const GenericMessage&) = default;
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 
139 private:
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
static const char * doName()
Get message name information.
Definition: GenericMessage.h:134
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.
COMMS_MSG_FIELDS_NAMES(data)
Allow access to internal fields.
Base class for all the custom protocol messages.
Definition: MessageBase.h:83
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
comms::option::def::HasName HasName
Same as comms::option::def::HasName.
Definition: options.h:1786
comms::option::app::EmptyOption EmptyOption
Same as comms::option::app::EmptyOption.
Definition: options.h:1831
comms::option::def::HasDoGetId HasDoGetId
Same as comms::option::def::HasDoGetId.
Definition: options.h:1481
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 used to specify actual type of the message.
Definition: options.h:202