Hi Vinicius,

On 03/27/2013 07:13 PM, Vinicius Costa Gomes wrote:
In some cases, it is possible that when sco_connect_cb() is called
the .Connect() message (stored in card->msg) is not valid anymore.

Can you tell me what cases these are?

My thinking is that we will treat the connect callback specially.

If the driver calls the callback function, then it is assumed that no further action is necessary. If the driver calls connect_sco(), then we assume that the callback function will never be called.

---
  src/handsfree-audio.c | 24 ++++++++++++++++--------
  1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 3f24a2a..841cc3f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -242,16 +242,19 @@ static gboolean sco_connect_cb(GIOChannel *io, 
GIOCondition cond,
  {
        struct ofono_handsfree_card *card = user_data;
        DBusMessage *reply;
-       int sk;
+       int sk, err;

        if (agent == NULL) {
                /* There's no agent, so there's no one to reply to */
-               reply = NULL;
+               if (card->msg)
+                       dbus_message_unref(card->msg);
+
+               card->msg = NULL;
                goto done;
        }

        if (cond&  (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
-               reply = __ofono_error_failed(card->msg);
+               err = -EIO;
                goto done;
        }

@@ -261,14 +264,19 @@ static gboolean sco_connect_cb(GIOChannel *io, 
GIOCondition cond,

        close(sk);

-       reply = dbus_message_new_method_return(card->msg);
+       err = 0;

  done:
-       if (reply)
-               g_dbus_send_message(ofono_dbus_get_connection(), reply);
+       /* Or the msg was already replied to, or the agent exited */
+       if (card->msg == NULL)
+               return FALSE;

-       dbus_message_unref(card->msg);
-       card->msg = NULL;
+       if (err<  0)
+               reply = __ofono_error_failed(card->msg);
+       else
+               reply = dbus_message_new_method_return(card->msg);
+
+       __ofono_dbus_pending_reply(&card->msg, reply);

        return FALSE;
  }

Regards,
-Denis
_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to