25 #include <QCoreApplication> 35 void Score(
int &Score)
80 (
void)factory->
Score(score);
85 power = factory->
Create(score);
91 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to create power implementation"));
120 TorcHTTPService(this, QStringLiteral(
"power"), QStringLiteral(
"power"),
TorcPower::staticMetaObject, QStringLiteral(
"ShuttingDown,Suspending,Hibernating,Restarting,WokeUp,LowBattery,Refresh")),
127 m_powerEnabled(new
TorcSetting(m_powerGroupItem, QStringLiteral(
"EnablePower"),
128 tr(
"Enable power management"),
130 m_allowShutdown(new
TorcSetting(m_powerEnabled, QStringLiteral(
"AllowShutdown"),
131 tr(
"Allow Torc to shutdown the system"),
133 m_allowSuspend(new
TorcSetting(m_powerEnabled, QStringLiteral(
"AllowSuspend"),
134 tr(
"Allow Torc to suspend the system"),
136 m_allowHibernate(new
TorcSetting(m_powerEnabled, QStringLiteral(
"AllowHibernate"),
137 tr(
"Allow Torc to hibernate the system"),
139 m_allowRestart(new
TorcSetting(m_powerEnabled, QStringLiteral(
"AllowRestart"),
140 tr(
"Allow Torc to restart the system"),
142 m_lastBatteryLevel(UnknownPower),
147 batteryLevel(UnknownPower)
165 if (m_powerEnabled->
GetValue().toBool())
216 m_allowShutdown->
Remove();
226 if (m_allowHibernate)
228 m_allowHibernate->
Remove();
244 if (m_powerGroupItem)
246 m_powerGroupItem->
Remove();
256 caps += QStringLiteral(
"Shutdown ");
258 caps += QStringLiteral(
"Suspend ");
260 caps += QStringLiteral(
"Hibernate ");
262 caps += QStringLiteral(
"Restart ");
265 caps = QStringLiteral(
"None");
267 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Power support: %1").arg(caps));
279 if (m_lastBatteryLevel == Level)
285 bool wasalreadylow = m_lastBatteryLevel >= 0 && m_lastBatteryLevel <=
BatteryLow;
286 m_lastBatteryLevel = Level;
288 if (m_lastBatteryLevel ==
ACPower)
289 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"On AC power"));
291 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Unknown power status"));
293 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Battery level %1%").arg(m_lastBatteryLevel));
296 bool lowbattery = !wasalreadylow && (m_lastBatteryLevel >= 0 && m_lastBatteryLevel <=
BatteryLow);
297 int level = m_lastBatteryLevel;
326 return QObject::event(Event);
421 bool changed = m_allowShutdown->
GetValue().toBool() && Active;
429 bool changed = Value && m_allowShutdown->
GetIsActive();
437 bool changed = m_allowSuspend->
GetValue().toBool() && Active;
445 bool changed = Value && m_allowSuspend->
GetIsActive();
453 bool changed = m_allowHibernate->
GetValue().toBool() && Active;
461 bool changed = Value && m_allowHibernate->
GetIsActive();
469 bool changed = m_allowHibernate->
GetValue().toBool() && Active;
477 bool changed = Value && m_allowHibernate->
GetIsActive();
486 result.insert(QStringLiteral(
"canSuspend"),
GetCanSuspend());
488 result.insert(QStringLiteral(
"canRestart"),
GetCanRestart());
495 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"System will shut down"));
501 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"System will go to sleep"));
507 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"System will hibernate"));
513 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"System restarting"));
519 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"System woke up"));
525 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Sending low battery warning"));
550 Strings.insert(QStringLiteral(
"Suspend"), QCoreApplication::translate(
"TorcPower",
"Suspend"));
551 Strings.insert(QStringLiteral(
"Shutdown"), QCoreApplication::translate(
"TorcPower",
"Shutdown"));
552 Strings.insert(QStringLiteral(
"Hibernate"), QCoreApplication::translate(
"TorcPower",
"Hibernate"));
553 Strings.insert(QStringLiteral(
"Restart"), QCoreApplication::translate(
"TorcPower",
"Restart"));
554 Strings.insert(QStringLiteral(
"ConfirmSuspend"), QCoreApplication::translate(
"TorcPower",
"Are you sure you want to suspend the device?"));
555 Strings.insert(QStringLiteral(
"ConfirmShutdown"), QCoreApplication::translate(
"TorcPower",
"Are you sure you want to shutdown the device?"));
556 Strings.insert(QStringLiteral(
"ConfirmHibernate"), QCoreApplication::translate(
"TorcPower",
"Are you sure you want to hibernate the device?"));
557 Strings.insert(QStringLiteral(
"ConfirmRestart"), QCoreApplication::translate(
"TorcPower",
"Are you sure you want to restart the device?"));
558 Strings.insert(QStringLiteral(
"ACPowerTr"), QCoreApplication::translate(
"TorcPower",
"On AC Power"));
559 Strings.insert(QStringLiteral(
"UnknownPowerTr"), QCoreApplication::translate(
"TorcPower",
"Unknown power status"));
void GetStrings(QVariantMap &Strings)
QVariantMap GetPowerStatus(void)
void CanHibernateActiveChanged(bool Active)
void CanShutdownChanged(bool CanShutdown)
TorcLocalContext * gLocalContext
High level group of related settings.
A static class used to create the TorcPower singleton in the admin thread.
#define TORC_ADMIN_MED_PRIORITY
A wrapper around a database setting.
bool event(QEvent *Event) override
A factory class for automatically running objects outside of the main loop.
int GetEvent(void)
Return the Torc action associated with this event.
void BatteryLevelChanged(int BatteryLevel)
void BatteryUpdated(int Level)
TorcPowerFactory * NextPowerFactory(void) const
bool GetCanHibernate(void)
TorcSetting * m_canHibernate
virtual bool DownRef(void)
virtual TorcPower * Create(int Score)=0
void CanHibernateChanged(bool CanHibernate)
void CanRestartValueChanged(bool Value)
static void NotifyEvent(int Event)
virtual bool DoSuspend(void)=0
TorcSetting * m_canSuspend
static TorcPower * CreatePower(void)
virtual bool DoHibernate(void)=0
A dummy/default power implementation.
TorcPowerFactory * nextPowerFactory
virtual bool DoRestart(void)=0
static TorcPowerFactory * GetTorcPowerFactory(void)
void HandleSubscriberDeleted(QObject *Subscriber)
QReadWriteLock m_httpServiceLock
TorcSetting * m_canShutdown
static TorcPowerFactory * gPowerFactory
void CanSuspendValueChanged(bool Value)
A generic power status class.
void CanHibernateValueChanged(bool Value)
QString GetUIName(void) override
A general purpose event object.
virtual void Score(int &Score)=0
virtual bool DoShutdown(void)=0
#define LOG(_MASK_, _LEVEL_, _STRING_)
void ActiveChanged(bool Active)
void AddObserver(QObject *Observer)
brief Register the given object to receive events.
A factory class to register translatable strings for use with external interfaces/applications.
void CanSuspendChanged(bool CanSuspend)
void SetActiveThreshold(int Threshold)
void ValueChanged(int Value)
void CanRestartActiveChanged(bool Active)
void RemoveObserver(QObject *Observer)
brief Deregister the given object.
TorcPowerObject TorcPowerObject
bool QueueShutdownEvent(int Event)
void CanRestartChanged(bool CanRestart)
int GetBatteryLevel(void)
bool GetCanShutdown(void)
TorcSetting * m_canRestart
void CanShutdownActiveChanged(bool Active)
TorcPowerFactoryNull TorcPowerFactoryNull
void CanSuspendActiveChanged(bool Active)
void SubscriberDeleted(QObject *Subscriber)
void CanShutdownValueChanged(bool Value)
void SetActive(bool Value)