16#define LOC QString("Power: ")
77 static QHash<void*,std::chrono::seconds> s_delays;
79 QMutexLocker locker(&
s_lock);
101 s_delays.insert(Reference, MinimumDelay);
106 s_delays.remove(Reference);
110 if (s_instance->
DecrRef() == 0)
111 s_instance =
nullptr;
117 std::chrono::seconds max = std::max_element(s_delays.cbegin(), s_delays.cend()).value();
133 if (supported.isEmpty())
135 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Supported actions: %1").arg(supported.join(
",")));
154 QStringList supported;
184 QMutexLocker locker(&
s_lock);
195 LOG(VB_GENERAL, LOG_DEBUG,
LOC + QString(
"Delay: %1 User: %2 Requested: %3 Supported: %4")
199 if (!Delay || delay < 1s)
224 QMutexLocker locker(&
s_lock);
227 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"No power request to cancel");
230 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Cancelling %1 request with %2 seconds remaining")
281 LOG(VB_GENERAL, LOG_ERR,
LOC +
282 QString(
"Ignoring %1 request: %2 pending in %3 seconds")
290 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Will %1 in %2 seconds")
313 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"About to: %1 %2")
330 QMutexLocker locker(&
s_lock);
335 static constexpr qint64 kSecsInDay { 24LL * 60 * 60 };
336 QDateTime now = QDateTime::currentDateTime();
338 qint64
days = secs / kSecsInDay;
339 QTime time = QTime(0, 0).addSecs(secs % kSecsInDay);
340 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Woke up after %1days %2hours %3minutes and %4seconds")
341 .arg(
days).arg(time.hour()).arg(time.minute()).arg(time.second()));
353 LOG(VB_GENERAL, LOG_INFO,
LOC +
"On AC power");
355 else if (Level ==
UPS)
358 LOG(VB_GENERAL, LOG_INFO,
LOC +
"On UPS");
362 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Battery at %1%").arg(Level));
368 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Low battery!");
379 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Unknown power source");
std::enable_if_t< std::chrono::__is_duration< T >::value, 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
duration< CHRONO_TYPE, ratio< 86400 > > days
static eu8 clamp(eu8 value, eu8 low, eu8 high)