2 * Copyright (C) 2012-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.
20 virtual ~ITimerCallback() = default;
22 virtual void OnTimeout() = 0;
25 class CTimer
: protected CThread
28 explicit CTimer(ITimerCallback
*callback
);
29 explicit CTimer(std::function
<void()> const& callback
);
32 bool Start(std::chrono::milliseconds timeout
, bool interval
= false);
33 bool Stop(bool wait
= false);
35 void RestartAsync(std::chrono::milliseconds timeout
);
37 bool IsRunning() const { return CThread::IsRunning(); }
39 float GetElapsedSeconds() const;
40 float GetElapsedMilliseconds() const;
43 void Process() override
;
46 std::function
<void()> m_callback
;
47 std::chrono::milliseconds m_timeout
;
49 std::chrono::time_point
<std::chrono::steady_clock
> m_endTime
;
50 CEvent m_eventTimeout
;