Embedded Template Library  1.0
fsm.h
1 /******************************************************************************
2 The MIT License(MIT)
3 
4 Embedded Template Library.
5 https://github.com/ETLCPP/etl
6 https://www.etlcpp.com
7 
8 Copyright(c) 2017 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
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 -ofsm.h -DHandlers=<n> fsm_generator.h
42 // Where <n> is the number of messages to support.
43 //
44 // e.g.
45 // To generate handlers for up to 16 events...
46 // python -m cogapp -d -e -ofsm.h -DHandlers=16 fsm_generator.h
47 //
48 // See generate.bat
49 //***************************************************************************
50 
51 #ifndef ETL_FSM_INCLUDED
52 #define ETL_FSM_INCLUDED
53 
54 #include <stdint.h>
55 
56 #include "platform.h"
57 #include "array.h"
58 #include "nullptr.h"
59 #include "error_handler.h"
60 #include "exception.h"
61 #include "user_type.h"
62 #include "message_router.h"
63 #include "integral_limits.h"
64 #include "largest.h"
65 
66 #undef ETL_FILE
67 #define ETL_FILE "34"
68 
69 #include "private/minmax_push.h"
70 
71 namespace etl
72 {
73  class fsm;
74 
76 #if !defined(ETL_FSM_STATE_ID_TYPE)
77  typedef uint_least8_t fsm_state_id_t;
78 #else
79  typedef ETL_FSM_STATE_ID_TYPE fsm_state_id_t;
80 #endif
81 
82  // For internal FSM use.
83  typedef typename etl::larger_type<etl::message_id_t>::type fsm_internal_id_t;
84 
85  //***************************************************************************
87  //***************************************************************************
89  {
90  public:
91 
92  fsm_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
93  : etl::exception(reason_, file_name_, line_number_)
94  {
95  }
96  };
97 
98  //***************************************************************************
100  //***************************************************************************
102  {
103  public:
104 
105  fsm_null_state_exception(string_type file_name_, numeric_type line_number_)
106  : etl::fsm_exception(ETL_ERROR_TEXT("fsm:null state", ETL_FILE"A"), file_name_, line_number_)
107  {
108  }
109  };
110 
111  //***************************************************************************
113  //***************************************************************************
115  {
116  public:
117 
118  fsm_state_id_exception(string_type file_name_, numeric_type line_number_)
119  : etl::fsm_exception(ETL_ERROR_TEXT("fsm:state id", ETL_FILE"B"), file_name_, line_number_)
120  {
121  }
122  };
123 
124  //***************************************************************************
126  //***************************************************************************
128  {
129  public:
130 
131  fsm_state_list_exception(string_type file_name_, numeric_type line_number_)
132  : etl::fsm_exception(ETL_ERROR_TEXT("fsm:state list", ETL_FILE"C"), file_name_, line_number_)
133  {
134  }
135  };
136 
137  //***************************************************************************
139  //***************************************************************************
141  {
142  public:
143 
144  fsm_state_list_order_exception(string_type file_name_, numeric_type line_number_)
145  : etl::fsm_exception(ETL_ERROR_TEXT("fsm:state list order", ETL_FILE"D"), file_name_, line_number_)
146  {
147  }
148  };
149 
150  //***************************************************************************
152  //***************************************************************************
154  {
155  public:
156 
158  friend class etl::fsm;
159 
160  //*******************************************
162  //*******************************************
164  {
165  return state_id;
166  }
167 
168  protected:
169 
170  //*******************************************
172  //*******************************************
174  : state_id(state_id_),
175  p_context(ETL_NULLPTR)
176  {
177  }
178 
179  //*******************************************
181  //*******************************************
183  {
184  }
185 
186  //*******************************************
187  inline etl::fsm& get_fsm_context() const
188  {
189  return *p_context;
190  }
191 
192  private:
193 
194  virtual fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message) = 0;
195 
196  virtual fsm_state_id_t on_enter_state() { return state_id; } // By default, do nothing.
197  virtual void on_exit_state() {} // By default, do nothing.
198 
199  //*******************************************
200  void set_fsm_context(etl::fsm& context)
201  {
202  p_context = &context;
203  }
204 
205  // The state id.
206  const etl::fsm_state_id_t state_id;
207 
208  // A pointer to the FSM context.
209  etl::fsm* p_context;
210 
211  // Disabled.
212  ifsm_state(const ifsm_state&);
213  ifsm_state& operator =(const ifsm_state&);
214  };
215 
216  //***************************************************************************
218  //***************************************************************************
219  class fsm : public etl::imessage_router
220  {
221  public:
222 
223  //*******************************************
225  //*******************************************
226  fsm(etl::message_router_id_t id)
227  : imessage_router(id),
228  p_state(ETL_NULLPTR)
229  {
230  }
231 
232  //*******************************************
234  //*******************************************
235  template <typename TSize>
236  void set_states(etl::ifsm_state** p_states, TSize size)
237  {
238  state_list = p_states;
239  number_of_states = etl::fsm_state_id_t(size);
240 
241  ETL_ASSERT(number_of_states > 0, ETL_ERROR(etl::fsm_state_list_exception));
242 
243  for (etl::fsm_state_id_t i = 0; i < size; ++i)
244  {
245  ETL_ASSERT(state_list[i] != ETL_NULLPTR, ETL_ERROR(etl::fsm_null_state_exception));
246  ETL_ASSERT(state_list[i]->get_state_id() == i, ETL_ERROR(etl::fsm_state_list_order_exception));
247  state_list[i]->set_fsm_context(*this);
248  }
249  }
250 
251  //*******************************************
256  //*******************************************
257  void start(bool call_on_enter_state = true)
258  {
259  // Can only be started once.
260  if (p_state == ETL_NULLPTR)
261  {
262  p_state = state_list[0];
263  ETL_ASSERT(p_state != ETL_NULLPTR, ETL_ERROR(etl::fsm_null_state_exception));
264 
265  if (call_on_enter_state)
266  {
267  etl::fsm_state_id_t next_state_id;
268  etl::ifsm_state* p_last_state;
269 
270  do
271  {
272  p_last_state = p_state;
273  next_state_id = p_state->on_enter_state();
274  p_state = state_list[next_state_id];
275 
276  } while (p_last_state != p_state);
277  }
278  }
279  }
280 
281  //*******************************************
283  //*******************************************
284  void receive(const etl::imessage& message) ETL_OVERRIDE
285  {
286  static etl::null_message_router nmr;
287  receive(nmr, message);
288  }
289 
290  //*******************************************
292  //*******************************************
293  void receive(imessage_router& source, etl::message_router_id_t destination_router_id, const etl::imessage& message) ETL_OVERRIDE
294  {
295  if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
296  {
297  receive(source, message);
298  }
299  }
300 
301  //*******************************************
303  //*******************************************
304  void receive(etl::imessage_router& source, const etl::imessage& message) ETL_OVERRIDE
305  {
306  etl::fsm_state_id_t next_state_id = p_state->process_event(source, message);
307  ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
308 
309  etl::ifsm_state* p_next_state = state_list[next_state_id];
310 
311  // Have we changed state?
312  if (p_next_state != p_state)
313  {
314  do
315  {
316  p_state->on_exit_state();
317  p_state = p_next_state;
318 
319  next_state_id = p_state->on_enter_state();
320  ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
321 
322  p_next_state = state_list[next_state_id];
323 
324  } while (p_next_state != p_state); // Have we changed state again?
325  }
326  }
327 
328  using imessage_router::accepts;
329 
330  //*******************************************
333  //*******************************************
334  bool accepts(etl::message_id_t) const ETL_OVERRIDE
335  {
336  return true;
337  }
338 
339  //*******************************************
341  //*******************************************
343  {
344  ETL_ASSERT(p_state != ETL_NULLPTR, ETL_ERROR(etl::fsm_null_state_exception));
345  return p_state->get_state_id();
346  }
347 
348  //*******************************************
350  //*******************************************
352  {
353  ETL_ASSERT(p_state != ETL_NULLPTR, ETL_ERROR(etl::fsm_null_state_exception));
354  return *p_state;
355  }
356 
357  //*******************************************
359  //*******************************************
360  const ifsm_state& get_state() const
361  {
362  ETL_ASSERT(p_state != ETL_NULLPTR, ETL_ERROR(etl::fsm_null_state_exception));
363  return *p_state;
364  }
365 
366  //*******************************************
368  //*******************************************
369  bool is_started() const
370  {
371  return p_state != ETL_NULLPTR;
372  }
373 
374  //*******************************************
377  //*******************************************
378  void reset(bool call_on_exit_state = false)
379  {
380  if ((p_state != ETL_NULLPTR) && call_on_exit_state)
381  {
382  p_state->on_exit_state();
383  }
384 
385  p_state = ETL_NULLPTR;
386  }
387 
388  //********************************************
389  ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
390  {
391  return false;
392  }
393 
394  //********************************************
395  bool is_producer() const ETL_OVERRIDE
396  {
397  return true;
398  }
399 
400  //********************************************
401  bool is_consumer() const ETL_OVERRIDE
402  {
403  return true;
404  }
405 
406  private:
407 
408  etl::ifsm_state* p_state;
409  etl::ifsm_state** state_list;
410  etl::fsm_state_id_t number_of_states;
411  };
412 
413  //***************************************************************************
414  // The definition for all 16 message types.
415  //***************************************************************************
416  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
417  typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
418  typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
419  typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
420  typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
421  class fsm_state : public ifsm_state
422  {
423  public:
424 
425  enum
426  {
427  STATE_ID = STATE_ID_
428  };
429 
430  fsm_state()
431  : ifsm_state(STATE_ID)
432  {
433  }
434 
435  protected:
436 
437  ~fsm_state()
438  {
439  }
440 
441  inline TContext& get_fsm_context() const
442  {
443  return static_cast<TContext&>(ifsm_state::get_fsm_context());
444  }
445 
446  private:
447 
448  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
449  {
450  etl::fsm_state_id_t new_state_id;
451  etl::message_id_t event_id = message.message_id;
452 
453  switch (event_id)
454  {
455  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
456  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
457  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
458  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
459  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
460  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
461  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
462  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
463  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
464  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
465  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
466  case T12::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T12&>(message)); break;
467  case T13::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T13&>(message)); break;
468  case T14::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T14&>(message)); break;
469  case T15::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T15&>(message)); break;
470  case T16::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T16&>(message)); break;
471  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
472  }
473 
474  return new_state_id;
475  }
476  };
477 
478  //***************************************************************************
479  // Specialisation for 15 message types.
480  //***************************************************************************
481  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
482  typename T1, typename T2, typename T3, typename T4,
483  typename T5, typename T6, typename T7, typename T8,
484  typename T9, typename T10, typename T11, typename T12,
485  typename T13, typename T14, typename T15>
486  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, void> : public ifsm_state
487  {
488  public:
489 
490  enum
491  {
492  STATE_ID = STATE_ID_
493  };
494 
495  fsm_state()
496  : ifsm_state(STATE_ID)
497  {
498  }
499 
500  protected:
501 
502  ~fsm_state()
503  {
504  }
505 
506  inline TContext& get_fsm_context() const
507  {
508  return static_cast<TContext&>(ifsm_state::get_fsm_context());
509  }
510 
511  private:
512 
513  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
514  {
515  etl::fsm_state_id_t new_state_id;
516  etl::message_id_t event_id = message.message_id;
517 
518  switch (event_id)
519  {
520  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
521  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
522  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
523  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
524  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
525  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
526  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
527  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
528  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
529  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
530  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
531  case T12::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T12&>(message)); break;
532  case T13::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T13&>(message)); break;
533  case T14::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T14&>(message)); break;
534  case T15::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T15&>(message)); break;
535  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
536  }
537 
538  return new_state_id;
539  }
540  };
541 
542  //***************************************************************************
543  // Specialisation for 14 message types.
544  //***************************************************************************
545  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
546  typename T1, typename T2, typename T3, typename T4,
547  typename T5, typename T6, typename T7, typename T8,
548  typename T9, typename T10, typename T11, typename T12,
549  typename T13, typename T14>
550  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, void, void> : public ifsm_state
551  {
552  public:
553 
554  enum
555  {
556  STATE_ID = STATE_ID_
557  };
558 
559  fsm_state()
560  : ifsm_state(STATE_ID)
561  {
562  }
563 
564  protected:
565 
566  ~fsm_state()
567  {
568  }
569 
570  inline TContext& get_fsm_context() const
571  {
572  return static_cast<TContext&>(ifsm_state::get_fsm_context());
573  }
574 
575  private:
576 
577  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
578  {
579  etl::fsm_state_id_t new_state_id;
580  etl::message_id_t event_id = message.message_id;
581 
582  switch (event_id)
583  {
584  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
585  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
586  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
587  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
588  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
589  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
590  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
591  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
592  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
593  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
594  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
595  case T12::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T12&>(message)); break;
596  case T13::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T13&>(message)); break;
597  case T14::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T14&>(message)); break;
598  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
599  }
600 
601  return new_state_id;
602  }
603  };
604 
605  //***************************************************************************
606  // Specialisation for 13 message types.
607  //***************************************************************************
608  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
609  typename T1, typename T2, typename T3, typename T4,
610  typename T5, typename T6, typename T7, typename T8,
611  typename T9, typename T10, typename T11, typename T12,
612  typename T13>
613  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, void, void, void> : public ifsm_state
614  {
615  public:
616 
617  enum
618  {
619  STATE_ID = STATE_ID_
620  };
621 
622  fsm_state()
623  : ifsm_state(STATE_ID)
624  {
625  }
626 
627  protected:
628 
629  ~fsm_state()
630  {
631  }
632 
633  inline TContext& get_fsm_context() const
634  {
635  return static_cast<TContext&>(ifsm_state::get_fsm_context());
636  }
637 
638  private:
639 
640  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
641  {
642  etl::fsm_state_id_t new_state_id;
643  etl::message_id_t event_id = message.message_id;
644 
645  switch (event_id)
646  {
647  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
648  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
649  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
650  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
651  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
652  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
653  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
654  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
655  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
656  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
657  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
658  case T12::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T12&>(message)); break;
659  case T13::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T13&>(message)); break;
660  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
661  }
662 
663  return new_state_id;
664  }
665  };
666 
667  //***************************************************************************
668  // Specialisation for 12 message types.
669  //***************************************************************************
670  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
671  typename T1, typename T2, typename T3, typename T4,
672  typename T5, typename T6, typename T7, typename T8,
673  typename T9, typename T10, typename T11, typename T12>
674  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, void, void, void, void> : public ifsm_state
675  {
676  public:
677 
678  enum
679  {
680  STATE_ID = STATE_ID_
681  };
682 
683  fsm_state()
684  : ifsm_state(STATE_ID)
685  {
686  }
687 
688  protected:
689 
690  ~fsm_state()
691  {
692  }
693 
694  inline TContext& get_fsm_context() const
695  {
696  return static_cast<TContext&>(ifsm_state::get_fsm_context());
697  }
698 
699  private:
700 
701  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
702  {
703  etl::fsm_state_id_t new_state_id;
704  etl::message_id_t event_id = message.message_id;
705 
706  switch (event_id)
707  {
708  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
709  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
710  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
711  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
712  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
713  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
714  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
715  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
716  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
717  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
718  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
719  case T12::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T12&>(message)); break;
720  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
721  }
722 
723  return new_state_id;
724  }
725  };
726 
727  //***************************************************************************
728  // Specialisation for 11 message types.
729  //***************************************************************************
730  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
731  typename T1, typename T2, typename T3, typename T4,
732  typename T5, typename T6, typename T7, typename T8,
733  typename T9, typename T10, typename T11>
734  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, void, void, void, void, void> : public ifsm_state
735  {
736  public:
737 
738  enum
739  {
740  STATE_ID = STATE_ID_
741  };
742 
743  fsm_state()
744  : ifsm_state(STATE_ID)
745  {
746  }
747 
748  protected:
749 
750  ~fsm_state()
751  {
752  }
753 
754  inline TContext& get_fsm_context() const
755  {
756  return static_cast<TContext&>(ifsm_state::get_fsm_context());
757  }
758 
759  private:
760 
761  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
762  {
763  etl::fsm_state_id_t new_state_id;
764  etl::message_id_t event_id = message.message_id;
765 
766  switch (event_id)
767  {
768  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
769  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
770  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
771  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
772  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
773  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
774  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
775  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
776  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
777  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
778  case T11::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T11&>(message)); break;
779  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
780  }
781 
782  return new_state_id;
783  }
784  };
785 
786  //***************************************************************************
787  // Specialisation for 10 message types.
788  //***************************************************************************
789  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
790  typename T1, typename T2, typename T3, typename T4,
791  typename T5, typename T6, typename T7, typename T8,
792  typename T9, typename T10>
793  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, void, void, void, void, void, void> : public ifsm_state
794  {
795  public:
796 
797  enum
798  {
799  STATE_ID = STATE_ID_
800  };
801 
802  fsm_state()
803  : ifsm_state(STATE_ID)
804  {
805  }
806 
807  protected:
808 
809  ~fsm_state()
810  {
811  }
812 
813  inline TContext& get_fsm_context() const
814  {
815  return static_cast<TContext&>(ifsm_state::get_fsm_context());
816  }
817 
818  private:
819 
820  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
821  {
822  etl::fsm_state_id_t new_state_id;
823  etl::message_id_t event_id = message.message_id;
824 
825  switch (event_id)
826  {
827  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
828  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
829  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
830  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
831  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
832  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
833  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
834  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
835  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
836  case T10::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T10&>(message)); break;
837  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
838  }
839 
840  return new_state_id;
841  }
842  };
843 
844  //***************************************************************************
845  // Specialisation for 9 message types.
846  //***************************************************************************
847  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
848  typename T1, typename T2, typename T3, typename T4,
849  typename T5, typename T6, typename T7, typename T8,
850  typename T9>
851  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, void, void, void, void, void, void, void> : public ifsm_state
852  {
853  public:
854 
855  enum
856  {
857  STATE_ID = STATE_ID_
858  };
859 
860  fsm_state()
861  : ifsm_state(STATE_ID)
862  {
863  }
864 
865  protected:
866 
867  ~fsm_state()
868  {
869  }
870 
871  inline TContext& get_fsm_context() const
872  {
873  return static_cast<TContext&>(ifsm_state::get_fsm_context());
874  }
875 
876  private:
877 
878  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
879  {
880  etl::fsm_state_id_t new_state_id;
881  etl::message_id_t event_id = message.message_id;
882 
883  switch (event_id)
884  {
885  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
886  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
887  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
888  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
889  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
890  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
891  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
892  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
893  case T9::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T9&>(message)); break;
894  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
895  }
896 
897  return new_state_id;
898  }
899  };
900 
901  //***************************************************************************
902  // Specialisation for 8 message types.
903  //***************************************************************************
904  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
905  typename T1, typename T2, typename T3, typename T4,
906  typename T5, typename T6, typename T7, typename T8>
907  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, void, void, void, void, void, void, void, void> : public ifsm_state
908  {
909  public:
910 
911  enum
912  {
913  STATE_ID = STATE_ID_
914  };
915 
916  fsm_state()
917  : ifsm_state(STATE_ID)
918  {
919  }
920 
921  protected:
922 
923  ~fsm_state()
924  {
925  }
926 
927  inline TContext& get_fsm_context() const
928  {
929  return static_cast<TContext&>(ifsm_state::get_fsm_context());
930  }
931 
932  private:
933 
934  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
935  {
936  etl::fsm_state_id_t new_state_id;
937  etl::message_id_t event_id = message.message_id;
938 
939  switch (event_id)
940  {
941  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
942  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
943  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
944  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
945  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
946  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
947  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
948  case T8::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T8&>(message)); break;
949  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
950  }
951 
952  return new_state_id;
953  }
954  };
955 
956  //***************************************************************************
957  // Specialisation for 7 message types.
958  //***************************************************************************
959  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
960  typename T1, typename T2, typename T3, typename T4,
961  typename T5, typename T6, typename T7>
962  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, void, void, void, void, void, void, void, void, void> : public ifsm_state
963  {
964  public:
965 
966  enum
967  {
968  STATE_ID = STATE_ID_
969  };
970 
971  fsm_state()
972  : ifsm_state(STATE_ID)
973  {
974  }
975 
976  protected:
977 
978  ~fsm_state()
979  {
980  }
981 
982  inline TContext& get_fsm_context() const
983  {
984  return static_cast<TContext&>(ifsm_state::get_fsm_context());
985  }
986 
987  private:
988 
989  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
990  {
991  etl::fsm_state_id_t new_state_id;
992  etl::message_id_t event_id = message.message_id;
993 
994  switch (event_id)
995  {
996  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
997  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
998  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
999  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
1000  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
1001  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
1002  case T7::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T7&>(message)); break;
1003  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1004  }
1005 
1006  return new_state_id;
1007  }
1008  };
1009 
1010  //***************************************************************************
1011  // Specialisation for 6 message types.
1012  //***************************************************************************
1013  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1014  typename T1, typename T2, typename T3, typename T4,
1015  typename T5, typename T6>
1016  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1017  {
1018  public:
1019 
1020  enum
1021  {
1022  STATE_ID = STATE_ID_
1023  };
1024 
1025  fsm_state()
1026  : ifsm_state(STATE_ID)
1027  {
1028  }
1029 
1030  protected:
1031 
1032  ~fsm_state()
1033  {
1034  }
1035 
1036  inline TContext& get_fsm_context() const
1037  {
1038  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1039  }
1040 
1041  private:
1042 
1043  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1044  {
1045  etl::fsm_state_id_t new_state_id;
1046  etl::message_id_t event_id = message.message_id;
1047 
1048  switch (event_id)
1049  {
1050  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1051  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
1052  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
1053  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
1054  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
1055  case T6::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T6&>(message)); break;
1056  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1057  }
1058 
1059  return new_state_id;
1060  }
1061  };
1062 
1063  //***************************************************************************
1064  // Specialisation for 5 message types.
1065  //***************************************************************************
1066  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1067  typename T1, typename T2, typename T3, typename T4,
1068  typename T5>
1069  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1070  {
1071  public:
1072 
1073  enum
1074  {
1075  STATE_ID = STATE_ID_
1076  };
1077 
1078  fsm_state()
1079  : ifsm_state(STATE_ID)
1080  {
1081  }
1082 
1083  protected:
1084 
1085  ~fsm_state()
1086  {
1087  }
1088 
1089  inline TContext& get_fsm_context() const
1090  {
1091  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1092  }
1093 
1094  private:
1095 
1096  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1097  {
1098  etl::fsm_state_id_t new_state_id;
1099  etl::message_id_t event_id = message.message_id;
1100 
1101  switch (event_id)
1102  {
1103  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1104  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
1105  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
1106  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
1107  case T5::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T5&>(message)); break;
1108  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1109  }
1110 
1111  return new_state_id;
1112  }
1113  };
1114 
1115  //***************************************************************************
1116  // Specialisation for 4 message types.
1117  //***************************************************************************
1118  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1119  typename T1, typename T2, typename T3, typename T4>
1120  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, void, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1121  {
1122  public:
1123 
1124  enum
1125  {
1126  STATE_ID = STATE_ID_
1127  };
1128 
1129  fsm_state()
1130  : ifsm_state(STATE_ID)
1131  {
1132  }
1133 
1134  protected:
1135 
1136  ~fsm_state()
1137  {
1138  }
1139 
1140  inline TContext& get_fsm_context() const
1141  {
1142  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1143  }
1144 
1145  private:
1146 
1147  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1148  {
1149  etl::fsm_state_id_t new_state_id;
1150  etl::message_id_t event_id = message.message_id;
1151 
1152  switch (event_id)
1153  {
1154  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1155  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
1156  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
1157  case T4::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T4&>(message)); break;
1158  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1159  }
1160 
1161  return new_state_id;
1162  }
1163  };
1164 
1165  //***************************************************************************
1166  // Specialisation for 3 message types.
1167  //***************************************************************************
1168  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1169  typename T1, typename T2, typename T3>
1170  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, void, void, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1171  {
1172  public:
1173 
1174  enum
1175  {
1176  STATE_ID = STATE_ID_
1177  };
1178 
1179  fsm_state()
1180  : ifsm_state(STATE_ID)
1181  {
1182  }
1183 
1184  protected:
1185 
1186  ~fsm_state()
1187  {
1188  }
1189 
1190  inline TContext& get_fsm_context() const
1191  {
1192  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1193  }
1194 
1195  private:
1196 
1197  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1198  {
1199  etl::fsm_state_id_t new_state_id;
1200  etl::message_id_t event_id = message.message_id;
1201 
1202  switch (event_id)
1203  {
1204  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1205  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
1206  case T3::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T3&>(message)); break;
1207  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1208  }
1209 
1210  return new_state_id;
1211  }
1212  };
1213 
1214  //***************************************************************************
1215  // Specialisation for 2 message types.
1216  //***************************************************************************
1217  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1218  typename T1, typename T2>
1219  class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, void, void, void, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1220  {
1221  public:
1222 
1223  enum
1224  {
1225  STATE_ID = STATE_ID_
1226  };
1227 
1228  fsm_state()
1229  : ifsm_state(STATE_ID)
1230  {
1231  }
1232 
1233  protected:
1234 
1235  ~fsm_state()
1236  {
1237  }
1238 
1239  inline TContext& get_fsm_context() const
1240  {
1241  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1242  }
1243 
1244  private:
1245 
1246  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1247  {
1248  etl::fsm_state_id_t new_state_id;
1249  etl::message_id_t event_id = message.message_id;
1250 
1251  switch (event_id)
1252  {
1253  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1254  case T2::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T2&>(message)); break;
1255  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1256  }
1257 
1258  return new_state_id;
1259  }
1260  };
1261 
1262  //***************************************************************************
1263  // Specialisation for 1 message type.
1264  //***************************************************************************
1265  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_,
1266  typename T1>
1267  class fsm_state<TContext, TDerived, STATE_ID_, T1, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1268  {
1269  public:
1270 
1271  enum
1272  {
1273  STATE_ID = STATE_ID_
1274  };
1275 
1276  fsm_state()
1277  : ifsm_state(STATE_ID)
1278  {
1279  }
1280 
1281  protected:
1282 
1283  ~fsm_state()
1284  {
1285  }
1286 
1287  inline TContext& get_fsm_context() const
1288  {
1289  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1290  }
1291 
1292  private:
1293 
1294  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1295  {
1296  etl::fsm_state_id_t new_state_id;
1297  etl::message_id_t event_id = message.message_id;
1298 
1299  switch (event_id)
1300  {
1301  case T1::ID: new_state_id = static_cast<TDerived*>(this)->on_event(source, static_cast<const T1&>(message)); break;
1302  default: new_state_id = static_cast<TDerived*>(this)->on_event_unknown(source, message); break;
1303  }
1304 
1305  return new_state_id;
1306  }
1307  };
1308 
1309  //***************************************************************************
1310  // Specialisation for 0 message types.
1311  //***************************************************************************
1312  template <typename TContext, typename TDerived, const etl::fsm_state_id_t STATE_ID_>
1313  class fsm_state<TContext, TDerived, STATE_ID_, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void> : public ifsm_state
1314  {
1315  public:
1316 
1317  enum
1318  {
1319  STATE_ID = STATE_ID_
1320  };
1321 
1322  fsm_state()
1323  : ifsm_state(STATE_ID)
1324  {
1325  }
1326 
1327  protected:
1328 
1329  ~fsm_state()
1330  {
1331  }
1332 
1333  inline TContext& get_fsm_context() const
1334  {
1335  return static_cast<TContext&>(ifsm_state::get_fsm_context());
1336  }
1337  private:
1338 
1339  etl::fsm_state_id_t process_event(etl::imessage_router& source, const etl::imessage& message)
1340  {
1341  return static_cast<TDerived*>(this)->on_event_unknown(source, message);
1342  }
1343  };
1344 }
1345 
1346 #undef ETL_FILE
1347 
1348 #include "private/minmax_pop.h"
1349 
1350 #endif
Base exception class for FSM.
Definition: fsm.h:89
Exception for null state pointer.
Definition: fsm.h:102
Exception for invalid state id.
Definition: fsm.h:115
Exception for incompatible state list.
Definition: fsm.h:128
Exception for incompatible order state list.
Definition: fsm.h:141
Definition: fsm.h:422
The FSM class.
Definition: fsm.h:220
etl::fsm_state_id_t get_state_id() const
Gets the current state id.
Definition: fsm.h:342
void receive(const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm.h:284
fsm(etl::message_router_id_t id)
Constructor.
Definition: fsm.h:226
bool accepts(etl::message_id_t) const ETL_OVERRIDE
Definition: fsm.h:334
void reset(bool call_on_exit_state=false)
Definition: fsm.h:378
ifsm_state & get_state()
Gets a reference to the current state interface.
Definition: fsm.h:351
void set_states(etl::ifsm_state **p_states, TSize size)
Set the states for the FSM.
Definition: fsm.h:236
const ifsm_state & get_state() const
Gets a const reference to the current state interface.
Definition: fsm.h:360
void receive(etl::imessage_router &source, const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm.h:304
void start(bool call_on_enter_state=true)
Definition: fsm.h:257
void receive(imessage_router &source, etl::message_router_id_t destination_router_id, const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm.h:293
bool is_started() const
Checks if the FSM has been started.
Definition: fsm.h:369
Interface class for FSM states.
Definition: fsm.h:154
~ifsm_state()
Destructor.
Definition: fsm.h:182
etl::fsm_state_id_t get_state_id() const
Gets the id for this state.
Definition: fsm.h:163
ifsm_state(etl::fsm_state_id_t state_id_)
Constructor.
Definition: fsm.h:173
This is the base of all message routers.
Definition: message_router_generator.h:114
Definition: message.h:68
Definition: message.h:92
This router can be used as a sink for messages or a 'null source' router.
Definition: message_router_generator.h:194
#define ETL_ASSERT(b, e)
Definition: error_handler.h:290
Definition: exception.h:47
Defines a type that is as larger or larger than the specified type. Will return the specified type is...
Definition: largest_generator.h:352
Definition: absolute.h:37
uint_least8_t message_id_t
Allow alternative type for message id.
Definition: message_types.h:40
uint_least8_t fsm_state_id_t
Allow alternative type for state id.
Definition: fsm.h:73