From: Inaky Perez-Gonzalez <[email protected]>

When the SMS message going through the TX hoops changes states, call
the given callback function (if any). This will be used later to hook
up the D-Bus propagation of property changed signals.

Note this will do away with the ofono_sms_txq_submit_cb callback, as
it can be implemented in terms of a state change callback.
---
 src/ofono.h |    5 +++--
 src/sms.c   |   31 +++++++++++++++++++++++--------
 src/stk.c   |   19 +++++++++++++++++--
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index 2f7dfba..38e877f 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -216,12 +216,13 @@ enum ofono_sms_tx_state {
 
 const char *ofono_sms_tx_state_to_string(enum ofono_sms_tx_state);
 
-typedef void (*ofono_sms_txq_submit_cb_t)(gboolean ok, void *data);
+typedef void (*ofono_sms_msg_stch_cb_t)(void *data,
+                                       enum ofono_sms_tx_state new_state);
 
 struct tx_queue_entry *__ofono_sms_txq_submit(struct ofono_sms *sms,
                                                GSList *list,
                                                unsigned int flags,
-                                               ofono_sms_txq_submit_cb_t cb,
+                                               ofono_sms_msg_stch_cb_t stch_cb,
                                                void *data,
                                                ofono_destroy_func destroy);
 
diff --git a/src/sms.c b/src/sms.c
index a5e3a85..0d786a1 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -115,7 +115,7 @@ struct tx_queue_entry {
        unsigned int msg_id;
        unsigned int retry;
        unsigned int flags;
-       ofono_sms_txq_submit_cb_t cb;
+       ofono_sms_msg_stch_cb_t stch_cb;
        void *data;
        ofono_destroy_func destroy;
 };
@@ -518,6 +518,8 @@ static void __ofono_sms_tx_state_set(struct tx_queue_entry 
*entry,
        ofono_debug("%s:%d: SMS state change: %p %u -> %u\n",
                    file, line, entry, state_old, state_new);
        entry->state = state_new;
+       if (entry->stch_cb)
+               entry->stch_cb(entry->data, state_new);
 }
 
 
@@ -596,9 +598,6 @@ static void tx_finished(const struct ofono_error *error, 
int mr, void *data)
 next_q:
        entry = g_queue_peek_head(sms->txq);
 
-       if (entry->cb)
-               entry->cb(ok, entry->data);
-
        if (entry->flags & OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
                enum ofono_history_sms_status hs;
 
@@ -742,11 +741,26 @@ static struct tx_queue_entry *tx_queue_entry_new(GSList 
*msg_list)
        return entry;
 }
 
-static void send_message_cb(gboolean ok, void *data)
+static void send_message_stch_cb(void *data, enum ofono_sms_tx_state new_state)
 {
        DBusConnection *conn = ofono_dbus_get_connection();
        DBusMessage *msg = data;
        DBusMessage *reply;
+       gboolean ok;
+
+       /*
+        * We care about only the final states
+        * (DONE/CANCELLED/FAILED/EXPIRED), the rest are just
+        * ignored.
+        */
+       if (new_state == OFONO_SMS_TX_ST_DONE)
+               ok = TRUE;
+       else if (new_state == OFONO_SMS_TX_ST_CANCELLED
+                || new_state == OFONO_SMS_TX_ST_FAILED
+                || new_state == OFONO_SMS_TX_ST_EXPIRED)
+               ok = FALSE;
+       else
+               return;
 
        if (ok)
                reply = dbus_message_new_method_return(msg);
@@ -817,7 +831,8 @@ static DBusMessage *sms_send_message(DBusConnection *conn, 
DBusMessage *msg,
        if (sms->use_delivery_reports)
                flags |= OFONO_SMS_SUBMIT_FLAG_REQUEST_SR;
 
-       sms_msg = __ofono_sms_txq_submit(sms, msg_list, flags, send_message_cb,
+       sms_msg = __ofono_sms_txq_submit(sms, msg_list, flags,
+                                               send_message_stch_cb,
                                                dbus_message_ref(msg),
                                                send_message_destroy);
 
@@ -1561,7 +1576,7 @@ void *ofono_sms_get_data(struct ofono_sms *sms)
 struct tx_queue_entry *__ofono_sms_txq_submit(struct ofono_sms *sms,
                                                GSList *list,
                                                unsigned int flags,
-                                               ofono_sms_txq_submit_cb_t cb,
+                                               ofono_sms_msg_stch_cb_t stch_cb,
                                                void *data,
                                                ofono_destroy_func destroy)
 {
@@ -1575,7 +1590,7 @@ struct tx_queue_entry *__ofono_sms_txq_submit(struct 
ofono_sms *sms,
        }
 
        entry->flags = flags;
-       entry->cb = cb;
+       entry->stch_cb = stch_cb;
        entry->data = data;
        entry->destroy = destroy;
        entry->sms_mgr = sms;
diff --git a/src/stk.c b/src/stk.c
index 7d98f92..5636eb6 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -660,12 +660,27 @@ static void send_sms_cancel(struct ofono_stk *stk)
        stk_alpha_id_unset(stk);
 }
 
-static void send_sms_submit_cb(gboolean ok, void *data)
+static void send_sms_stch_cb(void *data, enum ofono_sms_tx_state new_state)
 {
        struct sms_submit_req *req = data;
        struct ofono_stk *stk = req->stk;
        struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
        struct stk_response rsp;
+       gboolean ok;
+
+       /*
+        * We care about only the final states
+        * (DONE/CANCELLED/FAILED/EXPIRED), the rest are just
+        * ignored.
+        */
+       if (new_state == OFONO_SMS_TX_ST_DONE)
+               ok = TRUE;
+       else if (new_state == OFONO_SMS_TX_ST_CANCELLED
+                || new_state == OFONO_SMS_TX_ST_FAILED
+                || new_state == OFONO_SMS_TX_ST_EXPIRED)
+               ok = FALSE;
+       else
+               return;
 
        ofono_debug("SMS submission %s", ok ? "successful" : "failed");
 
@@ -712,7 +727,7 @@ static gboolean handle_command_send_sms(const struct 
stk_command *cmd,
        msg_list.data = (void *) &cmd->send_sms.gsm_sms;
        msg_list.next = NULL;
 
-       __ofono_sms_txq_submit(sms, &msg_list, 0, send_sms_submit_cb,
+       __ofono_sms_txq_submit(sms, &msg_list, 0, send_sms_stch_cb,
                                stk->sms_submit_req, g_free);
 
        stk->cancel_cmd = send_sms_cancel;
-- 
1.6.6.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to