Merge pull request #26166 from ksooo/improve-plugin-ctx-menus
[xbmc.git] / xbmc / utils / AlarmClock.h
blob392ba0265b1969e514302af178b57d659dbccf8e
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "Stopwatch.h"
12 #include "threads/CriticalSection.h"
13 #include "threads/Thread.h"
15 #include <map>
16 #include <string>
18 struct SAlarmClockEvent
20 CStopWatch watch;
21 double m_fSecs;
22 std::string m_strCommand;
23 bool m_loop;
26 class CAlarmClock : public CThread
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
34 return m_bIsRunning;
37 inline bool HasAlarm(const std::string& strName)
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 {}",strName);
43 return (m_event.find(strName) != m_event.end());
46 double GetRemaining(const std::string& strName)
48 std::map<std::string,SAlarmClockEvent>::iterator iter;
49 if ((iter=m_event.find(strName)) != m_event.end())
51 return iter->second.m_fSecs - static_cast<double>(iter->second.watch.IsRunning()
52 ? iter->second.watch.GetElapsedSeconds()
53 : 0.f);
56 return 0.0;
59 void Stop(const std::string& strName, bool bSilent = false);
60 void Process() override;
61 private:
62 std::map<std::string,SAlarmClockEvent> m_event;
63 CCriticalSection m_events;
65 bool m_bIsRunning = false;
68 extern CAlarmClock g_alarmClock;