MythTV master
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
MythPower Class Reference

#include <libmythbase/mythpower.h>

Inheritance diagram for MythPower:
[legend]
Collaboration diagram for MythPower:
[legend]

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 MythPowerAcquireRelease (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
 

Detailed Description

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.

Note
CancelFeature is currently untested and may be removed. It is unclear whether it is useable. As soon as the feature is requested, various system processes start to shutdown. This often renders the GUI either unresponsive or simply not visible. Hence trying to show a cancel dialog is pointless.

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.

Todo:

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.

Member Enumeration Documentation

◆ Feature

enum MythPower::Feature : std::uint8_t
Enumerator
FeatureNone 
FeatureShutdown 
FeatureSuspend 
FeatureHibernate 
FeatureRestart 
FeatureHybridSleep 

Definition at line 35 of file mythpower.h.

◆ PowerLevel

enum MythPower::PowerLevel : std::int8_t
Enumerator
UPS 
ACPower 
BatteryEmpty 
BatteryLow 
BatteryFull 
UnknownPower 
Unset 

Definition at line 24 of file mythpower.h.

Constructor & Destructor Documentation

◆ MythPower()

MythPower::MythPower ( )
protected

Definition at line 123 of file mythpower.cpp.

Referenced by AcquireRelease().

◆ ~MythPower()

MythPower::~MythPower ( )
overrideprotecteddefault

Member Function Documentation

◆ AcquireRelease()

MythPower * MythPower::AcquireRelease ( void *  Reference,
bool  Acquire,
std::chrono::seconds  MinimumDelay = 0s 
)
static

◆ CancelFeature

void MythPower::CancelFeature ( void  )
virtualslot

This is untested as it is currently not clear whether it is useful.

Definition at line 222 of file mythpower.cpp.

Referenced by MythPowerDBus::CancelFeature().

◆ DidWakeUp()

void MythPower::DidWakeUp ( void  )
protectedvirtual

Reimplemented in MythPowerDBus.

Definition at line 328 of file mythpower.cpp.

Referenced by CancelFeature(), and MythPowerDBus::DidWakeUp().

◆ DoFeature()

virtual bool MythPower::DoFeature ( bool  = false)
inlineprotectedvirtual

Reimplemented in MythPowerDBus, and MythPowerOSX.

Definition at line 82 of file mythpower.h.

Referenced by FeatureTimeout(), and RequestFeature().

◆ FeatureHappening()

void MythPower::FeatureHappening ( Feature  Spontaneous = FeatureNone)
protectedvirtual

Signal to the rest of MythTV that the given feature will happen now.

Note
If other elements of MythTV have not previously been notified of a pending action there is little they can do now as there is no guarantee anything will be completed before the system goes offline.

Definition at line 301 of file mythpower.cpp.

Referenced by MythPowerDBus::DBusShuttingDown(), MythPowerDBus::DBusSuspending(), MythPowerOSX::DoFeature(), and MythPowerDBus::ReleaseLock().

◆ FeatureIsEquivalent()

bool MythPower::FeatureIsEquivalent ( Feature  First,
Feature  Second 
)
staticprotected

◆ FeatureTimeout

void MythPower::FeatureTimeout ( void  )
protectedslot

Definition at line 238 of file mythpower.cpp.

Referenced by MythPower().

◆ FeatureToString()

QString MythPower::FeatureToString ( enum Feature  Type)
staticprotected

◆ GetFeatureList()

QStringList MythPower::GetFeatureList ( void  )

Definition at line 152 of file mythpower.cpp.

Referenced by Init(), and OverrideExitMenu().

◆ GetFeatures()

MythPower::Features MythPower::GetFeatures ( void  )

Definition at line 143 of file mythpower.cpp.

Referenced by GetFeatureList().

◆ GetPowerLevel()

int MythPower::GetPowerLevel ( void  ) const

Definition at line 173 of file mythpower.cpp.

◆ Hibernating

void MythPower::Hibernating ( void  )
signal

Referenced by FeatureHappening().

◆ HybridSleeping

void MythPower::HybridSleeping ( void  )
signal

Referenced by FeatureHappening().

◆ Init()

void MythPower::Init ( void  )
protectedvirtual

Reimplemented in MythPowerDBus, and MythPowerOSX.

Definition at line 130 of file mythpower.cpp.

Referenced by MythPowerDBus::Init(), and MythPowerOSX::Init().

◆ IsFeatureSupported()

bool MythPower::IsFeatureSupported ( Feature  Supported)

◆ LowBattery

void MythPower::LowBattery ( void  )
signal

Referenced by PowerLevelChanged().

◆ PowerLevelChanged()

void MythPower::PowerLevelChanged ( int  Level)
protected

Definition at line 345 of file mythpower.cpp.

Referenced by MythPowerOSX::Refresh(), and MythPowerDBus::UpdateBattery().

◆ Refresh

virtual void MythPower::Refresh ( void  )
inlineprotectedvirtualslot

Definition at line 73 of file mythpower.h.

◆ RequestFeature()

bool MythPower::RequestFeature ( Feature  Request,
bool  Delay = true 
)
virtual

◆ Restarting

void MythPower::Restarting ( void  )
signal

Referenced by FeatureHappening().

◆ ScheduleFeature()

bool MythPower::ScheduleFeature ( enum Feature  Type,
std::chrono::seconds  Delay 
)
protectedvirtual

Reimplemented in MythPowerDBus.

Definition at line 274 of file mythpower.cpp.

Referenced by RequestFeature(), and MythPowerDBus::ScheduleFeature().

◆ SetRequestedDelay()

void MythPower::SetRequestedDelay ( std::chrono::seconds  Delay)
protected

Definition at line 138 of file mythpower.cpp.

Referenced by AcquireRelease().

◆ ShuttingDown

void MythPower::ShuttingDown ( void  )
signal

Referenced by FeatureHappening().

◆ Suspending

void MythPower::Suspending ( void  )
signal

Referenced by FeatureHappening().

◆ WillHibernate

void MythPower::WillHibernate ( std::chrono::milliseconds  MilliSeconds = 0ms)
signal

Referenced by RequestFeature().

◆ WillHybridSleep

void MythPower::WillHybridSleep ( std::chrono::milliseconds  MilliSeconds = 0ms)
signal

Referenced by RequestFeature().

◆ WillRestart

void MythPower::WillRestart ( std::chrono::milliseconds  MilliSeconds = 0ms)
signal

Referenced by RequestFeature(), and UPnp::UPnp().

◆ WillShutDown

void MythPower::WillShutDown ( std::chrono::milliseconds  MilliSeconds = 0ms)
signal

◆ WillSuspend

void MythPower::WillSuspend ( std::chrono::milliseconds  MilliSeconds = 0ms)
signal

◆ WokeUp

void MythPower::WokeUp ( std::chrono::seconds  SecondsAsleep)
signal

Referenced by DidWakeUp(), and UPnp::UPnp().

Member Data Documentation

◆ m_features

Features MythPower::m_features { FeatureNone }
protected

◆ m_featureTimer

QTimer MythPower::m_featureTimer
protected

◆ m_isSpontaneous

bool MythPower::m_isSpontaneous { false }
protected

Definition at line 93 of file mythpower.h.

Referenced by DidWakeUp(), and FeatureHappening().

◆ m_maxRequestedDelay

std::chrono::seconds MythPower::m_maxRequestedDelay { 0s }
protected

Definition at line 94 of file mythpower.h.

Referenced by RequestFeature(), SetRequestedDelay(), and MythPowerDBus::UpdateStatus().

◆ m_maxSupportedDelay

std::chrono::seconds MythPower::m_maxSupportedDelay { MAXIMUM_SHUTDOWN_WAIT }
protected

◆ m_powerLevel

int MythPower::m_powerLevel { Unset }
protected

Definition at line 98 of file mythpower.h.

Referenced by GetPowerLevel(), and PowerLevelChanged().

◆ m_scheduledFeature

Feature MythPower::m_scheduledFeature { FeatureNone }
protected

◆ m_sleepTime

QDateTime MythPower::m_sleepTime
protected

Definition at line 97 of file mythpower.h.

Referenced by DidWakeUp(), and FeatureHappening().

◆ m_warnForLowBattery

bool MythPower::m_warnForLowBattery { false }
protected

Definition at line 99 of file mythpower.h.

Referenced by PowerLevelChanged().

◆ s_lock

QRecursiveMutex MythPower::s_lock
staticprotected

The documentation for this class was generated from the following files: