![](/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@91:c2a86b1f8aaa, 2015-01-08 (annotated)
- Committer:
- klauss
- Date:
- Thu Jan 08 23:44:08 2015 +0000
- Revision:
- 91:c2a86b1f8aaa
- Parent:
- 82:f55d13babca0
- Child:
- 92:92df17f538a8
- melhorias no tratamento dos pacotes udp, melhorando o tratamento da fila, evitando que ela transborde
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 | 81:3656f00ab3db | 21 | cb->set_msg_id( cb->get_msg_id() & ~BIT7 ); |
klauss | 81:3656f00ab3db | 22 | |
klauss | 81:3656f00ab3db | 23 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )data, |
klauss | 81:3656f00ab3db | 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 | 81:3656f00ab3db | 39 | cb->set_msg_id( cb->get_msg_id() & ~BIT7 ); |
klauss | 81:3656f00ab3db | 40 | |
klauss | 81:3656f00ab3db | 41 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, ( char * )data, |
klauss | 81:3656f00ab3db | 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 | 74:81c47fff88a5 | 60 | void call_manager( Vector * v_call, Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Timeslice * ts ){ |
klauss | 81:3656f00ab3db | 61 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 74:81c47fff88a5 | 62 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 74:81c47fff88a5 | 63 | if( call->is_timetofinish() ){ |
klauss | 74:81c47fff88a5 | 64 | v_call->remove_element( i ); |
klauss | 74:81c47fff88a5 | 65 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 81:3656f00ab3db | 66 | if( cb != NULL ){ |
klauss | 74:81c47fff88a5 | 67 | cb->status = cb_idle; |
klauss | 74:81c47fff88a5 | 68 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 74:81c47fff88a5 | 69 | cb->set_timeslice( 0x00 ); |
klauss | 74:81c47fff88a5 | 70 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 71 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 74:81c47fff88a5 | 72 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, |
klauss | 74:81c47fff88a5 | 73 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 74:81c47fff88a5 | 74 | cb->send_bye(); |
klauss | 74:81c47fff88a5 | 75 | set_status( cb->sip->status, sip_idle ); |
klauss | 74:81c47fff88a5 | 76 | cb->re_start_timer(); |
klauss | 91:c2a86b1f8aaa | 77 | cb->reset_cb_status(); |
klauss | 74:81c47fff88a5 | 78 | } |
klauss | 74:81c47fff88a5 | 79 | delete( call ); |
klauss | 74:81c47fff88a5 | 80 | } |
klauss | 74:81c47fff88a5 | 81 | } |
klauss | 78:1353744f01e1 | 82 | } |
klauss | 78:1353744f01e1 | 83 | |
klauss | 78:1353744f01e1 | 84 | void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ |
klauss | 78:1353744f01e1 | 85 | uint8_t data[ __CB_BUFFER_SIZE__ ]; |
klauss | 78:1353744f01e1 | 86 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 78:1353744f01e1 | 87 | |
klauss | 78:1353744f01e1 | 88 | if( inviting_cb != NULL ){ |
klauss | 78:1353744f01e1 | 89 | if( inviting_cb->status != cb_on_call ){ |
klauss | 78:1353744f01e1 | 90 | inviting_cb->cb_set_status( cb_trying ); |
klauss | 78:1353744f01e1 | 91 | if( debug_invite ) debug_msg("Request invite cbx status :: cb_trying" ); |
klauss | 78:1353744f01e1 | 92 | } |
klauss | 78:1353744f01e1 | 93 | } |
klauss | 78:1353744f01e1 | 94 | |
klauss | 78:1353744f01e1 | 95 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 96 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 97 | if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; |
klauss | 78:1353744f01e1 | 98 | |
klauss | 78:1353744f01e1 | 99 | int ext = cb->get_ext(); |
klauss | 78:1353744f01e1 | 100 | int port = cb->get_port(); |
klauss | 78:1353744f01e1 | 101 | |
klauss | 78:1353744f01e1 | 102 | VZ_call * call = NULL; |
klauss | 78:1353744f01e1 | 103 | |
klauss | 78:1353744f01e1 | 104 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 105 | case cb_trying : { |
klauss | 78:1353744f01e1 | 106 | uint8_t temp = cb->get_msg_id(); |
klauss | 78:1353744f01e1 | 107 | cb->set_msg_id( temp |= BIT7 ); |
klauss | 78:1353744f01e1 | 108 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 78:1353744f01e1 | 109 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 78:1353744f01e1 | 110 | |
klauss | 78:1353744f01e1 | 111 | cb->cb_set_status( cb_idle ); |
klauss | 78:1353744f01e1 | 112 | |
klauss | 78:1353744f01e1 | 113 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 114 | |
klauss | 78:1353744f01e1 | 115 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 78:1353744f01e1 | 116 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 117 | |
klauss | 78:1353744f01e1 | 118 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 119 | |
klauss | 78:1353744f01e1 | 120 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 121 | |
klauss | 78:1353744f01e1 | 122 | if( debug_invite ) debug_msg( "-- Trying -- without TS --"); |
klauss | 78:1353744f01e1 | 123 | |
klauss | 78:1353744f01e1 | 124 | return; |
klauss | 78:1353744f01e1 | 125 | }else{ |
klauss | 78:1353744f01e1 | 126 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 78:1353744f01e1 | 127 | |
klauss | 78:1353744f01e1 | 128 | cb->cb_set_status( cb_ringing ); |
klauss | 78:1353744f01e1 | 129 | |
klauss | 78:1353744f01e1 | 130 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 78:1353744f01e1 | 131 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 132 | |
klauss | 81:3656f00ab3db | 133 | if( debug_invite ) debug_msg("-- %d on TS::%d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 134 | } |
klauss | 78:1353744f01e1 | 135 | }break; |
klauss | 78:1353744f01e1 | 136 | case cb_ringing : { |
klauss | 78:1353744f01e1 | 137 | call = cb->invite(); |
klauss | 82:f55d13babca0 | 138 | |
klauss | 82:f55d13babca0 | 139 | if( cb->get_sip_status() == sip_busy ){ |
klauss | 82:f55d13babca0 | 140 | cb->cb_set_status( cb_busy ); |
klauss | 82:f55d13babca0 | 141 | }else if( call != NULL ){ |
klauss | 78:1353744f01e1 | 142 | if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); |
klauss | 78:1353744f01e1 | 143 | |
klauss | 78:1353744f01e1 | 144 | if( cb->get_sip_status() == sip_on_call ){ |
klauss | 78:1353744f01e1 | 145 | |
klauss | 78:1353744f01e1 | 146 | set_status( cb->status, cb_on_call ); |
klauss | 78:1353744f01e1 | 147 | |
klauss | 81:3656f00ab3db | 148 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 78:1353744f01e1 | 149 | |
klauss | 78:1353744f01e1 | 150 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 151 | |
klauss | 78:1353744f01e1 | 152 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, ( char * )data, |
klauss | 78:1353744f01e1 | 153 | cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 154 | |
klauss | 81:3656f00ab3db | 155 | cb->set_invite_response_pending(); |
klauss | 78:1353744f01e1 | 156 | |
klauss | 78:1353744f01e1 | 157 | if( debug_invite ) debug_msg( "-- ringing -- accepting call request --" ); |
klauss | 78:1353744f01e1 | 158 | } |
klauss | 78:1353744f01e1 | 159 | }else{ |
klauss | 78:1353744f01e1 | 160 | if( cb->get_sip_status() == sip_denied ) cb->cb_set_status( cb_denied ); |
klauss | 78:1353744f01e1 | 161 | } |
klauss | 78:1353744f01e1 | 162 | }break; |
klauss | 78:1353744f01e1 | 163 | case cb_busy : { |
klauss | 78:1353744f01e1 | 164 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 165 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 78:1353744f01e1 | 166 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 167 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 81:3656f00ab3db | 168 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 169 | |
klauss | 78:1353744f01e1 | 170 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 171 | |
klauss | 78:1353744f01e1 | 172 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 78:1353744f01e1 | 173 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 174 | |
klauss | 78:1353744f01e1 | 175 | if( debug_invite ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 78:1353744f01e1 | 176 | |
klauss | 78:1353744f01e1 | 177 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 78:1353744f01e1 | 178 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 179 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 78:1353744f01e1 | 180 | v_call->remove_element( i ); |
klauss | 91:c2a86b1f8aaa | 181 | if( call != NULL ) delete( call ); |
klauss | 78:1353744f01e1 | 182 | break; |
klauss | 78:1353744f01e1 | 183 | } |
klauss | 78:1353744f01e1 | 184 | } |
klauss | 78:1353744f01e1 | 185 | |
klauss | 78:1353744f01e1 | 186 | cb->send_bye(); |
klauss | 78:1353744f01e1 | 187 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 188 | cb->re_start_timer(); |
klauss | 78:1353744f01e1 | 189 | }break; |
klauss | 78:1353744f01e1 | 190 | case cb_denied : { |
klauss | 78:1353744f01e1 | 191 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 78:1353744f01e1 | 192 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 193 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 81:3656f00ab3db | 194 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 195 | |
klauss | 78:1353744f01e1 | 196 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 197 | |
klauss | 78:1353744f01e1 | 198 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 78:1353744f01e1 | 199 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 200 | |
klauss | 78:1353744f01e1 | 201 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 78:1353744f01e1 | 202 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 203 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 78:1353744f01e1 | 204 | v_call->remove_element( i ); |
klauss | 91:c2a86b1f8aaa | 205 | if( call != NULL ) delete( call ); |
klauss | 78:1353744f01e1 | 206 | break; |
klauss | 78:1353744f01e1 | 207 | } |
klauss | 78:1353744f01e1 | 208 | } |
klauss | 91:c2a86b1f8aaa | 209 | debug_msg(""); |
klauss | 78:1353744f01e1 | 210 | if( debug_invite ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 78:1353744f01e1 | 211 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 212 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 213 | }break; |
klauss | 78:1353744f01e1 | 214 | } |
klauss | 78:1353744f01e1 | 215 | } |
klauss | 74:81c47fff88a5 | 216 | } |