MythTV  master
mythpower.h
Go to the documentation of this file.
1 #ifndef MYTHPOWER_H
2 #define MYTHPOWER_H
3 
4 // Qt
5 #include <QtGlobal>
6 #include <QRecursiveMutex>
7 #include <QObject>
8 #include <QDateTime>
9 #include <QTimer>
10 
11 // MythTV
12 #include "mythbaseexp.h"
13 #include "mythchrono.h"
14 #include "referencecounter.h"
15 
16 static constexpr std::chrono::seconds DEFAULT_SHUTDOWN_WAIT { 5s };
17 static constexpr std::chrono::seconds MAXIMUM_SHUTDOWN_WAIT { 30s };
18 
19 class MBASE_PUBLIC MythPower : public QObject, public ReferenceCounter
20 {
21  Q_OBJECT
22 
23  public:
24  enum PowerLevel : std::int8_t
25  {
26  UPS = -2,
27  ACPower = -1,
28  BatteryEmpty = 0,
29  BatteryLow = 10,
30  BatteryFull = 100,
31  UnknownPower = 101,
32  Unset = 102,
33  };
34 
35  enum Feature : std::uint8_t
36  {
37  FeatureNone = 0x00,
38  FeatureShutdown = 0x01,
39  FeatureSuspend = 0x02,
40  FeatureHibernate = 0x04,
41  FeatureRestart = 0x08,
42  FeatureHybridSleep = 0x10
43  };
44 
45  Q_DECLARE_FLAGS(Features, Feature)
46 
47  static MythPower* AcquireRelease(void* Reference, bool Acquire, std::chrono::seconds MinimumDelay = 0s);
48  virtual bool RequestFeature (Feature Request, bool Delay = true);
49  Features GetFeatures (void);
50  bool IsFeatureSupported(Feature Supported);
51  int GetPowerLevel (void) const;
52  QStringList GetFeatureList (void);
53 
54  public slots:
55  virtual void CancelFeature (void);
56 
57  signals:
58  void ShuttingDown (void);
59  void Suspending (void);
60  void Hibernating (void);
61  void Restarting (void);
62  void HybridSleeping (void);
63  void WillShutDown (std::chrono::milliseconds MilliSeconds = 0ms);
64  void WillSuspend (std::chrono::milliseconds MilliSeconds = 0ms);
65  void WillHibernate (std::chrono::milliseconds MilliSeconds = 0ms);
66  void WillRestart (std::chrono::milliseconds MilliSeconds = 0ms);
67  void WillHybridSleep(std::chrono::milliseconds MilliSeconds = 0ms);
68  void WokeUp (std::chrono::seconds SecondsAsleep);
69  void LowBattery (void);
70 
71  protected slots:
72  void FeatureTimeout (void);
73  virtual void Refresh (void) { }
74 
75  protected:
76  static QRecursiveMutex s_lock;
77 
78  MythPower();
79  ~MythPower() override = default;
80 
81  virtual void Init (void);
82  virtual bool DoFeature (bool /*Delayed*/ = false) { return false; }
83  virtual void DidWakeUp (void);
84  virtual void FeatureHappening (Feature Spontaneous = FeatureNone);
85  virtual bool ScheduleFeature (enum Feature Type, std::chrono::seconds Delay);
86  void SetRequestedDelay (std::chrono::seconds Delay);
87  void PowerLevelChanged (int Level);
88  static QString FeatureToString (enum Feature Type);
89  static bool FeatureIsEquivalent(Feature First, Feature Second);
90 
91  Features m_features { FeatureNone };
92  Feature m_scheduledFeature { FeatureNone };
93  bool m_isSpontaneous { false };
94  std::chrono::seconds m_maxRequestedDelay { 0s };
95  std::chrono::seconds m_maxSupportedDelay { MAXIMUM_SHUTDOWN_WAIT };
97  QDateTime m_sleepTime;
98  int m_powerLevel { Unset };
99  bool m_warnForLowBattery { false };
100 
101  private:
102  Q_DISABLE_COPY(MythPower)
103 };
104 
105 Q_DECLARE_OPERATORS_FOR_FLAGS(MythPower::Features)
106 
107 #endif // MYTHPOWER_H
MythPower
Definition: mythpower.h:19
MythPower::PowerLevel
PowerLevel
Definition: mythpower.h:24
mythbaseexp.h
MythPower::m_sleepTime
QDateTime m_sleepTime
Definition: mythpower.h:97
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythPower::Feature
Feature
Definition: mythpower.h:35
referencecounter.h
hardwareprofile.distros.mythtv_data.request.Request
def Request(url=None)
Definition: request.py:62
DEFAULT_SHUTDOWN_WAIT
static constexpr std::chrono::seconds DEFAULT_SHUTDOWN_WAIT
Definition: mythpower.h:16
MythPower::s_lock
static QRecursiveMutex s_lock
Definition: mythpower.h:76
MythPower::DoFeature
virtual bool DoFeature(bool=false)
Definition: mythpower.h:82
MAXIMUM_SHUTDOWN_WAIT
static constexpr std::chrono::seconds MAXIMUM_SHUTDOWN_WAIT
Definition: mythpower.h:17
mythchrono.h
MythPower::m_featureTimer
QTimer m_featureTimer
Definition: mythpower.h:96
MythPower::Refresh
virtual void Refresh(void)
Definition: mythpower.h:73
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:26