This patch implements the "Unregister" method of the Handsfree Audio
Manager. The agent is unregistered if sender and path match.
---
 plugins/hfp_audio.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/plugins/hfp_audio.c b/plugins/hfp_audio.c
index a8e365c..f46d739 100644
--- a/plugins/hfp_audio.c
+++ b/plugins/hfp_audio.c
@@ -146,9 +146,33 @@ invalid_args:
 static DBusMessage *am_agent_unregister(DBusConnection *conn,
                                        DBusMessage *msg, void *user_data)
 {
-       return g_dbus_create_error(msg, OFONO_ERROR_INTERFACE
-                                               ".NotImplemented",
-                                               "Implementation not provided");
+       GSList *list;
+       const char *sender, *path;
+       struct agent match, *agent;
+       DBusMessageIter iter;
+
+       sender = dbus_message_get_sender(msg);
+
+       if (dbus_message_iter_init(msg, &iter) == FALSE)
+               goto invalid_args;
+
+       dbus_message_iter_get_basic(&iter, &path);
+
+       match.owner = (char *) sender;
+       match.path = (char *) path;
+       list = g_slist_find_custom(agents, &match, agent_cmp);
+       if (list == NULL)
+               goto invalid_args;
+
+       agent = list->data;
+       agents = g_slist_remove(agents, agent);
+       agent_free(agent);
+
+       return dbus_message_new_method_return(msg);
+
+invalid_args:
+       return g_dbus_create_error(msg, OFONO_ERROR_INTERFACE ".Rejected",
+                                       "Invalid arguments in method call");
 }
 
 static const GDBusMethodTable am_methods[] = {
-- 
1.7.11.7

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to