From: Inaky Perez-Gonzalez <[email protected]>
This hooks sms_msg_stch_dbus_cb() into the SMS state change callback
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.
---
src/sms.c | 36 +++++++++++++++++++++++++++++++++++-
test/test-sms-msg-state-change | 24 ++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletions(-)
create mode 100755 test/test-sms-msg-state-change
diff --git a/src/sms.c b/src/sms.c
index 4569cf3..c0b2e00 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -820,6 +820,40 @@ struct tx_queue_entry *sms_msg_send(
/*
+ * Send a PropertyChange signal when the state changes
+ *
+ * D-Bus typing is "ss" for variable/value.
+ */
+static
+void sms_msg_stch_dbus_cb(void *_dbus_data,
+ enum ofono_sms_tx_state new_state)
+{
+ struct sms_msg_dbus_data *dbus_data = _dbus_data;
+ DBusConnection *dbus_conn = ofono_dbus_get_connection();
+ DBusMessage *dbus_signal;
+ DBusMessageIter iter;
+ const char *property = "TXState";
+ const char *new_state_str;
+
+ /*
+ * This will be called in the first transition, when all the
+ * D-Bus stuff is not yet in place.
+ */
+ if (dbus_data->dbus_path == NULL)
+ return;
+ dbus_signal = dbus_message_new_signal(
+ dbus_data->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(new_state);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &new_state_str);
+ g_dbus_send_message(dbus_conn, dbus_signal);
+}
+
+
+/*
* D-Bus: Send a SMS text message
*
* @conn: D-Bus connection
@@ -846,7 +880,7 @@ static DBusMessage *dbus_sms_msg_send(DBusConnection *conn,
DBusMessage *msg,
dbus_data = g_new0(struct sms_msg_dbus_data, 1);
sms_msg = sms_msg_send(sms, to, text, SMS_MSG_SEND_HISTORY,
- NULL,
+ sms_msg_stch_dbus_cb,
sms_msg_dbus_destroy,
dbus_data);
if (sms_msg == NULL)
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