![](/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@137:32dd35a6dbc9, 2015-11-24 (annotated)
- Committer:
- klauss
- Date:
- Tue Nov 24 14:06:22 2015 +0000
- Revision:
- 137:32dd35a6dbc9
- Parent:
- 135:2f4290590e51
core source of the .bin (09/21/2015) in the field
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 | 135:2f4290590e51 | 6 | VZ_call * |
klauss | 135:2f4290590e51 | 7 | find_Call ( Vector * v_call, const int ext ) |
klauss | 135:2f4290590e51 | 8 | { |
klauss | 135:2f4290590e51 | 9 | for ( register int i = 0; i < v_call -> size(); i ++ ) |
klauss | 135:2f4290590e51 | 10 | { |
klauss | 135:2f4290590e51 | 11 | VZ_call * call = NULL; |
klauss | 135:2f4290590e51 | 12 | |
klauss | 135:2f4290590e51 | 13 | call = ( VZ_call * )v_call -> get_element ( i ); |
klauss | 119:ee6a53069455 | 14 | if ( call != NULL ) |
klauss | 119:ee6a53069455 | 15 | { |
klauss | 135:2f4290590e51 | 16 | if ( call -> get_cb_ext () == ext ) return ( call ); |
klauss | 119:ee6a53069455 | 17 | } |
klauss | 74:81c47fff88a5 | 18 | } |
klauss | 74:81c47fff88a5 | 19 | return( NULL ); |
klauss | 74:81c47fff88a5 | 20 | } |
klauss | 74:81c47fff88a5 | 21 | |
klauss | 74:81c47fff88a5 | 22 | /* remove calls por timeout */ |
klauss | 125:8ff4dc96ad58 | 23 | void call_manager ( Vector * v_call, Vector * v_cb, Timeslice * ts ) |
klauss | 119:ee6a53069455 | 24 | { |
klauss | 132:05cd37f7e007 | 25 | //FIXME precisa tratar o caso dos parametros NULL ? |
klauss | 119:ee6a53069455 | 26 | static uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 119:ee6a53069455 | 27 | |
klauss | 125:8ff4dc96ad58 | 28 | for ( register uint8_t i = 0; i < v_call->size(); i++ ) |
klauss | 119:ee6a53069455 | 29 | { |
klauss | 135:2f4290590e51 | 30 | bool should_remove = false; |
klauss | 135:2f4290590e51 | 31 | |
klauss | 74:81c47fff88a5 | 32 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 124:c1b6c893e1c3 | 33 | |
klauss | 124:c1b6c893e1c3 | 34 | if ( call == NULL ) continue; |
klauss | 124:c1b6c893e1c3 | 35 | |
klauss | 124:c1b6c893e1c3 | 36 | if ( end_call ) |
klauss | 119:ee6a53069455 | 37 | { |
klauss | 124:c1b6c893e1c3 | 38 | if ( end_call_ext == call -> get_cb_ext () ) |
klauss | 124:c1b6c893e1c3 | 39 | { |
klauss | 124:c1b6c893e1c3 | 40 | end_call = false; |
klauss | 124:c1b6c893e1c3 | 41 | end_call_ext = 0; |
klauss | 124:c1b6c893e1c3 | 42 | should_remove = true; |
klauss | 124:c1b6c893e1c3 | 43 | } |
klauss | 124:c1b6c893e1c3 | 44 | } |
klauss | 124:c1b6c893e1c3 | 45 | |
klauss | 132:05cd37f7e007 | 46 | if ( call->is_timetofinish() || call -> cbx_pkg_is_idle() || should_remove ) |
klauss | 124:c1b6c893e1c3 | 47 | { |
klauss | 125:8ff4dc96ad58 | 48 | if ( debug_invite && !should_remove ) |
klauss | 124:c1b6c893e1c3 | 49 | { |
klauss | 132:05cd37f7e007 | 50 | if ( call -> cbx_pkg_is_idle () ) { |
klauss | 132:05cd37f7e007 | 51 | if( debug_invite ) vz_debug ("[%d] Call timeout: no pkg", call -> get_cb_ext () ); |
klauss | 92:92df17f538a8 | 52 | } else { |
klauss | 132:05cd37f7e007 | 53 | if( debug_invite ) vz_debug ("[%d] Call timeout", call->get_cb_ext () ); |
klauss | 92:92df17f538a8 | 54 | } |
klauss | 92:92df17f538a8 | 55 | } |
klauss | 124:c1b6c893e1c3 | 56 | |
klauss | 132:05cd37f7e007 | 57 | v_call -> remove_element ( i ); |
klauss | 132:05cd37f7e007 | 58 | Call_Box * cb = find_CB ( v_cb, call -> get_cb_ext () ); |
klauss | 132:05cd37f7e007 | 59 | if ( cb != NULL ) |
klauss | 132:05cd37f7e007 | 60 | { |
klauss | 132:05cd37f7e007 | 61 | data [ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 62 | |
klauss | 132:05cd37f7e007 | 63 | send2callboxes ( build_cb_package ( cb -> get_ext (), cb -> get_port (), CB_BYE, |
klauss | 132:05cd37f7e007 | 64 | ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 65 | |
klauss | 132:05cd37f7e007 | 66 | ts -> return_timeslice ( cb -> call_end () ); |
klauss | 74:81c47fff88a5 | 67 | } |
klauss | 74:81c47fff88a5 | 68 | delete( call ); |
klauss | 74:81c47fff88a5 | 69 | } |
klauss | 74:81c47fff88a5 | 70 | } |
klauss | 125:8ff4dc96ad58 | 71 | if ( end_call_ext != 0 ) |
klauss | 125:8ff4dc96ad58 | 72 | { |
klauss | 132:05cd37f7e007 | 73 | if ( debug_invite ) vz_debug ( "Call from %i not foud", end_call_ext ); |
klauss | 125:8ff4dc96ad58 | 74 | end_call = false; |
klauss | 125:8ff4dc96ad58 | 75 | end_call_ext = 0; |
klauss | 125:8ff4dc96ad58 | 76 | } |
klauss | 78:1353744f01e1 | 77 | } |
klauss | 78:1353744f01e1 | 78 | |
klauss | 135:2f4290590e51 | 79 | void |
klauss | 135:2f4290590e51 | 80 | invite_handler ( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ) |
klauss | 126:1f90756250fb | 81 | { |
klauss | 126:1f90756250fb | 82 | |
klauss | 126:1f90756250fb | 83 | if ( ( v_call != NULL ) and ( v_cb != NULL ) and ( ts != NULL ) ) |
klauss | 119:ee6a53069455 | 84 | { |
klauss | 126:1f90756250fb | 85 | uint8_t data [ CB_BUFFER_SIZE ]; |
klauss | 126:1f90756250fb | 86 | uint8_t write_buffer [ CB_BUFFER_SIZE ]; |
klauss | 116:39a41ebb675c | 87 | |
klauss | 126:1f90756250fb | 88 | if ( inviting_cb != NULL ) |
klauss | 126:1f90756250fb | 89 | { |
klauss | 126:1f90756250fb | 90 | if ( inviting_cb -> get_status () == cb_idle ) |
klauss | 126:1f90756250fb | 91 | { |
klauss | 126:1f90756250fb | 92 | inviting_cb -> cb_set_status ( cb_trying ); |
klauss | 132:05cd37f7e007 | 93 | if ( debug_invite ) vz_debug ("[%d] Request invite <cb_idle,cb_trying>", inviting_cb->get_ext () ); |
klauss | 119:ee6a53069455 | 94 | } |
klauss | 119:ee6a53069455 | 95 | } |
klauss | 117:e9facba9db27 | 96 | |
klauss | 126:1f90756250fb | 97 | for ( register uint8_t i = 0; i < v_cb->size (); i++ ) |
klauss | 119:ee6a53069455 | 98 | { |
klauss | 126:1f90756250fb | 99 | Call_Box * cb = ( Call_Box * ) v_cb->get_element ( i ); |
klauss | 119:ee6a53069455 | 100 | |
klauss | 119:ee6a53069455 | 101 | if ( cb == NULL ) continue; |
klauss | 119:ee6a53069455 | 102 | |
klauss | 126:1f90756250fb | 103 | if ( ( cb -> get_status () == cb_idle ) or ( cb -> get_status () == cb_on_call ) ) continue; |
klauss | 119:ee6a53069455 | 104 | |
klauss | 126:1f90756250fb | 105 | int ext = cb->get_ext (); |
klauss | 126:1f90756250fb | 106 | int port = cb->get_port (); |
klauss | 119:ee6a53069455 | 107 | |
klauss | 126:1f90756250fb | 108 | switch ( cb -> get_status () ) |
klauss | 121:ee02790d00b7 | 109 | { |
klauss | 119:ee6a53069455 | 110 | case cb_trying : { |
klauss | 126:1f90756250fb | 111 | uint8_t timeslice = ts -> get_timeslice (); |
klauss | 117:e9facba9db27 | 112 | |
klauss | 126:1f90756250fb | 113 | if ( timeslice == 0 ) |
klauss | 126:1f90756250fb | 114 | { |
klauss | 119:ee6a53069455 | 115 | |
klauss | 126:1f90756250fb | 116 | data [ TIMESLICE_PLACE ] = 0x00; |
klauss | 119:ee6a53069455 | 117 | |
klauss | 126:1f90756250fb | 118 | // validar troca de mensagens com nros "nao previstos" |
klauss | 126:1f90756250fb | 119 | send2callboxes ( build_cb_package ( ext, port, INVITE, |
klauss | 126:1f90756250fb | 120 | ( char * )data, ( cb->get_msg_id () | BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 121 | |
klauss | 126:1f90756250fb | 122 | cb -> call_end (); |
klauss | 119:ee6a53069455 | 123 | |
klauss | 132:05cd37f7e007 | 124 | if ( debug_invite ) vz_debug ( "[%d] Trying without TS <cb_trying,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 125 | |
klauss | 119:ee6a53069455 | 126 | return; |
klauss | 126:1f90756250fb | 127 | } |
klauss | 126:1f90756250fb | 128 | else |
klauss | 126:1f90756250fb | 129 | { |
klauss | 119:ee6a53069455 | 130 | |
klauss | 126:1f90756250fb | 131 | data [ TIMESLICE_PLACE ] = timeslice; |
klauss | 119:ee6a53069455 | 132 | |
klauss | 126:1f90756250fb | 133 | cb -> call_init ( timeslice ); |
klauss | 126:1f90756250fb | 134 | |
klauss | 126:1f90756250fb | 135 | // validar troca de mensagens com nros "nao previstos" |
klauss | 119:ee6a53069455 | 136 | send2callboxes( build_cb_package( ext, port, INVITE, |
klauss | 126:1f90756250fb | 137 | ( char * )data, cb->get_msg_id (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 138 | |
klauss | 132:05cd37f7e007 | 139 | if ( debug_invite ) vz_debug ("[%d] TS::%d <cb_trying,cb_ringing>", ext, data [ TIMESLICE_PLACE ] ); |
klauss | 119:ee6a53069455 | 140 | } |
klauss | 119:ee6a53069455 | 141 | }break; |
klauss | 119:ee6a53069455 | 142 | case cb_ringing : { |
klauss | 135:2f4290590e51 | 143 | VZ_call * call = cb -> invite (); |
klauss | 117:e9facba9db27 | 144 | |
klauss | 126:1f90756250fb | 145 | if ( cb -> get_sip_status () == sip_busy ){ |
klauss | 119:ee6a53069455 | 146 | cb->cb_set_status( cb_busy ); |
klauss | 126:1f90756250fb | 147 | } |
klauss | 126:1f90756250fb | 148 | else if ( call != NULL ) |
klauss | 126:1f90756250fb | 149 | { |
klauss | 126:1f90756250fb | 150 | if ( find_Call ( v_call, call -> get_cb_ext () ) == NULL ) v_call -> add ( call ); |
klauss | 116:39a41ebb675c | 151 | |
klauss | 126:1f90756250fb | 152 | call -> init_cbx_pkg_idle_timer (); |
klauss | 119:ee6a53069455 | 153 | |
klauss | 126:1f90756250fb | 154 | if ( cb -> get_sip_status () == sip_on_call ) |
klauss | 126:1f90756250fb | 155 | { |
klauss | 116:39a41ebb675c | 156 | |
klauss | 126:1f90756250fb | 157 | data [ TIMESLICE_PLACE ] = cb -> get_timeslice (); |
klauss | 119:ee6a53069455 | 158 | |
klauss | 126:1f90756250fb | 159 | // confirmar a msg_id se sempre é bem aceita pelo cbx |
klauss | 126:1f90756250fb | 160 | send2callboxes ( build_cb_package( ext, port, INVITE, ( char * )data, |
klauss | 119:ee6a53069455 | 161 | cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 162 | |
klauss | 126:1f90756250fb | 163 | cb -> call_confirmed (); |
klauss | 114:472502b31a12 | 164 | |
klauss | 132:05cd37f7e007 | 165 | if ( debug_invite ) vz_debug ( "[%d] Ringing call ok <cb_ringing,cb_on_call>", ext ); |
klauss | 119:ee6a53069455 | 166 | } |
klauss | 126:1f90756250fb | 167 | } else { |
klauss | 126:1f90756250fb | 168 | if ( cb -> get_sip_status () == sip_denied ) |
klauss | 119:ee6a53069455 | 169 | { |
klauss | 126:1f90756250fb | 170 | cb -> cb_set_status ( cb_denied ); |
klauss | 132:05cd37f7e007 | 171 | if ( debug_invite ) vz_debug ( "[%d] call denied <sip_denied>::<cb_ringing,cb_denied>", ext ); |
klauss | 119:ee6a53069455 | 172 | } else { |
klauss | 126:1f90756250fb | 173 | if ( cb -> time_to_retry () ) |
klauss | 121:ee02790d00b7 | 174 | { |
klauss | 121:ee02790d00b7 | 175 | if ( cb -> get_sip_status () == sip_waiting_trying ) |
klauss | 119:ee6a53069455 | 176 | { |
klauss | 132:05cd37f7e007 | 177 | if ( debug_invite ) vz_debug ("[%4i %3i] Resend invite to *", ext, cb -> get_invite_try_number () ); |
klauss | 126:1f90756250fb | 178 | cb -> retry_send_invite_pkg_to_ast (); |
klauss | 119:ee6a53069455 | 179 | } |
klauss | 119:ee6a53069455 | 180 | } |
klauss | 119:ee6a53069455 | 181 | } |
klauss | 109:a5b8264ffbbc | 182 | } |
klauss | 119:ee6a53069455 | 183 | }break; |
klauss | 119:ee6a53069455 | 184 | case cb_busy : { |
klauss | 126:1f90756250fb | 185 | data [ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 186 | |
klauss | 126:1f90756250fb | 187 | send2callboxes ( build_cb_package( ext, port, CB_BYE, |
klauss | 119:ee6a53069455 | 188 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 189 | |
klauss | 126:1f90756250fb | 190 | for ( register uint8_t i = 0; i < v_call -> size (); i++ ) |
klauss | 126:1f90756250fb | 191 | { |
klauss | 126:1f90756250fb | 192 | VZ_call * call = ( VZ_call * ) v_call->get_element ( i ); |
klauss | 126:1f90756250fb | 193 | |
klauss | 126:1f90756250fb | 194 | if ( call -> get_cb_ext () == cb -> get_ext () ) |
klauss | 126:1f90756250fb | 195 | { |
klauss | 126:1f90756250fb | 196 | v_call -> remove_element ( i ); |
klauss | 126:1f90756250fb | 197 | if ( call != NULL ) delete ( call ); |
klauss | 119:ee6a53069455 | 198 | break; |
klauss | 119:ee6a53069455 | 199 | } |
klauss | 119:ee6a53069455 | 200 | } |
klauss | 119:ee6a53069455 | 201 | |
klauss | 126:1f90756250fb | 202 | ts -> return_timeslice ( cb -> call_end () ); |
klauss | 119:ee6a53069455 | 203 | |
klauss | 132:05cd37f7e007 | 204 | if ( debug_invite ) vz_debug ( "[%d] Busy Here <cb_busy,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 205 | }break; |
klauss | 117:e9facba9db27 | 206 | |
klauss | 119:ee6a53069455 | 207 | case cb_denied : { |
klauss | 126:1f90756250fb | 208 | data [ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 209 | |
klauss | 126:1f90756250fb | 210 | send2callboxes ( build_cb_package( ext, port, CB_BYE, |
klauss | 119:ee6a53069455 | 211 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 212 | |
klauss | 126:1f90756250fb | 213 | for ( register uint8_t i = 0; i < v_call -> size (); i++ ) |
klauss | 126:1f90756250fb | 214 | { |
klauss | 126:1f90756250fb | 215 | VZ_call * call = ( VZ_call * ) v_call->get_element ( i ); |
klauss | 126:1f90756250fb | 216 | if ( call -> get_cb_ext () == cb->get_ext () ) |
klauss | 126:1f90756250fb | 217 | { |
klauss | 126:1f90756250fb | 218 | v_call -> remove_element( i ); |
klauss | 126:1f90756250fb | 219 | if ( call != NULL ) delete ( call ); |
klauss | 119:ee6a53069455 | 220 | break; |
klauss | 119:ee6a53069455 | 221 | } |
klauss | 117:e9facba9db27 | 222 | } |
klauss | 126:1f90756250fb | 223 | ts -> return_timeslice ( cb -> call_end () ); |
klauss | 119:ee6a53069455 | 224 | |
klauss | 132:05cd37f7e007 | 225 | if ( debug_invite ) vz_debug ( "[%d] call denied <cb_denied,cb_idle>", ext ); |
klauss | 119:ee6a53069455 | 226 | }break; |
klauss | 119:ee6a53069455 | 227 | } |
klauss | 78:1353744f01e1 | 228 | } |
klauss | 78:1353744f01e1 | 229 | } |
klauss | 74:81c47fff88a5 | 230 | } |