Blame reference.h

Packit 96c956
/*
Packit 96c956
  chronyd/chronyc - Programs for keeping computer clocks accurate.
Packit 96c956
Packit 96c956
 **********************************************************************
Packit 96c956
 * Copyright (C) Richard P. Curnow  1997-2002
Packit 96c956
 * Copyright (C) Miroslav Lichvar  2014
Packit 96c956
 * 
Packit 96c956
 * This program is free software; you can redistribute it and/or modify
Packit 96c956
 * it under the terms of version 2 of the GNU General Public License as
Packit 96c956
 * published by the Free Software Foundation.
Packit 96c956
 * 
Packit 96c956
 * This program is distributed in the hope that it will be useful, but
Packit 96c956
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 96c956
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 96c956
 * General Public License for more details.
Packit 96c956
 * 
Packit 96c956
 * You should have received a copy of the GNU General Public License along
Packit 96c956
 * with this program; if not, write to the Free Software Foundation, Inc.,
Packit 96c956
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Packit 96c956
 * 
Packit 96c956
 **********************************************************************
Packit 96c956
Packit 96c956
  =======================================================================
Packit 96c956
Packit 96c956
  This is the header file for the module that keeps track of the current
Packit 96c956
  reference.
Packit 96c956
Packit 96c956
  */
Packit 96c956
Packit 96c956
#ifndef GOT_REFERENCE_H
Packit 96c956
#define GOT_REFERENCE_H
Packit 96c956
Packit 96c956
#include "sysincl.h"
Packit 96c956
Packit 96c956
#include "ntp.h"
Packit 96c956
#include "reports.h"
Packit 96c956
Packit 96c956
/* Leap second handling modes */
Packit 96c956
typedef enum {
Packit 96c956
  REF_LeapModeSystem,
Packit 96c956
  REF_LeapModeSlew,
Packit 96c956
  REF_LeapModeStep,
Packit 96c956
  REF_LeapModeIgnore,
Packit 96c956
} REF_LeapMode;
Packit 96c956
Packit 96c956
/* Init function */
Packit 96c956
extern void REF_Initialise(void);
Packit 96c956
Packit 96c956
/* Fini function */
Packit 96c956
extern void REF_Finalise(void);
Packit 96c956
Packit 96c956
typedef enum {
Packit 96c956
  REF_ModeNormal,
Packit 96c956
  REF_ModeInitStepSlew,
Packit 96c956
  REF_ModeUpdateOnce,
Packit 96c956
  REF_ModePrintOnce,
Packit 96c956
  REF_ModeIgnore,
Packit 96c956
} REF_Mode;
Packit 96c956
Packit 96c956
/* Set reference update mode */
Packit 96c956
extern void REF_SetMode(REF_Mode mode);
Packit 96c956
Packit 96c956
/* Get reference update mode */
Packit 96c956
extern REF_Mode REF_GetMode(void);
Packit 96c956
Packit 96c956
/* Function type for handlers to be called back when mode ends */
Packit 96c956
typedef void (*REF_ModeEndHandler)(int result);
Packit 96c956
Packit 96c956
/* Set the handler for being notified of mode ending */
Packit 96c956
extern void REF_SetModeEndHandler(REF_ModeEndHandler handler);
Packit 96c956
Packit 96c956
/* Get leap second handling mode */
Packit 96c956
extern REF_LeapMode REF_GetLeapMode(void);
Packit 96c956
Packit 96c956
/* Function which takes a local cooked time and returns the estimated
Packit 96c956
   time of the reference.  It also returns the other parameters
Packit 96c956
   required for forming the outgoing NTP packet.
Packit 96c956
Packit 96c956
   local_time is the cooked local time returned by the LCL module
Packit 96c956
Packit 96c956
   is_synchronised indicates whether we are synchronised to anything
Packit 96c956
   at the moment.
Packit 96c956
Packit 96c956
   leap indicates the current leap status
Packit 96c956
Packit 96c956
   stratum is the stratum of this machine, when considered to be sync'd to the
Packit 96c956
   reference
Packit 96c956
   
Packit 96c956
   ref_id is the reference_id of the source
Packit 96c956
Packit 96c956
   ref_time is the time at which the we last set the reference source up
Packit 96c956
Packit 96c956
   root_delay is the root delay of the sample we are using
Packit 96c956
Packit 96c956
   root_dispersion is the root dispersion of the sample we are using, with all the
Packit 96c956
   skew etc added on.
Packit 96c956
Packit 96c956
   */
