MythTV  master
Public Slots | Static Public Member Functions | Protected Slots | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
MythPowerDBus Class Reference

#include <mythpowerdbus.h>

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

Public Slots

void CancelFeature (void) override
 This is untested. More...
 
void Changed (void)
 
void DeviceAdded (const QDBusObjectPath &Device)
 
void DeviceRemoved (const QDBusObjectPath &Device)
 
void DeviceChanged (const QDBusObjectPath &Device)
 Update power device state. More...
 
void DBusSuspending (bool Stopping)
 
void DBusShuttingDown (bool Stopping)
 
- Public Slots inherited from MythPower
virtual void CancelFeature (void)
 This is untested as it is currently not clear whether it is useful. More...
 

Static Public Member Functions

static bool IsAvailable (void)
 Static check for DBus interfaces that support some form of power management. More...
 
- Static Public Member Functions inherited from MythPower
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 ReleaseLock (void)
 Release our inhibition lock. More...
 
- Protected Slots inherited from MythPower
void FeatureTimeout (void)
 
virtual void Refresh (void)
 

Protected Member Functions

 MythPowerDBus ()
 
 ~MythPowerDBus () override
 
void Init (void) override
 
bool DoFeature (bool Delayed=false) override
 
void DidWakeUp (void) override
 
bool ScheduleFeature (enum Feature Type, uint Delay) override
 Schedule a MythTV initiated power feature. More...
 
- Protected Member Functions inherited from MythPower
 MythPower ()
 
 ~MythPower () override=default
 
virtual void FeatureHappening (Feature Spontaneous=FeatureNone)
 Signal to the rest of MythTV that the given feature will happen now. More...
 
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...
 

Private Member Functions

bool UpdateStatus (void)
 
int RetrieveBatteryLevel (const QString &Path)
 
void UpdateBattery (void)
 
void UpdateProperties (void)
 
void AcquireLock (Features Types)
 Acquire an inhibition lock for logind power events. More...
 

Private Attributes

bool m_onBattery { false }
 
QMap< QString, int > m_batteries { }
 
QDBusConnection m_bus { QDBusConnection::systemBus() }
 
QDBusInterface * m_upowerInterface { nullptr }
 
QDBusInterface * m_logindInterface { nullptr }
 
int m_lockHandle { -1 }
 
QTimer m_delayTimer { }
 

Friends

class MythPower
 

Additional Inherited Members

- Public Types inherited from MythPower
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
}
 
- Signals inherited from MythPower
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 inherited from MythPower
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 Protected Member Functions inherited from MythPower
static QString FeatureToString (enum Feature Type)
 
static bool FeatureIsEquivalent (Feature First, Feature Second)
 
- Protected Attributes inherited from MythPower
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 inherited from MythPower
static QMutex s_lock
 

Detailed Description

Definition at line 10 of file mythpowerdbus.h.

Constructor & Destructor Documentation

◆ MythPowerDBus()

MythPowerDBus::MythPowerDBus ( )
protected

Definition at line 60 of file mythpowerdbus.cpp.

◆ ~MythPowerDBus()

MythPowerDBus::~MythPowerDBus ( )
overrideprotected

Definition at line 67 of file mythpowerdbus.cpp.

Member Function Documentation

◆ IsAvailable()

bool MythPowerDBus::IsAvailable ( void  )
static

Static check for DBus interfaces that support some form of power management.

This currently looks for UPower and login1 (logind) interfaces.

UPower is used for battery status.

logind manages shutdown, suspend etc. We make use of ScheduleShutdown where possible to integrate better with other services and mimic ScheduleShutdown otherwise (e.g. for suspend). Two different MythTV services (e.g both frontend and backend) should integrate well with their behaviour as both can delay events independantly as needed (though this might lead to user confusion if an event is delayed longer than they expect).

Note
ConsoleKit appears to be dead in the water (and reported as dangerous!).
The UPower interface is now focused on battery device status and does not support Suspend or Hibernate in more recent specs.
HAL is deprecated.
Todo:
Check status of KDE ("org.kde.KSMServerInterface") and Gnome("org.gnome.SessionManager").

Definition at line 41 of file mythpowerdbus.cpp.

Referenced by MythPower::AcquireRelease().

◆ CancelFeature

void MythPowerDBus::CancelFeature ( void  )
overrideslot

This is untested.

Definition at line 342 of file mythpowerdbus.cpp.

◆ Changed

void MythPowerDBus::Changed ( void  )
slot

Definition at line 351 of file mythpowerdbus.cpp.

Referenced by Init().

◆ DeviceAdded

void MythPowerDBus::DeviceAdded ( const QDBusObjectPath &  Device)
slot

Definition at line 358 of file mythpowerdbus.cpp.

Referenced by Init().

◆ DeviceRemoved

void MythPowerDBus::DeviceRemoved ( const QDBusObjectPath &  Device)
slot

Definition at line 370 of file mythpowerdbus.cpp.

Referenced by Init().

◆ DeviceChanged

void MythPowerDBus::DeviceChanged ( const QDBusObjectPath &  Device)
slot

Update power device state.

This is typically called by the UPower service when the battery state has changed.

Definition at line 387 of file mythpowerdbus.cpp.

Referenced by Init().

◆ DBusSuspending

