|
MythTV master
|
#include <libmythbase/mythpower.h>
Public Types | |
| enum | PowerLevel : std::int8_t { UPS = -2 , ACPower = -1 , BatteryEmpty = 0 , BatteryLow = 10 , BatteryFull = 100 , UnknownPower = 101 , Unset = 102 } |
| enum | Feature : std::uint8_t { FeatureNone = 0x00 , FeatureShutdown = 0x01 , FeatureSuspend = 0x02 , FeatureHibernate = 0x04 , FeatureRestart = 0x08 , FeatureHybridSleep = 0x10 } |
Public Slots | |
| virtual void | CancelFeature (void) |
| This is untested as it is currently not clear whether it is useful. More... | |
Signals | |
| void | ShuttingDown (void) |
| void | Suspending (void) |
| void | Hibernating (void) |
| void | Restarting (void) |
| void | HybridSleeping (void) |
| void | WillShutDown (std::chrono::milliseconds MilliSeconds=0ms) |
| void | WillSuspend (std::chrono::milliseconds MilliSeconds=0ms) |
| void | WillHibernate (std::chrono::milliseconds MilliSeconds=0ms) |
| void | WillRestart (std::chrono::milliseconds MilliSeconds=0ms) |
| void | WillHybridSleep (std::chrono::milliseconds MilliSeconds=0ms) |
| void | WokeUp (std::chrono::seconds SecondsAsleep) |
| void | LowBattery (void) |
Public Member Functions | |
| virtual bool | RequestFeature (Feature Request, bool Delay=true) |
| Features | GetFeatures (void) |
| bool | IsFeatureSupported (Feature Supported) |
| int | GetPowerLevel (void) const |
| QStringList | GetFeatureList (void) |
Public Member Functions inherited from ReferenceCounter | |
| ReferenceCounter (const QString &debugName, bool logDebug=true) | |
| Creates reference counter with an initial value of 1. More... | |
| virtual int | IncrRef (void) |
| Increments reference count. More... | |
| virtual int | DecrRef (void) |
| Decrements reference count and deletes on 0. More... | |
Static Public Member Functions | |
| static MythPower * | AcquireRelease (void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s) |
Static Public Member Functions inherited from ReferenceCounter | |
| static void | PrintDebug (void) |
| Print out any leaks if that level of debugging is enabled. More... | |
Protected Slots | |
| void | FeatureTimeout (void) |
| virtual void | Refresh (void) |
Protected Member Functions | |
| MythPower () | |
| ~MythPower () override=default | |
| virtual void | Init (void) |
| virtual bool | DoFeature (bool=false) |
| virtual void | DidWakeUp (void) |
| virtual void | FeatureHappening (Feature Spontaneous=FeatureNone) |
| Signal to the rest of MythTV that the given feature will happen now. More... | |
| virtual bool | ScheduleFeature (enum Feature Type, std::chrono::seconds Delay) |
| void | SetRequestedDelay (std::chrono::seconds Delay) |
| void | PowerLevelChanged (int Level) |
Protected Member Functions inherited from ReferenceCounter | |
| virtual | ~ReferenceCounter (void) |
| Called on destruction, will warn if object deleted with references in place. More... | |
Static Protected Member Functions | |
| static QString | FeatureToString (enum Feature Type) |
| static bool | FeatureIsEquivalent (Feature First, Feature Second) |
Protected Attributes | |
| Features | m_features { FeatureNone } |
| Feature | m_scheduledFeature { FeatureNone } |
| bool | m_isSpontaneous { false } |
| std::chrono::seconds | m_maxRequestedDelay { 0s } |
| std::chrono::seconds | m_maxSupportedDelay { MAXIMUM_SHUTDOWN_WAIT } |
| QTimer | m_featureTimer |
| QDateTime | m_sleepTime |
| int | m_powerLevel { Unset } |
| bool | m_warnForLowBattery { false } |
Protected Attributes inherited from ReferenceCounter | |
| bool | m_logDebug |
| This is used to suppress creating LoggingItem classes for LoggingItem reference count changes. More... | |
| QAtomicInt | m_referenceCount {1} |
Static Protected Attributes | |
| static QRecursiveMutex | s_lock |
MythPower is a reference counted, singleton class.
Classes wishing to listen for or schedule power events should acquire a reference to MythPower via AcquireRelease using a suitable Reference and Acquire set to true.
AcquireRelease will always return a valid pointer but the default implementation has no actual power support.
If the class in question wishes to register a delay so that it can safely cleanup before shutdown/suspend, it should pass a MinimumDelay (seconds) to AcquireRelease. The MythPower object will then attempt to delay any events for at least that period of time. This behaviour is not guaranteed - most notably in the case of externally triggered events. The actual delay attempted will be the maximum of those registered and, in the case of user initiated events, the EXIT_SHUTDOWN_DELAY user setting (which defaults to 3 seconds).
There is no method to subsequently alter the delay. Should this be needed, release the current reference and re-acquire with a new MinimumDelay. To ensure the underlying MythPower object is not deleted, take a temporary reference with AcquireRelease using a different, unique Reference value.
Do not acquire multiple references with the same Reference value. This will lead to unexpected delay behaviour.
To release the MythPower reference, call AcquireRelease with the same Reference (typically a pointer to the owning class) and Acquire set to false.
To check supported power behaviours, call either GetFeatures or IsFeatureSupported.
Call RequestFeature to initiate shutdown/suspend etc. The default behaviour is to delay the action.
Call CancelFeature to cancel a previously scheduled shutdown/suspend.
Signals
WillShutdown etc are emitted in advance and provide the listener with an opportunity to do stuff. There is no guarantee on how long they have. ShuttingDown etc are emitted when the requested feature (or system event) is imminent. There is, in theory, no time to do stuff. WokeUp is emitted when the system has been woken up OR when a scheduled event has been cancelled.
Add OSX subclass
Add Windows subclass
Add Android subclass
Add sending Myth events as well as emitting signals.
Definition at line 19 of file mythpower.h.
| enum MythPower::Feature : std::uint8_t |
| Enumerator | |
|---|---|
| FeatureNone | |
| FeatureShutdown | |
| FeatureSuspend | |
| FeatureHibernate | |
| FeatureRestart | |
| FeatureHybridSleep | |
Definition at line 35 of file mythpower.h.
| enum MythPower::PowerLevel : std::int8_t |
| Enumerator | |
|---|---|
| UPS | |
| ACPower | |
| BatteryEmpty | |
| BatteryLow | |
| BatteryFull | |
| UnknownPower | |
| Unset | |
Definition at line 24 of file mythpower.h.
|
protected |
Definition at line 126 of file mythpower.cpp.
Referenced by AcquireRelease().
|
overrideprotecteddefault |
|
static |
Definition at line 77 of file mythpower.cpp.
Referenced by MythCoreContext::InitPower(), ShutDownRebootSetting::ShutDownRebootSetting(), UPnp::UPnp(), ExitPrompter::~ExitPrompter(), MythCoreContextPrivate::~MythCoreContextPrivate(), and UPnp::~UPnp().
|
virtualslot |
This is untested as it is currently not clear whether it is useful.
Definition at line 225 of file mythpower.cpp.
Referenced by MythPowerDBus::CancelFeature().
|
protectedvirtual |
Reimplemented in MythPowerDBus.
Definition at line 331 of file mythpower.cpp.
Referenced by CancelFeature(), and MythPowerDBus::DidWakeUp().
|
inlineprotectedvirtual |
Reimplemented in MythPowerDBus, and MythPowerOSX.
Definition at line 82 of file mythpower.h.
Referenced by FeatureTimeout(), and RequestFeature().
|
protectedvirtual |
Signal to the rest of MythTV that the given feature will happen now.
Definition at line 304 of file mythpower.cpp.
Referenced by MythPowerDBus::DBusShuttingDown(), MythPowerDBus::DBusSuspending(), MythPowerOSX::DoFeature(), and MythPowerDBus::ReleaseLock().
Definition at line 260 of file mythpower.cpp.
Referenced by MythPowerDBus::DBusShuttingDown(), and MythPowerDBus::DBusSuspending().
|
protectedslot |
Definition at line 241 of file mythpower.cpp.
Referenced by MythPower().
|
staticprotected |
Definition at line 246 of file mythpower.cpp.
Referenced by CancelFeature(), FeatureHappening(), GetFeatureList(), ScheduleFeature(), MythPowerDBus::ScheduleFeature(), and MythPowerDBus::UpdateStatus().
| QStringList MythPower::GetFeatureList | ( | void | ) |
Definition at line 155 of file mythpower.cpp.
Referenced by Init(), and OverrideExitMenu().
| MythPower::Features MythPower::GetFeatures | ( | void | ) |
Definition at line 146 of file mythpower.cpp.
Referenced by GetFeatureList().
| int MythPower::GetPowerLevel | ( | void | ) | const |
Definition at line 176 of file mythpower.cpp.
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
protectedvirtual |
Reimplemented in MythPowerDBus, and MythPowerOSX.
Definition at line 133 of file mythpower.cpp.
Referenced by MythPowerDBus::Init(), and MythPowerOSX::Init().
| bool MythPower::IsFeatureSupported | ( | Feature | Supported | ) |
Definition at line 167 of file mythpower.cpp.
Referenced by ExitPrompter::DoHalt(), ExitPrompter::DoReboot(), ExitPrompter::DoSuspend(), HaltCommand(), ExitPrompter::HandleExit(), RebootCommand(), and SuspendCommand().
|
signal |
Referenced by PowerLevelChanged().
|
protected |
Definition at line 348 of file mythpower.cpp.
Referenced by MythPowerOSX::Refresh(), and MythPowerDBus::UpdateBattery().
|
inlineprotectedvirtualslot |
Definition at line 73 of file mythpower.h.
Definition at line 185 of file mythpower.cpp.
Referenced by ExitPrompter::DoHalt(), ExitPrompter::DoReboot(), and ExitPrompter::DoSuspend().
|
signal |
Referenced by FeatureHappening().
|
protectedvirtual |
Reimplemented in MythPowerDBus.
Definition at line 277 of file mythpower.cpp.
Referenced by RequestFeature(), and MythPowerDBus::ScheduleFeature().
|
protected |
Definition at line 141 of file mythpower.cpp.
Referenced by AcquireRelease().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by RequestFeature().
|
signal |
Referenced by RequestFeature().
|
signal |
Referenced by RequestFeature(), and UPnp::UPnp().
|
signal |
Referenced by RequestFeature(), MythPowerDBus::UpdateStatus(), and UPnp::UPnp().
|
signal |
Referenced by RequestFeature(), MythPowerDBus::UpdateStatus(), and UPnp::UPnp().
|
signal |
Referenced by DidWakeUp(), and UPnp::UPnp().
|
protected |
Definition at line 91 of file mythpower.h.
Referenced by MythPowerDBus::DoFeature(), MythPowerOSX::DoFeature(), GetFeatures(), MythPowerOSX::Init(), IsFeatureSupported(), RequestFeature(), and MythPowerDBus::UpdateProperties().
|
protected |
Definition at line 96 of file mythpower.h.
Referenced by CancelFeature(), DidWakeUp(), MythPower(), RequestFeature(), ScheduleFeature(), and MythPowerDBus::ScheduleFeature().
|
protected |
Definition at line 93 of file mythpower.h.
Referenced by DidWakeUp(), and FeatureHappening().
|
protected |
Definition at line 94 of file mythpower.h.
Referenced by RequestFeature(), SetRequestedDelay(), and MythPowerDBus::UpdateStatus().
|
protected |
Definition at line 95 of file mythpower.h.
Referenced by RequestFeature(), MythPowerDBus::UpdateProperties(), and MythPowerDBus::UpdateStatus().
|
protected |
Definition at line 98 of file mythpower.h.
Referenced by GetPowerLevel(), and PowerLevelChanged().
|
protected |
Definition at line 92 of file mythpower.h.
Referenced by CancelFeature(), MythPowerDBus::DBusShuttingDown(), MythPowerDBus::DBusSuspending(), DidWakeUp(), MythPowerDBus::DoFeature(), MythPowerOSX::DoFeature(), FeatureHappening(), MythPowerDBus::ReleaseLock(), RequestFeature(), ScheduleFeature(), MythPowerDBus::UpdateStatus(), and MythPowerDBus::~MythPowerDBus().
|
protected |
Definition at line 97 of file mythpower.h.
Referenced by DidWakeUp(), and FeatureHappening().
|
protected |
Definition at line 99 of file mythpower.h.
Referenced by PowerLevelChanged().
|
staticprotected |
Definition at line 76 of file mythpower.h.
Referenced by MythPowerDBus::AcquireLock(), AcquireRelease(), CancelFeature(), MythPowerDBus::CancelFeature(), MythPowerDBus::Changed(), MythPowerDBus::DeviceAdded(), MythPowerDBus::DeviceChanged(), MythPowerDBus::DeviceRemoved(), DidWakeUp(), MythPowerDBus::DidWakeUp(), GetFeatures(), GetPowerLevel(), MythPowerDBus::IsAvailable(), IsFeatureSupported(), MythPowerDBus::ReleaseLock(), RequestFeature(), and MythPowerDBus::UpdateBattery().