1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2002-2009 Free Software Foundation Europe e.V. 5 Copyright (C) 2016-2019 Bareos GmbH & Co. KG 6 7 This program is Free Software; you can redistribute it and/or 8 modify it under the terms of version three of the GNU Affero General Public 9 License as published by the Free Software Foundation and included 10 in the file LICENSE. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Affero General Public License for more details. 16 17 You should have received a copy of the GNU Affero General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 02110-1301, USA. 21 */ 22 23 #ifndef BAREOS_LIB_TIMER_THREAD_H_ 24 #define BAREOS_LIB_TIMER_THREAD_H_ 25 26 #include "lib/dlist.h" 27 28 #include <chrono> 29 30 namespace TimerThread { 31 32 struct Timer { 33 bool single_shot = true; 34 bool is_active = false; 35 std::chrono::milliseconds interval; 36 void (*user_callback)(Timer* t) = nullptr; 37 void (*user_destructor)(Timer* t) = nullptr; 38 void* user_data = nullptr; 39 40 std::chrono::steady_clock::time_point scheduled_run_timepoint; 41 }; 42 43 bool Start(void); 44 void Stop(void); 45 46 Timer* NewTimer(void); 47 48 bool RegisterTimer(Timer* t); 49 bool UnregisterTimer(Timer* t); 50 bool IsRegisteredTimer(const Timer* t); 51 52 bool CurrentThreadIsTimerThread(); 53 void SetTimerIdleSleepTime(std::chrono::seconds time); 54 55 std::time_t GetCalenderTimeOnLastTimerThreadRun(); 56 57 } // namespace TimerThread 58 59 #endif /* BAREOS_LIB_TIMER_THREAD_H_ */ 60