Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
109:a5b8264ffbbc
Parent:
108:18a3702650f3
Child:
112:6ae726539ab9
--- a/call_box.cpp	Wed Mar 18 13:33:54 2015 +0000
+++ b/call_box.cpp	Tue Apr 07 14:27:44 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;
@@ -240,7 +224,9 @@
         this->sip->status = status;
     }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 ){
@@ -304,6 +290,8 @@
         return this->sip->get_sip_rtp_port();
     }else{
         if( debug_cb) debug_msg("Sip equals NULL o.O");
+        deleted_sip++;
+        debug_msg("Sip equals NULL o.O");
         return -1;
     }
 }
@@ -312,26 +300,57 @@
 {
     if( this->sip != NULL ){
         this->sip->set_sip_rtp_port( new_rtp_port );
+    }else{
+        if( debug_cb) debug_msg("Sip equals NULL o.O");
+        deleted_sip++;
+        debug_msg("Sip equals NULL o.O");
     }
 }
 
-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 () );
+int Call_Box::print_yourself ( void )
+{   
+    send_msg ("");
+    send_msg ("Values ::\r\n");
+    switch( status ) {
+        case cb_idle : {
+            send_msg ("status :: cb_idle" );
+            break;
+        }
+        case cb_ringing : {
+            send_msg ("status :: cb_ringing" );
+            break;
+        }
+        case cb_trying : {
+            send_msg ("status :: cb_trying" );
+            break;
+        }
+        case cb_on_call : {
+            send_msg ("status :: cb_on_call" );
+            break;
+        }
+        case cb_busy : {
+            send_msg ("status :: cb_busy" );
+            break;
+        }
+        case cb_denied : {
+            send_msg ("status :: cb_denied" );
+            break;
+        }
+    }
+    send_msg ("ext :: %i", ext );
+    send_msg ("port :: %i", port );
+    send_msg ("Timer t :: %d", ( int )t.read () );
+    send_msg ("remaining_attempts :: %u", remaining_attempts );
+    send_msg ("timeout :: %f", timeout );
+    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 ("seconds :: %d", ( int )seconds.read () );
+    send_msg ("sip_socket_fd :: %d", sip_socket_fd );
+    send_msg ("");
+    
+    return ( sizeof( Call_Box ) );
 }
\ No newline at end of file