Skip to content

Commit 8578eae

Browse files
committed
Added tutorial26 code.
1 parent be6bd97 commit 8578eae

37 files changed

+2692
-0
lines changed

tutorials/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ add_subdirectory (tutorial22)
3535
add_subdirectory (tutorial23)
3636
add_subdirectory (tutorial24)
3737
add_subdirectory (tutorial25)
38+
add_subdirectory (tutorial26)

tutorials/tutorial26/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
get_filename_component(name ${CMAKE_CURRENT_SOURCE_DIR} NAME)
2+
3+
set (schema_files
4+
${CMAKE_CURRENT_SOURCE_DIR}/dsl/schema.xml
5+
)
6+
7+
set (server_src
8+
src/ServerSession.cpp
9+
)
10+
11+
set (client_src
12+
src/ClientSession.cpp
13+
)
14+
15+
dsl_tutorial_parse(${name} SCHEMAS ${schema_files})
16+
17+
bin_tutorial_server(${name} ${server_src})
18+
bin_tutorial_client(${name} ${client_src})
19+

tutorials/tutorial26/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Tutorial 26
2+
Stateful message sequence.
3+
4+
[Read Previous Tutorial](../tutorial25) <-----------------------

tutorials/tutorial26/dsl/schema.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<schema name="tutorial26" endian="big" nonUniqueMsgIdAllowed="true">
3+
<fields>
4+
<string name="Msg1Name" defaultValue="Message 1" />
5+
<string name="Msg2Name" defaultValue="Message 2" />
6+
<string name="Msg3Name" defaultValue="Message 3" />
7+
</fields>
8+
<frame name="Frame">
9+
<size name="Size">
10+
<int name="SizeField" type="uint16" />
11+
</size>
12+
<id name="Id">
13+
<int name="IdField" type="uint8" pseudo="true" />
14+
</id>
15+
<payload name="Data" />
16+
</frame>
17+
18+
<message name="Msg1" id="0" order="0" displayName="^Msg1Name" />
19+
<message name="Msg2" id="0" order="1" displayName="^Msg2Name" />
20+
<message name="Msg3" id="0" order="2" displayName="^Msg3Name" />
21+
</schema>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Generated by commsdsl2comms v7.1.0
2+
3+
/// @file
4+
/// @brief Contains definition of <b>"Message"</b> interface class.
5+
6+
#pragma once
7+
8+
#include "comms/Message.h"
9+
#include "comms/options.h"
10+
#include "tutorial26/MsgId.h"
11+
12+
namespace tutorial26
13+
{
14+
15+
/// @brief Definition of <b>"Message"</b> common interface class.
16+
/// @tparam TOpt Interface definition options
17+
/// @headerfile tutorial26/Message.h
18+
template <typename... TOpt>
19+
using Message =
20+
comms::Message<
21+
TOpt...,
22+
comms::option::def::BigEndian,
23+
comms::option::def::MsgIdType<tutorial26::MsgId>
24+
>;
25+
26+
} // namespace tutorial26
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated by commsdsl2comms v7.1.0
2+
3+
/// @file
4+
/// @brief Contains definition of message ids enumeration.
5+
6+
#pragma once
7+
8+
#include <cstdint>
9+
#include "tutorial26/Version.h"
10+
11+
namespace tutorial26
12+
{
13+
14+
/// @brief Message ids enumeration.
15+
enum MsgId : unsigned
16+
{
17+
MsgId_Msg1 = 0U,
18+
MsgId_Msg2 = 0U,
19+
MsgId_Msg3 = 0U
20+
};
21+
22+
} // namespace tutorial26
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Generated by commsdsl2comms v7.1.0
2+
3+
/// @file
4+
/// @brief Contains protocol version definition.
5+
6+
#pragma once
7+
8+
#include "comms/version.h"
9+
10+
/// @brief Version of the protocol specification.
11+
#define TUTORIAL26_SPEC_VERSION (0U)
12+
13+
namespace tutorial26
14+
{
15+
16+
/// @brief Version of the protocol specification.
17+
inline constexpr unsigned specVersion()
18+
{
19+
return TUTORIAL26_SPEC_VERSION;
20+
}
21+
22+
} // namespace tutorial26
23+
24+
// Generated compile time check for minimal supported version of the COMMS library
25+
static_assert(COMMS_MAKE_VERSION(5, 4, 0) <= comms::version(),
26+
"The version of COMMS library is too old");
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// Generated by commsdsl2comms v7.1.0
2+
3+
/// @file
4+
/// @brief Contains dispatch to handling function(s) for client input input messages.
5+
6+
#pragma once
7+
8+
#include <cstdint>
9+
#include "tutorial26/input/ClientInputMessages.h"
10+
#include "tutorial26/options/DefaultOptions.h"
11+
12+
namespace tutorial26
13+
{
14+
15+
namespace dispatch
16+
{
17+
18+
/// @brief Dispatch message object to its appropriate handling function.
19+
/// @details @b switch statement based (on message ID) cast and dispatch functionality.
20+
/// @tparam TProtOptions Protocol options struct used for the application,
21+
/// like @ref tutorial26::options::DefaultOptions.
22+
/// @param[in] id Numeric message ID.
23+
/// @param[in] idx Index of the message among messages with the same ID.
24+
/// @param[in] msg Message object held by reference to its interface class.
25+
/// @param[in] handler Reference to handling object. Must define
26+
/// @b handle() member function for every message type it exects
27+
/// to handle and one for the interface class as well.
28+
/// @code
29+
/// using MyInterface = tutorial26::Message<...>;
30+
/// using MyMsg1 = tutorial26::message::Msg1<MyInterface, tutorial26::options::DefaultOptions>;
31+
/// using MyMsg2 = tutorial26::message::Msg2<MyInterface, tutorial26::options::DefaultOptions>;
32+
/// struct MyHandler {
33+
/// void handle(MyMsg1& msg) {...}
34+
/// void handle(MyMsg2& msg) {...}
35+
/// ...
36+
/// // Handle all unexpected or irrelevant messages.
37+
/// void handle(MyInterface& msg) {...}
38+
/// };
39+
/// @endcode
40+
/// Every @b handle() function may return a value, but every
41+
/// function must return the @b same type.
42+
/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h
43+
template<typename TProtOptions, typename TId, typename TMsg, typename THandler>
44+
auto dispatchClientInputMessage(
45+
TId id,
46+
std::size_t idx,
47+
TMsg& msg,
48+
THandler& handler) -> decltype(handler.handle(msg))
49+
{
50+
using InterfaceType = typename std::decay<decltype(msg)>::type;
51+
switch(static_cast<std::intmax_t>(id)) {
52+
case 0 /* 0x0 */:
53+
{
54+
switch (idx) {
55+
case 0U:
56+
{
57+
using MsgType = tutorial26::message::Msg1<InterfaceType, TProtOptions>;
58+
return handler.handle(static_cast<MsgType&>(msg));
59+
}
60+
case 1U:
61+
{
62+
using MsgType = tutorial26::message::Msg2<InterfaceType, TProtOptions>;
63+
return handler.handle(static_cast<MsgType&>(msg));
64+
}
65+
case 2U:
66+
{
67+
using MsgType = tutorial26::message::Msg3<InterfaceType, TProtOptions>;
68+
return handler.handle(static_cast<MsgType&>(msg));
69+
}
70+
default:
71+
return handler.handle(msg);
72+
};
73+
break;
74+
}
75+
default:
76+
break;
77+
};
78+
79+
return handler.handle(msg);
80+
}
81+
82+
/// @brief Dispatch message object to its appropriate handling function.
83+
/// @details Same as other dispatchClientInputMessage(), but without @b idx parameter.
84+
/// @tparam TProtOptions Protocol options struct used for the application,
85+
/// like @ref tutorial26::options::DefaultOptions.
86+
/// @param[in] id Numeric message ID.
87+
/// @param[in] msg Message object held by reference to its interface class.
88+
/// @param[in] handler Reference to handling object.
89+
/// @see dispatchClientInputMessage()
90+
/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h
91+
template<typename TProtOptions, typename TId, typename TMsg, typename THandler>
92+
auto dispatchClientInputMessage(
93+
TId id,
94+
TMsg& msg,
95+
THandler& handler) -> decltype(handler.handle(msg))
96+
{
97+
return dispatchClientInputMessage<TProtOptions>(id, 0U, msg, handler);
98+
}
99+
100+
/// @brief Dispatch message object to its appropriate handling function.
101+
/// @details Same as other dispatchClientInputMessage(), but passing
102+
/// tutorial26::options::DefaultOptions as first template parameter.
103+
/// @param[in] id Numeric message ID.
104+
/// @param[in] idx Index of the message among messages with the same ID.
105+
/// @param[in] msg Message object held by reference to its interface class.
106+
/// @param[in] handler Reference to handling object.
107+
/// @see dispatchClientInputMessage()
108+
/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h
109+
template<typename TId, typename TMsg, typename THandler>
110+
auto dispatchClientInputMessageDefaultOptions(
111+
TId id,
112+
std::size_t idx,
113+
TMsg& msg,
114+
THandler& handler) -> decltype(handler.handle(msg))
115+
{
116+
return dispatchClientInputMessage<tutorial26::options::DefaultOptions>(id, idx, msg, handler);
117+
}
118+
119+
/// @brief Dispatch message object to its appropriate handling function.
120+
/// @details Same as other dispatchClientInputMessageDefaultOptions(),
121+
/// but without @b idx parameter.
122+
/// @param[in] id Numeric message ID.
123+
/// @param[in] msg Message object held by reference to its interface class.
124+
/// @param[in] handler Reference to handling object.
125+
/// @see dispatchClientInputMessageDefaultOptions()
126+
/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h
127+
template<typename TId, typename TMsg, typename THandler>
128+
auto dispatchClientInputMessageDefaultOptions(
129+
TId id,
130+
TMsg& msg,
131+
THandler& handler) -> decltype(handler.handle(msg))
132+
{
133+
return dispatchClientInputMessage<tutorial26::options::DefaultOptions>(id, msg, handler);
134+
}
135+
136+
/// @brief Message dispatcher class to be used with
137+
/// @b comms::processAllWithDispatchViaDispatcher() function (or similar).
138+
/// @tparam TProtOptions Protocol options struct used for the application,
139+
/// like @ref tutorial26::options::DefaultOptions.
140+
/// @headerfile tutorial26/dispatch/DispatchClientInputMessage.h
141+
template <typename TProtOptions = tutorial26::options::DefaultOptions>
142+
struct ClientInputMsgDispatcher
143+
{
144+
/// @brief Class detection tag
145+
using MsgDispatcherTag = void;
146+
147+
/// @brief Dispatch message to its handler.
148+
/// @details Uses appropriate @ref dispatchClientInputMessage() function.
149+
/// @param[in] id ID of the message.
150+
/// @param[in] idx Index (or offset) of the message among those having the same numeric ID.
151+
/// @param[in] msg Reference to message object.
152+
/// @param[in] handler Reference to handler object.
153+
/// @return What the @ref dispatchClientInputMessage() function returns.
154+
template <typename TMsg, typename THandler>
155+
static auto dispatch(tutorial26::MsgId id, std::size_t idx, TMsg& msg, THandler& handler) ->
156+
decltype(tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, idx, msg, handler))
157+
{
158+
return tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, idx, msg, handler);
159+
}
160+
161+
/// @brief Complementary dispatch function.
162+
/// @details Same as other dispatch without @b TAllMessages template parameter,
163+
/// used by @b comms::processAllWithDispatchViaDispatcher().
164+
template <typename TAllMessages, typename TMsg, typename THandler>
165+
static auto dispatch(tutorial26::MsgId id, std::size_t idx, TMsg& msg, THandler& handler) ->
166+
decltype(dispatch(id, idx, msg, handler))
167+
{
168+
return dispatch(id, idx, msg, handler);
169+
}
170+
171+
/// @brief Dispatch message to its handler.
172+
/// @details Uses appropriate @ref dispatchClientInputMessage() function.
173+
/// @param[in] id ID of the message.
174+
/// @param[in] msg Reference to message object.
175+
/// @param[in] handler Reference to handler object.
176+
/// @return What the @ref dispatchClientInputMessage() function returns.
177+
template <typename TMsg, typename THandler>
178+
static auto dispatch(tutorial26::MsgId id, TMsg& msg, THandler& handler) ->
179+
decltype(tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, msg, handler))
180+
{
181+
return tutorial26::dispatch::dispatchClientInputMessage<TProtOptions>(id, msg, handler);
182+
}
183+
184+
/// @brief Complementary dispatch function.
185+
/// @details Same as other dispatch without @b TAllMessages template parameter,
186+
/// used by @b comms::processAllWithDispatchViaDispatcher().
187+
template <typename TAllMessages, typename TMsg, typename THandler>
188+
static auto dispatch(tutorial26::MsgId id, TMsg& msg, THandler& handler) ->
189+
decltype(dispatch(id, msg, handler))
190+
{
191+
return dispatch(id, msg, handler);
192+
}
193+
};
194+
195+
/// @brief Message dispatcher class to be used with
196+
/// @b comms::processAllWithDispatchViaDispatcher() function (or similar).
197+
/// @details Same as ClientInputMsgDispatcher, but passing
198+
/// @ref tutorial26::options::DefaultOptions as template parameter.
199+
/// @note Defined in tutorial26/dispatch/DispatchClientInputMessage.h
200+
using ClientInputMsgDispatcherDefaultOptions =
201+
ClientInputMsgDispatcher<>;
202+
203+
} // namespace dispatch
204+
205+
} // namespace tutorial26

0 commit comments

Comments
 (0)