Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
126:1f90756250fb
Parent:
125:8ff4dc96ad58
Child:
132:05cd37f7e007
--- a/call_manager.cpp	Wed May 13 21:18:12 2015 +0000
+++ b/call_manager.cpp	Wed May 20 19:50:31 2015 +0000
@@ -43,7 +43,7 @@
     }
 }
 
-VZ_call * __find_Call__( Vector * v_call, int ext ){
+VZ_call * find_Call ( Vector * v_call, const int ext ){
     VZ_call * call = NULL;
     for( register int i = 0; i < v_call->size(); i++ ){
         call = ( VZ_call * )v_call->get_element( i );
@@ -112,136 +112,154 @@
     }
 }
 
-void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){
-    if ( ( v_call != NULL ) && ( v_cb != NULL ) && ( ts != NULL ) )
+void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb )
+{
+    
+    if ( ( v_call != NULL ) and ( v_cb != NULL ) and ( ts != NULL ) )
     {
-        uint8_t data[ CB_BUFFER_SIZE ];
-        uint8_t write_buffer[ CB_BUFFER_SIZE ];
+        uint8_t data [ CB_BUFFER_SIZE ];
+        uint8_t write_buffer [ CB_BUFFER_SIZE ];
     
-        if( inviting_cb != NULL ){
-            if( inviting_cb -> get_status () == cb_idle ){            
-                inviting_cb->cb_set_status( cb_trying );
-                if( debug_invite ) debug_msg("[%d] Request invite <cb_idle,cb_trying>", inviting_cb->get_ext ()  );
+        if ( inviting_cb != NULL )
+        {
+            if ( inviting_cb -> get_status () == cb_idle )
+            {
+                inviting_cb -> cb_set_status ( cb_trying );
+                if ( debug_invite ) debug_msg ("[%d] Request invite <cb_idle,cb_trying>", inviting_cb->get_ext ()  );
             }
         }
         
-        for( register uint8_t i = 0; i < v_cb->size(); i++ )
+        for ( register uint8_t i = 0; i < v_cb->size (); i++ )
         {
-            Call_Box * cb = ( Call_Box * )v_cb->get_element( i );
+            Call_Box * cb = ( Call_Box * ) v_cb->get_element ( i );
             
             if ( cb == NULL ) continue;
             
-            if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue;
+            if ( ( cb -> get_status () == cb_idle ) or ( cb -> get_status () == cb_on_call ) ) continue;
             
-            int ext = cb->get_ext();
-            int port = cb->get_port();
+            int ext = cb->get_ext ();
+            int port = cb->get_port ();
             
             VZ_call * call = NULL;
     
-            switch( cb -> get_status () )
+            switch ( cb -> get_status () )
             {            
                 case cb_trying : {                
-                    uint8_t timeslice = ts->get_timeslice ();
+                    uint8_t timeslice = ts -> get_timeslice ();
                     
-                    if( timeslice == 0 ){
+                    if ( timeslice == 0 )
+                    {
                         
-                        data[ TIMESLICE_PLACE ] = 0x00;
+                        data [ TIMESLICE_PLACE ] = 0x00;
           
-                        send2callboxes( build_cb_package( ext, port, INVITE, 
-                            ( char * )data, ( cb->get_msg_id() | BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
+                        // validar troca de mensagens com nros "nao previstos"
+                        send2callboxes ( build_cb_package ( ext, port, INVITE, 
+                            ( char * )data, ( cb->get_msg_id () | BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                          
-                        cb->call_end ();
+                        cb -> call_end ();
                          
-                        if( debug_invite ) debug_msg( "[%d] Trying without TS <cb_trying,cb_idle>", ext );
+                        if ( debug_invite ) debug_msg ( "[%d] Trying without TS <cb_trying,cb_idle>", ext );
                         
                         return;
-                    }else{
+                    }
+                        else
+                    {
                         
-                        data[ TIMESLICE_PLACE ] = timeslice;
+                        data [ TIMESLICE_PLACE ] = timeslice;
                         
-                        cb->call_init ( timeslice );
-                            
+                        cb -> call_init ( timeslice );
+                        
+                        // validar troca de mensagens com nros "nao previstos"    
                         send2callboxes( build_cb_package( ext, port, INVITE, 
-                            ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
+                            ( char * )data, cb->get_msg_id (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                         
-                        if( debug_invite ) debug_msg("[%d] TS::%d <cb_trying,cb_ringing>", ext, data[ TIMESLICE_PLACE ] );
+                        if ( debug_invite ) debug_msg("[%d] TS::%d <cb_trying,cb_ringing>", ext, data [ TIMESLICE_PLACE ] );
                     }
                 }break;
                 case cb_ringing : {
-                    call = cb->invite();
+                    call = cb -> invite ();
                     
-                    if( cb->get_sip_status() == sip_busy ){
+                    if ( cb -> get_sip_status () == sip_busy ){
                         cb->cb_set_status( cb_busy );
-                    }else if( call != NULL ){
-                        if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call );
+                    } 
+                        else if ( call != NULL )
+                    {
+                        if ( find_Call ( v_call, call -> get_cb_ext () ) == NULL ) v_call -> add ( call );
                         
-                        call->init_cbx_pkg_idle_timer();
+                        call -> init_cbx_pkg_idle_timer ();
                         
-                        if( cb->get_sip_status() == sip_on_call ){
+                        if ( cb -> get_sip_status () == sip_on_call )
+                        {
                         
-                            data[ TIMESLICE_PLACE ] = cb->get_timeslice();  
+                            data [ TIMESLICE_PLACE ] = cb -> get_timeslice ();  
                             
-                            send2callboxes( build_cb_package( ext, port, INVITE, ( char * )data, 
+                            // confirmar a msg_id se sempre é bem aceita pelo cbx
+                            send2callboxes ( build_cb_package( ext, port, INVITE, ( char * )data, 
                                 cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                             
-                            cb->call_confirmed ();    
+                            cb -> call_confirmed ();    
                     
-                            if( debug_invite ) debug_msg( "[%d] Ringing call ok <cb_ringing,cb_on_call>", ext );
+                            if ( debug_invite ) debug_msg( "[%d] Ringing call ok <cb_ringing,cb_on_call>", ext );
                         }
-                    }else{
-                        if( cb->get_sip_status() == sip_denied )
+                    } else {
+                        if ( cb -> get_sip_status () == sip_denied )
                         {
-                            cb->cb_set_status( cb_denied );
-                            if( debug_invite ) debug_msg( "[%d] call denied <sip_denied>::<cb_ringing,cb_denied>", ext );
+                            cb -> cb_set_status ( cb_denied );
+                            if ( debug_invite ) debug_msg ( "[%d] call denied <sip_denied>::<cb_ringing,cb_denied>", ext );
                         } else {
-                            if ( cb->time_to_retry () )
+                            if ( cb -> time_to_retry () )
                             {                                
                                 if ( cb -> get_sip_status () == sip_waiting_trying )
                                 {
                                     if ( debug_invite ) debug_msg ("[%4i %3i] Resend invite to *", ext, cb -> get_invite_try_number ()  );
-                                    cb->retry_send_invite_pkg_to_ast ();    
+                                    cb -> retry_send_invite_pkg_to_ast ();    
                                 }
                             }    
                         }
                     }
                 }break;
                 case cb_busy : {
-                    data[ TIMESLICE_PLACE ] = 0;
+                    data [ TIMESLICE_PLACE ] = 0;
                     
-                    send2callboxes( build_cb_package( ext, port, CB_BYE, 
+                    send2callboxes ( build_cb_package( ext, port, CB_BYE, 
                         ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                     
-                    for( register uint8_t i = 0; i < v_call->size(); i++ ){
-                        VZ_call * call = ( VZ_call * )v_call->get_element( i );
-                        if( call->get_cb_ext() == cb->get_ext() ){ 
-                            v_call->remove_element( i );
-                            if( call != NULL ) delete( call );
+                    for ( register uint8_t i = 0; i < v_call -> size (); i++ )
+                    {
+                        VZ_call * call = ( VZ_call * ) v_call->get_element ( i );
+    
+                        if ( call -> get_cb_ext () == cb -> get_ext () )
+                        { 
+                            v_call -> remove_element ( i );
+                            if ( call != NULL ) delete ( call );
                             break;
                         }
                     }
                         
-                    ts->return_timeslice( cb->call_end () );
+                    ts -> return_timeslice ( cb -> call_end () );
                     
-                    if( debug_invite ) debug_msg( "[%d] Busy Here <cb_busy,cb_idle>", ext );
+                    if ( debug_invite ) debug_msg( "[%d] Busy Here <cb_busy,cb_idle>", ext );
                 }break;
                 
                 case cb_denied : {
-                    data[ TIMESLICE_PLACE ] = 0;
+                    data [ TIMESLICE_PLACE ] = 0;
                     
-                    send2callboxes( build_cb_package( ext, port, CB_BYE, 
+                    send2callboxes ( build_cb_package( ext, port, CB_BYE, 
                         ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                         
-                    for( register uint8_t i = 0; i < v_call->size(); i++ ){
-                        VZ_call * call = ( VZ_call * )v_call->get_element( i );
-                        if( call->get_cb_ext() == cb->get_ext() ){ 
-                            v_call->remove_element( i );
-                            if( call != NULL ) delete( call );
+                    for ( register uint8_t i = 0; i < v_call -> size (); i++ )
+                    {
+                        VZ_call * call = ( VZ_call * ) v_call->get_element ( i );
+                        if ( call -> get_cb_ext () == cb->get_ext () )
+                        {
+                            v_call -> remove_element( i );
+                            if ( call != NULL ) delete ( call );
                             break;
                         }
                     }
-                    ts->return_timeslice( cb->call_end () );
+                    ts -> return_timeslice ( cb -> call_end () );
     
-                    if( debug_invite ) debug_msg( "[%d] call denied <cb_denied,cb_idle>", ext );
+                    if ( debug_invite ) debug_msg ( "[%d] call denied <cb_denied,cb_idle>", ext );
                 }break;
             }
         }