Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
114:472502b31a12
Parent:
113:db67ae00550e
Child:
115:a1e1e2e60a2c
--- a/call_box.cpp	Thu Apr 16 12:57:13 2015 +0000
+++ b/call_box.cpp	Mon Apr 20 14:40:09 2015 +0000
@@ -9,34 +9,9 @@
     msg_id = 0x10;
     timeslice = 0x00;
     status = cb_idle;
-    
-    {
-        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 = new Sip( ext, port );
     sip_socket_fd = sip->get_socket_fd();
     if( sip == NULL )
-    
     {
         memory_is_over = true;
         if( debug_memory ) debug_msg("Sip allocation fail");
@@ -45,6 +20,7 @@
     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++;
@@ -97,8 +73,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");
@@ -118,8 +94,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");
@@ -139,8 +115,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;
@@ -168,9 +144,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, ext + shift_port );
-            deleted_sip++;
+            this->sip = new Sip( ext, port );
             
             if( sip == NULL ){
                 memory_is_over = true;
@@ -207,8 +183,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;
@@ -227,9 +203,17 @@
 }
 
 void Call_Box::reset_sip( void ){
-    if( this->sip != NULL ) delete( this->sip );
+    debug_msg("reset_sip");
     
-    this->sip = new Sip( ext, ext + shift_port );
+    if( this->sip != NULL )
+    {
+         delete( this->sip );
+         debug_msg("deletei");
+    }
+    
+    this->sip = new Sip( ext, port );
+    debug_msg( "sobrescrevi" );
+    
     deleted_sip++;
     
     if( sip == NULL ) memory_is_over = true;
@@ -241,7 +225,8 @@
     }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 ){
@@ -296,13 +281,7 @@
 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 )
-{ 
-    int now = t.read ();
-    if( now >= 9999 || now <= 0 ) t.reset ();
-    return t.read (); 
-}
+int Call_Box::get_timer( void ){ return t.read(); }
 
 int Call_Box::get_rtp_port ( void )
 {
@@ -311,6 +290,7 @@
     }else{
         if( debug_cb) debug_msg("Sip equals NULL o.O");
         deleted_sip++;
+        debug_msg("Sip equals NULL o.O");
         return -1;
     }
 }
@@ -319,33 +299,11 @@
 {
     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++;
-    } 
-}
-
-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 () );
+        debug_msg("Sip equals NULL o.O");
+    }
 }
 
 int Call_Box::print_yourself ( void )
@@ -394,4 +352,25 @@
     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