diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/AlarmClock.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/utils/AlarmClock.h')
| -rw-r--r-- | xbmc/utils/AlarmClock.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/xbmc/utils/AlarmClock.h b/xbmc/utils/AlarmClock.h new file mode 100644 index 0000000..e613595 --- /dev/null +++ b/xbmc/utils/AlarmClock.h | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include "Stopwatch.h" | ||
| 12 | #include "threads/CriticalSection.h" | ||
| 13 | #include "threads/Thread.h" | ||
| 14 | |||
| 15 | #include <map> | ||
| 16 | #include <string> | ||
| 17 | |||
| 18 | struct SAlarmClockEvent | ||
| 19 | { | ||
| 20 | CStopWatch watch; | ||
| 21 | double m_fSecs; | ||
| 22 | std::string m_strCommand; | ||
| 23 | bool m_loop; | ||
| 24 | }; | ||
| 25 | |||
| 26 | class CAlarmClock : public CThread | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | CAlarmClock(); | ||
| 30 | ~CAlarmClock() override; | ||
| 31 | void Start(const std::string& strName, float n_secs, const std::string& strCommand, bool bSilent = false, bool bLoop = false); | ||
| 32 | inline bool IsRunning() const | ||
| 33 | { | ||
| 34 | return m_bIsRunning; | ||
| 35 | } | ||
| 36 | |||
| 37 | inline bool HasAlarm(const std::string& strName) | ||
| 38 | { | ||
| 39 | // note: strName should be lower case only here | ||
| 40 | // No point checking it at the moment due to it only being called | ||
| 41 | // from GUIInfoManager (which is always lowercase) | ||
| 42 | // CLog::Log(LOGDEBUG,"checking for %s",strName.c_str()); | ||
| 43 | return (m_event.find(strName) != m_event.end()); | ||
| 44 | } | ||
| 45 | |||
| 46 | double GetRemaining(const std::string& strName) | ||
| 47 | { | ||
| 48 | std::map<std::string,SAlarmClockEvent>::iterator iter; | ||
| 49 | if ((iter=m_event.find(strName)) != m_event.end()) | ||
| 50 | { | ||
| 51 | return iter->second.m_fSecs-(iter->second.watch.IsRunning() ? iter->second.watch.GetElapsedSeconds() : 0.f); | ||
| 52 | } | ||
| 53 | |||
| 54 | return 0.f; | ||
| 55 | } | ||
| 56 | |||
| 57 | void Stop(const std::string& strName, bool bSilent = false); | ||
| 58 | void Process() override; | ||
| 59 | private: | ||
| 60 | std::map<std::string,SAlarmClockEvent> m_event; | ||
| 61 | CCriticalSection m_events; | ||
| 62 | |||
| 63 | bool m_bIsRunning = false; | ||
| 64 | }; | ||
| 65 | |||
| 66 | extern CAlarmClock g_alarmClock; | ||
| 67 | |||
