![](/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_box.cpp
- Revision:
- 121:ee02790d00b7
- Parent:
- 119:ee6a53069455
- Child:
- 122:480c44b0e205
--- a/call_box.cpp Mon May 04 17:25:29 2015 +0000 +++ b/call_box.cpp Fri May 08 04:15:23 2015 +0000 @@ -1,20 +1,49 @@ #include "call_box.h" -Call_Box::Call_Box( int ext, int port ){ +Call_Box::Call_Box( const int ext, const int port ) +{ this->ext = ext; this->port = port; - t.start(); + + t.start (); remaining_attempts = __MAX_ATTEMPTS__; timeout = __TIMEOUT__; msg_id = 0x10; timeslice = 0x00; status = cb_idle; - sip = new Sip( ext, port ); - sip_socket_fd = sip->get_socket_fd(); - if( sip == NULL ) + + { + shift_port = SHIFT_PORT; + + FILE * fp = NULL; + char inner_tmp[ 20 ]; + + fp = fopen( "/qspi/shift_port.txt", "r" ); + if( fp == NULL ) + { + if( debug_cb ) debug_msg("Failed to open /qspi/shift_port.txt" ); + shift_port = SHIFT_PORT; + }else{ + if( fread( (void *)inner_tmp, 1, 20, fp ) > 0 ){ + shift_port = atoi( inner_tmp ); + if( debug_cb ) debug_msg("Shift port %d", shift_port ); + }else{ + if( debug_cb ) debug_msg("Failed to read /qspi/shift_port.txt" ); + shift_port = SHIFT_PORT; + } + } + + fclose( fp ); + } + + sip = new Sip( ext, ext + shift_port ); + + if ( sip == NULL ) { memory_is_over = true; - if( debug_memory ) debug_msg("[%d] Sip allocation fail", this->ext ); + if ( debug_memory ) debug_msg ("[%d] Sip allocation fail", this->ext ); + } else { + sip_socket_fd = sip->get_socket_fd (); } next_aging_type = __CYCLES__; @@ -23,57 +52,57 @@ invite_retry_count = MAX_INVITE_RETRY; cb_new_counter++; invite_try_number = 0; + overflow = false; } -int Call_Box::get_status( void ){ return this->status; } +int Call_Box::get_status ( void ) { return this->status; } + +void Call_Box::cb_set_status ( const uint8_t status ){ this->status = status; } -void Call_Box::cb_set_status( uint8_t status ){ this->status = status; } - -int Call_Box::get_sip_status( void ){ - if( sip == NULL ) return -1; +int Call_Box::get_sip_status ( void ) +{ + if ( sip == NULL ) return ( -1 ); - else return this->sip->get_status(); -} - -int Call_Box::set_sip_status( uint8_t status ){ - if( sip == NULL ) return( -1 ); - - sip->sip_set_status( status ); - - return( 0 ); + return ( sip -> get_status () ); } Call_Box::~Call_Box( void ){ - if( sip != NULL ) delete( sip ); + if ( sip != NULL ) delete ( sip ); cb_delete_counter++; } -int Call_Box::get_port( void ){ return( this->port ); } +int Call_Box::get_port ( void ) { return ( this->port ); } -int Call_Box::get_ext( void ){ return( this->ext ); } +int Call_Box::get_ext ( void ) { return ( this->ext ); } -float Call_Box::get_elapsed_time( void ){ return( this->t.read_ms() ); } +float Call_Box::get_elapsed_time ( void ) { return ( this -> t.read_ms () ); } -void Call_Box::reset_elapsed_time( void ){ - this->t.reset(); +void Call_Box::reset_elapsed_time ( void ) +{ + this -> t.reset (); timeout = __TIMEOUT__; next_aging_type = __CYCLES__; } -void Call_Box::registry( void ){ +void Call_Box::registry ( void ) +{ if ( drop_registry_pkg ) { - send_msg("[%d] Dropando registry pck", this->ext ); + send_msg ("[%d] Dropando registry pck", this->ext ); return; } - if( this->sip != NULL ) + if ( this->sip != NULL ) { - if( sip->registry() > 0x00 ) reset_elapsed_time(); - if( debug_aging ) send_msg( "[%d] Registered - ( %f )", this->ext, __TIMEOUT__ - t.read() ); + if ( sip -> registry () > 0 ) + { + reset_elapsed_time (); + overflow = false; + } + if ( debug_aging ) send_msg ( "[%d] Registered - ( %f )", this->ext, __TIMEOUT__ - t.read() ); } else { - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; } } @@ -82,18 +111,19 @@ { VZ_call * call = NULL; - if( this->sip != NULL ) + if ( this->sip != NULL ) { - call = sip->invite(); + call = sip->invite (); } else { - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; } - if( debug_cb ) send_msg("[%d] Call returned value :: %p ", this->ext, (void * )call ); - if( call == NULL ) t.start(); - return( call ); + if ( debug_cb ) send_msg ("[%d] Call returned value :: %p ", this->ext, ( void * ) call ); + if ( call == NULL ) t.start (); + + return ( call ); } /* Retorna @@ -101,64 +131,72 @@ < 0 :: tive problemas > 0 :: devo remover essa call do vetor de calls */ -int Call_Box::listen_SIP_server( void ){ - if( this->sip == NULL ) +int Call_Box::listen_SIP_server ( void ) +{ + if ( this->sip == NULL ) { - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; return ( -3 ); } else { - if( status == cb_on_call || status == cb_idle ){ - return ( sip->listen_SIP_server() ); + if ( status == cb_on_call || status == cb_idle ) + { + return ( sip -> listen_SIP_server () ); } else return ( 0 ); } } -void Call_Box::set_msg_id( uint8_t msg_id ){ +void Call_Box::set_msg_id ( const uint8_t msg_id ) { this->msg_id = ( msg_id > 0x10 ) ? msg_id : 0x11; } -uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); } +uint8_t Call_Box::get_msg_id ( void ) { return ( this->msg_id ); } -void Call_Box::set_timeslice( uint8_t timeslice ){ +void Call_Box::set_timeslice ( const uint8_t timeslice ) { this->timeslice = timeslice; } -uint8_t Call_Box::get_timeslice( void ){ return( this->timeslice ); } + +uint8_t Call_Box::get_timeslice ( void ) { return ( this->timeslice ); } -void Call_Box::send_bye( void ){ - if( this->sip == NULL ) +void Call_Box::send_bye ( void ) +{ + if ( this->sip == NULL ) { - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; } else { - sip->send_bye(); + sip -> send_bye (); } } -void Call_Box::reset_sip( void ){ - debug_msg("[%d] reset_sip", this->ext ); +void Call_Box::reset_sip ( void ) +{ + debug_msg ("[%d] reset_sip", this->ext ); - if( this->sip != NULL ) + if ( this->sip != NULL ) { - delete( this->sip ); - debug_msg("[%d] deletei", this->ext ); + delete ( this->sip ); + debug_msg ("[%d] deletei", this->ext ); } - this->sip = new Sip( ext, port ); - debug_msg( "[%d ]sobrescrevi", this->ext ); + this->sip = new Sip ( ext, ext + shift_port ); + debug_msg ( "[%d ]sobrescrevi", this->ext ); deleted_sip++; - if( sip == NULL ) memory_is_over = true; + if ( sip == NULL ) memory_is_over = true; } -void Call_Box::set_sip_status( int status ){ - if( this->sip != NULL ){ - this->sip->status = status; - }else{ - if( debug_cb) debug_msg("[%d] Sip equals NULL o.O", this->ext ); +void Call_Box::set_sip_status ( const uint8_t new_sip_status ) +{ + if ( this->sip != NULL ) + { + this -> sip -> sip_set_status ( new_sip_status ); + } else + { + if ( debug_cb) debug_msg("[%d] Sip equals NULL o.O", this->ext ); deleted_sip++; debug_msg("[%d] Sip equals NULL o.O", this->ext ); } @@ -166,52 +204,60 @@ void Call_Box::set_invite_response_ok ( void ) { - this->invite_response = true; + this -> invite_response = true; if ( debug_invite ) send_msg ("[%d] Invite response :: ok", this->ext ); } -void Call_Box::set_invite_response_pending( void ){ this->invite_response = false; } +void Call_Box::set_invite_response_pending ( void ) { this->invite_response = false; } -bool Call_Box::get_invite_response( void ){ return( this->invite_response ); } +bool Call_Box::get_invite_response ( void ) { return ( this->invite_response ); } -void Call_Box::invite_retry_count_reset( void ){ invite_retry_count = MAX_INVITE_RETRY; } +void Call_Box::invite_retry_count_reset ( void ) { invite_retry_count = MAX_INVITE_RETRY; } uint16_t Call_Box::get_invite_retry_count( void ){ return ( invite_retry_count ) ? invite_retry_count-- : 0; } -void Call_Box::set_bye_response_ok( void ){ this->bye_response = true; } +void Call_Box::set_bye_response_ok ( void ) { this->bye_response = true; } -void Call_Box::set_bye_response_pending( void ){ this->bye_response = false; } +void Call_Box::set_bye_response_pending ( void ) { this->bye_response = false; } -bool Call_Box::get_bye_response( void ){ return( this->bye_response ); } +bool Call_Box::get_bye_response( void ) { return( this->bye_response ); } -int Call_Box::get_sip_socket_fd ( void ) { return( sip_socket_fd ); } +int Call_Box::get_sip_socket_fd ( void ) { return ( sip_socket_fd ); } -int Call_Box::sip_udp_incomming_pkg( void ){ - return sip->udp_incomming_pkg(); +int Call_Box::sip_udp_incomming_pkg ( void ) { + return sip -> udp_incomming_pkg (); } void Call_Box::reset_cb_status ( void ) { if( sip != NULL ) sip->reset_call(); } -int Call_Box::get_sip_ext( void ){ return this->sip->get_ext(); } +int Call_Box::get_sip_ext ( void ) { return this -> sip->get_ext (); } -int Call_Box::get_sip_port( void ){ return this->sip->get_port(); } +int Call_Box::get_sip_port ( void ) { return this -> sip->get_port (); } int Call_Box::get_timer ( void ) { int now = t.read (); - if( now >= 9999 || now <= 0 ) t.reset (); + + //if ( now >= 1500 || now <= 0 ) + if ( now >= 60 || now <= 0 ) + { + t.reset (); + overflow = true; + } + return t.read (); } int Call_Box::get_rtp_port ( void ) { - if( this->sip != NULL ){ - return this->sip->get_sip_rtp_port(); - }else{ - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + if ( this -> sip != NULL ) + { + return this -> sip -> get_sip_rtp_port (); + } else { + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; @@ -219,9 +265,10 @@ } } -void Call_Box::set_rtp_port ( int new_rtp_port ) +void Call_Box::set_rtp_port ( const int new_rtp_port ) { - if( this->sip != NULL ){ + if ( this->sip != NULL ) + { this->sip->set_sip_rtp_port( new_rtp_port ); }else{ debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); @@ -232,13 +279,13 @@ void Call_Box::init_rtp_timer ( void ) { - this->rtp_timer.start(); + this -> rtp_timer.start (); } void Call_Box::reset_rtp_timer ( void ) { - this->rtp_timer.stop(); - this->rtp_timer.reset(); + this -> rtp_timer.stop (); + this -> rtp_timer.reset (); } bool Call_Box::is_rtp_timer_timeout ( void ) @@ -246,10 +293,7 @@ return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; } -int Call_Box::get_rtp_timer ( void ) -{ - return ( rtp_timer.read () ); -} +int Call_Box::get_rtp_timer ( void ) { return ( rtp_timer.read () ); } int Call_Box::print_yourself ( void ) { @@ -298,7 +342,7 @@ return ( sizeof( Call_Box ) ); } -int Call_Box::call_init ( int timeslice ) +int Call_Box::call_init ( const int timeslice ) { invite_timer.reset (); @@ -317,7 +361,7 @@ return 0; } -int Call_Box::call_end ( bool send_bye_to_ast ) +int Call_Box::call_end ( const bool send_bye_to_ast ) { uint8_t timeslice = this->timeslice; @@ -357,7 +401,7 @@ { set_invite_response_pending (); - this->status = cb_on_call; + this -> status = cb_on_call; msg_id_update (); @@ -380,7 +424,8 @@ bool Call_Box::time_to_retry ( void ) { - if ( invite_timer.read_ms () > 1000 ){ + if ( invite_timer.read_ms () > 1000 ) + { invite_timer.reset (); return true; } else { @@ -392,15 +437,32 @@ int Call_Box::retry_send_invite_pkg_to_ast ( void ) { - if( this->sip != NULL ) + if ( this -> sip != NULL ) { invite_try_number++; return ( sip -> retry_send_last_invite_pkg_to_ast () ); } else { - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; return ( 0 ); } -} \ No newline at end of file +} + +int Call_Box::sip_print_yourself ( void ) +{ + if ( this -> sip != NULL ) + { + return sip -> print_yourself (); + } else { + debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + + return ( -1 ); + } + +} + +Sip * Call_Box::get_sip ( void ) { return this -> sip ; } + +bool Call_Box::get_overflow_flag ( void ) { return ( this->overflow ); } \ No newline at end of file