blob: 7acd1328a80079c8342dc7d0025479275bdb981e [file] [log] [blame]
Matt Spinlerdae0a8d2017-07-24 13:42:55 -05001#pragma once
2
3#include <memory>
4#include <string>
5
Lei YUab093322019-10-09 16:43:22 +08006namespace phosphor
Matt Spinlerdae0a8d2017-07-24 13:42:55 -05007{
8namespace 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 */
17class Device
18{
Matt Spinlerf0f02b92018-10-25 16:12:43 -050019 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 Spinlerdae0a8d2017-07-24 13:42:55 -050026
Matt Spinlerf0f02b92018-10-25 16:12:43 -050027 /**
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)
34 {
35 }
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050036
Matt Spinlerf0f02b92018-10-25 16:12:43 -050037 /**
38 * Returns the instance number
39 */
40 inline auto getInstance() const
41 {
42 return instance;
43 }
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050044
Matt Spinlerf0f02b92018-10-25 16:12:43 -050045 /**
46 * Returns the name
47 */
48 inline auto getName() const
49 {
50 return name;
51 }
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050052
Matt Spinlerf0f02b92018-10-25 16:12:43 -050053 /**
54 * Pure virtual function to analyze an error
55 */
56 virtual void analyze() = 0;
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050057
Matt Spinlerf0f02b92018-10-25 16:12:43 -050058 /**
59 * Stubbed virtual function to call when it's known
60 * the chip is in error state. Override if functionality
61 * is required
62 */
63 virtual void onFailure()
64 {
65 }
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050066
Matt Spinlerf0f02b92018-10-25 16:12:43 -050067 /**
68 * Pure virtual function to clear faults on the device
69 */
70 virtual void clearFaults() = 0;
Matt Spinlerb54357f2017-08-21 14:38:54 -050071
Matt Spinlerf0f02b92018-10-25 16:12:43 -050072 private:
73 /**
74 * the device name
75 */
76 const std::string name;
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050077
Matt Spinlerf0f02b92018-10-25 16:12:43 -050078 /**
79 * the device instance number
80 */
81 const size_t instance;
Matt Spinlerdae0a8d2017-07-24 13:42:55 -050082};
83
Matt Spinlerf0f02b92018-10-25 16:12:43 -050084} // namespace power
Lei YUab093322019-10-09 16:43:22 +080085} // namespace phosphor