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