![](/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
call_manager.cpp
- Committer:
- klauss
- Date:
- 2015-04-30
- Revision:
- 119:ee6a53069455
- Parent:
- 117:e9facba9db27
- Child:
- 121:ee02790d00b7
File content as of revision 119:ee6a53069455:
#include "call_manager.h" Timer invite_pkg_retry_timer; Timer bye_pkg_retry_timer; void init_invite_pgk_retry_manager( void ){ invite_pkg_retry_timer.start(); } void init_bye_pgk_retry_manager( void ){ bye_pkg_retry_timer.start(); } void invite_pgk_retry_manager( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ for( register uint8_t i = 0; i < v_cb->size(); i++ ){ Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if( cb->get_status() == cb_on_call ){ if( cb->get_invite_response() == false ){ invite_pkg_retry_timer.reset(); send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), INVITE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); return; } } } } void bye_pgk_retry_manager( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ for( register uint8_t i = 0; i < v_cb->size(); i++ ){ Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if( cb->get_status() == cb_idle ){ if( cb->get_bye_response() == false ){ bye_pkg_retry_timer.reset(); send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), CB_BYE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); return; } } } } VZ_call * __find_Call__( Vector * v_call, int ext ){ VZ_call * call = NULL; for( register int i = 0; i < v_call->size(); i++ ){ call = ( VZ_call * )v_call->get_element( i ); if ( call != NULL ) { if( call->get_cb_ext() == ext ) return( call ); } } return( NULL ); } /* remove calls por timeout */ void call_manager( Vector * v_call, Vector * v_cb, Timeslice * ts ) { //FixME pode dar problema por conta do static static uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; for( register uint8_t i = 0; i < v_call->size(); i++ ) { VZ_call * call = ( VZ_call * )v_call->get_element( i ); if( call->is_timetofinish() || call->cbx_pkg_is_idle() ) { if( debug_invite ){ if( call->cbx_pkg_is_idle() ){ if( debug_invite ) debug_msg("[%d] Call timeout: no pkg", call->get_cb_ext () ); } else { if( debug_invite ) debug_msg("[%d] Call timeout", call->get_cb_ext () ); } } v_call->remove_element( i ); Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); if( cb != NULL ){ data[ TIMESLICE_PLACE ] = 0; send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), CB_BYE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); ts->return_timeslice( cb->call_end () ); } delete( call ); } } } void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ if ( ( v_call != NULL ) && ( v_cb != NULL ) && ( ts != NULL ) ) { uint8_t data[ CB_BUFFER_SIZE ]; uint8_t write_buffer[ CB_BUFFER_SIZE ]; if( inviting_cb != NULL ){ if( inviting_cb->status == cb_idle ){ inviting_cb->cb_set_status( cb_trying ); if( debug_invite ) debug_msg("[%d] Request invite <cb_idle,cb_trying>", inviting_cb->get_ext () ); } } for( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if ( cb == NULL ) continue; if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; int ext = cb->get_ext(); int port = cb->get_port(); VZ_call * call = NULL; switch( cb->status ){ case cb_trying : { uint8_t timeslice = ts->get_timeslice (); if( timeslice == 0 ){ data[ TIMESLICE_PLACE ] = 0x00; send2callboxes( build_cb_package( ext, port, INVITE, ( char * )data, ( cb->get_msg_id() | BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); cb->call_end (); if( debug_invite ) debug_msg( "[%d] Trying without TS <cb_trying,cb_idle>", ext ); return; }else{ data[ TIMESLICE_PLACE ] = timeslice; cb->call_init ( timeslice ); 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] TS::%d <cb_trying,cb_ringing>", ext, data[ TIMESLICE_PLACE ] ); } }break; case cb_ringing : { call = cb->invite(); if( cb->get_sip_status() == sip_busy ){ cb->cb_set_status( cb_busy ); }else if( call != NULL ){ if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); call->init_cbx_pkg_idle_timer(); if( cb->get_sip_status() == sip_on_call ){ data[ TIMESLICE_PLACE ] = cb->get_timeslice(); send2callboxes( build_cb_package( ext, port, INVITE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); cb->call_confirmed (); if( debug_invite ) debug_msg( "[%d] Ringing call ok <cb_ringing,cb_on_call>", ext ); } }else{ if( cb->get_sip_status() == sip_denied ) { cb->cb_set_status( cb_denied ); if( debug_invite ) debug_msg( "[%d] call denied <sip_denied>::<cb_ringing,cb_denied>", ext ); } else { if ( cb->time_to_retry () ) { if ( cb->sip != NULL ) { if ( cb->sip->get_status () == sip_waiting_trying ) { if ( debug_invite ) debug_msg ("[%4i %3i] Resend invite to *", ext, cb -> get_invite_try_number () ); cb->retry_send_invite_pkg_to_ast (); } } } } } }break; case cb_busy : { data[ TIMESLICE_PLACE ] = 0; send2callboxes( build_cb_package( ext, port, CB_BYE, ( char * )data, cb->msg_id_update (), 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 ); if( call != NULL ) delete( call ); break; } } ts->return_timeslice( cb->call_end () ); if( debug_invite ) debug_msg( "[%d] Busy Here <cb_busy,cb_idle>", ext ); }break; case cb_denied : { data[ TIMESLICE_PLACE ] = 0; send2callboxes( build_cb_package( ext, port, CB_BYE, ( char * )data, cb->msg_id_update (), 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 ); if( call != NULL ) delete( call ); break; } } ts->return_timeslice( cb->call_end () ); if( debug_invite ) debug_msg( "[%d] call denied <cb_denied,cb_idle>", ext ); }break; } } } }