@ -1018,42 +1018,38 @@ static int agent_hangup(struct ast_channel *ast)
return 0 ;
return 0 ;
}
}
static int agent_cont_sleep ( void * data )
static int agent_cont_sleep ( void * data )
{
{
struct agent_pvt * p ;
struct agent_pvt * p ;
int res ;
int res ;
p = ( struct agent_pvt * ) data ;
p = ( struct agent_pvt * ) data ;
ast_mutex_lock ( & p - > lock ) ;
ast_mutex_lock ( & p - > lock ) ;
res = p - > app_sleep_cond ;
res = p - > app_sleep_cond ;
if ( p - > lastdisc . tv_sec ) {
if ( res & & p - > lastdisc . tv_sec ) {
if ( ast_tvdiff_ms ( ast_tvnow ( ) , p - > lastdisc ) > 0 )
if ( ast_tvdiff_ms ( ast_tvnow ( ) , p - > lastdisc ) > 0 ) {
res = 1 ;
res = 0 ;
}
}
}
ast_mutex_unlock ( & p - > lock ) ;
ast_mutex_unlock ( & p - > lock ) ;
if ( ! res )
if ( ! res ) {
ast_debug ( 5 , " agent_cont_sleep() returning %d \n " , res ) ;
ast_debug ( 5 , " agent_cont_sleep() returning %d \n " , res ) ;
}
return res ;
return res ;
}
}
static int agent_ack_sleep ( void * data )
static int agent_ack_sleep ( struct agent_pvt * p )
{
{
struct agent_pvt * p ;
int digit ;
int res = 0 ;
int to = 1000 ;
int to = 1000 ;
struct ast_frame * f ;
struct ast_frame * f ;
struct timeval start = ast_tvnow ( ) ;
struct timeval start = ast_tvnow ( ) ;
int ms ;
int ms ;
/* Wait a second and look for something */
/* Wait a second and look for something */
p = ( struct agent_pvt * ) data ;
if ( ! p - > chan )
return - 1 ;
while ( ( ms = ast_remaining_ms ( start , to ) ) ) {
while ( ( ms = ast_remaining_ms ( start , to ) ) ) {
ms = ast_waitfor ( p - > chan , ms ) ;
ms = ast_waitfor ( p - > chan , ms ) ;
if ( ms < 0 ) {
if ( ms < 0 ) {
@ -1063,23 +1059,31 @@ static int agent_ack_sleep(void *data)
return 0 ;
return 0 ;
}
}
f = ast_read ( p - > chan ) ;
f = ast_read ( p - > chan ) ;
if ( ! f )
if ( ! f ) {
return - 1 ;
return - 1 ;
if ( f - > frametype = = AST_FRAME_DTMF )
}
res = f - > subclass . integer ;
if ( f - > frametype = = AST_FRAME_DTMF ) {
else
digit = f - > subclass . integer ;
res = 0 ;
} else {
digit = 0 ;
}
ast_frfree ( f ) ;
ast_frfree ( f ) ;
ast_mutex_lock ( & p - > lock ) ;
ast_mutex_lock ( & p - > lock ) ;
if ( ! p - > app_sleep_cond ) {
if ( ! p - > app_sleep_cond ) {
ast_mutex_unlock ( & p - > lock ) ;
ast_mutex_unlock ( & p - > lock ) ;
return 0 ;
return 0 ;
} else if ( res = = p - > acceptdtmf ) {
}
if ( digit = = p - > acceptdtmf ) {
ast_mutex_unlock ( & p - > lock ) ;
ast_mutex_unlock ( & p - > lock ) ;
return 1 ;
return 1 ;
}
}
if ( p - > lastdisc . tv_sec ) {
if ( ast_tvdiff_ms ( ast_tvnow ( ) , p - > lastdisc ) > 0 ) {
ast_mutex_unlock ( & p - > lock ) ;
return 0 ;
}
}
ast_mutex_unlock ( & p - > lock ) ;
ast_mutex_unlock ( & p - > lock ) ;
res = 0 ;
}
}
return 0 ;
return 0 ;
}
}