Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv13236/apps

Modified Files:
        app_alarmreceiver.c app_disa.c app_dumpchan.c app_forkcdr.c 
        app_mp3.c app_nbscat.c app_readfile.c app_sayunixtime.c 
        app_sms.c app_talkdetect.c app_test.c app_voicemail.c 
Log Message:
add a library of timeval manipulation functions, and change a large number of 
usses to use the new functions (bug #4504)


Index: app_alarmreceiver.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_alarmreceiver.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_alarmreceiver.c 11 Jul 2005 20:46:25 -0000      1.13
+++ app_alarmreceiver.c 15 Jul 2005 23:00:46 -0000      1.14
@@ -235,14 +235,12 @@
        int i = 0;
        int r;
        struct ast_frame *f;
-       struct timeval now, lastdigittime;
+       struct timeval lastdigittime;
        
-       gettimeofday(&lastdigittime,NULL);
+       lastdigittime = ast_tvnow();
        for(;;){
-               gettimeofday(&now,NULL);
-               
                  /* if outa time, leave */
-               if (ast_tvdiff_ms(&now, &lastdigittime) > 
+               if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
                    ((i > 0) ? sdto : fdto)){
                        if(option_verbose >= 4)
                                ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: 
DTMF Digit Timeout on %s\n", chan->name);
@@ -287,7 +285,7 @@
                if(i >= length)
                        break;
                
-               gettimeofday(&lastdigittime,NULL);
+               lastdigittime = ast_tvnow();
        }
        
        digit_string[i] = '\0'; /* Nul terminate the end of the digit string */

Index: app_disa.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_disa.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- app_disa.c  7 Jul 2005 22:42:06 -0000       1.29
+++ app_disa.c  15 Jul 2005 23:00:46 -0000      1.30
@@ -90,15 +90,6 @@
 
 LOCAL_USER_DECL;
 
-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);
-}
-
 static void play_dialtone(struct ast_channel *chan, char *mailbox)
 {
        const struct tone_zone_sound *ts = NULL;
@@ -121,7 +112,7 @@
        char tmp[256],arg2[256]="",exten[AST_MAX_EXTENSION],acctcode[20]="";
        char *ourcontext,*ourcallerid,ourcidname[256],ourcidnum[256],*mailbox;
        struct ast_frame *f;
-       struct timeval lastout, now, lastdigittime;
+       struct timeval lastdigittime;
        int res;
        time_t rstart;
        FILE *fp;
@@ -142,7 +133,6 @@
                ast_log(LOG_WARNING, "Unable to set read format to Mu-law on 
%s\n",chan->name);
                return -1;
        }
-       lastout.tv_sec = lastout.tv_usec = 0;
        if (!data || !strlen((char *)data)) {
                ast_log(LOG_WARNING, "disa requires an argument 
(passcode/passcode file)\n");
                return -1;
@@ -187,15 +177,14 @@
                k |= 1; /* We have the password */
                ast_log(LOG_DEBUG, "DISA no-password login success\n");
        }
-       gettimeofday(&lastdigittime,NULL);
+       lastdigittime = ast_tvnow();
 
        play_dialtone(chan, mailbox);
 
        for(;;)
        {
-               gettimeofday(&now,NULL);
                  /* if outa time, give em reorder */
-               if (ms_diff(&now,&lastdigittime) > 
+               if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > 
                    ((k&2) ? digittimeout : firstdigittimeout))
                {
                        ast_log(LOG_DEBUG,"DISA %s entry timeout on chan %s\n",
@@ -238,7 +227,7 @@
                        k|=2; /* We have the first digit */ 
                        ast_playtones_stop(chan);
                }
-               gettimeofday(&lastdigittime,NULL);
+               lastdigittime = ast_tvnow();
                  /* got a DTMF tone */
                if (i < AST_MAX_EXTENSION) /* if still valid number of digits */
                {

Index: app_dumpchan.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_dumpchan.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_dumpchan.c      6 Jun 2005 22:39:31 -0000       1.8
+++ app_dumpchan.c      15 Jul 2005 23:00:46 -0000      1.9
@@ -51,7 +51,7 @@
        char cgrp[256];
        char pgrp[256];
        
-       gettimeofday(&now, NULL);
+       now = ast_tvnow();
        memset(buf,0,size);
        if (!c)
                return 0;

Index: app_forkcdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_forkcdr.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_forkcdr.c       6 Jun 2005 22:39:31 -0000       1.9
+++ app_forkcdr.c       15 Jul 2005 23:00:46 -0000      1.10
@@ -46,7 +46,7 @@
        struct ast_cdr *newcdr = ast_cdr_alloc();
        memcpy(newcdr,cdr,sizeof(struct ast_cdr));
        ast_cdr_append(cdr,newcdr);
-       gettimeofday(&newcdr->start, NULL);
+       newcdr->start = ast_tvnow();
        memset(&newcdr->answer, 0, sizeof(newcdr->answer));
        memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
        ast_cdr_copy_vars(newcdr, cdr);

Index: app_mp3.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_mp3.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- app_mp3.c   6 Jun 2005 22:39:31 -0000       1.25
+++ app_mp3.c   15 Jul 2005 23:00:46 -0000      1.26
@@ -109,7 +109,7 @@
        int pid = -1;
        int owriteformat;
        int timeout = 2000;
-       struct timeval now, next;
+       struct timeval next;
        struct ast_frame *f;
        struct myframe {
                struct ast_frame f;
@@ -134,35 +134,20 @@
                return -1;
        }
        
-       gettimeofday(&now, NULL);
        res = mp3play((char *)data, fds[1]);
        if (!strncasecmp((char *)data, "http://";, 7)) {
                timeout = 10000;
        }
        /* Wait 1000 ms first */
-       next = now;
+       next = ast_tvnow();
        next.tv_sec += 1;
        if (res >= 0) {
                pid = res;
                /* Order is important -- there's almost always going to be 
mp3...  we want to prioritize the
                   user */
                for (;;) {
-                       gettimeofday(&now, NULL);
-                       ms = (next.tv_sec - now.tv_sec) * 1000;
-                       ms += (next.tv_usec - now.tv_usec) / 1000;
-#if 0
-                       printf("ms: %d\n", ms);
-#endif                 
+                       ms = ast_tvdiff_ms(next, ast_tvnow());
                        if (ms <= 0) {
-#if 0
-                               {
-                                       static struct timeval last;
-                                       struct timeval tv;
-                                       gettimeofday(&tv, NULL);
-                                       printf("Since last: %ld\n", (tv.tv_sec 
- last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
-                                       last = tv;
-                               }
-#endif
                                res = timed_read(fds[0], myf.frdata, 
sizeof(myf.frdata), timeout);
                                if (res > 0) {
                                        myf.f.frametype = AST_FRAME_VOICE;
@@ -184,14 +169,7 @@
                                        res = 0;
                                        break;
                                }
-                               next.tv_usec += res / 2 * 125;
-                               if (next.tv_usec >= 1000000) {
-                                       next.tv_usec -= 1000000;
-                                       next.tv_sec++;
-                               }
-#if 0
-                               printf("Next: %d\n", ms);
-#endif                         
+                               next = ast_tvadd(next, 
ast_samp2tv(myf.f.samples, 8000));
                        } else {
                                ms = ast_waitfor(chan, ms);
                                if (ms < 0) {

Index: app_nbscat.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_nbscat.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_nbscat.c        6 Jun 2005 22:39:31 -0000       1.10
+++ app_nbscat.c        15 Jul 2005 23:00:46 -0000      1.11
@@ -99,7 +99,7 @@
        int ms = -1;
        int pid = -1;
        int owriteformat;
-       struct timeval now, next;
+       struct timeval next;
        struct ast_frame *f;
        struct myframe {
                struct ast_frame f;
@@ -122,29 +122,15 @@
        
        res = NBScatplay(fds[1]);
        /* Wait 1000 ms first */
-       next = now;
+       next = ast_tvnow();
        next.tv_sec += 1;
        if (res >= 0) {
                pid = res;
                /* Order is important -- there's almost always going to be 
mp3...  we want to prioritize the
                   user */
                for (;;) {
-                       gettimeofday(&now, NULL);
-                       ms = (next.tv_sec - now.tv_sec) * 1000;
-                       ms += (next.tv_usec - now.tv_usec) / 1000;
-#if 0
-                       printf("ms: %d\n", ms);
-#endif                 
+                       ms = ast_tvdiff_ms(next, ast_tvnow());
                        if (ms <= 0) {
-#if 0
-                               {
-                                       static struct timeval last;
-                                       struct timeval tv;
-                                       gettimeofday(&tv, NULL);
-                                       printf("Since last: %ld\n", (tv.tv_sec 
- last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
-                                       last = tv;
-                               }
-#endif
                                res = timed_read(fds[0], myf.frdata, 
sizeof(myf.frdata));
                                if (res > 0) {
                                        myf.f.frametype = AST_FRAME_VOICE;
@@ -166,14 +152,7 @@
                                        res = 0;
                                        break;
                                }
-                               next.tv_usec += res / 2 * 125;
-                               if (next.tv_usec >= 1000000) {
-                                       next.tv_usec -= 1000000;
-                                       next.tv_sec++;
-                               }
-#if 0
-                               printf("Next: %d\n", ms);
-#endif                         
+                               next = ast_tvadd(next, 
ast_samp2tv(myf.f.samples, 8000));
                        } else {
                                ms = ast_waitfor(chan, ms);
                                if (ms < 0) {

Index: app_readfile.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_readfile.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- app_readfile.c      8 Jul 2005 17:06:53 -0000       1.6
+++ app_readfile.c      15 Jul 2005 23:00:46 -0000      1.7
@@ -83,7 +83,7 @@
                if(len < strlen(returnvar))
                        returnvar[len]='\0';
                else
-                       ast_log(LOG_WARNING,"%s is longer than %d, and %zd \n", 
file, len, strlen(returnvar));
+                       ast_log(LOG_WARNING,"%s is longer than %d, and %d \n", 
file, len, (int)strlen(returnvar));
        }
        pbx_builtin_setvar_helper(chan, varname, returnvar);
        free(returnvar);

Index: app_sayunixtime.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_sayunixtime.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_sayunixtime.c   6 Jun 2005 22:39:31 -0000       1.10
+++ app_sayunixtime.c   15 Jul 2005 23:00:46 -0000      1.11
@@ -69,7 +69,7 @@
        
        LOCAL_USER_ADD(u);
 
-       gettimeofday(&tv,NULL);
+       tv = ast_tvnow();
        unixtime = (time_t)tv.tv_sec;
 
        if( !strcasecmp(chan->language, "da" ) ) {

Index: app_sms.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_sms.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- app_sms.c   10 Jul 2005 23:12:25 -0000      1.24
+++ app_sms.c   15 Jul 2005 23:00:46 -0000      1.25
@@ -1176,7 +1176,7 @@
        int i;
 
        if (len > sizeof (buf)) {
-               ast_log (LOG_WARNING, "Only doing %zd bytes (%d bytes 
requested)\n", sizeof (buf) / sizeof (signed short), len);
+               ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes 
requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len);
                len = sizeof (buf);
 #ifdef OUTALAW
                samples = len;

Index: app_talkdetect.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_talkdetect.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_talkdetect.c    10 Jul 2005 23:12:25 -0000      1.10
+++ app_talkdetect.c    15 Jul 2005 23:00:46 -0000      1.11
@@ -59,7 +59,7 @@
        char *stringp;
        struct ast_frame *fr;
        int notsilent=0;
-       struct timeval start = { 0, 0}, end = {0, 0};
+       struct timeval start = { 0, 0};
        int sil = 1000;
        int min = 100;
        int max = -1;
@@ -143,9 +143,7 @@
                                                        /* We've been quiet a 
little while */
                                                        if (notsilent) {
                                                                /* We had heard 
some talking */
-                                                               
gettimeofday(&end, NULL);
-                                                               ms = 
(end.tv_sec - start.tv_sec) * 1000;
-                                                               ms += 
(end.tv_usec - start.tv_usec) / 1000;
+                                                               ms = 
ast_tvdiff_ms(ast_tvnow(), start);
                                                                ms -= sil;
                                                                if (ms < 0)
                                                                        ms = 0;
@@ -171,7 +169,7 @@
                                                } else {
                                                        if (!notsilent) {
                                                                /* Heard some 
audio, mark the begining of the token */
-                                                               
gettimeofday(&start, NULL);
+                                                               start = 
ast_tvnow();
                                                                
ast_log(LOG_DEBUG, "Start of voice token!\n");
                                                                notsilent = 1;
                                                        }

Index: app_test.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_test.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_test.c  6 Jun 2005 22:39:32 -0000       1.10
+++ app_test.c  15 Jul 2005 23:00:46 -0000      1.11
@@ -55,7 +55,7 @@
        int samples=0;
        int x;
        short *foo;
-       struct timeval start, tv;
+       struct timeval start;
        struct ast_frame *f;
        int rformat;
        rformat = chan->readformat;
@@ -63,11 +63,9 @@
                ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
                return -1;
        }
-       gettimeofday(&start, NULL);
+       start = ast_tvnow();
        for(;;) {
-               gettimeofday(&tv, NULL);
-               mssofar = (tv.tv_sec - start.tv_sec) * 1000;
-               mssofar += (tv.tv_usec - start.tv_usec) / 1000;
+               mssofar = ast_tvdiff_ms(ast_tvnow(), start);
                if (mssofar > ms)
                        break;
                res = ast_waitfor(chan, ms - mssofar);

Index: app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.231
retrieving revision 1.232
diff -u -d -r1.231 -r1.232
--- app_voicemail.c     15 Jul 2005 00:27:41 -0000      1.231
+++ app_voicemail.c     15 Jul 2005 23:00:46 -0000      1.232
@@ -3295,7 +3295,7 @@
 #if 0
        /* Set the DIFF_* variables */
        localtime_r(&t, &time_now);
-       gettimeofday(&tv_now,NULL);
+       tv_now = ast_tvnow();
        tnow = tv_now.tv_sec;
        localtime_r(&tnow,&time_then);
 

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to