![](/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-05-20
- Revision:
- 126:1f90756250fb
- Parent:
- 125:8ff4dc96ad58
- Child:
- 132:05cd37f7e007
File content as of revision 126:1f90756250fb:
#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, const 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 ]; bool should_remove = false; for ( register uint8_t i = 0; i < v_call->size(); i++ ) { should_remove = false; VZ_call * call = ( VZ_call * )v_call->get_element( i ); if ( call == NULL ) continue; if ( end_call ) { if ( end_call_ext == call -> get_cb_ext () ) { end_call = false; end_call_ext = 0; should_remove = true; } } if ( call->is_timetofinish() || call->cbx_pkg_is_idle() || should_remove ) { if ( debug_invite && !should_remove ) { 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 ); } } if ( end_call_ext != 0 ) { if ( debug_invite ) debug_msg ( "Call from %i not foud", end_call_ext ); end_call = false; end_call_ext = 0; } } void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ) { if ( ( v_call != NULL ) and ( v_cb != NULL ) and ( ts != NULL ) ) { uint8_t data [ CB_BUFFER_SIZE ]; uint8_t write_buffer [ CB_BUFFER_SIZE ]; if ( inviting_cb != NULL ) { if ( inviting_cb -> get_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 ) or ( cb -> get_status () == cb_on_call ) ) continue; int ext = cb->get_ext (); int port = cb->get_port (); VZ_call * call = NULL; switch ( cb -> get_status () ) { case cb_trying : { uint8_t timeslice = ts -> get_timeslice (); if ( timeslice == 0 ) { data [ TIMESLICE_PLACE ] = 0x00; // validar troca de mensagens com nros "nao previstos" 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 ); // validar troca de mensagens com nros "nao previstos" 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 (); // confirmar a msg_id se sempre é bem aceita pelo cbx 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 -> get_sip_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; } } } }