Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / AlarmClock.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "StdString.h"
24 #include "Stopwatch.h"
25 #include "threads/CriticalSection.h"
26 #include "threads/Thread.h"
27
28 #include <map>
29
30 struct SAlarmClockEvent
31 {
32   CStopWatch watch;
33   double m_fSecs;
34   CStdString m_strCommand;
35   bool m_loop;
36 };
37
38 class CAlarmClock : public CThread
39 {
40 public:
41   CAlarmClock();
42   ~CAlarmClock();
43   void Start(const CStdString& strName, float n_secs, const CStdString& strCommand, bool bSilent = false, bool bLoop = false);
44   inline bool IsRunning() const
45   {
46     return m_bIsRunning;
47   }
48
49   inline bool HasAlarm(const CStdString& strName)
50   {
51     // note: strName should be lower case only here
52     //       No point checking it at the moment due to it only being called
53     //       from GUIInfoManager (which is always lowercase)
54     //    CLog::Log(LOGDEBUG,"checking for %s",strName.c_str());
55     return (m_event.find(strName) != m_event.end());
56   }
57
58   double GetRemaining(const CStdString& strName)
59   {
60     std::map<CStdString,SAlarmClockEvent>::iterator iter;
61     if ((iter=m_event.find(strName)) != m_event.end())
62     {
63       return iter->second.m_fSecs-iter->second.watch.GetElapsedSeconds();
64     }
65
66     return 0.f;
67   }
68
69   void Stop(const CStdString& strName, bool bSilent = false);
70   virtual void Process();
71 private:
72   std::map<CStdString,SAlarmClockEvent> m_event;
73   CCriticalSection m_events;
74
75   bool m_bIsRunning;
76 };
77
78 extern CAlarmClock g_alarmClock;
79