Hi Alex, On 7/30/21 9:24 AM, [email protected] wrote:
Thanks Denis that helps. I see I need to learn a bit and get my head around this.For example I find this really confusing: cbd = req_cb_data_ref(cbd); if (g_at_chat_send(nmd->chat, "AT+CESQ", cesq_prefix, cesq_cb, cbd, req_cb_data_unref) == 0) { CALLBACK_WITH_FAILURE(cbd->cb, cbd->data); req_cb_data_unref(cbd); } This does some kind of allocation - ok This makes the call - ok fine Provides the unref function into the call - ok so far
So in this particular case, g_at_chat_send() returning 0 means the command could not be scheduled for whatever reason (usually the tty port is dead). By convention, failures do not side-effect. So you have to free any allocated resources manually. Hence the unref here.
But then I'm thinking if the call _succeeds_ our unref gets called?
Yes. destroy callback is called in every circumstance once g_at_chat_send() returns a success. So it will get called after cesq_cb(), or if the request is cleaned up early (cesq_cb() never called)
But if our call _fails_ then we have to do the unref ourselves?
Right, the 'no-side-effect' part applies. Regards, -Denis _______________________________________________ ofono mailing list -- [email protected] To unsubscribe send an email to [email protected]
