![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: call_manager.cpp
- Revision:
- 77:e8c0253b57bc
- Parent:
- 76:9f5f99dd895a
- Child:
- 78:1353744f01e1
--- a/call_manager.cpp Tue Nov 25 17:37:56 2014 +0000 +++ b/call_manager.cpp Tue Nov 25 18:43:01 2014 +0000 @@ -31,137 +31,4 @@ delete( call ); } } -} - -void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * cb ){ - uint8_t data[ __CB_BUFFER_SIZE__ ]; - uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; - - int ext = 0x00; - int port = 0x00; - - bool should_return = true; - - if( cb != NULL ){ - ext = cb->get_ext(); - port = cb->get_port(); - set_status( cb->status, cb_trying ); - if( debug_invite ) debug_msg("Request invite cbx status :: %d", cb->status ); - }else{ - should_return = true; - for( register uint8_t i = 0; i < v_cb->size(); i++ ){ - Call_Box * inner_cb = ( Call_Box * )v_cb->get_element( i ); - if( inner_cb -> get_status() != cb_idle ){ - should_return = false; - cb = inner_cb; - break; - } - } - if( should_return ) return; - } - - for( register uint8_t i = 0; i < v_cb->size(); i++ ){ - cb = ( Call_Box * )v_cb->get_element( i ); - - if( cb -> get_status() == cb_idle ) continue; - - VZ_call * call = NULL; - - switch( cb->status ){ - case cb_ringing : { - call = cb->invite(); - - if( call != NULL ){ - if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); - - //if( ( cb->get_sip_status() == sip_trying ) || ( cb->get_sip_status() == sip_ringing ) ); - - if( cb->get_sip_status() == sip_on_call ){ - //if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); - - /* isso quer dizer que o invite foi aceito, tenho que aceitar ele mais pra baixp*/ - send2callboxes( __build_cb_package__( ext, port, __INVITE__, ( char * )data, - cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - - if( debug_invite ) debug_msg( "-- ringing -- accepting call request --" ); - } - }else{ - if( cb->get_sip_status() == sip_denied ) set_status( cb->status , cb_denied ); - } - }break; - case cb_trying : { - data[ 0 ] |= BIT7; - cb->set_msg_id( data[ 0 ] ); - cb->set_timeslice( ts->get_timeslice() ); - // No protocolo VZ, timeslice == 0x00 significa que nao temos mais ts - if( cb->get_timeslice() == 0x00 ){ - set_status(cb->status,cb_idle); - data[ __TIMESLICE_PLACE__ ] = 0x00; - send2callboxes( __build_cb_package__( ext, port, __INVITE__, - ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - set_status( cb->sip->status, sip_idle ); - if( debug_invite ) debug_msg( "-- Trying -- without TS -- %s ", write_buffer ); - }else{ - data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); - - set_status( cb->status, cb_ringing ); - - /* Isso diz pro CBx o Timeslice que ele vai usar e deixa o Cbx na espera da resposta do Asterisk */ - send2callboxes( __build_cb_package__( ext, port, __INVITE__, - ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - - if( debug_invite ) debug_msg(" -- %d on TS::%d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); - - cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); - } - }break; - case cb_busy : { - set_status( cb->status, cb_idle ); - ts->return_timeslice( cb->get_timeslice() ); - cb->set_timeslice( 0x00 ); - data[ __TIMESLICE_PLACE__ ] = 0x00; - if( debug_invite ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); - - send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, - ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - - if( debug_invite ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); - - for( register uint8_t i = 0; i < v_call->size(); i++ ){ - VZ_call * call = ( VZ_call * )v_call->get_element( i ); - if( call->get_cb_ext() == cb->get_ext() ){ - v_call->remove_element( i ); - delete( call ); - break; - } - } - - cb->send_bye(); - set_status( cb->sip->status, sip_idle ); - cb->re_start_timer(); - }break; - case cb_denied : { - set_status( cb->status, cb_idle ); - ts->return_timeslice( cb->get_timeslice() ); - cb->set_timeslice( 0x00 ); - data[ __TIMESLICE_PLACE__ ] = 0x00; - if( debug_invite ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); - - send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, - ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - - for( register uint8_t i = 0; i < v_call->size(); i++ ){ - VZ_call * call = ( VZ_call * )v_call->get_element( i ); - if( call->get_cb_ext() == cb->get_ext() ){ - v_call->remove_element( i ); - delete( call ); - break; - } - } - - if( debug_invite ) debug_msg( "-- Trying -- denying call request --" ); - set_status( cb->sip->status, sip_idle ); - }break; - } - } } \ No newline at end of file