|
| 1 | +/* MIT License |
| 2 | + * |
| 3 | + * Copyright (c) 2023 - 2024 Andreas Merkle <web@blue-andi.de> |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in all |
| 13 | + * copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | + * SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +/******************************************************************************* |
| 25 | + DESCRIPTION |
| 26 | +*******************************************************************************/ |
| 27 | +/** |
| 28 | + * @brief Error State. |
| 29 | + * @author Gabryel Reyes <gabryelrdiaz@gmail.com> |
| 30 | + * |
| 31 | + * @addtogroup Application |
| 32 | + * |
| 33 | + * @{ |
| 34 | + */ |
| 35 | +#ifndef ERROR_STATE_H |
| 36 | +#define ERROR_STATE_H |
| 37 | + |
| 38 | +/****************************************************************************** |
| 39 | + * Compile Switches |
| 40 | + *****************************************************************************/ |
| 41 | + |
| 42 | +/****************************************************************************** |
| 43 | + * Includes |
| 44 | + *****************************************************************************/ |
| 45 | + |
| 46 | +#include <IState.h> |
| 47 | +#include <StateMachine.h> |
| 48 | + |
| 49 | +/****************************************************************************** |
| 50 | + * Macros |
| 51 | + *****************************************************************************/ |
| 52 | + |
| 53 | +/****************************************************************************** |
| 54 | + * Types and Classes |
| 55 | + *****************************************************************************/ |
| 56 | + |
| 57 | +/** The system error state. */ |
| 58 | +class ErrorState : public IState |
| 59 | +{ |
| 60 | +public: |
| 61 | + /** |
| 62 | + * Get state instance. |
| 63 | + * |
| 64 | + * @return State instance |
| 65 | + */ |
| 66 | + static ErrorState& getInstance() |
| 67 | + { |
| 68 | + static ErrorState instance; /* singleton idiom to force initialization in the first usage. */ |
| 69 | + |
| 70 | + return instance; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * If the state is entered, this method will called once. |
| 75 | + */ |
| 76 | + void entry() final; |
| 77 | + |
| 78 | + /** |
| 79 | + * Processing the state. |
| 80 | + * |
| 81 | + * @param[in] sm State machine, which is calling this state. |
| 82 | + */ |
| 83 | + void process(StateMachine& sm) final; |
| 84 | + |
| 85 | + /** |
| 86 | + * If the state is left, this method will be called once. |
| 87 | + */ |
| 88 | + void exit() final; |
| 89 | + |
| 90 | +protected: |
| 91 | +private: |
| 92 | + /** Flag: State is active. */ |
| 93 | + bool m_isActive; |
| 94 | + |
| 95 | + /** Flag: Release is requested. */ |
| 96 | + bool m_releaseRequested; |
| 97 | + |
| 98 | + /** |
| 99 | + * Default constructor. |
| 100 | + */ |
| 101 | + ErrorState() : IState(), m_isActive(false) |
| 102 | + { |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Default destructor. |
| 107 | + */ |
| 108 | + virtual ~ErrorState() |
| 109 | + { |
| 110 | + } |
| 111 | + |
| 112 | + /* Not allowed. */ |
| 113 | + ErrorState(const ErrorState& state); /**< Copy construction of an instance. */ |
| 114 | + ErrorState& operator=(const ErrorState& state); /**< Assignment of an instance. */ |
| 115 | +}; |
| 116 | + |
| 117 | +/****************************************************************************** |
| 118 | + * Functions |
| 119 | + *****************************************************************************/ |
| 120 | + |
| 121 | +#endif /* ERROR_STATE_H */ |
| 122 | +/** @} */ |
0 commit comments