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