Skip to content

Commit

Permalink
Added mention of the ".x_body" code injection fiels in the tutorial14.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Jan 23, 2025
1 parent a855ec0 commit 79f917b
Show file tree
Hide file tree
Showing 22 changed files with 297 additions and 12 deletions.
16 changes: 16 additions & 0 deletions tutorials/tutorial14/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ The `Msg1` definition of the schema uses these properties:
...
</message>
```

To avoid an explicit implementation of the function signature the **v7.0** of the [commsdsl2comms](https://github.com/commschamp/commsdsl)
allows usage of the **&lt;class&gt;.h.&lt;op&gt;_body** files (instead of **&lt;class&gt;.h.&lt;op&gt;** ones) contents
of which is expected to be only a body of the function without the signature.

- **.read_body** - Overwrites default read function body.
- **.write_body** - Overwrites default write function body.
- **.length_body** - Overwrites default serialization length function body.
- **.valid_body** - Overwrites default validity check function body.
- **.refresh_body** - Overwrites default refresh function body.
- **.name_body** - Overwrites default name retrieval function body.

There are multiple **Msg3.h.X_body** files inside [dsl_src/include/tutorial14/message](dsl_src/include/tutorial14/message) folder that
demonstrate usage of the suffixes above and the injected code finds its way to
[include/tutorial14/message/Msg3.h](include/tutorial14/message/Msg3.h).

----

## Summary
Expand Down
8 changes: 7 additions & 1 deletion tutorials/tutorial14/dsl/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<fields>
<string name="Msg1Name" defaultValue="Message 1" />
<string name="Msg2Name" defaultValue="Message 2" />
<string name="Msg3Name" defaultValue="Message 3" />

<enum name="MsgId" type="uint8" semanticType="messageId">
<validValue name="M1" val="1" displayName="^Msg1Name" />
<validValue name="M2" val="2" displayName="^Msg2Name" />
<validValue name="M3" val="3" displayName="^Msg3Name" />
</enum>

</fields>
Expand Down Expand Up @@ -45,6 +47,10 @@

<message name="Msg2" id="MsgId.M2" displayName="^Msg2Name">
<int name="F1" type="uint16" />
</message>
</message>

<message name="Msg3" id="MsgId.M3" displayName="^Msg3Name">
<int name="F1" type="uint32" />
</message>

</schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <iostream>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::cout << "Call of custom " << __FUNCTION__ << std::endl;
return Base::doLength();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::cout << "Call of custom " << __FUNCTION__ << std::endl;
return Base::doRead(iter, len);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::cout << "Call of custom " << __FUNCTION__ << std::endl;
return Base::doRefresh();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::cout << "Call of custom " << __FUNCTION__ << std::endl;
return Base::doValid();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
std::cout << "Call of custom " << __FUNCTION__ << std::endl;
return Base::doWrite(iter, len);
5 changes: 3 additions & 2 deletions tutorials/tutorial14/include/tutorial14/MsgId.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ enum MsgId : std::uint8_t
{
MsgId_M1 = 1, ///< message id of <b>Message 1</b> message.
MsgId_M2 = 2, ///< message id of <b>Message 2</b> message.
MsgId_M3 = 3, ///< message id of <b>Message 3</b> message.

// --- Extra values generated for convenience ---
MsgId_FirstValue = 1, ///< First defined value.
MsgId_LastValue = 2, ///< Last defined value.
MsgId_ValuesLimit = 3, ///< Upper limit for defined values.
MsgId_LastValue = 3, ///< Last defined value.
MsgId_ValuesLimit = 4, ///< Upper limit for defined values.
};

} // namespace tutorial14
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ auto dispatchClientInputMessage(
using MsgType = tutorial14::message::Msg2<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
case tutorial14::MsgId_M3:
{
using MsgType = tutorial14::message::Msg3<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
default:
break;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ auto dispatchMessage(
using MsgType = tutorial14::message::Msg2<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
case tutorial14::MsgId_M3:
{
using MsgType = tutorial14::message::Msg3<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
default:
break;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ auto dispatchServerInputMessage(
using MsgType = tutorial14::message::Msg2<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
case tutorial14::MsgId_M3:
{
using MsgType = tutorial14::message::Msg3<InterfaceType, TProtOptions>;
return handler.handle(static_cast<MsgType&>(msg));
}
default:
break;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class AllMessagesDynMemMsgFactory
switch (id) {
case tutorial14::MsgId_M1: return MsgPtr(new tutorial14::message::Msg1<TInterface, TProtOptions>);
case tutorial14::MsgId_M2: return MsgPtr(new tutorial14::message::Msg2<TInterface, TProtOptions>);
case tutorial14::MsgId_M3: return MsgPtr(new tutorial14::message::Msg3<TInterface, TProtOptions>);
default: break;
}

Expand Down Expand Up @@ -96,6 +97,7 @@ class AllMessagesDynMemMsgFactory
{
case tutorial14::MsgId_M1: return 1U;
case tutorial14::MsgId_M2: return 1U;
case tutorial14::MsgId_M3: return 1U;
default: break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ClientInputMessagesDynMemMsgFactory
switch (id) {
case tutorial14::MsgId_M1: return MsgPtr(new tutorial14::message::Msg1<TInterface, TProtOptions>);
case tutorial14::MsgId_M2: return MsgPtr(new tutorial14::message::Msg2<TInterface, TProtOptions>);
case tutorial14::MsgId_M3: return MsgPtr(new tutorial14::message::Msg3<TInterface, TProtOptions>);
default: break;
}

Expand Down Expand Up @@ -96,6 +97,7 @@ class ClientInputMessagesDynMemMsgFactory
{
case tutorial14::MsgId_M1: return 1U;
case tutorial14::MsgId_M2: return 1U;
case tutorial14::MsgId_M3: return 1U;
default: break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ServerInputMessagesDynMemMsgFactory
switch (id) {
case tutorial14::MsgId_M1: return MsgPtr(new tutorial14::message::Msg1<TInterface, TProtOptions>);
case tutorial14::MsgId_M2: return MsgPtr(new tutorial14::message::Msg2<TInterface, TProtOptions>);
case tutorial14::MsgId_M3: return MsgPtr(new tutorial14::message::Msg3<TInterface, TProtOptions>);
default: break;
}

Expand Down Expand Up @@ -96,6 +97,7 @@ class ServerInputMessagesDynMemMsgFactory
{
case tutorial14::MsgId_M1: return 1U;
case tutorial14::MsgId_M2: return 1U;
case tutorial14::MsgId_M3: return 1U;
default: break;
}

Expand Down
4 changes: 2 additions & 2 deletions tutorials/tutorial14/include/tutorial14/field/MsgId.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MsgId : public
tutorial14::field::MsgIdCommon::ValueType,
TExtraOpts...,
comms::option::def::HasName,
comms::option::def::ValidNumValueRange<1, 2>
comms::option::def::ValidNumValueRange<1, 3>
>
{
using Base =
Expand All @@ -37,7 +37,7 @@ class MsgId : public
tutorial14::field::MsgIdCommon::ValueType,
TExtraOpts...,
comms::option::def::HasName,
comms::option::def::ValidNumValueRange<1, 2>
comms::option::def::ValidNumValueRange<1, 3>
>;
public:
/// @brief Re-definition of the value type.
Expand Down
3 changes: 2 additions & 1 deletion tutorials/tutorial14/include/tutorial14/field/MsgIdCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct MsgIdCommon
static const char* Map[] = {
nullptr,
"Message 1",
"Message 2"
"Message 2",
"Message 3"
};
static const std::size_t MapSize = std::extent<decltype(Map)>::value;

Expand Down
7 changes: 5 additions & 2 deletions tutorials/tutorial14/include/tutorial14/input/AllMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <tuple>
#include "tutorial14/message/Msg1.h"
#include "tutorial14/message/Msg2.h"
#include "tutorial14/message/Msg3.h"
#include "tutorial14/options/DefaultOptions.h"

namespace tutorial14
Expand All @@ -23,7 +24,8 @@ template <typename TBase, typename TOpt = tutorial14::options::DefaultOptions>
using AllMessages =
std::tuple<
tutorial14::message::Msg1<TBase, TOpt>,
tutorial14::message::Msg2<TBase, TOpt>
tutorial14::message::Msg2<TBase, TOpt>,
tutorial14::message::Msg3<TBase, TOpt>
>;

} // namespace input
Expand All @@ -37,7 +39,8 @@ using AllMessages =
/// @param opts_ Type of the used protocol definition options.
#define TUTORIAL14_ALIASES_FOR_ALL_MESSAGES(prefix_, suffix_, interface_, opts_) \
using prefix_ ## Msg1 ## suffix_ = tutorial14::message::Msg1<interface_, opts_>; \
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>;
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>; \
using prefix_ ## Msg3 ## suffix_ = tutorial14::message::Msg3<interface_, opts_>;

/// @brief Create type aliases for the all messages of the protocol using default options.
/// @param prefix_ Prefix of the alias message type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <tuple>
#include "tutorial14/message/Msg1.h"
#include "tutorial14/message/Msg2.h"
#include "tutorial14/message/Msg3.h"
#include "tutorial14/options/DefaultOptions.h"

namespace tutorial14
Expand All @@ -23,7 +24,8 @@ template <typename TBase, typename TOpt = tutorial14::options::DefaultOptions>
using ClientInputMessages =
std::tuple<
tutorial14::message::Msg1<TBase, TOpt>,
tutorial14::message::Msg2<TBase, TOpt>
tutorial14::message::Msg2<TBase, TOpt>,
tutorial14::message::Msg3<TBase, TOpt>
>;

} // namespace input
Expand All @@ -37,7 +39,8 @@ using ClientInputMessages =
/// @param opts_ Type of the used protocol definition options.
#define TUTORIAL14_ALIASES_FOR_CLIENT_INPUT_MESSAGES(prefix_, suffix_, interface_, opts_) \
using prefix_ ## Msg1 ## suffix_ = tutorial14::message::Msg1<interface_, opts_>; \
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>;
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>; \
using prefix_ ## Msg3 ## suffix_ = tutorial14::message::Msg3<interface_, opts_>;

/// @brief Create type aliases for the client input messages of the protocol using default options.
/// @param prefix_ Prefix of the alias message type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <tuple>
#include "tutorial14/message/Msg1.h"
#include "tutorial14/message/Msg2.h"
#include "tutorial14/message/Msg3.h"
#include "tutorial14/options/DefaultOptions.h"

namespace tutorial14
Expand All @@ -23,7 +24,8 @@ template <typename TBase, typename TOpt = tutorial14::options::DefaultOptions>
using ServerInputMessages =
std::tuple<
tutorial14::message::Msg1<TBase, TOpt>,
tutorial14::message::Msg2<TBase, TOpt>
tutorial14::message::Msg2<TBase, TOpt>,
tutorial14::message::Msg3<TBase, TOpt>
>;

} // namespace input
Expand All @@ -37,7 +39,8 @@ using ServerInputMessages =
/// @param opts_ Type of the used protocol definition options.
#define TUTORIAL14_ALIASES_FOR_SERVER_INPUT_MESSAGES(prefix_, suffix_, interface_, opts_) \
using prefix_ ## Msg1 ## suffix_ = tutorial14::message::Msg1<interface_, opts_>; \
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>;
using prefix_ ## Msg2 ## suffix_ = tutorial14::message::Msg2<interface_, opts_>; \
using prefix_ ## Msg3 ## suffix_ = tutorial14::message::Msg3<interface_, opts_>;

/// @brief Create type aliases for the server input messages of the protocol using default options.
/// @param prefix_ Prefix of the alias message type.
Expand Down
Loading

0 comments on commit 79f917b

Please sign in to comment.