From 16246e120e9c856999e46b2c1961c1f278835063 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 20 Feb 2013 18:55:46 -0300 Subject: [PATCH] handsfree-audio: Add Agent "Register" method This patch adds the initial Handsfree Audio Manager "Register" method implementation. It adds the parsing of the arguments included in the message and checks if there is an agent registered already. --- src/handsfree-audio.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c index e75c9774..ee67f05e 100644 --- a/src/handsfree-audio.c +++ b/src/handsfree-audio.c @@ -32,6 +32,15 @@ #define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager" +struct agent { + char *owner; + char *path; + unsigned char *codecs; + int codecs_len; +}; + +static struct agent *agent = NULL; + static DBusMessage *am_get_cards(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -41,7 +50,35 @@ static DBusMessage *am_get_cards(DBusConnection *conn, static DBusMessage *am_agent_register(DBusConnection *conn, DBusMessage *msg, void *user_data) { - return __ofono_error_not_implemented(msg); + const char *sender, *path; + unsigned char *codecs; + DBusMessageIter iter, array; + int length; + + if (agent) + return __ofono_error_in_use(msg); + + sender = dbus_message_get_sender(msg); + + if (dbus_message_iter_init(msg, &iter) == FALSE) + return __ofono_error_invalid_args(msg); + + dbus_message_iter_get_basic(&iter, &path); + + dbus_message_iter_next(&iter); + dbus_message_iter_recurse(&iter, &array); + dbus_message_iter_get_fixed_array(&array, &codecs, &length); + + if (length == 0) + return __ofono_error_invalid_args(msg); + + agent = g_new0(struct agent, 1); + agent->owner = g_strdup(sender); + agent->path = g_strdup(path); + agent->codecs = g_memdup(codecs, length); + agent->codecs_len = length; + + return dbus_message_new_method_return(msg); } static DBusMessage *am_agent_unregister(DBusConnection *conn,