19#define LOC QString("Power: ")
80 static QHash<void*,std::chrono::seconds> s_delays;
82 QMutexLocker locker(&
s_lock);
104 s_delays.insert(Reference, MinimumDelay);
109 s_delays.remove(Reference);
113 if (s_instance->
DecrRef() == 0)
114 s_instance =
nullptr;
120 std::chrono::seconds max = std::ranges::max_element(std::as_const(s_delays)).value();
136 if (supported.isEmpty())
138 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Supported actions: %1").arg(supported.join(
",")));
157 QStringList supported;
187 QMutexLocker locker(&
s_lock);
198 LOG(VB_GENERAL, LOG_DEBUG,
LOC + QString(
"Delay: %1 User: %2 Requested: %3 Supported: %4")
202 if (!Delay || delay < 1s)
227 QMutexLocker locker(&
s_lock);
231 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"No power request to cancel");
235 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Cancelling %1 request with %2 seconds remaining")
286 LOG(VB_GENERAL, LOG_ERR,
LOC +
287 QString(
"Ignoring %1 request: %2 pending in %3 seconds")
295 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Will %1 in %2 seconds")
318 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"About to: %1 %2")
335 QMutexLocker locker(&
s_lock);
340 static constexpr qint64 kSecsInDay { 24LL * 60 * 60 };
341 QDateTime now = QDateTime::currentDateTime();
343 qint64 days = secs / kSecsInDay;
344 QTime time = QTime(0, 0).addSecs(secs % kSecsInDay);
345 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Woke up after %1days %2hours %3minutes and %4seconds")
346 .arg(days).arg(time.hour()).arg(time.minute()).arg(time.second()));
358 LOG(VB_GENERAL, LOG_INFO,
LOC +
"On AC power");
360 else if (Level ==
UPS)
363 LOG(VB_GENERAL, LOG_INFO,
LOC +
"On UPS");
367 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Battery at %1%").arg(Level));
373 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Low battery!");
384 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Unknown power source");
T GetDurSetting(const QString &key, T defaultval=T::zero())
static bool IsAvailable(void)
Static check for DBus interfaces that support some form of power management.
virtual bool DoFeature(bool=false)
std::chrono::seconds m_maxRequestedDelay
void WokeUp(std::chrono::seconds SecondsAsleep)
void FeatureTimeout(void)
static QRecursiveMutex s_lock
void WillSuspend(std::chrono::milliseconds MilliSeconds=0ms)
virtual bool RequestFeature(Feature Request, bool Delay=true)
virtual void FeatureHappening(Feature Spontaneous=FeatureNone)
Signal to the rest of MythTV that the given feature will happen now.
void HybridSleeping(void)
virtual void DidWakeUp(void)
Feature m_scheduledFeature
static bool FeatureIsEquivalent(Feature First, Feature Second)
void PowerLevelChanged(int Level)
Features GetFeatures(void)
bool IsFeatureSupported(Feature Supported)
void WillHybridSleep(std::chrono::milliseconds MilliSeconds=0ms)
void SetRequestedDelay(std::chrono::seconds Delay)
static MythPower * AcquireRelease(void *Reference, bool Acquire, std::chrono::seconds MinimumDelay=0s)
static QString FeatureToString(enum Feature Type)
virtual void CancelFeature(void)
This is untested as it is currently not clear whether it is useful.
std::chrono::seconds m_maxSupportedDelay
void WillShutDown(std::chrono::milliseconds MilliSeconds=0ms)
QStringList GetFeatureList(void)
int GetPowerLevel(void) const
void WillRestart(std::chrono::milliseconds MilliSeconds=0ms)
virtual bool ScheduleFeature(enum Feature Type, std::chrono::seconds Delay)
void WillHibernate(std::chrono::milliseconds MilliSeconds=0ms)
General purpose reference counter.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
virtual int IncrRef(void)
Increments reference count.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static constexpr std::chrono::seconds MAXIMUM_SHUTDOWN_WAIT
static eu8 clamp(eu8 value, eu8 low, eu8 high)