Embedded Template Library 1.0
Loading...
Searching...
No Matches
message_router.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2017 John Wellbelove
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files(the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions :
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27******************************************************************************/
28
29#if 0
30#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
31#endif
32
33//***************************************************************************
34// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
35//***************************************************************************
36
37//***************************************************************************
38// To generate to header file, run this at the command line.
39// Note: You will need Python and COG installed.
40//
41// python -m cogapp -d -e -omessage_router.h -DHandlers=<n> message_router_generator.h
42// Where <n> is the maximum number of messages to support.
43//
44// e.g.
45// To generate handlers for up to 16 messages...
46// python -m cogapp -d -e -omessage_router.h -DHandlers=16 message_router_generator.h
47//
48// See generate.bat
49//***************************************************************************
50
51#ifndef ETL_MESSAGE_ROUTER_INCLUDED
52#define ETL_MESSAGE_ROUTER_INCLUDED
53
54#include "platform.h"
55#include "message.h"
56#include "shared_message.h"
57#if ETL_HAS_VIRTUAL_MESSAGES
58 #include "message_packet.h"
59#endif
60#include "message_types.h"
61#include "alignment.h"
62#include "error_handler.h"
63#include "exception.h"
64#include "largest.h"
65#include "nullptr.h"
66#include "placement_new.h"
67#include "successor.h"
68#include "type_traits.h"
69
70#include <stdint.h>
71
72namespace etl
73{
74 //***************************************************************************
76 //***************************************************************************
77 class message_router_exception : public etl::exception
78 {
79 public:
80
81 message_router_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
82 : etl::exception(reason_, file_name_, line_number_)
83 {
84 }
85 };
86
87 //***************************************************************************
89 //***************************************************************************
90 class message_router_illegal_id : public etl::message_router_exception
91 {
92 public:
93
94 message_router_illegal_id(string_type file_name_, numeric_type line_number_)
95 : message_router_exception(ETL_ERROR_TEXT("message router:illegal id", ETL_MESSAGE_ROUTER_FILE_ID"A"), file_name_, line_number_)
96 {
97 }
98 };
99
100 //***************************************************************************
102 //***************************************************************************
103 class imessage_router;
104
106
107 //***************************************************************************
109 //***************************************************************************
110 class imessage_router : public etl::successor<imessage_router>
111 {
112 public:
113
114 virtual ~imessage_router() {}
115 virtual void receive(const etl::imessage&) = 0;
116 virtual bool accepts(etl::message_id_t) const = 0;
117 virtual bool is_null_router() const = 0;
118 virtual bool is_producer() const = 0;
119 virtual bool is_consumer() const = 0;
120
121 //********************************************
122 virtual void receive(etl::message_router_id_t destination_router_id, const etl::imessage& message)
123 {
124 if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
125 {
126 receive(message);
127 }
128 }
129
130 //********************************************
131 virtual void receive(etl::shared_message shared_msg)
132 {
133 receive(shared_msg.get_message());
134 }
135
136 //********************************************
137 virtual void receive(etl::message_router_id_t destination_router_id, etl::shared_message shared_msg)
138 {
139 if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
140 {
141 receive(shared_msg);
142 }
143 }
144
145 //********************************************
146 bool accepts(const etl::imessage& msg) const
147 {
148 return accepts(msg.get_message_id());
149 }
150
151 //********************************************
152 etl::message_router_id_t get_message_router_id() const
153 {
154 return message_router_id;
155 }
156
157 enum
158 {
159 NULL_MESSAGE_ROUTER = 255,
160 MESSAGE_BUS = 254,
161 ALL_MESSAGE_ROUTERS = 253,
162 MESSAGE_BROKER = 252,
163 MESSAGE_ROUTER = 251,
164 MAX_MESSAGE_ROUTER = 249
165 };
166
167 protected:
168
169 imessage_router(etl::message_router_id_t id_)
170 : message_router_id(id_)
171 {
172 }
173
174 imessage_router(etl::message_router_id_t id_, imessage_router& successor_)
175 : successor(successor_)
176 , message_router_id(id_)
177 {
178 }
179
180 private:
181
182 // Disabled.
183 imessage_router(const imessage_router&);
184 imessage_router& operator =(const imessage_router&);
185
186 etl::message_router_id_t message_router_id;
187 };
188
189 //***************************************************************************
191 //***************************************************************************
192 class null_message_router : public imessage_router
193 {
194 public:
195
196 //********************************************
197 null_message_router()
198 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER)
199 {
200 }
201
202 //********************************************
203 null_message_router(etl::imessage_router& successor_)
204 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_)
205 {
206 }
207
208 //********************************************
209 using etl::imessage_router::receive;
210
211 void receive(const etl::imessage& msg) ETL_OVERRIDE
212 {
213 if (has_successor())
214 {
215 get_successor().receive(msg);
216 }
217 }
218
219 //********************************************
220 using etl::imessage_router::accepts;
221
222 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
223 {
224 if (has_successor())
225 {
226 return get_successor().accepts(id);
227 }
228 else
229 {
230 return false;
231 }
232 }
233
234 //********************************************
235 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
236 {
237 return true;
238 }
239
240 //********************************************
241 bool is_producer() const ETL_OVERRIDE
242 {
243 return false;
244 }
245
246 //********************************************
247 bool is_consumer() const ETL_OVERRIDE
248 {
249 return false;
250 }
251
252 //********************************************
253 static null_message_router& instance()
254 {
255 static null_message_router nmr;
256 return nmr;
257 }
258 };
259
260 //***********************************************
263 {
264 return etl::null_message_router::instance();
265 }
266
267 //***************************************************************************
269 //***************************************************************************
270 class message_producer : public imessage_router
271 {
272 public:
273
274 //********************************************
275 message_producer()
276 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
277 {
278 }
279
280 //********************************************
281 message_producer(etl::imessage_router& successor_)
282 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_)
283 {
284 }
285
286 //********************************************
287 message_producer(etl::message_router_id_t id_)
288 : imessage_router(id_)
289 {
290 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
291 }
292
293 //********************************************
294 message_producer(etl::message_router_id_t id_, etl::imessage_router& successor_)
295 : imessage_router(id_, successor_)
296 {
297 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
298 }
299
300 //********************************************
301 using etl::imessage_router::receive;
302
303 void receive(const etl::imessage& msg) ETL_OVERRIDE
304 {
305 if (has_successor())
306 {
307 get_successor().receive(msg);
308 }
309 }
310
311 //********************************************
312 using etl::imessage_router::accepts;
313
314 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
315 {
316 if (has_successor())
317 {
318 return get_successor().accepts(id);
319 }
320 else
321 {
322 return false;
323 }
324 }
325
326 //********************************************
327 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
328 {
329 return false;
330 }
331
332 //********************************************
333 bool is_producer() const ETL_OVERRIDE
334 {
335 return true;
336 }
337
338 //********************************************
339 bool is_consumer() const ETL_OVERRIDE
340 {
341 return false;
342 }
343 };
344
345 //***************************************************************************
347 //***************************************************************************
348 template <typename T>
349 struct is_message_router : public etl::bool_constant<etl::is_base_of<etl::imessage_router, typename etl::remove_cvref<T>::type>::value>
350 {
351 };
352
353 //***************************************************************************
355 //***************************************************************************
356 template <typename TRouter, typename TMessage>
357 static
359 send_message(TRouter& destination,
360 const TMessage& message)
361 {
362 destination.receive(message);
363 }
364
365 //***************************************************************************
367 //***************************************************************************
368 template <typename TRouter>
369 static
371 send_message(TRouter& destination,
372 etl::shared_message message)
373 {
375 }
376
377 //***************************************************************************
379 //***************************************************************************
380 template <typename TRouter, typename TMessage>
381 static
383 send_message(TRouter& destination,
384 etl::message_router_id_t id,
385 const TMessage& message)
386 {
387 destination.receive(id, message);
388 }
389
390 //***************************************************************************
392 //***************************************************************************
393 template <typename TRouter>
394 static
396 send_message(TRouter& destination,
398 etl::shared_message message)
399 {
400 destination.receive(id, message);
401 }
402
403//*************************************************************************************************
404// For C++17 and above.
405//*************************************************************************************************
406#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION)
407 //***************************************************************************
408 // The definition for all message types.
409 //***************************************************************************
410 template <typename TDerived, typename... TMessageTypes>
411 class message_router : public imessage_router
412 {
413 public:
414
415#if ETL_HAS_VIRTUAL_MESSAGES
416 typedef etl::message_packet<TMessageTypes...> message_packet;
417#endif
418
419 //**********************************************
420 message_router()
421 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
422 {
423 }
424
425 //**********************************************
426 message_router(etl::imessage_router& successor_)
427 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
428 {
429 }
430
431 //**********************************************
432 message_router(etl::message_router_id_t id_)
433 : imessage_router(id_)
434 {
435 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
436 }
437
438 //**********************************************
439 message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)
440 : imessage_router(id_, successor_)
441 {
442 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
443 }
444
445 //**********************************************
446 using etl::imessage_router::receive;
447
448 void receive(const etl::imessage& msg) ETL_OVERRIDE
449 {
450 const bool was_handled = (receive_message_type<TMessageTypes>(msg) || ...);
451
452 if (!was_handled)
453 {
454 if (has_successor())
455 {
456 get_successor().receive(msg);
457 }
458 else
459 {
460 static_cast<TDerived*>(this)->on_receive_unknown(msg);
461 }
462 }
463 }
464
465 template <typename TMessage, typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value, int>::type = 0>
466 void receive(const TMessage& msg)
467 {
468 if constexpr (etl::is_one_of<TMessage, TMessageTypes...>::value)
469 {
470 static_cast<TDerived*>(this)->on_receive(msg);
471 }
472 else
473 {
474 if (has_successor())
475 {
476 get_successor().receive(msg);
477 }
478 else
479 {
480 static_cast<TDerived*>(this)->on_receive_unknown(msg);
481 }
482 }
483 }
484
485 //**********************************************
486 using imessage_router::accepts;
487
488 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
489 {
490 return (accepts_type<TMessageTypes>(id) || ...);
491 }
492
493 //********************************************
494 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
495 {
496 return false;
497 }
498
499 //********************************************
500 bool is_producer() const ETL_OVERRIDE
501 {
502 return true;
503 }
504
505 //********************************************
506 bool is_consumer() const ETL_OVERRIDE
507 {
508 return true;
509 }
510
511 private:
512
513 //********************************************
514 template <typename TMessage>
515 bool receive_message_type(const etl::imessage& msg)
516 {
517 if (TMessage::ID == msg.get_message_id())
518 {
519 static_cast<TDerived*>(this)->on_receive(static_cast<const TMessage&>(msg));
520 return true;
521 }
522 else
523 {
524 return false;
525 }
526 }
527
528 //********************************************
529 template <typename TMessage>
530 bool accepts_type(etl::message_id_t id) const
531 {
532 if (TMessage::ID == id)
533 {
534 return true;
535 }
536 else
537 {
538 if (has_successor())
539 {
540 return get_successor().accepts(id);
541 }
542 else
543 {
544 return false;
545 }
546 }
547 }
548 };
549#else
550//*************************************************************************************************
551// For C++14 and below.
552//*************************************************************************************************
553 //***************************************************************************
554 // The definition for all 16 message types.
555 //***************************************************************************
556 template <typename TDerived,
557 typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
558 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
559 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
560 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
562 {
563 public:
564
565 #if ETL_HAS_VIRTUAL_MESSAGES
567 #endif
568
569 //**********************************************
572 {
573 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
574 }
575
576 //**********************************************
579 {
580 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
581 }
582
583 //**********************************************
585 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
586 {
587 }
588
589 //**********************************************
591 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
592 {
593 }
594
595 //**********************************************
596 using etl::imessage_router::receive;
597
598 void receive(const etl::imessage& msg) ETL_OVERRIDE
599 {
600 const etl::message_id_t id = msg.get_message_id();
601
602 switch (id)
603 {
604 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
605 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
606 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
607 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
608 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
609 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
610 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
611 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
612 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
613 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
614 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
615 case T12::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T12&>(msg)); break;
616 case T13::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T13&>(msg)); break;
617 case T14::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T14&>(msg)); break;
618 case T15::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T15&>(msg)); break;
619 case T16::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T16&>(msg)); break;
620 default:
621 {
622 if (has_successor())
623 {
624 get_successor().receive(msg);
625 }
626 else
627 {
628 static_cast<TDerived*>(this)->on_receive_unknown(msg);
629 }
630 break;
631 }
632 }
633 }
634
635 template <typename TMessage>
637 receive(const TMessage& msg)
638 {
639 static_cast<TDerived*>(this)->on_receive(msg);
640 }
641
642 template <typename TMessage>
644 receive(const TMessage& msg)
645 {
646 if (has_successor())
647 {
648 get_successor().receive(msg);
649 }
650 else
651 {
652 static_cast<TDerived*>(this)->on_receive_unknown(msg);
653 }
654 }
655
656 //**********************************************
657 using imessage_router::accepts;
658
659 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
660 {
661 switch (id)
662 {
663 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
664 case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID: case T16::ID:
665 return true;
666 default:
667 {
668 if (has_successor())
669 {
670 return get_successor().accepts(id);
671 }
672 else
673 {
674 return false;
675 }
676 }
677 }
678 }
679
680 //********************************************
681 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
682 {
683 return false;
684 }
685
686 //********************************************
687 bool is_producer() const ETL_OVERRIDE
688 {
689 return true;
690 }
691
692 //********************************************
693 bool is_consumer() const ETL_OVERRIDE
694 {
695 return true;
696 }
697 };
698
699 //***************************************************************************
700 // Specialisation for 15 message types.
701 //***************************************************************************
702 template <typename TDerived,
703 typename T1, typename T2, typename T3, typename T4,
704 typename T5, typename T6, typename T7, typename T8,
705 typename T9, typename T10, typename T11, typename T12,
706 typename T13, typename T14, typename T15>
708 : public imessage_router
709 {
710 public:
711
712 #if ETL_HAS_VIRTUAL_MESSAGES
714 #endif
715
716 //**********************************************
719 {
720 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
721 }
722
723 //**********************************************
726 {
727 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
728 }
729
730 //**********************************************
732 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
733 {
734 }
735
736 //**********************************************
738 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
739 {
740 }
741
742 //**********************************************
743 using etl::imessage_router::receive;
744
745 void receive(const etl::imessage& msg) ETL_OVERRIDE
746 {
747 const size_t id = msg.get_message_id();
748
749 switch (id)
750 {
751 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
752 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
753 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
754 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
755 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
756 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
757 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
758 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
759 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
760 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
761 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
762 case T12::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T12&>(msg)); break;
763 case T13::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T13&>(msg)); break;
764 case T14::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T14&>(msg)); break;
765 case T15::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T15&>(msg)); break;
766 default:
767 {
768 if (has_successor())
769 {
770 get_successor().receive(msg);
771 }
772 else
773 {
774 static_cast<TDerived*>(this)->on_receive_unknown(msg);
775 }
776 break;
777 }
778 }
779 }
780
781 template <typename TMessage>
783 receive(const TMessage& msg)
784 {
785 static_cast<TDerived*>(this)->on_receive(msg);
786 }
787
788 template <typename TMessage>
790 receive(const TMessage& msg)
791 {
792 if (has_successor())
793 {
794 get_successor().receive(msg);
795 }
796 else
797 {
798 static_cast<TDerived*>(this)->on_receive_unknown(msg);
799 }
800 }
801
802
803 //**********************************************
804 using imessage_router::accepts;
805
806 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
807 {
808 switch (id)
809 {
810 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
811 case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID:
812 return true;
813 default:
814 {
815 if (has_successor())
816 {
817 return get_successor().accepts(id);
818 }
819 else
820 {
821 return false;
822 }
823 }
824 }
825 }
826
827 //********************************************
828 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
829 {
830 return false;
831 }
832
833 //********************************************
834 bool is_producer() const ETL_OVERRIDE
835 {
836 return true;
837 }
838
839 //********************************************
840 bool is_consumer() const ETL_OVERRIDE
841 {
842 return true;
843 }
844 };
845
846 //***************************************************************************
847 // Specialisation for 14 message types.
848 //***************************************************************************
849 template <typename TDerived,
850 typename T1, typename T2, typename T3, typename T4,
851 typename T5, typename T6, typename T7, typename T8,
852 typename T9, typename T10, typename T11, typename T12,
853 typename T13, typename T14>
855 : public imessage_router
856 {
857 public:
858
859 #if ETL_HAS_VIRTUAL_MESSAGES
861 #endif
862
863 //**********************************************
866 {
867 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
868 }
869
870 //**********************************************
873 {
874 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
875 }
876
877 //**********************************************
879 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
880 {
881 }
882
883 //**********************************************
885 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
886 {
887 }
888
889 //**********************************************
890 using etl::imessage_router::receive;
891
892 void receive(const etl::imessage& msg) ETL_OVERRIDE
893 {
894 const size_t id = msg.get_message_id();
895
896 switch (id)
897 {
898 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
899 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
900 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
901 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
902 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
903 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
904 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
905 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
906 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
907 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
908 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
909 case T12::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T12&>(msg)); break;
910 case T13::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T13&>(msg)); break;
911 case T14::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T14&>(msg)); break;
912 default:
913 {
914 if (has_successor())
915 {
916 get_successor().receive(msg);
917 }
918 else
919 {
920 static_cast<TDerived*>(this)->on_receive_unknown(msg);
921 }
922 break;
923 }
924 }
925 }
926
927 template <typename TMessage>
929 receive(const TMessage& msg)
930 {
931 static_cast<TDerived*>(this)->on_receive(msg);
932 }
933
934 template <typename TMessage>
936 receive(const TMessage& msg)
937 {
938 if (has_successor())
939 {
940 get_successor().receive(msg);
941 }
942 else
943 {
944 static_cast<TDerived*>(this)->on_receive_unknown(msg);
945 }
946 }
947
948
949 //**********************************************
950 using imessage_router::accepts;
951
952 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
953 {
954 switch (id)
955 {
956 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
957 case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID:
958 return true;
959 default:
960 {
961 if (has_successor())
962 {
963 return get_successor().accepts(id);
964 }
965 else
966 {
967 return false;
968 }
969 }
970 }
971 }
972
973 //********************************************
974 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
975 {
976 return false;
977 }
978
979 //********************************************
980 bool is_producer() const ETL_OVERRIDE
981 {
982 return true;
983 }
984
985 //********************************************
986 bool is_consumer() const ETL_OVERRIDE
987 {
988 return true;
989 }
990 };
991
992 //***************************************************************************
993 // Specialisation for 13 message types.
994 //***************************************************************************
995 template <typename TDerived,
996 typename T1, typename T2, typename T3, typename T4,
997 typename T5, typename T6, typename T7, typename T8,
998 typename T9, typename T10, typename T11, typename T12,
999 typename T13>
1001 : public imessage_router
1002 {
1003 public:
1004
1005 #if ETL_HAS_VIRTUAL_MESSAGES
1007 #endif
1008
1009 //**********************************************
1012 {
1013 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1014 }
1015
1016 //**********************************************
1019 {
1020 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1021 }
1022
1023 //**********************************************
1025 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1026 {
1027 }
1028
1029 //**********************************************
1031 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1032 {
1033 }
1034
1035 //**********************************************
1036 using etl::imessage_router::receive;
1037
1038 void receive(const etl::imessage& msg) ETL_OVERRIDE
1039 {
1040 const size_t id = msg.get_message_id();
1041
1042 switch (id)
1043 {
1044 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1045 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1046 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1047 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1048 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1049 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1050 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1051 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1052 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
1053 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
1054 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
1055 case T12::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T12&>(msg)); break;
1056 case T13::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T13&>(msg)); break;
1057 default:
1058 {
1059 if (has_successor())
1060 {
1061 get_successor().receive(msg);
1062 }
1063 else
1064 {
1065 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1066 }
1067 break;
1068 }
1069 }
1070 }
1071
1072 template <typename TMessage>
1074 receive(const TMessage& msg)
1075 {
1076 static_cast<TDerived*>(this)->on_receive(msg);
1077 }
1078
1079 template <typename TMessage>
1081 receive(const TMessage& msg)
1082 {
1083 if (has_successor())
1084 {
1085 get_successor().receive(msg);
1086 }
1087 else
1088 {
1089 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1090 }
1091 }
1092
1093
1094 //**********************************************
1095 using imessage_router::accepts;
1096
1097 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1098 {
1099 switch (id)
1100 {
1101 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1102 case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID:
1103 return true;
1104 default:
1105 {
1106 if (has_successor())
1107 {
1108 return get_successor().accepts(id);
1109 }
1110 else
1111 {
1112 return false;
1113 }
1114 }
1115 }
1116 }
1117
1118 //********************************************
1119 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1120 {
1121 return false;
1122 }
1123
1124 //********************************************
1125 bool is_producer() const ETL_OVERRIDE
1126 {
1127 return true;
1128 }
1129
1130 //********************************************
1131 bool is_consumer() const ETL_OVERRIDE
1132 {
1133 return true;
1134 }
1135 };
1136
1137 //***************************************************************************
1138 // Specialisation for 12 message types.
1139 //***************************************************************************
1140 template <typename TDerived,
1141 typename T1, typename T2, typename T3, typename T4,
1142 typename T5, typename T6, typename T7, typename T8,
1143 typename T9, typename T10, typename T11, typename T12>
1145 : public imessage_router
1146 {
1147 public:
1148
1149 #if ETL_HAS_VIRTUAL_MESSAGES
1151 #endif
1152
1153 //**********************************************
1156 {
1157 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1158 }
1159
1160 //**********************************************
1163 {
1164 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1165 }
1166
1167 //**********************************************
1169 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1170 {
1171 }
1172
1173 //**********************************************
1175 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1176 {
1177 }
1178
1179 //**********************************************
1180 using etl::imessage_router::receive;
1181
1182 void receive(const etl::imessage& msg) ETL_OVERRIDE
1183 {
1184 const size_t id = msg.get_message_id();
1185
1186 switch (id)
1187 {
1188 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1189 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1190 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1191 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1192 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1193 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1194 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1195 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1196 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
1197 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
1198 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
1199 case T12::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T12&>(msg)); break;
1200 default:
1201 {
1202 if (has_successor())
1203 {
1204 get_successor().receive(msg);
1205 }
1206 else
1207 {
1208 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1209 }
1210 break;
1211 }
1212 }
1213 }
1214
1215 template <typename TMessage>
1217 receive(const TMessage& msg)
1218 {
1219 static_cast<TDerived*>(this)->on_receive(msg);
1220 }
1221
1222 template <typename TMessage>
1224 receive(const TMessage& msg)
1225 {
1226 if (has_successor())
1227 {
1228 get_successor().receive(msg);
1229 }
1230 else
1231 {
1232 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1233 }
1234 }
1235
1236
1237 //**********************************************
1238 using imessage_router::accepts;
1239
1240 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1241 {
1242 switch (id)
1243 {
1244 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1245 case T9::ID: case T10::ID: case T11::ID: case T12::ID:
1246 return true;
1247 default:
1248 {
1249 if (has_successor())
1250 {
1251 return get_successor().accepts(id);
1252 }
1253 else
1254 {
1255 return false;
1256 }
1257 }
1258 }
1259 }
1260
1261 //********************************************
1262 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1263 {
1264 return false;
1265 }
1266
1267 //********************************************
1268 bool is_producer() const ETL_OVERRIDE
1269 {
1270 return true;
1271 }
1272
1273 //********************************************
1274 bool is_consumer() const ETL_OVERRIDE
1275 {
1276 return true;
1277 }
1278 };
1279
1280 //***************************************************************************
1281 // Specialisation for 11 message types.
1282 //***************************************************************************
1283 template <typename TDerived,
1284 typename T1, typename T2, typename T3, typename T4,
1285 typename T5, typename T6, typename T7, typename T8,
1286 typename T9, typename T10, typename T11>
1288 : public imessage_router
1289 {
1290 public:
1291
1292 #if ETL_HAS_VIRTUAL_MESSAGES
1294 #endif
1295
1296 //**********************************************
1299 {
1300 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1301 }
1302
1303 //**********************************************
1306 {
1307 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1308 }
1309
1310 //**********************************************
1312 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1313 {
1314 }
1315
1316 //**********************************************
1318 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1319 {
1320 }
1321
1322 //**********************************************
1323 using etl::imessage_router::receive;
1324
1325 void receive(const etl::imessage& msg) ETL_OVERRIDE
1326 {
1327 const size_t id = msg.get_message_id();
1328
1329 switch (id)
1330 {
1331 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1332 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1333 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1334 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1335 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1336 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1337 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1338 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1339 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
1340 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
1341 case T11::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T11&>(msg)); break;
1342 default:
1343 {
1344 if (has_successor())
1345 {
1346 get_successor().receive(msg);
1347 }
1348 else
1349 {
1350 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1351 }
1352 break;
1353 }
1354 }
1355 }
1356
1357 template <typename TMessage>
1359 receive(const TMessage& msg)
1360 {
1361 static_cast<TDerived*>(this)->on_receive(msg);
1362 }
1363
1364 template <typename TMessage>
1366 receive(const TMessage& msg)
1367 {
1368 if (has_successor())
1369 {
1370 get_successor().receive(msg);
1371 }
1372 else
1373 {
1374 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1375 }
1376 }
1377
1378
1379 //**********************************************
1380 using imessage_router::accepts;
1381
1382 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1383 {
1384 switch (id)
1385 {
1386 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1387 case T9::ID: case T10::ID: case T11::ID:
1388 return true;
1389 default:
1390 {
1391 if (has_successor())
1392 {
1393 return get_successor().accepts(id);
1394 }
1395 else
1396 {
1397 return false;
1398 }
1399 }
1400 }
1401 }
1402
1403 //********************************************
1404 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1405 {
1406 return false;
1407 }
1408
1409 //********************************************
1410 bool is_producer() const ETL_OVERRIDE
1411 {
1412 return true;
1413 }
1414
1415 //********************************************
1416 bool is_consumer() const ETL_OVERRIDE
1417 {
1418 return true;
1419 }
1420 };
1421
1422 //***************************************************************************
1423 // Specialisation for 10 message types.
1424 //***************************************************************************
1425 template <typename TDerived,
1426 typename T1, typename T2, typename T3, typename T4,
1427 typename T5, typename T6, typename T7, typename T8,
1428 typename T9, typename T10>
1430 : public imessage_router
1431 {
1432 public:
1433
1434 #if ETL_HAS_VIRTUAL_MESSAGES
1436 #endif
1437
1438 //**********************************************
1441 {
1442 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1443 }
1444
1445 //**********************************************
1448 {
1449 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1450 }
1451
1452 //**********************************************
1454 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1455 {
1456 }
1457
1458 //**********************************************
1460 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1461 {
1462 }
1463
1464 //**********************************************
1465 using etl::imessage_router::receive;
1466
1467 void receive(const etl::imessage& msg) ETL_OVERRIDE
1468 {
1469 const size_t id = msg.get_message_id();
1470
1471 switch (id)
1472 {
1473 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1474 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1475 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1476 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1477 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1478 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1479 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1480 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1481 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
1482 case T10::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T10&>(msg)); break;
1483 default:
1484 {
1485 if (has_successor())
1486 {
1487 get_successor().receive(msg);
1488 }
1489 else
1490 {
1491 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1492 }
1493 break;
1494 }
1495 }
1496 }
1497
1498 template <typename TMessage>
1500 receive(const TMessage& msg)
1501 {
1502 static_cast<TDerived*>(this)->on_receive(msg);
1503 }
1504
1505 template <typename TMessage>
1507 receive(const TMessage& msg)
1508 {
1509 if (has_successor())
1510 {
1511 get_successor().receive(msg);
1512 }
1513 else
1514 {
1515 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1516 }
1517 }
1518
1519
1520 //**********************************************
1521 using imessage_router::accepts;
1522
1523 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1524 {
1525 switch (id)
1526 {
1527 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1528 case T9::ID: case T10::ID:
1529 return true;
1530 default:
1531 {
1532 if (has_successor())
1533 {
1534 return get_successor().accepts(id);
1535 }
1536 else
1537 {
1538 return false;
1539 }
1540 }
1541 }
1542 }
1543
1544 //********************************************
1545 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1546 {
1547 return false;
1548 }
1549
1550 //********************************************
1551 bool is_producer() const ETL_OVERRIDE
1552 {
1553 return true;
1554 }
1555
1556 //********************************************
1557 bool is_consumer() const ETL_OVERRIDE
1558 {
1559 return true;
1560 }
1561 };
1562
1563 //***************************************************************************
1564 // Specialisation for 9 message types.
1565 //***************************************************************************
1566 template <typename TDerived,
1567 typename T1, typename T2, typename T3, typename T4,
1568 typename T5, typename T6, typename T7, typename T8,
1569 typename T9>
1571 : public imessage_router
1572 {
1573 public:
1574
1575 #if ETL_HAS_VIRTUAL_MESSAGES
1577 #endif
1578
1579 //**********************************************
1582 {
1583 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1584 }
1585
1586 //**********************************************
1589 {
1590 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1591 }
1592
1593 //**********************************************
1595 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1596 {
1597 }
1598
1599 //**********************************************
1601 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1602 {
1603 }
1604
1605 //**********************************************
1606 using etl::imessage_router::receive;
1607
1608 void receive(const etl::imessage& msg) ETL_OVERRIDE
1609 {
1610 const size_t id = msg.get_message_id();
1611
1612 switch (id)
1613 {
1614 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1615 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1616 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1617 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1618 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1619 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1620 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1621 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1622 case T9::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T9&>(msg)); break;
1623 default:
1624 {
1625 if (has_successor())
1626 {
1627 get_successor().receive(msg);
1628 }
1629 else
1630 {
1631 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1632 }
1633 break;
1634 }
1635 }
1636 }
1637
1638 template <typename TMessage>
1640 receive(const TMessage& msg)
1641 {
1642 static_cast<TDerived*>(this)->on_receive(msg);
1643 }
1644
1645 template <typename TMessage>
1647 receive(const TMessage& msg)
1648 {
1649 if (has_successor())
1650 {
1651 get_successor().receive(msg);
1652 }
1653 else
1654 {
1655 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1656 }
1657 }
1658
1659
1660 //**********************************************
1661 using imessage_router::accepts;
1662
1663 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1664 {
1665 switch (id)
1666 {
1667 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1668 case T9::ID:
1669 return true;
1670 default:
1671 {
1672 if (has_successor())
1673 {
1674 return get_successor().accepts(id);
1675 }
1676 else
1677 {
1678 return false;
1679 }
1680 }
1681 }
1682 }
1683
1684 //********************************************
1685 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1686 {
1687 return false;
1688 }
1689
1690 //********************************************
1691 bool is_producer() const ETL_OVERRIDE
1692 {
1693 return true;
1694 }
1695
1696 //********************************************
1697 bool is_consumer() const ETL_OVERRIDE
1698 {
1699 return true;
1700 }
1701 };
1702
1703 //***************************************************************************
1704 // Specialisation for 8 message types.
1705 //***************************************************************************
1706 template <typename TDerived,
1707 typename T1, typename T2, typename T3, typename T4,
1708 typename T5, typename T6, typename T7, typename T8>
1710 : public imessage_router
1711 {
1712 public:
1713
1714 #if ETL_HAS_VIRTUAL_MESSAGES
1716 #endif
1717
1718 //**********************************************
1721 {
1722 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1723 }
1724
1725 //**********************************************
1728 {
1729 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1730 }
1731
1732 //**********************************************
1734 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1735 {
1736 }
1737
1738 //**********************************************
1740 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1741 {
1742 }
1743
1744 //**********************************************
1745 using etl::imessage_router::receive;
1746
1747 void receive(const etl::imessage& msg) ETL_OVERRIDE
1748 {
1749 const size_t id = msg.get_message_id();
1750
1751 switch (id)
1752 {
1753 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1754 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1755 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1756 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1757 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1758 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1759 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1760 case T8::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T8&>(msg)); break;
1761 default:
1762 {
1763 if (has_successor())
1764 {
1765 get_successor().receive(msg);
1766 }
1767 else
1768 {
1769 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1770 }
1771 break;
1772 }
1773 }
1774 }
1775
1776 template <typename TMessage>
1778 receive(const TMessage& msg)
1779 {
1780 static_cast<TDerived*>(this)->on_receive(msg);
1781 }
1782
1783 template <typename TMessage>
1785 receive(const TMessage& msg)
1786 {
1787 if (has_successor())
1788 {
1789 get_successor().receive(msg);
1790 }
1791 else
1792 {
1793 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1794 }
1795 }
1796
1797
1798 //**********************************************
1799 using imessage_router::accepts;
1800
1801 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1802 {
1803 switch (id)
1804 {
1805 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
1806
1807 return true;
1808 default:
1809 {
1810 if (has_successor())
1811 {
1812 return get_successor().accepts(id);
1813 }
1814 else
1815 {
1816 return false;
1817 }
1818 }
1819 }
1820 }
1821
1822 //********************************************
1823 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1824 {
1825 return false;
1826 }
1827
1828 //********************************************
1829 bool is_producer() const ETL_OVERRIDE
1830 {
1831 return true;
1832 }
1833
1834 //********************************************
1835 bool is_consumer() const ETL_OVERRIDE
1836 {
1837 return true;
1838 }
1839 };
1840
1841 //***************************************************************************
1842 // Specialisation for 7 message types.
1843 //***************************************************************************
1844 template <typename TDerived,
1845 typename T1, typename T2, typename T3, typename T4,
1846 typename T5, typename T6, typename T7>
1848 : public imessage_router
1849 {
1850 public:
1851
1852 #if ETL_HAS_VIRTUAL_MESSAGES
1854 #endif
1855
1856 //**********************************************
1859 {
1860 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1861 }
1862
1863 //**********************************************
1866 {
1867 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1868 }
1869
1870 //**********************************************
1872 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
1873 {
1874 }
1875
1876 //**********************************************
1878 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
1879 {
1880 }
1881
1882 //**********************************************
1883 using etl::imessage_router::receive;
1884
1885 void receive(const etl::imessage& msg) ETL_OVERRIDE
1886 {
1887 const size_t id = msg.get_message_id();
1888
1889 switch (id)
1890 {
1891 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
1892 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
1893 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
1894 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
1895 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
1896 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
1897 case T7::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T7&>(msg)); break;
1898 default:
1899 {
1900 if (has_successor())
1901 {
1902 get_successor().receive(msg);
1903 }
1904 else
1905 {
1906 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1907 }
1908 break;
1909 }
1910 }
1911 }
1912
1913 template <typename TMessage>
1915 receive(const TMessage& msg)
1916 {
1917 static_cast<TDerived*>(this)->on_receive(msg);
1918 }
1919
1920 template <typename TMessage>
1922 receive(const TMessage& msg)
1923 {
1924 if (has_successor())
1925 {
1926 get_successor().receive(msg);
1927 }
1928 else
1929 {
1930 static_cast<TDerived*>(this)->on_receive_unknown(msg);
1931 }
1932 }
1933
1934
1935 //**********************************************
1936 using imessage_router::accepts;
1937
1938 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
1939 {
1940 switch (id)
1941 {
1942 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID:
1943 return true;
1944 default:
1945 {
1946 if (has_successor())
1947 {
1948 return get_successor().accepts(id);
1949 }
1950 else
1951 {
1952 return false;
1953 }
1954 }
1955 }
1956 }
1957
1958 //********************************************
1959 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
1960 {
1961 return false;
1962 }
1963
1964 //********************************************
1965 bool is_producer() const ETL_OVERRIDE
1966 {
1967 return true;
1968 }
1969
1970 //********************************************
1971 bool is_consumer() const ETL_OVERRIDE
1972 {
1973 return true;
1974 }
1975 };
1976
1977 //***************************************************************************
1978 // Specialisation for 6 message types.
1979 //***************************************************************************
1980 template <typename TDerived,
1981 typename T1, typename T2, typename T3, typename T4,
1982 typename T5, typename T6>
1984 : public imessage_router
1985 {
1986 public:
1987
1988 #if ETL_HAS_VIRTUAL_MESSAGES
1990 #endif
1991
1992 //**********************************************
1995 {
1996 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
1997 }
1998
1999 //**********************************************
2002 {
2003 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2004 }
2005
2006 //**********************************************
2008 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2009 {
2010 }
2011
2012 //**********************************************
2014 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2015 {
2016 }
2017
2018 //**********************************************
2019 using etl::imessage_router::receive;
2020
2021 void receive(const etl::imessage& msg) ETL_OVERRIDE
2022 {
2023 const size_t id = msg.get_message_id();
2024
2025 switch (id)
2026 {
2027 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2028 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
2029 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
2030 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
2031 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
2032 case T6::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T6&>(msg)); break;
2033 default:
2034 {
2035 if (has_successor())
2036 {
2037 get_successor().receive(msg);
2038 }
2039 else
2040 {
2041 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2042 }
2043 break;
2044 }
2045 }
2046 }
2047
2048 template <typename TMessage>
2050 receive(const TMessage& msg)
2051 {
2052 static_cast<TDerived*>(this)->on_receive(msg);
2053 }
2054
2055 template <typename TMessage>
2057 receive(const TMessage& msg)
2058 {
2059 if (has_successor())
2060 {
2061 get_successor().receive(msg);
2062 }
2063 else
2064 {
2065 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2066 }
2067 }
2068
2069
2070 //**********************************************
2071 using imessage_router::accepts;
2072
2073 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2074 {
2075 switch (id)
2076 {
2077 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID:
2078 return true;
2079 default:
2080 {
2081 if (has_successor())
2082 {
2083 return get_successor().accepts(id);
2084 }
2085 else
2086 {
2087 return false;
2088 }
2089 }
2090 }
2091 }
2092
2093 //********************************************
2094 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2095 {
2096 return false;
2097 }
2098
2099 //********************************************
2100 bool is_producer() const ETL_OVERRIDE
2101 {
2102 return true;
2103 }
2104
2105 //********************************************
2106 bool is_consumer() const ETL_OVERRIDE
2107 {
2108 return true;
2109 }
2110 };
2111
2112 //***************************************************************************
2113 // Specialisation for 5 message types.
2114 //***************************************************************************
2115 template <typename TDerived,
2116 typename T1, typename T2, typename T3, typename T4,
2117 typename T5>
2119 : public imessage_router
2120 {
2121 public:
2122
2123 #if ETL_HAS_VIRTUAL_MESSAGES
2125 #endif
2126
2127 //**********************************************
2130 {
2131 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2132 }
2133
2134 //**********************************************
2137 {
2138 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2139 }
2140
2141 //**********************************************
2143 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2144 {
2145 }
2146
2147 //**********************************************
2149 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2150 {
2151 }
2152
2153 //**********************************************
2154 using etl::imessage_router::receive;
2155
2156 void receive(const etl::imessage& msg) ETL_OVERRIDE
2157 {
2158 const size_t id = msg.get_message_id();
2159
2160 switch (id)
2161 {
2162 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2163 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
2164 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
2165 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
2166 case T5::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T5&>(msg)); break;
2167 default:
2168 {
2169 if (has_successor())
2170 {
2171 get_successor().receive(msg);
2172 }
2173 else
2174 {
2175 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2176 }
2177 break;
2178 }
2179 }
2180 }
2181
2182 template <typename TMessage>
2184 receive(const TMessage& msg)
2185 {
2186 static_cast<TDerived*>(this)->on_receive(msg);
2187 }
2188
2189 template <typename TMessage>
2191 receive(const TMessage& msg)
2192 {
2193 if (has_successor())
2194 {
2195 get_successor().receive(msg);
2196 }
2197 else
2198 {
2199 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2200 }
2201 }
2202
2203
2204 //**********************************************
2205 using imessage_router::accepts;
2206
2207 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2208 {
2209 switch (id)
2210 {
2211 case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID:
2212 return true;
2213 default:
2214 {
2215 if (has_successor())
2216 {
2217 return get_successor().accepts(id);
2218 }
2219 else
2220 {
2221 return false;
2222 }
2223 }
2224 }
2225 }
2226
2227 //********************************************
2228 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2229 {
2230 return false;
2231 }
2232
2233 //********************************************
2234 bool is_producer() const ETL_OVERRIDE
2235 {
2236 return true;
2237 }
2238
2239 //********************************************
2240 bool is_consumer() const ETL_OVERRIDE
2241 {
2242 return true;
2243 }
2244 };
2245
2246 //***************************************************************************
2247 // Specialisation for 4 message types.
2248 //***************************************************************************
2249 template <typename TDerived,
2250 typename T1, typename T2, typename T3, typename T4>
2252 : public imessage_router
2253 {
2254 public:
2255
2256 #if ETL_HAS_VIRTUAL_MESSAGES
2258 #endif
2259
2260 //**********************************************
2263 {
2264 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2265 }
2266
2267 //**********************************************
2270 {
2271 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2272 }
2273
2274 //**********************************************
2276 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2277 {
2278 }
2279
2280 //**********************************************
2282 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2283 {
2284 }
2285
2286 //**********************************************
2287 using etl::imessage_router::receive;
2288
2289 void receive(const etl::imessage& msg) ETL_OVERRIDE
2290 {
2291 const size_t id = msg.get_message_id();
2292
2293 switch (id)
2294 {
2295 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2296 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
2297 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
2298 case T4::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T4&>(msg)); break;
2299 default:
2300 {
2301 if (has_successor())
2302 {
2303 get_successor().receive(msg);
2304 }
2305 else
2306 {
2307 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2308 }
2309 break;
2310 }
2311 }
2312 }
2313
2314 template <typename TMessage>
2316 receive(const TMessage& msg)
2317 {
2318 static_cast<TDerived*>(this)->on_receive(msg);
2319 }
2320
2321 template <typename TMessage>
2323 receive(const TMessage& msg)
2324 {
2325 if (has_successor())
2326 {
2327 get_successor().receive(msg);
2328 }
2329 else
2330 {
2331 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2332 }
2333 }
2334
2335
2336 //**********************************************
2337 using imessage_router::accepts;
2338
2339 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2340 {
2341 switch (id)
2342 {
2343 case T1::ID: case T2::ID: case T3::ID: case T4::ID:
2344 return true;
2345 default:
2346 {
2347 if (has_successor())
2348 {
2349 return get_successor().accepts(id);
2350 }
2351 else
2352 {
2353 return false;
2354 }
2355 }
2356 }
2357 }
2358
2359 //********************************************
2360 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2361 {
2362 return false;
2363 }
2364
2365 //********************************************
2366 bool is_producer() const ETL_OVERRIDE
2367 {
2368 return true;
2369 }
2370
2371 //********************************************
2372 bool is_consumer() const ETL_OVERRIDE
2373 {
2374 return true;
2375 }
2376 };
2377
2378 //***************************************************************************
2379 // Specialisation for 3 message types.
2380 //***************************************************************************
2381 template <typename TDerived,
2382 typename T1, typename T2, typename T3>
2384 : public imessage_router
2385 {
2386 public:
2387
2388 #if ETL_HAS_VIRTUAL_MESSAGES
2390 #endif
2391
2392 //**********************************************
2395 {
2396 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2397 }
2398
2399 //**********************************************
2402 {
2403 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2404 }
2405
2406 //**********************************************
2408 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2409 {
2410 }
2411
2412 //**********************************************
2414 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2415 {
2416 }
2417
2418 //**********************************************
2419 using etl::imessage_router::receive;
2420
2421 void receive(const etl::imessage& msg) ETL_OVERRIDE
2422 {
2423 const size_t id = msg.get_message_id();
2424
2425 switch (id)
2426 {
2427 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2428 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
2429 case T3::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T3&>(msg)); break;
2430 default:
2431 {
2432 if (has_successor())
2433 {
2434 get_successor().receive(msg);
2435 }
2436 else
2437 {
2438 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2439 }
2440 break;
2441 }
2442 }
2443 }
2444
2445 template <typename TMessage>
2447 receive(const TMessage& msg)
2448 {
2449 static_cast<TDerived*>(this)->on_receive(msg);
2450 }
2451
2452 template <typename TMessage>
2454 receive(const TMessage& msg)
2455 {
2456 if (has_successor())
2457 {
2458 get_successor().receive(msg);
2459 }
2460 else
2461 {
2462 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2463 }
2464 }
2465
2466
2467 //**********************************************
2468 using imessage_router::accepts;
2469
2470 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2471 {
2472 switch (id)
2473 {
2474 case T1::ID: case T2::ID: case T3::ID:
2475 return true;
2476 default:
2477 {
2478 if (has_successor())
2479 {
2480 return get_successor().accepts(id);
2481 }
2482 else
2483 {
2484 return false;
2485 }
2486 }
2487 }
2488 }
2489
2490 //********************************************
2491 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2492 {
2493 return false;
2494 }
2495
2496 //********************************************
2497 bool is_producer() const ETL_OVERRIDE
2498 {
2499 return true;
2500 }
2501
2502 //********************************************
2503 bool is_consumer() const ETL_OVERRIDE
2504 {
2505 return true;
2506 }
2507 };
2508
2509 //***************************************************************************
2510 // Specialisation for 2 message types.
2511 //***************************************************************************
2512 template <typename TDerived,
2513 typename T1, typename T2>
2515 : public imessage_router
2516 {
2517 public:
2518
2519 #if ETL_HAS_VIRTUAL_MESSAGES
2521 #endif
2522
2523 //**********************************************
2526 {
2527 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2528 }
2529
2530 //**********************************************
2533 {
2534 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2535 }
2536
2537 //**********************************************
2539 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2540 {
2541 }
2542
2543 //**********************************************
2545 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2546 {
2547 }
2548
2549 //**********************************************
2550 using etl::imessage_router::receive;
2551
2552 void receive(const etl::imessage& msg) ETL_OVERRIDE
2553 {
2554 const size_t id = msg.get_message_id();
2555
2556 switch (id)
2557 {
2558 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2559 case T2::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T2&>(msg)); break;
2560 default:
2561 {
2562 if (has_successor())
2563 {
2564 get_successor().receive(msg);
2565 }
2566 else
2567 {
2568 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2569 }
2570 break;
2571 }
2572 }
2573 }
2574
2575 template <typename TMessage>
2577 receive(const TMessage& msg)
2578 {
2579 static_cast<TDerived*>(this)->on_receive(msg);
2580 }
2581
2582 template <typename TMessage>
2584 receive(const TMessage& msg)
2585 {
2586 if (has_successor())
2587 {
2588 get_successor().receive(msg);
2589 }
2590 else
2591 {
2592 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2593 }
2594 }
2595
2596
2597 //**********************************************
2598 using imessage_router::accepts;
2599
2600 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2601 {
2602 switch (id)
2603 {
2604 case T1::ID: case T2::ID:
2605 return true;
2606 default:
2607 {
2608 if (has_successor())
2609 {
2610 return get_successor().accepts(id);
2611 }
2612 else
2613 {
2614 return false;
2615 }
2616 }
2617 }
2618 }
2619
2620 //********************************************
2621 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2622 {
2623 return false;
2624 }
2625
2626 //********************************************
2627 bool is_producer() const ETL_OVERRIDE
2628 {
2629 return true;
2630 }
2631
2632 //********************************************
2633 bool is_consumer() const ETL_OVERRIDE
2634 {
2635 return true;
2636 }
2637 };
2638
2639 //***************************************************************************
2640 // Specialisation for 1 message type.
2641 //***************************************************************************
2642 template <typename TDerived,
2643 typename T1>
2645 : public imessage_router
2646 {
2647 public:
2648
2649 #if ETL_HAS_VIRTUAL_MESSAGES
2651 #endif
2652
2653 //**********************************************
2656 {
2657 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2658 }
2659
2660 //**********************************************
2663 {
2664 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
2665 }
2666
2667 //**********************************************
2669 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
2670 {
2671 }
2672
2673 //**********************************************
2675 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
2676 {
2677 }
2678
2679 //**********************************************
2680 using etl::imessage_router::receive;
2681
2682 void receive(const etl::imessage& msg) ETL_OVERRIDE
2683 {
2684 const size_t id = msg.get_message_id();
2685
2686 switch (id)
2687 {
2688 case T1::ID: static_cast<TDerived*>(this)->on_receive(static_cast<const T1&>(msg)); break;
2689 default:
2690 {
2691 if (has_successor())
2692 {
2693 get_successor().receive(msg);
2694 }
2695 else
2696 {
2697 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2698 }
2699 break;
2700 }
2701 }
2702 }
2703
2704 template <typename TMessage>
2706 receive(const TMessage& msg)
2707 {
2708 static_cast<TDerived*>(this)->on_receive(msg);
2709 }
2710
2711 template <typename TMessage>
2713 receive(const TMessage& msg)
2714 {
2715 if (has_successor())
2716 {
2717 get_successor().receive(msg);
2718 }
2719 else
2720 {
2721 static_cast<TDerived*>(this)->on_receive_unknown(msg);
2722 }
2723 }
2724
2725
2726 //**********************************************
2727 using imessage_router::accepts;
2728
2729 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
2730 {
2731 switch (id)
2732 {
2733 case T1::ID:
2734 return true;
2735 default:
2736 {
2737 if (has_successor())
2738 {
2739 return get_successor().accepts(id);
2740 }
2741 else
2742 {
2743 return false;
2744 }
2745 }
2746 }
2747 }
2748
2749 //********************************************
2750 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
2751 {
2752 return false;
2753 }
2754
2755 //********************************************
2756 bool is_producer() const ETL_OVERRIDE
2757 {
2758 return true;
2759 }
2760
2761 //********************************************
2762 bool is_consumer() const ETL_OVERRIDE
2763 {
2764 return true;
2765 }
2766 };
2767#endif
2768}
2769
2770#endif
This is the base of all message routers.
Definition message_router_generator.h:123
Definition message.h:73
Definition message_packet.h:367
Base exception class for message router.
Definition message_router_generator.h:90
Router id is out of the legal range.
Definition message_router_generator.h:103
Definition message_router.h:562
Definition message.h:91
Definition shared_message.h:49
ETL_NODISCARD etl::imessage & get_message()
Get a reference to the contained message.
Definition shared_message.h:189
Adds successor traits to a class.
Definition successor.h:73
bool has_successor() const
Does this have a successor?
Definition successor.h:184
successor_type & get_successor() const
Definition successor.h:174
successor()
Default constructor.
Definition successor.h:81
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
Definition exception.h:47
bitset_ext
Definition absolute.h:38
etl::imessage_router & get_null_message_router()
null message router functionality.
Definition message_router_generator.h:274
uint_least8_t message_id_t
Allow alternative type for message id.
Definition message_types.h:40
Definition type_traits_generator.h:849
Is T ultimately derived from etl::imessage_router?
Definition message_router_generator.h:362
Is T ultimately derived from etl::imessage?
Definition message.h:208
pair holds two objects of arbitrary type
Definition utility.h:164