Torc  0.1
torcpower.h
Go to the documentation of this file.
1 #ifndef TORCPOWER_H
2 #define TORCPOWER_H
3 
4 // Qt
5 #include <QObject>
6 #include <QMutex>
7 
8 // Torc
9 #include "torcsetting.h"
10 #include "torchttpservice.h"
11 
12 class TorcPower : public QObject, public TorcHTTPService
13 {
14  Q_OBJECT
15  Q_CLASSINFO("Version", "1.0.0")
16  Q_CLASSINFO("Shutdown", "methods=PUT")
17  Q_CLASSINFO("Suspend", "methods=PUT")
18  Q_CLASSINFO("Hibernate", "methods=PUT")
19  Q_CLASSINFO("Restart", "methods=PUT")
20  Q_PROPERTY(bool canShutdown READ GetCanShutdown NOTIFY CanShutdownChanged)
21  Q_PROPERTY(bool canSuspend READ GetCanSuspend NOTIFY CanSuspendChanged)
22  Q_PROPERTY(bool canHibernate READ GetCanHibernate NOTIFY CanHibernateChanged)
23  Q_PROPERTY(bool canRestart READ GetCanRestart NOTIFY CanRestartChanged)
24  Q_PROPERTY(int batteryLevel READ GetBatteryLevel NOTIFY BatteryLevelChanged)
25 
26  public:
28  {
29  ACPower = -1,
31  BatteryLow = 10,
32  BatteryFull = 100,
34  };
35 
36  public:
37  static void Create(void);
38  static void TearDown(void);
39 
40  public:
41  virtual ~TorcPower();
42  QString GetUIName (void) override;
43  bool event (QEvent *Event) override;
44 
45  signals:
46  void CanShutdownChanged (bool CanShutdown);
47  void CanSuspendChanged (bool CanSuspend);
48  void CanHibernateChanged (bool CanHibernate);
49  void CanRestartChanged (bool CanRestart);
50  void BatteryLevelChanged (int BatteryLevel);
51 
52  public slots:
53  void SubscriberDeleted (QObject *Subscriber);
54 
55  bool GetCanShutdown (void);
56  bool GetCanSuspend (void);
57  bool GetCanHibernate (void);
58  bool GetCanRestart (void);
59  int GetBatteryLevel (void);
60  QVariantMap GetPowerStatus (void);
61 
62  bool Shutdown (void);
63  bool Suspend (void);
64  bool Hibernate (void);
65  bool Restart (void);
66 
67  void ShuttingDown (void);
68  void Suspending (void);
69  void Hibernating (void);
70  void Restarting (void);
71  void WokeUp (void);
72  void LowBattery (void);
73 
74  protected slots:
75  void CanShutdownActiveChanged (bool Active);
76  void CanSuspendActiveChanged (bool Active);
77  void CanHibernateActiveChanged (bool Active);
78  void CanRestartActiveChanged (bool Active);
79  void CanShutdownValueChanged (bool Value);
80  void CanSuspendValueChanged (bool Value);
81  void CanHibernateValueChanged (bool Value);
82  void CanRestartValueChanged (bool Value);
83 
84  protected:
85  TorcPower();
86  void BatteryUpdated (int Level);
87  void Debug (void);
88  virtual bool DoShutdown (void) = 0;
89  virtual bool DoSuspend (void) = 0;
90  virtual bool DoHibernate (void) = 0;
91  virtual bool DoRestart (void) = 0;
92 
98 
99  private:
100  TorcSettingGroup *m_powerGroupItem;
101  TorcSetting *m_powerEnabled;
102  TorcSetting *m_allowShutdown;
103  TorcSetting *m_allowSuspend;
104  TorcSetting *m_allowHibernate;
105  TorcSetting *m_allowRestart;
106  int m_lastBatteryLevel;
107 
108  bool canShutdown; // dummy
109  bool canSuspend; // dummy
110  bool canHibernate; // dummy
111  bool canRestart; // dummy
112  int batteryLevel; // dummy
113 
114  private:
115  Q_DISABLE_COPY(TorcPower)
116 };
117 
122 class TorcPowerNull : public TorcPower
123 {
124  Q_OBJECT
125  public:
127  ~TorcPowerNull() = default;
128  bool DoShutdown (void) { return false; }
129  bool DoSuspend (void) { return false; }
130  bool DoHibernate (void) { return false; }
131  bool DoRestart (void) { return false; }
132 };
133 
135 {
136  public:
138  virtual ~TorcPowerFactory() = default;
139 
140  static TorcPower* CreatePower (void);
141  static TorcPowerFactory* GetTorcPowerFactory (void);
142  TorcPowerFactory* NextPowerFactory (void) const;
143  virtual void Score (int &Score) = 0;
144  virtual TorcPower* Create (int Score) = 0;
145 
146  protected:
149 
150  private:
151  Q_DISABLE_COPY(TorcPowerFactory)
152 };
153 
154 #endif // TORCPOWER_H
QVariantMap GetPowerStatus(void)
Definition: torcpower.cpp:482
void CanHibernateActiveChanged(bool Active)
Definition: torcpower.cpp:450
bool Hibernate(void)
Definition: torcpower.cpp:351
bool canRestart
Definition: torcpower.h:23
static void TearDown(void)
void CanShutdownChanged(bool CanShutdown)
void Restarting(void)
Definition: torcpower.cpp:511
bool Suspend(void)
Definition: torcpower.cpp:340
High level group of related settings.
Definition: torcsetting.h:123
A wrapper around a database setting.
Definition: torcsetting.h:15
bool event(QEvent *Event) override
Definition: torcpower.cpp:306
bool GetCanSuspend(void)
Definition: torcpower.cpp:386
void BatteryLevelChanged(int BatteryLevel)
static void Create(void)
void BatteryUpdated(int Level)
Definition: torcpower.cpp:275
void Debug(void)
Definition: torcpower.cpp:251
bool GetCanHibernate(void)
Definition: torcpower.cpp:394
TorcSetting * m_canHibernate
Definition: torcpower.h:95
bool canHibernate
Definition: torcpower.h:22
virtual ~TorcPower()
Definition: torcpower.cpp:198
void CanHibernateChanged(bool CanHibernate)
void CanRestartValueChanged(bool Value)
Definition: torcpower.cpp:474
void LowBattery(void)
Definition: torcpower.cpp:523
virtual bool DoSuspend(void)=0
TorcSetting * m_canSuspend
Definition: torcpower.h:94
virtual bool DoHibernate(void)=0
A dummy/default power implementation.
Definition: torcpower.h:122
TorcPowerFactory * nextPowerFactory
Definition: torcpower.h:148
void Hibernating(void)
Definition: torcpower.cpp:505
int batteryLevel
Definition: torcpower.h:24
bool DoShutdown(void)
Definition: torcpower.h:128
virtual bool DoRestart(void)=0
void ShuttingDown(void)
Definition: torcpower.cpp:493
bool canSuspend
Definition: torcpower.h:21
bool GetCanRestart(void)
Definition: torcpower.cpp:402
void Suspending(void)
Definition: torcpower.cpp:499
TorcSetting * m_canShutdown
Definition: torcpower.h:93
static TorcPowerFactory * gPowerFactory
Definition: torcpower.h:147
void WokeUp(void)
Definition: torcpower.cpp:517
bool canShutdown
Definition: torcpower.h:20
void CanSuspendValueChanged(bool Value)
Definition: torcpower.cpp:442
A generic power status class.
Definition: torcpower.h:12
void CanHibernateValueChanged(bool Value)
Definition: torcpower.cpp:458
QString GetUIName(void) override
Definition: torcpower.cpp:270
int m_batteryLevel
Definition: torcpower.h:97
virtual bool DoShutdown(void)=0
bool DoHibernate(void)
Definition: torcpower.h:130
void CanSuspendChanged(bool CanSuspend)
bool DoSuspend(void)
Definition: torcpower.h:129
void CanRestartActiveChanged(bool Active)
Definition: torcpower.cpp:466
void CanRestartChanged(bool CanRestart)
int GetBatteryLevel(void)
Definition: torcpower.cpp:410
bool GetCanShutdown(void)
Definition: torcpower.cpp:378
bool Restart(void)
Definition: torcpower.cpp:362
TorcSetting * m_canRestart
Definition: torcpower.h:96
void CanShutdownActiveChanged(bool Active)
Definition: torcpower.cpp:418
bool Shutdown(void)
Definition: torcpower.cpp:329
void CanSuspendActiveChanged(bool Active)
Definition: torcpower.cpp:434
void SubscriberDeleted(QObject *Subscriber)
Definition: torcpower.cpp:373
void CanShutdownValueChanged(bool Value)
Definition: torcpower.cpp:426
bool DoRestart(void)
Definition: torcpower.h:131