voltando a versao de n aberturas e fechamentos de sockets

Dependencies:   EthernetInterface NTPClient mbed-rtos_old mbed

Fork of header_main_public by VZTECH

Committer:
klauss
Date:
Mon Sep 15 20:55:48 2014 +0000
Revision:
10:22da1a0ac1e1
Parent:
8:e3bfe62a477e
Child:
12:07fd716e0f35
voltando a versao que abre e fecha n sockets, travando em momentos random

Who changed what in which revision?

UserRevisionLine numberNew contents of line
klauss 0:4d17cd9c8f9d 1 #include "call_box.h"
klauss 0:4d17cd9c8f9d 2
klauss 0:4d17cd9c8f9d 3 Call_Box::Call_Box( int ext, int port ){
klauss 0:4d17cd9c8f9d 4 this->ext = ext;
klauss 0:4d17cd9c8f9d 5 this->port = port;
klauss 0:4d17cd9c8f9d 6 t.start();
klauss 0:4d17cd9c8f9d 7 remaining_attempts = __MAX_ATTEMPTS__;
klauss 0:4d17cd9c8f9d 8 timeout = __TIMEOUT__;
klauss 0:4d17cd9c8f9d 9 //sip.set_ext( this->ext );
klauss 0:4d17cd9c8f9d 10 //sip.set_port( this->port );
klauss 4:de46f0d9b14d 11 msg_id = 0x10;
klauss 0:4d17cd9c8f9d 12 timeslice = 0x00;
klauss 0:4d17cd9c8f9d 13 status = cb_idle;
klauss 0:4d17cd9c8f9d 14 //Sip sip( ext, port );
klauss 10:22da1a0ac1e1 15 sip = NULL;
klauss 10:22da1a0ac1e1 16 //sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 17 }
klauss 0:4d17cd9c8f9d 18
klauss 0:4d17cd9c8f9d 19 Call_Box::~Call_Box( void ){
klauss 0:4d17cd9c8f9d 20 if( sip != NULL ) delete( sip );
klauss 0:4d17cd9c8f9d 21 }
klauss 0:4d17cd9c8f9d 22
klauss 0:4d17cd9c8f9d 23 int Call_Box::get_port( void ){ return( this->port ); }
klauss 0:4d17cd9c8f9d 24 int Call_Box::get_ext( void ){ return( this->ext ); }
klauss 0:4d17cd9c8f9d 25
klauss 0:4d17cd9c8f9d 26 float Call_Box::get_elapsed_time( void ){ return( this->t.read_ms() ); }
klauss 0:4d17cd9c8f9d 27
klauss 0:4d17cd9c8f9d 28 void Call_Box::reset_elapsed_time( void ){
klauss 0:4d17cd9c8f9d 29 this->t.reset();
klauss 0:4d17cd9c8f9d 30 remaining_attempts = __MAX_ATTEMPTS__;
klauss 3:cd9148672e25 31 // timeout = __TIMEOUT__;
klauss 0:4d17cd9c8f9d 32 }
klauss 0:4d17cd9c8f9d 33
klauss 0:4d17cd9c8f9d 34 bool Call_Box::is_timeout( void ){
klauss 0:4d17cd9c8f9d 35 return( t.read() > timeout ) ? true : false;
klauss 0:4d17cd9c8f9d 36 }
klauss 0:4d17cd9c8f9d 37
klauss 0:4d17cd9c8f9d 38 uint8_t Call_Box::reconfigure_timeout( void ){
klauss 3:cd9148672e25 39 //static int count = 1;
klauss 3:cd9148672e25 40 //if( timeout != __MAX_TIMEOUT__ ) timeout = __STEP__ * count++;
klauss 0:4d17cd9c8f9d 41 t.reset();
klauss 0:4d17cd9c8f9d 42 return( remaining_attempts-- );
klauss 0:4d17cd9c8f9d 43 }
klauss 0:4d17cd9c8f9d 44
klauss 0:4d17cd9c8f9d 45 void Call_Box::registry( void ){
klauss 0:4d17cd9c8f9d 46 if( this->sip == NULL ){
klauss 0:4d17cd9c8f9d 47 this->sip = new Sip( ext, port );
klauss 4:de46f0d9b14d 48 debug_msg(" Registrando %d", ext );
klauss 0:4d17cd9c8f9d 49
klauss 0:4d17cd9c8f9d 50 sip->registry();
klauss 0:4d17cd9c8f9d 51
klauss 0:4d17cd9c8f9d 52 delete( sip );
klauss 0:4d17cd9c8f9d 53 this->sip = NULL;
klauss 0:4d17cd9c8f9d 54 }else{
klauss 4:de46f0d9b14d 55 debug_msg(" Registrando %d", ext )
klauss 0:4d17cd9c8f9d 56 sip->registry();
klauss 0:4d17cd9c8f9d 57 }
klauss 0:4d17cd9c8f9d 58 }
klauss 0:4d17cd9c8f9d 59
klauss 0:4d17cd9c8f9d 60 void Call_Box::unregistry( void ){
klauss 0:4d17cd9c8f9d 61 if( this->sip == NULL ){
klauss 0:4d17cd9c8f9d 62 this->sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 63
klauss 0:4d17cd9c8f9d 64 sip->send_unregistry_pkg();
klauss 0:4d17cd9c8f9d 65
klauss 0:4d17cd9c8f9d 66 delete( sip );
klauss 0:4d17cd9c8f9d 67 this->sip = NULL;
klauss 0:4d17cd9c8f9d 68 }else{
klauss 0:4d17cd9c8f9d 69 sip->send_unregistry_pkg();
klauss 0:4d17cd9c8f9d 70 }
klauss 0:4d17cd9c8f9d 71 }
klauss 0:4d17cd9c8f9d 72
klauss 0:4d17cd9c8f9d 73 VZ_call * Call_Box::invite( void ){
klauss 0:4d17cd9c8f9d 74 if( this->sip == NULL ){
klauss 0:4d17cd9c8f9d 75 debug_msg("entrei no invite");
klauss 0:4d17cd9c8f9d 76 this->sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 77
klauss 0:4d17cd9c8f9d 78 VZ_call * call = sip->invite();
klauss 0:4d17cd9c8f9d 79
klauss 10:22da1a0ac1e1 80 //delete( sip );
klauss 10:22da1a0ac1e1 81 //this->sip = NULL;
klauss 10:22da1a0ac1e1 82 debug_msg("nao metei o socket");
klauss 0:4d17cd9c8f9d 83 debug_msg("Valor do retorno do invite :: %p ", call );
klauss 0:4d17cd9c8f9d 84 return( call );
klauss 0:4d17cd9c8f9d 85 }else{
klauss 0:4d17cd9c8f9d 86 debug_msg("entrei no invite persistente");
klauss 0:4d17cd9c8f9d 87
klauss 0:4d17cd9c8f9d 88 VZ_call * call = sip->invite();
klauss 0:4d17cd9c8f9d 89
klauss 0:4d17cd9c8f9d 90 debug_msg("Valor do retorno do invite persistente :: %p ", call );
klauss 0:4d17cd9c8f9d 91 return( call );
klauss 0:4d17cd9c8f9d 92 }
klauss 0:4d17cd9c8f9d 93 }
klauss 0:4d17cd9c8f9d 94
klauss 0:4d17cd9c8f9d 95 /* Retorna
klauss 0:4d17cd9c8f9d 96 = 0 :: ok
klauss 0:4d17cd9c8f9d 97 < 0 :: tive problemas
klauss 0:4d17cd9c8f9d 98 > 0 :: devo remover essa call do vetor de calls
klauss 0:4d17cd9c8f9d 99 */
klauss 0:4d17cd9c8f9d 100 int Call_Box::listen_SIP_server( void ){
klauss 0:4d17cd9c8f9d 101 if( this->sip == NULL ){
klauss 0:4d17cd9c8f9d 102 if( status == cb_on_call || status == cb_idle ){
klauss 0:4d17cd9c8f9d 103 this->sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 104 int out_read = sip->listen_SIP_server();
klauss 0:4d17cd9c8f9d 105 delete( sip );
klauss 0:4d17cd9c8f9d 106 this->sip = NULL;
klauss 0:4d17cd9c8f9d 107 return( out_read );
klauss 0:4d17cd9c8f9d 108 }else return( 0 );
klauss 0:4d17cd9c8f9d 109 }else{
klauss 0:4d17cd9c8f9d 110 if( status == cb_on_call || status == cb_idle ){
klauss 10:22da1a0ac1e1 111 //return ( sip->listen_SIP_server() );
klauss 10:22da1a0ac1e1 112 int out_read = sip->listen_SIP_server();
klauss 10:22da1a0ac1e1 113 if( out_read > 0 ){
klauss 10:22da1a0ac1e1 114 delete( sip );
klauss 10:22da1a0ac1e1 115 this->sip = NULL;
klauss 10:22da1a0ac1e1 116 }
klauss 10:22da1a0ac1e1 117 return( out_read );
klauss 10:22da1a0ac1e1 118 }else return( 0 );
klauss 0:4d17cd9c8f9d 119 }
klauss 0:4d17cd9c8f9d 120 }
klauss 0:4d17cd9c8f9d 121
klauss 0:4d17cd9c8f9d 122 void Call_Box::set_msg_id( uint8_t msg_id ){
klauss 0:4d17cd9c8f9d 123 this->msg_id = msg_id;
klauss 0:4d17cd9c8f9d 124 }
klauss 0:4d17cd9c8f9d 125 uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); }
klauss 0:4d17cd9c8f9d 126
klauss 0:4d17cd9c8f9d 127 void Call_Box::set_timeslice( uint8_t timeslice ){
klauss 0:4d17cd9c8f9d 128 this->timeslice = timeslice;
klauss 0:4d17cd9c8f9d 129 }
klauss 0:4d17cd9c8f9d 130 uint8_t Call_Box::get_timeslice( void ){ return( this->timeslice ); }
klauss 0:4d17cd9c8f9d 131
klauss 0:4d17cd9c8f9d 132 //void Call_Box::set_sip( Sip * sip ){
klauss 0:4d17cd9c8f9d 133 // this->sip = sip;
klauss 0:4d17cd9c8f9d 134 //}
klauss 0:4d17cd9c8f9d 135
klauss 0:4d17cd9c8f9d 136 void Call_Box::send_bye( void ){
klauss 10:22da1a0ac1e1 137 debug_msg("");
klauss 0:4d17cd9c8f9d 138 if( this->sip == NULL ){
klauss 0:4d17cd9c8f9d 139 this->sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 140
klauss 0:4d17cd9c8f9d 141 sip->send_bye();
klauss 10:22da1a0ac1e1 142 debug_msg("");
klauss 10:22da1a0ac1e1 143 delete( sip );
klauss 0:4d17cd9c8f9d 144 sip = NULL;
klauss 0:4d17cd9c8f9d 145 }else{
klauss 0:4d17cd9c8f9d 146 sip->send_bye();
klauss 10:22da1a0ac1e1 147 debug_msg("");
klauss 0:4d17cd9c8f9d 148 }
klauss 1:a1758104fa1d 149 }
klauss 1:a1758104fa1d 150
klauss 1:a1758104fa1d 151 void Call_Box::reset_sip( void ){
klauss 1:a1758104fa1d 152 if( this->sip != NULL ) delete( this->sip );
klauss 1:a1758104fa1d 153
klauss 1:a1758104fa1d 154 this->sip = new Sip( ext, port );
klauss 0:4d17cd9c8f9d 155 }