/****************************************************************************** The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com Copyright(c) 2017 John Wellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ #if 0 #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. #endif //*************************************************************************** // THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE. //*************************************************************************** //*************************************************************************** // To generate to header file, run this at the command line. // Note: You will need Python and COG installed. // // python -m cogapp -d -e -omessage_router.h -DHandlers= message_router_generator.h // Where is the maximum number of messages to support. // // e.g. // To generate handlers for up to 16 messages... // python -m cogapp -d -e -omessage_router.h -DHandlers=16 message_router_generator.h // // See generate.bat //*************************************************************************** #ifndef ETL_MESSAGE_ROUTER_INCLUDED #define ETL_MESSAGE_ROUTER_INCLUDED #include "platform.h" #include "message.h" #include "shared_message.h" #if ETL_HAS_VIRTUAL_MESSAGES #include "message_packet.h" #endif #include "message_types.h" #include "alignment.h" #include "error_handler.h" #include "exception.h" #include "largest.h" #include "nullptr.h" #include "placement_new.h" #include "successor.h" #include "type_traits.h" #include namespace etl { //*************************************************************************** /// Base exception class for message router //*************************************************************************** class message_router_exception : public etl::exception { public: message_router_exception(string_type reason_, string_type file_name_, numeric_type line_number_) : etl::exception(reason_, file_name_, line_number_) { } }; //*************************************************************************** /// Router id is out of the legal range. //*************************************************************************** class message_router_illegal_id : public etl::message_router_exception { public: message_router_illegal_id(string_type file_name_, numeric_type line_number_) : message_router_exception(ETL_ERROR_TEXT("message router:illegal id", ETL_MESSAGE_ROUTER_FILE_ID"A"), file_name_, line_number_) { } }; //*************************************************************************** /// Forward declare null message router functionality. //*************************************************************************** class imessage_router; etl::imessage_router& get_null_message_router(); //*************************************************************************** /// This is the base of all message routers. //*************************************************************************** class imessage_router : public etl::successor { public: virtual ~imessage_router() {} virtual void receive(const etl::imessage&) = 0; virtual bool accepts(etl::message_id_t) const = 0; virtual bool is_null_router() const = 0; virtual bool is_producer() const = 0; virtual bool is_consumer() const = 0; //******************************************** virtual void receive(etl::message_router_id_t destination_router_id, const etl::imessage& message) { if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS)) { receive(message); } } //******************************************** virtual void receive(etl::shared_message shared_msg) { receive(shared_msg.get_message()); } //******************************************** virtual void receive(etl::message_router_id_t destination_router_id, etl::shared_message shared_msg) { if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS)) { receive(shared_msg); } } //******************************************** bool accepts(const etl::imessage& msg) const { return accepts(msg.get_message_id()); } //******************************************** etl::message_router_id_t get_message_router_id() const { return message_router_id; } enum { NULL_MESSAGE_ROUTER = 255, MESSAGE_BUS = 254, ALL_MESSAGE_ROUTERS = 253, MESSAGE_BROKER = 252, MESSAGE_ROUTER = 251, MAX_MESSAGE_ROUTER = 249 }; protected: imessage_router(etl::message_router_id_t id_) : message_router_id(id_) { } imessage_router(etl::message_router_id_t id_, imessage_router& successor_) : successor(successor_) , message_router_id(id_) { } private: // Disabled. imessage_router(const imessage_router&); imessage_router& operator =(const imessage_router&); etl::message_router_id_t message_router_id; }; //*************************************************************************** /// This router can be used as a sink for messages or a 'null source' router. //*************************************************************************** class null_message_router : public imessage_router { public: //******************************************** null_message_router() : imessage_router(imessage_router::NULL_MESSAGE_ROUTER) { } //******************************************** null_message_router(etl::imessage_router& successor_) : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_) { } //******************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { if (has_successor()) { get_successor().receive(msg); } } //******************************************** using etl::imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return true; } //******************************************** bool is_producer() const ETL_OVERRIDE { return false; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return false; } //******************************************** static null_message_router& instance() { static null_message_router nmr; return nmr; } }; //*********************************************** /// null message router functionality. inline etl::imessage_router& get_null_message_router() { return etl::null_message_router::instance(); } //*************************************************************************** /// This router can be used as a producer-only of messages, such an interrupt routine. //*************************************************************************** class message_producer : public imessage_router { public: //******************************************** message_producer() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //******************************************** message_producer(etl::imessage_router& successor_) : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_) { } //******************************************** message_producer(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //******************************************** message_producer(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //******************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { if (has_successor()) { get_successor().receive(msg); } } //******************************************** using etl::imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return false; } }; //*************************************************************************** /// Is T ultimately derived from etl::imessage_router? //*************************************************************************** template struct is_message_router : public etl::bool_constant::type>::value> { }; //*************************************************************************** /// Send a message to a router. //*************************************************************************** template static typename etl::enable_if::value && etl::is_message::value, void>::type send_message(TRouter& destination, const TMessage& message) { destination.receive(message); } //*************************************************************************** /// Send a shared message to a router. //*************************************************************************** template static typename etl::enable_if::value, void>::type send_message(TRouter& destination, etl::shared_message message) { destination.receive(message); } //*************************************************************************** /// Send a message to a router with a particular id. //*************************************************************************** template static typename etl::enable_if::value && etl::is_message::value, void>::type send_message(TRouter& destination, etl::message_router_id_t id, const TMessage& message) { destination.receive(id, message); } //*************************************************************************** /// Send a shared message to a router with a particular id. //*************************************************************************** template static typename etl::enable_if::value, void>::type send_message(TRouter& destination, etl::message_router_id_t id, etl::shared_message message) { destination.receive(id, message); } //************************************************************************************************* // For C++17 and above. //************************************************************************************************* #if ETL_USING_CPP17 && !defined(ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** // The definition for all message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const bool was_handled = (receive_message_type(msg) || ...); if (!was_handled) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } } template ::value, int>::type = 0> void receive(const TMessage& msg) { if constexpr (etl::is_one_of::value) { static_cast(this)->on_receive(msg); } else { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { return (accepts_type(id) || ...); } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } private: //******************************************** template bool receive_message_type(const etl::imessage& msg) { if (TMessage::ID == msg.get_message_id()) { static_cast(this)->on_receive(static_cast(msg)); return true; } else { return false; } } //******************************************** template bool accepts_type(etl::message_id_t id) const { if (TMessage::ID == id) { return true; } else { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } }; #else //************************************************************************************************* // For C++14 and below. //************************************************************************************************* //*************************************************************************** // The definition for all 16 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const etl::message_id_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T12::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T13::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T14::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T15::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T16::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID: case T16::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 15 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T12::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T13::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T14::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T15::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 14 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T12::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T13::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T14::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 13 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T12::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T13::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 12 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T12::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: case T12::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 11 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T11::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: case T11::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 10 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T10::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: case T10::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 9 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T9::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: case T9::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 8 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T8::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 7 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T7::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 6 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T6::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 5 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T5::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 4 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T4::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: case T4::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 3 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T3::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: case T3::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 2 message types. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; case T2::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: case T2::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; //*************************************************************************** // Specialisation for 1 message type. //*************************************************************************** template class message_router : public imessage_router { public: #if ETL_HAS_VIRTUAL_MESSAGES typedef etl::message_packet< T1> message_packet; #endif //********************************************** message_router(etl::message_router_id_t id_) : imessage_router(id_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router(etl::message_router_id_t id_, etl::imessage_router& successor_) : imessage_router(id_, successor_) { ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id)); } //********************************************** message_router() : imessage_router(etl::imessage_router::MESSAGE_ROUTER) { } //********************************************** message_router(etl::imessage_router& successor_) : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_) { } //********************************************** using etl::imessage_router::receive; void receive(const etl::imessage& msg) ETL_OVERRIDE { const size_t id = msg.get_message_id(); switch (id) { case T1::ID: static_cast(this)->on_receive(static_cast(msg)); break; default: { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } break; } } } template typename etl::enable_if::value && etl::is_one_of::value, void>::type receive(const TMessage& msg) { static_cast(this)->on_receive(msg); } template typename etl::enable_if::value && !etl::is_one_of::value, void>::type receive(const TMessage& msg) { if (has_successor()) { get_successor().receive(msg); } else { static_cast(this)->on_receive_unknown(msg); } } //********************************************** using imessage_router::accepts; bool accepts(etl::message_id_t id) const ETL_OVERRIDE { switch (id) { case T1::ID: return true; default: { if (has_successor()) { return get_successor().accepts(id); } else { return false; } } } } //******************************************** ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE { return false; } //******************************************** bool is_producer() const ETL_OVERRIDE { return true; } //******************************************** bool is_consumer() const ETL_OVERRIDE { return true; } }; #endif } #endif