![](/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_box.cpp@113:db67ae00550e, 2015-04-16 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 16 12:57:13 2015 +0000
- Revision:
- 113:db67ae00550e
- Parent:
- 112:6ae726539ab9
- Child:
- 114:472502b31a12
valide esse fw
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "call_box.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 0:4d17cd9c8f9d | 3 | Call_Box::Call_Box( int ext, int port ){ |
klauss | 0:4d17cd9c8f9d | 4 | this->ext = ext; |
klauss | 0:4d17cd9c8f9d | 5 | this->port = port; |
klauss | 0:4d17cd9c8f9d | 6 | t.start(); |
klauss | 0:4d17cd9c8f9d | 7 | remaining_attempts = __MAX_ATTEMPTS__; |
klauss | 0:4d17cd9c8f9d | 8 | timeout = __TIMEOUT__; |
klauss | 4:de46f0d9b14d | 9 | msg_id = 0x10; |
klauss | 0:4d17cd9c8f9d | 10 | timeslice = 0x00; |
klauss | 0:4d17cd9c8f9d | 11 | status = cb_idle; |
klauss | 113:db67ae00550e | 12 | |
klauss | 113:db67ae00550e | 13 | { |
klauss | 113:db67ae00550e | 14 | FILE * fp = NULL; |
klauss | 113:db67ae00550e | 15 | char inner_tmp[ 20 ]; |
klauss | 113:db67ae00550e | 16 | |
klauss | 113:db67ae00550e | 17 | fp = fopen( "/qspi/shift_port.txt", "r" ); |
klauss | 113:db67ae00550e | 18 | if( fp == NULL ) |
klauss | 113:db67ae00550e | 19 | { |
klauss | 113:db67ae00550e | 20 | if( debug_cb ) debug_msg("Failed to open /qspi/shift_port.txt" ); |
klauss | 113:db67ae00550e | 21 | shift_port = SHIFT_PORT; |
klauss | 113:db67ae00550e | 22 | }else{ |
klauss | 113:db67ae00550e | 23 | if( fread( (void *)inner_tmp, 1, 20, fp ) > 0 ){ |
klauss | 113:db67ae00550e | 24 | shift_port = atoi( inner_tmp ); |
klauss | 113:db67ae00550e | 25 | if( debug_cb ) debug_msg("Shift port %d", shift_port ); |
klauss | 113:db67ae00550e | 26 | }else{ |
klauss | 113:db67ae00550e | 27 | if( debug_cb ) debug_msg("Failed to read /qspi/shift_port.txt" ); |
klauss | 113:db67ae00550e | 28 | shift_port = SHIFT_PORT; |
klauss | 113:db67ae00550e | 29 | } |
klauss | 113:db67ae00550e | 30 | } |
klauss | 113:db67ae00550e | 31 | |
klauss | 113:db67ae00550e | 32 | fclose( fp ); |
klauss | 113:db67ae00550e | 33 | } |
klauss | 113:db67ae00550e | 34 | |
klauss | 113:db67ae00550e | 35 | shift_port = SHIFT_PORT; |
klauss | 113:db67ae00550e | 36 | sip = new Sip( ext, ext + shift_port ); |
klauss | 89:0fe315117b00 | 37 | sip_socket_fd = sip->get_socket_fd(); |
klauss | 89:0fe315117b00 | 38 | if( sip == NULL ) |
klauss | 113:db67ae00550e | 39 | |
klauss | 89:0fe315117b00 | 40 | { |
klauss | 89:0fe315117b00 | 41 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 42 | if( debug_memory ) debug_msg("Sip allocation fail"); |
klauss | 89:0fe315117b00 | 43 | } |
klauss | 87:679ee0d594a9 | 44 | |
klauss | 78:1353744f01e1 | 45 | next_aging_type = __CYCLES__; |
klauss | 78:1353744f01e1 | 46 | seconds.start(); |
klauss | 81:3656f00ab3db | 47 | invite_response = true; |
klauss | 81:3656f00ab3db | 48 | bye_response = true; |
klauss | 92:92df17f538a8 | 49 | invite_retry_count = MAX_INVITE_RETRY; |
klauss | 85:b6f2dc1d0f4f | 50 | cb_new_counter++; |
klauss | 78:1353744f01e1 | 51 | } |
klauss | 78:1353744f01e1 | 52 | |
klauss | 78:1353744f01e1 | 53 | int Call_Box::get_status( void ){ return this->status; } |
klauss | 78:1353744f01e1 | 54 | |
klauss | 78:1353744f01e1 | 55 | void Call_Box::cb_set_status( uint8_t status ){ this->status = status; } |
klauss | 78:1353744f01e1 | 56 | |
klauss | 78:1353744f01e1 | 57 | int Call_Box::get_sip_status( void ){ |
klauss | 78:1353744f01e1 | 58 | if( sip == NULL ) return -1; |
klauss | 78:1353744f01e1 | 59 | |
klauss | 78:1353744f01e1 | 60 | else return this->sip->get_status(); |
klauss | 78:1353744f01e1 | 61 | } |
klauss | 78:1353744f01e1 | 62 | |
klauss | 78:1353744f01e1 | 63 | int Call_Box::set_sip_status( uint8_t status ){ |
klauss | 78:1353744f01e1 | 64 | if( sip == NULL ) return( -1 ); |
klauss | 78:1353744f01e1 | 65 | |
klauss | 78:1353744f01e1 | 66 | sip->sip_set_status( status ); |
klauss | 78:1353744f01e1 | 67 | |
klauss | 78:1353744f01e1 | 68 | return( 0 ); |
klauss | 0:4d17cd9c8f9d | 69 | } |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 0:4d17cd9c8f9d | 71 | Call_Box::~Call_Box( void ){ |
klauss | 85:b6f2dc1d0f4f | 72 | if( sip != NULL ) delete( sip ); |
klauss | 85:b6f2dc1d0f4f | 73 | cb_delete_counter++; |
klauss | 0:4d17cd9c8f9d | 74 | } |
klauss | 0:4d17cd9c8f9d | 75 | |
klauss | 0:4d17cd9c8f9d | 76 | int Call_Box::get_port( void ){ return( this->port ); } |
klauss | 0:4d17cd9c8f9d | 77 | int Call_Box::get_ext( void ){ return( this->ext ); } |
klauss | 0:4d17cd9c8f9d | 78 | |
klauss | 0:4d17cd9c8f9d | 79 | float Call_Box::get_elapsed_time( void ){ return( this->t.read_ms() ); } |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 100:09a23fcd3bdf | 81 | void Call_Box::reset_elapsed_time( void ){ |
klauss | 0:4d17cd9c8f9d | 82 | this->t.reset(); |
klauss | 78:1353744f01e1 | 83 | timeout = __TIMEOUT__; |
klauss | 78:1353744f01e1 | 84 | next_aging_type = __CYCLES__; |
klauss | 0:4d17cd9c8f9d | 85 | } |
klauss | 0:4d17cd9c8f9d | 86 | |
klauss | 0:4d17cd9c8f9d | 87 | bool Call_Box::is_timeout( void ){ |
klauss | 78:1353744f01e1 | 88 | if( seconds.read() > __RESQUEST_TIME__ ){ |
klauss | 78:1353744f01e1 | 89 | seconds.reset(); |
klauss | 78:1353744f01e1 | 90 | return( t.read() > __TIME_TO_REGISTER__ ) ? true : false; |
klauss | 78:1353744f01e1 | 91 | }else return false; |
klauss | 0:4d17cd9c8f9d | 92 | } |
klauss | 0:4d17cd9c8f9d | 93 | |
klauss | 78:1353744f01e1 | 94 | bool Call_Box::has_next_try( void ){ |
klauss | 78:1353744f01e1 | 95 | return( ( t.read() < __TIMEOUT__ ) ? true : false ); |
klauss | 0:4d17cd9c8f9d | 96 | } |
klauss | 0:4d17cd9c8f9d | 97 | |
klauss | 0:4d17cd9c8f9d | 98 | void Call_Box::registry( void ){ |
klauss | 0:4d17cd9c8f9d | 99 | if( this->sip == NULL ){ |
klauss | 113:db67ae00550e | 100 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 106:a34fcf9f0e02 | 101 | deleted_sip++; |
klauss | 87:679ee0d594a9 | 102 | if( sip == NULL ){ |
klauss | 87:679ee0d594a9 | 103 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 104 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 87:679ee0d594a9 | 105 | return; |
klauss | 87:679ee0d594a9 | 106 | } |
klauss | 0:4d17cd9c8f9d | 107 | |
klauss | 78:1353744f01e1 | 108 | if( sip->registry() > 0x00 ) reset_elapsed_time(); |
klauss | 81:3656f00ab3db | 109 | if( debug_aging ) debug_msg( "%d Registered - ( %f )", ext, __TIMEOUT__ - t.read() ); |
klauss | 78:1353744f01e1 | 110 | |
klauss | 0:4d17cd9c8f9d | 111 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 112 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 113 | }else{ |
klauss | 78:1353744f01e1 | 114 | if( sip->registry() > 0x00 ) reset_elapsed_time(); |
klauss | 81:3656f00ab3db | 115 | if( debug_aging ) debug_msg( "%d Registered - ( %f )", ext, __TIMEOUT__ - t.read() ); |
klauss | 0:4d17cd9c8f9d | 116 | } |
klauss | 0:4d17cd9c8f9d | 117 | } |
klauss | 0:4d17cd9c8f9d | 118 | |
klauss | 0:4d17cd9c8f9d | 119 | void Call_Box::unregistry( void ){ |
klauss | 0:4d17cd9c8f9d | 120 | if( this->sip == NULL ){ |
klauss | 113:db67ae00550e | 121 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 106:a34fcf9f0e02 | 122 | deleted_sip++; |
klauss | 87:679ee0d594a9 | 123 | if( sip == NULL ){ |
klauss | 87:679ee0d594a9 | 124 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 125 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 87:679ee0d594a9 | 126 | return; |
klauss | 87:679ee0d594a9 | 127 | } |
klauss | 0:4d17cd9c8f9d | 128 | sip->send_unregistry_pkg(); |
klauss | 0:4d17cd9c8f9d | 129 | |
klauss | 0:4d17cd9c8f9d | 130 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 131 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 132 | }else{ |
klauss | 0:4d17cd9c8f9d | 133 | sip->send_unregistry_pkg(); |
klauss | 0:4d17cd9c8f9d | 134 | } |
klauss | 0:4d17cd9c8f9d | 135 | } |
klauss | 0:4d17cd9c8f9d | 136 | |
klauss | 0:4d17cd9c8f9d | 137 | VZ_call * Call_Box::invite( void ){ |
klauss | 99:e80850c51106 | 138 | //t.stop(); |
klauss | 29:7246460b73f8 | 139 | VZ_call * call = NULL; |
klauss | 29:7246460b73f8 | 140 | |
klauss | 0:4d17cd9c8f9d | 141 | if( this->sip == NULL ){ |
klauss | 113:db67ae00550e | 142 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 106:a34fcf9f0e02 | 143 | deleted_sip++; |
klauss | 0:4d17cd9c8f9d | 144 | |
klauss | 87:679ee0d594a9 | 145 | if( sip != NULL ){ |
klauss | 87:679ee0d594a9 | 146 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 147 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 87:679ee0d594a9 | 148 | return( NULL ); |
klauss | 87:679ee0d594a9 | 149 | }else{ |
klauss | 87:679ee0d594a9 | 150 | call = sip->invite(); |
klauss | 87:679ee0d594a9 | 151 | |
klauss | 87:679ee0d594a9 | 152 | delete( sip ); |
klauss | 87:679ee0d594a9 | 153 | this->sip = NULL; |
klauss | 87:679ee0d594a9 | 154 | } |
klauss | 29:7246460b73f8 | 155 | }else{ |
klauss | 29:7246460b73f8 | 156 | call = sip->invite(); |
klauss | 0:4d17cd9c8f9d | 157 | } |
klauss | 29:7246460b73f8 | 158 | |
klauss | 29:7246460b73f8 | 159 | if( debug_cb ) debug_msg("Call returned value :: %p ", (void * )call ); |
klauss | 29:7246460b73f8 | 160 | if( call == NULL ) t.start(); |
klauss | 29:7246460b73f8 | 161 | return( call ); |
klauss | 0:4d17cd9c8f9d | 162 | } |
klauss | 0:4d17cd9c8f9d | 163 | |
klauss | 0:4d17cd9c8f9d | 164 | /* Retorna |
klauss | 0:4d17cd9c8f9d | 165 | = 0 :: ok |
klauss | 0:4d17cd9c8f9d | 166 | < 0 :: tive problemas |
klauss | 0:4d17cd9c8f9d | 167 | > 0 :: devo remover essa call do vetor de calls |
klauss | 0:4d17cd9c8f9d | 168 | */ |
klauss | 0:4d17cd9c8f9d | 169 | int Call_Box::listen_SIP_server( void ){ |
klauss | 0:4d17cd9c8f9d | 170 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 171 | if( status == cb_on_call || status == cb_idle ){ |
klauss | 113:db67ae00550e | 172 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 113:db67ae00550e | 173 | deleted_sip++; |
klauss | 87:679ee0d594a9 | 174 | |
klauss | 87:679ee0d594a9 | 175 | if( sip == NULL ){ |
klauss | 87:679ee0d594a9 | 176 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 177 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 87:679ee0d594a9 | 178 | return( -1 ); |
klauss | 87:679ee0d594a9 | 179 | }else{ |
klauss | 87:679ee0d594a9 | 180 | int out_read = sip->listen_SIP_server(); |
klauss | 87:679ee0d594a9 | 181 | |
klauss | 87:679ee0d594a9 | 182 | delete( sip ); |
klauss | 87:679ee0d594a9 | 183 | this->sip = NULL; |
klauss | 87:679ee0d594a9 | 184 | return( out_read ); |
klauss | 87:679ee0d594a9 | 185 | } |
klauss | 0:4d17cd9c8f9d | 186 | }else return( 0 ); |
klauss | 0:4d17cd9c8f9d | 187 | }else{ |
klauss | 0:4d17cd9c8f9d | 188 | if( status == cb_on_call || status == cb_idle ){ |
klauss | 13:ae278302dffe | 189 | return ( sip->listen_SIP_server() ); |
klauss | 13:ae278302dffe | 190 | } else return( 0 ); |
klauss | 0:4d17cd9c8f9d | 191 | } |
klauss | 0:4d17cd9c8f9d | 192 | } |
klauss | 0:4d17cd9c8f9d | 193 | |
klauss | 0:4d17cd9c8f9d | 194 | void Call_Box::set_msg_id( uint8_t msg_id ){ |
klauss | 78:1353744f01e1 | 195 | this->msg_id = ( msg_id > 0x10 ) ? msg_id : 0x11; |
klauss | 0:4d17cd9c8f9d | 196 | } |
klauss | 0:4d17cd9c8f9d | 197 | uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); } |
klauss | 0:4d17cd9c8f9d | 198 | |
klauss | 0:4d17cd9c8f9d | 199 | void Call_Box::set_timeslice( uint8_t timeslice ){ |
klauss | 0:4d17cd9c8f9d | 200 | this->timeslice = timeslice; |
klauss | 0:4d17cd9c8f9d | 201 | } |
klauss | 0:4d17cd9c8f9d | 202 | uint8_t Call_Box::get_timeslice( void ){ return( this->timeslice ); } |
klauss | 0:4d17cd9c8f9d | 203 | |
klauss | 0:4d17cd9c8f9d | 204 | //void Call_Box::set_sip( Sip * sip ){ |
klauss | 0:4d17cd9c8f9d | 205 | // this->sip = sip; |
klauss | 0:4d17cd9c8f9d | 206 | //} |
klauss | 0:4d17cd9c8f9d | 207 | |
klauss | 0:4d17cd9c8f9d | 208 | void Call_Box::send_bye( void ){ |
klauss | 0:4d17cd9c8f9d | 209 | if( this->sip == NULL ){ |
klauss | 113:db67ae00550e | 210 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 106:a34fcf9f0e02 | 211 | deleted_sip++; |
klauss | 0:4d17cd9c8f9d | 212 | |
klauss | 87:679ee0d594a9 | 213 | if( sip == NULL ){ |
klauss | 87:679ee0d594a9 | 214 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 215 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 87:679ee0d594a9 | 216 | return; |
klauss | 87:679ee0d594a9 | 217 | }else{ |
klauss | 13:ae278302dffe | 218 | |
klauss | 87:679ee0d594a9 | 219 | sip->send_bye(); |
klauss | 87:679ee0d594a9 | 220 | |
klauss | 87:679ee0d594a9 | 221 | delete( sip ); |
klauss | 87:679ee0d594a9 | 222 | sip = NULL; |
klauss | 87:679ee0d594a9 | 223 | } |
klauss | 0:4d17cd9c8f9d | 224 | }else{ |
klauss | 0:4d17cd9c8f9d | 225 | sip->send_bye(); |
klauss | 0:4d17cd9c8f9d | 226 | } |
klauss | 1:a1758104fa1d | 227 | } |
klauss | 1:a1758104fa1d | 228 | |
klauss | 1:a1758104fa1d | 229 | void Call_Box::reset_sip( void ){ |
klauss | 113:db67ae00550e | 230 | if( this->sip != NULL ) delete( this->sip ); |
klauss | 1:a1758104fa1d | 231 | |
klauss | 113:db67ae00550e | 232 | this->sip = new Sip( ext, ext + shift_port ); |
klauss | 106:a34fcf9f0e02 | 233 | deleted_sip++; |
klauss | 87:679ee0d594a9 | 234 | |
klauss | 87:679ee0d594a9 | 235 | if( sip == NULL ) memory_is_over = true; |
klauss | 14:22a35f575502 | 236 | } |
klauss | 14:22a35f575502 | 237 | |
klauss | 14:22a35f575502 | 238 | void Call_Box::set_sip_status( int status ){ |
klauss | 14:22a35f575502 | 239 | if( this->sip != NULL ){ |
klauss | 14:22a35f575502 | 240 | this->sip->status = status; |
klauss | 14:22a35f575502 | 241 | }else{ |
klauss | 78:1353744f01e1 | 242 | if( debug_cb) debug_msg("Sip equals NULL o.O"); |
klauss | 109:a5b8264ffbbc | 243 | deleted_sip++; |
klauss | 113:db67ae00550e | 244 | } |
klauss | 29:7246460b73f8 | 245 | } |
klauss | 29:7246460b73f8 | 246 | |
klauss | 29:7246460b73f8 | 247 | void Call_Box::re_start_timer( void ){ |
klauss | 29:7246460b73f8 | 248 | t.start(); |
klauss | 78:1353744f01e1 | 249 | } |
klauss | 78:1353744f01e1 | 250 | |
klauss | 78:1353744f01e1 | 251 | int8_t Call_Box::get_next_aging_type( void ){ |
klauss | 78:1353744f01e1 | 252 | next_aging_type--; |
klauss | 78:1353744f01e1 | 253 | |
klauss | 78:1353744f01e1 | 254 | if( ( next_aging_type % 2 ) == 0 || ( next_aging_type > __CYCLES__ - 15 ) ) return( REQUEST_REGISTRY ); |
klauss | 78:1353744f01e1 | 255 | |
klauss | 78:1353744f01e1 | 256 | else if( ( next_aging_type % 7 ) == 0 ) return( REQUEST_PEND ); |
klauss | 78:1353744f01e1 | 257 | |
klauss | 78:1353744f01e1 | 258 | else return( REQUEST_PING ); |
klauss | 81:3656f00ab3db | 259 | } |
klauss | 81:3656f00ab3db | 260 | |
klauss | 81:3656f00ab3db | 261 | void Call_Box::set_invite_response_ok( void ){ this->invite_response = true; } |
klauss | 92:92df17f538a8 | 262 | |
klauss | 92:92df17f538a8 | 263 | //void Call_Box::set_first_invite_response_ok( void ){ this->invite_first_response = true; |
klauss | 92:92df17f538a8 | 264 | // debug_msg(""); |
klauss | 92:92df17f538a8 | 265 | //} |
klauss | 92:92df17f538a8 | 266 | |
klauss | 81:3656f00ab3db | 267 | void Call_Box::set_invite_response_pending( void ){ this->invite_response = false; } |
klauss | 81:3656f00ab3db | 268 | bool Call_Box::get_invite_response( void ){ return( this->invite_response ); } |
klauss | 81:3656f00ab3db | 269 | |
klauss | 92:92df17f538a8 | 270 | //void Call_Box::set_first_invite_response_pending( void ){ this->first_invite_response = false; } |
klauss | 92:92df17f538a8 | 271 | //bool Call_Box::get_first_invite_response( void ){ return( this->first_invite_response ); } |
klauss | 92:92df17f538a8 | 272 | |
klauss | 92:92df17f538a8 | 273 | |
klauss | 92:92df17f538a8 | 274 | void Call_Box::invite_retry_count_reset( void ){ invite_retry_count = MAX_INVITE_RETRY; } |
klauss | 92:92df17f538a8 | 275 | uint8_t Call_Box::get_invite_retry_count( void ){ |
klauss | 92:92df17f538a8 | 276 | return ( invite_retry_count ) ? invite_retry_count-- : 0; |
klauss | 92:92df17f538a8 | 277 | } |
klauss | 92:92df17f538a8 | 278 | |
klauss | 81:3656f00ab3db | 279 | void Call_Box::set_bye_response_ok( void ){ this->bye_response = true; } |
klauss | 81:3656f00ab3db | 280 | void Call_Box::set_bye_response_pending( void ){ this->bye_response = false; } |
klauss | 89:0fe315117b00 | 281 | bool Call_Box::get_bye_response( void ){ return( this->bye_response ); } |
klauss | 89:0fe315117b00 | 282 | |
klauss | 89:0fe315117b00 | 283 | |
klauss | 89:0fe315117b00 | 284 | int Call_Box::get_sip_socket_fd( void ){ |
klauss | 89:0fe315117b00 | 285 | return( sip_socket_fd ); |
klauss | 89:0fe315117b00 | 286 | } |
klauss | 89:0fe315117b00 | 287 | |
klauss | 91:c2a86b1f8aaa | 288 | int Call_Box::sip_udp_incomming_pkg( void ){ |
klauss | 91:c2a86b1f8aaa | 289 | return sip->udp_incomming_pkg(); |
klauss | 91:c2a86b1f8aaa | 290 | } |
klauss | 91:c2a86b1f8aaa | 291 | |
klauss | 91:c2a86b1f8aaa | 292 | void Call_Box::reset_cb_status( void ){ |
klauss | 91:c2a86b1f8aaa | 293 | if( sip != NULL ) sip->reset_call(); |
klauss | 97:8985817e8847 | 294 | } |
klauss | 97:8985817e8847 | 295 | |
klauss | 97:8985817e8847 | 296 | int Call_Box::get_sip_ext( void ){ return this->sip->get_ext(); } |
klauss | 99:e80850c51106 | 297 | int Call_Box::get_sip_port( void ){ return this->sip->get_port(); } |
klauss | 99:e80850c51106 | 298 | |
klauss | 113:db67ae00550e | 299 | |
klauss | 113:db67ae00550e | 300 | int Call_Box::get_timer ( void ) |
klauss | 113:db67ae00550e | 301 | { |
klauss | 113:db67ae00550e | 302 | int now = t.read (); |
klauss | 113:db67ae00550e | 303 | if( now >= 9999 || now <= 0 ) t.reset (); |
klauss | 113:db67ae00550e | 304 | return t.read (); |
klauss | 113:db67ae00550e | 305 | } |
klauss | 108:18a3702650f3 | 306 | |
klauss | 108:18a3702650f3 | 307 | int Call_Box::get_rtp_port ( void ) |
klauss | 108:18a3702650f3 | 308 | { |
klauss | 108:18a3702650f3 | 309 | if( this->sip != NULL ){ |
klauss | 108:18a3702650f3 | 310 | return this->sip->get_sip_rtp_port(); |
klauss | 108:18a3702650f3 | 311 | }else{ |
klauss | 108:18a3702650f3 | 312 | if( debug_cb) debug_msg("Sip equals NULL o.O"); |
klauss | 109:a5b8264ffbbc | 313 | deleted_sip++; |
klauss | 108:18a3702650f3 | 314 | return -1; |
klauss | 108:18a3702650f3 | 315 | } |
klauss | 108:18a3702650f3 | 316 | } |
klauss | 108:18a3702650f3 | 317 | |
klauss | 108:18a3702650f3 | 318 | void Call_Box::set_rtp_port ( int new_rtp_port ) |
klauss | 108:18a3702650f3 | 319 | { |
klauss | 108:18a3702650f3 | 320 | if( this->sip != NULL ){ |
klauss | 108:18a3702650f3 | 321 | this->sip->set_sip_rtp_port( new_rtp_port ); |
klauss | 113:db67ae00550e | 322 | } |
klauss | 113:db67ae00550e | 323 | else |
klauss | 113:db67ae00550e | 324 | { |
klauss | 113:db67ae00550e | 325 | if ( debug_cb ) debug_msg("Sip equals NULL o.O"); |
klauss | 109:a5b8264ffbbc | 326 | deleted_sip++; |
klauss | 113:db67ae00550e | 327 | } |
klauss | 113:db67ae00550e | 328 | } |
klauss | 113:db67ae00550e | 329 | |
klauss | 113:db67ae00550e | 330 | void Call_Box::init_rtp_timer ( void ) |
klauss | 113:db67ae00550e | 331 | { |
klauss | 113:db67ae00550e | 332 | this->rtp_timer.start(); |
klauss | 113:db67ae00550e | 333 | } |
klauss | 113:db67ae00550e | 334 | |
klauss | 113:db67ae00550e | 335 | void Call_Box::reset_rtp_timer ( void ) |
klauss | 113:db67ae00550e | 336 | { |
klauss | 113:db67ae00550e | 337 | this->rtp_timer.stop(); |
klauss | 113:db67ae00550e | 338 | this->rtp_timer.reset(); |
klauss | 113:db67ae00550e | 339 | } |
klauss | 113:db67ae00550e | 340 | |
klauss | 113:db67ae00550e | 341 | bool Call_Box::is_rtp_timer_timeout ( void ) |
klauss | 113:db67ae00550e | 342 | { |
klauss | 113:db67ae00550e | 343 | return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; |
klauss | 113:db67ae00550e | 344 | } |
klauss | 113:db67ae00550e | 345 | |
klauss | 113:db67ae00550e | 346 | int Call_Box::get_rtp_timer ( void ) |
klauss | 113:db67ae00550e | 347 | { |
klauss | 113:db67ae00550e | 348 | return ( rtp_timer.read () ); |
klauss | 108:18a3702650f3 | 349 | } |
klauss | 108:18a3702650f3 | 350 | |
klauss | 109:a5b8264ffbbc | 351 | int Call_Box::print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 352 | { |
klauss | 109:a5b8264ffbbc | 353 | send_msg (""); |
klauss | 109:a5b8264ffbbc | 354 | send_msg ("Values ::\r\n"); |
klauss | 109:a5b8264ffbbc | 355 | switch( status ) { |
klauss | 109:a5b8264ffbbc | 356 | case cb_idle : { |
klauss | 109:a5b8264ffbbc | 357 | send_msg ("status :: cb_idle" ); |
klauss | 109:a5b8264ffbbc | 358 | break; |
klauss | 109:a5b8264ffbbc | 359 | } |
klauss | 109:a5b8264ffbbc | 360 | case cb_ringing : { |
klauss | 109:a5b8264ffbbc | 361 | send_msg ("status :: cb_ringing" ); |
klauss | 109:a5b8264ffbbc | 362 | break; |
klauss | 109:a5b8264ffbbc | 363 | } |
klauss | 109:a5b8264ffbbc | 364 | case cb_trying : { |
klauss | 109:a5b8264ffbbc | 365 | send_msg ("status :: cb_trying" ); |
klauss | 109:a5b8264ffbbc | 366 | break; |
klauss | 109:a5b8264ffbbc | 367 | } |
klauss | 109:a5b8264ffbbc | 368 | case cb_on_call : { |
klauss | 109:a5b8264ffbbc | 369 | send_msg ("status :: cb_on_call" ); |
klauss | 109:a5b8264ffbbc | 370 | break; |
klauss | 109:a5b8264ffbbc | 371 | } |
klauss | 109:a5b8264ffbbc | 372 | case cb_busy : { |
klauss | 109:a5b8264ffbbc | 373 | send_msg ("status :: cb_busy" ); |
klauss | 109:a5b8264ffbbc | 374 | break; |
klauss | 109:a5b8264ffbbc | 375 | } |
klauss | 109:a5b8264ffbbc | 376 | case cb_denied : { |
klauss | 109:a5b8264ffbbc | 377 | send_msg ("status :: cb_denied" ); |
klauss | 109:a5b8264ffbbc | 378 | break; |
klauss | 109:a5b8264ffbbc | 379 | } |
klauss | 109:a5b8264ffbbc | 380 | } |
klauss | 109:a5b8264ffbbc | 381 | send_msg ("ext :: %i", ext ); |
klauss | 109:a5b8264ffbbc | 382 | send_msg ("port :: %i", port ); |
klauss | 109:a5b8264ffbbc | 383 | send_msg ("Timer t :: %d", ( int )t.read () ); |
klauss | 109:a5b8264ffbbc | 384 | send_msg ("remaining_attempts :: %u", remaining_attempts ); |
klauss | 109:a5b8264ffbbc | 385 | send_msg ("timeout :: %f", timeout ); |
klauss | 109:a5b8264ffbbc | 386 | send_msg ("msg_id :: %d", msg_id ); |
klauss | 109:a5b8264ffbbc | 387 | send_msg ("timeslice :: %u", timeslice ); |
klauss | 109:a5b8264ffbbc | 388 | send_msg ("next_aging_type :: %u", next_aging_type ); |
klauss | 109:a5b8264ffbbc | 389 | send_msg ("invite_response :: %s", ( invite_response ) ? "true" : "false" ); |
klauss | 109:a5b8264ffbbc | 390 | send_msg ("invite_retry_count :: %u", invite_retry_count ); |
klauss | 109:a5b8264ffbbc | 391 | send_msg ("bye_response :: %s", ( bye_response ) ? "true" : "false" ); |
klauss | 109:a5b8264ffbbc | 392 | send_msg ("seconds :: %d", ( int )seconds.read () ); |
klauss | 109:a5b8264ffbbc | 393 | send_msg ("sip_socket_fd :: %d", sip_socket_fd ); |
klauss | 109:a5b8264ffbbc | 394 | send_msg (""); |
klauss | 109:a5b8264ffbbc | 395 | |
klauss | 109:a5b8264ffbbc | 396 | return ( sizeof( Call_Box ) ); |
klauss | 108:18a3702650f3 | 397 | } |