Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 1 | #include "occ_status.hpp" |
Vishwanatha Subbanna | 6add0b8 | 2017-07-21 19:02:37 +0530 | [diff] [blame^] | 2 | #include "occ_sensor.hpp" |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 3 | namespace open_power |
| 4 | { |
| 5 | namespace occ |
| 6 | { |
| 7 | |
| 8 | // Handles updates to occActive property |
| 9 | bool Status::occActive(bool value) |
| 10 | { |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 11 | if (value != this->occActive()) |
| 12 | { |
| 13 | if (value) |
| 14 | { |
| 15 | // Bind the device |
| 16 | device.bind(); |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 17 | |
| 18 | // And watch for errors |
| 19 | device.addErrorWatch(); |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 20 | } |
| 21 | else |
| 22 | { |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 23 | // Stop watching for errors |
| 24 | device.removeErrorWatch(); |
| 25 | |
| 26 | // Do the unbind. |
Vishwanatha Subbanna | 32e84e9 | 2017-06-28 19:17:28 +0530 | [diff] [blame] | 27 | device.unBind(); |
| 28 | } |
| 29 | } |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 30 | return Base::Status::occActive(value); |
| 31 | } |
| 32 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 33 | // Callback handler when a device error is reported. |
| 34 | void Status::deviceErrorHandler() |
| 35 | { |
| 36 | // This would deem OCC inactive |
| 37 | this->occActive(false); |
| 38 | } |
| 39 | |
Vishwanatha Subbanna | 307d80b | 2017-06-28 15:56:09 +0530 | [diff] [blame] | 40 | } // namespace occ |
| 41 | } // namespace open_power |