MythTV
master
|
#include <mythpower.h>
Public Types | |
enum | PowerLevel { UPS = -2, ACPower = -1, BatteryEmpty = 0, BatteryLow = 10, BatteryFull = 100, UnknownPower = 101, Unset } |
enum | Feature { 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) |
![]() | |
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 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) |
![]() | |
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 } |
![]() | |
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 23 of file mythpower.h.
Enumerator | |
---|---|
UPS | |
ACPower | |
BatteryEmpty | |
BatteryLow | |
BatteryFull | |
UnknownPower | |
Unset |
Definition at line 28 of file mythpower.h.
enum MythPower::Feature |
Enumerator | |
---|---|
FeatureNone | |
FeatureShutdown | |
FeatureSuspend | |
FeatureHibernate | |
FeatureRestart | |
FeatureHybridSleep |
Definition at line 39 of file mythpower.h.
|
protected |
Definition at line 124 of file mythpower.cpp.
Referenced by AcquireRelease().
|
overrideprotecteddefault |
|
static |
Definition at line 75 of file mythpower.cpp.
Referenced by MythCoreContext::InitPower(), ShutDownRebootSetting::ShutDownRebootSetting(), UPnp::UPnp(), ExitPrompter::~ExitPrompter(), MythCoreContextPrivate::~MythCoreContextPrivate(), and UPnp::~UPnp().
Definition at line 183 of file mythpower.cpp.
Referenced by ExitPrompter::DoHalt(), ExitPrompter::DoReboot(), and ExitPrompter::DoSuspend().
MythPower::Features MythPower::GetFeatures | ( | void | ) |
Definition at line 144 of file mythpower.cpp.
Referenced by GetFeatureList().
Definition at line 165 of file mythpower.cpp.
Referenced by ExitPrompter::DoHalt(), ExitPrompter::DoReboot(), ExitPrompter::DoSuspend(), HaltCommand(), ExitPrompter::HandleExit(), RebootCommand(), and SuspendCommand().
int MythPower::GetPowerLevel | ( | void | ) | const |
Definition at line 174 of file mythpower.cpp.
QStringList MythPower::GetFeatureList | ( | void | ) |
Definition at line 153 of file mythpower.cpp.
Referenced by Init(), and OverrideExitMenu().
|
virtualslot |
This is untested as it is currently not clear whether it is useful.
Definition at line 223 of file mythpower.cpp.
Referenced by MythPowerDBus::CancelFeature().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by FeatureHappening().
|
signal |
Referenced by RequestFeature(), MythPowerDBus::UpdateStatus(), and UPnp::UPnp().
|
signal |
Referenced by RequestFeature(), MythPowerDBus::UpdateStatus(), and UPnp::UPnp().
|
signal |
Referenced by RequestFeature().
|
signal |
Referenced by RequestFeature(), and UPnp::UPnp().
|
signal |
Referenced by RequestFeature().
|
signal |
Referenced by DidWakeUp(), and UPnp::UPnp().
|
signal |
Referenced by PowerLevelChanged().
|
protectedslot |
Definition at line 239 of file mythpower.cpp.
Referenced by MythPower().
|
inlineprotectedvirtualslot |
Definition at line 77 of file mythpower.h.
|
protectedvirtual |
Reimplemented in MythPowerDBus, and MythPowerOSX.
Definition at line 131 of file mythpower.cpp.
Referenced by MythPowerOSX::Init(), and MythPowerDBus::Init().
Reimplemented in MythPowerDBus, and MythPowerOSX.
Definition at line 90 of file mythpower.h.
Referenced by FeatureTimeout(), and RequestFeature().
|
protectedvirtual |
Reimplemented in MythPowerDBus.
Definition at line 329 of file mythpower.cpp.
Referenced by CancelFeature(), and MythPowerDBus::DidWakeUp().
|
protectedvirtual |
Signal to the rest of MythTV that the given feature will happen now.
Definition at line 302 of file mythpower.cpp.
Referenced by MythPowerDBus::DBusShuttingDown(), MythPowerDBus::DBusSuspending(), MythPowerOSX::DoFeature(), and MythPowerDBus::ReleaseLock().
Reimplemented in MythPowerDBus.
Definition at line 275 of file mythpower.cpp.
Referenced by RequestFeature(), and MythPowerDBus::ScheduleFeature().
|
protected |
Definition at line 139 of file mythpower.cpp.
Referenced by AcquireRelease().
|
protected |
Definition at line 346 of file mythpower.cpp.
Referenced by MythPowerOSX::Refresh(), and MythPowerDBus::UpdateBattery().
|
staticprotected |
Definition at line 244 of file mythpower.cpp.
Referenced by CancelFeature(), FeatureHappening(), GetFeatureList(), MythPowerDBus::ScheduleFeature(), ScheduleFeature(), and MythPowerDBus::UpdateStatus().
Definition at line 258 of file mythpower.cpp.
Referenced by MythPowerDBus::DBusShuttingDown(), and MythPowerDBus::DBusSuspending().
|
staticprotected |
Definition at line 83 of file mythpower.h.
Referenced by MythPowerDBus::AcquireLock(), AcquireRelease(), MythPowerDBus::CancelFeature(), CancelFeature(), MythPowerDBus::Changed(), MythPowerDBus::DeviceAdded(), MythPowerDBus::DeviceChanged(), MythPowerDBus::DeviceRemoved(), MythPowerDBus::DidWakeUp(), DidWakeUp(), GetFeatures(), GetPowerLevel(), MythPowerDBus::IsAvailable(), IsFeatureSupported(), MythPowerDBus::ReleaseLock(), RequestFeature(), and MythPowerDBus::UpdateBattery().
|
protected |
Definition at line 99 of file mythpower.h.
Referenced by MythPowerOSX::DoFeature(), MythPowerDBus::DoFeature(), GetFeatures(), MythPowerOSX::Init(), IsFeatureSupported(), RequestFeature(), and MythPowerDBus::UpdateProperties().
|
protected |
Definition at line 100 of file mythpower.h.
Referenced by CancelFeature(), MythPowerDBus::DBusShuttingDown(), MythPowerDBus::DBusSuspending(), DidWakeUp(), MythPowerOSX::DoFeature(), MythPowerDBus::DoFeature(), FeatureHappening(), MythPowerDBus::ReleaseLock(), RequestFeature(), ScheduleFeature(), MythPowerDBus::UpdateStatus(), and MythPowerDBus::~MythPowerDBus().
Definition at line 101 of file mythpower.h.
Referenced by DidWakeUp(), and FeatureHappening().
|
protected |
Definition at line 102 of file mythpower.h.
Referenced by RequestFeature(), SetRequestedDelay(), and MythPowerDBus::UpdateStatus().
|
protected |
Definition at line 103 of file mythpower.h.
Referenced by RequestFeature(), MythPowerDBus::UpdateProperties(), and MythPowerDBus::UpdateStatus().
|
protected |
Definition at line 104 of file mythpower.h.
Referenced by CancelFeature(), DidWakeUp(), MythPower(), RequestFeature(), MythPowerDBus::ScheduleFeature(), and ScheduleFeature().
|
protected |
Definition at line 105 of file mythpower.h.
Referenced by DidWakeUp(), and FeatureHappening().
|
protected |
Definition at line 106 of file mythpower.h.
Referenced by GetPowerLevel(), and PowerLevelChanged().
Definition at line 107 of file mythpower.h.
Referenced by PowerLevelChanged().