diff options
author | Mikel Astiz <mikel.astiz@bmw-carit.de> | 2011-10-12 14:35:29 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2011-10-13 13:20:13 -0500 |
commit | 7b9fa9455c1a4e961f47ecad18e17d0e26f8db65 (patch) | |
tree | fdefad4c54bff5df368e604b08b22d66040eef45 /src/handsfree.c | |
parent | 6a0a8d1c2e37cdf449bfed6d0fe04cbceb90b1c4 (diff) | |
download | ofono-7b9fa9455c1a4e961f47ecad18e17d0e26f8db65.tar.bz2 |
handsfree: Expose RequestPhoneNumber in D-Bus API
Diffstat (limited to 'src/handsfree.c')
-rw-r--r-- | src/handsfree.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/handsfree.c b/src/handsfree.c index 2566ed0e..ee3847ee 100644 --- a/src/handsfree.c +++ b/src/handsfree.c @@ -48,6 +48,7 @@ struct ofono_handsfree { const struct ofono_handsfree_driver *driver; void *driver_data; struct ofono_atom *atom; + DBusMessage *pending; }; void ofono_handsfree_set_inband_ringing(struct ofono_handsfree *hf, @@ -122,11 +123,54 @@ static DBusMessage *handsfree_set_property(DBusConnection *conn, return __ofono_error_invalid_args(msg); } +static void request_phone_number_cb(const struct ofono_error *error, + const struct ofono_phone_number *number, + void *data) +{ + struct ofono_handsfree *hf = data; + DBusMessage *reply; + const char *phone_number; + + if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { + DBG("Phone number request callback returned error: %s", + telephony_error_to_str(error)); + + reply = __ofono_error_failed(hf->pending); + __ofono_dbus_pending_reply(&hf->pending, reply); + return; + } + + phone_number = phone_number_to_string(number); + reply = dbus_message_new_method_return(hf->pending); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &phone_number, + DBUS_TYPE_INVALID); + __ofono_dbus_pending_reply(&hf->pending, reply); +} + +static DBusMessage *handsfree_request_phone_number(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + struct ofono_handsfree *hf = data; + + if (hf->pending) + return __ofono_error_busy(msg); + + if (!hf->driver->request_phone_number) + return __ofono_error_not_supported(msg); + + hf->pending = dbus_message_ref(msg); + hf->driver->request_phone_number(hf, request_phone_number_cb, hf); + + return NULL; +} + static GDBusMethodTable handsfree_methods[] = { { "GetProperties", "", "a{sv}", handsfree_get_properties, G_DBUS_METHOD_FLAG_ASYNC }, { "SetProperty", "sv", "", handsfree_set_property, G_DBUS_METHOD_FLAG_ASYNC }, + { "RequestPhoneNumber", "", "s", handsfree_request_phone_number, + G_DBUS_METHOD_FLAG_ASYNC }, { NULL, NULL, NULL, NULL } }; @@ -190,6 +234,12 @@ static void handsfree_unregister(struct ofono_atom *atom) DBusConnection *conn = ofono_dbus_get_connection(); struct ofono_modem *modem = __ofono_atom_get_modem(atom); const char *path = __ofono_atom_get_path(atom); + struct ofono_handsfree *hf = __ofono_atom_get_data(atom); + + if (hf->pending) { + DBusMessage *reply = __ofono_error_failed(hf->pending); + __ofono_dbus_pending_reply(&hf->pending, reply); + } ofono_modem_remove_interface(modem, OFONO_HANDSFREE_INTERFACE); g_dbus_unregister_interface(conn, path, |