From 44c9744d69b2e116d7881ad5413f27fe1812ed89 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 30 May 2014 13:02:45 +0200 Subject: [PATCH] local: replace is_step_change parameter of change handler with enum Prepare for a new change type that will be added later. --- local.c | 14 +++++++------- local.h | 11 ++++++++--- manual.c | 4 ++-- ntp_sources.c | 4 ++-- refclock.c | 4 ++-- reference.c | 4 ++-- rtc_linux.c | 3 ++- sched.c | 6 +++--- sources.c | 4 ++-- sys_generic.c | 4 ++-- 10 files changed, 32 insertions(+), 26 deletions(-) diff --git a/local.c b/local.c index f43de38..3619b58 100644 --- a/local.c +++ b/local.c @@ -251,12 +251,12 @@ void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void * static void invoke_parameter_change_handlers(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change) + LCL_ChangeType change_type) { ChangeListEntry *ptr; for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) { - (ptr->handler)(raw, cooked, dfreq, doffset, is_step_change, ptr->anything); + (ptr->handler)(raw, cooked, dfreq, doffset, change_type, ptr->anything); } } @@ -401,7 +401,7 @@ LCL_SetAbsoluteFrequency(double afreq_ppm) LCL_CookTime(&raw, &cooked, NULL); /* Dispatch to all handlers */ - invoke_parameter_change_handlers(&raw, &cooked, dfreq, 0.0, 0); + invoke_parameter_change_handlers(&raw, &cooked, dfreq, 0.0, LCL_ChangeAdjust); current_freq_ppm = afreq_ppm; @@ -431,7 +431,7 @@ LCL_AccumulateDeltaFrequency(double dfreq) LCL_CookTime(&raw, &cooked, NULL); /* Dispatch to all handlers */ - invoke_parameter_change_handlers(&raw, &cooked, dfreq, 0.0, 0); + invoke_parameter_change_handlers(&raw, &cooked, dfreq, 0.0, LCL_ChangeAdjust); } /* ================================================== */ @@ -450,7 +450,7 @@ LCL_AccumulateOffset(double offset, double corr_rate) (*drv_accrue_offset)(offset, corr_rate); /* Dispatch to all handlers */ - invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, 0); + invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, LCL_ChangeAdjust); } /* ================================================== */ @@ -469,7 +469,7 @@ LCL_ApplyStepOffset(double offset) (*drv_apply_step_offset)(offset); /* Dispatch to all handlers */ - invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, 1); + invoke_parameter_change_handlers(&raw, &cooked, 0.0, offset, LCL_ChangeStep); } /* ================================================== */ @@ -479,7 +479,7 @@ LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked, double offset, double dispersion) { /* Dispatch to all handlers */ - invoke_parameter_change_handlers(raw, cooked, 0.0, offset, 1); + invoke_parameter_change_handlers(raw, cooked, 0.0, offset, LCL_ChangeStep); lcl_InvokeDispersionNotifyHandlers(dispersion); } diff --git a/local.h b/local.h index eea7072..bdf38bd 100644 --- a/local.h +++ b/local.h @@ -67,16 +67,21 @@ extern void LCL_GetOffsetCorrection(struct timeval *raw, double *correction, dou doffset : delta offset applied (positive => make local system fast by that amount, negative => make it slow by that amount) - is_step_change : true if change is being applied as a jump (using - settimeofday rather than adjtime) + change_type : what type of change is being applied anything : Passthrough argument from call to registration routine */ +typedef enum { + LCL_ChangeAdjust, + LCL_ChangeStep +} LCL_ChangeType; + typedef void (*LCL_ParameterChangeHandler) (struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, + double doffset, + LCL_ChangeType change_type, void *anything ); diff --git a/manual.c b/manual.c index 9886ce5..011d07a 100644 --- a/manual.c +++ b/manual.c @@ -66,7 +66,7 @@ slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *not_used); /* ================================================== */ @@ -216,7 +216,7 @@ slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *not_used) { double delta_time; diff --git a/ntp_sources.c b/ntp_sources.c index ddba8a3..3fa5b29 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -94,7 +94,7 @@ slew_sources(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything); /* ================================================== */ @@ -479,7 +479,7 @@ slew_sources(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything) { int i; diff --git a/refclock.c b/refclock.c index 67f0588..83b9488 100644 --- a/refclock.c +++ b/refclock.c @@ -97,7 +97,7 @@ static int valid_sample_time(RCL_Instance instance, struct timeval *tv); static int pps_stratum(RCL_Instance instance, struct timeval *tv); static void poll_timeout(void *arg); static void slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, void *anything); + double doffset, LCL_ChangeType change_type, void *anything); static void add_dispersion(double dispersion, void *anything); static void log_sample(RCL_Instance instance, struct timeval *sample_time, int filtered, int pulse, double raw_offset, double cooked_offset, double dispersion); @@ -577,7 +577,7 @@ poll_timeout(void *arg) static void slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, void *anything) + double doffset, LCL_ChangeType change_type, void *anything) { int i; diff --git a/reference.c b/reference.c index b1a6386..6038ce3 100644 --- a/reference.c +++ b/reference.c @@ -144,10 +144,10 @@ handle_slew(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything) { - if (is_step_change) { + if (change_type == LCL_ChangeStep) { UTI_AddDoubleToTimeval(&last_ref_update, -doffset, &last_ref_update); } } diff --git a/rtc_linux.c b/rtc_linux.c index 198e3b7..602345c 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -265,7 +265,8 @@ static void slew_samples (struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, + double doffset, + LCL_ChangeType change_type, void *anything) { int i; diff --git a/sched.c b/sched.c index 8c547a1..2204f96 100644 --- a/sched.c +++ b/sched.c @@ -123,7 +123,7 @@ handle_slew(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything); /* ================================================== */ @@ -503,14 +503,14 @@ handle_slew(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything) { TimerQueueEntry *ptr; double delta; int i; - if (is_step_change) { + if (change_type != LCL_ChangeAdjust) { /* If a step change occurs, just shift all raw time stamps by the offset */ for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) { diff --git a/sources.c b/sources.c index 8eae88b..d0600cc 100644 --- a/sources.c +++ b/sources.c @@ -154,7 +154,7 @@ static double combine_limit; static void slew_sources(struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, void *anything); + double doffset, LCL_ChangeType change_type, void *anything); static void add_dispersion(double dispersion, void *anything); static char * @@ -1087,7 +1087,7 @@ slew_sources(struct timeval *raw, struct timeval *cooked, double dfreq, double doffset, - int is_step_change, + LCL_ChangeType change_type, void *anything) { int i; diff --git a/sys_generic.c b/sys_generic.c index 33b792f..51c6824 100644 --- a/sys_generic.c +++ b/sys_generic.c @@ -93,9 +93,9 @@ static void handle_end_of_slew(void *anything); static void handle_step(struct timeval *raw, struct timeval *cooked, double dfreq, - double doffset, int is_step_change, void *anything) + double doffset, LCL_ChangeType change_type, void *anything) { - if (is_step_change) + if (change_type == LCL_ChangeStep) UTI_AddDoubleToTimeval(&slew_start, -doffset, &slew_start); }