From 65cf5fa1595b8ef8da4fe0ffb04ae561ec1bf75f Mon Sep 17 00:00:00 2001 From: barbieri Date: Thu, 18 Mar 2010 22:09:55 +0000 Subject: [PATCH] e_dbus/ofono: Add SmsManager interface support. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit By: João Paulo Rechi Vita git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@47336 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/e_dbus_ofono_test.c | 62 +++++++++++++++++++++++++++++++++ src/lib/ofono/E_Ofono.h | 8 +++-- src/lib/ofono/Makefile.am | 3 +- src/lib/ofono/e_ofono.c | 12 +++++++ src/lib/ofono/e_ofono_element.c | 3 +- src/lib/ofono/e_ofono_private.h | 3 ++ src/lib/ofono/e_ofono_sms.c | 77 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 src/lib/ofono/e_ofono_sms.c diff --git a/src/bin/e_dbus_ofono_test.c b/src/bin/e_dbus_ofono_test.c index 97606ea..b39edde 100644 --- a/src/bin/e_dbus_ofono_test.c +++ b/src/bin/e_dbus_ofono_test.c @@ -315,6 +315,66 @@ _on_cmd_modem_set_powered(char *cmd, char *args) return 1; } +/* SMS Commands */ + +static int +_on_cmd_sms_sca_set(char *cmd, char *args) +{ + char *next_args, *sca; + E_Ofono_Element *element = _element_from_args("org.ofono.SmsManager", args, + &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing service center address\n", stderr); + return 1; + } + + sca = next_args; + if (e_ofono_sms_sca_set(element, sca, _method_success_check, + "sms_sca_set")) + printf(":::Service Center Address on modem %s set to %s\n", + element->path, sca); + else + fputs("ERROR: couldn't change Service Center Address\n", stderr); + + return 1; +} + +static int +_on_cmd_sms_send_message(char *cmd, char *args) +{ + char *next_args, *number, *message; + E_Ofono_Element *element = _element_from_args("org.ofono.SmsManager", args, + &next_args); + + if (!element) + return 1; + + number = next_args; + if (!number) + { + fputs("ERROR: missing recipient number and message text.\n", stderr); + return 1; + } + + message = _tok(number); + if (!message) + { + fputs("ERROR: missing message text.\n", stderr); + return 1; + } + + if (!e_ofono_sms_send_message(element, number, message, + _method_success_check, "sms_send_message")) + fputs("ERROR: error setting property.\n", stderr); + + return 1; +} + static int _on_input(void *data, Ecore_Fd_Handler *fd_handler) { @@ -333,6 +393,8 @@ _on_input(void *data, Ecore_Fd_Handler *fd_handler) {"manager_get", _on_cmd_manager_get}, {"manager_modems_get", _on_cmd_manager_modems_get}, {"modem_set_powered", _on_cmd_modem_set_powered}, + {"sms_sca_set", _on_cmd_sms_sca_set}, + {"sms_send_message", _on_cmd_sms_send_message}, {NULL, NULL} }; diff --git a/src/lib/ofono/E_Ofono.h b/src/lib/ofono/E_Ofono.h index 534f7e5..33504e8 100644 --- a/src/lib/ofono/E_Ofono.h +++ b/src/lib/ofono/E_Ofono.h @@ -53,8 +53,7 @@ extern "C" { struct { Eina_Inlist *properties_get; Eina_Inlist *property_set; - Eina_Inlist *agent_register; - Eina_Inlist *agent_unregister; + Eina_Inlist *send_sms; } _pending; struct { Ecore_Idler *changed; @@ -82,6 +81,11 @@ extern "C" { EAPI Eina_Bool e_ofono_netreg_operator_get(const E_Ofono_Element *element, const char **op) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; EAPI Eina_Bool e_ofono_netreg_strength_get(const E_Ofono_Element *element, uint8_t *strength) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + /* SMS Methods */ + EAPI Eina_Bool e_ofono_sms_sca_get(const E_Ofono_Element *element, const char **sca) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_sms_sca_set(E_Ofono_Element *element, const char *sca, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_sms_send_message(const E_Ofono_Element *element, const char *number, const char *message, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + /* Low-Level API: * * Should just be used to work around problems until proper solution diff --git a/src/lib/ofono/Makefile.am b/src/lib/ofono/Makefile.am index 0228b93..715d1db 100644 --- a/src/lib/ofono/Makefile.am +++ b/src/lib/ofono/Makefile.am @@ -16,7 +16,8 @@ e_ofono.c \ e_ofono_element.c \ e_ofono_manager.c \ e_ofono_modem.c \ -e_ofono_network_reg.c +e_ofono_network_reg.c \ +e_ofono_sms.c libeofono_la_LIBADD = \ @EDBUS_LIBS@ @EVAS_LIBS@ \ diff --git a/src/lib/ofono/e_ofono.c b/src/lib/ofono/e_ofono.c index de2f2aa..8ca58b3 100644 --- a/src/lib/ofono/e_ofono.c +++ b/src/lib/ofono/e_ofono.c @@ -31,6 +31,9 @@ const char *e_ofono_prop_mode = NULL; const char *e_ofono_prop_status = NULL; const char *e_ofono_prop_operator = NULL; const char *e_ofono_prop_strength = NULL; +const char *e_ofono_iface_sms = NULL; +const char *e_ofono_prop_sca = NULL; +const char *e_ofono_method_send_sms = NULL; int _e_dbus_ofono_log_dom = -1; @@ -247,6 +250,12 @@ e_ofono_system_init(E_DBus_Connection *edbus_conn) e_ofono_prop_operator = eina_stringshare_add("Operator"); if (e_ofono_prop_strength == NULL) e_ofono_prop_strength = eina_stringshare_add("Strength"); + if (e_ofono_iface_sms == NULL) + e_ofono_iface_sms = eina_stringshare_add("org.ofono.SmsManager"); + if (e_ofono_prop_sca == NULL) + e_ofono_prop_sca = eina_stringshare_add("ServiceCenterAddress"); + if (e_ofono_method_send_sms == NULL) + e_ofono_method_send_sms = eina_stringshare_add("SendMessage"); e_ofono_conn = edbus_conn; cb_name_owner_changed = e_dbus_signal_handler_add @@ -303,5 +312,8 @@ e_ofono_system_shutdown(void) _stringshare_del(&e_ofono_prop_status); _stringshare_del(&e_ofono_prop_operator); _stringshare_del(&e_ofono_prop_strength); + _stringshare_del(&e_ofono_iface_sms); + _stringshare_del(&e_ofono_prop_sca); + _stringshare_del(&e_ofono_method_send_sms); return 0; } diff --git a/src/lib/ofono/e_ofono_element.c b/src/lib/ofono/e_ofono_element.c index 13ab991..c57fe24 100644 --- a/src/lib/ofono/e_ofono_element.c +++ b/src/lib/ofono/e_ofono_element.c @@ -1054,8 +1054,7 @@ e_ofono_element_free(E_Ofono_Element *element) e_ofono_element_pending_cancel_and_free(&element->_pending.properties_get); e_ofono_element_pending_cancel_and_free(&element->_pending.property_set); - e_ofono_element_pending_cancel_and_free(&element->_pending.agent_register); - e_ofono_element_pending_cancel_and_free(&element->_pending.agent_unregister); + e_ofono_element_pending_cancel_and_free(&element->_pending.send_sms); e_ofono_element_extra_properties_free(element); eina_stringshare_del(element->interface); diff --git a/src/lib/ofono/e_ofono_private.h b/src/lib/ofono/e_ofono_private.h index 99f35d8..bbe7366 100644 --- a/src/lib/ofono/e_ofono_private.h +++ b/src/lib/ofono/e_ofono_private.h @@ -39,6 +39,9 @@ extern const char *e_ofono_prop_status; extern const char *e_ofono_prop_operator; extern const char *e_ofono_prop_strength; + extern const char *e_ofono_iface_sms; + extern const char *e_ofono_prop_sca; + extern const char *e_ofono_method_send_sms; extern int _e_dbus_ofono_log_dom; diff --git a/src/lib/ofono/e_ofono_sms.c b/src/lib/ofono/e_ofono_sms.c new file mode 100644 index 0000000..c594acb --- /dev/null +++ b/src/lib/ofono/e_ofono_sms.c @@ -0,0 +1,77 @@ +#include "e_ofono_private.h" + +/** + * Get property "ServiceCenterAddress" value. + * + * @param sca where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_sca_get(const E_Ofono_Element *element, const char **sca) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(sca, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_sca, NULL, sca); +} + +/** + * Call method SetProperty("ServiceCenterAddress", powered) at the given + * element on server. + * + * + * @param sca value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_sca_set(E_Ofono_Element *element, const char *sca, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + return e_ofono_element_property_set_full + (element, e_ofono_prop_sca, DBUS_TYPE_STRING, sca, cb, data); +} + +/** + * Send SMS message. + * + * Call method SendMessage(number, text) to send a new SMS message. + * + * @param number the destination of the message + * @param message text of message body + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_send_message(const E_Ofono_Element *element, const char *number, const char *message, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(number, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(message, 0); + + DBusMessage *m; + DBusMessageIter i; + + if (!(m = dbus_message_new_method_call(e_ofono_system_bus_name_get(), + element->path, element->interface, + e_ofono_method_send_sms))) + return EINA_FALSE; + + dbus_message_iter_init_append(m, &i); + dbus_message_iter_append_basic(&i, DBUS_TYPE_STRING, &number); + dbus_message_iter_append_basic(&i, DBUS_TYPE_STRING, &message); + + return e_ofono_element_message_send(element, e_ofono_method_send_sms, + e_ofono_iface_sms, NULL, m, + &element->_pending.send_sms, cb, data); +} -- 2.7.4