void MythPowerDBus::DBusSuspending ( bool  Stopping)
slot

Definition at line 185 of file mythpowerdbus.cpp.

Referenced by Init().

◆ DBusShuttingDown

void MythPowerDBus::DBusShuttingDown ( bool  Stopping)
slot

Definition at line 200 of file mythpowerdbus.cpp.

Referenced by Init().

◆ ReleaseLock

void MythPowerDBus::ReleaseLock ( void  )
protectedslot

Release our inhibition lock.

This will be called when we exit (cleanup) or when we are ready implement or allow shutdown/resume events.

Definition at line 551 of file mythpowerdbus.cpp.

Referenced by AcquireLock(), DoFeature(), MythPowerDBus(), and ~MythPowerDBus().

◆ Init()

void MythPowerDBus::Init ( void  )
overrideprotectedvirtual

Reimplemented from MythPower.

Definition at line 77 of file mythpowerdbus.cpp.

Referenced by MythPowerDBus().

◆ DoFeature()

bool MythPowerDBus::DoFeature ( bool  Delayed = false)
overrideprotectedvirtual

Reimplemented from MythPower.

Definition at line 164 of file mythpowerdbus.cpp.

Referenced by ScheduleFeature().

◆ DidWakeUp()

void MythPowerDBus::DidWakeUp ( void  )
overrideprotectedvirtual

Reimplemented from MythPower.

Definition at line 263 of file mythpowerdbus.cpp.

Referenced by DBusShuttingDown(), and DBusSuspending().

◆ ScheduleFeature()

bool MythPowerDBus::ScheduleFeature ( enum Feature  Type,
uint  Delay 
)
overrideprotectedvirtual

Schedule a MythTV initiated power feature.

The default MythPopwer implementation will schedule the feature at a point in the future. logind however allows us to schedule shutdown events (but not suspend/hibernate etc). This has the advantage that logind will send a PrepareForShutdown signal - which gives other services advanced warning of the pending shutdown and allows them to prepare properly.

For suspend type events, we mimic the delay by initiating the suspend straight away but retaining the inhibition lock until we are ready. This plays nicely with other services (which receive the PrepareForSleep signal immediately) but on some systems means the display is turned off too soon.

Reimplemented from MythPower.

Definition at line 284 of file mythpowerdbus.cpp.

◆ UpdateStatus()

bool MythPowerDBus::UpdateStatus ( void  )
private

Definition at line 215 of file mythpowerdbus.cpp.

Referenced by DBusShuttingDown(), and DBusSuspending().

◆ RetrieveBatteryLevel()

int MythPowerDBus::RetrieveBatteryLevel ( const QString &  Path)
private

Definition at line 465 of file mythpowerdbus.cpp.

Referenced by DeviceAdded(), and DeviceChanged().

◆ UpdateBattery()

void MythPowerDBus::UpdateBattery ( void  )
private

Definition at line 430 of file mythpowerdbus.cpp.

Referenced by Changed(), DeviceAdded(), DeviceChanged(), and DeviceRemoved().

◆ UpdateProperties()

void MythPowerDBus::UpdateProperties ( void  )
private

Definition at line 398 of file mythpowerdbus.cpp.

Referenced by Changed().

◆ AcquireLock()

void MythPowerDBus::AcquireLock ( Features  Types)
private

Acquire an inhibition lock for logind power events.

We typically acquire a lock for both suspend and shutdown. We must hold this at all times (when we want to inhibit those events). Failure to hold a lock may lead to race conditions and other unpredictable behaviour. When we are ready, the lock is released (closed) and logind will proceed. On resume, we take a new lock immediately.

Note
We only ask for delay inhibition.
See also
ReleaseLock

Definition at line 512 of file mythpowerdbus.cpp.

Referenced by DidWakeUp(), and Init().

Friends And Related Function Documentation

◆ MythPower

friend class MythPower
friend

Definition at line 14 of file mythpowerdbus.h.

Member Data Documentation

◆ m_onBattery

bool MythPowerDBus::m_onBattery { false }
private

Definition at line 47 of file mythpowerdbus.h.

Referenced by RetrieveBatteryLevel(), UpdateBattery(), and UpdateProperties().

◆ m_batteries

QMap<QString,int> MythPowerDBus::m_batteries { }
private

Definition at line 48 of file mythpowerdbus.h.

Referenced by DeviceAdded(), DeviceChanged(), DeviceRemoved(), and UpdateBattery().

◆ m_bus

QDBusConnection MythPowerDBus::m_bus { QDBusConnection::systemBus() }
private

Definition at line 49 of file mythpowerdbus.h.

Referenced by Init(), and RetrieveBatteryLevel().

◆ m_upowerInterface

QDBusInterface* MythPowerDBus::m_upowerInterface { nullptr }
private

Definition at line 50 of file mythpowerdbus.h.

Referenced by Init(), and ~MythPowerDBus().

◆ m_logindInterface

QDBusInterface* MythPowerDBus::m_logindInterface { nullptr }
private

◆ m_lockHandle

int MythPowerDBus::m_lockHandle { -1 }
private

Definition at line 52 of file mythpowerdbus.h.

Referenced by AcquireLock(), and ReleaseLock().

◆ m_delayTimer

QTimer MythPowerDBus::m_delayTimer { }
private

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