![](/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:
- 132:05cd37f7e007
- Parent:
- 126:1f90756250fb
- Child:
- 135:2f4290590e51
--- a/call_box.cpp Tue Jul 21 20:03:35 2015 +0000 +++ b/call_box.cpp Tue Sep 01 17:21:11 2015 +0000 @@ -10,36 +10,14 @@ timeslice = 0x00; status = cb_idle; - { - shift_port = SHIFT_PORT; - - FILE * fp = NULL; - char inner_tmp[ 20 ]; + shift_port = cm -> get_shift_port (); - 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 ) vz_debug ("[%d] Sip allocation fail", this->ext ); } else { sip_socket_fd = sip->get_socket_fd (); } @@ -51,6 +29,7 @@ invite_try_number = 0; overflow = false; overflow_times = 0; + invite_counter = 0; } int Call_Box::get_status ( void ) { return this->status; } @@ -88,24 +67,24 @@ { if ( drop_registry_pkg ) { - send_msg ("[%d] Dropando registry pck", this->ext ); + vz_printf ("[%d] Dropando registry pck", this->ext ); return -5; } + reset_elapsed_time (); + if ( this -> sip not_eq NULL ) { int return_value = sip -> registry (); if ( return_value > 0 ) - { - reset_elapsed_time (); - - if ( debug_aging ) send_msg ( "[%d] Registered", this->ext ); + { + if ( debug_aging ) vz_printf ( "[%d] Registered", this->ext ); return ( return_value ); } } else { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; return ( -3 ); } @@ -121,12 +100,12 @@ { call = sip->invite (); } else { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%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 ( debug_cb ) vz_printf ("[%d] Call returned value :: %p ", this->ext, ( void * ) call ); if ( call == NULL ) t.start (); @@ -142,7 +121,7 @@ { if ( this->sip == NULL ) { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; @@ -168,11 +147,11 @@ void Call_Box::send_bye ( void ) { - if ( this->sip == NULL ) + if ( this -> sip == NULL ) { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this -> ext ); - deleted_sip++; + deleted_sip ++; } else { sip -> send_bye (); } @@ -180,16 +159,16 @@ void Call_Box::reset_sip ( void ) { - debug_msg ("[%d] reset_sip", this->ext ); + vz_debug ("[%d] reset_sip", this->ext ); if ( this->sip not_eq NULL ) { delete ( this->sip ); - debug_msg ("[%d] deletei", this->ext ); + vz_debug ("[%d] deletei", this->ext ); } this->sip = new Sip ( ext, ext + shift_port ); - debug_msg ( "[%d ]sobrescrevi", this->ext ); + vz_debug ( "[%d ]sobrescrevi", this->ext ); deleted_sip++; @@ -203,16 +182,16 @@ this -> sip -> sip_set_status ( new_sip_status ); } else { - if ( debug_cb) debug_msg("[%d] Sip equals NULL o.O", this->ext ); + if ( debug_cb) vz_debug ("[%d] Sip equals NULL o.O", this->ext ); deleted_sip++; - debug_msg("[%d] Sip equals NULL o.O", this->ext ); + vz_debug ("[%d] Sip equals NULL o.O", this->ext ); } } void Call_Box::set_invite_response_ok ( void ) { this -> invite_response = true; - if ( debug_invite ) send_msg ("[%d] Invite response :: ok", this->ext ); + if ( debug_invite ) vz_debug ("[%d] Invite response :: ok", this->ext ); } void Call_Box::set_invite_response_pending ( void ) { this->invite_response = false; } @@ -266,7 +245,7 @@ { return this -> sip -> get_sip_rtp_port (); } else { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; @@ -280,7 +259,7 @@ { this->sip->set_sip_rtp_port( new_rtp_port ); }else{ - debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; } @@ -306,46 +285,46 @@ int Call_Box::print_yourself ( void ) { - send_msg (""); - send_msg ("Values ::\r\n"); + vz_printf ("\r\n"); + vz_printf ("Values ::\r\n"); switch( status ) { case cb_idle : { - send_msg ("status :: cb_idle" ); + vz_printf ("status :: cb_idle" ); break; } case cb_ringing : { - send_msg ("status :: cb_ringing" ); + vz_printf ("status :: cb_ringing" ); break; } case cb_trying : { - send_msg ("status :: cb_trying" ); + vz_printf ("status :: cb_trying" ); break; } case cb_on_call : { - send_msg ("status :: cb_on_call" ); + vz_printf ("status :: cb_on_call" ); break; } case cb_busy : { - send_msg ("status :: cb_busy" ); + vz_printf ("status :: cb_busy" ); break; } case cb_denied : { - send_msg ("status :: cb_denied" ); + vz_printf ("status :: cb_denied" ); break; } } - send_msg ("ext :: %i", ext ); - send_msg ("port :: %i", port ); - send_msg ("Timer t :: %d", ( int )t.read () ); - send_msg ("overflow_times :: %u", overflow_times ); - send_msg ("msg_id :: %d", msg_id ); - send_msg ("timeslice :: %u", timeslice ); - send_msg ("next_aging_type :: %u", next_aging_type ); - send_msg ("invite_response :: %s", ( invite_response ) ? "true" : "false" ); - send_msg ("invite_retry_count :: %u", invite_retry_count ); - send_msg ("bye_response :: %s", ( bye_response ) ? "true" : "false" ); - send_msg ("sip_socket_fd :: %d", sip_socket_fd ); - send_msg (""); + vz_printf ("ext :: %i", ext ); + vz_printf ("port :: %i", port ); + vz_printf ("Timer t :: %d", ( int )t.read () ); + vz_printf ("overflow_times :: %u", overflow_times ); + vz_printf ("msg_id :: %d", msg_id ); + vz_printf ("timeslice :: %u", timeslice ); + vz_printf ("next_aging_type :: %u", next_aging_type ); + vz_printf ("invite_response :: %s", ( invite_response ) ? "true" : "false" ); + vz_printf ("invite_retry_count :: %u", invite_retry_count ); + vz_printf ("bye_response :: %s", ( bye_response ) ? "true" : "false" ); + vz_printf ("sip_socket_fd :: %d", sip_socket_fd ); + vz_printf ("\r\n"); return ( sizeof( Call_Box ) ); } @@ -371,16 +350,16 @@ int Call_Box::call_end ( const bool send_bye_to_ast ) { - uint8_t timeslice = this->timeslice; + uint8_t timeslice = this -> timeslice; - this->timeslice = 0; + this -> timeslice = 0; - this->status = cb_idle; + this -> status = cb_idle; if ( sip not_eq NULL ) { sip -> sip_set_status ( sip_idle ); } else { - if( debug_cb ) debug_msg("[%d] Sip equals NULL o.O", this->ext ); + if( debug_cb ) vz_debug ("[%d] Sip equals NULL o.O", this -> ext ); } set_rtp_port ( 0 ); @@ -452,7 +431,7 @@ invite_try_number++; return ( sip -> retry_send_last_invite_pkg_to_ast () ); } else { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); deleted_sip++; @@ -466,7 +445,7 @@ { return sip -> print_yourself (); } else { - debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); + vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); return ( -1 ); } @@ -479,5 +458,20 @@ uint8_t Call_Box::get_overflow_times ( void ) { return ( this -> overflow_times ); } +void Call_Box::update_time ( void ){ get_timer (); } -void Call_Box::update_time ( void ){ get_timer (); } \ No newline at end of file +uint16_t Call_Box::get_invite_counter ( void ) { return ( this -> invite_counter ); } + +uint16_t Call_Box::update_invite_counter ( void ) { return ( this -> invite_counter++ ); } + +int Call_Box::update ( void ) +{ + shift_port = cm -> get_shift_port (); + + if ( sip not_eq NULL ) + { + sip -> set_port ( ext + shift_port ); + sip -> update (); + } + return ( 0 ); +} \ No newline at end of file