Embedded Template Library 1.0
Loading...
Searching...
No Matches
message_router_generator.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/*[[[cog
30import cog
31cog.outl("#if 0")
32]]]*/
33/*[[[end]]]*/
34#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
35/*[[[cog
36import cog
37cog.outl("#endif")
38]]]*/
39/*[[[end]]]*/
40
41/*[[[cog
42import cog
43cog.outl("//***************************************************************************")
44cog.outl("// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.")
45cog.outl("//***************************************************************************")
46]]]*/
47/*[[[end]]]*/
48
49//***************************************************************************
50// To generate to header file, run this at the command line.
51// Note: You will need Python and COG installed.
52//
53// python -m cogapp -d -e -omessage_router.h -DHandlers=<n> message_router_generator.h
54// Where <n> is the maximum number of messages to support.
55//
56// e.g.
57// To generate handlers for up to 16 messages...
58// python -m cogapp -d -e -omessage_router.h -DHandlers=16 message_router_generator.h
59//
60// See generate.bat
61//***************************************************************************
62
63#ifndef ETL_MESSAGE_ROUTER_INCLUDED
64#define ETL_MESSAGE_ROUTER_INCLUDED
65
66#include "platform.h"
67#include "message.h"
68#include "shared_message.h"
69#if ETL_HAS_VIRTUAL_MESSAGES
70 #include "message_packet.h"
71#endif
72#include "message_types.h"
73#include "alignment.h"
74#include "error_handler.h"
75#include "exception.h"
76#include "largest.h"
77#include "nullptr.h"
78#include "placement_new.h"
79#include "successor.h"
80#include "type_traits.h"
81
82#include <stdint.h>
83
84namespace etl
85{
86 //***************************************************************************
88 //***************************************************************************
90 {
91 public:
92
93 message_router_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
95 {
96 }
97 };
98
99 //***************************************************************************
101 //***************************************************************************
103 {
104 public:
105
107 : message_router_exception(ETL_ERROR_TEXT("message router:illegal id", ETL_MESSAGE_ROUTER_FILE_ID"A"), file_name_, line_number_)
108 {
109 }
110 };
111
112 //***************************************************************************
114 //***************************************************************************
115 class imessage_router;
116
118
119 //***************************************************************************
121 //***************************************************************************
122 class imessage_router : public etl::successor<imessage_router>
123 {
124 public:
125
126 virtual ~imessage_router() {}
127 virtual void receive(const etl::imessage&) = 0;
128 virtual bool accepts(etl::message_id_t) const = 0;
129 virtual bool is_null_router() const = 0;
130 virtual bool is_producer() const = 0;
131 virtual bool is_consumer() const = 0;
132
133 //********************************************
134 virtual void receive(etl::message_router_id_t destination_router_id, const etl::imessage& message)
135 {
136 if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
137 {
138 receive(message);
139 }
140 }
141
142 //********************************************
143 virtual void receive(etl::shared_message shared_msg)
144 {
145 receive(shared_msg.get_message());
146 }
147
148 //********************************************
149 virtual void receive(etl::message_router_id_t destination_router_id, etl::shared_message shared_msg)
150 {
151 if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
152 {
153 receive(shared_msg);
154 }
155 }
156
157 //********************************************
158 bool accepts(const etl::imessage& msg) const
159 {
160 return accepts(msg.get_message_id());
161 }
162
163 //********************************************
164 etl::message_router_id_t get_message_router_id() const
165 {
166 return message_router_id;
167 }
168
169 enum
170 {
171 NULL_MESSAGE_ROUTER = 255,
172 MESSAGE_BUS = 254,
173 ALL_MESSAGE_ROUTERS = 253,
174 MESSAGE_BROKER = 252,
175 MESSAGE_ROUTER = 251,
176 MAX_MESSAGE_ROUTER = 249
177 };
178
179 protected:
180
181 imessage_router(etl::message_router_id_t id_)
182 : message_router_id(id_)
183 {
184 }
185
186 imessage_router(etl::message_router_id_t id_, imessage_router& successor_)
188 , message_router_id(id_)
189 {
190 }
191
192 private:
193
194 // Disabled.
197
198 etl::message_router_id_t message_router_id;
199 };
200
201 //***************************************************************************
203 //***************************************************************************
205 {
206 public:
207
208 //********************************************
210 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER)
211 {
212 }
213
214 //********************************************
216 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_)
217 {
218 }
219
220 //********************************************
221 using etl::imessage_router::receive;
222
223 void receive(const etl::imessage& msg) ETL_OVERRIDE
224 {
225 if (has_successor())
226 {
227 get_successor().receive(msg);
228 }
229 }
230
231 //********************************************
232 using etl::imessage_router::accepts;
233
234 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
235 {
236 if (has_successor())
237 {
238 return get_successor().accepts(id);
239 }
240 else
241 {
242 return false;
243 }
244 }
245
246 //********************************************
247 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
248 {
249 return true;
250 }
251
252 //********************************************
253 bool is_producer() const ETL_OVERRIDE
254 {
255 return false;
256 }
257
258 //********************************************
259 bool is_consumer() const ETL_OVERRIDE
260 {
261 return false;
262 }
263
264 //********************************************
265 static null_message_router& instance()
266 {
268 return nmr;
269 }
270 };
271
272 //***********************************************
275 {
276 return etl::null_message_router::instance();
277 }
278
279 //***************************************************************************
281 //***************************************************************************
283 {
284 public:
285
286 //********************************************
288 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
289 {
290 }
291
292 //********************************************
294 : imessage_router(imessage_router::NULL_MESSAGE_ROUTER, successor_)
295 {
296 }
297
298 //********************************************
301 {
302 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
303 }
304
305 //********************************************
308 {
309 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
310 }
311
312 //********************************************
313 using etl::imessage_router::receive;
314
315 void receive(const etl::imessage& msg) ETL_OVERRIDE
316 {
317 if (has_successor())
318 {
319 get_successor().receive(msg);
320 }
321 }
322
323 //********************************************
324 using etl::imessage_router::accepts;
325
326 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
327 {
328 if (has_successor())
329 {
330 return get_successor().accepts(id);
331 }
332 else
333 {
334 return false;
335 }
336 }
337
338 //********************************************
339 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
340 {
341 return false;
342 }
343
344 //********************************************
345 bool is_producer() const ETL_OVERRIDE
346 {
347 return true;
349
350 //********************************************
351 bool is_consumer() const ETL_OVERRIDE
352 {
353 return false;
354 }
355 };
356
357 //***************************************************************************
359 //***************************************************************************
360 template <typename T>
361 struct is_message_router : public etl::bool_constant<etl::is_base_of<etl::imessage_router, typename etl::remove_cvref<T>::type>::value>
362 {
363 };
364
365 //***************************************************************************
367 //***************************************************************************
368 template <typename TRouter, typename TMessage>
369 static
371 send_message(TRouter& destination,
372 const TMessage& message)
373 {
375 }
376
377 //***************************************************************************
379 //***************************************************************************
380 template <typename TRouter>
381 static
383 send_message(TRouter& destination,
385 {
386 destination.receive(message);
387 }
388
389 //***************************************************************************
391 //***************************************************************************
392 template <typename TRouter, typename TMessage>
393 static
395 send_message(TRouter& destination,
397 const TMessage& message)
398 {
399 destination.receive(id, message);
400 }
401
402 //***************************************************************************
404 //***************************************************************************
405 template <typename TRouter>
406 static
408 send_message(TRouter& destination,
410 etl::shared_message message)
411 {
412 destination.receive(id, message);
413 }
414
415//*************************************************************************************************
416// For C++17 and above.
417//*************************************************************************************************
418#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION)
419 //***************************************************************************
420 // The definition for all message types.
421 //***************************************************************************
422 template <typename TDerived, typename... TMessageTypes>
423 class message_router : public imessage_router
424 {
425 public:
426
427#if ETL_HAS_VIRTUAL_MESSAGES
428 typedef etl::message_packet<TMessageTypes...> message_packet;
429#endif
430
431 //**********************************************
432 message_router()
433 : imessage_router(etl::imessage_router::MESSAGE_ROUTER)
434 {
435 }
436
437 //**********************************************
438 message_router(etl::imessage_router& successor_)
439 : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)
440 {
441 }
442
443 //**********************************************
444 message_router(etl::message_router_id_t id_)
445 : imessage_router(id_)
446 {
447 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
448 }
449
450 //**********************************************
451 message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)
452 : imessage_router(id_, successor_)
453 {
454 ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));
455 }
456
457 //**********************************************
458 using etl::imessage_router::receive;
459
460 void receive(const etl::imessage& msg) ETL_OVERRIDE
461 {
462 const bool was_handled = (receive_message_type<TMessageTypes>(msg) || ...);
463
464 if (!was_handled)
465 {
466 if (has_successor())
467 {
468 get_successor().receive(msg);
469 }
470 else
471 {
472 static_cast<TDerived*>(this)->on_receive_unknown(msg);
473 }
474 }
475 }
476
477 template <typename TMessage, typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value, int>::type = 0>
478 void receive(const TMessage& msg)
479 {
480 if constexpr (etl::is_one_of<TMessage, TMessageTypes...>::value)
481 {
482 static_cast<TDerived*>(this)->on_receive(msg);
483 }
484 else
485 {
486 if (has_successor())
487 {
488 get_successor().receive(msg);
489 }
490 else
491 {
492 static_cast<TDerived*>(this)->on_receive_unknown(msg);
493 }
494 }
495 }
496
497 //**********************************************
498 using imessage_router::accepts;
499
500 bool accepts(etl::message_id_t id) const ETL_OVERRIDE
501 {
502 return (accepts_type<TMessageTypes>(id) || ...);
503 }
504
505 //********************************************
506 ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
507 {
508 return false;
509 }
510
511 //********************************************
512 bool is_producer() const ETL_OVERRIDE
513 {
514 return true;
515 }
516
517 //********************************************
518 bool is_consumer() const ETL_OVERRIDE
519 {
520 return true;
521 }
522
523 private:
524
525 //********************************************
526 template <typename TMessage>
527 bool receive_message_type(const etl::imessage& msg)
528 {
529 if (TMessage::ID == msg.get_message_id())
530 {
531 static_cast<TDerived*>(this)->on_receive(static_cast<const TMessage&>(msg));
532 return true;
533 }
534 else
535 {
536 return false;
537 }
538 }
539
540 //********************************************
541 template <typename TMessage>
542 bool accepts_type(etl::message_id_t id) const
543 {
544 if (TMessage::ID == id)
545 {
546 return true;
547 }
548 else
549 {
550 if (has_successor())
551 {
552 return get_successor().accepts(id);
553 }
554 else
555 {
556 return false;
557 }
558 }
559 }
560 };
561#else
562//*************************************************************************************************
563// For C++14 and below.
564//*************************************************************************************************
565 /*[[[cog
566 import cog
567 ################################################
568 # The first definition for all of the messages.
569 ################################################
570 cog.outl("//***************************************************************************")
571 cog.outl("// The definition for all %s message types." % Handlers)
572 cog.outl("//***************************************************************************")
573 cog.outl("template <typename TDerived,")
574 cog.out(" ")
575 cog.out("typename T1, ")
576 for n in range(2, int(Handlers)):
577 cog.out("typename T%s = void, " % n)
578 if n % 4 == 0:
579 cog.outl("")
580 cog.out(" ")
581 cog.outl("typename T%s = void>" % int(Handlers))
582 cog.out("class message_router")
583 cog.outl(" : public imessage_router")
584 cog.outl("{")
585 cog.outl("public:")
586 cog.outl("")
587 cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES")
588 cog.out(" typedef etl::message_packet<")
589 for n in range(1, int(Handlers)):
590 cog.out("T%s, " % n)
591 cog.outl(" T%s> message_packet;" % int(Handlers))
592 cog.outl("#endif")
593 cog.outl("")
594 cog.outl(" //**********************************************")
595 cog.outl(" message_router(etl::message_router_id_t id_)")
596 cog.outl(" : imessage_router(id_)")
597 cog.outl(" {")
598 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
599 cog.outl(" }")
600 cog.outl("")
601 cog.outl(" //**********************************************")
602 cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
603 cog.outl(" : imessage_router(id_, successor_)")
604 cog.outl(" {")
605 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
606 cog.outl(" }")
607 cog.outl("")
608 cog.outl(" //**********************************************")
609 cog.outl(" message_router()")
610 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
611 cog.outl(" {")
612 cog.outl(" }")
613 cog.outl("")
614 cog.outl(" //**********************************************")
615 cog.outl(" message_router(etl::imessage_router& successor_)")
616 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
617 cog.outl(" {")
618 cog.outl(" }")
619 cog.outl("")
620 cog.outl(" //**********************************************")
621 cog.outl(" using etl::imessage_router::receive;")
622 cog.outl("")
623 cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
624 cog.outl(" {")
625 cog.outl(" const etl::message_id_t id = msg.get_message_id();")
626 cog.outl("")
627 cog.outl(" switch (id)")
628 cog.outl(" {")
629 for n in range(1, int(Handlers) + 1):
630 cog.out(" case T%d::ID:" % n)
631 cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % n)
632 cog.outl(" break;")
633 cog.outl(" default:")
634 cog.outl(" {")
635 cog.outl(" if (has_successor())")
636 cog.outl(" {")
637 cog.outl(" get_successor().receive(msg);")
638 cog.outl(" }")
639 cog.outl(" else")
640 cog.outl(" {")
641 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
642 cog.outl(" }")
643 cog.outl(" break;")
644 cog.outl(" }")
645 cog.outl(" }")
646 cog.outl(" }")
647 cog.outl("")
648 cog.outl(" template <typename TMessage>")
649 cog.out(" typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value && etl::is_one_of<TMessage, ")
650 for n in range(1, int(Handlers)):
651 cog.out("T%s, " % n)
652 cog.outl("T%s>::value, void>::type" % int(Handlers))
653 cog.outl(" receive(const TMessage& msg)")
654 cog.outl(" {")
655 cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
656 cog.outl(" }")
657 cog.outl("")
658 cog.outl(" template <typename TMessage>")
659 cog.out(" typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value && !etl::is_one_of<TMessage, ")
660 for n in range(1, int(Handlers)):
661 cog.out("T%s, " % n)
662 cog.outl("T%s>::value, void>::type" % int(Handlers))
663 cog.outl(" receive(const TMessage& msg)")
664 cog.outl(" {")
665 cog.outl(" if (has_successor())")
666 cog.outl(" {")
667 cog.outl(" get_successor().receive(msg);")
668 cog.outl(" }")
669 cog.outl(" else")
670 cog.outl(" {")
671 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
672 cog.outl(" }")
673 cog.outl(" }")
674 cog.outl("")
675 cog.outl(" //**********************************************")
676 cog.outl(" using imessage_router::accepts;")
677 cog.outl("")
678 cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
679 cog.outl(" {")
680 cog.outl(" switch (id)")
681 cog.outl(" {")
682 cog.out(" ")
683 for n in range(1, int(Handlers) + 1):
684 cog.out("case T%d::ID: " % n)
685 if n % 8 == 0:
686 cog.outl("")
687 cog.out(" ")
688 cog.outl(" return true;")
689 cog.outl(" default:")
690 cog.outl(" {")
691 cog.outl(" if (has_successor())")
692 cog.outl(" {")
693 cog.outl(" return get_successor().accepts(id);")
694 cog.outl(" }")
695 cog.outl(" else")
696 cog.outl(" {")
697 cog.outl(" return false;")
698 cog.outl(" }")
699 cog.outl(" }")
700 cog.outl(" }")
701 cog.outl(" }")
702 cog.outl("")
703 cog.outl(" //********************************************")
704 cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
705 cog.outl(" {")
706 cog.outl(" return false;")
707 cog.outl(" }")
708 cog.outl("")
709 cog.outl(" //********************************************")
710 cog.outl(" bool is_producer() const ETL_OVERRIDE")
711 cog.outl(" {")
712 cog.outl(" return true;")
713 cog.outl(" }")
714 cog.outl("")
715 cog.outl(" //********************************************")
716 cog.outl(" bool is_consumer() const ETL_OVERRIDE")
717 cog.outl(" {")
718 cog.outl(" return true;")
719 cog.outl(" }")
720 cog.outl("};")
721
722 ####################################
723 # All of the other specialisations.
724 ####################################
725 for n in range(int(Handlers) - 1, 0, -1):
726 cog.outl("")
727 cog.outl("//***************************************************************************")
728 if n == 1:
729 cog.outl("// Specialisation for %d message type." % n)
730 else:
731 cog.outl("// Specialisation for %d message types." % n)
732 cog.outl("//***************************************************************************")
733 cog.outl("template <typename TDerived, ")
734 cog.out(" ")
735 for t in range(1, n):
736 cog.out("typename T%d, " % t)
737 if t % 4 == 0:
738 cog.outl("")
739 cog.out(" ")
740 cog.outl("typename T%d>" % n)
741 cog.out("class message_router<TDerived, ")
742 for t in range(1, n + 1):
743 cog.out("T%d, " % t)
744 if t % 16 == 0:
745 cog.outl("")
746 cog.out(" ")
747 for t in range(n + 1, int(Handlers)):
748 cog.out("void, ")
749 if t % 16 == 0:
750 cog.outl("")
751 cog.out(" ")
752 cog.outl("void>")
753 cog.outl(" : public imessage_router")
754 cog.outl("{")
755 cog.outl("public:")
756 cog.outl("")
757 cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES")
758 cog.out(" typedef etl::message_packet<")
759 for t in range(1, n):
760 cog.out("T%s, " % t)
761 cog.outl(" T%s> message_packet;" % n)
762 cog.outl("#endif")
763 cog.outl("")
764 cog.outl(" //**********************************************")
765 cog.outl(" message_router(etl::message_router_id_t id_)")
766 cog.outl(" : imessage_router(id_)")
767 cog.outl(" {")
768 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
769 cog.outl(" }")
770 cog.outl("")
771 cog.outl(" //**********************************************")
772 cog.outl(" message_router(etl::message_router_id_t id_, etl::imessage_router& successor_)")
773 cog.outl(" : imessage_router(id_, successor_)")
774 cog.outl(" {")
775 cog.outl(" ETL_ASSERT(id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER, ETL_ERROR(etl::message_router_illegal_id));")
776 cog.outl(" }")
777 cog.outl("")
778 cog.outl(" //**********************************************")
779 cog.outl(" message_router()")
780 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER)")
781 cog.outl(" {")
782 cog.outl(" }")
783 cog.outl("")
784 cog.outl(" //**********************************************")
785 cog.outl(" message_router(etl::imessage_router& successor_)")
786 cog.outl(" : imessage_router(etl::imessage_router::MESSAGE_ROUTER, successor_)")
787 cog.outl(" {")
788 cog.outl(" }")
789 cog.outl("")
790 cog.outl(" //**********************************************")
791 cog.outl(" using etl::imessage_router::receive;")
792 cog.outl("")
793 cog.outl(" void receive(const etl::imessage& msg) ETL_OVERRIDE")
794 cog.outl(" {")
795 cog.outl(" const size_t id = msg.get_message_id();")
796 cog.outl("")
797 cog.outl(" switch (id)")
798 cog.outl(" {")
799 for t in range(1, n + 1):
800 cog.out(" case T%d::ID:" % t)
801 cog.out(" static_cast<TDerived*>(this)->on_receive(static_cast<const T%d&>(msg));" % t)
802 cog.outl(" break;")
803 cog.outl(" default:")
804 cog.outl(" {")
805 cog.outl(" if (has_successor())")
806 cog.outl(" {")
807 cog.outl(" get_successor().receive(msg);")
808 cog.outl(" }")
809 cog.outl(" else")
810 cog.outl(" {")
811 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
812 cog.outl(" }")
813 cog.outl(" break;")
814 cog.outl(" }")
815 cog.outl(" }")
816 cog.outl(" }")
817 cog.outl("")
818 cog.outl(" template <typename TMessage>")
819 cog.out(" typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value && etl::is_one_of<TMessage, ")
820 for t in range(1, n):
821 cog.out("T%s, " % t)
822 cog.outl("T%s>::value, void>::type" % n)
823 cog.outl(" receive(const TMessage& msg)")
824 cog.outl(" {")
825 cog.outl(" static_cast<TDerived*>(this)->on_receive(msg);")
826 cog.outl(" }")
827 cog.outl("")
828 cog.outl(" template <typename TMessage>")
829 cog.out(" typename etl::enable_if<etl::is_base_of<imessage, TMessage>::value && !etl::is_one_of<TMessage, ")
830 for t in range(1, n):
831 cog.out("T%s, " % t)
832 cog.outl("T%s>::value, void>::type" % n)
833 cog.outl(" receive(const TMessage& msg)")
834 cog.outl(" {")
835 cog.outl(" if (has_successor())")
836 cog.outl(" {")
837 cog.outl(" get_successor().receive(msg);")
838 cog.outl(" }")
839 cog.outl(" else")
840 cog.outl(" {")
841 cog.outl(" static_cast<TDerived*>(this)->on_receive_unknown(msg);")
842 cog.outl(" }")
843 cog.outl(" }")
844 cog.outl("")
845 cog.outl("")
846 cog.outl(" //**********************************************")
847 cog.outl(" using imessage_router::accepts;")
848 cog.outl("")
849 cog.outl(" bool accepts(etl::message_id_t id) const ETL_OVERRIDE")
850 cog.outl(" {")
851 cog.outl(" switch (id)")
852 cog.outl(" {")
853 cog.out(" ")
854 for t in range(1, n + 1):
855 cog.out("case T%d::ID: " % t)
856 if t % 8 == 0:
857 cog.outl("")
858 cog.out(" ")
859 cog.outl("")
860 cog.outl(" return true;")
861 cog.outl(" default:")
862 cog.outl(" {")
863 cog.outl(" if (has_successor())")
864 cog.outl(" {")
865 cog.outl(" return get_successor().accepts(id);")
866 cog.outl(" }")
867 cog.outl(" else")
868 cog.outl(" {")
869 cog.outl(" return false;")
870 cog.outl(" }")
871 cog.outl(" }")
872 cog.outl(" }")
873 cog.outl(" }")
874 cog.outl("")
875 cog.outl(" //********************************************")
876 cog.outl(" ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE")
877 cog.outl(" {")
878 cog.outl(" return false;")
879 cog.outl(" }")
880 cog.outl("")
881 cog.outl(" //********************************************")
882 cog.outl(" bool is_producer() const ETL_OVERRIDE")
883 cog.outl(" {")
884 cog.outl(" return true;")
885 cog.outl(" }")
886 cog.outl("")
887 cog.outl(" //********************************************")
888 cog.outl(" bool is_consumer() const ETL_OVERRIDE")
889 cog.outl(" {")
890 cog.outl(" return true;")
891 cog.outl(" }")
892 cog.outl("};")
893 ]]]*/
894 /*[[[end]]]*/
895#endif
896}
897
898#endif
This is the base of all message routers.
Definition message_router_generator.h:123
Definition message.h:73
Definition message_packet.h:367
This router can be used as a producer-only of messages, such an interrupt routine.
Definition message_router_generator.h:283
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.h:91
This router can be used as a sink for messages or a 'null source' router.
Definition message_router_generator.h:205
Definition shared_message.h:49
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
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