From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/interfaces/legacy/Monitor.cpp | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 xbmc/interfaces/legacy/Monitor.cpp (limited to 'xbmc/interfaces/legacy/Monitor.cpp') diff --git a/xbmc/interfaces/legacy/Monitor.cpp b/xbmc/interfaces/legacy/Monitor.cpp new file mode 100644 index 0000000..34d0553 --- /dev/null +++ b/xbmc/interfaces/legacy/Monitor.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "Monitor.h" + +#include "threads/SystemClock.h" + +#include +#include + +using namespace std::chrono_literals; + +namespace XBMCAddon +{ + namespace xbmc + { + Monitor::Monitor(): abortEvent(true) + { + XBMC_TRACE; + if (languageHook) + { + Id = languageHook->GetAddonId(); + invokerId = languageHook->GetInvokerId(); + languageHook->RegisterMonitorCallback(this); + } + } + + void Monitor::AbortNotify() + { + XBMC_TRACE; + abortEvent.Set(); + } + + bool Monitor::waitForAbort(double timeout) + { + XBMC_TRACE; + int timeoutMS = ceil(timeout * 1000); + XbmcThreads::EndTime<> endTime{std::chrono::milliseconds(timeoutMS)}; + + if (timeoutMS <= 0) + endTime.SetInfinite(); + + while (!endTime.IsTimePast()) + { + { + DelayedCallGuard dg(languageHook); + auto timeout = std::min(endTime.GetTimeLeft(), 100ms); + if (abortEvent.Wait(timeout)) + return true; + } + if (languageHook) + languageHook->MakePendingCalls(); + } + return false; + } + + bool Monitor::abortRequested() + { + XBMC_TRACE; + return abortEvent.Signaled(); + } + + Monitor::~Monitor() + { + XBMC_TRACE; + deallocating(); + DelayedCallGuard dg(languageHook); + // we're shutting down so unregister me. + if (languageHook) + { + DelayedCallGuard dc; + languageHook->UnregisterMonitorCallback(this); + } + } + } +} + -- cgit v1.2.3