Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
call_box.cpp
00001 #include "call_box.h" 00002 00003 Call_Box::Call_Box( const int ext, const int port ) 00004 { 00005 this -> ext = ext; 00006 this -> port = port; 00007 00008 t.start (); 00009 msg_id = 0x10; 00010 timeslice = 0x00; 00011 status = cb_idle; 00012 00013 shift_port = cm -> get_shift_port (); 00014 00015 sip = new Sip( ext, ext + shift_port ); 00016 00017 if ( sip == NULL ) 00018 { 00019 memory_is_over = true; 00020 if ( debug_memory ) vz_debug ("[%d] Sip allocation fail", this->ext ); 00021 } else { 00022 sip_socket_fd = sip->get_socket_fd (); 00023 } 00024 00025 invite_response = true; 00026 bye_response = true; 00027 invite_retry_count = MAX_INVITE_RETRY; 00028 cb_new_counter++; 00029 invite_try_number = 0; 00030 overflow = false; 00031 overflow_times = 0; 00032 invite_counter = 0; 00033 00034 pair = NULL; 00035 } 00036 00037 int Call_Box::get_status ( void ) { return this->status; } 00038 00039 void Call_Box::cb_set_status ( const uint8_t status ){ this->status = status; } 00040 00041 int Call_Box::get_sip_status ( void ) 00042 { 00043 if ( sip == NULL ) return ( -1 ); 00044 00045 return ( sip -> get_status () ); 00046 } 00047 00048 Call_Box::~Call_Box( void ){ 00049 if ( sip not_eq NULL ) delete ( sip ); 00050 cb_delete_counter++; 00051 } 00052 00053 int Call_Box::get_port ( void ) { return ( this->port ); } 00054 00055 int Call_Box::get_ext ( void ) { return ( this->ext ); } 00056 00057 uint16_t Call_Box::get_elapsed_time ( void ) { return ( ( uint16_t ) this -> t.read_ms () ); } 00058 00059 void Call_Box::reset_elapsed_time ( void ) 00060 { 00061 this -> t.stop (); 00062 this -> t.reset (); 00063 this -> t.start (); 00064 overflow = false; 00065 overflow_times = 0; 00066 } 00067 00068 int Call_Box::registry ( void ) 00069 { 00070 if ( drop_registry_pkg ) 00071 { 00072 vz_printf ("[%d] Dropando registry pck", this->ext ); 00073 return -5; 00074 } 00075 00076 reset_elapsed_time (); 00077 00078 if ( this -> sip not_eq NULL ) 00079 { 00080 int return_value = sip -> registry (); 00081 00082 if ( return_value > 0 ) 00083 { 00084 if ( debug_aging ) vz_printf ( "[%d] Registered", this->ext ); 00085 00086 return ( return_value ); 00087 } 00088 } else { 00089 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00090 deleted_sip++; 00091 return ( -3 ); 00092 } 00093 00094 return ( 0 ); 00095 } 00096 00097 VZ_call * Call_Box::invite ( void ) 00098 { 00099 VZ_call * call = NULL; 00100 00101 if ( this->sip not_eq NULL ) 00102 { 00103 call = sip->invite (); 00104 } else { 00105 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00106 00107 deleted_sip++; 00108 } 00109 00110 if ( debug_cb ) vz_printf ("[%d] Call returned value :: %p ", this->ext, ( void * ) call ); 00111 00112 if ( call == NULL ) t.start (); 00113 00114 return ( call ); 00115 } 00116 00117 /* Retorna 00118 = 0 :: ok 00119 < 0 :: tive problemas 00120 > 0 :: devo remover essa call do vetor de calls 00121 */ 00122 int Call_Box::listen_SIP_server ( void ) 00123 { 00124 if ( this->sip == NULL ) 00125 { 00126 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00127 00128 deleted_sip++; 00129 00130 return ( -3 ); 00131 } else { 00132 if ( status == cb_on_call or status == cb_idle ) 00133 { 00134 return ( sip -> listen_SIP_server () ); 00135 } else return ( 0 ); 00136 } 00137 } 00138 00139 void Call_Box::set_msg_id ( const uint8_t msg_id ) { 00140 this->msg_id = ( msg_id > 0x10 ) ? msg_id : 0x11; 00141 } 00142 uint8_t Call_Box::get_msg_id ( void ) { return ( this->msg_id ); } 00143 00144 void Call_Box::set_timeslice ( const uint8_t timeslice ) { 00145 this->timeslice = timeslice; 00146 } 00147 00148 uint8_t Call_Box::get_timeslice ( void ) { return ( this->timeslice ); } 00149 00150 void Call_Box::send_bye ( void ) 00151 { 00152 if ( this -> sip == NULL ) 00153 { 00154 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this -> ext ); 00155 00156 deleted_sip ++; 00157 } else { 00158 sip -> send_bye (); 00159 } 00160 } 00161 00162 void Call_Box::set_sip_status ( const uint8_t new_sip_status ) 00163 { 00164 if ( this->sip not_eq NULL ) 00165 { 00166 this -> sip -> sip_set_status ( new_sip_status ); 00167 } else 00168 { 00169 if ( debug_cb) vz_debug ("[%d] Sip equals NULL o.O", this->ext ); 00170 deleted_sip++; 00171 vz_debug ("[%d] Sip equals NULL o.O", this->ext ); 00172 } 00173 } 00174 00175 void Call_Box::set_invite_response_ok ( void ) 00176 { 00177 this -> invite_response = true; 00178 if ( debug_invite ) vz_debug ("[%d] Invite response :: ok", this->ext ); 00179 } 00180 00181 void Call_Box::set_invite_response_pending ( void ) { this->invite_response = false; } 00182 00183 bool Call_Box::get_invite_response ( void ) { return ( this->invite_response ); } 00184 00185 void Call_Box::invite_retry_count_reset ( void ) { invite_retry_count = MAX_INVITE_RETRY; } 00186 00187 uint16_t Call_Box::get_invite_retry_count( void ){ 00188 return ( invite_retry_count ) ? invite_retry_count-- : 0; 00189 } 00190 00191 void Call_Box::set_bye_response_ok ( void ) { this->bye_response = true; } 00192 00193 int Call_Box::get_sip_socket_fd ( void ) { return ( sip_socket_fd ); } 00194 00195 int Call_Box::sip_udp_incomming_pkg ( void ) { 00196 return sip -> udp_incomming_pkg (); 00197 } 00198 00199 void Call_Box::reset_cb_status ( void ) { if ( sip not_eq NULL ) sip -> reset_call (); } 00200 00201 int Call_Box::get_sip_ext ( void ) { return this -> sip->get_ext (); } 00202 00203 int Call_Box::get_sip_port ( void ) { return this -> sip->get_port (); } 00204 00205 int Call_Box::get_timer ( void ) 00206 { 00207 int now = t.read (); 00208 00209 if ( now >= 1500 or now < 0 ) 00210 { 00211 this -> t.stop (); 00212 this -> t.reset (); 00213 this -> t.start (); 00214 overflow = true; 00215 if ( overflow_times not_eq 0xfe ) overflow_times++; 00216 } 00217 00218 return ( now ); 00219 } 00220 00221 int Call_Box::get_rtp_port ( void ) 00222 { 00223 if ( this -> sip not_eq NULL ) 00224 { 00225 return this -> sip -> get_sip_rtp_port (); 00226 } else { 00227 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00228 00229 deleted_sip++; 00230 00231 return -1; 00232 } 00233 } 00234 00235 void Call_Box::set_rtp_port ( const int new_rtp_port ) 00236 { 00237 if ( this->sip not_eq NULL ) 00238 { 00239 this->sip->set_sip_rtp_port( new_rtp_port ); 00240 }else{ 00241 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00242 00243 deleted_sip++; 00244 } 00245 } 00246 00247 void Call_Box::init_rtp_timer ( void ) 00248 { 00249 this -> rtp_timer.start (); 00250 } 00251 00252 void Call_Box::reset_rtp_timer ( void ) 00253 { 00254 this -> rtp_timer.stop (); 00255 this -> rtp_timer.reset (); 00256 } 00257 00258 bool Call_Box::is_rtp_timer_timeout ( void ) 00259 { 00260 return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; 00261 } 00262 00263 int Call_Box::print_yourself ( void ) 00264 { 00265 vz_printf ("\r\n"); 00266 vz_printf ("Values ::\r\n"); 00267 switch( status ) { 00268 case cb_idle : { 00269 vz_printf ("status :: cb_idle" ); 00270 break; 00271 } 00272 case cb_ringing : { 00273 vz_printf ("status :: cb_ringing" ); 00274 break; 00275 } 00276 case cb_trying : { 00277 vz_printf ("status :: cb_trying" ); 00278 break; 00279 } 00280 case cb_on_call : { 00281 vz_printf ("status :: cb_on_call" ); 00282 break; 00283 } 00284 case cb_busy : { 00285 vz_printf ("status :: cb_busy" ); 00286 break; 00287 } 00288 case cb_denied : { 00289 vz_printf ("status :: cb_denied" ); 00290 break; 00291 } 00292 } 00293 vz_printf ("ext :: %i", ext ); 00294 vz_printf ("port :: %i", port ); 00295 vz_printf ("Timer t :: %d", ( int )t.read () ); 00296 vz_printf ("overflow_times :: %u", overflow_times ); 00297 vz_printf ("msg_id :: %d", msg_id ); 00298 vz_printf ("timeslice :: %u", timeslice ); 00299 vz_printf ("next_aging_type :: %u", next_aging_type ); 00300 vz_printf ("invite_response :: %s", ( invite_response ) ? "true" : "false" ); 00301 vz_printf ("invite_retry_count :: %u", invite_retry_count ); 00302 vz_printf ("bye_response :: %s", ( bye_response ) ? "true" : "false" ); 00303 vz_printf ("sip_socket_fd :: %d", sip_socket_fd ); 00304 vz_printf ("\r\n"); 00305 00306 return ( sizeof( Call_Box ) ); 00307 } 00308 00309 int Call_Box::call_init ( const int timeslice ) 00310 { 00311 invite_timer.reset (); 00312 00313 invite_timer.start (); 00314 00315 this -> timeslice = timeslice; 00316 00317 this -> status = cb_ringing; 00318 00319 set_invite_response_pending (); 00320 00321 invite_try_number = 0; 00322 00323 msg_id_update (); 00324 00325 return 0; 00326 } 00327 00328 int 00329 Call_Box::call_end ( const bool send_bye_to_ast ) 00330 { 00331 uint8_t timeslice = this -> timeslice; 00332 00333 this -> timeslice = 0; 00334 00335 this -> status = cb_idle; 00336 00337 if ( sip not_eq NULL ) { 00338 sip -> sip_set_status ( sip_idle ); 00339 } else { 00340 if( debug_cb ) vz_debug ( "[%d] Sip equals NULL o.O", this -> ext ); 00341 } 00342 00343 set_rtp_port ( 0 ); 00344 00345 reset_rtp_timer (); 00346 00347 if ( send_bye_to_ast ) 00348 { 00349 if ( timeslice not_eq 0 ) send_bye (); 00350 } 00351 00352 reset_cb_status (); 00353 00354 invite_timer.stop (); 00355 00356 invite_timer.reset (); 00357 00358 invite_try_number = 0; 00359 00360 msg_id_update (); 00361 00362 reset_elapsed_time (); 00363 00364 if ( pair not_eq NULL ) pair -> reset_elapsed_time (); 00365 00366 return timeslice; 00367 } 00368 00369 Call_Box * Call_Box::get_pair_cbx ( void ) { return ( this -> pair ); } 00370 00371 int 00372 Call_Box::set_pair_cbx ( Call_Box * new_cbx ) 00373 { 00374 int ret = 0; 00375 00376 if ( new_cbx not_eq NULL ) 00377 { 00378 if ( pair not_eq NULL ) ret = -3; 00379 00380 else ret = 0; 00381 00382 pair = new_cbx; 00383 } else { 00384 ret = -1; 00385 } 00386 00387 return ( ret ); 00388 } 00389 00390 int Call_Box::call_confirmed ( void ) 00391 { 00392 set_invite_response_pending (); 00393 00394 this -> status = cb_on_call; 00395 00396 msg_id_update (); 00397 00398 return 0; 00399 } 00400 00401 uint8_t Call_Box::msg_id_update ( void ) 00402 { 00403 uint8_t update = ( msg_id + 1 ) bitand ( uint8_t ) compl BIT7; 00404 00405 this -> msg_id = ( update > 0x10 ) ? update : 0x11; 00406 00407 return this -> msg_id; 00408 } 00409 00410 void Call_Box::call_config ( void ) 00411 { 00412 set_invite_response_ok (); 00413 reset_rtp_timer (); 00414 init_rtp_timer (); 00415 } 00416 00417 bool Call_Box::time_to_retry ( void ) 00418 { 00419 if ( invite_timer.read_ms () > 1000 ) 00420 { 00421 invite_timer.reset (); 00422 return true; 00423 } else { 00424 return false; 00425 } 00426 } 00427 00428 uint8_t Call_Box::get_invite_try_number ( void ) {return invite_try_number; } 00429 00430 int Call_Box::retry_send_invite_pkg_to_ast ( void ) 00431 { 00432 if ( this -> sip not_eq NULL ) 00433 { 00434 invite_try_number++; 00435 return ( sip -> retry_send_last_invite_pkg_to_ast () ); 00436 } else { 00437 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00438 00439 deleted_sip++; 00440 00441 return ( 0 ); 00442 } 00443 } 00444 00445 int Call_Box::sip_print_yourself ( void ) 00446 { 00447 if ( this -> sip not_eq NULL ) 00448 { 00449 return sip -> print_yourself (); 00450 } else { 00451 vz_debug ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); 00452 00453 return ( -1 ); 00454 } 00455 00456 } 00457 00458 Sip * Call_Box::get_sip ( void ) { return this -> sip ; } 00459 00460 bool Call_Box::get_overflow_flag ( void ) { get_timer () ; return ( this -> overflow ); } 00461 00462 uint8_t Call_Box::get_overflow_times ( void ) { return ( this -> overflow_times ); } 00463 00464 void Call_Box::update_time ( void ){ get_timer (); } 00465 00466 uint16_t Call_Box::get_invite_counter ( void ) { return ( this -> invite_counter ); } 00467 00468 uint16_t Call_Box::update_invite_counter ( void ) { return ( this -> invite_counter++ ); } 00469 00470 int Call_Box::update ( void ) 00471 { 00472 shift_port = cm -> get_shift_port (); 00473 00474 if ( sip not_eq NULL ) 00475 { 00476 sip -> set_port ( ext + shift_port ); 00477 sip -> update (); 00478 } 00479 return ( 0 ); 00480 }
Generated on Tue Jul 12 2022 16:25:01 by
