![](/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_manager.cpp@124:c1b6c893e1c3, 2015-05-13 (annotated)
- Committer:
- klauss
- Date:
- Wed May 13 14:25:57 2015 +0000
- Revision:
- 124:c1b6c893e1c3
- Parent:
- 122:480c44b0e205
- Child:
- 125:8ff4dc96ad58
wip__
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 122:480c44b0e205 | 1 | #include "call_manager.h" |
klauss | 74:81c47fff88a5 | 2 | |
klauss | 81:3656f00ab3db | 3 | Timer invite_pkg_retry_timer; |
klauss | 81:3656f00ab3db | 4 | Timer bye_pkg_retry_timer; |
klauss | 81:3656f00ab3db | 5 | |
klauss | 81:3656f00ab3db | 6 | void init_invite_pgk_retry_manager( void ){ |
klauss | 81:3656f00ab3db | 7 | invite_pkg_retry_timer.start(); |
klauss | 81:3656f00ab3db | 8 | } |
klauss | 81:3656f00ab3db | 9 | |
klauss | 81:3656f00ab3db | 10 | void init_bye_pgk_retry_manager( void ){ |
klauss | 81:3656f00ab3db | 11 | bye_pkg_retry_timer.start(); |
klauss | 81:3656f00ab3db | 12 | } |
klauss | 81:3656f00ab3db | 13 | |
klauss | 81:3656f00ab3db | 14 | void invite_pgk_retry_manager( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ |
klauss | 81:3656f00ab3db | 15 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 81:3656f00ab3db | 16 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 81:3656f00ab3db | 17 | if( cb->get_status() == cb_on_call ){ |
klauss | 81:3656f00ab3db | 18 | if( cb->get_invite_response() == false ){ |
klauss | 81:3656f00ab3db | 19 | invite_pkg_retry_timer.reset(); |
klauss | 81:3656f00ab3db | 20 | |
klauss | 119:ee6a53069455 | 21 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), INVITE, ( char * )data, |
klauss | 119:ee6a53069455 | 22 | cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 81:3656f00ab3db | 23 | |
klauss | 81:3656f00ab3db | 24 | return; |
klauss | 81:3656f00ab3db | 25 | } |
klauss | 81:3656f00ab3db | 26 | } |
klauss | 81:3656f00ab3db | 27 | } |
klauss | 81:3656f00ab3db | 28 | } |
klauss | 81:3656f00ab3db | 29 | |
klauss | 81:3656f00ab3db | 30 | void bye_pgk_retry_manager( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ |
klauss | 81:3656f00ab3db | 31 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 81:3656f00ab3db | 32 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 81:3656f00ab3db | 33 | if( cb->get_status() == cb_idle ){ |
klauss | 81:3656f00ab3db | 34 | if( cb->get_bye_response() == false ){ |
klauss | 81:3656f00ab3db | 35 | bye_pkg_retry_timer.reset(); |
klauss | 81:3656f00ab3db | 36 | |
klauss | 119:ee6a53069455 | 37 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), CB_BYE, ( char * )data, |
klauss | 119:ee6a53069455 | 38 | cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 81:3656f00ab3db | 39 | |
klauss | 81:3656f00ab3db | 40 | return; |
klauss | 81:3656f00ab3db | 41 | } |
klauss | 81:3656f00ab3db | 42 | } |
klauss | 81:3656f00ab3db | 43 | } |
klauss | 81:3656f00ab3db | 44 | } |
klauss | 78:1353744f01e1 | 45 | |
klauss | 74:81c47fff88a5 | 46 | VZ_call * __find_Call__( Vector * v_call, int ext ){ |
klauss | 74:81c47fff88a5 | 47 | VZ_call * call = NULL; |
klauss | 74:81c47fff88a5 | 48 | for( register int i = 0; i < v_call->size(); i++ ){ |
klauss | 74:81c47fff88a5 | 49 | call = ( VZ_call * )v_call->get_element( i ); |
klauss | 119:ee6a53069455 | 50 | if ( call != NULL ) |
klauss | 119:ee6a53069455 | 51 | { |
klauss | 119:ee6a53069455 | 52 | if( call->get_cb_ext() == ext ) return( call ); |
klauss | 119:ee6a53069455 | 53 | } |
klauss | 74:81c47fff88a5 | 54 | } |
klauss | 74:81c47fff88a5 | 55 | return( NULL ); |
klauss | 74:81c47fff88a5 | 56 | } |
klauss | 74:81c47fff88a5 | 57 | |
klauss | 74:81c47fff88a5 | 58 | /* remove calls por timeout */ |
klauss | 119:ee6a53069455 | 59 | void call_manager( Vector * v_call, Vector * v_cb, Timeslice * ts ) |
klauss | 119:ee6a53069455 | 60 | { |
klauss | 119:ee6a53069455 | 61 | //FixME pode dar problema por conta do static |
klauss | 119:ee6a53069455 | 62 | static uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 119:ee6a53069455 | 63 | |
klauss | 124:c1b6c893e1c3 | 64 | bool should_remove = false; |
klauss | 124:c1b6c893e1c3 | 65 | |
klauss | 119:ee6a53069455 | 66 | for( register uint8_t i = 0; i < v_call->size(); i++ ) |
klauss | 119:ee6a53069455 | 67 | { |
klauss | 124:c1b6c893e1c3 | 68 | should_remove = false; |
klauss | 74:81c47fff88a5 | 69 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 124:c1b6c893e1c3 | 70 | |
klauss | 124:c1b6c893e1c3 | 71 | /* |
klauss | 124:c1b6c893e1c3 | 72 | if ( call == NULL ) continue; |
klauss | 124:c1b6c893e1c3 | 73 | |
klauss | 124:c1b6c893e1c3 | 74 | if ( end_call ) |
klauss | 119:ee6a53069455 | 75 | { |
klauss | 124:c1b6c893e1c3 | 76 | if ( end_call_ext == call -> get_cb_ext () ) |
klauss | 124:c1b6c893e1c3 | 77 | { |
klauss | 124:c1b6c893e1c3 | 78 | end_call = false; |
klauss | 124:c1b6c893e1c3 | 79 | end_call_ext = 0; |
klauss | 124:c1b6c893e1c3 | 80 | should_remove = true; |
klauss | 124:c1b6c893e1c3 | 81 | } |
klauss | 124:c1b6c893e1c3 | 82 | } |
klauss | 124:c1b6c893e1c3 | 83 | */ |
klauss | 124:c1b6c893e1c3 | 84 | |
klauss | 124:c1b6c893e1c3 | 85 | if( call->is_timetofinish() || call->cbx_pkg_is_idle() || should_remove ) |
klauss | 124:c1b6c893e1c3 | 86 | { |
klauss | 124:c1b6c893e1c3 | 87 | //if( debug_invite && !should_remove ) |
klauss | 124:c1b6c893e1c3 | 88 | if( debug_invite && !should_remove ) |
klauss | 124:c1b6c893e1c3 | 89 | { |
klauss | 92:92df17f538a8 | 90 | if( call->cbx_pkg_is_idle() ){ |
klauss | 119:ee6a53069455 | 91 | if( debug_invite ) debug_msg("[%d] Call timeout: no pkg", call->get_cb_ext () ); |
klauss | 92:92df17f538a8 | 92 | } else { |
klauss | 119:ee6a53069455 | 93 | if( debug_invite ) debug_msg("[%d] Call timeout", call->get_cb_ext () ); |
klauss | 92:92df17f538a8 | 94 | } |
klauss | 92:92df17f538a8 | 95 | } |
klauss | 124:c1b6c893e1c3 | 96 | |
klauss | 74:81c47fff88a5 | 97 | v_call->remove_element( i ); |
klauss | 122:480c44b0e205 | 98 | Call_Box * cb = find_CB ( v_cb, call->get_cb_ext() ); |
klauss | 81:3656f00ab3db | 99 | if( cb != NULL ){ |
klauss | 119:ee6a53069455 | 100 | data[ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 101 | |
klauss | 119:ee6a53069455 | 102 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), CB_BYE, |
klauss | 119:ee6a53069455 | 103 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 104 | |
klauss | 119:ee6a53069455 | 105 | ts->return_timeslice( cb->call_end () ); |
klauss | 74:81c47fff88a5 | 106 | } |
klauss | 74:81c47fff88a5 | 107 | delete( call ); |
klauss | 74:81c47fff88a5 | 108 | } |
klauss | 74:81c47fff88a5 | 109 | } |
klauss | 78:1353744f01e1 | 110 | } |
klauss | 78:1353744f01e1 | 111 | |
klauss | 78:1353744f01e1 | 112 | void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ |
klauss | 119:ee6a53069455 | 113 | if ( ( v_call != NULL ) && ( v_cb != NULL ) && ( ts != NULL ) ) |
klauss | 119:ee6a53069455 | 114 | { |
klauss | 119:ee6a53069455 | 115 | uint8_t data[ CB_BUFFER_SIZE ]; |
klauss | 119:ee6a53069455 | 116 | uint8_t write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 116:39a41ebb675c | 117 | |
klauss | 119:ee6a53069455 | 118 | if( inviting_cb != NULL ){ |
klauss | 121:ee02790d00b7 | 119 | if( inviting_cb -> get_status () == cb_idle ){ |
klauss | 119:ee6a53069455 | 120 | inviting_cb->cb_set_status( cb_trying ); |
klauss | 119:ee6a53069455 | 121 | if( debug_invite ) debug_msg("[%d] Request invite <cb_idle,cb_trying>", inviting_cb->get_ext () ); |
klauss | 119:ee6a53069455 | 122 | } |
klauss | 119:ee6a53069455 | 123 | } |
klauss | 117:e9facba9db27 | 124 | |
klauss | 119:ee6a53069455 | 125 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 119:ee6a53069455 | 126 | { |
klauss | 119:ee6a53069455 | 127 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 119:ee6a53069455 | 128 | |
klauss | 119:ee6a53069455 | 129 | if ( cb == NULL ) continue; |
klauss | 119:ee6a53069455 | 130 | |
klauss | 119:ee6a53069455 | 131 | if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; |
klauss | 119:ee6a53069455 | 132 | |
klauss | 119:ee6a53069455 | 133 | int ext = cb->get_ext(); |
klauss | 119:ee6a53069455 | 134 | int port = cb->get_port(); |
klauss | 119:ee6a53069455 | 135 | |
klauss | 119:ee6a53069455 | 136 | VZ_call * call = NULL; |
klauss | 119:ee6a53069455 | 137 | |
klauss | 121:ee02790d00b7 | 138 | switch( cb -> get_status () ) |
klauss | 121:ee02790d00b7 | 139 | { |
klauss | 119:ee6a53069455 | 140 | case cb_trying : { |
klauss | 119:ee6a53069455 | 141 | uint8_t timeslice = ts->get_timeslice (); |
klauss | 117:e9facba9db27 | 142 | |
klauss | 119:ee6a53069455 | 143 | if( timeslice == 0 ){ |
klauss | 119:ee6a53069455 | 144 | |
klauss | 119:ee6a53069455 | 145 | data[ TIMESLICE_PLACE ] = 0x00; |
klauss | 119:ee6a53069455 | 146 | |
klauss | 119:ee6a53069455 | 147 | send2callboxes( build_cb_package( ext, port, INVITE, |
klauss | 119:ee6a53069455 | 148 | ( char * )data, ( cb->get_msg_id() | BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 149 | |
klauss | 119:ee6a53069455 | 150 | cb->call_end (); |
klauss | 119:ee6a53069455 | 151 | |
klauss | 119:ee6a53069455 | 152 | if( debug_invite ) debug_msg( "[%d] Trying without TS <cb_trying,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 153 | |
klauss | 119:ee6a53069455 | 154 | return; |
klauss | 119:ee6a53069455 | 155 | }else{ |
klauss | 119:ee6a53069455 | 156 | |
klauss | 119:ee6a53069455 | 157 | data[ TIMESLICE_PLACE ] = timeslice; |
klauss | 119:ee6a53069455 | 158 | |
klauss | 119:ee6a53069455 | 159 | cb->call_init ( timeslice ); |
klauss | 119:ee6a53069455 | 160 | |
klauss | 119:ee6a53069455 | 161 | send2callboxes( build_cb_package( ext, port, INVITE, |
klauss | 119:ee6a53069455 | 162 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 163 | |
klauss | 119:ee6a53069455 | 164 | if( debug_invite ) debug_msg("[%d] TS::%d <cb_trying,cb_ringing>", ext, data[ TIMESLICE_PLACE ] ); |
klauss | 119:ee6a53069455 | 165 | } |
klauss | 119:ee6a53069455 | 166 | }break; |
klauss | 119:ee6a53069455 | 167 | case cb_ringing : { |
klauss | 119:ee6a53069455 | 168 | call = cb->invite(); |
klauss | 117:e9facba9db27 | 169 | |
klauss | 119:ee6a53069455 | 170 | if( cb->get_sip_status() == sip_busy ){ |
klauss | 119:ee6a53069455 | 171 | cb->cb_set_status( cb_busy ); |
klauss | 119:ee6a53069455 | 172 | }else if( call != NULL ){ |
klauss | 119:ee6a53069455 | 173 | if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); |
klauss | 116:39a41ebb675c | 174 | |
klauss | 119:ee6a53069455 | 175 | call->init_cbx_pkg_idle_timer(); |
klauss | 119:ee6a53069455 | 176 | |
klauss | 119:ee6a53069455 | 177 | if( cb->get_sip_status() == sip_on_call ){ |
klauss | 116:39a41ebb675c | 178 | |
klauss | 119:ee6a53069455 | 179 | data[ TIMESLICE_PLACE ] = cb->get_timeslice(); |
klauss | 119:ee6a53069455 | 180 | |
klauss | 119:ee6a53069455 | 181 | send2callboxes( build_cb_package( ext, port, INVITE, ( char * )data, |
klauss | 119:ee6a53069455 | 182 | cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 183 | |
klauss | 119:ee6a53069455 | 184 | cb->call_confirmed (); |
klauss | 114:472502b31a12 | 185 | |
klauss | 119:ee6a53069455 | 186 | if( debug_invite ) debug_msg( "[%d] Ringing call ok <cb_ringing,cb_on_call>", ext ); |
klauss | 119:ee6a53069455 | 187 | } |
klauss | 119:ee6a53069455 | 188 | }else{ |
klauss | 119:ee6a53069455 | 189 | if( cb->get_sip_status() == sip_denied ) |
klauss | 119:ee6a53069455 | 190 | { |
klauss | 119:ee6a53069455 | 191 | cb->cb_set_status( cb_denied ); |
klauss | 119:ee6a53069455 | 192 | if( debug_invite ) debug_msg( "[%d] call denied <sip_denied>::<cb_ringing,cb_denied>", ext ); |
klauss | 119:ee6a53069455 | 193 | } else { |
klauss | 119:ee6a53069455 | 194 | if ( cb->time_to_retry () ) |
klauss | 121:ee02790d00b7 | 195 | { |
klauss | 121:ee02790d00b7 | 196 | if ( cb -> get_sip_status () == sip_waiting_trying ) |
klauss | 119:ee6a53069455 | 197 | { |
klauss | 121:ee02790d00b7 | 198 | if ( debug_invite ) debug_msg ("[%4i %3i] Resend invite to *", ext, cb -> get_invite_try_number () ); |
klauss | 121:ee02790d00b7 | 199 | cb->retry_send_invite_pkg_to_ast (); |
klauss | 119:ee6a53069455 | 200 | } |
klauss | 119:ee6a53069455 | 201 | } |
klauss | 119:ee6a53069455 | 202 | } |
klauss | 109:a5b8264ffbbc | 203 | } |
klauss | 119:ee6a53069455 | 204 | }break; |
klauss | 119:ee6a53069455 | 205 | case cb_busy : { |
klauss | 119:ee6a53069455 | 206 | data[ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 207 | |
klauss | 119:ee6a53069455 | 208 | send2callboxes( build_cb_package( ext, port, CB_BYE, |
klauss | 119:ee6a53069455 | 209 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 210 | |
klauss | 119:ee6a53069455 | 211 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 119:ee6a53069455 | 212 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 119:ee6a53069455 | 213 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 119:ee6a53069455 | 214 | v_call->remove_element( i ); |
klauss | 119:ee6a53069455 | 215 | if( call != NULL ) delete( call ); |
klauss | 119:ee6a53069455 | 216 | break; |
klauss | 119:ee6a53069455 | 217 | } |
klauss | 119:ee6a53069455 | 218 | } |
klauss | 119:ee6a53069455 | 219 | |
klauss | 119:ee6a53069455 | 220 | ts->return_timeslice( cb->call_end () ); |
klauss | 119:ee6a53069455 | 221 | |
klauss | 119:ee6a53069455 | 222 | if( debug_invite ) debug_msg( "[%d] Busy Here <cb_busy,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 223 | }break; |
klauss | 117:e9facba9db27 | 224 | |
klauss | 119:ee6a53069455 | 225 | case cb_denied : { |
klauss | 119:ee6a53069455 | 226 | data[ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 227 | |
klauss | 119:ee6a53069455 | 228 | send2callboxes( build_cb_package( ext, port, CB_BYE, |
klauss | 119:ee6a53069455 | 229 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 230 | |
klauss | 119:ee6a53069455 | 231 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 119:ee6a53069455 | 232 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 119:ee6a53069455 | 233 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 119:ee6a53069455 | 234 | v_call->remove_element( i ); |
klauss | 119:ee6a53069455 | 235 | if( call != NULL ) delete( call ); |
klauss | 119:ee6a53069455 | 236 | break; |
klauss | 119:ee6a53069455 | 237 | } |
klauss | 117:e9facba9db27 | 238 | } |
klauss | 119:ee6a53069455 | 239 | ts->return_timeslice( cb->call_end () ); |
klauss | 119:ee6a53069455 | 240 | |
klauss | 119:ee6a53069455 | 241 | if( debug_invite ) debug_msg( "[%d] call denied <cb_denied,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 242 | }break; |
klauss | 119:ee6a53069455 | 243 | } |
klauss | 78:1353744f01e1 | 244 | } |
klauss | 78:1353744f01e1 | 245 | } |
klauss | 74:81c47fff88a5 | 246 | } |