![](/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@109:a5b8264ffbbc, 2015-04-07 (annotated)
- Committer:
- klauss
- Date:
- Tue Apr 07 14:27:44 2015 +0000
- Revision:
- 109:a5b8264ffbbc
- Parent:
- 108:18a3702650f3
- Child:
- 112:6ae726539ab9
bl wip
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 | 109:a5b8264ffbbc | 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 | 109:a5b8264ffbbc | 24 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )data, |
klauss | 109:a5b8264ffbbc | 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 | 109:a5b8264ffbbc | 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 | 109:a5b8264ffbbc | 43 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, ( char * )data, |
klauss | 109:a5b8264ffbbc | 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 | 109:a5b8264ffbbc | 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 | 109:a5b8264ffbbc | 81 | // cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 82 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 83 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 84 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 74:81c47fff88a5 | 85 | cb->send_bye(); |
klauss | 74:81c47fff88a5 | 86 | set_status( cb->sip->status, sip_idle ); |
klauss | 109:a5b8264ffbbc | 87 | //cb->re_start_timer(); |
klauss | 109:a5b8264ffbbc | 88 | cb->reset_cb_status(); |
klauss | 74:81c47fff88a5 | 89 | } |
klauss | 74:81c47fff88a5 | 90 | delete( call ); |
klauss | 74:81c47fff88a5 | 91 | } |
klauss | 74:81c47fff88a5 | 92 | } |
klauss | 78:1353744f01e1 | 93 | } |
klauss | 78:1353744f01e1 | 94 | |
klauss | 78:1353744f01e1 | 95 | void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ |
klauss | 109:a5b8264ffbbc | 96 | uint8_t data[ __CB_BUFFER_SIZE__ ]; |
klauss | 109:a5b8264ffbbc | 97 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 78:1353744f01e1 | 98 | |
klauss | 109:a5b8264ffbbc | 99 | if( inviting_cb != NULL ){ |
klauss | 109:a5b8264ffbbc | 100 | //if( inviting_cb->status != cb_on_call ){ |
klauss | 109:a5b8264ffbbc | 101 | |
klauss | 109:a5b8264ffbbc | 102 | //} |
klauss | 109:a5b8264ffbbc | 103 | if( inviting_cb->status == cb_idle ){ |
klauss | 109:a5b8264ffbbc | 104 | inviting_cb->cb_set_status( cb_trying ); |
klauss | 109:a5b8264ffbbc | 105 | if( debug_invite ) debug_msg("Request invite cbx status :: cb_trying" ); |
klauss | 108:18a3702650f3 | 106 | } |
klauss | 109:a5b8264ffbbc | 107 | } |
klauss | 109:a5b8264ffbbc | 108 | |
klauss | 109:a5b8264ffbbc | 109 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 109:a5b8264ffbbc | 110 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 111 | if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; |
klauss | 109:a5b8264ffbbc | 112 | |
klauss | 109:a5b8264ffbbc | 113 | int ext = cb->get_ext(); |
klauss | 109:a5b8264ffbbc | 114 | int port = cb->get_port(); |
klauss | 108:18a3702650f3 | 115 | |
klauss | 109:a5b8264ffbbc | 116 | VZ_call * call = NULL; |
klauss | 109:a5b8264ffbbc | 117 | |
klauss | 109:a5b8264ffbbc | 118 | switch( cb->status ){ |
klauss | 109:a5b8264ffbbc | 119 | case cb_trying : { |
klauss | 109:a5b8264ffbbc | 120 | uint8_t temp = cb->get_msg_id(); |
klauss | 109:a5b8264ffbbc | 121 | cb->set_msg_id( temp |= BIT7 ); |
klauss | 109:a5b8264ffbbc | 122 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 109:a5b8264ffbbc | 123 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 109:a5b8264ffbbc | 124 | |
klauss | 109:a5b8264ffbbc | 125 | cb->cb_set_status( cb_idle ); |
klauss | 109:a5b8264ffbbc | 126 | |
klauss | 109:a5b8264ffbbc | 127 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 109:a5b8264ffbbc | 128 | |
klauss | 109:a5b8264ffbbc | 129 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 109:a5b8264ffbbc | 130 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 131 | |
klauss | 109:a5b8264ffbbc | 132 | set_status( cb->sip->status, sip_idle ); |
klauss | 109:a5b8264ffbbc | 133 | |
klauss | 109:a5b8264ffbbc | 134 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 109:a5b8264ffbbc | 135 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 136 | |
klauss | 109:a5b8264ffbbc | 137 | if( debug_invite ) debug_msg( "-- Trying -- without TS --"); |
klauss | 109:a5b8264ffbbc | 138 | |
klauss | 109:a5b8264ffbbc | 139 | return; |
klauss | 109:a5b8264ffbbc | 140 | }else{ |
klauss | 109:a5b8264ffbbc | 141 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 109:a5b8264ffbbc | 142 | |
klauss | 109:a5b8264ffbbc | 143 | cb->cb_set_status( cb_ringing ); |
klauss | 109:a5b8264ffbbc | 144 | |
klauss | 109:a5b8264ffbbc | 145 | cb->set_invite_response_pending(); |
klauss | 109:a5b8264ffbbc | 146 | |
klauss | 109:a5b8264ffbbc | 147 | //cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ( ~BIT7 ) ); |
klauss | 109:a5b8264ffbbc | 148 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 108:18a3702650f3 | 149 | |
klauss | 109:a5b8264ffbbc | 150 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 109:a5b8264ffbbc | 151 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 152 | |
klauss | 109:a5b8264ffbbc | 153 | if( debug_invite ) debug_msg("-- %d on TS::%d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 109:a5b8264ffbbc | 154 | } |
klauss | 109:a5b8264ffbbc | 155 | }break; |
klauss | 109:a5b8264ffbbc | 156 | case cb_ringing : { |
klauss | 109:a5b8264ffbbc | 157 | call = cb->invite(); |
klauss | 109:a5b8264ffbbc | 158 | |
klauss | 109:a5b8264ffbbc | 159 | if( cb->get_sip_status() == sip_busy ){ |
klauss | 109:a5b8264ffbbc | 160 | cb->cb_set_status( cb_busy ); |
klauss | 109:a5b8264ffbbc | 161 | }else if( call != NULL ){ |
klauss | 109:a5b8264ffbbc | 162 | if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); |
klauss | 109:a5b8264ffbbc | 163 | |
klauss | 109:a5b8264ffbbc | 164 | call->init_cbx_pkg_idle_timer(); |
klauss | 109:a5b8264ffbbc | 165 | |
klauss | 109:a5b8264ffbbc | 166 | if( cb->get_sip_status() == sip_on_call ){ |
klauss | 108:18a3702650f3 | 167 | |
klauss | 109:a5b8264ffbbc | 168 | set_status( cb->status, cb_on_call ); |
klauss | 92:92df17f538a8 | 169 | |
klauss | 109:a5b8264ffbbc | 170 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 109:a5b8264ffbbc | 171 | |
klauss | 109:a5b8264ffbbc | 172 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 109:a5b8264ffbbc | 173 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 174 | |
klauss | 109:a5b8264ffbbc | 175 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, ( char * )data, |
klauss | 109:a5b8264ffbbc | 176 | cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 177 | //debug_msg("send ok liga o mic"); |
klauss | 109:a5b8264ffbbc | 178 | |
klauss | 109:a5b8264ffbbc | 179 | cb->set_invite_response_pending(); |
klauss | 109:a5b8264ffbbc | 180 | |
klauss | 109:a5b8264ffbbc | 181 | if( debug_invite ) debug_msg( "-- ringing -- accepting call request --" ); |
klauss | 78:1353744f01e1 | 182 | } |
klauss | 109:a5b8264ffbbc | 183 | }else{ |
klauss | 109:a5b8264ffbbc | 184 | if( cb->get_sip_status() == sip_denied ) cb->cb_set_status( cb_denied ); |
klauss | 109:a5b8264ffbbc | 185 | } |
klauss | 109:a5b8264ffbbc | 186 | }break; |
klauss | 109:a5b8264ffbbc | 187 | case cb_busy : { |
klauss | 109:a5b8264ffbbc | 188 | set_status( cb->status, cb_idle ); |
klauss | 109:a5b8264ffbbc | 189 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 109:a5b8264ffbbc | 190 | cb->set_timeslice( 0x00 ); |
klauss | 109:a5b8264ffbbc | 191 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 109:a5b8264ffbbc | 192 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 109:a5b8264ffbbc | 193 | |
klauss | 109:a5b8264ffbbc | 194 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 109:a5b8264ffbbc | 195 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 196 | |
klauss | 109:a5b8264ffbbc | 197 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 198 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 199 | |
klauss | 109:a5b8264ffbbc | 200 | if( debug_invite ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 109:a5b8264ffbbc | 201 | |
klauss | 109:a5b8264ffbbc | 202 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 109:a5b8264ffbbc | 203 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 109:a5b8264ffbbc | 204 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 109:a5b8264ffbbc | 205 | v_call->remove_element( i ); |
klauss | 109:a5b8264ffbbc | 206 | if( call != NULL ) delete( call ); |
klauss | 109:a5b8264ffbbc | 207 | break; |
klauss | 109:a5b8264ffbbc | 208 | } |
klauss | 109:a5b8264ffbbc | 209 | } |
klauss | 109:a5b8264ffbbc | 210 | |
klauss | 109:a5b8264ffbbc | 211 | cb->send_bye(); |
klauss | 109:a5b8264ffbbc | 212 | set_status( cb->sip->status, sip_idle ); |
klauss | 109:a5b8264ffbbc | 213 | //cb->re_start_timer(); |
klauss | 109:a5b8264ffbbc | 214 | }break; |
klauss | 109:a5b8264ffbbc | 215 | case cb_denied : { |
klauss | 109:a5b8264ffbbc | 216 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 109:a5b8264ffbbc | 217 | cb->set_timeslice( 0x00 ); |
klauss | 109:a5b8264ffbbc | 218 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 109:a5b8264ffbbc | 219 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 109:a5b8264ffbbc | 220 | |
klauss | 109:a5b8264ffbbc | 221 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 109:a5b8264ffbbc | 222 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 223 | |
klauss | 109:a5b8264ffbbc | 224 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 225 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 108:18a3702650f3 | 226 | |
klauss | 109:a5b8264ffbbc | 227 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 109:a5b8264ffbbc | 228 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 109:a5b8264ffbbc | 229 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 109:a5b8264ffbbc | 230 | v_call->remove_element( i ); |
klauss | 109:a5b8264ffbbc | 231 | if( call != NULL ) delete( call ); |
klauss | 109:a5b8264ffbbc | 232 | break; |
klauss | 78:1353744f01e1 | 233 | } |
klauss | 109:a5b8264ffbbc | 234 | } |
klauss | 109:a5b8264ffbbc | 235 | //cb->re_start_timer(); |
klauss | 109:a5b8264ffbbc | 236 | if( debug_invite ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 109:a5b8264ffbbc | 237 | set_status( cb->status, cb_idle ); |
klauss | 109:a5b8264ffbbc | 238 | set_status( cb->sip->status, sip_idle ); |
klauss | 109:a5b8264ffbbc | 239 | }break; |
klauss | 78:1353744f01e1 | 240 | } |
klauss | 78:1353744f01e1 | 241 | } |
klauss | 74:81c47fff88a5 | 242 | } |