21 #include <core/dbus/macros.h> 22 #include <core/dbus/object.h> 23 #include <core/dbus/property.h> 27 namespace com {
namespace canonical {
namespace indicator {
namespace power {
32 static std::string s =
"com.canonical.indicator.power.Battery";
36 static const core::dbus::types::ObjectPath&
path()
38 static core::dbus::types::ObjectPath p{
"/com/canonical/indicator/power/Battery"};
43 DBUS_CPP_READABLE_PROPERTY_DEF(PowerLevel,
Battery, std::string)
44 DBUS_CPP_READABLE_PROPERTY_DEF(IsWarning,
Battery,
bool)
52 struct BatteryObserver :
public media::power::BatteryObserver
56 static const std::map<std::string, core::ubuntu::media::power::Level> lut =
64 if (lut.count(s) == 0)
70 BatteryObserver(
const core::dbus::Object::Ptr&
object)
75 object->get_property<com::canonical::indicator::power::Battery::PowerLevel>(),
76 object->get_property<com::canonical::indicator::power::Battery::IsWarning>(),
80 properties.power_level->changed().connect([
this](
const std::string& value)
82 properties.typed_power_level = BatteryObserver::power_level_from_string(value);
88 const core::Property<core::ubuntu::media::power::Level>& level()
const override 90 return properties.typed_power_level;
93 const core::Property<bool>& is_warning_active()
const override 95 return *properties.is_warning;
99 core::dbus::Object::Ptr object;
105 core::Property<core::ubuntu::media::power::Level> typed_power_level;
106 std::shared_ptr<core::dbus::Property<com::canonical::indicator::power::Battery::PowerLevel>> power_level;
108 std::shared_ptr<core::dbus::Property<com::canonical::indicator::power::Battery::IsWarning>> is_warning;
113 core::ScopedConnection power_level;
122 auto service = core::dbus::Service::use_service<com::canonical::indicator::power::Battery>(es.session);
125 return std::make_shared<impl::BatteryObserver>(object);
static const core::dbus::types::ObjectPath & path()
static std::string & name()