VZTECH / Mbed 2 deprecated header_main

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers call_box.cpp Source File

call_box.cpp

00001 #include "call_box.h"
00002 
00003 Call_Box::Call_Box( int ext, int port ){
00004     this->ext = ext;
00005     this->port = port;
00006     t.start();
00007     remaining_attempts = __MAX_ATTEMPTS__;
00008     timeout = __TIMEOUT__;
00009     //sip.set_ext( this->ext );
00010     //sip.set_port( this->port );
00011     msg_id = 0x00;
00012     timeslice = 0x00;
00013     status = cb_idle;
00014     //Sip sip( ext, port );
00015     //sip = NULL;
00016     sip = new Sip( ext, port );
00017 }
00018 
00019 Call_Box::~Call_Box( void ){
00020     if( sip != NULL ) delete( sip );   
00021 }
00022 
00023 int Call_Box::get_port( void ){ return( this->port ); }
00024 int Call_Box::get_ext( void ){ return( this->ext ); }
00025 
00026 float Call_Box::get_elapsed_time( void ){ return( this->t.read_ms() ); }
00027 
00028 void Call_Box::reset_elapsed_time( void ){ 
00029     this->t.reset(); 
00030     remaining_attempts = __MAX_ATTEMPTS__;
00031     timeout = __TIMEOUT__;
00032 }
00033 
00034 bool Call_Box::is_timeout( void ){
00035     return( t.read() > timeout ) ? true : false;    
00036 }
00037 
00038 uint8_t Call_Box::reconfigure_timeout( void ){
00039     static int count = 1;
00040     if( timeout != __MAX_TIMEOUT__ ) timeout = __STEP__  * count++;
00041     t.reset();
00042     return( remaining_attempts-- );
00043 }
00044 
00045 void Call_Box::registry( void ){
00046     if( this->sip == NULL ){
00047         this->sip = new Sip( ext, port );
00048     
00049         sip->registry();
00050     
00051         delete( sip );
00052         this->sip = NULL;
00053     }else{
00054         sip->registry();
00055     }
00056 }
00057 
00058 void Call_Box::unregistry( void ){
00059     if( this->sip == NULL ){ 
00060         this->sip = new Sip( ext, port );
00061     
00062         sip->send_unregistry_pkg();
00063     
00064         delete( sip );
00065         this->sip = NULL;
00066     }else{
00067         sip->send_unregistry_pkg();
00068     }
00069 }
00070 
00071 VZ_call * Call_Box::invite( void ){
00072     if( this->sip == NULL ){
00073         debug_msg("entrei no invite");
00074         this->sip = new Sip( ext, port );
00075         
00076         VZ_call * call = sip->invite();
00077         
00078         delete( sip );
00079         this->sip = NULL;
00080         
00081         debug_msg("Valor do retorno do invite :: %p ", call );        
00082         return( call );
00083     }else{
00084         debug_msg("entrei no invite persistente");
00085         
00086         VZ_call * call = sip->invite();
00087         
00088         debug_msg("Valor do retorno do invite persistente :: %p ", call );        
00089         return( call );
00090     }
00091 }
00092 
00093 /*  Retorna 
00094     = 0 :: ok
00095     < 0 :: tive problemas
00096     > 0 :: devo remover essa call do vetor de calls 
00097 */
00098 int Call_Box::listen_SIP_server( void ){
00099     if( this->sip == NULL ){
00100         if( status == cb_on_call || status == cb_idle ){
00101             this->sip = new Sip( ext, port );
00102             int out_read = sip->listen_SIP_server();
00103             delete( sip );
00104             this->sip = NULL;
00105             return( out_read );
00106         }else return( 0 );
00107     }else{
00108         if( status == cb_on_call || status == cb_idle ){
00109             return ( sip->listen_SIP_server() );
00110         } else return( 0 );
00111     }
00112 }
00113 
00114 void Call_Box::set_msg_id( uint8_t msg_id ){
00115     this->msg_id = msg_id;
00116 }
00117 uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); }
00118 
00119 void Call_Box::set_timeslice( uint8_t timeslice ){
00120     this->timeslice = timeslice;
00121 }
00122 uint8_t Call_Box::get_timeslice( void ){ return( this->timeslice ); }
00123 
00124 //void Call_Box::set_sip( Sip * sip ){
00125 //    this->sip = sip;    
00126 //}
00127 
00128 void Call_Box::send_bye( void ){ 
00129     if( this->sip == NULL ){
00130         this->sip = new Sip( ext, port );
00131         
00132         sip->send_bye();
00133         
00134         delete( sip );
00135         
00136         sip = NULL;
00137     }else{
00138         sip->send_bye();
00139     }
00140 }
00141 
00142 void Call_Box::reset_sip( void ){
00143     if( this->sip != NULL ) delete( this->sip );
00144     
00145     this->sip = new Sip( ext, port );
00146 }