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 <mythpower.h>

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

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 (uint MilliSeconds=0)
 
void WillSuspend (uint MilliSeconds=0)
 
void WillHibernate (uint MilliSeconds=0)
 
void WillRestart (uint MilliSeconds=0)
 
void WillHybridSleep (uint MilliSeconds=0)
 
void WokeUp (qint64 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, uint MinimumDelay=0)
 
- 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, uint Delay)
 
void SetRequestedDelay (uint 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 }
 
uint m_maxRequestedDelay { 0 }
 
uint 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 QMutex 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 18 of file mythpower.h.

Member Enumeration Documentation

◆ PowerLevel

Enumerator
UPS 
ACPower 
BatteryEmpty 
BatteryLow 
BatteryFull 
UnknownPower 
Unset 

Definition at line 23 of file mythpower.h.

◆ Feature

Enumerator
FeatureNone 
FeatureShutdown 
FeatureSuspend 
FeatureHibernate 
FeatureRestart 
FeatureHybridSleep 

Definition at line 34 of file mythpower.h.

Constructor & Destructor Documentation

◆ MythPower()

MythPower::MythPower ( )
protected

Definition at line 119 of file mythpower.cpp.

Referenced by AcquireRelease().

◆ ~MythPower()

MythPower::~MythPower ( )
overrideprotecteddefault

Member Function Documentation

◆ AcquireRelease()

MythPower * MythPower::AcquireRelease ( void *  Reference,
bool  Acquire,
uint  MinimumDelay = 0 
)
static

◆ RequestFeature()

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

◆ GetFeatures()

MythPower::Features MythPower::GetFeatures ( void  )

Definition at line 139 of file mythpower.cpp.

Referenced by GetFeatureList().

◆ IsFeatureSupported()

bool MythPower::IsFeatureSupported ( Feature  Supported)

◆ GetPowerLevel()

int MythPower::GetPowerLevel ( void  ) const

Definition at line 169 of file mythpower.cpp.

◆ GetFeatureList()

QStringList MythPower::GetFeatureList ( void  )

Definition at line 148 of file mythpower.cpp.

Referenced by Init(), and OverrideExitMenu().

◆ CancelFeature

void MythPower::CancelFeature ( void  )
virtualslot

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

Definition at line 217 of file mythpower.cpp.

Referenced by MythPowerDBus::CancelFeature().

◆ ShuttingDown

void MythPower::ShuttingDown ( void  )
signal

Referenced by FeatureHappening().

◆ Suspending

void MythPower::Suspending ( void  )
signal

Referenced by FeatureHappening().

◆ Hibernating

void MythPower::Hibernating ( void  )
signal

Referenced by FeatureHappening().

◆ Restarting

void MythPower::Restarting ( void  )
signal

Referenced by FeatureHappening().

◆ HybridSleeping

void MythPower::HybridSleeping ( void  )
signal

Referenced by FeatureHappening().

◆ WillShutDown

void MythPower::WillShutDown ( uint  MilliSeconds = 0)
signal

◆ WillSuspend

void MythPower::WillSuspend ( uint  MilliSeconds = 0)
signal

◆ WillHibernate

void MythPower::WillHibernate ( uint  MilliSeconds = 0)
signal

Referenced by RequestFeature().

◆ WillRestart

void MythPower::WillRestart ( uint  MilliSeconds = 0)
signal

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

◆ WillHybridSleep

void MythPower::WillHybridSleep ( uint  MilliSeconds = 0)
signal

Referenced by RequestFeature().

◆ WokeUp

void MythPower::WokeUp ( qint64  SecondsAsleep)
signal

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

◆ LowBattery

void MythPower::LowBattery ( void  )
signal

Referenced by PowerLevelChanged().

◆ FeatureTimeout

void MythPower::FeatureTimeout ( void  )
protectedslot

Definition at line 233 of file mythpower.cpp.

Referenced by MythPower().

◆ Refresh

virtual void MythPower::Refresh ( void  )
inlineprotectedvirtualslot

Definition at line 72 of file mythpower.h.

◆ Init()

void MythPower::Init ( void  )
protectedvirtual

Reimplemented in MythPowerOSX, and MythPowerDBus.

Definition at line 126 of file mythpower.cpp.

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

◆ DoFeature()

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

Reimplemented in MythPowerOSX, and MythPowerDBus.

Definition at line 81 of file mythpower.h.

Referenced by FeatureTimeout(), and RequestFeature().

◆ DidWakeUp()

void MythPower::DidWakeUp ( void  )
protectedvirtual

Reimplemented in MythPowerDBus.

Definition at line 323 of file mythpower.cpp.

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

◆ 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 296 of file mythpower.cpp.

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

◆ ScheduleFeature()

bool MythPower::ScheduleFeature ( enum Feature  Type,
uint  Delay 
)
protectedvirtual

Reimplemented in MythPowerDBus.

Definition at line 269 of file mythpower.cpp.

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

◆ SetRequestedDelay()

void MythPower::SetRequestedDelay ( uint  Delay)
protected

Definition at line 134 of file mythpower.cpp.

Referenced by AcquireRelease().

◆ PowerLevelChanged()

void MythPower::PowerLevelChanged ( int  Level)
protected

Definition at line 340 of file mythpower.cpp.

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

◆ FeatureToString()

QString MythPower::FeatureToString ( enum Feature  Type)
staticprotected

◆ FeatureIsEquivalent()

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

Member Data Documentation

◆ s_lock

QMutex MythPower::s_lock
staticprotected

◆ m_features

Features MythPower::m_features { FeatureNone }
protected

◆ m_scheduledFeature

Feature MythPower::m_scheduledFeature { FeatureNone }
protected

◆ m_isSpontaneous

bool MythPower::m_isSpontaneous { false }
protected

Definition at line 92 of file mythpower.h.

Referenced by DidWakeUp(), and FeatureHappening().

◆ m_maxRequestedDelay

uint MythPower::m_maxRequestedDelay { 0 }
protected

Definition at line 93 of file mythpower.h.

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

◆ m_maxSupportedDelay

uint MythPower::m_maxSupportedDelay { MAXIMUM_SHUTDOWN_WAIT }
protected

◆ m_featureTimer

QTimer MythPower::m_featureTimer { }
protected

◆ m_sleepTime

QDateTime MythPower::m_sleepTime { }
protected

Definition at line 96 of file mythpower.h.

Referenced by DidWakeUp(), and FeatureHappening().

◆ m_powerLevel

int MythPower::m_powerLevel { Unset }
protected

Definition at line 97 of file mythpower.h.

Referenced by GetPowerLevel(), and PowerLevelChanged().

◆ m_warnForLowBattery

bool MythPower::m_warnForLowBattery { false }
protected

Definition at line 98 of file mythpower.h.

Referenced by PowerLevelChanged().


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