Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
| 4 | #include <string> |
| 5 | |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 6 | namespace phosphor |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 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 | */ |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 33 | Device(const std::string& name, size_t inst) : name(name), instance(inst) {} |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 34 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 35 | /** |
| 36 | * Returns the instance number |
| 37 | */ |
| 38 | inline auto getInstance() const |
| 39 | { |
| 40 | return instance; |
| 41 | } |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 42 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 43 | /** |
| 44 | * Returns the name |
| 45 | */ |
| 46 | inline auto getName() const |
| 47 | { |
| 48 | return name; |
| 49 | } |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 50 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 51 | /** |
| 52 | * Pure virtual function to analyze an error |
| 53 | */ |
| 54 | virtual void analyze() = 0; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 55 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 56 | /** |
| 57 | * Stubbed virtual function to call when it's known |
| 58 | * the chip is in error state. Override if functionality |
| 59 | * is required |
| 60 | */ |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 61 | virtual void onFailure() {} |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 62 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 63 | /** |
| 64 | * Pure virtual function to clear faults on the device |
| 65 | */ |
| 66 | virtual void clearFaults() = 0; |
Matt Spinler | b54357f | 2017-08-21 14:38:54 -0500 | [diff] [blame] | 67 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 68 | private: |
| 69 | /** |
| 70 | * the device name |
| 71 | */ |
| 72 | const std::string name; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 73 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 74 | /** |
| 75 | * the device instance number |
| 76 | */ |
| 77 | const size_t instance; |
Matt Spinler | dae0a8d | 2017-07-24 13:42:55 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 80 | } // namespace power |
Lei YU | ab09332 | 2019-10-09 16:43:22 +0800 | [diff] [blame] | 81 | } // namespace phosphor |