3
3
*
4
4
* QuickNet Internet Phone Jack Channel
5
5
*
6
- * Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
6
+ * Copyright (C) 1999, Mark Spencer
7
7
*
8
8
* Mark Spencer <markster@linux-support.net>
9
9
*
@@ -60,7 +60,7 @@ static pthread_mutex_t monlock = PTHREAD_MUTEX_INITIALIZER;
60
60
which are not currently in use. */
61
61
static pthread_t monitor_thread = -1 ;
62
62
63
- static int restart_monitor ();
63
+ static int restart_monitor (void );
64
64
65
65
/* The private structures of the Phone Jack channels are linked for
66
66
selecting outgoing channels */
@@ -129,7 +129,8 @@ static int ixj_call(struct ast_channel *ast, char *dest, int timeout)
129
129
}
130
130
/* When we call, it just works, really, there's no destination... Just
131
131
ring the phone and wait for someone to answer */
132
- ast_log (LOG_DEBUG , "Ringing %s on %s (%d)\n" , dest , ast -> name , ast -> fd );
132
+ if (option_debug )
133
+ ast_log (LOG_DEBUG , "Ringing %s on %s (%d)\n" , dest , ast -> name , ast -> fd );
133
134
ioctl (p -> fd , IXJCTL_RING_START );
134
135
ast -> state = AST_STATE_RINGING ;
135
136
return 0 ;
@@ -139,7 +140,8 @@ static int ixj_hangup(struct ast_channel *ast)
139
140
{
140
141
struct ixj_pvt * p ;
141
142
p = ast -> pvt -> pvt ;
142
- ast_log (LOG_DEBUG , "ixj_hangup(%s)\n" , ast -> name );
143
+ if (option_debug )
144
+ ast_log (LOG_DEBUG , "ixj_hangup(%s)\n" , ast -> name );
143
145
if (!ast -> pvt -> pvt ) {
144
146
ast_log (LOG_WARNING , "Asked to hangup channel not connected\n" );
145
147
return 0 ;
@@ -217,7 +219,8 @@ static int ixj_setup(struct ast_channel *ast)
217
219
static int ixj_answer (struct ast_channel * ast )
218
220
{
219
221
ixj_setup (ast );
220
- ast_log (LOG_DEBUG , "ixj_answer(%s)\n" , ast -> name );
222
+ if (option_debug )
223
+ ast_log (LOG_DEBUG , "ixj_answer(%s)\n" , ast -> name );
221
224
ast -> rings = 0 ;
222
225
ast -> state = AST_STATE_UP ;
223
226
return 0 ;
@@ -287,6 +290,14 @@ static struct ast_frame *ixj_read(struct ast_channel *ast)
287
290
res = read (p -> fd , p -> buf , IXJ_MAX_BUF );
288
291
ast -> blocking = 0 ;
289
292
if (res < 0 ) {
293
+ #if 0
294
+ if (errno == EAGAIN ) {
295
+ ast_log (LOG_WARNING , "Null frame received\n" );
296
+ p -> fr .frametype = AST_FRAME_NULL ;
297
+ p -> fr .subclass = 0 ;
298
+ return & p -> fr ;
299
+ }
300
+ #endif
290
301
ast_log (LOG_WARNING , "Error reading: %s\n" , strerror (errno ));
291
302
return NULL ;
292
303
}
@@ -486,6 +497,10 @@ static void ixj_check_exception(struct ixj_pvt *i)
486
497
ixj_new (i , AST_STATE_UP );
487
498
/* No need to restart monitor, we are the monitor */
488
499
if (i -> owner ) {
500
+ pthread_mutex_lock (& usecnt_lock );
501
+ usecnt -- ;
502
+ pthread_mutex_unlock (& usecnt_lock );
503
+ ast_update_use_count ();
489
504
ixj_setup (i -> owner );
490
505
}
491
506
} else if (ast_exists_extension (NULL , "default" , i -> ext , 1 )) {
@@ -494,10 +509,16 @@ static void ixj_check_exception(struct ixj_pvt *i)
494
509
strncpy (i -> context , "default" , sizeof (i -> context ));
495
510
ixj_new (i , AST_STATE_UP );
496
511
if (i -> owner ) {
512
+ pthread_mutex_lock (& usecnt_lock );
513
+ usecnt -- ;
514
+ pthread_mutex_unlock (& usecnt_lock );
515
+ ast_update_use_count ();
497
516
ixj_setup (i -> owner );
498
517
}
499
518
} else if ((strlen (i -> ext ) >= ast_pbx_longest_extension (i -> context )) &&
500
519
(strlen (i -> ext ) >= ast_pbx_longest_extension ("default" ))) {
520
+ if (option_debug )
521
+ ast_log (LOG_DEBUG , "%s is too long\n" , i -> ext );
501
522
/* It's not a valid extension, give a busy signal */
502
523
ioctl (i -> fd , IXJCTL_BUSY );
503
524
}
@@ -512,18 +533,23 @@ static void ixj_check_exception(struct ixj_pvt *i)
512
533
if (i -> mode == MODE_IMMEDIATE ) {
513
534
ixj_new (i , AST_STATE_RING );
514
535
} else if (i -> mode == MODE_DIALTONE ) {
515
- #if 0
516
- /* XXX Bug in the Phone jack, you can't detect DTMF when playing a tone XXX */
517
- ioctl ( i -> fd , IXJCTL_DIALTONE );
518
- #else
536
+ pthread_mutex_lock ( & usecnt_lock );
537
+ usecnt ++ ;
538
+ pthread_mutex_unlock ( & usecnt_lock );
539
+ ast_update_use_count ();
519
540
/* Play the dialtone */
520
541
i -> dialtone ++ ;
521
542
ioctl (i -> fd , IXJCTL_PLAY_STOP );
522
543
ioctl (i -> fd , IXJCTL_PLAY_CODEC , ULAW );
523
544
ioctl (i -> fd , IXJCTL_PLAY_START );
524
- #endif
525
545
}
526
546
} else {
547
+ if (i -> dialtone ) {
548
+ pthread_mutex_lock (& usecnt_lock );
549
+ usecnt -- ;
550
+ pthread_mutex_unlock (& usecnt_lock );
551
+ ast_update_use_count ();
552
+ }
527
553
memset (i -> ext , 0 , sizeof (i -> ext ));
528
554
ioctl (i -> fd , IXJCTL_CPT_STOP );
529
555
ioctl (i -> fd , IXJCTL_PLAY_STOP );
@@ -690,11 +716,13 @@ static int restart_monitor()
690
716
return 0 ;
691
717
}
692
718
693
- struct ixj_pvt * mkif (char * iface , int mode )
719
+ static struct ixj_pvt * mkif (char * iface , int mode )
694
720
{
695
721
/* Make a ixj_pvt structure for this interface */
696
722
struct ixj_pvt * tmp ;
723
+ #if 0
697
724
int flags ;
725
+ #endif
698
726
699
727
tmp = malloc (sizeof (struct ixj_pvt ));
700
728
if (tmp ) {
@@ -709,8 +737,10 @@ struct ixj_pvt *mkif(char *iface, int mode)
709
737
ioctl (tmp -> fd , IXJCTL_RING_STOP );
710
738
ioctl (tmp -> fd , IXJCTL_CPT_STOP );
711
739
tmp -> mode = mode ;
740
+ #if 0
712
741
flags = fcntl (tmp -> fd , F_GETFL );
713
742
fcntl (tmp -> fd , F_SETFL , flags | O_NONBLOCK );
743
+ #endif
714
744
tmp -> owner = NULL ;
715
745
tmp -> lastformat = -1 ;
716
746
tmp -> lastinput = -1 ;
0 commit comments