![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
call_box_manager.cpp
- Committer:
- klauss
- Date:
- 2015-05-20
- Revision:
- 126:1f90756250fb
- Parent:
- 124:c1b6c893e1c3
- Child:
- 132:05cd37f7e007
File content as of revision 126:1f90756250fb:
#include "call_box_manager.h" Timer timer_refresh; Timer timer_aging; Timer timer_sync_refresh; Call_Box * find_CB ( Vector * v_cb, const int ext ) { Call_Box * cb = NULL; for ( register int i = 0; i < v_cb -> size (); i++ ) { cb = ( Call_Box * ) v_cb -> get_element ( i ); if ( cb not_eq NULL ) { if ( cb -> get_ext () == ext ) return ( cb ); } } return ( NULL ); } int refresh ( Vector * v_cb ) { if ( v_cb not_eq NULL) { static int lst_index = 0; if ( v_cb -> size () > 0 ) { //FIXME pode acontecder problemas por ser static static uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ]; led4 = 0; if ( lst_index >= v_cb -> size () ) lst_index = 0; Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( lst_index++ ); if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) { if ( cb -> get_ext () % 2 == 1 ) { Call_Box * cb_master = find_CB ( v_cb, cb -> get_ext () - 1 ); if ( ( cb_master not_eq NULL ) and ( cb_master -> get_status () not_eq cb_idle ) ) return ( 0x20 ); } else { // checking slave status Call_Box * cb_slave = find_CB ( v_cb, cb -> get_ext () + 1 ); if ( ( cb_slave not_eq NULL ) and ( cb_slave -> get_status () not_eq cb_idle ) ) return ( 0x21 ); } send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), REGISTRY, ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_refresh ) send_msg("[%d] Refresh", cb->get_ext() ); return( 0 ); }else return( -5 ); }else return( -3 ); }else return( -1 ); } void wake_all_up ( Vector * v_cb ) { /*** [ Principio ] -- Procurar por CBx que constem sem seus pares registrados na lógica. -- Mandar uma mensagem do tipo prompt-ping para este elemento -- Fluxo -- - Verificar se possui uma lista ordenada de CBx atualizada - Caso nao possua, gerar esta lista. - Para cada iteraçao - Verifica se o CBx é master ou slave - Verifica se o par deste esta registrado - Caso contratio - Verifica se o CBx encontrado esta em ligaçao - Caso nao esteja, encaminha mensagem de ping para o CBx ausente da dupla. ***/ uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; if( ( v_cb not_eq NULL ) ) { static int ext_list[ MAX_CB_IN_A_BRANCH + 1 ]; static uint8_t last_size = 0; uint8_t size = v_cb->size(); static int wake_all_up_index = 0; if( last_size not_eq size ) { for( register int i = 0; i < size; i++ ){ ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); } qsort( ext_list, v_cb->size(), sizeof( int ), wake_comp ); } if( size > 0 ) { // testa se eh o master if( ( ext_list[ wake_all_up_index ] % 2 ) == 0 ) { //testa se o slave nao esta registrado if( ( size == 1 ) or ( ( wake_all_up_index + 1 ) == size ) or ( ( ext_list[ wake_all_up_index + 1 ] not_eq ( ext_list[ wake_all_up_index ] + 1 ) ) ) ) { strcpy( ( char * )data, "ping\r" ); Call_Box * cb = find_CB( v_cb, ext_list[ wake_all_up_index ] ); // verifica se o master esta em chamada. if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) { send2callboxes( build_cb_package( ( cb->get_ext() + 1 ), ( cb->get_port() + 1 ), PROMPT, ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_wake ) send_msg("%d without %d - ping sent to %d", ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] + 1, cb->get_ext() + 1 ); } } }else{ if( ( size == 1 ) or ( wake_all_up_index == 0 ) or ( wake_all_up_index >= 1 ) and ( ( ext_list[ wake_all_up_index - 1 ] not_eq ( ext_list[ wake_all_up_index ] - 1 ) ) ) ) { strcpy( ( char * )data, "ping\r" ); Call_Box * cb = find_CB( v_cb, ( ext_list[ wake_all_up_index ] ) ); // verifica se o slave esta em chamada. if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) { send2callboxes( build_cb_package( ( cb->get_ext() - 1 ), ( cb->get_port() - 1 ), PROMPT, ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if ( debug_wake ) send_msg ("%d without %d - ping sent to %d", ext_list [ wake_all_up_index ], ext_list [ wake_all_up_index ] - 1, cb -> get_ext () - 1 ); } } } } if ( ++wake_all_up_index >= size ) wake_all_up_index = 0; } }