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 takes 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 | 36 +++++++++++++++++++++++++-----------
src/stk.c | 22 ++++++++++++++++++----
3 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/src/ofono.h b/src/ofono.h
index 51c2743..d5ac6f5 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -216,11 +216,12 @@ 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 1075f33..668a645 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -114,7 +114,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;
};
@@ -530,6 +530,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);
}
@@ -602,10 +604,6 @@ static void tx_finished(const struct ofono_error *error,
int mr, void *data)
next_q:
entry = g_queue_peek_head(sms->txq);
-#warning FIXME: cb should not be called on WSR?
- if (entry->cb)
- entry->cb(ok, entry->data);
-
if (entry->flags & OFONO_SMS_SUBMIT_FLAG_RECORD_HISTORY) {
enum ofono_history_sms_status hs;
@@ -700,12 +698,27 @@ 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();
struct sms_msg_dbus_data *dbus_data = data;
DBusMessage *msg = dbus_data->dbus_msg;
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);
@@ -795,9 +808,10 @@ 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, msg_id,
send_message_cb,
- dbus_message_ref(msg),
- send_message_destroy);
+ sms_msg = __ofono_sms_txq_submit(sms, msg_list, flags, msg_id,
+ send_message_stch_cb,
+ dbus_message_ref(msg),
+ send_message_destroy);
g_slist_foreach(msg_list, (GFunc)g_free, NULL);
g_slist_free(msg_list);
@@ -1528,7 +1542,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);
@@ -1542,7 +1556,7 @@ struct tx_queue_entry * __ofono_sms_txq_submit(struct
ofono_sms *sms, GSList *li
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 400b033..c253aa2 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -287,13 +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");
if (req->cancelled) {
@@ -339,8 +353,8 @@ static gboolean handle_command_send_sms(const struct
stk_command *cmd,
msg_list.data = (void *) &cmd->send_sms.gsm_sms;
msg_list.next = NULL;
#warning FIXME: fix msg_id, missing
- __ofono_sms_txq_submit(sms, &msg_list, 0, 0, send_sms_submit_cb,
- stk->sms_submit_req, g_free);
+ __ofono_sms_txq_submit(sms, &msg_list, 0, 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