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:
- 113:db67ae00550e
- Parent:
- 112:6ae726539ab9
- Child:
- 114:472502b31a12
--- a/call_box.cpp Mon Apr 13 12:16:21 2015 +0000 +++ b/call_box.cpp Thu Apr 16 12:57:13 2015 +0000 @@ -9,9 +9,34 @@ msg_id = 0x10; timeslice = 0x00; status = cb_idle; - sip = new Sip( ext, 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 ); + } + + shift_port = SHIFT_PORT; + sip = new Sip( ext, ext + shift_port ); sip_socket_fd = sip->get_socket_fd(); if( sip == NULL ) + { memory_is_over = true; if( debug_memory ) debug_msg("Sip allocation fail"); @@ -20,7 +45,6 @@ next_aging_type = __CYCLES__; seconds.start(); invite_response = true; - //invite_first_response = true; bye_response = true; invite_retry_count = MAX_INVITE_RETRY; cb_new_counter++; @@ -73,8 +97,8 @@ void Call_Box::registry( void ){ if( this->sip == NULL ){ + this->sip = new Sip( ext, ext + shift_port ); deleted_sip++; - this->sip = new Sip( ext, port ); if( sip == NULL ){ memory_is_over = true; if( debug_memory ) debug_msg("Call_Box cb allocation fail"); @@ -94,8 +118,8 @@ void Call_Box::unregistry( void ){ if( this->sip == NULL ){ + this->sip = new Sip( ext, ext + shift_port ); deleted_sip++; - this->sip = new Sip( ext, port ); if( sip == NULL ){ memory_is_over = true; if( debug_memory ) debug_msg("Call_Box cb allocation fail"); @@ -115,8 +139,8 @@ VZ_call * call = NULL; if( this->sip == NULL ){ + this->sip = new Sip( ext, ext + shift_port ); deleted_sip++; - this->sip = new Sip( ext, port ); if( sip != NULL ){ memory_is_over = true; @@ -144,9 +168,9 @@ */ int Call_Box::listen_SIP_server( void ){ if( this->sip == NULL ){ - deleted_sip++; if( status == cb_on_call || status == cb_idle ){ - this->sip = new Sip( ext, port ); + this->sip = new Sip( ext, ext + shift_port ); + deleted_sip++; if( sip == NULL ){ memory_is_over = true; @@ -183,8 +207,8 @@ void Call_Box::send_bye( void ){ if( this->sip == NULL ){ + this->sip = new Sip( ext, ext + shift_port ); deleted_sip++; - this->sip = new Sip( ext, port ); if( sip == NULL ){ memory_is_over = true; @@ -203,17 +227,9 @@ } void Call_Box::reset_sip( void ){ - debug_msg("reset_sip"); + if( this->sip != NULL ) delete( this->sip ); - if( this->sip != NULL ) - { - delete( this->sip ); - debug_msg("deletei"); - } - - this->sip = new Sip( ext, port ); - debug_msg( "sobrescrevi" ); - + this->sip = new Sip( ext, ext + shift_port ); deleted_sip++; if( sip == NULL ) memory_is_over = true; @@ -225,8 +241,7 @@ }else{ if( debug_cb) debug_msg("Sip equals NULL o.O"); deleted_sip++; - debug_msg("Sip equals NULL o.O"); - } + } } void Call_Box::re_start_timer( void ){ @@ -281,7 +296,13 @@ 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_timer( void ){ return t.read(); } + +int Call_Box::get_timer ( void ) +{ + int now = t.read (); + if( now >= 9999 || now <= 0 ) t.reset (); + return t.read (); +} int Call_Box::get_rtp_port ( void ) { @@ -290,7 +311,6 @@ }else{ if( debug_cb) debug_msg("Sip equals NULL o.O"); deleted_sip++; - debug_msg("Sip equals NULL o.O"); return -1; } } @@ -299,11 +319,33 @@ { if( this->sip != NULL ){ this->sip->set_sip_rtp_port( new_rtp_port ); - }else{ - if( debug_cb) debug_msg("Sip equals NULL o.O"); + } + else + { + if ( debug_cb ) debug_msg("Sip equals NULL o.O"); deleted_sip++; - debug_msg("Sip equals NULL o.O"); - } + } +} + +void Call_Box::init_rtp_timer ( void ) +{ + this->rtp_timer.start(); +} + +void Call_Box::reset_rtp_timer ( void ) +{ + this->rtp_timer.stop(); + this->rtp_timer.reset(); +} + +bool Call_Box::is_rtp_timer_timeout ( void ) +{ + return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; +} + +int Call_Box::get_rtp_timer ( void ) +{ + return ( rtp_timer.read () ); } int Call_Box::print_yourself ( void ) @@ -352,25 +394,4 @@ send_msg (""); return ( sizeof( Call_Box ) ); -} - -void Call_Box::init_rtp_timer ( void ) -{ - this->rtp_timer.start(); -} - -void Call_Box::reset_rtp_timer ( void ) -{ - this->rtp_timer.stop(); - this->rtp_timer.reset(); -} - -bool Call_Box::is_rtp_timer_timeout ( void ) -{ - return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; -} - -int Call_Box::get_rtp_timer ( void ) -{ - return ( rtp_timer.read () ); } \ No newline at end of file