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   |   30 ++++++++++++++++++++++--------
 src/stk.c   |   19 +++++++++++++++++--
 3 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index 0ba38ce..679c3c3 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, unsigned ref,
-       ofono_sms_txq_submit_cb_t cb,
+       ofono_sms_msg_stch_cb_t stch_cb,
        void *data, ofono_destroy_func destroy);
 
 #include <ofono/sim.h>
diff --git a/src/sms.c b/src/sms.c
index 8028ca2..127e40c 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -113,7 +113,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;
 };
@@ -516,6 +516,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);
 }
 
 
@@ -594,9 +596,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;
 
@@ -692,11 +691,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);
@@ -763,7 +777,7 @@ static DBusMessage *sms_send_message(DBusConnection *conn, 
DBusMessage *msg,
                flags |= OFONO_SMS_SUBMIT_FLAG_REQUEST_SR;
 
        sms_msg = __ofono_sms_txq_submit(sms, msg_list, flags, msg_id,
-                                        send_message_cb,
+                                        send_message_stch_cb,
                                         dbus_message_ref(msg),
                                         send_message_destroy);
 
@@ -1501,7 +1515,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, unsigned msg_id,
-       ofono_sms_txq_submit_cb_t cb,
+       ofono_sms_msg_stch_cb_t stch_cb,
        void *data, ofono_destroy_func destroy)
 {
        struct tx_queue_entry *entry = tx_queue_entry_new(list);
@@ -1515,7 +1529,7 @@ struct tx_queue_entry *__ofono_sms_txq_submit(
 
        entry->msg_id = msg_id;
        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 620811b..a9c2d17 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -287,12 +287,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");
 
@@ -340,7 +355,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;
        msg_id = sms_uuid_from_pdu_list(&msg_list);
-       __ofono_sms_txq_submit(sms, &msg_list, 0, msg_id, send_sms_submit_cb,
+       __ofono_sms_txq_submit(sms, &msg_list, 0, msg_id, 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