Skip to content

Commit c7f019a

Browse files
committed
Emphasising polymorphic dispatch in tutorial26.
1 parent af35d63 commit c7f019a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tutorials/tutorial26/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,31 @@ the actual message object (extends [comms::MessageBase](https://commschamp.githu
122122
the latter the code will attempt to invoke non-virtual member functions of the message object, such as `doRead()` instead of polymorphic
123123
`read()`.
124124

125+
Another **important** aspect of the stateful message sequence support is the **necessity** to use polymorphic message dispatch.
126+
```cpp
127+
using Message =
128+
tutorial26::Message<
129+
...
130+
comms::option::app::Handler<ServerSession> // Polymorphic dispatch
131+
>;
132+
```
133+
The dispatch also needs be **without** usage of the dispatcher.
134+
```cpp
135+
auto es = comms::processSingleWithDispatch(buf, bufLen, m_frame, *m_msg, *this);
136+
```
137+
To be able to dispatch message to handling via the dispatcher object there is a need to know both numeric message ID as well as
138+
index (offset) of the message type within the used [input messages tuple](include/tutorial26/input/ServerInputMessages.h) among
139+
other message types reporting the same ID. When the input message is pre-allocated there is no way to detect the relevant information.
140+
125141
## Summary
126142

127143
- The transport framing allows deserialization of the pre-allocated message object, which allows implementation of the
128144
stateful sequence of messages.
129145
- The processing functions from the [comms/process.h](https://commschamp.github.io/comms_doc/process_8h.html) wrap the
130146
frame function(s) invocations and allow transparent passing of the same message parameter to the frame function,
131147
whether it is a reference to the message object itself or a reference to a smart pointer to the message object.
148+
- It is necessary to use polymorphic dispatch (using `comms::option::app::Handler` option) functionality.
149+
- When dispatching the message object for handling, the polymorphic dispatch functionality needs to be used and
150+
not the dispatcher object.
132151

133-
[Read Previous Tutorial](../tutorial25) &lt;-----------------------
152+
[Read Previous Tutorial](../tutorial25) &lt;-----------------------&gt; [Read Next Tutorial](../tutorial27)

0 commit comments

Comments
 (0)