Updated QueuedMessageRouter and QueuedFSM examples to use current message frameworks.

This commit is contained in:
John Wellbelove 2021-05-24 20:08:56 +01:00
parent 71e83c1b5e
commit 830d0d00f1
9 changed files with 39 additions and 49 deletions

View File

@ -99,18 +99,18 @@ public:
//*************************************************************************** //***************************************************************************
// The overridden virtual receive function. // The overridden virtual receive function.
//*************************************************************************** //***************************************************************************
void receive(etl::imessage_router& sender_, const etl::imessage& msg_) override void receive(const etl::imessage& msg_) override
{ {
if (accepts(msg_)) if (accepts(msg_))
{ {
// Place in queue. // Place in queue.
queue.emplace(&sender_, msg_); queue.emplace(msg_);
std::cout << "Queueing message " << int(msg_.message_id) << std::endl; std::cout << "Queueing message " << int(msg_.get_message_id()) << std::endl;
} }
else else
{ {
std::cout << "Ignoring message " << int(msg_.message_id) << std::endl; std::cout << "Ignoring message " << int(msg_.get_message_id()) << std::endl;
} }
} }
@ -121,14 +121,13 @@ public:
{ {
while (!queue.empty()) while (!queue.empty())
{ {
Item& item = queue.front(); message_packet& packet = queue.front();
etl::imessage& msg = item.packet.get(); etl::imessage& msg = packet.get();
etl::imessage_router& sender = *item.sender; std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
std::cout << "Processing message " << int(msg.message_id) << std::endl;
// Call the base class's receive function. // Call the base class's receive function.
// This will route it to the correct 'on_event' handler. // This will route it to the correct 'on_event' handler.
etl::fsm::receive(sender, msg); etl::fsm::receive(msg);
queue.pop(); queue.pop();
} }
@ -136,23 +135,10 @@ public:
private: private:
//*************************************************************************** typedef etl::message_packet< Message1, Message2, Message3, Message4> message_packet;
// The item to queue.
//***************************************************************************
struct Item
{
Item(etl::imessage_router* sender_, const etl::imessage& msg_)
: sender(sender_),
packet(msg_)
{
}
etl::imessage_router* sender;
etl::message_packet< Message1, Message2, Message3, Message4> packet; // Defines a packet suitable for all possible messages.
};
// The queue of message items. // The queue of message items.
etl::queue<Item, 10> queue; etl::queue<message_packet, 10> queue;
}; };
//***************************************************************************** //*****************************************************************************
@ -178,33 +164,33 @@ public:
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message1& msg) etl::fsm_state_id_t on_event(const Message1& msg)
{ {
std::cout << " S1 : Received message " << int(msg.message_id) << " : '" << msg.i << "'" << std::endl; std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
std::cout.flush(); std::cout.flush();
return STATE1; return STATE1;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message2& msg) etl::fsm_state_id_t on_event(const Message2& msg)
{ {
std::cout << " S1 : Received message " << int(msg.message_id) << " : '" << msg.d << "'" << std::endl; std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
std::cout.flush(); std::cout.flush();
return STATE1; return STATE1;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message3& msg) etl::fsm_state_id_t on_event(const Message3& msg)
{ {
std::cout << " S1 : Received message " << int(msg.message_id) << " : '" << msg.s << "'" << std::endl; std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
std::cout.flush(); std::cout.flush();
return STATE1; return STATE1;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event_unknown(etl::imessage_router& sender, const etl::imessage& msg) etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
{ {
std::cout << " S1 : Received unknown message " << int(msg.message_id) << std::endl; std::cout << " S1 : Received unknown message " << int(msg.get_message_id()) << std::endl;
std::cout.flush(); std::cout.flush();
return STATE2; return STATE2;
} }
@ -233,30 +219,30 @@ public:
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message1& msg) etl::fsm_state_id_t on_event(const Message1& msg)
{ {
std::cout << " S2 : Received message " << int(msg.message_id) << " : '" << msg.i << "'" << std::endl; std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
return STATE2; return STATE2;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message2& msg) etl::fsm_state_id_t on_event(const Message2& msg)
{ {
std::cout << " S2 : Received message " << int(msg.message_id) << " : '" << msg.d << "'" << std::endl; std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
return STATE2; return STATE2;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Message3& msg) etl::fsm_state_id_t on_event(const Message3& msg)
{ {
std::cout << " S2 : Received message " << int(msg.message_id) << " : '" << msg.s << "'" << std::endl; std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
return STATE2; return STATE2;
} }
//*************************************************************************** //***************************************************************************
etl::fsm_state_id_t on_event_unknown(etl::imessage_router& sender, const etl::imessage& msg) etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
{ {
std::cout << " S2 : Received unknown message " << int(msg.message_id) << std::endl; std::cout << " S2 : Received unknown message " << int(msg.get_message_id()) << std::endl;
return STATE1; return STATE1;
} }
}; };

View File

@ -23,32 +23,32 @@
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid> <ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>QueuedFSM</RootNamespace> <RootNamespace>QueuedFSM</RootNamespace>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View File

@ -39,7 +39,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 20 #define ETL_VERSION_MAJOR 20
#define ETL_VERSION_MINOR 10 #define ETL_VERSION_MINOR 10
#define ETL_VERSION_PATCH 5 #define ETL_VERSION_PATCH 6
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH)

View File

@ -1,6 +1,6 @@
{ {
"name": "ETL Embedded Template Library", "name": "ETL Embedded Template Library",
"version": "20.10.5", "version": "20.10.6",
"author s": { "author s": {
"name": "John Wellbelove", "name": "John Wellbelove",
"email": "john.wellbelove@etlcpp.com" "email": "john.wellbelove@etlcpp.com"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library ETL name=Embedded Template Library ETL
version=20.10.5 version=20.10.6
author= John Wellbelove <john.wellbelove@etlcpp.com> author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com> maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT license=MIT

View File

@ -8,7 +8,7 @@ project('PROJECT_NAME',
'cpp_std=c++17', 'build.cpp_std=c++17', 'cpp_std=c++17', 'build.cpp_std=c++17',
], ],
meson_version: '>=0.54.0', meson_version: '>=0.54.0',
version: '20.10.5' version: '20.10.6'
) )
###################### ######################

View File

@ -1,3 +1,7 @@
===============================================================================
20.10.6
Updated QueuedMessageRouter and QueuedFSM examples to use current message frameworks.
=============================================================================== ===============================================================================
20.10.5 20.10.5
Added container_type to etl::stack, etl::queue and etl::priority_queue. Added container_type to etl::stack, etl::queue and etl::priority_queue.