Packit 96c956
Packit 96c956
extern void REF_GetReferenceParams
Packit 96c956
(
Packit 96c956
 struct timespec *local_time,
Packit 96c956
 int *is_synchronised,
Packit 96c956
 NTP_Leap *leap,
Packit 96c956
 int *stratum,
Packit 96c956
 uint32_t *ref_id,
Packit 96c956
 struct timespec *ref_time,
Packit 96c956
 double *root_delay,
Packit 96c956
 double *root_dispersion
Packit 96c956
);
Packit 96c956
Packit 96c956
/* Function called by the clock selection process to register a new
Packit 96c956
   reference source and its parameters
Packit 96c956
Packit 96c956
   stratum is the stratum of the reference
Packit 96c956
Packit 96c956
   leap is the leap status read from the source
Packit 96c956
Packit 96c956
   ref_id is the reference id of the reference
Packit 96c956
Packit 96c956
   ref_time is the time at which the parameters are assumed to be
Packit 96c956
   correct, in terms of local time
Packit 96c956
Packit 96c956
   frequency is the amount of local clock gain relative to the
Packit 96c956
   reference per unit time interval of the local clock
Packit 96c956
Packit 96c956
   skew is the maximum estimated frequency error (so we are within
Packit 96c956
   [frequency+-skew])
Packit 96c956
Packit 96c956
   root_delay is the root delay of the sample we are using
Packit 96c956
Packit 96c956
   root_dispersion is the root dispersion of the sample we are using
Packit 96c956
Packit 96c956
   */
Packit 96c956
Packit 96c956
extern void REF_SetReference
Packit 96c956
(
Packit 96c956
 int stratum,
Packit 96c956
 NTP_Leap leap,
Packit 96c956
 int combined_sources,
Packit 96c956
 uint32_t ref_id,
Packit 96c956
 IPAddr *ref_ip,
Packit 96c956
 struct timespec *ref_time,
Packit 96c956
 double offset,
Packit 96c956
 double offset_sd,
Packit 96c956
 double frequency,
Packit 96c956
 double frequency_sd,
Packit 96c956
 double skew,
Packit 96c956
 double root_delay,
Packit 96c956
 double root_dispersion
Packit 96c956
);
Packit 96c956
Packit 96c956
extern void REF_SetManualReference
Packit 96c956
(
Packit 96c956
 struct timespec *ref_time,
Packit 96c956
 double offset,
Packit 96c956
 double frequency,
Packit 96c956
 double skew
Packit 96c956
);
Packit 96c956
Packit 96c956
/* Mark the local clock as unsynchronised */
Packit 96c956
extern void
Packit 96c956
REF_SetUnsynchronised(void);
Packit 96c956
Packit 96c956
/* Return the current stratum of this host or 16 if the host is not
Packit 96c956
   synchronised */
Packit 96c956
extern int REF_GetOurStratum(void);
Packit 96c956
Packit 96c956
/* Return stratum of the local reference if orphan mode is enabled */
Packit 96c956
extern int REF_GetOrphanStratum(void);
Packit 96c956
Packit 96c956
/* Return the current skew */
Packit 96c956
extern double REF_GetSkew(void);
Packit 96c956
Packit 96c956
/* Modify the setting for the maximum skew we are prepared to allow updates on (in ppm). */
Packit 96c956
extern void REF_ModifyMaxupdateskew(double new_max_update_skew);
Packit 96c956
Packit 96c956
/* Modify makestep settings */
Packit 96c956
extern void REF_ModifyMakestep(int limit, double threshold);
Packit 96c956
Packit 96c956
extern void REF_EnableLocal(int stratum, double distance, int orphan);
Packit 96c956
extern void REF_DisableLocal(void);
Packit 96c956
Packit 96c956
/* Check if current raw or cooked time is close to a leap second
Packit 96c956
   and is better to discard any measurements */
Packit 96c956
extern int REF_IsLeapSecondClose(void);
Packit 96c956
Packit 96c956
/* Return TAI-UTC offset corresponding to a time in UTC if available */
Packit 96c956
extern int REF_GetTaiOffset(struct timespec *ts);
Packit 96c956
Packit 96c956
extern void REF_GetTrackingReport(RPT_TrackingReport *rep);
Packit 96c956
Packit 96c956
#endif /* GOT_REFERENCE_H */