1 /* 2 chronyd/chronyc - Programs for keeping computer clocks accurate. 3 4 ********************************************************************** 5 * Copyright (C) Richard P. Curnow 1997-2002 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of version 2 of the GNU General Public License as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 ********************************************************************** 21 22 ======================================================================= 23 24 Exported header file for sched.c 25 */ 26 27 #ifndef GOT_SCHED_H 28 #define GOT_SCHED_H 29 30 #include "sysincl.h" 31 32 /* Type for timeout IDs, valid IDs are always greater than zero */ 33 typedef unsigned int SCH_TimeoutID; 34 35 typedef enum { 36 SCH_ReservedTimeoutValue = 0, 37 SCH_NtpClientClass, 38 SCH_NtpPeerClass, 39 SCH_NtpBroadcastClass, 40 SCH_NumberOfClasses /* needs to be last */ 41 } SCH_TimeoutClass; 42 43 typedef void* SCH_ArbitraryArgument; 44 typedef void (*SCH_FileHandler)(int fd, int event, SCH_ArbitraryArgument); 45 typedef void (*SCH_TimeoutHandler)(SCH_ArbitraryArgument); 46 47 /* Exported functions */ 48 49 /* Initialisation function for the module */ 50 extern void SCH_Initialise(void); 51 52 /* Finalisation function for the module */ 53 extern void SCH_Finalise(void); 54 55 /* File events */ 56 #define SCH_FILE_INPUT 1 57 #define SCH_FILE_OUTPUT 2 58 #define SCH_FILE_EXCEPTION 4 59 60 /* Register a handler for when select goes true on a file descriptor */ 61 extern void SCH_AddFileHandler(int fd, int events, SCH_FileHandler handler, SCH_ArbitraryArgument arg); 62 extern void SCH_RemoveFileHandler(int fd); 63 extern void SCH_SetFileHandlerEvent(int fd, int event, int enable); 64 65 /* Get the time stamp taken after a file descriptor became ready or a timeout expired */ 66 extern void SCH_GetLastEventTime(struct timespec *cooked, double *err, struct timespec *raw); 67 68 /* Get a low-precision monotonic timestamp (starting at 0.0) */ 69 extern double SCH_GetLastEventMonoTime(void); 70 71 /* This queues a timeout to elapse at a given (raw) local time */ 72 extern SCH_TimeoutID SCH_AddTimeout(struct timespec *ts, SCH_TimeoutHandler handler, SCH_ArbitraryArgument arg); 73 74 /* This queues a timeout to elapse at a given delta time relative to the current (raw) time */ 75 extern SCH_TimeoutID SCH_AddTimeoutByDelay(double delay, SCH_TimeoutHandler, SCH_ArbitraryArgument); 76 77 /* This queues a timeout in a particular class, ensuring that the 78 expiry time is at least a given separation away from any other 79 timeout in the same class, given randomness is added to the delay 80 and separation */ 81 extern SCH_TimeoutID SCH_AddTimeoutInClass(double min_delay, double separation, double randomness, 82 SCH_TimeoutClass class, 83 SCH_TimeoutHandler handler, SCH_ArbitraryArgument); 84 85 /* The next one probably ought to return a status code */ 86 extern void SCH_RemoveTimeout(SCH_TimeoutID); 87 88 extern void SCH_MainLoop(void); 89 90 extern void SCH_QuitProgram(void); 91 92 #endif /* GOT_SCHED_H */ 93