Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <string> |
| 5 | |
| 6 | namespace witherspoon |
| 7 | { |
| 8 | namespace power |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * @class Device |
| 13 | * |
| 14 | * This object is an abstract base class for a device that |
| 15 | * can be monitored for power faults. |
| 16 | */ |
| 17 | class Device |
| 18 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 19 | public: |
| 20 | Device() = delete; |
| 21 | virtual ~Device() = default; |
| 22 | Device(const Device&) = delete; |
| 23 | Device& operator=(const Device&) = delete; |
| 24 | Device(Device&&) = default; |
| 25 | Device& operator=(Device&&) = default; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 26 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 27 | /** |
| 28 | * Constructor |
| 29 | * |
| 30 | * @param name - the device name |
| 31 | * @param inst - the device instance |
| 32 | */ |
| 33 | Device(const std::string& name, size_t inst) : name(name), instance(inst) |
Patrick Williams | 2c4fbc4 | 2020-06-26 15:33:11 -0500 | [diff] [blame] | 34 | {} |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 35 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 36 | /** |
| 37 | * Returns the instance number |
| 38 | */ |
| 39 | inline auto getInstance() const |
| 40 | { |
| 41 | return instance; |
| 42 | } |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 43 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 44 | /** |
| 45 | * Returns the name |
| 46 | */ |
| 47 | inline auto getName() const |
| 48 | { |
| 49 | return name; |
| 50 | } |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 51 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 52 | /** |
| 53 | * Pure virtual function to analyze an error |
| 54 | */ |
| 55 | virtual void analyze() = 0; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 56 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 57 | /** |
| 58 | * Stubbed virtual function to call when it's known |
| 59 | * the chip is in error state. Override if functionality |
| 60 | * is required |
| 61 | */ |
| 62 | virtual void onFailure() |
Patrick Williams | 2c4fbc4 | 2020-06-26 15:33:11 -0500 | [diff] [blame] | 63 | {} |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 64 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 65 | /** |
| 66 | * Pure virtual function to clear faults on the device |
| 67 | */ |
| 68 | virtual void clearFaults() = 0; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 69 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 70 | private: |
| 71 | /** |
| 72 | * the device name |
| 73 | */ |
| 74 | const std::string name; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 75 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 76 | /** |
| 77 | * the device instance number |
| 78 | */ |
| 79 | const size_t instance; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 82 | } // namespace power |
| 83 | } // namespace witherspoon |