From: Inaky Perez-Gonzalez <[email protected]>
This hooks __sms_msg_state_change_dbus_signal() into
__ofono_sms_tx_state_set(), so that a D-Bus signal will be emitted
whenever an SMS Message transitions state. This allows a client to
track, if desired, what is going on with the SMS Message it cares about.
With this, we can remove, in tx_finished() the asynchornous
finalization of the call (via sms_msg->dbus_msg) and make the call
synchronous (follow up commit).
The rest of the sites that were calling __ofono_sms_tx_state_set() get
(by definition) to send the signal.
---
src/sms.c | 33 +++++++++++++++++++++++++++------
test/test-sms-msg-state-change | 24 ++++++++++++++++++++++++
2 files changed, 51 insertions(+), 6 deletions(-)
create mode 100755 test/test-sms-msg-state-change
diff --git a/src/sms.c b/src/sms.c
index 77904ad..11d1f33 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -380,6 +380,32 @@ static void ofono_sms_tx_state_check(const char *file,
unsigned line,
/*
+ * Send a PropertyChange signal when the state changes
+ *
+ * D-Bus typing is "ss" for variable/value.
+ */
+static
+void __sms_msg_state_change_dbus_signal(struct tx_queue_entry *sms_msg)
+{
+ DBusConnection *dbus_conn = ofono_dbus_get_connection();
+ DBusMessage *dbus_signal;
+ DBusMessageIter iter;
+ const char *property = "TXState";
+ const char *new_state_str;
+
+ dbus_signal = dbus_message_new_signal(
+ sms_msg->dbus_path, SMS_MSG_INTERFACE, "PropertyChanged");
+ if (!dbus_signal)
+ return;
+ dbus_message_iter_init_append(dbus_signal, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property);
+ new_state_str = ofono_sms_tx_state_to_string(sms_msg->state);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &new_state_str);
+ g_dbus_send_message(dbus_conn, dbus_signal);
+}
+
+
+/*
* Set a pending SMS's state
*
* This is just syntatic sugar that validates that the transition is
@@ -441,6 +467,7 @@ 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;
+ __sms_msg_state_change_dbus_signal(entry);
}
@@ -584,10 +611,7 @@ static void tx_finished(const struct ofono_error *error,
int mr, void *data)
DBG("Max retries reached, giving up");
- ofono_sms_tx_state_set(entry, OFONO_SMS_TX_ST_CANCELING);
entry = g_queue_pop_head(sms->txq);
- __ofono_dbus_pending_reply(&entry->dbus_msg,
- __ofono_error_failed(entry->dbus_msg));
__ofono_history_sms_send_status(modem, entry->msg_id,
time(NULL),
@@ -621,9 +645,6 @@ static void tx_finished(const struct ofono_error *error,
int mr, void *data)
}
entry = g_queue_pop_head(sms->txq);
- __ofono_dbus_pending_reply(
- &entry->dbus_msg,
- dbus_message_new_method_return(entry->dbus_msg));
__ofono_history_sms_send_status(modem, entry->msg_id,
time(NULL),
OFONO_HISTORY_SMS_STATUS_SUBMITTED);
diff --git a/test/test-sms-msg-state-change b/test/test-sms-msg-state-change
new file mode 100755
index 0000000..18486bf
--- /dev/null
+++ b/test/test-sms-msg-state-change
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+def property_changed(name, value, path, interface):
+ if interface == "org.ofono.SMSMessage":
+ print "%s: name %s value %s interface %s" \
+ % (path, name, value, interface)
+
+if __name__ == '__main__':
+ print "FIXME: this should test the whole state change transition
machine"
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+
+ bus.add_signal_receiver(
+ property_changed, bus_name="org.ofono",
+ signal_name = "PropertyChanged", path_keyword="path",
+ interface_keyword="interface")
+ mainloop = gobject.MainLoop()
+ mainloop.run()
--
1.6.6.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono