Files
comaps/map/power_management/power_manager.hpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

62 lines
1.5 KiB
C++

#pragma once
#include "map/power_management/power_management_schemas.hpp"
#include "platform/battery_tracker.hpp"
#include "base/visitor.hpp"
#include <cstdint>
#include <string>
#include <vector>
namespace power_management
{
// Note: this class is NOT thread-safe.
class PowerManager : public platform::BatteryLevelTracker::Subscriber
{
public:
class Subscriber
{
public:
virtual void OnPowerFacilityChanged(Facility const facility, bool enabled) = 0;
virtual void OnPowerSchemeChanged(Scheme const actualScheme) = 0;
protected:
virtual ~Subscriber() = default;
};
static std::string GetConfigPath();
void Load();
// Set some facility state manually, it turns current scheme to Scheme::None.
void SetFacility(Facility const facility, bool enabled);
void SetScheme(Scheme const scheme);
bool IsFacilityEnabled(Facility const facility) const;
FacilitiesState const & GetFacilities() const;
Scheme const & GetScheme() const;
// BatteryLevelTracker::Subscriber overrides:
void OnBatteryLevelReceived(uint8_t level) override;
void Subscribe(Subscriber * subscriber);
void UnsubscribeAll();
private:
struct Config
{
DECLARE_VISITOR(visitor(m_facilities, "current_state"), visitor(m_scheme, "scheme"))
Config() { m_facilities.fill(true); }
FacilitiesState m_facilities;
Scheme m_scheme = Scheme::Normal;
};
bool Save();
std::vector<Subscriber *> m_subscribers;
Config m_config;
};
} // namespace power_management