diff options
-rwxr-xr-x | apps/app_alarmreceiver.c | 16 | ||||
-rwxr-xr-x | include/asterisk/utils.h | 13 |
2 files changed, 14 insertions, 15 deletions
diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index 324d656ce..bdf264ea5 100755 --- a/apps/app_alarmreceiver.c +++ b/apps/app_alarmreceiver.c @@ -219,20 +219,6 @@ static int send_tone_burst(struct ast_channel *chan, float freq, int duration, i } /* -* Return the difference in milliseconds between two timeval structs -*/ - -static int ms_diff(struct timeval *tv1, struct timeval *tv2){ - - int ms; - - ms = (tv1->tv_sec - tv2->tv_sec) * 1000; - ms += (tv1->tv_usec - tv2->tv_usec) / 1000; - - return(ms); -} - -/* * Receive a string of DTMF digits where the length of the digit string is known in advance. Do not give preferential * treatment to any digit value, and allow separate time out values to be specified for the first digit and all subsequent * digits. @@ -256,7 +242,7 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int gettimeofday(&now,NULL); /* if outa time, leave */ - if (ms_diff(&now,&lastdigittime) > + if (ast_tvdiff_ms(&lastdigittime, &now) > ((i > 0) ? sdto : fdto)){ if(option_verbose >= 4) ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name); diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index 5b2001a6d..9fb0b83cd 100755 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -247,4 +247,17 @@ void ast_copy_string(char *dst, const char *src, size_t size); */ int ast_build_string(char **buffer, size_t *space, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); +/* functions for working with 'struct timeval' instances */ + +/*! + * \brief Computes the difference (in milliseconds) between two \c struct \c timeval instances. + * \param start the beginning of the time period + * \param end the end of the time period + * \return the difference in milliseconds + */ +static inline int ast_tvdiff_ms(struct timeval *start, struct timeval *end) +{ + return ((end->tv_sec - start->tv_sec) * 1000) + ((end->tv_usec - start->tv_usec) / 1000); +} + #endif /* _ASTERISK_UTILS_H */ |