![](/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@81:3656f00ab3db, 2014-12-30 (annotated)
- Committer:
- klauss
- Date:
- Tue Dec 30 12:37:40 2014 +0000
- Revision:
- 81:3656f00ab3db
- Parent:
- 78:1353744f01e1
- Child:
- 82:f55d13babca0
tentando resolver o bug de apertar duas vezes o botao pra fazer uma call
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 | 74:81c47fff88a5 | 77 | } |
klauss | 74:81c47fff88a5 | 78 | delete( call ); |
klauss | 74:81c47fff88a5 | 79 | } |
klauss | 74:81c47fff88a5 | 80 | } |
klauss | 78:1353744f01e1 | 81 | } |
klauss | 78:1353744f01e1 | 82 | |
klauss | 78:1353744f01e1 | 83 | void invite_handler( Vector * v_call, Vector * v_cb, Timeslice * ts, Call_Box * inviting_cb ){ |
klauss | 78:1353744f01e1 | 84 | uint8_t data[ __CB_BUFFER_SIZE__ ]; |
klauss | 78:1353744f01e1 | 85 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 78:1353744f01e1 | 86 | |
klauss | 78:1353744f01e1 | 87 | if( inviting_cb != NULL ){ |
klauss | 78:1353744f01e1 | 88 | if( inviting_cb->status != cb_on_call ){ |
klauss | 78:1353744f01e1 | 89 | inviting_cb->cb_set_status( cb_trying ); |
klauss | 78:1353744f01e1 | 90 | if( debug_invite ) debug_msg("Request invite cbx status :: cb_trying" ); |
klauss | 78:1353744f01e1 | 91 | } |
klauss | 78:1353744f01e1 | 92 | } |
klauss | 78:1353744f01e1 | 93 | |
klauss | 78:1353744f01e1 | 94 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 95 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 96 | if( cb->get_status() == cb_idle || cb->get_status() == cb_on_call ) continue; |
klauss | 78:1353744f01e1 | 97 | |
klauss | 78:1353744f01e1 | 98 | int ext = cb->get_ext(); |
klauss | 78:1353744f01e1 | 99 | int port = cb->get_port(); |
klauss | 78:1353744f01e1 | 100 | |
klauss | 78:1353744f01e1 | 101 | VZ_call * call = NULL; |
klauss | 78:1353744f01e1 | 102 | |
klauss | 78:1353744f01e1 | 103 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 104 | case cb_trying : { |
klauss | 78:1353744f01e1 | 105 | uint8_t temp = cb->get_msg_id(); |
klauss | 78:1353744f01e1 | 106 | cb->set_msg_id( temp |= BIT7 ); |
klauss | 78:1353744f01e1 | 107 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 78:1353744f01e1 | 108 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 78:1353744f01e1 | 109 | |
klauss | 78:1353744f01e1 | 110 | cb->cb_set_status( cb_idle ); |
klauss | 78:1353744f01e1 | 111 | |
klauss | 78:1353744f01e1 | 112 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 113 | |
klauss | 78:1353744f01e1 | 114 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 78:1353744f01e1 | 115 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 116 | |
klauss | 78:1353744f01e1 | 117 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 118 | |
klauss | 78:1353744f01e1 | 119 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 120 | |
klauss | 78:1353744f01e1 | 121 | if( debug_invite ) debug_msg( "-- Trying -- without TS --"); |
klauss | 78:1353744f01e1 | 122 | |
klauss | 78:1353744f01e1 | 123 | return; |
klauss | 78:1353744f01e1 | 124 | }else{ |
klauss | 78:1353744f01e1 | 125 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 78:1353744f01e1 | 126 | |
klauss | 78:1353744f01e1 | 127 | cb->cb_set_status( cb_ringing ); |
klauss | 78:1353744f01e1 | 128 | |
klauss | 78:1353744f01e1 | 129 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, |
klauss | 78:1353744f01e1 | 130 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 131 | |
klauss | 81:3656f00ab3db | 132 | if( debug_invite ) debug_msg("-- %d on TS::%d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 133 | } |
klauss | 78:1353744f01e1 | 134 | }break; |
klauss | 78:1353744f01e1 | 135 | case cb_ringing : { |
klauss | 78:1353744f01e1 | 136 | call = cb->invite(); |
klauss | 78:1353744f01e1 | 137 | |
klauss | 78:1353744f01e1 | 138 | if( call != NULL ){ |
klauss | 78:1353744f01e1 | 139 | if( __find_Call__( v_call, call->get_cb_ext() ) == NULL ) v_call -> add( call ); |
klauss | 78:1353744f01e1 | 140 | |
klauss | 78:1353744f01e1 | 141 | if( cb->get_sip_status() == sip_on_call ){ |
klauss | 78:1353744f01e1 | 142 | |
klauss | 78:1353744f01e1 | 143 | set_status( cb->status, cb_on_call ); |
klauss | 78:1353744f01e1 | 144 | |
klauss | 81:3656f00ab3db | 145 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 78:1353744f01e1 | 146 | |
klauss | 78:1353744f01e1 | 147 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 148 | |
klauss | 78:1353744f01e1 | 149 | send2callboxes( __build_cb_package__( ext, port, __INVITE__, ( char * )data, |
klauss | 78:1353744f01e1 | 150 | cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 151 | |
klauss | 81:3656f00ab3db | 152 | cb->set_invite_response_pending(); |
klauss | 78:1353744f01e1 | 153 | |
klauss | 78:1353744f01e1 | 154 | if( debug_invite ) debug_msg( "-- ringing -- accepting call request --" ); |
klauss | 81:3656f00ab3db | 155 | }else if( cb->get_sip_status() == sip_busy ){ |
klauss | 81:3656f00ab3db | 156 | cb->cb_set_status( cb_busy ); |
klauss | 78:1353744f01e1 | 157 | } |
klauss | 78:1353744f01e1 | 158 | }else{ |
klauss | 78:1353744f01e1 | 159 | if( cb->get_sip_status() == sip_denied ) cb->cb_set_status( cb_denied ); |
klauss | 78:1353744f01e1 | 160 | } |
klauss | 78:1353744f01e1 | 161 | }break; |
klauss | 78:1353744f01e1 | 162 | case cb_busy : { |
klauss | 78:1353744f01e1 | 163 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 164 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 78:1353744f01e1 | 165 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 166 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 81:3656f00ab3db | 167 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 168 | |
klauss | 78:1353744f01e1 | 169 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 170 | |
klauss | 78:1353744f01e1 | 171 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 78:1353744f01e1 | 172 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 173 | |
klauss | 78:1353744f01e1 | 174 | if( debug_invite ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 78:1353744f01e1 | 175 | |
klauss | 78:1353744f01e1 | 176 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 78:1353744f01e1 | 177 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 178 | if( call->get_cb_ext() == cb->get_ext() ){ |
klauss | 78:1353744f01e1 | 179 | v_call->remove_element( i ); |
klauss | 78:1353744f01e1 | 180 | delete( call ); |
klauss | 78:1353744f01e1 | 181 | break; |
klauss | 78:1353744f01e1 | 182 | } |
klauss | 78:1353744f01e1 | 183 | } |
klauss | 78:1353744f01e1 | 184 | |
klauss | 78:1353744f01e1 | 185 | cb->send_bye(); |
klauss | 78:1353744f01e1 | 186 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 187 | cb->re_start_timer(); |
klauss | 78:1353744f01e1 | 188 | }break; |
klauss | 78:1353744f01e1 | 189 | case cb_denied : { |
klauss | 78:1353744f01e1 | 190 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 78:1353744f01e1 | 191 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 192 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 81:3656f00ab3db | 193 | if( debug_invite ) debug_msg("-- %d on %d --", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 78:1353744f01e1 | 194 | |
klauss | 78:1353744f01e1 | 195 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 196 | |
klauss | 78:1353744f01e1 | 197 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 78:1353744f01e1 | 198 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
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 | 78:1353744f01e1 | 204 | delete( call ); |
klauss | 78:1353744f01e1 | 205 | break; |
klauss | 78:1353744f01e1 | 206 | } |
klauss | 78:1353744f01e1 | 207 | } |
klauss | 78:1353744f01e1 | 208 | |
klauss | 78:1353744f01e1 | 209 | if( debug_invite ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 78:1353744f01e1 | 210 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 211 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 212 | }break; |
klauss | 78:1353744f01e1 | 213 | } |
klauss | 78:1353744f01e1 | 214 | } |
klauss | 74:81c47fff88a5 | 215 | } |