Remove LiveTV menu.
[vuplus_xbmc] / xbmc / threads / SystemClock.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #pragma once
22
23 #include <limits>
24
25 namespace XbmcThreads
26 {
27   /**
28    * This function returns the system clock's number of milliseconds but with
29    *  an arbitrary reference point. It handles the wrapping of any underlying
30    *  system clock by setting a starting point at the first call. It should
31    *  only be used for measuring time durations.
32    *
33    * Of course, on windows it just calls timeGetTime, so you're on your own.
34    */
35   unsigned int SystemClockMillis();
36
37   /**
38    * DO NOT compare the results from SystemClockMillis() to an expected end time
39    *  that was calculated by adding a number of milliseconds to some start time.
40    *  The reason is because the SystemClockMillis could wrap. Instead use this
41    *  class which uses differences (which are safe accross a wrap).
42    */
43   class EndTime
44   {
45     unsigned int startTime;
46     unsigned int totalWaitTime;
47   public:
48     static const unsigned int InfiniteValue;
49     inline EndTime() : startTime(0), totalWaitTime(0) {}
50     inline EndTime(unsigned int millisecondsIntoTheFuture) : startTime(SystemClockMillis()), totalWaitTime(millisecondsIntoTheFuture) {}
51
52     inline void Set(unsigned int millisecondsIntoTheFuture) { startTime = SystemClockMillis(); totalWaitTime = millisecondsIntoTheFuture; }
53
54     inline bool IsTimePast() const { return totalWaitTime == InfiniteValue ? false : (totalWaitTime == 0 ? true : (SystemClockMillis() - startTime) >= totalWaitTime); }
55
56     inline unsigned int MillisLeft() const
57     {
58       if (totalWaitTime == InfiniteValue)
59         return InfiniteValue;
60       if (totalWaitTime == 0)
61         return 0;
62       unsigned int timeWaitedAlready = (SystemClockMillis() - startTime);
63       return (timeWaitedAlready >= totalWaitTime) ? 0 : (totalWaitTime - timeWaitedAlready);
64     }
65
66     inline void SetExpired() { totalWaitTime = 0; }
67     inline void SetInfinite() { totalWaitTime = InfiniteValue; }
68     inline bool IsInfinite(void) const { return (totalWaitTime == InfiniteValue); }
69     inline unsigned int GetInitialTimeoutValue(void) const { return totalWaitTime; }
70     inline unsigned int GetStartTime(void) const { return startTime; }
71   };
72 }