126 | | 0. You need to implement reachability API (sample is provided in the patch). With this API we can monitor the access point connection status and perform re-registration when necessary. |
127 | | 1. We need to keep track of which transport is being used by the registration, by implementing the {{{on_reg_state2()}}} and {{{on_transport_state()}}} callbacks. Add reference counter to it to prevent other from deleting the transport while we're referencing it (it shouldn't happen while the registration is active, but just in case). Sample code: |
| 126 | 1. You need to implement reachability API (sample is provided in the patch). With this API we can monitor the access point connection status and perform re-registration when necessary. |
| 127 | 2. We need to keep track of which transport is being used by the registration, by implementing the {{{on_reg_state2()}}} and {{{on_transport_state()}}} callbacks. Add reference counter to it to prevent other from deleting the transport while we're referencing it (it shouldn't happen while the registration is active, but just in case). Sample code: |
178 | | |
179 | | 2. When IP address change is detected: a) close the TCP transport that we saved in step 1) above, and b) send unregistration. Sample code: |
| 178 | Starting from release 2.4, we have a new callback {{{on_reg_started2()}}} (for more details, please refer to ticket #1825), which allows application to get the transport much earlier, i.e. when the registration process begins. This allows application to close the transport before connecting state. So, you can choose to split the implementation in {{{on_reg_state2()}}} above into two callbacks {{{on_reg_started2()}}} and {{{on_reg_state2()}}}: |
| 179 | {{{ |
| 180 | static void on_reg_started2(pjsua_acc_id acc_id, pjsua_reg_info *info) |
| 181 | { |
| 182 | struct pjsip_regc_cbparam *rp = info->cbparam; |
| 183 | |
| 184 | |
| 185 | ... |
| 186 | if (acc_id != the_acc_id) |
| 187 | return; |
| 188 | |
| 189 | if (the_transport != rp->rdata->tp_info.transport) { |
| 190 | /* Registration success */ |
| 191 | if (the_transport) { |
| 192 | PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); |
| 193 | pjsip_transport_dec_ref(the_transport); |
| 194 | the_transport = NULL; |
| 195 | } |
| 196 | /* Save transport instance so that we can close it later when |
| 197 | * new IP address is detected. |
| 198 | */ |
| 199 | PJ_LOG(3,(THIS_FILE, "xxx: Saving transport..")); |
| 200 | the_transport = rp->rdata->tp_info.transport; |
| 201 | pjsip_transport_add_ref(the_transport); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static void on_reg_state2(pjsua_acc_id acc_id, pjsua_reg_info *info) |
| 206 | { |
| 207 | struct pjsip_regc_cbparam *rp = info->cbparam; |
| 208 | |
| 209 | |
| 210 | ... |
| 211 | if (acc_id != the_acc_id) |
| 212 | return; |
| 213 | |
| 214 | if (rp->code/100 == 2 && rp->expiration > 0 && rp->contact_cnt > 0) { |
| 215 | /* We already saved the transport instance */ |
| 216 | } else { |
| 217 | if (the_transport) { |
| 218 | PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); |
| 219 | pjsip_transport_dec_ref(the_transport); |
| 220 | the_transport = NULL; |
| 221 | } |
| 222 | } |
| 223 | ... |
| 224 | } |
| 225 | }}} |
| 226 | |
| 227 | 3. When IP address change is detected: a) close the TCP transport that we saved in step 2) above, and b) send unregistration. Sample code: |