| 40 | } |
| 41 | |
| 42 | void PowerManager::Load() |
| 43 | { |
| 44 | try |
| 45 | { |
| 46 | FileReader reader(GetConfigPath()); |
| 47 | NonOwningReaderSource source(reader); |
| 48 | |
| 49 | coding::DeserializerJson des(source); |
| 50 | Config result; |
| 51 | des(result); |
| 52 | |
| 53 | m_config = result; |
| 54 | |
| 55 | if (m_config.m_scheme == Scheme::Auto) |
| 56 | GetPlatform().GetBatteryTracker().Subscribe(this); |
| 57 | |
| 58 | for (size_t i = 0; i < m_config.m_facilities.size(); ++i) |
| 59 | NotifySubscribers(m_subscribers, static_cast<Facility>(i), m_config.m_facilities[i]); |
| 60 | |
| 61 | NotifySubscribers(m_subscribers, m_config.m_scheme); |
| 62 | return; |
| 63 | } |
| 64 | catch (base::Json::Exception & ex) |
| 65 | { |
| 66 | LOG(LERROR, ("Cannot deserialize power manager data from file. Exception:", ex.Msg())); |
| 67 | } |
| 68 | catch (FileReader::Exception const & ex) |
| 69 | { |
| 70 | LOG(LWARNING, ("Cannot read power manager config file. Exception:", ex.Msg())); |
| 71 | } |
| 72 | |
| 73 | // Reset to default state. |
| 74 | m_config = {}; |
| 75 | } |
| 76 | |
| 77 | void PowerManager::SetFacility(Facility const facility, bool enabled) |
| 78 | { |
no test coverage detected