![](/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@108:18a3702650f3, 2015-03-18 (annotated)
- Committer:
- klauss
- Date:
- Wed Mar 18 13:33:54 2015 +0000
- Revision:
- 108:18a3702650f3
- Parent:
- 105:a930035b6556
- Child:
- 109:a5b8264ffbbc
wip - bug udp porta, corrompendo v_cb->size () em ultima analise
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 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 | 92:92df17f538a8 | 21 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 81:3656f00ab3db | 22 | |
klauss | 105:a930035b6556 | 23 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )data, |
klauss | 105:a930035b6556 | 24 | cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 25 | |
klauss | 81:3656f00ab3db | 26 | return; |
klauss | 81:3656f00ab3db | 27 | } |
klauss | 81:3656f00ab3db | 28 | } |
klauss | 81:3656f00ab3db | 29 | } |
klauss | 81:3656f00ab3db | 30 | } |
klauss | 81:3656f00ab3db | 31 | |
klauss | 81:3656f00ab3db | 32 | void bye_pgk_retry_manager( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ |
klauss | 81:3656f00ab3db | 33 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 81:3656f00ab3db | 34 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 81:3656f00ab3db | 35 | if( cb->get_status() == cb_idle ){ |
klauss | 81:3656f00ab3db | 36 | if( cb->get_bye_response() == false ){ |
klauss | 81:3656f00ab3db | 37 | bye_pkg_retry_timer.reset(); |
klauss | 81:3656f00ab3db | 38 | |
klauss | 92:92df17f538a8 | 39 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 81:3656f00ab3db | 40 | |
klauss | 105:a930035b6556 | 41 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), __CB_BYE__, ( char * )data, |
klauss | 105:a930035b6556 | 42 | cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 43 | |
klauss | 81:3656f00ab3db | 44 | return; |
klauss | 81:3656f00ab3db | 45 | } |
klauss | 81:3656f00ab3db | 46 | } |
klauss | 81:3656f00ab3db | 47 | } |
klauss | 81:3656f00ab3db | 48 | } |
klauss | 78:1353744f01e1 | 49 | |
klauss | 74:81c47fff88a5 | 50 | VZ_call * __find_Call__( Vector * v_call, int ext ){ |
klauss | 74:81c47fff88a5 | 51 | VZ_call * call = NULL; |
klauss | 74:81c47fff88a5 | 52 | for( register int i = 0; i < v_call->size(); i++ ){ |
klauss | 74:81c47fff88a5 | 53 | call = ( VZ_call * )v_call->get_element( i ); |
klauss | 74:81c47fff88a5 | 54 | if( call->get_cb_ext() == ext ) return( call ); |
klauss | 74:81c47fff88a5 | 55 | } |
klauss | 74:81c47fff88a5 | 56 | return( NULL ); |
klauss | 74:81c47fff88a5 | 57 | } |
klauss | 74:81c47fff88a5 | 58 | |
klauss | 74:81c47fff88a5 | 59 | /* remove calls por timeout */ |
klauss | 108:18a3702650f3 | 60 | void call_manager( Vector * v_call, Vector * v_cb, Timeslice * ts ){ |
klauss | 108:18a3702650f3 | 61 | //end call |
klauss | 108:18a3702650f3 | 62 | uint8_t data[ CB_BUFFER_SIZE ]; |
klauss | 108:18a3702650f3 | 63 | uint8_t write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 108:18a3702650f3 | 64 | |
klauss | 81:3656f00ab3db | 65 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 74:81c47fff88a5 | 66 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 92:92df17f538a8 | 67 | if( call->is_timetofinish() || call->cbx_pkg_is_idle() ){ |
klauss | 92:92df17f538a8 | 68 | |
klauss | 92:92df17f538a8 | 69 | if( debug_invite ){ |
klauss | 92:92df17f538a8 | 70 | if( call->cbx_pkg_is_idle() ){ |
klauss | 97:8985817e8847 | 71 | if( debug_invite ) debug_msg("Call timeout: no pkg"); |
klauss | 92:92df17f538a8 | 72 | } else { |
klauss | 97:8985817e8847 | 73 | if( debug_invite ) debug_msg("Call timeout"); |
klauss | 92:92df17f538a8 | 74 | } |
klauss | 92:92df17f538a8 | 75 | } |
klauss | 74:81c47fff88a5 | 76 | v_call->remove_element( i ); |
klauss | 74:81c47fff88a5 | 77 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 81:3656f00ab3db | 78 | if( cb != NULL ){ |
klauss | 74:81c47fff88a5 | 79 | cb->status = cb_idle; |
klauss | 74:81c47fff88a5 | 80 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 74:81c47fff88a5 | 81 | cb->set_timeslice( 0x00 ); |
klauss | 74:81c47fff88a5 | 82 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 92:92df17f538a8 | 83 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 105:a930035b6556 | 84 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), __CB_BYE__, |
klauss | 105:a930035b6556 | 85 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 74:81c47fff88a5 | 86 | cb->send_bye(); |
klauss | 74:81c47fff88a5 | 87 | set_status( cb->sip->status, sip_idle ); |
klauss | 108:18a3702650f3 | 88 | cb -> reset_cb_status (); |
klauss | 108:18a3702650f3 | 89 | cb -> set_rtp_port ( 0 ); |
klauss | 108:18a3702650f3 | 90 | cb -> reset_rtp_timer (); |
klauss | 74:81c47fff88a5 | 91 | } |
klauss | 74:81c47fff88a5 | 92 | delete( call ); |
klauss | 74:81c47fff88a5 | 93 | } |
klauss | 74:81c47fff88a5 | 94 | } |
klauss | 78:1353744f01e1 | 95 | } |
klauss | 78:1353744f01e1 | 96 | |
klauss | 78:1353744f01e1 | 97 | void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ |
klauss | 105:a930035b6556 | 98 | uint8_t data[ CB_BUFFER_SIZE ]; |
klauss | 105:a930035b6556 | 99 | uint8_t write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 78:1353744f01e1 | 100 | |
klauss | 108:18a3702650f3 | 101 | if ( ( v_call != NULL ) && ( v_cb != NULL ) && ( ts != NULL ) ) |
klauss | 108:18a3702650f3 | 102 | { |
klauss | 108:18a3702650f3 | 103 | if( inviting_cb != NULL ){ |
klauss | 108:18a3702650f3 | 104 | if( inviting_cb->status == cb_idle ){ |
klauss | 108:18a3702650f3 | 105 | inviting_cb->cb_set_status( cb_trying ); |
klauss | 108:18a3702650f3 | 106 | if( debug_invite ) debug_msg("Request invite cbx status :: cb_trying" ); |
klauss | 108:18a3702650f3 | 107 | } |
klauss | 108:18a3702650f3 | 108 | } |
klauss | 108:18a3702650f3 | 109 | |
klauss | 108:18a3702650f3 | 110 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 108:18a3702650f3 | 111 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 108:18a3702650f3 | 112 | if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; |
klauss | 92:92df17f538a8 | 113 | |
klauss | 108:18a3702650f3 | 114 | int ext = cb->get_ext(); |
klauss | 108:18a3702650f3 | 115 | int port = cb->get_port(); |
klauss | 108:18a3702650f3 | 116 | |
klauss | 108:18a3702650f3 | 117 | VZ_call * call = NULL; |
klauss | 78:1353744f01e1 | 118 | |
klauss | 108:18a3702650f3 | 119 | switch( cb->status ){ |
klauss | 108:18a3702650f3 | 120 | case cb_trying : { |
klauss | 108:18a3702650f3 | 121 | uint8_t temp = cb->get_msg_id(); |
klauss | 108:18a3702650f3 | 122 | cb->set_msg_id( temp |= BIT7 ); |
klauss | 108:18a3702650f3 | 123 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 108:18a3702650f3 | 124 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 108:18a3702650f3 | 125 | |
klauss | 108:18a3702650f3 | 126 | cb->cb_set_status( cb_idle ); |
klauss | 108:18a3702650f3 | 127 | |
klauss | 108:18a3702650f3 | 128 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 108:18a3702650f3 | 129 | |
klauss | 108:18a3702650f3 | 130 | send2callboxes( build_cb_package( ext, port, __INVITE__, |
klauss | 108:18a3702650f3 | 131 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 108:18a3702650f3 | 132 | |
klauss | 108:18a3702650f3 | 133 | set_status( cb->sip->status, sip_idle ); |
klauss | 108:18a3702650f3 | 134 | |
klauss | 108:18a3702650f3 | 135 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 108:18a3702650f3 | 136 | |
klauss | 108:18a3702650f3 | 137 | if( debug_invite ) debug_msg( "-- Trying -- without TS --"); |
klauss | 108:18a3702650f3 | 138 | |
klauss | 108:18a3702650f3 | 139 | cb -> set_rtp_port ( 0 ); |
klauss | 108:18a3702650f3 | 140 | |
klauss | 108:18a3702650f3 | 141 | cb -> reset_rtp_timer (); |
klauss | 108:18a3702650f3 | 142 | |
klauss | 108:18a3702650f3 | 143 | return; |
klauss | 108:18a3702650f3 | 144 | }else{ |
klauss | 108:18a3702650f3 | 145 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 108:18a3702650f3 | 146 | |
klauss | 108:18a3702650f3 | 147 | cb->cb_set_status( cb_ringing ); |
klauss | 108:18a3702650f3 | 148 | |
klauss | 108:18a3702650f3 | 149 | cb->set_invite_response_pending(); |
klauss | 108:18a3702650f3 | 150 | |
klauss | 108:18a3702650f3 | 151 | //cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ( ~BIT7 ) ); |
klauss | 108:18a3702650f3 | 152 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 108:18a3702650f3 | 153 | |
klauss | 108:18a3702650f3 | 154 | send2callboxes( build_cb_package( ext, port, __INVITE__, |
klauss | 108:18a3702650f3 | 155 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 108:18a3702650f3 | 156 | |
klauss | 108:18a3702650f3 | 157 | if( debug_invite ) debug_msg("-- %d on TS::%d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 108:18a3702650f3 | 158 | } |
klauss | 108:18a3702650f3 | 159 | }break; |
klauss | 108:18a3702650f3 | 160 | case cb_ringing : { |
klauss | 108:18a3702650f3 | 161 | call = cb->invite(); |
klauss | 78:1353744f01e1 | 162 | |
klauss | 108:18a3702650f3 | 163 | if( cb->get_sip_status() == sip_busy ){ |
klauss | 108:18a3702650f3 | 164 | cb->cb_set_status( cb_busy ); |
klauss | 108:18a3702650f3 | 165 | }else if( call != NULL ){ |
klauss | 108:18a3702650f3 | 166 | if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); |
klauss | 108:18a3702650f3 | 167 | |
klauss | 108:18a3702650f3 | 168 | call->init_cbx_pkg_idle_timer(); |
klauss | 108:18a3702650f3 | 169 | |
klauss | 108:18a3702650f3 | 170 | if( cb->get_sip_status() == sip_on_call ){ |
klauss | 108:18a3702650f3 | 171 | |
klauss | 108:18a3702650f3 | 172 | set_status( cb->status, cb_on_call ); |
klauss | 108:18a3702650f3 | 173 | |
klauss | 108:18a3702650f3 | 174 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 108:18a3702650f3 | 175 | |
klauss | 108:18a3702650f3 | 176 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 108:18a3702650f3 | 177 | |
klauss | 108:18a3702650f3 | 178 | send2callboxes( build_cb_package( ext, port, __INVITE__, ( char * )data, |
klauss | 108:18a3702650f3 | 179 | cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 108:18a3702650f3 | 180 | |
klauss | 108:18a3702650f3 | 181 | cb->set_invite_response_pending(); |
klauss | 108:18a3702650f3 | 182 | |
klauss | 108:18a3702650f3 | 183 | if( debug_invite ) debug_msg( "-- ringing -- accepting call request --" ); |
klauss | 108:18a3702650f3 | 184 | } |
klauss | 108:18a3702650f3 | 185 | }else{ |
klauss | 108:18a3702650f3 | 186 | if( cb->get_sip_status() == sip_denied ) cb->cb_set_status( cb_denied ); |
klauss | 108:18a3702650f3 | 187 | } |
klauss | 108:18a3702650f3 | 188 | }break; |
klauss | 108:18a3702650f3 | 189 | case cb_busy : { |
klauss | 108:18a3702650f3 | 190 | set_status( cb->status, cb_idle ); |
klauss | 108:18a3702650f3 | 191 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 108:18a3702650f3 | 192 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 193 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 108:18a3702650f3 | 194 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 195 | |
klauss | 92:92df17f538a8 | 196 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 78:1353744f01e1 | 197 | |
klauss | 108:18a3702650f3 | 198 | send2callboxes( build_cb_package( ext, port, __CB_BYE__, |
klauss | 105:a930035b6556 | 199 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 200 | |
klauss | 108:18a3702650f3 | 201 | if( debug_invite ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 92:92df17f538a8 | 202 | |
klauss | 108:18a3702650f3 | 203 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 108:18a3702650f3 | 204 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 108:18a3702650f3 | 205 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 108:18a3702650f3 | 206 | v_call->remove_element( i ); |
klauss | 108:18a3702650f3 | 207 | if( call != NULL ) delete( call ); |
klauss | 108:18a3702650f3 | 208 | break; |
klauss | 108:18a3702650f3 | 209 | } |
klauss | 78:1353744f01e1 | 210 | } |
klauss | 108:18a3702650f3 | 211 | |
klauss | 108:18a3702650f3 | 212 | cb->send_bye(); |
klauss | 108:18a3702650f3 | 213 | set_status( cb->sip->status, sip_idle ); |
klauss | 108:18a3702650f3 | 214 | cb -> set_rtp_port ( 0 ); |
klauss | 108:18a3702650f3 | 215 | cb -> reset_rtp_timer (); |
klauss | 108:18a3702650f3 | 216 | }break; |
klauss | 108:18a3702650f3 | 217 | case cb_denied : { |
klauss | 108:18a3702650f3 | 218 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 108:18a3702650f3 | 219 | cb->set_timeslice( 0x00 ); |
klauss | 108:18a3702650f3 | 220 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 108:18a3702650f3 | 221 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 108:18a3702650f3 | 222 | |
klauss | 108:18a3702650f3 | 223 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 108:18a3702650f3 | 224 | |
klauss | 108:18a3702650f3 | 225 | send2callboxes( build_cb_package( ext, port, __CB_BYE__, |
klauss | 108:18a3702650f3 | 226 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 108:18a3702650f3 | 227 | |
klauss | 108:18a3702650f3 | 228 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 108:18a3702650f3 | 229 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 108:18a3702650f3 | 230 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 108:18a3702650f3 | 231 | v_call->remove_element( i ); |
klauss | 108:18a3702650f3 | 232 | if( call != NULL ) delete( call ); |
klauss | 108:18a3702650f3 | 233 | break; |
klauss | 108:18a3702650f3 | 234 | } |
klauss | 78:1353744f01e1 | 235 | } |
klauss | 108:18a3702650f3 | 236 | if( debug_invite ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 108:18a3702650f3 | 237 | set_status( cb->status, cb_idle ); |
klauss | 108:18a3702650f3 | 238 | set_status( cb->sip->status, sip_idle ); |
klauss | 108:18a3702650f3 | 239 | cb -> set_rtp_port ( 0 ); |
klauss | 108:18a3702650f3 | 240 | cb -> reset_rtp_timer (); |
klauss | 108:18a3702650f3 | 241 | }break; |
klauss | 108:18a3702650f3 | 242 | } |
klauss | 78:1353744f01e1 | 243 | } |
klauss | 78:1353744f01e1 | 244 | } |
klauss | 74:81c47fff88a5 | 245 | } |